5 #include <sys/socket.h>
9 char *socket_name = "/vsys/fd_fusemount.control";
10 unsigned int arg_length = 128;
12 void send_argument(int control_channel_fd, const char *source) {
14 sent=send(control_channel_fd, source, arg_length, 0);
15 if (sent<arg_length) {
16 printf("Error receiving arguments over the control buffer\n");
21 int connect_socket() {
22 int fd = socket( AF_UNIX, SOCK_STREAM, 0 );
23 struct sockaddr_un addr;
24 addr.sun_family = AF_UNIX;
25 strcpy( addr.sun_path, socket_name );
26 int len = strlen(socket_name) + sizeof(addr.sun_family);
27 assert( connect( fd, (struct sockaddr *) &addr, len ) == 0 );
31 int get_magic_fd (char *data) {
35 data[arg_length-1]='\0';
36 ptr = strstr(data,"fd=");
40 // Found two fd= expressions
41 if (strstr(ptr+3,"fd="))
45 sscanf(ptr+3,"%d",&fd);
52 int mount(const char *source, const char *target, const char *filesystemtype,
53 unsigned long mountflags, const void *data) {
54 int fd = connect_socket();
55 int old_fuse_fd, new_fuse_fd;
59 send_argument(fd, source);
60 send_argument(fd, target );
61 send_argument(fd, filesystemtype );
62 send_argument(fd, data );
64 old_fuse_fd = get_magic_fd (data);
67 if (old_fuse_fd == -1) {
68 printf ("Reroutemount: Could not identify FUSE fd: %d\n", old_fuse_fd);
72 send_fd(fd, old_fuse_fd);
73 new_fuse_fd=receive_fd(fd);
75 if (new_fuse_fd == -1) {
76 printf ("Reroutemount: Fusemount returned bad fd: %d\n", new_fuse_fd);
80 if( dup2(new_fuse_fd, old_fuse_fd ) != new_fuse_fd ) {
81 printf ("Could not duplicate returned file descriptor\n");