5 #include <sys/socket.h>
7 #include "stolen_from_fuse.h"
9 char *socket_name = "/vsys/fd_fusemount.control";
11 int connect_socket() {
12 int fd = socket( AF_UNIX, SOCK_STREAM, 0 );
13 struct sockaddr_un addr;
14 addr.sun_family = AF_UNIX;
15 strcpy( addr.sun_path, socket_name );
16 int len = strlen(socket_name) + sizeof(addr.sun_family);
17 assert( connect( fd, (struct sockaddr *) &addr, len ) == 0 );
21 void do_umount( char *const argv[], int n, int fd ) {
25 sprintf( buf, "%08x\n", n );
26 write( fd, buf, strlen(buf) );
30 for( i = 0; i < n; i++ ) {
31 assert( strlen(argv[i]) < 1024 );
32 sprintf( buf, "%s\n", argv[i] );
33 write( fd, buf, strlen(buf) );
37 int n2 = read( fd, inbuf, 10 );
44 int umount2( const char *mnt, int flags ) {
46 int fd = connect_socket();
49 argv[0] = "fusermount";
53 do_umount( (char **const) argv, 3, fd );
59 int mount(const char *source, const char *target, const char *filesystemtype,
60 unsigned long mountflags, const void *data) {
62 int fd = connect_socket();
65 sprintf( buf, "%08x\n", 0 );
66 write( fd, buf, strlen(buf) );
68 sprintf( buf, "%s\n%s\n%s\n%ld\n%s\n", source, target, filesystemtype,
70 write( fd, buf, strlen(buf) );
73 int n = read( fd, inbuf, 9 );
77 assert( sscanf( inbuf, "%08x\n", &r ) == 1);
85 fuse_fd = receive_fd(fd);
87 // what was the old fd?
90 int s = sscanf( data, "fd=%d,%s", &old_fd, extra );
91 assert( dup2( fuse_fd, old_fd ) == old_fd );
100 int execv( const char *path, char *const argv[] ) {
102 if( strstr( path, "fusermount" ) == NULL ) {
103 return execv( path, argv );
106 // also make sure this is an unmount . . .
110 while( arg != NULL ) {
111 if( strcmp( arg, "-u" ) == 0 ) {
119 return execv( path, argv );
122 // Have root do any fusermounts we need done
123 int fd = connect_socket();
125 do_umount( argv, n, fd );