]> Joshua Wise's Git repositories - netwatch.git/blobdiff - tools/smram-linux-tool.c
Split smm-open-ich2 into two files:
[netwatch.git] / tools / smram-linux-tool.c
diff --git a/tools/smram-linux-tool.c b/tools/smram-linux-tool.c
new file mode 100644 (file)
index 0000000..0d47bb4
--- /dev/null
@@ -0,0 +1,68 @@
+#include <unistd.h>
+#include <getopt.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+static struct option longopts[] = {
+       { "open",       no_argument,    NULL,   'o'     },
+       { "close",      no_argument,    NULL,   'c'     },
+       { "dump",       no_argument,    NULL,   'd'     },
+       { NULL,         0,              NULL,   0       }
+};
+
+#define OP_DUMP 1
+#define OP_SET 2
+
+void usage(int argc, char **argv)
+{
+       printf("Usage: %s [ --dump ] [ --open | --close ]\n",
+               argv[0]);
+       exit(1);
+}
+
+int main(int argc, char **argv)
+{
+       if (geteuid() != 0)
+       {
+               printf("This program must be run as root, dumbass.\n");
+               return 1;
+       }
+       
+       int ch;
+       int op = 0;
+       int do_open = 0;
+       while ((ch = getopt_long(argc, argv, "ocsd:", longopts, NULL)) != -1)
+       {
+               switch (ch)
+               {
+               case 'o':
+                       if (op & OP_SET) usage(argc, argv);
+                       op |= OP_SET;
+                       do_open = 1;
+                       break;
+               case 'c':
+                       if (op & OP_SET) usage(argc, argv);
+                       op |= OP_SET;
+                       break;
+               case 'd':
+                       op |= OP_DUMP;
+                       break;
+               default:
+                       usage(argc, argv);
+               }
+       }
+
+       if (!op) usage(argc, argv);
+
+       if (op & OP_DUMP)
+       {
+               smram_aseg_dump();
+       }
+
+       if (op & OP_SET)
+       {
+               smram_aseg_set_state(do_open);
+       }
+       
+       return 0;
+}
This page took 0.022986 seconds and 4 git commands to generate.