From e352b2ad17457306e6c1c0254df53f9c29981438 Mon Sep 17 00:00:00 2001 From: "Darrick J. Wong" Date: Thu, 28 Aug 2025 10:30:43 -0700 Subject: [PATCH] fuse2fs: mount norecovery if main block device is readonly 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" --- misc/fuse2fs.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c index 99227477..83886faf 100644 --- a/misc/fuse2fs.c +++ b/misc/fuse2fs.c @@ -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.")); -- 2.47.3