1 /* Adaptation of Jeremy Stribling's version of the script to work with Vsys */
9 #include <sys/socket.h>
13 void remove_string( char *data, char *string ) {
14 char *pos = strstr( data, string );
16 char *comma = strchr( pos, ',' );
18 char *endpos = pos - 1;
25 strcpy( tmp, comma+1 );
31 int do_mount( int control_channel ) {
33 int n = read( control_channel, buf, 1024 );
38 unsigned long mountflags;
41 int r = sscanf( buf, "%s\n%s\n%s\n%ld\n%s\n", source, target, fstype,
44 assert( r == 5 ); // shouldn't be an assert
46 int s = mount( source, target, fstype, mountflags, data );
48 // TODO: should probably make sure this is for a fuse filesystem type . . .
50 if( s != 0 && errno == EINVAL ) {
51 // replace fd with a new one
52 remove_string( data, "fd" );
55 fd = open_fuse_device(&dev);
56 char *end = data+strlen(data);
57 if( strlen(data) != 0 ) {
61 sprintf( end, "fd=%d", fd );
63 s = mount( source, target, fstype, mountflags, data );
69 sprintf( outbuf, "%08x\n", errno );
71 sprintf( outbuf, "%08x\n", fd );
73 write( control_channel, outbuf, strlen(outbuf) );
77 // now we have to sendmsg it back
79 int r = send_fd(control_channel, fd);
83 int x = read(control_channel, outbuf, 1 );
93 int do_umount( int control_channel, int num ) {
99 char *argbuf = (char *) malloc(sizeof(char)*(1024*num+1));
100 const char *args[num+1];
103 // read all of the arguments
107 int n = read( control_channel, argbuf, 1024*num+1 );
108 assert( n < 1024*num+1 ); // no assert here
110 while( num_left > 0 ) {
112 if( sscanf( argbuf, "%s\n", arg ) != 1 ) {
115 int len = strlen(arg);
116 char *a = malloc( sizeof(char)*(strlen(arg)+1) );
118 if( strcmp( a, "-o" ) == 0 ) {
121 args[args_index] = a;
127 } while( args_index < num );
131 // The last argument is the mountpoint, that's really all we care about
132 printf( "umounting %s\n", args[num-1] );
133 int r = fuse_mnt_umount("reroutemount_server", args[num-1], 0 );
135 // write the status (probably not necessary)
138 sprintf( outbuf, "%d\n", errno );
140 sprintf( outbuf, "%d\n", 0 );
142 write( control_channel, outbuf, strlen(outbuf) );
146 int main( int argc, char **argv ) {
149 printf("This script is invoked by vsys\n");
153 sscanf(argv[2],"%d",&control_channel);
157 int n = read( control_channel, buf, 9 );
160 close(control_channel);
165 if( sscanf( buf, "%08x\n", &num ) != 1 ) {
166 close(control_channel);
171 do_mount( control_channel );
173 do_umount( control_channel, num );
175 close(control_channel);