ubase

suckless linux base utils
git clone git://git.2f30.org/ubase
Log | Files | Refs | README | LICENSE

commit d4c1710911198be8837afa781777731534b14a42
parent 7efb360b3c3d509fe6c5639ac2e05f44e41c673d
Author: sin <sin@2f30.org>
Date:   Wed,  7 Aug 2013 09:52:10 +0100

Add umount(8)

No manpage yet.

Diffstat:
MMakefile | 4+++-
Alinux/umount.c | 14++++++++++++++
Aopenbsd/umount.c | 15+++++++++++++++
Mubase.h | 7+++++++
Aumount.c | 32++++++++++++++++++++++++++++++++
5 files changed, 71 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile @@ -7,12 +7,14 @@ HDR = util.h arg.h ubase.h LIB = \ $(OS)/grabmntinfo.o \ $(OS)/syslog.o \ + $(OS)/umount.o \ util/eprintf.o \ util/estrtol.o SRC = \ df.c \ - dmesg.c + dmesg.c \ + umount.c OBJ = $(SRC:.c=.o) $(LIB) BIN = $(SRC:.c=) diff --git a/linux/umount.c b/linux/umount.c @@ -0,0 +1,14 @@ +#include <sys/mount.h> +#include <stdio.h> +#include "../ubase.h" +#include "../util.h" + +int +do_umount(const char *target, int opts) +{ + int flags = 0; + + if (opts & UBASE_MNT_FORCE) + flags |= MNT_FORCE; + return umount2(target, flags); +} diff --git a/openbsd/umount.c b/openbsd/umount.c @@ -0,0 +1,15 @@ +#include <sys/param.h> +#include <sys/mount.h> +#include <stdio.h> +#include "../ubase.h" +#include "../util.h" + +int +do_umount(const char *target, int opts) +{ + int flags = 0; + + if (opts & UBASE_MNT_FORCE) + flags |= MNT_FORCE; + return unmount(target, flags); +} diff --git a/ubase.h b/ubase.h @@ -11,3 +11,10 @@ int grabmntinfo(struct mntinfo **minfo); /* syslog.c */ int syslog_size(void); int syslog_read(void *buf, size_t n); + +/* umount.c */ +enum { + UBASE_MNT_FORCE = 1 << 0 +}; + +int do_umount(const char *target, int opts); diff --git a/umount.c b/umount.c @@ -0,0 +1,32 @@ +#include <stdio.h> +#include "ubase.h" +#include "util.h" + +static void +usage(void) +{ + eprintf("usage: %s [-f] target\n", argv0); +} + +int +main(int argc, char *argv[]) { + int i; + int fflag = 0; + int ret = 0; + + ARGBEGIN { + case 'f': + fflag = UBASE_MNT_FORCE; + break; + default: + usage(); + } ARGEND; + if (argc < 1) + usage(); + for (i = 0; i < argc; i++) { + if (do_umount(argv[i], fflag) < 0) + eprintf("do_umount:"); + ret = 1; + } + return ret; +}