diff options
| author | Richard Maw <richard.maw@codethink.co.uk> | 2014-06-12 12:04:01 +0100 |
|---|---|---|
| committer | Richard Maw <richard.maw@codethink.co.uk> | 2014-06-12 12:04:01 +0100 |
| commit | c5c1033c5c7deda8abe3448ec81bbb33c72219e0 (patch) | |
| tree | 6e5cef29b85161eea8a7488a029f5a32f982c6ab /sys-utils/mount.c | |
| parent | 462008f79be9e195670b202cb43827b8aeb1e60b (diff) | |
| parent | 2fb567c080e1762ec6a2147564f03068f55d4f14 (diff) | |
| download | util-linux-baserock/morph.tar.gz | |
Merge branch 'baserock/richardmaw/yakshave/util-linux-blkid' into baserock/morphbaserock/morph
Reviewed-by: Lars Wirzenius
Reviewed-by: Sam Thursfield
Diffstat (limited to 'sys-utils/mount.c')
| -rw-r--r-- | sys-utils/mount.c | 48 |
1 files changed, 36 insertions, 12 deletions
diff --git a/sys-utils/mount.c b/sys-utils/mount.c index 8ff94611c..97365b168 100644 --- a/sys-utils/mount.c +++ b/sys-utils/mount.c @@ -163,7 +163,7 @@ static void print_all(struct libmnt_context *cxt, char *pattern, int show_label) free(xsrc); } - mnt_free_cache(cache); + mnt_unref_cache(cache); mnt_free_iter(itr); } @@ -197,12 +197,14 @@ static int mount_all(struct libmnt_context *cxt) if (mnt_context_is_verbose(cxt)) printf("%-25s: mount successfully forked\n", tgt); } else { - mk_exit_code(cxt, mntrc); /* to print warnings */ - - if (mnt_context_get_status(cxt)) { + if (mk_exit_code(cxt, mntrc) == MOUNT_EX_SUCCESS) { nsucc++; - if (mnt_context_is_verbose(cxt)) + /* Note that MOUNT_EX_SUCCESS return code does + * not mean that FS has been really mounted + * (e.g. nofail option) */ + if (mnt_context_get_status(cxt) + && mnt_context_is_verbose(cxt)) printf("%-25s: successfully mounted\n", tgt); } else nerrs++; @@ -429,6 +431,8 @@ try_readonly: warnx(_("you must specify the filesystem type")); return MOUNT_EX_USAGE; case -MNT_ERR_NOSOURCE: + if (uflags & MNT_MS_NOFAIL) + return MOUNT_EX_SUCCESS; if (src) warnx(_("can't find %s"), src); else @@ -641,6 +645,8 @@ static struct libmnt_table *append_fstab(struct libmnt_context *cxt, mnt_table_set_parser_errcb(fstab, table_parser_errcb); mnt_context_set_fstab(cxt, fstab); + + mnt_unref_table(fstab); /* reference is handled by @cxt now */ } if (mnt_table_parse_fstab(fstab, path)) @@ -682,6 +688,8 @@ static void sanitize_paths(struct libmnt_context *cxt) static void append_option(struct libmnt_context *cxt, const char *opt) { + if (opt && (*opt == '=' || *opt == '\'' || *opt == '\"' || isblank(*opt))) + errx(MOUNT_EX_USAGE, _("unsupported option format: %s"), opt); if (mnt_context_append_options(cxt, opt)) err(MOUNT_EX_SYSERR, _("failed to append option '%s'"), opt); } @@ -988,8 +996,7 @@ int main(int argc, char **argv) * make a connection between the fstab and the canonicalization * cache. */ - struct libmnt_cache *cache = mnt_context_get_cache(cxt); - mnt_table_set_cache(fstab, cache); + mnt_table_set_cache(fstab, mnt_context_get_cache(cxt)); } if (!mnt_context_get_source(cxt) && @@ -1027,25 +1034,42 @@ int main(int argc, char **argv) mnt_context_get_target(cxt))) { /* * B) mount -L|-U|--source|--target + * + * non-root may specify source *or* target, but not both */ if (mnt_context_is_restricted(cxt) && mnt_context_get_source(cxt) && mnt_context_get_target(cxt)) exit_non_root(NULL); - } else if (argc == 1) { + } else if (argc == 1 && (!mnt_context_get_source(cxt) || + !mnt_context_get_target(cxt))) { /* * C) mount [-L|-U|--source] <target> + * mount [--target <dir>] <source> * mount <source|target> * * non-root may specify source *or* target, but not both + * + * It does not matter for libmount if we set source or target + * here (the library is able to swap it), but it matters for + * sanitize_paths(). */ + int istag = mnt_tag_is_valid(argv[0]); + + if (istag && mnt_context_get_source(cxt)) + /* -L, -U or --source together with LABEL= or UUID= */ + errx(MOUNT_EX_USAGE, _("source specified more than once")); + else if (istag || mnt_context_get_target(cxt)) + mnt_context_set_source(cxt, argv[0]); + else + mnt_context_set_target(cxt, argv[0]); + if (mnt_context_is_restricted(cxt) && - mnt_context_get_source(cxt)) + mnt_context_get_source(cxt) && + mnt_context_get_target(cxt)) exit_non_root(NULL); - mnt_context_set_target(cxt, argv[0]); - } else if (argc == 2 && !mnt_context_get_source(cxt) && !mnt_context_get_target(cxt)) { /* @@ -1053,6 +1077,7 @@ int main(int argc, char **argv) */ if (mnt_context_is_restricted(cxt)) exit_non_root(NULL); + mnt_context_set_source(cxt, argv[0]); mnt_context_set_target(cxt, argv[1]); @@ -1077,7 +1102,6 @@ int main(int argc, char **argv) success_message(cxt); done: mnt_free_context(cxt); - mnt_free_table(fstab); return rc; } |
