fsck.f2fs: allow --dry-run to check readonly mounted fs
authorChao Yu <yuchao0@huawei.com>
Mon, 24 Feb 2020 11:31:15 +0000 (19:31 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Mon, 24 Feb 2020 22:01:53 +0000 (14:01 -0800)
As Ondřej Jirman <megi@xff.cz> reported:

I was trying to run: fsck.f2fs --dry-run /dev/mmcblk0p2 on a RO mounted device,
and fsck refuses to run. Strace shows that it tries to open the block device
with O_EXCL even in RO mode, which will always fail if the block device
is mounted.

fsck.f2fs --dry-run /dev/mmcblk0p2
Info: Dry run
Info: Mounted device!
Info: Check FS only on RO mounted device
Error: Failed to open the device!

I suggest not using O_EXCL for --dry-run check.

Let's change to allow --dry-run to check readonly mounted fs.

Reported-by: Ondřej Jirman <megi@xff.cz>
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
lib/libf2fs.c

index d527d68..5c064c8 100644 (file)
@@ -907,7 +907,8 @@ int get_device_info(int i)
                        return -1;
                }
 
-               if (S_ISBLK(stat_buf->st_mode) && !c.force && c.func != DUMP) {
+               if (S_ISBLK(stat_buf->st_mode) &&
+                               !c.force && c.func != DUMP && !c.dry_run) {
                        fd = open(dev->path, O_RDWR | O_EXCL);
                        if (fd < 0)
                                fd = open_check_fs(dev->path, O_EXCL);