[PATCH 9/9] mount: use standard mountpath if path is ommitted

Sascha Hauer s.hauer at pengutronix.de
Sun Sep 29 06:05:00 EDT 2013


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 at pengutronix.de>
---
 commands/mount.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/commands/mount.c b/commands/mount.c
index 96a4164..2e9d4be 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
 
 /**
-- 
1.8.4.rc3




More information about the barebox mailing list