From e5149d3b22f7ac913850d4e69b8523c3771e0716 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 18 Aug 2022 13:46:38 +0200 Subject: [PATCH] libmount: (mount) use optlist for mount(2) options and flags Signed-off-by: Karel Zak --- libmount/src/context_mount.c | 3 --- libmount/src/hook_mount_legacy.c | 30 ++++++++++++++++++++++++------ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/libmount/src/context_mount.c b/libmount/src/context_mount.c index e8ec1307b7..b3e5b19e4f 100644 --- a/libmount/src/context_mount.c +++ b/libmount/src/context_mount.c @@ -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; diff --git a/libmount/src/hook_mount_legacy.c b/libmount/src/hook_mount_legacy.c index 63c0262a73..9b24bdf30b 100644 --- a/libmount/src/hook_mount_legacy.c +++ b/libmount/src/hook_mount_legacy.c @@ -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" : "")); + "[source=%s, target=%s, type=%s, flags=0x%08lx, options=%s]", + src, target, type, flags, + options ? (cxt->flags & MNT_FL_MOUNTDATA) ? "binary" : + options : "")); 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)); -- 2.47.3