From a4b0c77de08fca142ae22c74b3317930af404baa Mon Sep 17 00:00:00 2001 From: Miklos Szeredi Date: Fri, 19 Apr 2002 15:57:02 +0000 Subject: [PATCH] interface cleanup --- include/fuse.h | 23 ++++++++++++----------- lib/helper.c | 43 +++++++++++++++++++++++++------------------ 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/include/fuse.h b/include/fuse.h index ea28d0d..b9e7962 100644 --- a/include/fuse.h +++ b/include/fuse.h @@ -100,6 +100,18 @@ struct fuse_context { extern "C" { #endif +/* + * Create a FUSE mountpoint + * + * Returns a control file descriptor suitable for passing to + * fuse_new() + * + * @param mountpoint the mount point path + * @param mount arguments (passed to the fusermount program) + * @return the control file descriptor on success, -1 on failure + */ +int fuse_mount(const char *mountpoint, const char *mount_args); + /** * Create a new FUSE filesystem. * @@ -180,17 +192,6 @@ struct fuse_context *fuse_get_context(struct fuse *f); */ void fuse_main(int argc, char *argv[], const struct fuse_operations *op); -/* - * Spawn an I/O slave, creating an fd suitable for passing to fuse_new() - * - * This spawns fusermount, and then a small message tosser process to - * allow access to fuse_new() and fuse_loop() without the limitations - * of reexecuting the main FUSE process and destroying stdin. - * - * @param mountpoint a char pointer to the requested mountpoint - */ -int fuse_mount_ioslave(char *mountpoint); - /* ----------------------------------------------------------- * * Advanced API for event handling, don't worry about this... * * ----------------------------------------------------------- */ diff --git a/lib/helper.c b/lib/helper.c index c7c48ae..ff59f4a 100644 --- a/lib/helper.c +++ b/lib/helper.c @@ -41,7 +41,7 @@ static void fuse_unmount() system(getenv(FUSE_UMOUNT_CMD_ENV)); } -static int fuse_mount(int *argcp, char **argv) +static int fuse_mount_obsolete(int *argcp, char **argv) { char *isreexec = getenv(FUSE_MOUNTED_ENV); @@ -111,9 +111,15 @@ int receive_fd(int fd) { return *(int*)CMSG_DATA(cmsg); } -int fuse_mount_ioslave(char *mountpoint) { +int fuse_mount(const char *mountpoint, const char *mount_args) +{ int fds[2], pid; + int rv, fd; char env[10]; + + /* FIXME: parse mount_args (or just pass it to fusermount ???) */ + mount_args = mount_args; + if(socketpair(PF_UNIX,SOCK_DGRAM,0,fds)) { fprintf(stderr,"fuse: failed to socketpair()\n"); return -1; @@ -125,22 +131,23 @@ int fuse_mount_ioslave(char *mountpoint) { close(fds[1]); return -1; } - if(pid) { - int rv, fd = fds[1]; - close(fds[0]); - while((rv = receive_fd(fd)) < 0) - sleep(1); - close(fd); - while(wait(NULL) != pid); /* bury zombie */ - return rv; + if(pid == 0) { + close(fds[1]); + fcntl(fds[0],F_SETFD,0); + snprintf(env,sizeof(env),"%i",fds[0]); + setenv("_FUSE_IOSLAVE_FD",env,1); + execlp("fusermount","fusermount",mountpoint,"fuse_ioslave",NULL); + fprintf(stderr,"fuse: failed to exec fusermount\n"); + exit(1); } - close(fds[1]); - fcntl(fds[0],F_SETFD,0); - snprintf(env,sizeof(env),"%i",fds[0]); - setenv("_FUSE_IOSLAVE_FD",env,1); - execlp("fusermount","fusermount",mountpoint,"fuse_ioslave",NULL); - fprintf(stderr,"fuse: failed to exec fusermount\n"); - exit(1); + + fd = fds[1]; + close(fds[0]); + while((rv = receive_fd(fd)) < 0) + sleep(1); + close(fd); + while(wait(NULL) != pid); /* bury zombie */ + return rv; } static void exit_handler() @@ -180,7 +187,7 @@ void fuse_main(int argc, char *argv[], const struct fuse_operations *op) int multithreaded; struct fuse *fuse; - fd = fuse_mount(&argc, argv); + fd = fuse_mount_obsolete(&argc, argv); if(fd == -1) exit(1); -- 2.30.2