diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2013-09-29 11:56:36 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2013-09-30 16:03:02 +0200 |
commit | cadca92008b08b5ef36ef3fb1f23a5542cf73f5c (patch) | |
tree | a4e81dc461ac9a2d20a2c811d89ebe5e7c745414 /commands/mount.c | |
parent | 869a6e1d0e11ff12aca2bdf679dc51a2a30da40e (diff) | |
download | barebox-cadca92008b08b5ef36ef3fb1f23a5542cf73f5c.tar.gz barebox-cadca92008b08b5ef36ef3fb1f23a5542cf73f5c.tar.xz |
mount: use standard mountpath if path is ommitted
With this a mount <devname> will mount the device to /mnt/<devname>. This
directory is created automatically if it doesn't exist already.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands/mount.c')
-rw-r--r-- | commands/mount.c | 27 |
1 files changed, 26 insertions, 1 deletions
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 <fs.h> #include <errno.h> #include <getopt.h> +#include <linux/err.h> 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] <device> <mountpoint>]\n") +BAREBOX_CMD_HELP_USAGE("mount [[OPTIONS] <device> [mountpoint]]\n") BAREBOX_CMD_HELP_OPT("-t <type>", "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/<partname>\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 /** |