12 #include "mount_util.h" 28 #include <sys/mount.h> 29 #include <sys/param.h> 32 #define umount2(mnt, flags) unmount(mnt, (flags == 2) ? MNT_FORCE : 0) 36 #define mtab_needs_update(mnt) 0 38 static int mtab_needs_update(
const char *mnt)
44 if (strncmp(mnt, _PATH_MOUNTED, strlen(mnt)) == 0 &&
45 _PATH_MOUNTED[strlen(mnt)] ==
'/')
55 res = lstat(_PATH_MOUNTED, &stbuf);
63 if (S_ISLNK(stbuf.st_mode))
70 res = access(_PATH_MOUNTED, W_OK);
71 err = (res == -1) ? errno : 0;
83 static int add_mount(
const char *progname,
const char *fsname,
84 const char *mnt,
const char *type,
const char *opts)
91 sigemptyset(&blockmask);
92 sigaddset(&blockmask, SIGCHLD);
93 res = sigprocmask(SIG_BLOCK, &blockmask, &oldmask);
95 fprintf(stderr,
"%s: sigprocmask: %s\n", progname, strerror(errno));
101 fprintf(stderr,
"%s: fork: %s\n", progname, strerror(errno));
107 sigprocmask(SIG_SETMASK, &oldmask, NULL);
109 if(setuid(geteuid()) == -1) {
110 fprintf(stderr,
"%s: setuid: %s\n", progname, strerror(errno));
115 execle(
"/bin/mount",
"/bin/mount",
"--no-canonicalize",
"-i",
116 "-f",
"-t", type,
"-o", opts, fsname, mnt, NULL, &env);
117 fprintf(stderr,
"%s: failed to execute /bin/mount: %s\n",
118 progname, strerror(errno));
121 res = waitpid(res, &status, 0);
123 fprintf(stderr,
"%s: waitpid: %s\n", progname, strerror(errno));
129 sigprocmask(SIG_SETMASK, &oldmask, NULL);
134 int fuse_mnt_add_mount(
const char *progname,
const char *fsname,
135 const char *mnt,
const char *type,
const char *opts)
137 if (!mtab_needs_update(mnt))
140 return add_mount(progname, fsname, mnt, type, opts);
143 static int exec_umount(
const char *progname,
const char *rel_mnt,
int lazy)
150 sigemptyset(&blockmask);
151 sigaddset(&blockmask, SIGCHLD);
152 res = sigprocmask(SIG_BLOCK, &blockmask, &oldmask);
154 fprintf(stderr,
"%s: sigprocmask: %s\n", progname, strerror(errno));
160 fprintf(stderr,
"%s: fork: %s\n", progname, strerror(errno));
166 sigprocmask(SIG_SETMASK, &oldmask, NULL);
168 if(setuid(geteuid()) == -1) {
169 fprintf(stderr,
"%s: setuid: %s\n", progname, strerror(errno));
175 execle(
"/bin/umount",
"/bin/umount",
"-i", rel_mnt,
178 execle(
"/bin/umount",
"/bin/umount",
"-i", rel_mnt,
181 fprintf(stderr,
"%s: failed to execute /bin/umount: %s\n",
182 progname, strerror(errno));
185 res = waitpid(res, &status, 0);
187 fprintf(stderr,
"%s: waitpid: %s\n", progname, strerror(errno));
194 sigprocmask(SIG_SETMASK, &oldmask, NULL);
199 int fuse_mnt_umount(
const char *progname,
const char *abs_mnt,
200 const char *rel_mnt,
int lazy)
204 if (!mtab_needs_update(abs_mnt)) {
205 res = umount2(rel_mnt, lazy ? 2 : 0);
207 fprintf(stderr,
"%s: failed to unmount %s: %s\n",
208 progname, abs_mnt, strerror(errno));
212 return exec_umount(progname, rel_mnt, lazy);
215 static int remove_mount(
const char *progname,
const char *mnt)
222 sigemptyset(&blockmask);
223 sigaddset(&blockmask, SIGCHLD);
224 res = sigprocmask(SIG_BLOCK, &blockmask, &oldmask);
226 fprintf(stderr,
"%s: sigprocmask: %s\n", progname, strerror(errno));
232 fprintf(stderr,
"%s: fork: %s\n", progname, strerror(errno));
238 sigprocmask(SIG_SETMASK, &oldmask, NULL);
240 if(setuid(geteuid()) == -1) {
241 fprintf(stderr,
"%s: setuid: %s\n", progname, strerror(errno));
246 execle(
"/bin/umount",
"/bin/umount",
"--no-canonicalize",
"-i",
247 "--fake", mnt, NULL, &env);
248 fprintf(stderr,
"%s: failed to execute /bin/umount: %s\n",
249 progname, strerror(errno));
252 res = waitpid(res, &status, 0);
254 fprintf(stderr,
"%s: waitpid: %s\n", progname, strerror(errno));
260 sigprocmask(SIG_SETMASK, &oldmask, NULL);
264 int fuse_mnt_remove_mount(
const char *progname,
const char *mnt)
266 if (!mtab_needs_update(mnt))
269 return remove_mount(progname, mnt);
272 char *fuse_mnt_resolve_path(
const char *progname,
const char *orig)
279 const char *toresolv;
282 fprintf(stderr,
"%s: invalid mountpoint '%s'\n", progname,
289 fprintf(stderr,
"%s: failed to allocate memory\n", progname);
295 for (end = copy + strlen(copy) - 1; end > copy && *end ==
'/'; end --);
299 tmp = strrchr(copy,
'/');
308 if (strcmp(lastcomp,
".") == 0 || strcmp(lastcomp,
"..") == 0) {
315 if (realpath(toresolv, buf) == NULL) {
316 fprintf(stderr,
"%s: bad mount point %s: %s\n", progname, orig,
321 if (lastcomp == NULL)
324 dst = (
char *) malloc(strlen(buf) + 1 + strlen(lastcomp) + 1);
326 unsigned buflen = strlen(buf);
327 if (buflen && buf[buflen-1] ==
'/')
328 sprintf(dst,
"%s%s", buf, lastcomp);
330 sprintf(dst,
"%s/%s", buf, lastcomp);
335 fprintf(stderr,
"%s: failed to allocate memory\n", progname);
339 int fuse_mnt_check_fuseblk(
void)
342 FILE *f = fopen(
"/proc/filesystems",
"r");
346 while (fgets(buf,
sizeof(buf), f))
347 if (strstr(buf,
"fuseblk\n")) {