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@xxxxxxxxxxxxxx> --- 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