(no commit message)
authorSapan Bhatia <sapanb@cs.princeton.edu>
Wed, 25 Mar 2009 18:35:50 +0000 (18:35 +0000)
committerSapan Bhatia <sapanb@cs.princeton.edu>
Wed, 25 Mar 2009 18:35:50 +0000 (18:35 +0000)
fuse/fdpass.c [moved from fuse/stolen_from_fuse.c with 56% similarity]
fuse/fdpass.h [new file with mode: 0644]
fuse/reroutemount.c
fuse/stolen_from_fuse.h [deleted file]

similarity index 56%
rename from fuse/stolen_from_fuse.c
rename to fuse/fdpass.c
index 87fef01..5548064 100644 (file)
@@ -1,3 +1,6 @@
+// Modified version of library functions in FUSE
+//
+
 #include <assert.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -6,16 +9,8 @@
 #include <sys/mount.h>
 #include <sys/socket.h>
 #include <sys/un.h>
-#include "stolen_from_fuse.h"
-
-// Most of this code is stolen from FUSE 2.7.4
 
-/** Function to pass a file descriptor over a UNIX socket.
-  * 
-  * Sends the file descriptor fd over the channel sock_fd.
-  *
-  ***/
-int rrm_send_fd(int sock_fd, int fd)
+int send_fd(int sock_fd, int fd)
 {
        int retval;
        struct msghdr msg;
@@ -56,7 +51,7 @@ int rrm_send_fd(int sock_fd, int fd)
  * >= 0         => fd
  * -1   => error
  */
-int rrm_receive_fd(int fd)
+int receive_fd(int fd)
 {
        struct msghdr msg;
        struct iovec iov;
@@ -96,67 +91,3 @@ int rrm_receive_fd(int fd)
        return *(int*)CMSG_DATA(cmsg);
 }
 
-int rrm_fuse_mnt_umount(const char *progname, const char *mnt, int lazy)
-{
-       int res;
-       int status;
-       
-       res = umount2(mnt, lazy ? 2 : 0);
-       if (res == -1)
-         fprintf(stderr, "%s: failed to unmount %s: %s\n",
-                 progname, mnt, strerror(errno));
-       return res;
-
-}
-
-static int rrm_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, "failed to allocate memory\n" );
-                               
-                       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, "failed to open %s: %s\n", dev,
-                       strerror(errno));
-       }
-       return fd;
-}
-
-static int rrm_try_open_fuse_device(char **devp)
-{
-       int fd;
-       int err;
-
-       //drop_privs();
-       fd = rrm_try_open(FUSE_DEV_NEW, devp, 0);
-       //restore_privs();
-       if (fd >= 0)
-               return fd;
-
-       err = fd;
-       fd = rrm_try_open(FUSE_DEV_OLD, devp, 1);
-       if (fd >= 0)
-               return fd;
-
-       return err;
-}
-
-int rrm_open_fuse_device(char **devp)
-{
-       int fd = rrm_try_open_fuse_device(devp);
-       if (fd >= -1)
-               return fd;
-
-       fprintf(stderr,
-               "fuse device not found, try 'modprobe fuse' first\n");
-
-       return -1;
-}
diff --git a/fuse/fdpass.h b/fuse/fdpass.h
new file mode 100644 (file)
index 0000000..f00a6fb
--- /dev/null
@@ -0,0 +1,5 @@
+// Modified version of library functions in FUSE
+//
+int send_fd(int sock_fd, int fd);
+int receive_fd(int fd);
+
index 9bb8b60..6a4469d 100644 (file)
@@ -9,7 +9,7 @@
 char *socket_name = "/vsys/fd_fusemount.control";
 unsigned int arg_length = 128;
 
-void send_argument(int control_channel_fd, char *source) {
+void send_argument(int control_channel_fd, const char *source) {
     int sent;
     sent=send(control_channel_fd, source, arg_length, 0);
     if (sent<arg_length) {
@@ -99,17 +99,17 @@ int mount(const char *source, const char *target, const char *filesystemtype,
 
   old_fuse_fd = get_magic_fd (data);
 
-  send_fd(fd, old_fuse_fd);
 
-  if (fuse_fd == -1) {
-      printf ("Reroutemount: Could not identify FUSE fd: %d\n", fuse_fd);
+  if (old_fuse_fd == -1) {
+      printf ("Reroutemount: Could not identify FUSE fd: %d\n", old_fuse_fd);
       exit(1);
   }
 
+  send_fd(fd, old_fuse_fd);
   new_fuse_fd=receive_fd(fd);
 
   if (new_fuse_fd == -1) {
-      printf ("Reroutemount: Fusemount returned bad fd: %d\n", fuse_fd);
+      printf ("Reroutemount: Fusemount returned bad fd: %d\n", new_fuse_fd);
       exit(1);
   }
 
@@ -124,6 +124,7 @@ int mount(const char *source, const char *target, const char *filesystemtype,
 }
 
 int execv( const char *path, char *const argv[] ) {
+  int fd;
 
   if( strstr( path, "fusermount" ) == NULL ) {
     return execv( path, argv );
@@ -146,10 +147,9 @@ int execv( const char *path, char *const argv[] ) {
   }
 
   // Have root do any fusermounts we need done
-  int fd = connect_socket();
+  fd = connect_socket();
 
   do_umount( argv, n, fd );
-
   exit(0);
 
 }
diff --git a/fuse/stolen_from_fuse.h b/fuse/stolen_from_fuse.h
deleted file mode 100644 (file)
index 2ade06c..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-#define FUSE_DEV_OLD "/proc/fs/fuse/dev"
-#define FUSE_DEV_NEW "/dev/fuse"
-
-int rrm_receive_fd(int fd);
-int rrm_send_fd(int sock_fd, int fd);
-int rrm_open_fuse_device(char **devp);
-int rrm_fuse_mnt_umount(const char *progname, const char *mnt, int lazy);
-