Thanks to visit codestin.com
Credit goes to github.com

Skip to content

daemon: Implement e2fsck -n flag (as FORCENO option) #201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions daemon/ext2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand All @@ -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);

Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions docs/guestfs-release-notes-1.56.pod
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ The C<fstrim> 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<e2fsck> API has a new C<FORCENO> option enabling use of
the command line I<-n> flag.

=begin comment

=head2 Tools
Expand Down
20 changes: 15 additions & 5 deletions generator/actions_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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"), [];
Expand Down Expand Up @@ -6683,7 +6683,7 @@ The usage of this device, for example C<filesystem> or C<raid>.

{ 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<device>.
Expand All @@ -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<forceall> option.
This option may not be specified at the same time as the C<forceall>
or C<forceno> options.

=item C<forceall>

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<correct> option.
This option may not be specified at the same time as the C<correct>
or C<forceno> options.

=item C<forceno>

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<correct>
or C<forceall> options.

=back" };

Expand Down