Whamcloud - gitweb
e2fsck: Make the -n always open the file system read-only
authorTheodore Ts'o <tytso@mit.edu>
Sat, 13 Mar 2010 00:18:20 +0000 (19:18 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 15 Mar 2010 04:14:12 +0000 (00:14 -0400)
A user was surprised when -n -D caused the file system to be opened
read/write, and then outsmarted himself when e2fsck asked the question:

   WARNING!!!  Running e2fsck on a mounted filesystem may cause
   SEVERE filesystem damage.

   Do you really want to continue (y/n)?

This is partially our fault for not documenting the fact that -D
overrode opening the filesystem read-write.  But the bottom line is it
much safer if -n *always* opens the file system read-only, so there
can be no confusion.  This means that we have to disable certain
combination of options, such as "-n -c", "-n -l", and "-n -L", and
"-n -D", but the utility of these combinations is pretty low, and
is more than offset by making e2fsck idiot-proof.

Addresses-Launchpad-Bug: #537483

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
e2fsck/e2fsck.8.in
e2fsck/unix.c

index a970173..3fb15e6 100644 (file)
@@ -242,16 +242,7 @@ in the file are added to the bad blocks list.)
 Open the filesystem read-only, and assume an answer of `no' to all
 questions.  Allows
 .B e2fsck
-to be used non-interactively.  (Note: if the 
-.BR \-c ,
-.BR \-l ,
-or
-.B \-L
-options are specified in addition to the 
-.B \-n
-option, then the filesystem will be opened read-write, to permit the
-bad-blocks list to be updated.  However, no other changes will be made
-to the filesystem.)  This option
+to be used non-interactively.  This option
 may not be specified at the same time as the 
 .B \-p
 or
index 6248958..49e9008 100644 (file)
@@ -789,8 +789,23 @@ static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx)
                return 0;
        if (optind != argc - 1)
                usage(ctx);
-       if ((ctx->options & E2F_OPT_NO) && !bad_blocks_file &&
-           !cflag && !(ctx->options & E2F_OPT_COMPRESS_DIRS))
+       if ((ctx->options & E2F_OPT_NO) &&
+           (ctx->options & E2F_OPT_COMPRESS_DIRS)) {
+               com_err(ctx->program_name, 0,
+                       _("The -n and -D options are incompatible."));
+               fatal_error(ctx, 0);
+       }
+       if ((ctx->options & E2F_OPT_NO) && cflag) {
+               com_err(ctx->program_name, 0,
+                       _("The -n and -c options are incompatible."));
+               fatal_error(ctx, 0);
+       }
+       if ((ctx->options & E2F_OPT_NO) && bad_blocks_file) {
+               com_err(ctx->program_name, 0,
+                       _("The -n and -l/-L options are incompatible."));
+               fatal_error(ctx, 0);
+       }
+       if (ctx->options & E2F_OPT_NO)
                ctx->options |= E2F_OPT_READONLY;
 
        ctx->io_options = strchr(argv[optind], '?');