From: Karel Zak Date: Wed, 13 Jul 2022 14:04:58 +0000 (+0200) Subject: libmount: apply fstab options to context optlist X-Git-Tag: v2.39-rc1~322 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1017f628c0d6d49897e6d6cabf78e19a591e1528;p=thirdparty%2Futil-linux.git libmount: apply fstab options to context optlist Signed-off-by: Karel Zak --- diff --git a/libmount/src/context.c b/libmount/src/context.c index e3bcc495fc..23228a39e7 100644 --- a/libmount/src/context.c +++ b/libmount/src/context.c @@ -2205,6 +2205,7 @@ end: */ static int apply_fs(struct libmnt_context *cxt, struct libmnt_fs *fs, unsigned long mflags) { + struct libmnt_optlist *ls; int rc; if (!cxt->optsmode) { @@ -2241,28 +2242,34 @@ static int apply_fs(struct libmnt_context *cxt, struct libmnt_fs *fs, unsigned l if (rc) goto done; + ls = mnt_context_get_optlist(cxt); + if (!ls) { + rc = -ENOMEM; + goto done; + } + if (cxt->optsmode & MNT_OMODE_IGNORE) ; else if (cxt->optsmode & MNT_OMODE_REPLACE) { - rc = mnt_fs_set_options(cxt->fs, mnt_fs_get_options(fs)); + rc = mnt_optlist_set_optstr(ls, mnt_fs_get_options(fs), NULL); /* mount --read-only for non-root users is allowed */ if (rc == 0 && (mflags & MS_RDONLY) && mnt_context_is_restricted(cxt) && cxt->optsmode == MNT_OMODE_USER) - rc = mnt_fs_append_options(cxt->fs, "ro"); + rc = mnt_optlist_append_optstr(ls, "ro", NULL); } else if (cxt->optsmode & MNT_OMODE_APPEND) - rc = mnt_fs_append_options(cxt->fs, mnt_fs_get_options(fs)); + rc = mnt_optlist_append_optstr(ls, mnt_fs_get_options(fs), NULL); else if (cxt->optsmode & MNT_OMODE_PREPEND) - rc = mnt_fs_prepend_options(cxt->fs, mnt_fs_get_options(fs)); + rc = mnt_optlist_prepend_optstr(ls, mnt_fs_get_options(fs), NULL); if (!rc) cxt->flags |= MNT_FL_TAB_APPLIED; done: - DBG(CXT, ul_debugobj(cxt, "final entry [rc=%d]:", rc)); + DBG(CXT, ul_debugobj(cxt, "final entry [rc=%d]", rc)); DBG(CXT, mnt_fs_print_debug(cxt->fs, stderr)); return rc; @@ -2428,10 +2435,10 @@ int mnt_context_apply_fstab(struct libmnt_context *cxt) rc = -MNT_ERR_NOFSTAB; - } else if (isremount && !iscmdbind) { + } else if (isremount && !iscmdbind && cxt->optlist) { - /* remove "bind" from fstab (or no-op if not present) */ - mnt_optstr_remove_option(&cxt->fs->optstr, "bind"); + /* ignore "bind" on remount when the flag is read from fstab */ + mnt_optlist_remove_named(cxt->optlist, "bind", NULL); } return rc; } diff --git a/libmount/src/mountP.h b/libmount/src/mountP.h index 669a3360c6..d8926ffaab 100644 --- a/libmount/src/mountP.h +++ b/libmount/src/mountP.h @@ -486,12 +486,14 @@ extern void mnt_ref_optlist(struct libmnt_optlist *ls); extern void mnt_unref_optlist(struct libmnt_optlist *ls); extern int mnt_optlist_register_map(struct libmnt_optlist *ls, const struct libmnt_optmap *map); extern int mnt_optlist_remove_opt(struct libmnt_optlist *ls, struct libmnt_opt *opt); +extern int mnt_optlist_remove_named(struct libmnt_optlist *ls, const char *name, + const struct libmnt_optmap *map); extern int mnt_optlist_next_opt(struct libmnt_optlist *ls, struct libmnt_iter *itr, struct libmnt_opt **opt); extern struct libmnt_opt *mnt_optlist_get_opt(struct libmnt_optlist *ls, unsigned long id, const struct libmnt_optmap *map); extern struct libmnt_opt *mnt_optlist_get_named(struct libmnt_optlist *ls, - char *name, const struct libmnt_optmap *map); + const char *name, const struct libmnt_optmap *map); extern int mnt_optlist_set_optstr(struct libmnt_optlist *ls, const char *optstr, const struct libmnt_optmap *map); extern int mnt_optlist_append_optstr(struct libmnt_optlist *ls, const char *optstr, diff --git a/libmount/src/optlist.c b/libmount/src/optlist.c index ce2712e323..90de6d264f 100644 --- a/libmount/src/optlist.c +++ b/libmount/src/optlist.c @@ -174,6 +174,14 @@ int mnt_optlist_remove_opt(struct libmnt_optlist *ls, struct libmnt_opt *opt) return 0; } +int mnt_optlist_remove_named(struct libmnt_optlist *ls, const char *name, + const struct libmnt_optmap *map) +{ + struct libmnt_opt *opt = mnt_optlist_get_named(ls, name, map); + + return opt ? mnt_optlist_remove_opt(ls, opt) : 0; +} + int mnt_optlist_next_opt(struct libmnt_optlist *ls, struct libmnt_iter *itr, struct libmnt_opt **opt) { @@ -214,7 +222,7 @@ struct libmnt_opt *mnt_optlist_get_opt(struct libmnt_optlist *ls, } struct libmnt_opt *mnt_optlist_get_named(struct libmnt_optlist *ls, - char *name, const struct libmnt_optmap *map) + const char *name, const struct libmnt_optmap *map) { struct libmnt_iter itr; struct libmnt_opt *opt;