]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
resize2fs: open device read-only when -P is passed
authorMichael Hudson-Doyle <michael.hudson@ubuntu.com>
Thu, 26 May 2022 01:08:28 +0000 (13:08 +1200)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 11 Aug 2022 14:39:48 +0000 (10:39 -0400)
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>
resize/main.c
tests/scripts/resize_test

index d2ba344815cd50bac03d67069683c575f19907bd..a1a1c79a8b2752d1bbb5362185852a53259e7333 100644 (file)
@@ -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;
index fc9d1c246fb3f97b80f09ca23fc2d59a7f8453fc..a000c85e5941372009d764c54091d60f67b9e406 100755 (executable)
@@ -60,6 +60,14 @@ rm -f $OUT_TMP
 echo $FSCK -fy $TMPFILE >> $LOG 2>&1 
 $FSCK -fy $TMPFILE >> $LOG 2>&1 
 
+chmod u-w $TMPFILE
+echo $RESIZE2FS -P $TMPFILE >> $LOG 2>&1
+if ! $RESIZE2FS -P $TMPFILE >> $LOG 2>&1
+then
+       return 1
+fi
+chmod u+w $TMPFILE
+
 echo $RESIZE2FS $RESIZE2FS_OPTS -d $DBG_FLAGS $TMPFILE $SIZE_2 >> $LOG 2>&1
 if ! $RESIZE2FS $RESIZE2FS_OPTS -d $DBG_FLAGS $TMPFILE $SIZE_2 >> $LOG 2>&1
 then