From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH] mount: support specifying mount -o options more than once
Date: Fri, 14 Feb 2025 11:31:14 +0100 [thread overview]
Message-ID: <20250214103114.2900899-1-a.fatoum@pengutronix.de> (raw)
Specifying -o more than once is useful for scripts: A mount.9P script
for example can specify some default options and the caller of the
script can specify an extra -o to add extra options.
This is supported by normal mount(1), but wasn't so far in the barebox
variant. Remedy that.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
commands/mount.c | 41 ++++++++++++++++++++++++++++++-----------
1 file changed, 30 insertions(+), 11 deletions(-)
diff --git a/commands/mount.c b/commands/mount.c
index 81a40e951076..002a38e1959f 100644
--- a/commands/mount.c
+++ b/commands/mount.c
@@ -9,14 +9,18 @@
#include <errno.h>
#include <getopt.h>
#include <linux/err.h>
+#include <stringlist.h>
static int do_mount(int argc, char *argv[])
{
- int opt, verbose = 0;
+ int ret = 0, opt, verbose = 0;
struct driver *drv;
const char *type = NULL;
const char *mountpoint, *devstr;
- const char *fsoptions = NULL;
+ struct string_list fsoption_list;
+ char *fsoptions = NULL;
+
+ string_list_init(&fsoption_list);
while ((opt = getopt(argc, argv, "ao:t:v")) > 0) {
switch (opt) {
@@ -27,7 +31,7 @@ static int do_mount(int argc, char *argv[])
type = optarg;
break;
case 'o':
- fsoptions = optarg;
+ string_list_add(&fsoption_list, optarg);
break;
case 'v':
verbose++;
@@ -56,11 +60,22 @@ static int do_mount(int argc, char *argv[])
}
}
- return 0;
+ goto out;
+ }
+
+ if (argc == 0) {
+ ret = COMMAND_ERROR_USAGE;
+ goto out;
}
devstr = argv[0];
+ fsoptions = string_list_join(&fsoption_list, " ");
+ if (!fsoptions) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
if (argc == 1) {
struct cdev *cdev;
const char *path;
@@ -70,8 +85,10 @@ static int do_mount(int argc, char *argv[])
device_detect_by_name(devstr);
cdev = cdev_by_name(devstr);
- if (!cdev)
- return -ENOENT;
+ if (!cdev) {
+ ret = -ENOENT;
+ goto out;
+ }
path = cdev_mount_default(cdev, fsoptions);
if (IS_ERR(path))
@@ -79,12 +96,9 @@ static int do_mount(int argc, char *argv[])
printf("mounted /dev/%s on %s\n", devstr, path);
- return 0;
+ goto out;
}
- if (argc < 2)
- return COMMAND_ERROR_USAGE;
-
if (argc == 3) {
/*
* Old behaviour: mount <dev> <type> <mountpoint>
@@ -95,7 +109,12 @@ static int do_mount(int argc, char *argv[])
mountpoint = argv[1];
}
- return mount(devstr, type, mountpoint, fsoptions);
+ ret = mount(devstr, type, mountpoint, fsoptions);
+
+out:
+ free(fsoptions);
+ string_list_free(&fsoption_list);
+ return ret;
}
BAREBOX_CMD_HELP_START(mount)
--
2.39.5
next reply other threads:[~2025-02-14 10:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-14 10:31 Ahmad Fatoum [this message]
2025-02-17 9:33 ` Sascha Hauer
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=20250214103114.2900899-1-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/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