From: Darrick J. Wong Date: Thu, 24 Apr 2025 21:40:31 +0000 (-0700) Subject: fuse2fs: set fuse subtype via argv[0] if possible X-Git-Tag: v1.47.3-rc1~101 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=13e365bbfdd97cc086ee9e33cb42f514d8a415ac;p=thirdparty%2Fe2fsprogs.git fuse2fs: set fuse subtype via argv[0] if possible If argv[0] ends in "ext[0-9]", set the fuse subtype string to this value. This enables us to place fuse2fs at some place in the filesystem like /sbin/mount.ext2 and have /proc/mounts report the filesystem type as "fuse.ext2". This is fairly boring, but it'll make it easier to test things in fstests. Signed-off-by: Darrick J. Wong Link: https://lore.kernel.org/r/174553064709.1160289.11028230202411857669.stgit@frogsfrogsfrogs Signed-off-by: Theodore Ts'o --- diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c index 1029f215..9ffc47ce 100644 --- a/misc/fuse2fs.c +++ b/misc/fuse2fs.c @@ -26,6 +26,7 @@ #endif #include #include +#include #ifdef __SET_FOB_FOR_FUSE # error Do not set magic value __SET_FOB_FOR_FUSE!!!! #endif @@ -3812,6 +3813,23 @@ static int fuse2fs_opt_proc(void *data, const char *arg, return 1; } +static const char *get_subtype(const char *argv0) +{ + size_t argvlen = strlen(argv0); + + if (argvlen < 4) + goto out_default; + + if (argv0[argvlen - 4] == 'e' && + argv0[argvlen - 3] == 'x' && + argv0[argvlen - 2] == 't' && + isdigit(argv0[argvlen - 1])) + return &argv0[argvlen - 4]; + +out_default: + return "ext4"; +} + int main(int argc, char *argv[]) { struct fuse_args args = FUSE_ARGS_INIT(argc, argv); @@ -3960,8 +3978,9 @@ int main(int argc, char *argv[]) get_random_bytes(&fctx.next_generation, sizeof(unsigned int)); /* Set up default fuse parameters */ - snprintf(extra_args, BUFSIZ, "-okernel_cache,subtype=ext4," + snprintf(extra_args, BUFSIZ, "-okernel_cache,subtype=%s," "fsname=%s,attr_timeout=0" FUSE_PLATFORM_OPTS, + get_subtype(argv[0]), fctx.device); if (fctx.no_default_opts == 0) fuse_opt_add_arg(&args, extra_args);