11 #include "fuse_config.h"
12 #include "mount_util.h"
27 #include <sys/mount.h>
28 #include <sys/fsuid.h>
29 #include <sys/socket.h>
30 #include <sys/utsname.h>
35 #define FUSE_COMMFD_ENV "_FUSE_COMMFD"
37 #define FUSE_DEV "/dev/fuse"
40 #define MS_DIRSYNC 128
46 #define MS_PRIVATE (1<<18)
50 #define UMOUNT_DETACH 0x00000002
52 #ifndef UMOUNT_NOFOLLOW
53 #define UMOUNT_NOFOLLOW 0x00000008
56 #define UMOUNT_UNUSED 0x80000000
59 static const char *progname;
61 static int user_allow_other = 0;
62 static int mount_max = 1000;
64 static int auto_unmount = 0;
66 static const char *get_user_name(
void)
68 struct passwd *pw = getpwuid(getuid());
69 if (pw != NULL && pw->pw_name != NULL)
72 fprintf(stderr,
"%s: could not determine username\n", progname);
77 static uid_t oldfsuid;
78 static gid_t oldfsgid;
80 static void drop_privs(
void)
83 oldfsuid = setfsuid(getuid());
84 oldfsgid = setfsgid(getgid());
88 static void restore_privs(
void)
100 static int lock_umount(
void)
102 const char *mtab_lock = _PATH_MOUNTED
".fuselock";
105 struct stat mtab_stat;
108 if (lstat(_PATH_MOUNTED, &mtab_stat) == 0 && S_ISLNK(mtab_stat.st_mode))
111 mtablock = open(mtab_lock, O_RDWR | O_CREAT, 0600);
112 if (mtablock == -1) {
113 fprintf(stderr,
"%s: unable to open fuse lock file: %s\n",
114 progname, strerror(errno));
117 res = lockf(mtablock, F_LOCK, 0);
119 fprintf(stderr,
"%s: error getting lock: %s\n", progname,
128 static void unlock_umount(
int mtablock)
133 res = lockf(mtablock, F_ULOCK, 0);
135 fprintf(stderr,
"%s: error releasing lock: %s\n",
136 progname, strerror(errno));
142 static int add_mount(
const char *source,
const char *mnt,
const char *type,
145 return fuse_mnt_add_mount(progname, source, mnt, type, opts);
148 static int may_unmount(
const char *mnt,
int quiet)
152 const char *user = NULL;
156 const char *mtab = _PATH_MOUNTED;
158 user = get_user_name();
162 fp = setmntent(mtab,
"r");
164 fprintf(stderr,
"%s: failed to open %s: %s\n", progname, mtab,
169 uidlen = sprintf(uidstr,
"%u", getuid());
172 while ((entp = getmntent(fp)) != NULL) {
173 if (!found && strcmp(entp->mnt_dir, mnt) == 0 &&
174 (strcmp(entp->mnt_type,
"fuse") == 0 ||
175 strcmp(entp->mnt_type,
"fuseblk") == 0 ||
176 strncmp(entp->mnt_type,
"fuse.", 5) == 0 ||
177 strncmp(entp->mnt_type,
"fuseblk.", 8) == 0)) {
178 char *p = strstr(entp->mnt_opts,
"user=");
180 (p == entp->mnt_opts || *(p-1) ==
',') &&
181 strcmp(p + 5, user) == 0) {
188 strstr(entp->mnt_opts,
"user_id=")) &&
189 (p == entp->mnt_opts ||
191 strncmp(p + 8, uidstr, uidlen) == 0 &&
192 (*(p+8+uidlen) ==
',' ||
193 *(p+8+uidlen) ==
'\0')) {
204 "%s: entry for %s not found in %s\n",
205 progname, mnt, mtab);
236 static int check_is_mount_child(
void *p)
239 const char *last = a[0];
240 const char *mnt = a[1];
241 const char *type = a[2];
243 const char *procmounts =
"/proc/mounts";
249 res = mount(
"",
"/",
"", MS_PRIVATE | MS_REC, NULL);
251 fprintf(stderr,
"%s: failed to mark mounts private: %s\n",
252 progname, strerror(errno));
256 fp = setmntent(procmounts,
"r");
258 fprintf(stderr,
"%s: failed to open %s: %s\n", progname,
259 procmounts, strerror(errno));
264 while (getmntent(fp) != NULL)
268 fp = setmntent(procmounts,
"r");
270 fprintf(stderr,
"%s: failed to open %s: %s\n", progname,
271 procmounts, strerror(errno));
275 res = mount(
".",
"/",
"", MS_BIND | MS_REC, NULL);
277 fprintf(stderr,
"%s: failed to bind parent to /: %s\n",
278 progname, strerror(errno));
283 while ((entp = getmntent(fp)) != NULL) {
288 if (entp->mnt_dir[0] ==
'/' &&
289 strcmp(entp->mnt_dir + 1, last) == 0 &&
290 (!type || strcmp(entp->mnt_type, type) == 0)) {
298 fprintf(stderr,
"%s: %s not mounted\n", progname, mnt);
305 static pid_t clone_newns(
void *a)
308 char *stack = buf + (
sizeof(buf) / 2 - ((
size_t) buf & 15));
311 extern int __clone2(
int (*fn)(
void *),
312 void *child_stack_base,
size_t stack_size,
313 int flags,
void *arg, pid_t *ptid,
314 void *tls, pid_t *ctid);
316 return __clone2(check_is_mount_child, stack,
sizeof(buf) / 2,
317 CLONE_NEWNS, a, NULL, NULL, NULL);
319 return clone(check_is_mount_child, stack, CLONE_NEWNS, a);
323 static int check_is_mount(
const char *last,
const char *mnt,
const char *type)
327 const char *a[3] = { last, mnt, type };
329 pid = clone_newns((
void *) a);
330 if (pid == (pid_t) -1) {
331 fprintf(stderr,
"%s: failed to clone namespace: %s\n",
332 progname, strerror(errno));
335 p = waitpid(pid, &status, __WCLONE);
336 if (p == (pid_t) -1) {
337 fprintf(stderr,
"%s: waitpid failed: %s\n",
338 progname, strerror(errno));
341 if (!WIFEXITED(status)) {
342 fprintf(stderr,
"%s: child terminated abnormally (status %i)\n",
346 if (WEXITSTATUS(status) != 0)
352 static int chdir_to_parent(
char *copy,
const char **lastp)
359 tmp = strrchr(copy,
'/');
360 if (tmp == NULL || tmp[1] ==
'\0') {
361 fprintf(stderr,
"%s: internal error: invalid abs path: <%s>\n",
369 }
else if (tmp[1] !=
'\0') {
379 fprintf(stderr,
"%s: failed to chdir to %s: %s\n",
380 progname, parent, strerror(errno));
384 if (getcwd(buf,
sizeof(buf)) == NULL) {
385 fprintf(stderr,
"%s: failed to obtain current directory: %s\n",
386 progname, strerror(errno));
389 if (strcmp(buf, parent) != 0) {
390 fprintf(stderr,
"%s: mountpoint moved (%s -> %s)\n", progname,
400 static int unmount_fuse_locked(
const char *mnt,
int quiet,
int lazy)
405 int umount_flags = (lazy ? UMOUNT_DETACH : 0) | UMOUNT_NOFOLLOW;
408 res = may_unmount(mnt, quiet);
415 fprintf(stderr,
"%s: failed to allocate memory\n", progname);
420 res = chdir_to_parent(copy, &last);
425 res = umount2(last, umount_flags);
426 if (res == -1 && !quiet) {
427 fprintf(stderr,
"%s: failed to unmount %s: %s\n",
428 progname, mnt, strerror(errno));
438 fprintf(stderr,
"%s: failed to chdir to '/'\n", progname);
442 return fuse_mnt_remove_mount(progname, mnt);
445 static int unmount_fuse(
const char *mnt,
int quiet,
int lazy)
448 int mtablock = lock_umount();
450 res = unmount_fuse_locked(mnt, quiet, lazy);
451 unlock_umount(mtablock);
456 static int count_fuse_fs(
void)
460 const char *mtab = _PATH_MOUNTED;
461 FILE *fp = setmntent(mtab,
"r");
463 fprintf(stderr,
"%s: failed to open %s: %s\n", progname, mtab,
467 while ((entp = getmntent(fp)) != NULL) {
468 if (strcmp(entp->mnt_type,
"fuse") == 0 ||
469 strncmp(entp->mnt_type,
"fuse.", 5) == 0)
478 static int count_fuse_fs(
void)
483 static int add_mount(
const char *source,
const char *mnt,
const char *type,
493 static int unmount_fuse(
const char *mnt,
int quiet,
int lazy)
496 return fuse_mnt_umount(progname, mnt, mnt, lazy);
500 static void strip_line(
char *line)
502 char *s = strchr(line,
'#');
505 for (s = line + strlen(line) - 1;
506 s >= line && isspace((
unsigned char) *s); s--);
508 for (s = line; isspace((
unsigned char) *s); s++);
510 memmove(line, s, strlen(s)+1);
513 static void parse_line(
char *line,
int linenum)
516 if (strcmp(line,
"user_allow_other") == 0)
517 user_allow_other = 1;
518 else if (sscanf(line,
"mount_max = %i", &tmp) == 1)
522 "%s: unknown parameter in %s at line %i: '%s'\n",
523 progname, FUSE_CONF, linenum, line);
526 static void read_conf(
void)
528 FILE *fp = fopen(FUSE_CONF,
"r");
533 while (fgets(line,
sizeof(line), fp) != NULL) {
535 if (line[strlen(line)-1] ==
'\n') {
537 parse_line(line, linenum);
541 }
else if(line[strlen(line)-1] ==
'\n') {
542 fprintf(stderr,
"%s: reading %s: line %i too long\n", progname, FUSE_CONF, linenum);
550 fprintf(stderr,
"%s: reading %s: missing newline at end of file\n", progname, FUSE_CONF);
554 fprintf(stderr,
"%s: reading %s: read failed\n", progname, FUSE_CONF);
558 }
else if (errno != ENOENT) {
559 bool fatal = (errno != EACCES && errno != ELOOP &&
560 errno != ENAMETOOLONG && errno != ENOTDIR &&
562 fprintf(stderr,
"%s: failed to open %s: %s\n",
563 progname, FUSE_CONF, strerror(errno));
569 static int begins_with(
const char *s,
const char *beg)
571 if (strncmp(s, beg, strlen(beg)) == 0)
584 static struct mount_flags mount_flags[] = {
585 {
"rw", MS_RDONLY, 0, 1},
586 {
"ro", MS_RDONLY, 1, 1},
587 {
"suid", MS_NOSUID, 0, 0},
588 {
"nosuid", MS_NOSUID, 1, 1},
589 {
"dev", MS_NODEV, 0, 0},
590 {
"nodev", MS_NODEV, 1, 1},
591 {
"exec", MS_NOEXEC, 0, 1},
592 {
"noexec", MS_NOEXEC, 1, 1},
593 {
"async", MS_SYNCHRONOUS, 0, 1},
594 {
"sync", MS_SYNCHRONOUS, 1, 1},
595 {
"atime", MS_NOATIME, 0, 1},
596 {
"noatime", MS_NOATIME, 1, 1},
597 {
"diratime", MS_NODIRATIME, 0, 1},
598 {
"nodiratime", MS_NODIRATIME, 1, 1},
599 {
"lazytime", MS_LAZYTIME, 1, 1},
600 {
"nolazytime", MS_LAZYTIME, 0, 1},
601 {
"relatime", MS_RELATIME, 1, 1},
602 {
"norelatime", MS_RELATIME, 0, 1},
603 {
"strictatime", MS_STRICTATIME, 1, 1},
604 {
"nostrictatime", MS_STRICTATIME, 0, 1},
605 {
"dirsync", MS_DIRSYNC, 1, 1},
609 static int find_mount_flag(
const char *s,
unsigned len,
int *on,
int *flag)
613 for (i = 0; mount_flags[i].opt != NULL; i++) {
614 const char *opt = mount_flags[i].opt;
615 if (strlen(opt) == len && strncmp(opt, s, len) == 0) {
616 *on = mount_flags[i].on;
617 *flag = mount_flags[i].flag;
618 if (!mount_flags[i].safe && getuid() != 0) {
621 "%s: unsafe option %s ignored\n",
630 static int add_option(
char **optsp,
const char *opt,
unsigned expand)
634 newopts = strdup(opt);
636 unsigned oldsize = strlen(*optsp);
637 unsigned newsize = oldsize + 1 + strlen(opt) + expand + 1;
638 newopts = (
char *) realloc(*optsp, newsize);
640 sprintf(newopts + oldsize,
",%s", opt);
642 if (newopts == NULL) {
643 fprintf(stderr,
"%s: failed to allocate memory\n", progname);
650 static int get_mnt_opts(
int flags,
char *opts,
char **mnt_optsp)
655 if (!(flags & MS_RDONLY) && add_option(mnt_optsp,
"rw", 0) == -1)
658 for (i = 0; mount_flags[i].opt != NULL; i++) {
659 if (mount_flags[i].on && (flags & mount_flags[i].flag) &&
660 add_option(mnt_optsp, mount_flags[i].opt, 0) == -1)
664 if (add_option(mnt_optsp, opts, 0) == -1)
667 l = strlen(*mnt_optsp);
668 if ((*mnt_optsp)[l-1] ==
',')
669 (*mnt_optsp)[l-1] =
'\0';
671 const char *user = get_user_name();
675 if (add_option(mnt_optsp,
"user=", strlen(user)) == -1)
677 strcat(*mnt_optsp, user);
682 static int opt_eq(
const char *s,
unsigned len,
const char *opt)
684 if(strlen(opt) == len && strncmp(s, opt, len) == 0)
690 static int get_string_opt(
const char *s,
unsigned len,
const char *opt,
694 unsigned opt_len = strlen(opt);
699 *val = (
char *) malloc(len - opt_len + 1);
701 fprintf(stderr,
"%s: failed to allocate memory\n", progname);
708 for (i = 0; i < len; i++) {
709 if (s[i] ==
'\\' && i + 1 < len)
722 static int mount_notrunc(
const char *source,
const char *target,
723 const char *filesystemtype,
unsigned long mountflags,
725 if (strlen(data) > sysconf(_SC_PAGESIZE) - 1) {
726 fprintf(stderr,
"%s: mount options too long\n", progname);
730 return mount(source, target, filesystemtype, mountflags, data);
734 static int do_mount(
const char *mnt,
const char **typep, mode_t rootmode,
735 int fd,
const char *opts,
const char *dev,
char **sourcep,
739 int flags = MS_NOSUID | MS_NODEV;
741 char *mnt_opts = NULL;
745 char *subtype = NULL;
750 optbuf = (
char *) malloc(strlen(opts) + 128);
752 fprintf(stderr,
"%s: failed to allocate memory\n", progname);
756 for (s = opts, d = optbuf; *s;) {
758 const char *fsname_str =
"fsname=";
759 const char *subtype_str =
"subtype=";
760 bool escape_ok = begins_with(s, fsname_str) ||
761 begins_with(s, subtype_str);
762 for (len = 0; s[len]; len++) {
763 if (escape_ok && s[len] ==
'\\' && s[len + 1])
765 else if (s[len] ==
',')
768 if (begins_with(s, fsname_str)) {
769 if (!get_string_opt(s, len, fsname_str, &fsname))
771 }
else if (begins_with(s, subtype_str)) {
772 if (!get_string_opt(s, len, subtype_str, &subtype))
774 }
else if (opt_eq(s, len,
"blkdev")) {
777 "%s: option blkdev is privileged\n",
782 }
else if (opt_eq(s, len,
"auto_unmount")) {
784 }
else if (!opt_eq(s, len,
"nonempty") &&
785 !begins_with(s,
"fd=") &&
786 !begins_with(s,
"rootmode=") &&
787 !begins_with(s,
"user_id=") &&
788 !begins_with(s,
"group_id=")) {
792 if (opt_eq(s, len,
"large_read")) {
793 struct utsname utsname;
795 res = uname(&utsname);
797 sscanf(utsname.release,
"%u.%u",
798 &kmaj, &kmin) == 2 &&
799 (kmaj > 2 || (kmaj == 2 && kmin > 4))) {
800 fprintf(stderr,
"%s: note: 'large_read' mount option is deprecated for %i.%i kernels\n", progname, kmaj, kmin);
804 if (getuid() != 0 && !user_allow_other &&
805 (opt_eq(s, len,
"allow_other") ||
806 opt_eq(s, len,
"allow_root"))) {
807 fprintf(stderr,
"%s: option %.*s only allowed if 'user_allow_other' is set in %s\n", progname, len, s, FUSE_CONF);
811 if (find_mount_flag(s, len, &on, &flag)) {
816 }
else if (opt_eq(s, len,
"default_permissions") ||
817 opt_eq(s, len,
"allow_other") ||
818 begins_with(s,
"max_read=") ||
819 begins_with(s,
"blksize=")) {
824 fprintf(stderr,
"%s: unknown option '%.*s'\n", progname, len, s);
834 res = get_mnt_opts(flags, optbuf, &mnt_opts);
838 sprintf(d,
"fd=%i,rootmode=%o,user_id=%u,group_id=%u",
839 fd, rootmode, getuid(), getgid());
841 source = malloc((fsname ? strlen(fsname) : 0) +
842 (subtype ? strlen(subtype) : 0) + strlen(dev) + 32);
844 type = malloc((subtype ? strlen(subtype) : 0) + 32);
845 if (!type || !source) {
846 fprintf(stderr,
"%s: failed to allocate memory\n", progname);
851 sprintf(type,
"%s.%s", blkdev ?
"fuseblk" :
"fuse", subtype);
853 strcpy(type, blkdev ?
"fuseblk" :
"fuse");
856 strcpy(source, fsname);
858 strcpy(source, subtype ? subtype : dev);
860 res = mount_notrunc(source, mnt, type, flags, optbuf);
861 if (res == -1 && errno == ENODEV && subtype) {
863 strcpy(type, blkdev ?
"fuseblk" :
"fuse");
866 sprintf(source,
"%s#%s", subtype, fsname);
868 strcpy(source, type);
871 res = mount_notrunc(source, mnt, type, flags, optbuf);
873 if (res == -1 && errno == EINVAL) {
875 sprintf(d,
"fd=%i,rootmode=%o,user_id=%u",
876 fd, rootmode, getuid());
877 res = mount_notrunc(source, mnt, type, flags, optbuf);
880 int errno_save = errno;
881 if (blkdev && errno == ENODEV && !fuse_mnt_check_fuseblk())
882 fprintf(stderr,
"%s: 'fuseblk' support missing\n",
885 fprintf(stderr,
"%s: mount failed: %s\n", progname,
886 strerror(errno_save));
891 *mnt_optsp = mnt_opts;
907 static int check_perm(
const char **mntp,
struct stat *stbuf,
int *mountpoint_fd)
910 const char *mnt = *mntp;
911 const char *origmnt = mnt;
912 struct statfs fs_buf;
915 res = lstat(mnt, stbuf);
917 fprintf(stderr,
"%s: failed to access mountpoint %s: %s\n",
918 progname, mnt, strerror(errno));
926 if (S_ISDIR(stbuf->st_mode)) {
930 "%s: failed to chdir to mountpoint: %s\n",
931 progname, strerror(errno));
935 res = lstat(mnt, stbuf);
938 "%s: failed to access mountpoint %s: %s\n",
939 progname, origmnt, strerror(errno));
943 if ((stbuf->st_mode & S_ISVTX) && stbuf->st_uid != getuid()) {
944 fprintf(stderr,
"%s: mountpoint %s not owned by user\n",
949 res = access(mnt, W_OK);
951 fprintf(stderr,
"%s: user has no write access to mountpoint %s\n",
955 }
else if (S_ISREG(stbuf->st_mode)) {
956 static char procfile[256];
957 *mountpoint_fd = open(mnt, O_WRONLY);
958 if (*mountpoint_fd == -1) {
959 fprintf(stderr,
"%s: failed to open %s: %s\n",
960 progname, mnt, strerror(errno));
963 res = fstat(*mountpoint_fd, stbuf);
966 "%s: failed to access mountpoint %s: %s\n",
967 progname, mnt, strerror(errno));
970 if (!S_ISREG(stbuf->st_mode)) {
972 "%s: mountpoint %s is no longer a regular file\n",
977 sprintf(procfile,
"/proc/self/fd/%i", *mountpoint_fd);
981 "%s: mountpoint %s is not a directory or a regular file\n",
992 if (statfs(*mntp, &fs_buf)) {
993 fprintf(stderr,
"%s: failed to access mountpoint %s: %s\n",
994 progname, mnt, strerror(errno));
1003 typeof(fs_buf.f_type) f_type_whitelist[] = {
1033 0x736675005346544e ,
1037 for (i = 0; i <
sizeof(f_type_whitelist)/
sizeof(f_type_whitelist[0]); i++) {
1038 if (f_type_whitelist[i] == fs_buf.f_type)
1042 fprintf(stderr,
"%s: mounting over filesystem type %#010lx is forbidden\n",
1043 progname, (
unsigned long)fs_buf.f_type);
1047 static int try_open(
const char *dev,
char **devp,
int silent)
1049 int fd = open(dev, O_RDWR);
1051 *devp = strdup(dev);
1052 if (*devp == NULL) {
1053 fprintf(stderr,
"%s: failed to allocate memory\n",
1058 }
else if (errno == ENODEV ||
1062 fprintf(stderr,
"%s: failed to open %s: %s\n", progname, dev,
1068 static int try_open_fuse_device(
char **devp)
1073 fd = try_open(FUSE_DEV, devp, 0);
1078 static int open_fuse_device(
char **devp)
1080 int fd = try_open_fuse_device(devp);
1085 "%s: fuse device not found, try 'modprobe fuse' first\n",
1092 static int mount_fuse(
const char *mnt,
const char *opts,
const char **type)
1098 char *source = NULL;
1099 char *mnt_opts = NULL;
1100 const char *real_mnt = mnt;
1101 int mountpoint_fd = -1;
1103 fd = open_fuse_device(&dev);
1110 if (getuid() != 0 && mount_max != -1) {
1111 int mount_count = count_fuse_fs();
1112 if (mount_count >= mount_max) {
1113 fprintf(stderr,
"%s: too many FUSE filesystems mounted; mount_max=N can be set in %s\n", progname, FUSE_CONF);
1118 res = check_perm(&real_mnt, &stbuf, &mountpoint_fd);
1121 res = do_mount(real_mnt, type, stbuf.st_mode & S_IFMT,
1122 fd, opts, dev, &source, &mnt_opts);
1124 if (mountpoint_fd != -1)
1125 close(mountpoint_fd);
1132 fprintf(stderr,
"%s: failed to chdir to '/'\n", progname);
1136 if (geteuid() == 0) {
1137 res = add_mount(source, mnt, *type, mnt_opts);
1157 static int send_fd(
int sock_fd,
int fd)
1161 struct cmsghdr *p_cmsg;
1163 size_t cmsgbuf[CMSG_SPACE(
sizeof(fd)) /
sizeof(size_t)];
1167 msg.msg_control = cmsgbuf;
1168 msg.msg_controllen =
sizeof(cmsgbuf);
1169 p_cmsg = CMSG_FIRSTHDR(&msg);
1170 p_cmsg->cmsg_level = SOL_SOCKET;
1171 p_cmsg->cmsg_type = SCM_RIGHTS;
1172 p_cmsg->cmsg_len = CMSG_LEN(
sizeof(fd));
1173 p_fds = (
int *) CMSG_DATA(p_cmsg);
1175 msg.msg_controllen = p_cmsg->cmsg_len;
1176 msg.msg_name = NULL;
1177 msg.msg_namelen = 0;
1183 vec.iov_base = &sendchar;
1184 vec.iov_len =
sizeof(sendchar);
1185 while ((retval = sendmsg(sock_fd, &msg, 0)) == -1 && errno == EINTR);
1187 perror(
"sending file descriptor");
1209 static int should_auto_unmount(
const char *mnt,
const char *type)
1218 fprintf(stderr,
"%s: failed to allocate memory\n", progname);
1222 if (chdir_to_parent(copy, &last) == -1)
1224 if (check_is_mount(last, mnt, type) == -1)
1227 fd = open(mnt, O_RDONLY);
1231 result = errno == ENOTCONN;
1238 static void usage(
void)
1240 printf(
"%s: [options] mountpoint\n"
1243 " -V print version\n"
1244 " -o opt[,opt...] mount options\n"
1247 " -z lazy unmount\n",
1252 static void show_version(
void)
1254 printf(
"fusermount3 version: %s\n", PACKAGE_VERSION);
1258 int main(
int argc,
char *argv[])
1266 static int unmount = 0;
1267 static int lazy = 0;
1268 static int quiet = 0;
1271 const char *opts =
"";
1272 const char *type = NULL;
1274 static const struct option long_opts[] = {
1275 {
"unmount", no_argument, NULL,
'u'},
1276 {
"lazy", no_argument, NULL,
'z'},
1277 {
"quiet", no_argument, NULL,
'q'},
1278 {
"help", no_argument, NULL,
'h'},
1279 {
"version", no_argument, NULL,
'V'},
1282 progname = strdup(argc > 0 ? argv[0] :
"fusermount");
1283 if (progname == NULL) {
1284 fprintf(stderr,
"%s: failed to allocate memory\n", argv[0]);
1288 while ((ch = getopt_long(argc, argv,
"hVo:uzq", long_opts,
1320 if (lazy && !unmount) {
1321 fprintf(stderr,
"%s: -z can only be used with -u\n", progname);
1325 if (optind >= argc) {
1326 fprintf(stderr,
"%s: missing mountpoint argument\n", progname);
1328 }
else if (argc > optind + 1) {
1329 fprintf(stderr,
"%s: extra arguments after the mountpoint\n",
1334 origmnt = argv[optind];
1337 mnt = fuse_mnt_resolve_path(progname, origmnt);
1341 fprintf(stderr,
"%s: failed to chdir to '/'\n", progname);
1353 commfd = getenv(FUSE_COMMFD_ENV);
1354 if (commfd == NULL) {
1355 fprintf(stderr,
"%s: old style mounting not supported\n",
1360 fd = mount_fuse(mnt, opts, &type);
1365 res = send_fd(cfd, fd);
1370 if (!auto_unmount) {
1382 fprintf(stderr,
"%s: failed to chdir to '/'\n", progname);
1386 sigfillset(&sigset);
1387 sigprocmask(SIG_BLOCK, &sigset, NULL);
1393 unsigned char buf[16];
1394 int n = recv(cfd, buf,
sizeof(buf), 0);
1405 if (!should_auto_unmount(mnt, type)) {
1411 res = unmount_fuse(mnt, quiet, lazy);
1413 res = umount2(mnt, lazy ? UMOUNT_DETACH : 0);
1414 if (res == -1 && !quiet)
1416 "%s: failed to unmount %s: %s\n",
1417 progname, mnt, strerror(errno));