2 * Copyright (c) 2007 Alistair Crooks. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. The name of the author may not be used to endorse or promote
13 * products derived from this software without specific prior written
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
17 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
22 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include <sys/cdefs.h>
31 __COPYRIGHT("@(#) Copyright (c) 2007\
32 The NetBSD Foundation, Inc. All rights reserved.");
33 __RCSID("$NetBSD: fusermount.c,v 1.2 2007/06/11 21:16:23 agc Exp $");
36 #include <sys/types.h>
37 #include <sys/param.h>
38 #include <sys/mount.h>
46 #ifndef FUSERMOUNT_VERSION
47 #define FUSERMOUNT_VERSION "2.6.0"
59 /* unmount mount point(s) */
61 refuse_unmount(int argc
, char **argv
)
66 for (ret
= 1, i
= 0 ; i
< argc
; i
++) {
67 if (unmount(argv
[i
], 0) < 0) {
68 warn("can't unmount `%s'", argv
[i
]);
75 /* print the usage meessage */
77 usage(const char *prog
)
79 (void) fprintf(stderr
,
80 "Usage: %s [-c] [-d name] [-h] [-p] [-u] [-x] mountpoint...\n",
82 (void) fprintf(stderr
, "\t-c\tuse kernel cache\n");
83 (void) fprintf(stderr
, "\t-d name\tuse name in mount information\n");
84 (void) fprintf(stderr
, "\t-h\tprint help information\n");
85 (void) fprintf(stderr
, "\t-p\tcheck file permissions\n");
86 (void) fprintf(stderr
, "\t-u\tunmount mount point(s)\n");
87 (void) fprintf(stderr
,
88 "\t-x\tallow access to mortal (non-root) users\n");
92 main(int argc
, char **argv
)
102 action
= ActionMount
;
103 while ((i
= getopt(argc
, argv
, "Vcd:hpux")) != -1) {
106 printf("fusermount version: %s\n", FUSERMOUNT_VERSION
);
110 flags
|= FlagKernelCache
;
119 flags
|= FlagCheckPerm
;
122 action
= ActionUnmount
;
125 if (geteuid() != 0) {
127 "-x option is only allowed for use by root");
129 flags
|= FlagNonrootUsers
;
132 warnx("Unrecognised argument `%c'", i
);
137 if (optind
>= argc
- 2) {
138 warnx("Not enough command line arguments");
142 execme
= argv
[optind
+ 1];
144 argv
[optind
+ 1] = progname
;
146 /* mountpoint = argv[optind]; */
149 execvp(execme
, &argv
[optind
+ 1]);
152 if (!refuse_unmount(argc
- optind
, argv
+ optind
)) {