linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fuse2fs: open read-only when image is not writable
@ 2025-10-17 21:11 Dave Dykstra
  2025-10-17 23:32 ` Darrick J. Wong
  0 siblings, 1 reply; 2+ messages in thread
From: Dave Dykstra @ 2025-10-17 21:11 UTC (permalink / raw)
  To: linux-ext4; +Cc: Dave Dykstra, Dave Dykstra

This opens the image read-only when the image is not writable. If it is then found that a journal recovery is needed, an error is returned then.

The ret value is set to 2 after the option checks so that if there's an error resulting in "goto out" it won't print an error about unrecognized options.

Also submitted as PR https://github.com/tytso/e2fsprogs/pull/250
for the issue https://github.com/tytso/e2fsprogs/issues/244.

Replaces 
  https://lore.kernel.org/linux-ext4/20251016200206.3035-1-dave.dykstra@cern.ch/
  https://lore.kernel.org/linux-ext4/175798064776.350013.6744611652039454651.stgit@frogsfrogsfrogs/

Signed-off-by: Dave Dykstra <2129743+DrDaveD@users.noreply.github.com>
---
 misc/fuse2fs.c | 32 ++++++++++++++++++++++++++++----
 1 file changed, 28 insertions(+), 4 deletions(-)

diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index cb5620c7..6a107d2b 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -4696,9 +4696,24 @@ 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)) {
+			if (fctx.ro) {
+				dbg_printf(&fctx, "%s: %s\n", __func__,
+ _("Permission denied with writable, trying without.\n"));
+			} else {
+				dbg_printf(&fctx, "%s: %s\n", __func__,
+ _("No write access, opening read-only.\n"));
+				fctx.ro = 1;
+			}
+			flags &= ~EXT2_FLAG_RW;
+			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;
+		}
 	}
 	fctx.fs = global_fs;
 	global_fs->priv_data = &fctx;
@@ -4741,6 +4756,8 @@ int main(int argc, char *argv[])
 		goto out;
 	}
 
+	ret = 2;
+
 	if (global_fs->super->s_state & EXT2_ERROR_FS) {
 		err_printf(&fctx, "%s\n",
  _("Errors detected; running e2fsck is required."));
@@ -4760,6 +4777,11 @@ int main(int argc, char *argv[])
  _("Mounting read-only without recovering journal."));
 			fctx.ro = 1;
 			global_fs->flags &= ~EXT2_FLAG_RW;
+		} else if (fctx.ro && !(flags & EXT2_FLAG_RW)) {
+			err_printf(&fctx, "%s\n",
+ _("Journal needs recovery but filesystem could not be opened read-write."));
+			err_printf(&fctx, "%s\n", _("Please run e2fsck -fy."));
+			goto out;
 		} else {
 			log_printf(&fctx, "%s\n", _("Recovering journal."));
 			err = ext2fs_run_ext3_journal(&global_fs);
@@ -4833,8 +4855,10 @@ int main(int argc, char *argv[])
 	if (fctx.no_default_opts == 0)
 		fuse_opt_add_arg(&args, extra_args);
 
-	if (fctx.ro)
+	if (fctx.ro) {
+		/* This is in case ro was implied above and not passed in */
 		fuse_opt_add_arg(&args, "-oro");
+	}
 
 	if (fctx.fakeroot) {
 #ifdef HAVE_MOUNT_NODEV
-- 
2.43.5


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] fuse2fs: open read-only when image is not writable
  2025-10-17 21:11 [PATCH] fuse2fs: open read-only when image is not writable Dave Dykstra
@ 2025-10-17 23:32 ` Darrick J. Wong
  0 siblings, 0 replies; 2+ messages in thread
From: Darrick J. Wong @ 2025-10-17 23:32 UTC (permalink / raw)
  To: Dave Dykstra, Theodore Ts'o; +Cc: linux-ext4, Dave Dykstra

On Fri, Oct 17, 2025 at 04:11:30PM -0500, Dave Dykstra wrote:
> This opens the image read-only when the image is not writable. If it is then found that a journal recovery is needed, an error is returned then.
> 
> The ret value is set to 2 after the option checks so that if there's an error resulting in "goto out" it won't print an error about unrecognized options.
> 
> Also submitted as PR https://github.com/tytso/e2fsprogs/pull/250
> for the issue https://github.com/tytso/e2fsprogs/issues/244.
> 
> Replaces 
>   https://lore.kernel.org/linux-ext4/20251016200206.3035-1-dave.dykstra@cern.ch/
>   https://lore.kernel.org/linux-ext4/175798064776.350013.6744611652039454651.stgit@frogsfrogsfrogs/
> 
> Signed-off-by: Dave Dykstra <2129743+DrDaveD@users.noreply.github.com>

Please slow down and give me a chance to reshuffle and QA my existing
fixes for the problems you've complained about.

--D

> ---
>  misc/fuse2fs.c | 32 ++++++++++++++++++++++++++++----
>  1 file changed, 28 insertions(+), 4 deletions(-)
> 
> diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
> index cb5620c7..6a107d2b 100644
> --- a/misc/fuse2fs.c
> +++ b/misc/fuse2fs.c
> @@ -4696,9 +4696,24 @@ 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)) {
> +			if (fctx.ro) {
> +				dbg_printf(&fctx, "%s: %s\n", __func__,
> + _("Permission denied with writable, trying without.\n"));
> +			} else {
> +				dbg_printf(&fctx, "%s: %s\n", __func__,
> + _("No write access, opening read-only.\n"));
> +				fctx.ro = 1;
> +			}
> +			flags &= ~EXT2_FLAG_RW;
> +			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;
> +		}
>  	}
>  	fctx.fs = global_fs;
>  	global_fs->priv_data = &fctx;
> @@ -4741,6 +4756,8 @@ int main(int argc, char *argv[])
>  		goto out;
>  	}
>  
> +	ret = 2;
> +
>  	if (global_fs->super->s_state & EXT2_ERROR_FS) {
>  		err_printf(&fctx, "%s\n",
>   _("Errors detected; running e2fsck is required."));
> @@ -4760,6 +4777,11 @@ int main(int argc, char *argv[])
>   _("Mounting read-only without recovering journal."));
>  			fctx.ro = 1;
>  			global_fs->flags &= ~EXT2_FLAG_RW;
> +		} else if (fctx.ro && !(flags & EXT2_FLAG_RW)) {
> +			err_printf(&fctx, "%s\n",
> + _("Journal needs recovery but filesystem could not be opened read-write."));
> +			err_printf(&fctx, "%s\n", _("Please run e2fsck -fy."));
> +			goto out;
>  		} else {
>  			log_printf(&fctx, "%s\n", _("Recovering journal."));
>  			err = ext2fs_run_ext3_journal(&global_fs);
> @@ -4833,8 +4855,10 @@ int main(int argc, char *argv[])
>  	if (fctx.no_default_opts == 0)
>  		fuse_opt_add_arg(&args, extra_args);
>  
> -	if (fctx.ro)
> +	if (fctx.ro) {
> +		/* This is in case ro was implied above and not passed in */
>  		fuse_opt_add_arg(&args, "-oro");
> +	}
>  
>  	if (fctx.fakeroot) {
>  #ifdef HAVE_MOUNT_NODEV
> -- 
> 2.43.5
> 
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-10-17 23:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-17 21:11 [PATCH] fuse2fs: open read-only when image is not writable Dave Dykstra
2025-10-17 23:32 ` Darrick J. Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).