Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/autofs/automount.c
Show First 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | unmount_by_statfs(const struct statfs *sb, bool force) | ||||
error = unmount(fsid_str, flags); | error = unmount(fsid_str, flags); | ||||
free(fsid_str); | free(fsid_str); | ||||
if (error != 0) | if (error != 0) | ||||
log_warn("cannot unmount %s", sb->f_mntonname); | log_warn("cannot unmount %s", sb->f_mntonname); | ||||
return (error); | return (error); | ||||
} | } | ||||
static int | |||||
unmount_by_umount(struct statfs* sfp, bool force) | |||||
{ | |||||
FILE *f; | |||||
char fsid[sizeof(sfp->f_fsid)*2+1]; | |||||
size_t i; | |||||
if (sfp->f_fsid.val[0] == 0 || sfp->f_fsid.val[1] == 0) | |||||
return (-1); | |||||
/* umount(8) expects the file system ID to be in hexadecimal format */ | |||||
for (i = 0; i < sizeof(sfp->f_fsid); i++) | |||||
snprintf(fsid+strlen(fsid), sizeof(fsid) - strlen(fsid), | |||||
"%02x", ((u_char *)&sfp->f_fsid)[i]); | |||||
if (force) | |||||
f = auto_popen("umount", "-f", fsid, NULL); | |||||
else | |||||
f = auto_popen("umount", fsid, NULL); | |||||
assert(f != NULL); | |||||
return (auto_pclose(f)); | |||||
} | |||||
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; | ||||
for (i = 0; i < nitems; i++) { | for (i = 0; i < nitems; i++) { | ||||
if (strcmp(mntbuf[i].f_mntonname, mountpoint) == 0) | if (strcmp(mntbuf[i].f_mntonname, mountpoint) == 0) | ||||
return (mntbuf + i); | return (mntbuf + i); | ||||
▲ Show 20 Lines • Show All 204 Lines • ▼ Show 20 Lines | for (i = 0; i < nitems; i++) { | ||||
} | } | ||||
if ((mntbuf[i].f_flags & MNT_AUTOMOUNTED) == 0) { | if ((mntbuf[i].f_flags & MNT_AUTOMOUNTED) == 0) { | ||||
log_debugx("skipping %s, not automounted", | log_debugx("skipping %s, not automounted", | ||||
mntbuf[i].f_mntonname); | mntbuf[i].f_mntonname); | ||||
continue; | continue; | ||||
} | } | ||||
if (unmount_by_umount(&(mntbuf[i]), force) != 0) | |||||
unmount_by_statfs(&(mntbuf[i]), force); | unmount_by_statfs(&(mntbuf[i]), force); | ||||
} | } | ||||
} | } | ||||
static void | static void | ||||
usage_automount(void) | usage_automount(void) | ||||
{ | { | ||||
fprintf(stderr, "usage: automount [-D name=value][-o opts][-Lcfuv]\n"); | fprintf(stderr, "usage: automount [-D name=value][-o opts][-Lcfuv]\n"); | ||||
▲ Show 20 Lines • Show All 81 Lines • Show Last 20 Lines |