From: Karel Zak Date: Thu, 31 Oct 2019 11:10:03 +0000 (+0100) Subject: libmount: allow use -o together with --all X-Git-Tag: v2.35-rc1~77 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=34333e5244167a8f6385faa350938ed5cb6d5c0a;p=thirdparty%2Futil-linux.git libmount: allow use -o together with --all For example: # mount --verbose --all -t xfs -o ro will mount all all XFS filesystems from fstab, but read-only. Signed-off-by: Karel Zak --- diff --git a/libmount/src/context_mount.c b/libmount/src/context_mount.c index ae72929330..70a843e89b 100644 --- a/libmount/src/context_mount.c +++ b/libmount/src/context_mount.c @@ -1291,11 +1291,6 @@ int mnt_context_next_mount(struct libmnt_context *cxt, if (!cxt || !fs || !itr) return -EINVAL; - mtab = cxt->mtab; - cxt->mtab = NULL; /* do not reset mtab */ - mnt_reset_context(cxt); - cxt->mtab = mtab; - rc = mnt_context_get_fstab(cxt, &fstab); if (rc) return rc; @@ -1346,6 +1341,23 @@ int mnt_context_next_mount(struct libmnt_context *cxt, return 0; } + /* Save mount options, etc. -- this is effective for the first + * mnt_context_next_mount() call only. Make sure that cxt has not set + * source, target or fstype. + */ + if (!mnt_context_has_template(cxt)) { + mnt_context_set_source(cxt, NULL); + mnt_context_set_target(cxt, NULL); + mnt_context_set_fstype(cxt, NULL); + mnt_context_save_template(cxt); + } + + /* reset context, but protect mtab */ + mtab = cxt->mtab; + cxt->mtab = NULL; + mnt_reset_context(cxt); + cxt->mtab = mtab; + if (mnt_context_is_fork(cxt)) { rc = mnt_fork_context(cxt); if (rc) @@ -1356,9 +1368,12 @@ int mnt_context_next_mount(struct libmnt_context *cxt, } } - /* child or non-forked */ + /* + * child or non-forked + */ - rc = mnt_context_set_fs(cxt, *fs); + /* copy stuff from fstab to context */ + rc = mnt_context_apply_fs(cxt, *fs); if (!rc) { /* * "-t " is used to filter out fstab entries, but for ordinary @@ -1470,8 +1485,16 @@ int mnt_context_next_remount(struct libmnt_context *cxt, return 0; } - if (!mnt_context_has_template(cxt)) + /* Save mount options, etc. -- this is effective for the first + * mnt_context_next_remount() call only. Make sure that cxt has not set + * source, target or fstype. + */ + if (!mnt_context_has_template(cxt)) { + mnt_context_set_source(cxt, NULL); + mnt_context_set_target(cxt, NULL); + mnt_context_set_fstype(cxt, NULL); mnt_context_save_template(cxt); + } /* restore original, but protect mtab */ cxt->mtab = NULL; diff --git a/sys-utils/mount.8 b/sys-utils/mount.8 index 7b3f876617..75d90e4e9b 100644 --- a/sys-utils/mount.8 +++ b/sys-utils/mount.8 @@ -583,6 +583,9 @@ The option \fB\-\-all\fR is possible to use for remount operation too. In this case all filters (\fB\-t\fR and \fB\-O\fR) are applied to the table of already mounted filesystems. .sp +Since version 2.35 is possible to use the command line option \fB\-o\fR to +alter mount options from fstab (see also \fB\-\-options\-mode\fR). +.sp Note that it is a bad practice to use \fBmount \-a\fR for .I fstab checking. The recommended solution is \fBfindmnt \-\-verify\fR.