]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: (mount) use optlist for mount(2) options and flags
authorKarel Zak <kzak@redhat.com>
Thu, 18 Aug 2022 11:46:38 +0000 (13:46 +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/context_mount.c
libmount/src/hook_mount_legacy.c

index e8ec1307b7ed0ada4897ba9454677cc0d9078d8e..b3e5b19e4f0547a29b8781a8b1aba7945f68f5e3 100644 (file)
@@ -908,9 +908,6 @@ int mnt_context_do_mount(struct libmnt_context *cxt)
 
        DBG(CXT, ul_debugobj(cxt, "mount: do mount"));
 
-       if (!(cxt->flags & MNT_FL_MOUNTDATA))
-               cxt->mountdata = (char *) mnt_fs_get_fs_options(cxt->fs);
-
        ns_old = mnt_context_switch_target_ns(cxt);
        if (!ns_old)
                return -MNT_ERR_NAMESPACE;
index 63c0262a732ba8da574b7d2a6c076fdf32d588d9..9b24bdf30ba3dbe7b64094d6ca72a882f3c708a1 100644 (file)
@@ -211,22 +211,40 @@ static int hook_mount(struct libmnt_context *cxt,
                      void *data __attribute__((__unused__)))
 {
        int rc = 0;
-       const char *src, *target, *type;
+       unsigned long flags = 0;
+       struct libmnt_optlist *ol = NULL;
+       const char *src, *target, *type, *options = NULL;
 
        src = mnt_fs_get_srcpath(cxt->fs);
        target = mnt_fs_get_target(cxt->fs);
        type = mnt_fs_get_fstype(cxt->fs);
 
+       ol = mnt_context_get_optlist(cxt);
+       if (!ol)
+               return -ENOMEM;
        if (!target)
                return -EINVAL;
        if (!src)
                src = "none";
 
+       /* FS specific mount options/data */
+       if (cxt->flags & MNT_FL_MOUNTDATA)
+               options = cxt->mountdata;
+       else
+               rc = mnt_optlist_get_optstr(ol, &options,
+                               NULL, MNT_OL_FLTR_UNKNOWN);
+       /* mount flags */
+       if (!rc)
+               rc = mnt_optlist_get_flags(ol, &flags,
+                               mnt_get_builtin_optmap(MNT_LINUX_MAP), 0);
+       if (rc)
+               return rc;
+
        DBG(HOOK, ul_debugobj(hs, "  mount(2) "
-               "[source=%s, target=%s, type=%s,"
-               " mountflags=0x%08lx, mountdata=%s]",
-               src, target, type,
-               cxt->mountflags, cxt->mountdata ? "yes" : "<none>"));
+               "[source=%s, target=%s, type=%s, flags=0x%08lx, options=%s]",
+               src, target, type, flags,
+               options ? (cxt->flags & MNT_FL_MOUNTDATA) ? "binary" :
+                         options : "<none>"));
 
        if (mnt_context_is_fake(cxt)) {
                DBG(HOOK, ul_debugobj(hs, " FAKE (-f)"));
@@ -234,7 +252,7 @@ static int hook_mount(struct libmnt_context *cxt,
                return 0;
        }
 
-       if (mount(src, target, type, cxt->mountflags, cxt->mountdata)) {
+       if (mount(src, target, type, flags, options)) {
                cxt->syscall_status = -errno;
                DBG(HOOK, ul_debugobj(hs, "  mount(2) failed [errno=%d %m]",
                                        -cxt->syscall_status));