aboutsummaryrefslogtreecommitdiffstats
path: root/libmount/src
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2024-03-20 16:08:16 +0100
committerKarel Zak <kzak@redhat.com>2024-03-20 16:08:16 +0100
commit0c5485348b155420ecd1bfcdabb1b869ca5ee3c2 (patch)
tree05b05fa06d146b2fe4ea209e6380f1d1817c14f3 /libmount/src
parent7d16145c4696772bb5438a43a482f68fbf046370 (diff)
downloadutil-linux-0c5485348b155420ecd1bfcdabb1b869ca5ee3c2.tar.gz
libmount: make sure "option=" is used as string
mount(8) cares about case when option specified as "name=" (it means without data). See for example 727c689908c5e68c92aa1dd65e0d3bdb6d91c1e5. We need this also for new mount API and use FSCONFIG_SET_STRING rather than FSCONFIG_SET_FLAG. strace -e fsconfig ./mount -o usrjquota= /dev/sdc1 /mnt/test Old: fsconfig(3, FSCONFIG_SET_STRING, "source", "/dev/sdc1", 0) = 0 fsconfig(3, FSCONFIG_SET_FLAG, "usrjquota", NULL, 0) = -1 EINVAL (Invalid argument) Fixed: fsconfig(3, FSCONFIG_SET_STRING, "source", "/dev/sdc1", 0) = 0 fsconfig(3, FSCONFIG_SET_STRING, "usrjquota", "", 0) = 0 Fixes: https://github.com/util-linux/util-linux/issues/2837 Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src')
-rw-r--r--libmount/src/hook_mount.c3
-rw-r--r--libmount/src/mountP.h1
-rw-r--r--libmount/src/optlist.c14
3 files changed, 17 insertions, 1 deletions
diff --git a/libmount/src/hook_mount.c b/libmount/src/hook_mount.c
index 92438966c0..f0cc381963 100644
--- a/libmount/src/hook_mount.c
+++ b/libmount/src/hook_mount.c
@@ -224,6 +224,9 @@ static int configure_superblock(struct libmnt_context *cxt,
/* Ignore VFS flags, userspace and external options */
continue;
+ if (!value && mnt_opt_is_sepnodata(opt))
+ value = ""; /* force use the value as string */
+
rc = fsconfig_set_value(cxt, hs, fd, name, value);
if (rc != 0)
goto done;
diff --git a/libmount/src/mountP.h b/libmount/src/mountP.h
index 458aa1a00d..fcc40bffc5 100644
--- a/libmount/src/mountP.h
+++ b/libmount/src/mountP.h
@@ -608,6 +608,7 @@ extern int mnt_opt_set_value(struct libmnt_opt *opt, const char *str);
extern int mnt_opt_set_u64value(struct libmnt_opt *opt, uint64_t num);
extern int mnt_opt_set_quoted_value(struct libmnt_opt *opt, const char *str);
extern int mnt_opt_is_external(struct libmnt_opt *opt);
+extern int mnt_opt_is_sepnodata(struct libmnt_opt *opt);
/* fs.c */
extern int mnt_fs_follow_optlist(struct libmnt_fs *fs, struct libmnt_optlist *ol);
diff --git a/libmount/src/optlist.c b/libmount/src/optlist.c
index 101c908aef..476acfd656 100644
--- a/libmount/src/optlist.c
+++ b/libmount/src/optlist.c
@@ -46,6 +46,7 @@ struct libmnt_opt {
unsigned int external : 1, /* visible for external helpers only */
recursive : 1, /* recursive flag */
+ sepnodata : 1, /* value separator, but without data ("name=") */
is_linux : 1, /* defined in ls->linux_map (VFS attr) */
quoted : 1; /* name="value" */
};
@@ -438,6 +439,10 @@ static struct libmnt_opt *optlist_new_opt(struct libmnt_optlist *ls,
opt->value = strndup(value, valsz);
if (!opt->value)
goto fail;
+
+ } else if (value) {
+ /* separator specified, but empty value ("name=") */
+ opt->sepnodata = 1;
}
if (namesz) {
opt->name = strndup(name, namesz);
@@ -957,7 +962,8 @@ int mnt_optlist_strdup_optstr(struct libmnt_optlist *ls, char **optstr,
continue;
rc = mnt_buffer_append_option(&buf,
opt->name, strlen(opt->name),
- opt->value,
+ opt->value ? opt->value :
+ opt->sepnodata ? "" : NULL,
opt->value ? strlen(opt->value) : 0,
opt->quoted);
if (rc)
@@ -1043,6 +1049,7 @@ struct libmnt_optlist *mnt_copy_optlist(struct libmnt_optlist *ls)
no->src = opt->src;
no->external = opt->external;
no->quoted = opt->quoted;
+ no->sepnodata = opt->sepnodata;
}
}
@@ -1184,6 +1191,11 @@ int mnt_opt_is_external(struct libmnt_opt *opt)
return opt && opt->external ? 1 : 0;
}
+int mnt_opt_is_sepnodata(struct libmnt_opt *opt)
+{
+ return opt->sepnodata;
+}
+
#ifdef TEST_PROGRAM