From 38a0966da88da6d199eb1da37456b4c33f4901da Mon Sep 17 00:00:00 2001 From: Wanlong Gao Date: Sat, 14 Jan 2012 00:22:09 +0800 Subject: NEW API: add a new api e2fsck m: Wanlong Gao Add a new api e2fsck with two options: correct: same as '-p' option of e2fsck forceall: same as '-y' option of e2fsck Thanks for Rich's idea. v1->v2: use optargs_bitmask v2->v3: change the optargs_bitmask check Signed-off-by: Wanlong Gao --- daemon/ext2.c | 49 ++++++++++++++++++++++++++++++++++++++++++ generator/generator_actions.ml | 24 +++++++++++++++++++++ src/MAX_PROC_NR | 2 +- 3 files changed, 74 insertions(+), 1 deletion(-) diff --git a/daemon/ext2.c b/daemon/ext2.c index c280ca2e..5f6ee5ac 100644 --- a/daemon/ext2.c +++ b/daemon/ext2.c @@ -293,6 +293,55 @@ do_resize2fs_M (const char *device) return 0; } +int +do_e2fsck (const char *device, + int correct, + int forceall) +{ + const char *argv[MAX_ARGS]; + char *err; + size_t i = 0; + int r; + char prog[] = "e2fsck"; + + if (e2prog (prog) == -1) + return -1; + + /* Default if not selected. */ + if (!(optargs_bitmask & GUESTFS_E2FSCK_CORRECT_BITMASK)) + correct = 0; + if (!(optargs_bitmask & GUESTFS_E2FSCK_FORCEALL_BITMASK)) + forceall = 0; + + if (correct && forceall) { + reply_with_error("Only one of the options may be specified"); + return -1; + } + + + ADD_ARG (argv, i, prog); + ADD_ARG (argv, i, "-f"); + + if (correct) + ADD_ARG (argv, i, "-p"); + + if (forceall) + ADD_ARG (argv, i, "-y"); + + ADD_ARG (argv, i, device); + ADD_ARG (argv, i, NULL); + + r = commandv (NULL, &err, argv); + if (r == -1 || r >= 2) { + reply_with_error ("%s", err); + free (err); + return -1; + } + + free (err); + return 0; +} + int do_e2fsck_f (const char *device) { diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml index fb82bb6b..2e40c390 100644 --- a/generator/generator_actions.ml +++ b/generator/generator_actions.ml @@ -3454,6 +3454,8 @@ are activated or deactivated."); ["umount"; "/"]; ["lvresize"; "/dev/VG/LV"; "20"]; ["e2fsck_f"; "/dev/VG/LV"]; + ["e2fsck"; "/dev/VG/LV"; "true"; "false"]; + ["e2fsck"; "/dev/VG/LV"; "false"; "true"]; ["resize2fs"; "/dev/VG/LV"]; ["mount_options"; ""; "/dev/VG/LV"; "/"]; ["cat"; "/new"]], "test content"); @@ -6595,6 +6597,28 @@ The filesystem type or RAID of this device. The usage of this device, for example C or C. +=back"); + + ("e2fsck", (RErr, [Device "device"], [OBool "correct"; OBool "forceall"]), 304, [], + [], (* lvresize tests this *) + "check an ext2/ext3 filesystem", + "\ +This runs the ext2/ext3 filesystem checker on C. +Force to check the filesystem even if it appears to be clean. + +=over 4 + +=item C + +Automatically repair the file system. This option will cause e2fsck to automatically +fix any filesystem problems that can be safely fixed without human intervention. +This option may not be specified at the same time as the C option. + +=item C + +Assume an answer of 'yes' to all questions; allows e2fsck to be used non-interactively. +This option may not be specified at the same time as the C option. + =back"); ] diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index 81606223..873b744b 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -303 +304 -- cgit