From d74ae8266fc052033cef8252dc607e97994dd74e Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 14 Jul 2022 11:00:45 +0200 Subject: [PATCH] libmount: add mnt_optlist_remove_flags() and mnt_opt_set_external() - 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 --- libmount/src/mountP.h | 4 +++- libmount/src/optlist.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/libmount/src/mountP.h b/libmount/src/mountP.h index d8926ffaab..d2e371ceb8 100644 --- a/libmount/src/mountP.h +++ b/libmount/src/mountP.h @@ -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); diff --git a/libmount/src/optlist.c b/libmount/src/optlist.c index 90de6d264f..cd2313baba 100644 --- a/libmount/src/optlist.c +++ b/libmount/src/optlist.c @@ -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) -- 2.47.3