From 7f92db73273fda65ad7660410f0d23f0c9b1095e Mon Sep 17 00:00:00 2001 From: sin Date: Fri, 7 Mar 2014 13:49:40 +0000 Subject: [PATCH] Implement umount -a --- umount.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/umount.c b/umount.c index 23b9ff7..b205812 100644 --- a/umount.c +++ b/umount.c @@ -1,23 +1,30 @@ /* See LICENSE file for copyright and license details. */ -#include +#include #include #include +#include #include "util.h" static void usage(void) { - eprintf("usage: %s [-lfn] target\n", argv0); + eprintf("usage: %s [-alfn] target\n", argv0); } int main(int argc, char *argv[]) { int i; + int aflag = 0; int flags = 0; int ret = EXIT_SUCCESS; + FILE *fp; + struct mntent *me; ARGBEGIN { + case 'a': + aflag = 1; + break; case 'f': flags |= MNT_FORCE; break; @@ -30,9 +37,23 @@ main(int argc, char *argv[]) usage(); } ARGEND; - if (argc < 1) + if (argc < 1 && aflag == 0) usage(); + if (aflag == 1) { + fp = setmntent("/etc/fstab", "r"); + if (!fp) + eprintf("setmntent %s:", "/etc/fstab"); + while ((me = getmntent(fp))) { + if (umount2(me->mnt_dir, flags) < 0) { + perror("umount2:"); + ret = EXIT_FAILURE; + } + } + endmntent(fp); + return ret; + } + for (i = 0; i < argc; i++) { if (umount2(argv[i], flags) < 0) perror("umount2:");