]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: (optlist) add new shortcuts, fix add_flags()
authorKarel Zak <kzak@redhat.com>
Mon, 22 Aug 2022 13:08:33 +0000 (15:08 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 3 Jan 2023 11:58:42 +0000 (12:58 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/mountP.h
libmount/src/optlist.c

index 05e2e84781a45feacafcb3729efe1ed98358c085..82a206201fe10ef4bbbac289723ed9b682ec9e83 100644 (file)
@@ -534,6 +534,10 @@ extern int mnt_optlist_strdup_optstr(struct libmnt_optlist *ls, 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_optlist_is_remount(struct libmnt_optlist *ls);
+extern int mnt_optlist_is_bind(struct libmnt_optlist *ls);
+extern int mnt_optlist_is_move(struct libmnt_optlist *ls);
+extern int mnt_optlist_is_rdonly(struct libmnt_optlist *ls);
+
 extern int mnt_optlist_merge_opts(struct libmnt_optlist *ls);
 
 extern int mnt_opt_has_value(struct libmnt_opt *opt);
index 8569d9827b972cffe01322f0d5ee97e6bffdc1df..b6e7e5cd8f9d1ae9f07e7ea464a1a33a9264a885 100644 (file)
@@ -51,8 +51,11 @@ struct libmnt_optlist {
        unsigned long           propagation;    /* propagation MS_ flags */
        struct list_head        opts;           /* parsed options */
 
-       unsigned int merged : 1,                /* don't care about MNT_OPTSRC_* */
-                    remount : 1;
+       unsigned int    merged : 1,             /* don't care about MNT_OPTSRC_* */
+                       is_remount : 1,
+                       is_bind : 1,
+                       is_rdonly : 1,
+                       is_move : 1;
 };
 
 struct libmnt_optlist *mnt_new_optlist(void)
@@ -171,7 +174,13 @@ int mnt_optlist_remove_opt(struct libmnt_optlist *ls, struct libmnt_opt *opt)
                if (opt->ent->id & MS_PROPAGATION)
                        ls->propagation &= ~opt->ent->id;
                else if (opt->ent->id == MS_REMOUNT)
-                       ls->remount = 0;
+                       ls->is_remount = 0;
+               else if (opt->ent->id == MS_BIND)
+                       ls->is_bind = 0;
+               else if (opt->ent->id == MS_RDONLY)
+                       ls->is_rdonly = 0;
+               else if (opt->ent->id == MS_MOVE)
+                       ls->is_move = 0;
        }
 
        optlist_cleanup_cache(ls, opt->map);
@@ -359,8 +368,14 @@ static struct libmnt_opt *optlist_new_opt(struct libmnt_optlist *ls,
        if (map && ent && map == ls->linux_map) {
                if (ent->id & MS_PROPAGATION)
                        ls->propagation |= ent->id;
-               else if (ent->id == MS_REMOUNT)
-                       ls->remount = 1;
+               else if (opt->ent->id == MS_REMOUNT)
+                       ls->is_remount = 1;
+               else if (opt->ent->id == MS_BIND)
+                       ls->is_bind = 1;
+               else if (opt->ent->id == MS_RDONLY)
+                       ls->is_rdonly = 1;
+               else if (opt->ent->id == MS_MOVE)
+                       ls->is_move = 1;
        }
 
        if (ent && map) {
@@ -495,6 +510,7 @@ static int optlist_add_flags(struct libmnt_optlist *ls, unsigned long flags,
                        else
                                continue;       /* name=<value> */
                        sz = p - ent->name;
+                       p -= sz;
                } else {
                        p = (char *) ent->name;
                        sz = strlen(ent->name); /* alone "name" */
@@ -771,9 +787,25 @@ int mnt_optlist_is_propagation_only(struct libmnt_optlist *ls)
 
 int mnt_optlist_is_remount(struct libmnt_optlist *ls)
 {
-       return ls && ls->remount;
+       return ls && ls->is_remount;
+}
+
+int mnt_optlist_is_move(struct libmnt_optlist *ls)
+{
+       return ls && ls->is_move;
 }
 
+int mnt_optlist_is_bind(struct libmnt_optlist *ls)
+{
+       return ls && ls->is_bind;
+}
+
+int mnt_optlist_is_rdonly(struct libmnt_optlist *ls)
+{
+       return ls && ls->is_rdonly;
+}
+
+
 int mnt_opt_has_value(struct libmnt_opt *opt)
 {
        return opt && opt->value;