]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
statmount: add flag to retrieve unescaped options
authorMiklos Szeredi <mszeredi@redhat.com>
Tue, 12 Nov 2024 10:10:04 +0000 (11:10 +0100)
committerChristian Brauner <brauner@kernel.org>
Wed, 13 Nov 2024 16:27:02 +0000 (17:27 +0100)
commit2f4d4503e9e5ab765a7948f98bc5deef7850f607
tree6a5bb5fb883eb226e80f47024c5a6236d7e551be
parent39bb1bf0b49495e70d0763a143ad889925c3d373
statmount: add flag to retrieve unescaped options

Filesystem options can be retrieved with STATMOUNT_MNT_OPTS, which
returns a string of comma separated options, where some characters are
escaped using the \OOO notation.

Add a new flag, STATMOUNT_OPT_ARRAY, which instead returns the raw
option values separated with '\0' charaters.

Since escaped charaters are rare, this inteface is preferable for
non-libmount users which likley don't want to deal with option
de-escaping.

Example code:

if (st->mask & STATMOUNT_OPT_ARRAY) {
const char *opt = st->str + st->opt_array;

for (unsigned int i = 0; i < st->opt_num; i++) {
printf("opt_array[%i]: <%s>\n", i, opt);
opt += strlen(opt) + 1;
}
}

Example ouput:

(1) mnt_opts: <lowerdir+=/l\054w\054r,lowerdir+=/l\054w\054r1,upperdir=/upp\054r,workdir=/w\054rk,redirect_dir=nofollow,uuid=null>

(2) opt_array[0]: <lowerdir+=/l,w,r>
    opt_array[1]: <lowerdir+=/l,w,r1>
    opt_array[2]: <upperdir=/upp,r>
    opt_array[3]: <workdir=/w,rk>
    opt_array[4]: <redirect_dir=nofollow>
    opt_array[5]: <uuid=null>

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Link: https://lore.kernel.org/r/20241112101006.30715-1-mszeredi@redhat.com
Acked-by: Jeff Layton <jlayton@kernel.org>
[brauner: tweak variable naming and parsing add example output]
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/namespace.c
include/uapi/linux/mount.h