Whamcloud - gitweb
Change e2fsck to open non-mounted filesystems in exclusive mode
authorTheodore Ts'o <tytso@mit.edu>
Sun, 19 Mar 2006 01:01:09 +0000 (20:01 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 19 Mar 2006 01:01:09 +0000 (20:01 -0500)
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" <tytso@mit.edu>
e2fsck/ChangeLog
e2fsck/unix.c

index 7facefa..dee2992 100644 (file)
@@ -1,3 +1,9 @@
+2006-03-18  Theodore Ts'o  <tytso@mit.edu>
+
+       * 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  <tytso@mit.edu>
 
        * e2fsck.h, journal.c (e2fsck_fix_ext3_journal_hint), 
index b3db14c..d2bc594 100644 (file)
@@ -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 "