]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
fuse2fs: mount norecovery if main block device is readonly
authorDarrick J. Wong <djwong@kernel.org>
Thu, 28 Aug 2025 17:30:43 +0000 (10:30 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Fri, 17 Oct 2025 23:34:22 +0000 (16:34 -0700)
If the main block device is read-only, downgrade the mount to an ro
norecovery mount to match what the kernel does.  This will make
generic/050 somewhat less grouchy.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
misc/fuse2fs.c

index 9922747728a438b65397cfbdf13f3c2150b52e5e..83886faf2eada80b20f96fd4b3a2a609748a22bc 100644 (file)
@@ -4773,6 +4773,19 @@ int main(int argc, char *argv[])
                flags |= EXT2_FLAG_DIRECT_IO;
        err = ext2fs_open2(fctx.device, options, flags, 0, 0, unix_io_manager,
                           &global_fs);
+       if (err == EPERM || err == EACCES) {
+               /*
+                * Source device cannot be opened for write.  Under these
+                * circumstances, mount(8) will try again with a ro mount,
+                * and the kernel will open the block device readonly.
+                */
+               log_printf(&fctx, "%s\n",
+ _("WARNING: source write-protected, mounted read-only."));
+               flags &= ~EXT2_FLAG_RW;
+               fctx.ro = 1;
+               err = ext2fs_open2(fctx.device, options, flags, 0, 0,
+                                  unix_io_manager, &global_fs);
+       }
        if (err) {
                err_printf(&fctx, "%s.\n", error_message(err));
                err_printf(&fctx, "%s\n", _("Please run e2fsck -fy."));