Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/autofs/automount.c
Show First 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | |||||
#include <unistd.h> | #include <unistd.h> | ||||
#include "common.h" | #include "common.h" | ||||
#include "mntopts.h" | #include "mntopts.h" | ||||
static int | static int | ||||
unmount_by_statfs(const struct statfs *sb, bool force) | unmount_by_statfs(const struct statfs *sb, bool force) | ||||
{ | { | ||||
int error; | |||||
if ((error = unmount_automount(&sb->f_fsid, force ? MNT_FORCE : 0)) != 0) | |||||
log_warn("cannot unmount %s (FSID:%d:%d)", | |||||
sb->f_mntonname, sb->f_fsid.val[0], sb->f_fsid.val[1]); | |||||
return (error); | |||||
} | |||||
static int | |||||
unmount_by_umount(const fsid_t *fsid, int flags) | |||||
{ | |||||
FILE *f; | |||||
char fsid_str[sizeof(*fsid)*2+1]; | |||||
size_t i; | |||||
/* umount(8) expects the file system ID to be in hexadecimal format */ | |||||
for (i = 0; i < sizeof(*fsid); i++) | |||||
snprintf(fsid_str+(i*2), sizeof(fsid_str) - (i*2), | |||||
"%02x", ((const u_char *)fsid)[i]); | |||||
if (flags & MNT_FORCE) | |||||
f = auto_popen("umount", "-f", fsid_str, NULL); | |||||
else | |||||
f = auto_popen("umount", fsid_str, NULL); | |||||
assert(f != NULL); | |||||
return (auto_pclose(f)); | |||||
} | |||||
/* | |||||
* Unmount a filesystem. Default to umount(8) and fallback to unmount(3). | |||||
*/ | |||||
int | |||||
unmount_automount(const fsid_t *fsid, int flags) | |||||
{ | |||||
int error; | |||||
char *fsid_str; | char *fsid_str; | ||||
int error, ret, flags; | |||||
ret = asprintf(&fsid_str, "FSID:%d:%d", | /* need to find reference where FSID:0:0 is error */ | ||||
sb->f_fsid.val[0], sb->f_fsid.val[1]); | if (fsid->val[0] == 0 || fsid->val[1] == 0) | ||||
if (ret < 0) | return (EACCES); | ||||
/* any debug or warnings will be logged from auto_pclose() */ | |||||
if ((error = unmount_by_umount(fsid, flags)) == 0) | |||||
return (0); | |||||
if (asprintf(&fsid_str, "FSID:%d:%d", fsid->val[0], fsid->val[1]) < 0) | |||||
log_err(1, "asprintf"); | log_err(1, "asprintf"); | ||||
log_debugx("unmounting %s using %s", sb->f_mntonname, fsid_str); | flags |= MNT_BYFSID; | ||||
if ((error = unmount(fsid_str, flags)) == 0) | |||||
return (0); | |||||
flags = MNT_BYFSID; | log_debugx("cannot unmount (%s): %s", fsid_str, strerror(errno)); | ||||
if (force) | |||||
flags |= MNT_FORCE; | |||||
error = unmount(fsid_str, flags); | |||||
free(fsid_str); | |||||
if (error != 0) | |||||
log_warn("cannot unmount %s", sb->f_mntonname); | |||||
free(fsid_str); | |||||
return (error); | return (error); | ||||
} | } | ||||
static const struct statfs * | static const struct statfs * | ||||
find_statfs(const struct statfs *mntbuf, int nitems, const char *mountpoint) | find_statfs(const struct statfs *mntbuf, int nitems, const char *mountpoint) | ||||
{ | { | ||||
int i; | int i; | ||||
▲ Show 20 Lines • Show All 305 Lines • Show Last 20 Lines |