Whamcloud - gitweb
Change resize2fs open modes for mounted and unmounted filesystems
authorTheodore Ts'o <tytso@mit.edu>
Sun, 19 Mar 2006 01:03:47 +0000 (20:03 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 19 Mar 2006 01:03:47 +0000 (20:03 -0500)
If the filesystem is mounted, open it in read-only mode since the userspace
program should not try to modify it directly.  If the filesystem is not mounted,
open it in exclusive mode to avoid potential problems (such as someone
trying to mount the filesystem while it is being resized).

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
resize/ChangeLog
resize/main.c

index 07ca8f4..6b727e9 100644 (file)
@@ -1,3 +1,12 @@
+2006-03-18  Theodore Ts'o  <tytso@mit.edu>
+
+       * main.c (main): If the filesystem is mounted, open it in
+               read-only mode since the userspace program should not try
+               to modify it directly.  If the filesystem is not mounted,
+               open it in exclusive mode to avoid potential problems
+               (such as someone trying to mount the filesystem while it
+               is being resized).
+
 2006-03-17  Theodore Ts'o  <tytso@mit.edu>
 
        * resize2fs.8.in: Update manpage to document that that resize2fs
index d6ddaa7..e202c5f 100644 (file)
@@ -102,6 +102,7 @@ int main (int argc, char ** argv)
        int             flags = 0;
        int             flush = 0;
        int             force = 0;
+       int             io_flags = 0;
        int             fd, ret;
        blk_t           new_size = 0;
        blk_t           max_size = 0;
@@ -234,7 +235,9 @@ int main (int argc, char ** argv)
        } else 
                io_ptr = unix_io_manager;
 
-       retval = ext2fs_open2(device_name, io_options, EXT2_FLAG_RW, 
+       if (!(mount_flags & EXT2_MF_MOUNTED))
+               io_flags = EXT2_FLAG_RW | EXT2_FLAG_EXCLUSIVE;
+       retval = ext2fs_open2(device_name, io_options, io_flags, 
                              0, 0, io_ptr, &fs);
        if (retval) {
                com_err (program_name, retval, _("while trying to open %s"),