2
FUSE: Filesystem in Userspace
3
Copyright (C) 2001-2005 Miklos Szeredi <miklos@szeredi.hu>
5
This program can be distributed under the terms of the GNU LGPL.
6
See the file COPYING.LIB.
10
#include "fuse_compat.h"
17
#include <sys/socket.h>
21
#define FUSERMOUNT_PROG "fusermount"
22
#define FUSE_COMMFD_ENV "_FUSE_COMMFD"
29
static int receive_fd(int fd)
36
char ccmsg[CMSG_SPACE(sizeof(connfd))];
46
/* old BSD implementations should use msg_accrights instead of
47
* msg_control; the interface is different. */
48
msg.msg_control = ccmsg;
49
msg.msg_controllen = sizeof(ccmsg);
51
while(((rv = recvmsg(fd, &msg, 0)) == -1) && errno == EINTR);
61
cmsg = CMSG_FIRSTHDR(&msg);
62
if (!cmsg->cmsg_type == SCM_RIGHTS) {
63
fprintf(stderr, "got control message of unknown type %d\n",
67
return *(int*)CMSG_DATA(cmsg);
70
void fuse_unmount(const char *mountpoint)
72
const char *mountprog = FUSERMOUNT_PROG;
73
char umount_cmd[1024];
75
snprintf(umount_cmd, sizeof(umount_cmd) - 1, "%s -u -q -z %s", mountprog,
78
umount_cmd[sizeof(umount_cmd) - 1] = '\0';
82
int fuse_mount(const char *mountpoint, const char *opts)
84
const char *mountprog = FUSERMOUNT_PROG;
89
res = socketpair(PF_UNIX, SOCK_STREAM, 0, fds);
91
perror("fuse: socketpair() failed");
101
perror("fuse: fork() failed");
109
const char *argv[] = {mountprog, opts ? "-o" : mountpoint, opts,
113
fcntl(fds[0], F_SETFD, 0);
114
snprintf(env, sizeof(env), "%i", fds[0]);
115
setenv(FUSE_COMMFD_ENV, env, 1);
116
execvp(mountprog, (char **) argv);
117
perror("fuse: failed to exec fusermount");
122
rv = receive_fd(fds[1]);
124
waitpid(pid, NULL, 0); /* bury zombie */
129
int fuse_mount_compat1(const char *mountpoint, const char *args[])
131
/* just ignore mount args for now */
133
return fuse_mount(mountpoint, NULL);