]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: apply fstab options to context optlist
authorKarel Zak <kzak@redhat.com>
Wed, 13 Jul 2022 14:04:58 +0000 (16:04 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 3 Jan 2023 11:53:12 +0000 (12:53 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/context.c
libmount/src/mountP.h
libmount/src/optlist.c

index e3bcc495fc6945cac98a7fd24ba4182a291ec87c..23228a39e78a0a763d3b3e0d83cc4822a56a0422 100644 (file)
@@ -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;
 }
index 669a3360c656bd369e1a2b4b7ac70136f2597377..d8926ffaab6c7607d85a3a63bb154e9985f57075 100644 (file)
@@ -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,
index ce2712e3237469bd9880b5d3b9bc000e8fc59529..90de6d264f94ffc36b9b5e95347ead33d70ca4b2 100644 (file)
@@ -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;