From 2e14e0c8cc5bc61ffacd380a981808194e9c7f84 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Sat, 18 Mar 2006 20:01:09 -0500 Subject: [PATCH] Change e2fsck to open non-mounted filesystems in exclusive mode Thanks to Andreas Dilger for this idea. If the filesystem is not mounted, e2fsck will open it in exclusive mode to prevent the a confused/careless system administrator from mounting the filesystem while the filesystem check is taking place, which could cause all sorts of problems. Signed-off-by: "Theodore Ts'o" --- e2fsck/ChangeLog | 6 ++++++ e2fsck/unix.c | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/e2fsck/ChangeLog b/e2fsck/ChangeLog index 7facefa..dee2992 100644 --- a/e2fsck/ChangeLog +++ b/e2fsck/ChangeLog @@ -1,3 +1,9 @@ +2006-03-18 Theodore Ts'o + + * unix.c (main): If the filesystem is not mounted, open the + filesystem in exclusive mode (to prevent 2.6 kernels from + mounting the filesystem while it is being checked). + 2006-03-10 Theodore Ts'o * e2fsck.h, journal.c (e2fsck_fix_ext3_journal_hint), diff --git a/e2fsck/unix.c b/e2fsck/unix.c index b3db14c..d2bc594 100644 --- a/e2fsck/unix.c +++ b/e2fsck/unix.c @@ -910,6 +910,8 @@ restart: flags = 0; if ((ctx->options & E2F_OPT_READONLY) == 0) flags |= EXT2_FLAG_RW; + if ((ctx->mount_flags & EXT2_MF_MOUNTED) == 0) + flags |= EXT2_FLAG_EXCLUSIVE; if (ctx->superblock && ctx->blocksize) { retval = ext2fs_open2(ctx->filesystem_name, ctx->io_options, @@ -961,6 +963,9 @@ restart: "r/o" : "r/w"); else if (retval == ENXIO) printf(_("Possibly non-existent or swap device?\n")); + else if (retval == EBUSY) + printf(_("Filesystem mounted or opened exclusively " + "by another program?\n")); #ifdef EROFS else if (retval == EROFS) printf(_("Disk write-protected; use the -n option " -- 1.8.3.1