]> Joshua Wise's Git repositories - netwatch.git/blob - tools/smram-linux-tool.c
Split smm-open-ich2 into two files:
[netwatch.git] / tools / smram-linux-tool.c
1 #include <unistd.h>
2 #include <getopt.h>
3 #include <stdlib.h>
4 #include <stdio.h>
5
6 static struct option longopts[] = {
7         { "open",       no_argument,    NULL,   'o'     },
8         { "close",      no_argument,    NULL,   'c'     },
9         { "dump",       no_argument,    NULL,   'd'     },
10         { NULL,         0,              NULL,   0       }
11 };
12
13 #define OP_DUMP 1
14 #define OP_SET 2
15
16 void usage(int argc, char **argv)
17 {
18         printf("Usage: %s [ --dump ] [ --open | --close ]\n",
19                 argv[0]);
20         exit(1);
21 }
22
23 int main(int argc, char **argv)
24 {
25         if (geteuid() != 0)
26         {
27                 printf("This program must be run as root, dumbass.\n");
28                 return 1;
29         }
30         
31         int ch;
32         int op = 0;
33         int do_open = 0;
34         while ((ch = getopt_long(argc, argv, "ocsd:", longopts, NULL)) != -1)
35         {
36                 switch (ch)
37                 {
38                 case 'o':
39                         if (op & OP_SET) usage(argc, argv);
40                         op |= OP_SET;
41                         do_open = 1;
42                         break;
43                 case 'c':
44                         if (op & OP_SET) usage(argc, argv);
45                         op |= OP_SET;
46                         break;
47                 case 'd':
48                         op |= OP_DUMP;
49                         break;
50                 default:
51                         usage(argc, argv);
52                 }
53         }
54
55         if (!op) usage(argc, argv);
56
57         if (op & OP_DUMP)
58         {
59                 smram_aseg_dump();
60         }
61
62         if (op & OP_SET)
63         {
64                 smram_aseg_set_state(do_open);
65         }
66         
67         return 0;
68 }
This page took 0.027608 seconds and 4 git commands to generate.