From 298c9c2f2e7cbe4250d054d2e0f4bef007a940ac Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Fri, 12 Mar 2010 19:18:20 -0500 Subject: 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/unix.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'e2fsck/unix.c') diff --git a/e2fsck/unix.c b/e2fsck/unix.c index 62489580..49e90085 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], '?'); -- cgit v1.2.3