]> git.neil.brown.name Git - lafs-utils.git/commitdiff
Make write_* subcommands for a common 'write'.
authorNeilBrown <neilb@suse.de>
Sat, 19 Mar 2011 08:45:27 +0000 (19:45 +1100)
committerNeilBrown <neilb@suse.de>
Sat, 19 Mar 2011 08:45:27 +0000 (19:45 +1100)
Signed-off-by: NeilBrown <neilb@suse.de>
tools/lafs.c

index 12a9cc363d694aae42bf7e87accef08f29508aab..e3158607004dd823a2b03056c5f1dd2e1d4b6e86 100644 (file)
@@ -968,6 +968,25 @@ static void c_add_device(struct state *st, void **args)
 
 }
 
+/****** WRITE *****/
+static struct cmd write_cmds[];
+
+static char help_write[] = "Write content of various structures";
+static struct args args_write[] = {
+       { "STRUCT", subcommand, -1, {write_cmds}, "Structure type to write"},
+       TERMINAL_ARG
+};
+static void c_write(struct state *st, void **args)
+{
+       struct cmd *c = args[1];
+       if (!c) {
+               printf("write: Please give a structure to write\n");
+               return;
+       }
+
+       c->cmd(st, args);
+}
+
 /****** WRITE_DEV ******/
 static char help_write_dev[] = "Write devices blocks to one or all devices";
 static struct args args_write_dev[] = {
@@ -979,13 +998,13 @@ static void c_write_dev(struct state *st, void **args)
 {
        struct lafs_device *dev;
        int found = 0;
-       if (!args[1] && !args[2]) {
+       if (!args[2] && !args[3]) {
                printf("write dev: no device given for writing\n");
                return;
        }
 
        for (dev = st->lafs->devs; dev; dev = dev->next) {
-               if (args[2] || strcmp(dev->name, (char*)args[1]) == 0) {
+               if (args[3] || strcmp(dev->name, (char*)args[2]) == 0) {
                        int err = lafs_write_dev(dev);
                        found = 1;
                        if (err)
@@ -997,11 +1016,11 @@ static void c_write_dev(struct state *st, void **args)
        }
        if (found)
                return;
-       if (args[2])
+       if (args[3])
                printf("write dev: no devices exist to write to.\n");
        else
                printf("write dev: %s is not a registered device in this LaFS.\n",
-                      (char*)args[1]);
+                      (char*)args[2]);
 }
 
 /****** WRITE_STATE ******/
@@ -1043,6 +1062,14 @@ static void c_write_checkpoint(struct state *st, void **args)
                       (unsigned long long) st->lafs->seq);
 }
 
+#define WCMD(x) {#x, c_write_##x, args_write_##x, help_write_##x}
+static struct cmd write_cmds[] = {
+       WCMD(checkpoint),
+       WCMD(dev),
+       WCMD(state),
+       { NULL, NULL, NULL, NULL}
+};
+
 /****** LOAD_DEV ******/
 static char help_load_dev[] = "Allow access to LaFS filesystem stored on given device";
 static struct args args_load_dev[] = {
@@ -1365,9 +1392,7 @@ static struct cmd lafs_cmds[] = {
        CMD(reset),
        CMD(show),
        CMD(store),
-       CMD(write_checkpoint),
-       CMD(write_dev),
-       CMD(write_state),
+       CMD(write),
        { NULL, NULL, NULL, NULL}
 };