From 298c9c2f2e7cbe4250d054d2e0f4bef007a940ac Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Fri, 12 Mar 2010 19:18:20 -0500 Subject: [PATCH] e2fsck: Make the -n always open the file system read-only 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" --- e2fsck/e2fsck.8.in | 11 +---------- e2fsck/unix.c | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/e2fsck/e2fsck.8.in b/e2fsck/e2fsck.8.in index a970173..3fb15e6 100644 --- a/e2fsck/e2fsck.8.in +++ b/e2fsck/e2fsck.8.in @@ -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 diff --git a/e2fsck/unix.c b/e2fsck/unix.c index 6248958..49e9008 100644 --- a/e2fsck/unix.c +++ b/e2fsck/unix.c @@ -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], '?'); -- 1.8.3.1