aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorMeng Lu Wang <mwang@ddn.com>2025-04-10 16:58:57 +0800
committerBernd Schubert <bernd@bsbernd.com>2025-04-15 20:17:49 +0200
commitd66ca89e86a72fa5ad48d88ef5570062a79397be (patch)
tree0c4efd98acdb5c69b9b4ee24af0357f1b95b4618 /util
parent0d4a6281c297aeb200dc30664372fc252fff0f99 (diff)
downloadlibfuse-d66ca89e86a72fa5ad48d88ef5570062a79397be.tar.gz
mount: Add FUSE_KERN_DEVICE env variable to specify fuse kernel device
For kernel development it might be necessary to load a module with renamed symbols and renamed /dev/<devicenode>. Reason is that for example ubuntu kernels have fuse compiled in and it is not possible to replace it at run time. And fuse might also be used for other file systems - a different device node is then needed. Also consolidate device path handling and remove unnecessary string duplication in mount_fuse() in fusermount.c. Signed-off-by: Meng Lu Wang <mwang@ddn.com>
Diffstat (limited to 'util')
-rw-r--r--util/fusermount.c54
1 files changed, 14 insertions, 40 deletions
diff --git a/util/fusermount.c b/util/fusermount.c
index da6d5f2..68fa31e 100644
--- a/util/fusermount.c
+++ b/util/fusermount.c
@@ -41,6 +41,7 @@
#endif
#define FUSE_COMMFD_ENV "_FUSE_COMMFD"
+#define FUSE_KERN_DEVICE_ENV "FUSE_KERN_DEVICE"
#define FUSE_DEV "/dev/fuse"
@@ -1163,56 +1164,30 @@ static int check_perm(const char **mntp, struct stat *stbuf, int *mountpoint_fd)
return -1;
}
-static int try_open(const char *dev, char **devp, int silent)
-{
- int fd = open(dev, O_RDWR);
- if (fd != -1) {
- *devp = strdup(dev);
- if (*devp == NULL) {
- fprintf(stderr, "%s: failed to allocate memory\n",
- progname);
- close(fd);
- fd = -1;
- }
- } else if (errno == ENODEV ||
- errno == ENOENT)/* check for ENOENT too, for the udev case */
- return -2;
- else if (!silent) {
- fprintf(stderr, "%s: failed to open %s: %s\n", progname, dev,
- strerror(errno));
- }
- return fd;
-}
-
-static int try_open_fuse_device(char **devp)
+static int open_fuse_device(const char *dev)
{
int fd;
drop_privs();
- fd = try_open(FUSE_DEV, devp, 0);
+ fd = open(dev, O_RDWR);
+ if (fd == -1) {
+ if (errno == ENODEV || errno == ENOENT)/* check for ENOENT too, for the udev case */
+ fprintf(stderr,
+ "%s: fuse device %s not found. Kernel module not loaded?\n",
+ progname, dev);
+ else
+ fprintf(stderr,
+ "%s: failed to open %s: %s\n", progname, dev, strerror(errno));
+ }
restore_privs();
return fd;
}
-static int open_fuse_device(char **devp)
-{
- int fd = try_open_fuse_device(devp);
- if (fd >= -1)
- return fd;
-
- fprintf(stderr,
- "%s: fuse device not found, try 'modprobe fuse' first\n",
- progname);
-
- return -1;
-}
-
-
static int mount_fuse(const char *mnt, const char *opts, const char **type)
{
int res;
int fd;
- char *dev;
+ const char *dev = getenv(FUSE_KERN_DEVICE_ENV) ?: FUSE_DEV;
struct stat stbuf;
char *source = NULL;
char *mnt_opts = NULL;
@@ -1221,7 +1196,7 @@ static int mount_fuse(const char *mnt, const char *opts, const char **type)
char *do_mount_opts = NULL;
char *x_opts = NULL;
- fd = open_fuse_device(&dev);
+ fd = open_fuse_device(dev);
if (fd == -1)
return -1;
@@ -1292,7 +1267,6 @@ static int mount_fuse(const char *mnt, const char *opts, const char **type)
out_free:
free(source);
free(mnt_opts);
- free(dev);
free(x_opts);
free(do_mount_opts);