]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: add mnt_optlist_remove_flags() and mnt_opt_set_external()
authorKarel Zak <kzak@redhat.com>
Thu, 14 Jul 2022 09:00:45 +0000 (11:00 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 3 Jan 2023 11:58:36 +0000 (12:58 +0100)
- add mnt_optlist_remove_flags() to make it easy to work with flags
- add mnt_opt_set_external() to hidde unnecessary options
- clean up private library header file

Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/mountP.h
libmount/src/optlist.c

index d8926ffaab6c7607d85a3a63bb154e9985f57075..d2e371ceb8acad790393b08b8a2de7ada7ee3817 100644 (file)
@@ -417,7 +417,6 @@ struct libmnt_context
 
        unsigned int    enabled_textdomain : 1; /* bindtextdomain() called */
        unsigned int    noautofs : 1;           /* ignore autofs mounts */
-       unsigned int    is_propagation_only : 1;
 
        struct list_head        hooksets_datas; /* global hooksets data */
        struct list_head        hooksets_hooks; /* global hooksets data */
@@ -488,6 +487,8 @@ extern int mnt_optlist_register_map(struct libmnt_optlist *ls, const struct libm
 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_remove_flags(struct libmnt_optlist *ls, unsigned long flags,
+                        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,
@@ -515,6 +516,7 @@ extern int mnt_optlist_get_optstr(struct libmnt_optlist *ol, const char **optstr
 extern int mnt_optlist_get_propagation(struct libmnt_optlist *ls);
 extern int mnt_optlist_is_propagation_only(struct libmnt_optlist *ls);
 extern int mnt_opt_has_value(struct libmnt_opt *opt);
+extern int mnt_opt_set_external(struct libmnt_opt *opt, int enable);
 extern int mnt_optlist_merge_opts(struct libmnt_optlist *ls);
 
 
index 90de6d264f94ffc36b9b5e95347ead33d70ca4b2..cd2313babaae8b0b0c487b0216c0d40690fa5b97 100644 (file)
@@ -511,6 +511,29 @@ int mnt_optlist_set_flags(struct libmnt_optlist *ls, unsigned long flags,
        return mnt_optlist_append_flags(ls, flags, map);
 }
 
+int mnt_optlist_remove_flags(struct libmnt_optlist *ls, unsigned long flags,
+                       const struct libmnt_optmap *map)
+{
+       struct list_head *p, *next;
+
+       if (!ls || !map)
+               return -EINVAL;
+
+       DBG(OPTLIST, ul_debugobj(ls, "remove 0x%08lx", flags));
+
+       list_for_each_safe(p, next, &ls->opts) {
+               struct libmnt_opt *opt = list_entry(p, struct libmnt_opt, opts);
+
+               if (opt->external || !opt->ent)
+                       continue;
+               if (map && opt->map != map)
+                       continue;
+               if (opt->ent->id & flags)
+                       mnt_optlist_remove_opt(ls, opt);
+       }
+       return 0;
+}
+
 int mnt_optlist_insert_flags(struct libmnt_optlist *ls, unsigned long flags,
                        const struct libmnt_optmap *map,
                        unsigned long after,
@@ -640,6 +663,14 @@ int mnt_opt_has_value(struct libmnt_opt *opt)
        return opt && opt->value;
 }
 
+int mnt_opt_set_external(struct libmnt_opt *opt, int enable)
+{
+       if (!opt)
+               return -EINVAL;
+       opt->external = enable ? 1 : 0;
+       return 0;
+}
+
 #ifdef TEST_PROGRAM
 
 static int mk_optlist(struct libmnt_optlist **ol, const char *optstr)