summaryrefslogtreecommitdiffstats
path: root/usr/utils/umount.c
blob: 41275f7bed79ca51ad7aa156a3dc1ecf0ba97b7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
 * by rmk
 */
#include <sys/mount.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

char *progname;

int main(int argc, char *argv[])
{
	int c, flag = 0;

	progname = argv[0];

	do {
		c = getopt(argc, argv, "fli");
		if (c == EOF)
			break;
		switch (c) {
		case 'f':
			flag |= MNT_FORCE;
			break;
		case 'l':
			flag |= MNT_DETACH;
			break;
		case 'i':
			/* ignore for now; no support for umount helpers */
			break;
		case '?':
			fprintf(stderr, "%s: invalid option -%c\n",
				progname, optopt);
			exit(1);
		}
	} while (1);

	if (optind + 1 != argc) {
		fprintf(stderr, "Usage: %s [-f] [-l] [-i] mntpoint\n",
			progname);
		return 1;
	}

	if (umount2(argv[optind], flag) == -1) {
		perror("umount2");
		return 255;
	}

	return 0;
}