Change resize2fs open modes for mounted and unmounted filesystems
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>
diff --git a/resize/ChangeLog b/resize/ChangeLog
index 07ca8f4..6b727e9 100644
--- a/resize/ChangeLog
+++ b/resize/ChangeLog
@@ -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
diff --git a/resize/main.c b/resize/main.c
index d6ddaa7..e202c5f 100644
--- a/resize/main.c
+++ b/resize/main.c
@@ -102,6 +102,7 @@
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 @@
} 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"),