From: Bernd Schubert <bernd@bsbernd.com>
To: linux-fsdevel@vger.kernel.org
Cc: Miklos Szeredi <miklos@szeredi.hu>,
Joanne Koong <joannelkoong@gmail.com>,
"Darrick J. Wong" <djwong@kernel.org>,
Bernd Schubert <bernd@bsbernd.com>,
Bernd Schubert <bschubert@ddn.com>
Subject: [PATCH 16/19] fusermount: Refactor extract_x_options
Date: Mon, 23 Mar 2026 18:45:11 +0100 [thread overview]
Message-ID: <20260323-fuse-init-before-mount-v1-16-a52d3040af69@bsbernd.com> (raw)
In-Reply-To: <20260323-fuse-init-before-mount-v1-0-a52d3040af69@bsbernd.com>
From: Bernd Schubert <bschubert@ddn.com>
Just to make it better readable.
Also add a NULL check for *regular_opts and *x_prefixed_opts,
there will be multiple callers in an upcoming commit and
it becomes harder to track that no caller has an error.
Signed-off-by: Bernd Schubert <bschubert@ddn.com>
---
util/fusermount.c | 58 ++++++++++++++++++++++++++++++++-----------------------
1 file changed, 34 insertions(+), 24 deletions(-)
diff --git a/util/fusermount.c b/util/fusermount.c
index ecf509bb80d5cd129f6e582f1ec666502c55603a..80b42a594e89cdc2f43824f5e274892522fd8cce 100644
--- a/util/fusermount.c
+++ b/util/fusermount.c
@@ -112,22 +112,31 @@ static struct mntent *GETMNTENT(FILE *stream)
/*
* Take a ',' separated option string and extract "x-" options
+ * @original: The original option string
+ * @regular_opts: The regular options
+ * @x_prefixed_opts: The "x-" options
*/
-static int extract_x_options(const char *original, char **non_x_opts,
- char **x_opts)
+static int extract_x_options(const char *original, char **regular_opts,
+ char **x_prefixed_opts)
{
size_t orig_len;
const char *opt, *opt_end;
orig_len = strlen(original) + 1;
- *non_x_opts = calloc(1, orig_len);
- *x_opts = calloc(1, orig_len);
+ if (*regular_opts != NULL || *x_prefixed_opts != NULL) {
+ fprintf(stderr, "%s: regular_opts or x_prefixed_opts not NULL\n",
+ __func__);
+ return -EINVAL;
+ }
- size_t non_x_opts_len = orig_len;
- size_t x_opts_len = orig_len;
+ *regular_opts = calloc(1, orig_len);
+ *x_prefixed_opts = calloc(1, orig_len);
- if (*non_x_opts == NULL || *x_opts == NULL) {
+ size_t regular_opts_len = orig_len;
+ size_t x_prefixed_opts_len = orig_len;
+
+ if (*regular_opts == NULL || *x_prefixed_opts == NULL) {
fprintf(stderr, "%s: Failed to allocate %zuB.\n",
__func__, orig_len);
return -ENOMEM;
@@ -143,16 +152,16 @@ static int extract_x_options(const char *original, char **non_x_opts,
size_t opt_len = opt_end - opt;
size_t opt_len_left = orig_len - (opt - original);
size_t buf_len;
- bool is_x_opts;
+ bool is_x_prefixed_opts;
if (strncmp(opt, "x-", MIN(2, opt_len_left)) == 0) {
- buf_len = x_opts_len;
- is_x_opts = true;
- opt_buf = *x_opts;
+ buf_len = x_prefixed_opts_len;
+ is_x_prefixed_opts = true;
+ opt_buf = *x_prefixed_opts;
} else {
- buf_len = non_x_opts_len;
- is_x_opts = false;
- opt_buf = *non_x_opts;
+ buf_len = regular_opts_len;
+ is_x_prefixed_opts = false;
+ opt_buf = *regular_opts;
}
if (buf_len < orig_len) {
@@ -163,7 +172,8 @@ static int extract_x_options(const char *original, char **non_x_opts,
/* omits ',' */
if ((ssize_t)(buf_len - opt_len) < 0) {
/* This would be a bug */
- fprintf(stderr, "%s: no buf space left in copy, orig='%s'\n",
+ fprintf(stderr,
+ "%s: no buf space left in copy, orig='%s'\n",
__func__, original);
return -EIO;
}
@@ -171,10 +181,10 @@ static int extract_x_options(const char *original, char **non_x_opts,
strncat(opt_buf, opt, opt_end - opt);
buf_len -= opt_len;
- if (is_x_opts)
- x_opts_len = buf_len;
+ if (is_x_prefixed_opts)
+ x_prefixed_opts_len = buf_len;
else
- non_x_opts_len = buf_len;
+ regular_opts_len = buf_len;
}
return 0;
@@ -1379,7 +1389,7 @@ static int mount_fuse(const char *mnt, const char *opts, const char **type)
const char *real_mnt = mnt;
int mountpoint_fd = -1;
char *do_mount_opts = NULL;
- char *x_opts = NULL;
+ char *x_prefixed_opts = NULL;
fd = open_fuse_device(dev);
if (fd == -1)
@@ -1397,7 +1407,7 @@ static int mount_fuse(const char *mnt, const char *opts, const char **type)
}
// Extract any options starting with "x-"
- res= extract_x_options(opts, &do_mount_opts, &x_opts);
+ res = extract_x_options(opts, &do_mount_opts, &x_prefixed_opts);
if (res)
goto fail_close_fd;
@@ -1420,14 +1430,14 @@ static int mount_fuse(const char *mnt, const char *opts, const char **type)
}
if (geteuid() == 0) {
- if (x_opts && strlen(x_opts) > 0) {
+ if (x_prefixed_opts && strlen(x_prefixed_opts) > 0) {
/*
* Add back the options starting with "x-" to opts from
* do_mount. +2 for ',' and '\0'
*/
size_t mnt_opts_len = strlen(mnt_opts);
size_t x_mnt_opts_len = mnt_opts_len+
- strlen(x_opts) + 2;
+ strlen(x_prefixed_opts) + 2;
char *x_mnt_opts = calloc(1, x_mnt_opts_len);
if (mnt_opts_len) {
@@ -1435,7 +1445,7 @@ static int mount_fuse(const char *mnt, const char *opts, const char **type)
strncat(x_mnt_opts, ",", 2);
}
- strncat(x_mnt_opts, x_opts,
+ strncat(x_mnt_opts, x_prefixed_opts,
x_mnt_opts_len - mnt_opts_len - 2);
free(mnt_opts);
@@ -1452,7 +1462,7 @@ static int mount_fuse(const char *mnt, const char *opts, const char **type)
out_free:
free(source);
free(mnt_opts);
- free(x_opts);
+ free(x_prefixed_opts);
free(do_mount_opts);
return fd;
--
2.43.0
next prev parent reply other threads:[~2026-03-23 18:18 UTC|newest]
Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-23 17:44 [PATCH 00/19] libfuse: Add support for synchronous init Bernd Schubert
2026-03-23 17:44 ` [PATCH 01/19] ci-build: Add environment logging Bernd Schubert
2026-03-23 17:44 ` [PATCH 02/19] Add 'STRCPY' to the checkpatch ignore option Bernd Schubert
2026-03-23 21:03 ` Darrick J. Wong
2026-03-23 17:44 ` [PATCH 03/19] checkpatch.pl: Add _Atomic to $Attribute patttern Bernd Schubert
2026-03-23 21:09 ` Darrick J. Wong
2026-03-23 17:44 ` [PATCH 04/19] Add a new daemonize API Bernd Schubert
2026-03-23 22:28 ` Darrick J. Wong
2026-03-24 17:36 ` Bernd Schubert
2026-03-24 22:20 ` Darrick J. Wong
2026-03-23 17:45 ` [PATCH 05/19] Sync fuse_kernel.h with linux-6.18 Bernd Schubert
2026-03-23 21:16 ` Darrick J. Wong
2026-03-23 17:45 ` [PATCH 06/19] mount.c: Split fuse_mount_sys to prepare privileged sync FUSE_INIT Bernd Schubert
2026-03-23 22:34 ` Darrick J. Wong
2026-03-23 17:45 ` [PATCH 07/19] Add FUSE_MOUNT_FALLBACK_NEEDED define for -2 mount errors Bernd Schubert
2026-03-23 22:36 ` Darrick J. Wong
2026-03-24 18:03 ` Bernd Schubert
2026-03-23 17:45 ` [PATCH 08/19] Refactor mount code / move common functions to mount_util.c Bernd Schubert
2026-03-23 22:40 ` Darrick J. Wong
2026-03-23 17:45 ` [PATCH 09/19] Move mount flags to mount_i.h Bernd Schubert
2026-03-23 22:45 ` Darrick J. Wong
2026-03-24 18:40 ` Bernd Schubert
2026-03-23 17:45 ` [PATCH 10/19] conftest.py: Add more valgrind filter patterns Bernd Schubert
2026-03-23 17:45 ` [PATCH 11/19] Add support for the new linux mount API Bernd Schubert
2026-03-23 23:42 ` Darrick J. Wong
2026-03-24 20:16 ` Bernd Schubert
2026-03-24 22:46 ` Darrick J. Wong
2026-03-23 17:45 ` [PATCH 12/19] fuse mount: Support synchronous FUSE_INIT (privileged daemon) Bernd Schubert
2026-03-24 0:03 ` Darrick J. Wong
2026-03-24 20:42 ` Bernd Schubert
2026-03-24 22:50 ` Darrick J. Wong
2026-03-25 7:52 ` Bernd Schubert
2026-03-25 16:42 ` Darrick J. Wong
2026-03-23 17:45 ` [PATCH 13/19] Add fuse_session_set_debug() to enable debug output without foreground Bernd Schubert
2026-03-24 0:04 ` Darrick J. Wong
2026-03-23 17:45 ` [PATCH 14/19] Move more generic mount code to mount_util.{c,h} Bernd Schubert
2026-03-24 0:06 ` Darrick J. Wong
2026-03-24 20:57 ` Bernd Schubert
2026-03-23 17:45 ` [PATCH 15/19] Split the fusermount do_mount function Bernd Schubert
2026-03-24 0:14 ` Darrick J. Wong
2026-03-24 21:05 ` Bernd Schubert
2026-03-24 22:53 ` Darrick J. Wong
2026-03-23 17:45 ` Bernd Schubert [this message]
2026-03-24 0:18 ` [PATCH 16/19] fusermount: Refactor extract_x_options Darrick J. Wong
2026-03-23 17:45 ` [PATCH 17/19] Make fusermount work bidirectional for sync init Bernd Schubert
2026-03-24 19:35 ` Darrick J. Wong
2026-03-24 21:24 ` Bernd Schubert
2026-03-24 22:59 ` Darrick J. Wong
2026-03-25 19:48 ` Bernd Schubert
2026-03-25 22:03 ` Darrick J. Wong
2026-03-23 17:45 ` [PATCH 18/19] New mount API: Filter out "user=" Bernd Schubert
2026-03-24 19:51 ` Darrick J. Wong
2026-03-24 20:01 ` Bernd Schubert
2026-03-24 23:02 ` Darrick J. Wong
2026-03-23 17:45 ` [PATCH 19/19] Add support for sync-init of unprivileged daemons Bernd Schubert
2026-03-24 20:21 ` Darrick J. Wong
2026-03-24 21:53 ` Bernd Schubert
2026-03-24 23:13 ` Darrick J. Wong
2026-03-24 0:19 ` [PATCH 00/19] libfuse: Add support for synchronous init Darrick J. Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260323-fuse-init-before-mount-v1-16-a52d3040af69@bsbernd.com \
--to=bernd@bsbernd.com \
--cc=bschubert@ddn.com \
--cc=djwong@kernel.org \
--cc=joannelkoong@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=miklos@szeredi.hu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox