2
FUSE: Filesystem in Userspace
3
Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
5
This program can be distributed under the terms of the GNU LGPL.
6
See the file COPYING.LIB.
9
#include "mount_util.h"
20
int fuse_mnt_add_mount(const char *progname, const char *fsname,
21
const char *mnt, const char *type, const char *opts)
28
fprintf(stderr, "%s: fork: %s\n", progname, strerror(errno));
32
char templ[] = "/tmp/fusermountXXXXXX";
38
* hide in a directory, where mount isn't able to resolve
39
* fsname as a valid path
43
fprintf(stderr, "%s: failed to create temporary directory\n",
48
fprintf(stderr, "%s: failed to chdir to %s: %s\n",
49
progname, tmp, strerror(errno));
53
execl("/bin/mount", "/bin/mount", "-i", "-f", "-t", type, "-o", opts,
55
fprintf(stderr, "%s: failed to execute /bin/mount: %s\n", progname,
59
res = waitpid(res, &status, 0);
61
fprintf(stderr, "%s: waitpid: %s\n", progname, strerror(errno));
70
int fuse_mnt_umount(const char *progname, const char *mnt, int lazy)
77
fprintf(stderr, "%s: fork: %s\n", progname, strerror(errno));
82
execl("/bin/umount", "/bin/umount", "-i", mnt, lazy ? "-l" : NULL,
84
fprintf(stderr, "%s: failed to execute /bin/umount: %s\n", progname,
88
res = waitpid(res, &status, 0);
90
fprintf(stderr, "%s: waitpid: %s\n", progname, strerror(errno));
99
char *fuse_mnt_resolve_path(const char *progname, const char *orig)
106
const char *toresolv;
109
fprintf(stderr, "%s: invalid mountpoint '%s'\n", progname, orig);
115
fprintf(stderr, "%s: failed to allocate memory\n", progname);
121
for (end = copy + strlen(copy) - 1; end > copy && *end == '/'; end --);
125
tmp = strrchr(copy, '/');
134
if (strcmp(lastcomp, ".") == 0 || strcmp(lastcomp, "..") == 0) {
141
if (realpath(toresolv, buf) == NULL) {
142
fprintf(stderr, "%s: bad mount point %s: %s\n", progname, orig,
147
if (lastcomp == NULL)
150
dst = (char *) malloc(strlen(buf) + 1 + strlen(lastcomp) + 1);
152
unsigned buflen = strlen(buf);
153
if (buflen && buf[buflen-1] == '/')
154
sprintf(dst, "%s%s", buf, lastcomp);
156
sprintf(dst, "%s/%s", buf, lastcomp);
161
fprintf(stderr, "%s: failed to allocate memory\n", progname);
165
int fuse_mnt_check_empty(const char *progname, const char *mnt,
166
mode_t rootmode, off_t rootsize)
170
if (S_ISDIR(rootmode)) {
172
DIR *dp = opendir(mnt);
174
fprintf(stderr, "%s: failed to open mountpoint for reading: %s\n",
175
progname, strerror(errno));
178
while ((ent = readdir(dp)) != NULL) {
179
if (strcmp(ent->d_name, ".") != 0 &&
180
strcmp(ent->d_name, "..") != 0) {
190
fprintf(stderr, "%s: mountpoint is not empty\n", progname);
191
fprintf(stderr, "%s: if you are sure this is safe, use the 'nonempty' mount option\n", progname);
197
int fuse_mnt_check_fuseblk(void)
200
FILE *f = fopen("/proc/filesystems", "r");
204
while (fgets(buf, sizeof(buf), f))
205
if (strstr(buf, "fuseblk\n")) {