5 #include <sys/socket.h>
9 char *socket_name = "/vsys/fd_fusemount.control";
11 unsigned int arg_length = 128;
13 void send_argument(int control_channel_fd, const char *source) {
15 sent=send(control_channel_fd, source, arg_length, 0);
16 if (sent<arg_length) {
17 printf("Error receiving arguments over the control buffer\n");
22 int connect_socket() {
23 int fd = socket( AF_UNIX, SOCK_STREAM, 0 );
24 struct sockaddr_un addr;
25 addr.sun_family = AF_UNIX;
26 strcpy( addr.sun_path, socket_name );
27 int len = strlen(socket_name) + sizeof(addr.sun_family);
28 printf("Connecting to %s\n", socket_name);
29 assert( connect( fd, (struct sockaddr *) &addr, len ) == 0 );
33 int get_magic_fd (char *data) {
37 data[arg_length-1]='\0';
38 ptr = strstr(data,"fd=");
42 // Found two fd= expressions
43 if (strstr(ptr+3,"fd="))
47 sscanf(ptr+3,"%d",&fd);
54 int mount(const char *source, const char *target, const char *filesystemtype,
55 unsigned long mountflags, const void *data) {
56 int fd = connect_socket();
57 int old_fuse_fd, new_fuse_fd;
62 send_argument(fd, source);
63 send_argument(fd, target );
64 send_argument(fd, filesystemtype );
65 send_argument(fd, data );
67 old_fuse_fd = get_magic_fd (data);
70 if (old_fuse_fd == -1) {
71 printf ("Reroutemount: Could not identify FUSE fd: %d\n", old_fuse_fd);
75 send_fd(fd, old_fuse_fd);
76 new_fuse_fd=receive_fd(fd);
78 if (new_fuse_fd == -1) {
79 printf ("Reroutemount: Fusemount returned bad fd: %d\n", new_fuse_fd);
83 if( (dupfd=dup2(new_fuse_fd, old_fuse_fd )) != old_fuse_fd ) {
84 printf ("Could not duplicate returned file descriptor: %d\n",dupfd);