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