X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=fuse%2Freroutemount.c;h=c1c140b7a1f5cecf201b2404751bca63ced59840;hb=2b07978b1e21113105b6ea76dca1900da83c2dc3;hp=6a4469d5b86fa9a89a29e78fd8f3b482d60e94e7;hpb=280515b790c44566679b0e1271466695f0914132;p=vsys-wrappers.git diff --git a/fuse/reroutemount.c b/fuse/reroutemount.c index 6a4469d..c1c140b 100644 --- a/fuse/reroutemount.c +++ b/fuse/reroutemount.c @@ -4,9 +4,10 @@ #include #include #include -#include "stolen_from_fuse.h" +#include "fdpass.h" char *socket_name = "/vsys/fd_fusemount.control"; + unsigned int arg_length = 128; void send_argument(int control_channel_fd, const char *source) { @@ -17,54 +18,18 @@ void send_argument(int control_channel_fd, const char *source) { exit(1); } } + int connect_socket() { int fd = socket( AF_UNIX, SOCK_STREAM, 0 ); struct sockaddr_un addr; addr.sun_family = AF_UNIX; strcpy( addr.sun_path, socket_name ); int len = strlen(socket_name) + sizeof(addr.sun_family); + printf("Connecting to %s\n", socket_name); assert( connect( fd, (struct sockaddr *) &addr, len ) == 0 ); return fd; } -void do_umount( char *const argv[], int n, int fd ) { - - // write the length - char buf[1024]; - sprintf( buf, "%08x\n", n ); - write( fd, buf, strlen(buf) ); - - // now write each arg - int i; - for( i = 0; i < n; i++ ) { - assert( strlen(argv[i]) < 1024 ); - sprintf( buf, "%s\n", argv[i] ); - write( fd, buf, strlen(buf) ); - } - - char inbuf[10]; - int n2 = read( fd, inbuf, 10 ); - inbuf[n2] = '\0'; - - int r = atoi(inbuf); - -} - -int umount2( const char *mnt, int flags ) { - - int fd = connect_socket(); - - const char *argv[3]; - argv[0] = "fusermount"; - argv[1] = "-u"; - argv[2] = mnt; - - do_umount( (char **const) argv, 3, fd ); - - close(fd); - -} - int get_magic_fd (char *data) { char *ptr; int fd; @@ -85,10 +50,12 @@ int get_magic_fd (char *data) { else return -1; } + int mount(const char *source, const char *target, const char *filesystemtype, unsigned long mountflags, const void *data) { int fd = connect_socket(); int old_fuse_fd, new_fuse_fd; + int dupfd; char buf[1024]; @@ -113,8 +80,8 @@ int mount(const char *source, const char *target, const char *filesystemtype, exit(1); } - if( dup2(new_fuse_fd, old_fuse_fd ) != new_fuse_fd ) { - printf ("Could not duplicate returned file descriptor\n"); + if( (dupfd=dup2(new_fuse_fd, old_fuse_fd )) != old_fuse_fd ) { + printf ("Could not duplicate returned file descriptor: %d\n",dupfd); exit(1); } @@ -122,35 +89,3 @@ int mount(const char *source, const char *target, const char *filesystemtype, return 0; } - -int execv( const char *path, char *const argv[] ) { - int fd; - - if( strstr( path, "fusermount" ) == NULL ) { - return execv( path, argv ); - } - - // also make sure this is an unmount . . . - int n = 0; - char *arg = argv[n]; - int found_u = 0; - while( arg != NULL ) { - if( strcmp( arg, "-u" ) == 0 ) { - found_u = 1; - break; - } - arg = argv[++n]; - } - - if( !found_u ) { - return execv( path, argv ); - } - - // Have root do any fusermounts we need done - fd = connect_socket(); - - do_umount( argv, n, fd ); - exit(0); - -} -