From: NeilBrown Date: Sat, 19 Mar 2011 08:45:27 +0000 (+1100) Subject: Make write_* subcommands for a common 'write'. X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=772b88b5d156c1a59030c2125bb41352ec0833b4;p=lafs-utils.git Make write_* subcommands for a common 'write'. Signed-off-by: NeilBrown --- diff --git a/tools/lafs.c b/tools/lafs.c index 12a9cc3..e315860 100644 --- a/tools/lafs.c +++ b/tools/lafs.c @@ -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} };