]> Joshua Wise's Git repositories - netwatch.git/blame - tools/smram-linux-tool.c
Ass.
[netwatch.git] / tools / smram-linux-tool.c
CommitLineData
99970893
JP
1#include <unistd.h>
2#include <getopt.h>
3#include <stdlib.h>
4#include <stdio.h>
81148fa1 5#include <smram.h>
99970893
JP
6
7static 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
17void usage(int argc, char **argv)
18{
19 printf("Usage: %s [ --dump ] [ --open | --close ]\n",
20 argv[0]);
21 exit(1);
22}
23
24int main(int argc, char **argv)
25{
26 if (geteuid() != 0)
27 {
81148fa1 28 printf("%s: This program must be run as root.\n", argv[0]);
99970893
JP
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 {
81148fa1 65 smram_aseg_set_state(do_open ? SMRAM_ASEG_OPEN : SMRAM_ASEG_SMMONLY);
99970893
JP
66 }
67
68 return 0;
69}
This page took 0.032311 seconds and 4 git commands to generate.