2013-08-07 10:41:42 +00:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
2014-06-30 18:03:41 +00:00
|
|
|
#include <sys/mount.h>
|
|
|
|
|
2014-03-07 13:49:40 +00:00
|
|
|
#include <mntent.h>
|
2013-08-07 08:52:10 +00:00
|
|
|
#include <stdio.h>
|
2013-10-07 18:11:40 +00:00
|
|
|
#include <stdlib.h>
|
2014-03-12 14:35:20 +00:00
|
|
|
#include <string.h>
|
2014-06-30 18:03:41 +00:00
|
|
|
|
2013-08-07 08:52:10 +00:00
|
|
|
#include "util.h"
|
|
|
|
|
2015-02-06 14:19:33 +00:00
|
|
|
static int
|
|
|
|
umountall(int flags)
|
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
struct mntent *me;
|
|
|
|
int ret;
|
|
|
|
char **mntdirs = NULL;
|
|
|
|
int len = 0;
|
|
|
|
|
|
|
|
fp = setmntent("/proc/mounts", "r");
|
|
|
|
if (!fp)
|
|
|
|
eprintf("setmntent %s:", "/proc/mounts");
|
|
|
|
while ((me = getmntent(fp))) {
|
|
|
|
if (strcmp(me->mnt_type, "proc") == 0)
|
|
|
|
continue;
|
|
|
|
mntdirs = erealloc(mntdirs, ++len * sizeof(*mntdirs));
|
|
|
|
mntdirs[len - 1] = estrdup(me->mnt_dir);
|
|
|
|
}
|
|
|
|
endmntent(fp);
|
|
|
|
while (--len >= 0) {
|
|
|
|
if (umount2(mntdirs[len], flags) < 0) {
|
|
|
|
weprintf("umount2 %s:", mntdirs[len]);
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
free(mntdirs[len]);
|
|
|
|
}
|
|
|
|
free(mntdirs);
|
|
|
|
return ret;
|
|
|
|
}
|
2014-03-15 18:37:16 +00:00
|
|
|
|
2013-08-07 08:52:10 +00:00
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
2014-04-13 15:28:08 +00:00
|
|
|
weprintf("usage: %s [-lfn] target...\n", argv0);
|
2014-03-12 14:28:56 +00:00
|
|
|
weprintf("usage: %s -a [-lfn]\n", argv0);
|
2014-10-02 22:45:25 +00:00
|
|
|
exit(1);
|
2013-08-07 08:52:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2013-08-16 10:10:13 +00:00
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2013-08-07 08:52:10 +00:00
|
|
|
int i;
|
2014-03-07 13:49:40 +00:00
|
|
|
int aflag = 0;
|
2013-08-07 09:33:19 +00:00
|
|
|
int flags = 0;
|
2014-10-02 22:45:25 +00:00
|
|
|
int ret = 0;
|
2013-08-07 08:52:10 +00:00
|
|
|
|
|
|
|
ARGBEGIN {
|
2014-03-07 13:49:40 +00:00
|
|
|
case 'a':
|
|
|
|
aflag = 1;
|
|
|
|
break;
|
2013-08-07 08:52:10 +00:00
|
|
|
case 'f':
|
2013-08-14 13:19:05 +00:00
|
|
|
flags |= MNT_FORCE;
|
2013-08-07 09:33:19 +00:00
|
|
|
break;
|
|
|
|
case 'l':
|
2013-08-14 13:19:05 +00:00
|
|
|
flags |= MNT_DETACH;
|
2013-08-07 08:52:10 +00:00
|
|
|
break;
|
2013-09-06 10:01:03 +00:00
|
|
|
case 'n':
|
|
|
|
break;
|
2013-08-07 08:52:10 +00:00
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
} ARGEND;
|
2013-08-10 10:38:30 +00:00
|
|
|
|
2014-03-07 13:49:40 +00:00
|
|
|
if (argc < 1 && aflag == 0)
|
2013-08-07 08:52:10 +00:00
|
|
|
usage();
|
2013-08-10 10:38:30 +00:00
|
|
|
|
2014-03-15 18:37:16 +00:00
|
|
|
if (aflag == 1)
|
|
|
|
return umountall(flags);
|
2014-03-07 13:49:40 +00:00
|
|
|
|
2013-08-07 08:52:10 +00:00
|
|
|
for (i = 0; i < argc; i++) {
|
2014-03-07 13:52:31 +00:00
|
|
|
if (umount2(argv[i], flags) < 0) {
|
2014-03-15 18:10:01 +00:00
|
|
|
weprintf("umount2 %s:", argv[i]);
|
2014-10-02 22:45:25 +00:00
|
|
|
ret = 1;
|
2014-03-07 13:52:31 +00:00
|
|
|
}
|
2013-08-07 08:52:10 +00:00
|
|
|
}
|
|
|
|
return ret;
|
2015-02-06 14:19:33 +00:00
|
|
|
}
|