lib/mount.c: Restore "subtype#fsname" format for legacy kernel fallback

Commit 50fa7f0bc2 ("Move fuse_mnt_build_{source,type} to mount_util.c"
changed the ENODEV fallback behavior from using
"subtype#fsname" format to just "fsname" for the mount source.

This adds a use_subtype_prefix parameter to fuse_mnt_build_source() to
control whether the legacy "subtype#fsname" format should be used. This
centralizes the source string building logic and avoids code duplication
in the ENODEV fallback paths.

Original behavior (before 50fa7f0bc2):
    if (mo->fsname) {
        if (!mo->blkdev)
            sprintf(source, "%s#%s", mo->subtype, mo->fsname);
    } else {
        strcpy(source, type);
    }

Behavior after 50fa7f0bc2 (unintended change):
    source = fuse_mnt_build_source(mo->fsname, NULL, devname);
    // Returns just fsname, not "subtype#fsname"

Behavior before 50fa7f0bc2 is restored again.

Signed-off-by: Bernd Schubert <bernd@bsbernd.com>
This commit is contained in:
Bernd Schubert
2026-05-25 15:44:15 +02:00
parent e465536dc9
commit 4e0f7cbc43
4 changed files with 24 additions and 12 deletions
+7 -7
View File
@@ -659,7 +659,7 @@ int fuse_kern_do_mount(const char *mnt, struct mount_opts *mo,
int res;
const char *devname = fuse_mnt_get_devname();
res = -ENOMEM;
source = fuse_mnt_build_source(mo->fsname, mo->subtype, devname);
source = fuse_mnt_build_source(mo->fsname, mo->subtype, devname, 0);
type = fuse_mnt_build_type(mo->blkdev, mo->subtype);
if (!type || !source) {
fuse_log(FUSE_LOG_ERR, "%s: failed to allocate memory\n",
@@ -670,16 +670,16 @@ int fuse_kern_do_mount(const char *mnt, struct mount_opts *mo,
res = mount(source, mnt, type, mo->flags, mo->kernel_opts);
if (res == -1 && errno == ENODEV && mo->subtype) {
/* Probably missing subtype support */
/*
* The allocated space by fuse_mnt_build_{source,type}
* might be too small.
*/
free(source);
free(type);
type = fuse_mnt_build_type(mo->blkdev, NULL);
source = fuse_mnt_build_source(mo->fsname, NULL, devname);
if (mo->fsname && !mo->blkdev) {
source = fuse_mnt_build_source(mo->fsname, mo->subtype,
devname, 1);
} else {
source = strdup(type);
}
if (!type || !source) {
fuse_log(FUSE_LOG_ERR,
+1 -1
View File
@@ -353,7 +353,7 @@ int fuse_kern_fsmount(const char *mnt, unsigned long flags, int blkdev,
/* Build type and source strings */
type = fuse_mnt_build_type(blkdev, subtype);
source = fuse_mnt_build_source(fsname, subtype, source_dev);
source = fuse_mnt_build_source(fsname, subtype, source_dev, 0);
err = -ENOMEM;
if (!type || !source) {
fprintf(stderr, "fuse: failed to allocate memory\n");
+15 -3
View File
@@ -536,13 +536,25 @@ const char *fuse_mnt_get_devname(void)
}
char *fuse_mnt_build_source(const char *fsname, const char *subtype,
const char *devname)
const char *devname, int use_subtype_prefix)
{
char *source;
int ret;
ret = asprintf(&source, "%s",
fsname ? fsname : (subtype ? subtype : devname));
if (use_subtype_prefix && fsname && subtype) {
ret = asprintf(&source, "%s#%s", subtype, fsname);
} else {
const char *src_str;
if (fsname)
src_str = fsname;
else if (subtype)
src_str = subtype;
else
src_str = devname;
ret = asprintf(&source, "%s", src_str);
}
if (ret == -1)
return NULL;
+1 -1
View File
@@ -39,7 +39,7 @@ int fuse_mnt_add_mount_helper(const char *mnt, const char *source,
/* Build source and type strings for mounting */
char *fuse_mnt_build_source(const char *fsname, const char *subtype,
const char *devname);
const char *devname, int use_subtype_prefix);
char *fuse_mnt_build_type(int blkdev, const char *subtype);
#endif /* FUSE_MOUNT_UTIL_H_ */