2 * mount(8) -- mount a filesystem
4 * Copyright (C) 2011 Red Hat, Inc. All rights reserved.
5 * Written by Karel Zak <kzak@redhat.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it would be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include <sys/types.h>
39 #include "exitcodes.h"
41 #include "closestream.h"
43 #define OPTUTILS_EXIT_CODE MOUNT_EX_USAGE
48 * --options-mode={ignore,append,prepend,replace} MNT_OMODE_{IGNORE, ...}
49 * --options-source={fstab,mtab,disable} MNT_OMODE_{FSTAB,MTAB,NOTAB}
50 * --options-source-force MNT_OMODE_FORCE
55 static int mk_exit_code(struct libmnt_context
*cxt
, int rc
);
57 static void __attribute__((__noreturn__
)) exit_non_root(const char *option
)
59 const uid_t ruid
= getuid();
60 const uid_t euid
= geteuid();
62 if (ruid
== 0 && euid
!= 0) {
63 /* user is root, but setuid to non-root */
65 errx(MOUNT_EX_USAGE
, _("only root can use \"--%s\" option "
66 "(effective UID is %u)"),
68 errx(MOUNT_EX_USAGE
, _("only root can do that "
69 "(effective UID is %u)"), euid
);
72 errx(MOUNT_EX_USAGE
, _("only root can use \"--%s\" option"), option
);
73 errx(MOUNT_EX_USAGE
, _("only root can do that"));
76 static void __attribute__((__noreturn__
)) print_version(void)
78 const char *ver
= NULL
;
79 const char **features
= NULL
, **p
;
81 mnt_get_library_version(&ver
);
82 mnt_get_library_features(&features
);
84 printf(_("%s from %s (libmount %s"),
85 program_invocation_short_name
,
90 fputs(p
== features
? ": " : ", ", stdout
);
94 exit(MOUNT_EX_SUCCESS
);
97 static int table_parser_errcb(struct libmnt_table
*tb
__attribute__((__unused__
)),
98 const char *filename
, int line
)
101 warnx(_("%s: parse error: ignore entry at line %d."),
107 * Replace control chars with '?' to be compatible with coreutils. For more
108 * robust solution use findmnt(1) where we use \x?? hex encoding.
110 static void safe_fputs(const char *data
)
114 for (p
= data
; p
&& *p
; p
++) {
115 if (iscntrl((unsigned char) *p
))
122 static void print_all(struct libmnt_context
*cxt
, char *pattern
, int show_label
)
124 struct libmnt_table
*tb
;
125 struct libmnt_iter
*itr
= NULL
;
126 struct libmnt_fs
*fs
;
127 struct libmnt_cache
*cache
= NULL
;
129 if (mnt_context_get_mtab(cxt
, &tb
))
130 err(MOUNT_EX_SYSERR
, _("failed to read mtab"));
132 itr
= mnt_new_iter(MNT_ITER_FORWARD
);
134 err(MOUNT_EX_SYSERR
, _("failed to initialize libmount iterator"));
136 cache
= mnt_new_cache();
138 while (mnt_table_next_fs(tb
, itr
, &fs
) == 0) {
139 const char *type
= mnt_fs_get_fstype(fs
);
140 const char *src
= mnt_fs_get_source(fs
);
141 const char *optstr
= mnt_fs_get_options(fs
);
144 if (type
&& pattern
&& !mnt_match_fstype(type
, pattern
))
147 if (!mnt_fs_is_pseudofs(fs
))
148 xsrc
= mnt_pretty_path(src
, cache
);
149 printf ("%s on ", xsrc
? xsrc
: src
);
150 safe_fputs(mnt_fs_get_target(fs
));
153 printf (" type %s", type
);
155 printf (" (%s)", optstr
);
156 if (show_label
&& src
) {
157 char *lb
= mnt_cache_find_tag_value(cache
, src
, "LABEL");
159 printf (" [%s]", lb
);
165 mnt_free_cache(cache
);
172 static int mount_all(struct libmnt_context
*cxt
)
174 struct libmnt_iter
*itr
;
175 struct libmnt_fs
*fs
;
176 int mntrc
, ignored
, rc
= MOUNT_EX_SUCCESS
;
178 int nsucc
= 0, nerrs
= 0;
180 itr
= mnt_new_iter(MNT_ITER_FORWARD
);
182 warn(_("failed to initialize libmount iterator"));
183 return MOUNT_EX_SYSERR
;
186 while (mnt_context_next_mount(cxt
, itr
, &fs
, &mntrc
, &ignored
) == 0) {
188 const char *tgt
= mnt_fs_get_target(fs
);
191 if (mnt_context_is_verbose(cxt
))
192 printf(ignored
== 1 ? _("%-25s: ignored\n") :
193 _("%-25s: already mounted\n"),
195 } else if (mnt_context_is_fork(cxt
)) {
196 if (mnt_context_is_verbose(cxt
))
197 printf("%-25s: mount successfully forked\n", tgt
);
199 mk_exit_code(cxt
, mntrc
); /* to print warnings */
201 if (mnt_context_get_status(cxt
)) {
204 if (mnt_context_is_verbose(cxt
))
205 printf("%-25s: successfully mounted\n", tgt
);
211 if (mnt_context_is_parent(cxt
)) {
212 /* wait for mount --fork children */
215 nerrs
= 0, nsucc
= 0;
217 rc
= mnt_context_wait_for_children(cxt
, &nchildren
, &nerrs
);
218 if (!rc
&& nchildren
)
219 nsucc
= nchildren
- nerrs
;
223 rc
= MOUNT_EX_SUCCESS
; /* all success */
225 rc
= MOUNT_EX_FAIL
; /* all failed */
227 rc
= MOUNT_EX_SOMEOK
; /* some success, some failed */
234 * Handles generic errors like ENOMEM, ...
237 * <0 error (usually -errno)
239 * Returns exit status (MOUNT_EX_*) and prints error message.
241 static int handle_generic_errors(int rc
, const char *msg
, ...)
256 rc
= MOUNT_EX_SYSERR
;
267 #if defined(HAVE_LIBSELINUX) && defined(HAVE_SECURITY_GET_INITIAL_CONTEXT)
268 #include <selinux/selinux.h>
269 #include <selinux/context.h>
271 static void selinux_warning(struct libmnt_context
*cxt
, const char *tgt
)
274 if (tgt
&& mnt_context_is_verbose(cxt
) && is_selinux_enabled() > 0) {
275 security_context_t raw
= NULL
, def
= NULL
;
277 if (getfilecon(tgt
, &raw
) > 0
278 && security_get_initial_context("file", &def
) == 0) {
280 if (!selinux_file_context_cmp(raw
, def
))
282 "mount: %s does not contain SELinux labels.\n"
283 " You just mounted an file system that supports labels which does not\n"
284 " contain labels, onto an SELinux box. It is likely that confined\n"
285 " applications will generate AVC messages and not be allowed access to\n"
286 " this file system. For more details see restorecon(8) and mount(8).\n"),
294 # define selinux_warning(_x, _y)
300 * <0 error (usually -errno or -1)
302 * Returns exit status (MOUNT_EX_*) and/or prints error message.
304 static int mk_exit_code(struct libmnt_context
*cxt
, int rc
)
308 unsigned long uflags
= 0, mflags
= 0;
310 int restricted
= mnt_context_is_restricted(cxt
);
311 const char *tgt
= mnt_context_get_target(cxt
);
312 const char *src
= mnt_context_get_source(cxt
);
315 if (mnt_context_helper_executed(cxt
))
317 * /sbin/mount.<type> called, return status
319 return mnt_context_get_helper_status(cxt
);
321 if (rc
== 0 && mnt_context_get_status(cxt
) == 1) {
323 * Libmount success && syscall success.
325 selinux_warning(cxt
, tgt
);
327 return MOUNT_EX_SUCCESS
; /* mount(2) success */
330 mnt_context_get_mflags(cxt
, &mflags
); /* mount(2) flags */
331 mnt_context_get_user_mflags(cxt
, &uflags
); /* userspace flags */
333 if (!mnt_context_syscall_called(cxt
)) {
335 * libmount errors (extra library checks)
339 warnx(_("only root can mount %s on %s"), src
, tgt
);
340 return MOUNT_EX_USAGE
;
342 warnx(_("%s is already mounted"), src
);
343 return MOUNT_EX_USAGE
;
344 case -MNT_ERR_NOFSTAB
:
345 if (mnt_context_is_swapmatch(cxt
)) {
346 warnx(_("can't find %s in %s"),
348 mnt_get_fstab_path());
349 return MOUNT_EX_USAGE
;
351 /* source/target explicitly defined */
353 warnx(_("can't find mountpoint %s in %s"),
354 tgt
, mnt_get_fstab_path());
356 warnx(_("can't find mount source %s in %s"),
357 src
, mnt_get_fstab_path());
358 return MOUNT_EX_USAGE
;
359 case -MNT_ERR_NOFSTYPE
:
361 warnx(_("I could not determine the filesystem type, "
362 "and none was specified"));
364 warnx(_("you must specify the filesystem type"));
365 return MOUNT_EX_USAGE
;
366 case -MNT_ERR_NOSOURCE
:
368 warnx(_("can't find %s"), src
);
370 warnx(_("mount source not defined"));
371 return MOUNT_EX_USAGE
;
372 case -MNT_ERR_MOUNTOPT
:
374 warn(_("failed to parse mount options"));
376 warnx(_("failed to parse mount options"));
377 return MOUNT_EX_USAGE
;
378 case -MNT_ERR_LOOPDEV
:
379 warn(_("%s: failed to setup loop device"), src
);
380 return MOUNT_EX_FAIL
;
382 return handle_generic_errors(rc
, _("%s: mount failed"),
385 } else if (mnt_context_get_syscall_errno(cxt
) == 0) {
387 * mount(2) syscall success, but something else failed
388 * (probably error in mtab processing).
391 return handle_generic_errors(rc
,
392 _("%s: filesystem mounted, but mount(8) failed"),
395 return MOUNT_EX_SOFTWARE
; /* internal error */
402 syserr
= mnt_context_get_syscall_errno(cxt
);
407 if (geteuid() == 0) {
408 if (stat(tgt
, &st
) || !S_ISDIR(st
.st_mode
))
409 warnx(_("mount point %s is not a directory"), tgt
);
411 warnx(_("permission denied"));
413 warnx(_("must be superuser to use mount"));
418 struct libmnt_table
*tb
;
420 if (mflags
& MS_REMOUNT
) {
421 warnx(_("%s is busy"), tgt
);
425 warnx(_("%s is already mounted or %s busy"), src
, tgt
);
427 if (src
&& mnt_context_get_mtab(cxt
, &tb
) == 0) {
428 struct libmnt_iter
*itr
= mnt_new_iter(MNT_ITER_FORWARD
);
429 struct libmnt_fs
*fs
;
431 while(mnt_table_next_fs(tb
, itr
, &fs
) == 0) {
432 const char *s
= mnt_fs_get_srcpath(fs
),
433 *t
= mnt_fs_get_target(fs
);
435 if (t
&& s
&& mnt_fs_streq_srcpath(fs
, src
))
437 " %s is already mounted on %s\n"), s
, t
);
445 warnx(_("mount point %s does not exist"), tgt
);
446 else if (stat(tgt
, &st
))
447 warnx(_("mount point %s is a symbolic link to nowhere"), tgt
);
448 else if (stat(src
, &st
)) {
449 if (uflags
& MNT_MS_NOFAIL
)
450 return MOUNT_EX_SUCCESS
;
452 warnx(_("special device %s does not exist"), src
);
455 warn(_("mount(2) failed")); /* print errno */
460 if (stat(tgt
, &st
) || ! S_ISDIR(st
.st_mode
))
461 warnx(_("mount point %s is not a directory"), tgt
);
462 else if (stat(src
, &st
) && errno
== ENOTDIR
) {
463 if (uflags
& MNT_MS_NOFAIL
)
464 return MOUNT_EX_SUCCESS
;
466 warnx(_("special device %s does not exist "
467 "(a path prefix is not a directory)"), src
);
470 warn(_("mount(2) failed")); /* print errno */
475 if (mflags
& MS_REMOUNT
)
476 warnx(_("%s not mounted or bad option"), tgt
);
477 else if (mflags
& MS_PROPAGATION
)
478 warnx(_("%s is not mountpoint or bad option"), tgt
);
480 warnx(_("wrong fs type, bad option, bad superblock on %s,\n"
481 " missing codepage or helper program, or other error"),
484 if (mnt_fs_is_netfs(mnt_context_get_fs(cxt
)))
486 " (for several filesystems (e.g. nfs, cifs) you might\n"
487 " need a /sbin/mount.<type> helper program)\n"));
490 " In some cases useful info is found in syslog - try\n"
491 " dmesg | tail or so\n"));
495 warnx(_("mount table full"));
499 warnx(_("%s: can't read superblock"), src
);
503 warnx(_("unknown filesystem type '%s'"), mnt_context_get_fstype(cxt
));
507 if (uflags
& MNT_MS_NOFAIL
)
508 return MOUNT_EX_SUCCESS
;
511 warnx(_("%s is not a block device, and stat(2) fails?"), src
);
512 else if (S_ISBLK(st
.st_mode
))
513 warnx(_("the kernel does not recognize %s as a block device\n"
514 " (maybe `modprobe driver'?)"), src
);
515 else if (S_ISREG(st
.st_mode
))
516 warnx(_("%s is not a block device (maybe try `-o loop'?)"), src
);
518 warnx(_(" %s is not a block device"), src
);
522 if (uflags
& MNT_MS_NOFAIL
)
523 return MOUNT_EX_SUCCESS
;
525 warnx(_("%s is not a valid block device"), src
);
530 if (mflags
& MS_RDONLY
)
531 warnx(_("cannot mount %s read-only"), src
);
534 warnx(_("%s is write-protected but explicit `-w' flag given"), src
);
536 else if (mflags
& MS_REMOUNT
)
537 warnx(_("cannot remount %s read-write, is write-protected"), src
);
540 warnx(_("%s is write-protected, mounting read-only"), src
);
542 mnt_context_reset_status(cxt
);
543 mnt_context_set_mflags(cxt
, mflags
| MS_RDONLY
);
544 rc
= mnt_context_do_mount(cxt
);
546 rc
= mnt_context_finalize_mount(cxt
);
553 warnx(_("no medium found on %s"), src
);
557 warn(_("mount %s on %s failed"), src
, tgt
);
561 return MOUNT_EX_FAIL
;
564 static struct libmnt_table
*append_fstab(struct libmnt_context
*cxt
,
565 struct libmnt_table
*fstab
,
570 fstab
= mnt_new_table();
572 err(MOUNT_EX_SYSERR
, _("failed to initialize libmount table"));
574 mnt_table_set_parser_errcb(fstab
, table_parser_errcb
);
575 mnt_context_set_fstab(cxt
, fstab
);
578 if (mnt_table_parse_fstab(fstab
, path
))
579 errx(MOUNT_EX_USAGE
,_("%s: failed to parse"), path
);
584 static void __attribute__((__noreturn__
)) usage(FILE *out
)
586 fputs(USAGE_HEADER
, out
);
589 " %1$s -a [options]\n"
590 " %1$s [options] [--source] <source> | [--target] <directory>\n"
591 " %1$s [options] <source> <directory>\n"
592 " %1$s <operation> <mountpoint> [<target>]\n"),
593 program_invocation_short_name
);
595 fputs(USAGE_OPTIONS
, out
);
597 " -a, --all mount all filesystems mentioned in fstab\n"
598 " -c, --no-canonicalize don't canonicalize paths\n"
599 " -f, --fake dry run; skip the mount(2) syscall\n"
600 " -F, --fork fork off for each device (use with -a)\n"
601 " -T, --fstab <path> alternative file to /etc/fstab\n"));
603 " -h, --help display this help text and exit\n"
604 " -i, --internal-only don't call the mount.<type> helpers\n"
605 " -l, --show-labels lists all mounts with LABELs\n"
606 " -n, --no-mtab don't write to /etc/mtab\n"));
608 " -o, --options <list> comma-separated list of mount options\n"
609 " -O, --test-opts <list> limit the set of filesystems (use with -a)\n"
610 " -r, --read-only mount the filesystem read-only (same as -o ro)\n"
611 " -t, --types <list> limit the set of filesystem types\n"));
613 " --source <src> explicitly specifies source (path, label, uuid)\n"
614 " --target <target> explicitly specifies mountpoint\n"));
616 " -v, --verbose say what is being done\n"
617 " -V, --version display version information and exit\n"
618 " -w, --read-write mount the filesystem read-write (default)\n"));
620 fputs(USAGE_SEPARATOR
, out
);
621 fputs(USAGE_HELP
, out
);
622 fputs(USAGE_VERSION
, out
);
626 " -L, --label <label> synonym for LABEL=<label>\n"
627 " -U, --uuid <uuid> synonym for UUID=<uuid>\n"
628 " LABEL=<label> specifies device by filesystem label\n"
629 " UUID=<uuid> specifies device by filesystem UUID\n"
630 " PARTLABEL=<label> specifies device by partition label\n"
631 " PARTUUID=<uuid> specifies device by partition UUID\n"));
634 " <device> specifies device by path\n"
635 " <directory> mountpoint for bind mounts (see --bind/rbind)\n"
636 " <file> regular file for loopdev setup\n"));
640 " -B, --bind mount a subtree somewhere else (same as -o bind)\n"
641 " -M, --move move a subtree to some other place\n"
642 " -R, --rbind mount a subtree and all submounts somewhere else\n"));
644 " --make-shared mark a subtree as shared\n"
645 " --make-slave mark a subtree as slave\n"
646 " --make-private mark a subtree as private\n"
647 " --make-unbindable mark a subtree as unbindable\n"));
649 " --make-rshared recursively mark a whole subtree as shared\n"
650 " --make-rslave recursively mark a whole subtree as slave\n"
651 " --make-rprivate recursively mark a whole subtree as private\n"
652 " --make-runbindable recursively mark a whole subtree as unbindable\n"));
654 fprintf(out
, USAGE_MAN_TAIL("mount(8)"));
656 exit(out
== stderr
? MOUNT_EX_USAGE
: MOUNT_EX_SUCCESS
);
659 int main(int argc
, char **argv
)
661 int c
, rc
= MOUNT_EX_SUCCESS
, all
= 0, show_labels
= 0;
662 struct libmnt_context
*cxt
;
663 struct libmnt_table
*fstab
= NULL
;
666 unsigned long oper
= 0;
669 MOUNT_OPT_SHARED
= CHAR_MAX
+ 1,
672 MOUNT_OPT_UNBINDABLE
,
676 MOUNT_OPT_RUNBINDABLE
,
681 static const struct option longopts
[] = {
682 { "all", 0, 0, 'a' },
683 { "fake", 0, 0, 'f' },
684 { "fstab", 1, 0, 'T' },
685 { "fork", 0, 0, 'F' },
686 { "help", 0, 0, 'h' },
687 { "no-mtab", 0, 0, 'n' },
688 { "read-only", 0, 0, 'r' },
690 { "verbose", 0, 0, 'v' },
691 { "version", 0, 0, 'V' },
692 { "read-write", 0, 0, 'w' },
694 { "options", 1, 0, 'o' },
695 { "test-opts", 1, 0, 'O' },
696 { "pass-fd", 1, 0, 'p' },
697 { "types", 1, 0, 't' },
698 { "uuid", 1, 0, 'U' },
699 { "label", 1, 0, 'L'},
700 { "bind", 0, 0, 'B' },
701 { "move", 0, 0, 'M' },
702 { "rbind", 0, 0, 'R' },
703 { "make-shared", 0, 0, MOUNT_OPT_SHARED
},
704 { "make-slave", 0, 0, MOUNT_OPT_SLAVE
},
705 { "make-private", 0, 0, MOUNT_OPT_PRIVATE
},
706 { "make-unbindable", 0, 0, MOUNT_OPT_UNBINDABLE
},
707 { "make-rshared", 0, 0, MOUNT_OPT_RSHARED
},
708 { "make-rslave", 0, 0, MOUNT_OPT_RSLAVE
},
709 { "make-rprivate", 0, 0, MOUNT_OPT_RPRIVATE
},
710 { "make-runbindable", 0, 0, MOUNT_OPT_RUNBINDABLE
},
711 { "no-canonicalize", 0, 0, 'c' },
712 { "internal-only", 0, 0, 'i' },
713 { "show-labels", 0, 0, 'l' },
714 { "target", 1, 0, MOUNT_OPT_TARGET
},
715 { "source", 1, 0, MOUNT_OPT_SOURCE
},
719 static const ul_excl_t excl
[] = { /* rows and cols in in ASCII order */
720 { 'B','M','R', /* bind,move,rbind */
721 MOUNT_OPT_SHARED
, MOUNT_OPT_SLAVE
,
722 MOUNT_OPT_PRIVATE
, MOUNT_OPT_UNBINDABLE
,
723 MOUNT_OPT_RSHARED
, MOUNT_OPT_RSLAVE
,
724 MOUNT_OPT_RPRIVATE
, MOUNT_OPT_RUNBINDABLE
},
726 { 'L','U', MOUNT_OPT_SOURCE
}, /* label,uuid,source */
729 int excl_st
[ARRAY_SIZE(excl
)] = UL_EXCL_STATUS_INIT
;
732 setlocale(LC_ALL
, "");
733 bindtextdomain(PACKAGE
, LOCALEDIR
);
735 atexit(close_stdout
);
738 cxt
= mnt_new_context();
740 err(MOUNT_EX_SYSERR
, _("libmount context allocation failed"));
742 mnt_context_set_tables_errcb(cxt
, table_parser_errcb
);
744 while ((c
= getopt_long(argc
, argv
, "aBcfFhilL:Mno:O:p:rRsU:vVwt:T:",
745 longopts
, NULL
)) != -1) {
747 /* only few options are allowed for non-root users */
748 if (mnt_context_is_restricted(cxt
) &&
749 !strchr("hlLUVvpris", c
) &&
750 c
!= MOUNT_OPT_TARGET
&&
751 c
!= MOUNT_OPT_SOURCE
)
752 exit_non_root(option_to_longopt(c
, longopts
));
754 err_exclusive_options(c
, longopts
, excl
, excl_st
);
761 mnt_context_disable_canonicalize(cxt
, TRUE
);
764 mnt_context_enable_fake(cxt
, TRUE
);
767 mnt_context_enable_fork(cxt
, TRUE
);
773 mnt_context_disable_helpers(cxt
, TRUE
);
776 mnt_context_disable_mtab(cxt
, TRUE
);
779 if (mnt_context_append_options(cxt
, "ro"))
780 err(MOUNT_EX_SYSERR
, _("failed to append options"));
784 mnt_context_enable_verbose(cxt
, TRUE
);
790 if (mnt_context_append_options(cxt
, "rw"))
791 err(MOUNT_EX_SYSERR
, _("failed to append options"));
795 if (mnt_context_append_options(cxt
, optarg
))
796 err(MOUNT_EX_SYSERR
, _("failed to append options"));
799 if (mnt_context_set_options_pattern(cxt
, optarg
))
800 err(MOUNT_EX_SYSERR
, _("failed to set options pattern"));
803 warnx(_("--pass-fd is no longer supported"));
806 xasprintf(&srcbuf
, "LABEL=\"%s\"", optarg
);
807 mnt_context_disable_swapmatch(cxt
, 1);
808 mnt_context_set_source(cxt
, srcbuf
);
812 xasprintf(&srcbuf
, "UUID=\"%s\"", optarg
);
813 mnt_context_disable_swapmatch(cxt
, 1);
814 mnt_context_set_source(cxt
, srcbuf
);
824 fstab
= append_fstab(cxt
, fstab
, optarg
);
827 mnt_context_enable_sloppy(cxt
, TRUE
);
836 oper
|= (MS_BIND
| MS_REC
);
838 case MOUNT_OPT_SHARED
:
841 case MOUNT_OPT_SLAVE
:
844 case MOUNT_OPT_PRIVATE
:
847 case MOUNT_OPT_UNBINDABLE
:
848 oper
|= MS_UNBINDABLE
;
850 case MOUNT_OPT_RSHARED
:
851 oper
|= (MS_SHARED
| MS_REC
);
853 case MOUNT_OPT_RSLAVE
:
854 oper
|= (MS_SLAVE
| MS_REC
);
856 case MOUNT_OPT_RPRIVATE
:
857 oper
|= (MS_PRIVATE
| MS_REC
);
859 case MOUNT_OPT_RUNBINDABLE
:
860 oper
|= (MS_UNBINDABLE
| MS_REC
);
862 case MOUNT_OPT_TARGET
:
863 mnt_context_disable_swapmatch(cxt
, 1);
864 mnt_context_set_target(cxt
, optarg
);
866 case MOUNT_OPT_SOURCE
:
867 mnt_context_disable_swapmatch(cxt
, 1);
868 mnt_context_set_source(cxt
, optarg
);
879 if (!mnt_context_get_source(cxt
) &&
880 !mnt_context_get_target(cxt
) &&
885 print_all(cxt
, types
, show_labels
);
889 if (oper
&& (types
|| all
|| mnt_context_get_source(cxt
)))
892 if (types
&& (all
|| strchr(types
, ',') ||
893 strncmp(types
, "no", 2) == 0))
894 mnt_context_set_fstype_pattern(cxt
, types
);
896 mnt_context_set_fstype(cxt
, types
);
905 } else if (argc
== 0 && (mnt_context_get_source(cxt
) ||
906 mnt_context_get_target(cxt
))) {
908 * B) mount -L|-U|--source|--target
910 if (mnt_context_is_restricted(cxt
) &&
911 mnt_context_get_source(cxt
) &&
912 mnt_context_get_target(cxt
))
915 } else if (argc
== 1) {
917 * C) mount [-L|-U|--source] <target>
918 * mount <source|target>
920 * non-root may specify source *or* target, but not both
922 if (mnt_context_is_restricted(cxt
) &&
923 mnt_context_get_source(cxt
))
926 mnt_context_set_target(cxt
, argv
[0]);
928 } else if (argc
== 2 && !mnt_context_get_source(cxt
)
929 && !mnt_context_get_target(cxt
)) {
931 * D) mount <source> <target>
933 if (mnt_context_is_restricted(cxt
))
935 mnt_context_set_source(cxt
, argv
[0]);
936 mnt_context_set_target(cxt
, argv
[1]);
942 /* MS_PROPAGATION operations, let's set the mount flags */
943 mnt_context_set_mflags(cxt
, oper
);
945 /* For -make* or --bind is fstab unnecessary */
946 mnt_context_set_optsmode(cxt
, MNT_OMODE_NOTAB
);
949 rc
= mnt_context_mount(cxt
);
950 rc
= mk_exit_code(cxt
, rc
);
953 mnt_free_context(cxt
);
954 mnt_free_table(fstab
);