From 9efa71981107145c1c66e8534939ae196763e47e Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Mon, 14 Mar 2011 12:22:17 +1100 Subject: [PATCH] lafs: add write_state command Signed-off-by: NeilBrown --- lib/lafs_write_state.c | 2 +- tools/lafs.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/lafs_write_state.c b/lib/lafs_write_state.c index d564fca..1d091bb 100644 --- a/lib/lafs_write_state.c +++ b/lib/lafs_write_state.c @@ -39,5 +39,5 @@ int lafs_write_state(struct lafs *fs) write(dev->fd, buf, fs->statesize); } } - return 1; + return 0; } diff --git a/tools/lafs.c b/tools/lafs.c index 28e0a6e..4cb06f2 100644 --- a/tools/lafs.c +++ b/tools/lafs.c @@ -995,6 +995,25 @@ static void c_write_dev(struct state *st, void **args) (char*)args[1]); } +/****** WRITE_STATE ******/ +static char help_write_state[] = "Write state blocks to all devices"; +static struct args args_write_state[] = { + TERMINAL_ARG +}; +static void c_write_state(struct state *st, void **args) +{ + if (st->lafs->blocksize == 0) + printf("write state: filesystem is not initialised\n"); + else if (st->lafs->devs == NULL) + printf("write state: No devices exist to write to\n"); + else if (lafs_write_state(st->lafs)) + printf("write state: Error writing a state block\n"); + else if (st->verbose) + printf("%s state blocks written: seq now %llu\n", + (st->lafs->seq & 1) ? "Odd" : "Even", + (unsigned long long) st->lafs->seq); +} + /****** STORE ******/ static char help_store[] = "Create a file in the LaFS from an external file"; static struct args args_store[] = { @@ -1027,6 +1046,7 @@ static struct cmd lafs_cmds[] = { CMD(reset), CMD(store), CMD(write_dev), + CMD(write_state), { NULL, NULL, NULL, NULL} }; -- 2.39.5