Re: [PATCH] fuse2fs: open read-only when ro option and image non-writable

Dave Dykstra
2025-10-17T20:14:56Z

On Fri, Oct 17, 2025 at 12:24:56PM -0700, Darrick J. Wong wrote:
> On Thu, Oct 16, 2025 at 03:02:06PM -0500, Dave Dykstra wrote:
...
> > diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
> > index cb5620c7..2ae2fc1a 100644
> > --- a/misc/fuse2fs.c
> > +++ b/misc/fuse2fs.c
> > @@ -4696,9 +4696,19 @@ int main(int argc, char *argv[])
> > 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."));
> > - goto out;
> > + if (((err == EACCES) || (err == EPERM)) && fctx.ro) {
>
> This is not correct. mount(8) for the kernel ext4 driver responds to
> the block device being readonly by retrying with an ro mount. The user
> is not required to specify 'ro':
>
> # blockdev --setro/ dev/sda
> # strace -e mount mount /dev/sda /mnt
> 40677<mount> 12:19:36 (+ 0.000102) mount("/dev/sda", "/mnt", "ext4", 0, NULL) = -1 EACCES (Permission denied)
> 40677<mount> 12:19:36 (+ 0.000285) mount("/dev/sda", "/mnt", "ext4", MS_RDONLY, NULL) = 0

Ok then, I'll change that.

...
> > fctx.fs = global_fs;
> > global_fs->priv_data = &fctx;
> > @@ -4741,6 +4751,8 @@ int main(int argc, char *argv[])
> > goto out;
> > }
> >
> > + ret = 4;
>
> Why 4? Is this an internal mount bug?

I was just guessing; I didn't know what the bits meant. Where are they
documented? All I knew was that it needed to not include the "& 1" bit
which was included with "ret = 3" because that printed an erroneous
error just after the "out" label.

Dave