summaryrefslogtreecommitdiff
path: root/resize
diff options
context:
space:
mode:
authorMichael Hudson-Doyle <michael.hudson@ubuntu.com>2022-05-26 13:08:28 +1200
committerTheodore Ts'o <tytso@mit.edu>2022-08-11 10:39:48 -0400
commitca340221b9f324fd5b12be485f729bd5101d5c14 (patch)
tree973fce9afd71d305d0c49333ff2181354b556bfa /resize
parent13f1ce96046fba15d93a90733b791312284fbb62 (diff)
downloade2fsprogs-ca340221b9f324fd5b12be485f729bd5101d5c14.tar.gz
resize2fs: open device read-only when -P is passed
We ran into this because we noticed that resize2fs -P $device was triggering udev events. I added a very simple test that just checks resize2fs -P on a file lacking the w bit succeeds. Signed-off-by: Michael Hudson-Doyle <michael.hudson@ubuntu.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'resize')
-rw-r--r--resize/main.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/resize/main.c b/resize/main.c
index d2ba3448..a1a1c79a 100644
--- a/resize/main.c
+++ b/resize/main.c
@@ -256,6 +256,7 @@ int main (int argc, char ** argv)
int force_min_size = 0;
int print_min_size = 0;
int fd, ret;
+ int open_flags = O_RDWR;
blk64_t new_size = 0;
blk64_t max_size = 0;
blk64_t min_size = 0;
@@ -363,7 +364,10 @@ int main (int argc, char ** argv)
len = 2 * len;
}
- fd = ext2fs_open_file(device_name, O_RDWR, 0);
+ if (print_min_size)
+ open_flags = O_RDONLY;
+
+ fd = ext2fs_open_file(device_name, open_flags, 0);
if (fd < 0) {
com_err("open", errno, _("while opening %s"),
device_name);
@@ -401,7 +405,7 @@ int main (int argc, char ** argv)
#endif
io_ptr = unix_io_manager;
- if (!(mount_flags & EXT2_MF_MOUNTED))
+ if (!(mount_flags & EXT2_MF_MOUNTED) && !print_min_size)
io_flags = EXT2_FLAG_RW | EXT2_FLAG_EXCLUSIVE;
io_flags |= EXT2_FLAG_64BITS | EXT2_FLAG_THREADS;