From 318171c1e27f89ad73e204db21e10a38198f61f5 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Tue, 20 May 2025 08:20:55 +0100 Subject: [PATCH] daemon: Implement e2fsck -n flag (as FORCENO option) Fixes: https://issues.redhat.com/browse/RHEL-92599 --- daemon/ext2.c | 17 ++++++++++++----- docs/guestfs-release-notes-1.56.pod | 3 +++ generator/actions_core.ml | 20 +++++++++++++++----- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/daemon/ext2.c b/daemon/ext2.c index 5a225bd40..3c55b9f8a 100644 --- a/daemon/ext2.c +++ b/daemon/ext2.c @@ -192,7 +192,7 @@ if_not_mounted_run_e2fsck (const char *device) if (!mounted) { optargs_bitmask = GUESTFS_E2FSCK_FORCEALL_BITMASK; - r = do_e2fsck (device, 0, 1); + r = do_e2fsck (device, 0, 1, 0); } return r; @@ -350,7 +350,8 @@ ext_minimum_size (const char *device) int do_e2fsck (const char *device, int correct, - int forceall) + int forceall, + int forceno) { const char *argv[MAX_ARGS]; CLEANUP_FREE char *err = NULL; @@ -362,9 +363,12 @@ do_e2fsck (const char *device, correct = 0; if (!(optargs_bitmask & GUESTFS_E2FSCK_FORCEALL_BITMASK)) forceall = 0; + if (!(optargs_bitmask & GUESTFS_E2FSCK_FORCENO_BITMASK)) + forceno = 0; - if (correct && forceall) { - reply_with_error ("only one of the options 'correct', 'forceall' may be specified"); + if (correct + forceall + forceno > 1) { + reply_with_error ("only one of the options 'correct', 'forceall' " + "or 'forceno' may be specified"); return -1; } @@ -377,6 +381,9 @@ do_e2fsck (const char *device, if (forceall) ADD_ARG (argv, i, "-y"); + if (forceno) + ADD_ARG (argv, i, "-n"); + ADD_ARG (argv, i, device); ADD_ARG (argv, i, NULL); @@ -402,7 +409,7 @@ int do_e2fsck_f (const char *device) { optargs_bitmask = GUESTFS_E2FSCK_CORRECT_BITMASK; - return do_e2fsck (device, 1, 0); + return do_e2fsck (device, 1, 0, 0); } int diff --git a/docs/guestfs-release-notes-1.56.pod b/docs/guestfs-release-notes-1.56.pod index 5005837d2..357ba6ea3 100644 --- a/docs/guestfs-release-notes-1.56.pod +++ b/docs/guestfs-release-notes-1.56.pod @@ -33,6 +33,9 @@ The C API has been modified to work around several issues in upstream and RHEL 9 kernels related to XFS support (Eric Sandeen, Dave Chinner). +The existing C API has a new C option enabling use of +the command line I<-n> flag. + =begin comment =head2 Tools diff --git a/generator/actions_core.ml b/generator/actions_core.ml index 2cb8cc430..0f39fd509 100644 --- a/generator/actions_core.ml +++ b/generator/actions_core.ml @@ -3409,8 +3409,8 @@ are activated or deactivated." }; ["umount"; "/"; "false"; "false"]; ["lvresize"; "/dev/VG/LV"; "20"]; ["e2fsck_f"; "/dev/VG/LV"]; - ["e2fsck"; "/dev/VG/LV"; "true"; "false"]; - ["e2fsck"; "/dev/VG/LV"; "false"; "true"]; + ["e2fsck"; "/dev/VG/LV"; "true"; "false"; "false"]; + ["e2fsck"; "/dev/VG/LV"; "false"; "true"; "false"]; ["resize2fs"; "/dev/VG/LV"]; ["mount"; "/dev/VG/LV"; "/"]; ["cat"; "/new"]], "test content"), []; @@ -6683,7 +6683,7 @@ The usage of this device, for example C or C. { defaults with name = "e2fsck"; added = (1, 15, 17); - style = RErr, [String (Device, "device")], [OBool "correct"; OBool "forceall"]; + style = RErr, [String (Device, "device")], [OBool "correct"; OBool "forceall"; OBool "forceno"]; shortdesc = "check an ext2/ext3 filesystem"; longdesc = "\ This runs the ext2/ext3 filesystem checker on C. @@ -6697,14 +6697,24 @@ 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. +This option may not be specified at the same time as the C +or C options. =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. +This option may not be specified at the same time as the C +or C options. + +=item C + +Open the filesystem readonly and assume an answer of ‘no’ to all +questions; allows e2fsck to be used non-interactively. + +This option may not be specified at the same time as the C +or C options. =back" };