From cadca92008b08b5ef36ef3fb1f23a5542cf73f5c Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sun, 29 Sep 2013 11:56:36 +0200 Subject: mount: use standard mountpath if path is ommitted With this a mount will mount the device to /mnt/. This directory is created automatically if it doesn't exist already. Signed-off-by: Sascha Hauer --- commands/mount.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'commands/mount.c') diff --git a/commands/mount.c b/commands/mount.c index 96a4164519..2e9d4bef5e 100644 --- a/commands/mount.c +++ b/commands/mount.c @@ -27,6 +27,7 @@ #include #include #include +#include static int do_mount(int argc, char *argv[]) { @@ -70,6 +71,28 @@ static int do_mount(int argc, char *argv[]) return 0; } + if (argc == optind + 1) { + struct cdev *cdev; + const char *path, *devstr; + + devstr = argv[optind]; + + if (!strncmp(devstr, "/dev/", 5)) + devstr += 5; + + cdev = cdev_by_name(devstr); + if (!cdev) + return -ENOENT; + + path = cdev_mount_default(cdev); + if (IS_ERR(path)) + return PTR_ERR(path); + + printf("mounted /dev/%s on %s\n", devstr, path); + + return 0; + } + if (argc < optind + 2) return COMMAND_ERROR_USAGE; @@ -93,7 +116,7 @@ static int do_mount(int argc, char *argv[]) } BAREBOX_CMD_HELP_START(mount) -BAREBOX_CMD_HELP_USAGE("mount [[OPTIONS] ]\n") +BAREBOX_CMD_HELP_USAGE("mount [[OPTIONS] [mountpoint]]\n") BAREBOX_CMD_HELP_OPT("-t ", "specify filesystem type\n") BAREBOX_CMD_HELP_OPT("-a", "Mount all blockdevices.\n") BAREBOX_CMD_HELP_OPT("-v", "be more verbose\n") @@ -102,6 +125,8 @@ BAREBOX_CMD_HELP_SHORT("If no fstype is specified, try to detect it automaticall BAREBOX_CMD_HELP_SHORT("If no argument is given, list mounted filesystems.\n") BAREBOX_CMD_HELP_SHORT("With -a the mount command mounts all block devices whose filesystem\n") BAREBOX_CMD_HELP_SHORT("can be detected automatically to /mnt/\n") +BAREBOX_CMD_HELP_SHORT("If mountpoint is not given a standard mountpoint of /mnt/devname>\n") +BAREBOX_CMD_HELP_SHORT("is used. This directoy is created automatically if necessary.\n") BAREBOX_CMD_HELP_END /** -- cgit v1.2.3