mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* fs mounting patches
@ 2013-09-29 10:04 Sascha Hauer
  2013-09-29 10:04 ` [PATCH 1/9] copy_file: Add missing O_TRUNC Sascha Hauer
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: Sascha Hauer @ 2013-09-29 10:04 UTC (permalink / raw)
  To: barebox

This makes the mount command more versatile and informative.

----------------------------------------------------------------
Sascha Hauer (9):
      copy_file: Add missing O_TRUNC
      fs: cleanup backingstore handling
      mount: print backingstore instead of dev_name
      fs: use bus_for_each_driver
      fs: remove unused field 'name' from struct fs_driver_d
      mount: implement -v option to print available filesystems
      fs: add cdev mount helpers
      mount: Allow to mount all available partitions
      mount: use standard mountpath if path is ommitted

 commands/mount.c      |  66 +++++++++++++++++++++++++-----
 fs/cramfs/cramfs.c    |  18 +++++----
 fs/ext4/ext_barebox.c |  14 ++-----
 fs/fat/fat.c          |  17 ++------
 fs/fs.c               | 110 ++++++++++++++++++++++++++++++++++++++++++++------
 fs/ubifs/ubifs.c      |  16 +++-----
 include/fs.h          |   7 +++-
 lib/copy_file.c       |   2 +-
 8 files changed, 186 insertions(+), 64 deletions(-)

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/9] copy_file: Add missing O_TRUNC
  2013-09-29 10:04 fs mounting patches Sascha Hauer
@ 2013-09-29 10:04 ` Sascha Hauer
  2013-09-29 10:04 ` [PATCH 2/9] fs: cleanup backingstore handling Sascha Hauer
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2013-09-29 10:04 UTC (permalink / raw)
  To: barebox

Without it, when copying a smaller file over a larger file the
resulting file still has the remaining space from the larger file.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 lib/copy_file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/copy_file.c b/lib/copy_file.c
index 55dee38..778cc00 100644
--- a/lib/copy_file.c
+++ b/lib/copy_file.c
@@ -29,7 +29,7 @@ int copy_file(const char *src, const char *dst, int verbose)
 		goto out;
 	}
 
-	dstfd = open(dst, O_WRONLY | O_CREAT);
+	dstfd = open(dst, O_WRONLY | O_CREAT | O_TRUNC);
 	if (dstfd < 0) {
 		printf("could not open %s: %s\n", dst, errno_str());
 		goto out;
-- 
1.8.4.rc3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 2/9] fs: cleanup backingstore handling
  2013-09-29 10:04 fs mounting patches Sascha Hauer
  2013-09-29 10:04 ` [PATCH 1/9] copy_file: Add missing O_TRUNC Sascha Hauer
@ 2013-09-29 10:04 ` Sascha Hauer
  2013-09-29 10:04 ` [PATCH 3/9] mount: print backingstore instead of dev_name Sascha Hauer
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2013-09-29 10:04 UTC (permalink / raw)
  To: barebox

All filesystem drivers which need a backingstore device do the same
ignoring of '/dev/' in the backingstore followed by a cdev_open. Add a
helper function for it and let the core handle the cdev. As a side
effect this makes sure that fsdev->cdev is also set when a device is
mounted without the leading '/dev/' which was previously ignored
by the mount code.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 fs/cramfs/cramfs.c    | 18 +++++++++++-------
 fs/ext4/ext_barebox.c | 14 ++++----------
 fs/fat/fat.c          | 17 ++++-------------
 fs/fs.c               | 28 ++++++++++++++++++++--------
 fs/ubifs/ubifs.c      | 16 ++++++----------
 include/fs.h          |  2 ++
 6 files changed, 47 insertions(+), 48 deletions(-)

diff --git a/fs/cramfs/cramfs.c b/fs/cramfs/cramfs.c
index 99f6d49..8218fcf 100644
--- a/fs/cramfs/cramfs.c
+++ b/fs/cramfs/cramfs.c
@@ -422,29 +422,33 @@ static int cramfs_probe(struct device_d *dev)
 {
 	struct fs_device_d *fsdev;
 	struct cramfs_priv *priv;
+	int ret;
 
 	fsdev = dev_to_fs_device(dev);
 
 	priv = xmalloc(sizeof(struct cramfs_priv));
 	dev->priv = priv;
 
-	if (strncmp(fsdev->backingstore, "/dev/", 5))
-		return -ENODEV;
+	ret = fsdev_open_cdev(fsdev);
+	if (ret)
+		goto err_out;
 
-	priv->cdev = cdev_by_name(fsdev->backingstore + 5);
-	if (!priv->cdev)
-		return -ENODEV;
+	priv->cdev = fsdev->cdev;
 
 	if (cramfs_read_super(priv)) {
 		dev_info(dev, "no valid cramfs found\n");
-		free(priv);
-		return -EINVAL;
+		ret =  -EINVAL;
 	}
 
 	priv->curr_base = -1;
 
 	cramfs_uncompress_init ();
 	return 0;
+
+err_out:
+	free(priv);
+
+	return ret;
 }
 
 static void cramfs_remove(struct device_d *dev)
diff --git a/fs/ext4/ext_barebox.c b/fs/ext4/ext_barebox.c
index adc8f75..69a7723 100644
--- a/fs/ext4/ext_barebox.c
+++ b/fs/ext4/ext_barebox.c
@@ -225,7 +225,6 @@ static int ext_readlink(struct device_d *dev, const char *pathname,
 static int ext_probe(struct device_d *dev)
 {
 	struct fs_device_d *fsdev = dev_to_fs_device(dev);
-	char *backingstore = fsdev->backingstore;
 	int ret;
 	struct ext_filesystem *fs;
 
@@ -234,14 +233,11 @@ static int ext_probe(struct device_d *dev)
 	dev->priv = fs;
 	fs->dev = dev;
 
-	if (!strncmp(backingstore , "/dev/", 5))
-		backingstore += 5;
-
-	fs->cdev = cdev_open(backingstore, O_RDWR);
-	if (!fs->cdev) {
-		ret = -ENOENT;
+	ret = fsdev_open_cdev(fsdev);
+	if (ret)
 		goto err_open;
-	}
+
+	fs->cdev = fsdev->cdev;
 
 	ret = ext4fs_mount(fs);
 	if (ret)
@@ -250,7 +246,6 @@ static int ext_probe(struct device_d *dev)
 	return 0;
 
 err_mount:
-	cdev_close(fs->cdev);
 err_open:
 	free(fs);
 
@@ -262,7 +257,6 @@ static void ext_remove(struct device_d *dev)
 	struct ext_filesystem *fs = dev->priv;
 
 	ext4fs_umount(fs);
-	cdev_close(fs->cdev);
 	free(fs);
 }
 
diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index 15879c4..e65ef58 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -373,19 +373,15 @@ static int fat_probe(struct device_d *dev)
 {
 	struct fs_device_d *fsdev = dev_to_fs_device(dev);
 	struct fat_priv *priv = xzalloc(sizeof(struct fat_priv));
-	char *backingstore = fsdev->backingstore;
 	int ret;
 
 	dev->priv = priv;
 
-	if (!strncmp(backingstore , "/dev/", 5))
-		backingstore += 5;
-
-	priv->cdev = cdev_open(backingstore, O_RDWR);
-	if (!priv->cdev) {
-		ret = -ENOENT;
+	ret = fsdev_open_cdev(fsdev);
+	if (ret)
 		goto err_open;
-	}
+
+	priv->cdev = fsdev->cdev;
 
 	priv->fat.userdata = priv;
 	ret = f_mount(&priv->fat);
@@ -395,7 +391,6 @@ static int fat_probe(struct device_d *dev)
 	return 0;
 
 err_mount:
-	cdev_close(priv->cdev);
 err_open:
 	free(priv);
 
@@ -404,10 +399,6 @@ err_open:
 
 static void fat_remove(struct device_d *dev)
 {
-	struct fat_priv *priv = dev->priv;
-
-	cdev_close(priv->cdev);
-
 	free(dev->priv);
 }
 
diff --git a/fs/fs.c b/fs/fs.c
index d913a50..4618b4f 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1231,6 +1231,9 @@ static void fs_remove(struct device_d *dev)
 	if (fsdev == fs_dev_root)
 		fs_dev_root = NULL;
 
+	if (fsdev->cdev)
+		cdev_close(fsdev->cdev);
+
 	free(fsdev->backingstore);
 	free(fsdev);
 }
@@ -1279,6 +1282,23 @@ static const char *detect_fs(const char *filename)
 	return NULL;
 }
 
+int fsdev_open_cdev(struct fs_device_d *fsdev)
+{
+	const char *backingstore = fsdev->backingstore;
+
+	if (!strncmp(backingstore , "/dev/", 5))
+		backingstore += 5;
+
+	fsdev->cdev = cdev_open(backingstore, O_RDWR);
+	if (!fsdev->cdev)
+		return -EINVAL;
+
+	fsdev->dev.parent = fsdev->cdev->dev;
+	fsdev->parent_device = fsdev->cdev->dev;
+
+	return 0;
+}
+
 /*
  * Mount a device to a directory.
  * We do this by registering a new device on which the filesystem
@@ -1323,14 +1343,6 @@ int mount(const char *device, const char *fsname, const char *_path)
 	fsdev->path = xstrdup(path);
 	fsdev->dev.bus = &fs_bus;
 
-	if (!strncmp(device, "/dev/", 5))
-		fsdev->cdev = cdev_by_name(device + 5);
-
-	if (fsdev->cdev) {
-		fsdev->dev.parent = fsdev->cdev->dev;
-		fsdev->parent_device = fsdev->cdev->dev;
-	}
-
 	ret = register_device(&fsdev->dev);
 	if (ret)
 		goto err_register;
diff --git a/fs/ubifs/ubifs.c b/fs/ubifs/ubifs.c
index 9df8dc5..dfa6107 100644
--- a/fs/ubifs/ubifs.c
+++ b/fs/ubifs/ubifs.c
@@ -553,25 +553,22 @@ static int ubifs_probe(struct device_d *dev)
 {
 	struct fs_device_d *fsdev = dev_to_fs_device(dev);
 	struct ubifs_priv *priv = xzalloc(sizeof(struct ubifs_priv));
-	char *backingstore = fsdev->backingstore;
 	int ret;
 
 	dev->priv = priv;
 
-	if (!strncmp(backingstore , "/dev/", 5))
-		backingstore += 5;
-
-	priv->cdev = cdev_open(backingstore, O_RDONLY);
-	if (!priv->cdev) {
-		ret = -ENOENT;
+	ret = fsdev_open_cdev(fsdev);
+	if (ret)
 		goto err_free;
-	}
+
+	priv->cdev = fsdev->cdev;
 
 	priv->ubi = ubi_open_volume_cdev(priv->cdev, UBI_READONLY);
 	if (IS_ERR(priv->ubi)) {
 		dev_err(dev, "failed to open ubi volume: %s\n",
 				strerror(-PTR_ERR(priv->ubi)));
-		return PTR_ERR(priv->ubi);
+		ret = PTR_ERR(priv->ubi);
+		goto err_free;
 	}
 
 	priv->sb = ubifs_get_super(priv->ubi, 0);
@@ -596,7 +593,6 @@ static void ubifs_remove(struct device_d *dev)
 
 	ubifs_umount(c);
 	ubi_close_volume(priv->ubi);
-	cdev_close(priv->cdev);
 
 	free(c);
 	free(sb);
diff --git a/include/fs.h b/include/fs.h
index 22c0746..c6c0f0e 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -193,4 +193,6 @@ void automount_print(void);
 
 int unlink_recursive(const char *path, char **failedpath);
 
+int fsdev_open_cdev(struct fs_device_d *fsdev);
+
 #endif /* __FS_H */
-- 
1.8.4.rc3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 3/9] mount: print backingstore instead of dev_name
  2013-09-29 10:04 fs mounting patches Sascha Hauer
  2013-09-29 10:04 ` [PATCH 1/9] copy_file: Add missing O_TRUNC Sascha Hauer
  2013-09-29 10:04 ` [PATCH 2/9] fs: cleanup backingstore handling Sascha Hauer
@ 2013-09-29 10:04 ` Sascha Hauer
  2013-09-29 10:04 ` [PATCH 4/9] fs: use bus_for_each_driver Sascha Hauer
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2013-09-29 10:04 UTC (permalink / raw)
  To: barebox

When printing the devices on which a path is mounted the backingstore is
the interesting thing, not dev_name.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/mount.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/commands/mount.c b/commands/mount.c
index be26af8..595145a 100644
--- a/commands/mount.c
+++ b/commands/mount.c
@@ -39,7 +39,7 @@ static int do_mount(int argc, char *argv[])
 	if (argc == 1) {
 		for_each_fs_device(fsdev) {
 			printf("%s on %s type %s\n",
-				fsdev->parent_device ? dev_name(fsdev->parent_device) : "none",
+				fsdev->backingstore ? fsdev->backingstore : "none",
 				fsdev->path,
 				fsdev->dev.name);
 		}
-- 
1.8.4.rc3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 4/9] fs: use bus_for_each_driver
  2013-09-29 10:04 fs mounting patches Sascha Hauer
                   ` (2 preceding siblings ...)
  2013-09-29 10:04 ` [PATCH 3/9] mount: print backingstore instead of dev_name Sascha Hauer
@ 2013-09-29 10:04 ` Sascha Hauer
  2013-09-29 10:04 ` [PATCH 5/9] fs: remove unused field 'name' from struct fs_driver_d Sascha Hauer
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2013-09-29 10:04 UTC (permalink / raw)
  To: barebox

Instead of using for_each_driver and testing for the bus type.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 fs/fs.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index 4618b4f..3434134 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1269,10 +1269,7 @@ static const char *detect_fs(const char *filename)
 	if (type == filetype_unknown)
 		return NULL;
 
-	for_each_driver(drv) {
-		if (drv->bus != &fs_bus)
-			continue;
-
+	bus_for_each_driver(&fs_bus, drv) {
 		fdrv = drv_to_fs_driver(drv);
 
 		if (type == fdrv->type)
-- 
1.8.4.rc3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 5/9] fs: remove unused field 'name' from struct fs_driver_d
  2013-09-29 10:04 fs mounting patches Sascha Hauer
                   ` (3 preceding siblings ...)
  2013-09-29 10:04 ` [PATCH 4/9] fs: use bus_for_each_driver Sascha Hauer
@ 2013-09-29 10:04 ` Sascha Hauer
  2013-09-29 10:04 ` [PATCH 6/9] mount: implement -v option to print available filesystems Sascha Hauer
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2013-09-29 10:04 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 include/fs.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/include/fs.h b/include/fs.h
index c6c0f0e..b82c246 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -39,7 +39,6 @@ typedef struct filep {
 #define FS_DRIVER_NO_DEV	1
 
 struct fs_driver_d {
-	char *name;
 	int (*probe) (struct device_d *dev);
 	int (*mkdir)(struct device_d *dev, const char *pathname);
 	int (*rmdir)(struct device_d *dev, const char *pathname);
-- 
1.8.4.rc3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 6/9] mount: implement -v option to print available filesystems
  2013-09-29 10:04 fs mounting patches Sascha Hauer
                   ` (4 preceding siblings ...)
  2013-09-29 10:04 ` [PATCH 5/9] fs: remove unused field 'name' from struct fs_driver_d Sascha Hauer
@ 2013-09-29 10:04 ` Sascha Hauer
  2013-09-29 10:04 ` [PATCH 7/9] fs: add cdev mount helpers Sascha Hauer
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2013-09-29 10:04 UTC (permalink / raw)
  To: barebox

It's useful to know which filesystems a barebox binary supports.
Add a -v option to the mount command to find it out.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/mount.c | 35 +++++++++++++++++++++++++----------
 include/fs.h     |  1 +
 2 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/commands/mount.c b/commands/mount.c
index 595145a..203c4de 100644
--- a/commands/mount.c
+++ b/commands/mount.c
@@ -31,27 +31,40 @@
 static int do_mount(int argc, char *argv[])
 {
 	int opt;
-	int ret = 0;
+	int ret = 0, verbose = 0;
 	struct fs_device_d *fsdev;
+	struct driver_d *drv;
 	const char *type = NULL;
 	const char *mountpoint, *dev;
 
-	if (argc == 1) {
+	while ((opt = getopt(argc, argv, "t:v")) > 0) {
+		switch (opt) {
+		case 't':
+			type = optarg;
+			break;
+		case 'v':
+			verbose++;
+			break;
+		}
+	}
+
+	if (argc == optind) {
 		for_each_fs_device(fsdev) {
 			printf("%s on %s type %s\n",
 				fsdev->backingstore ? fsdev->backingstore : "none",
 				fsdev->path,
 				fsdev->dev.name);
 		}
-		return 0;
-	}
 
-	while ((opt = getopt(argc, argv, "t:")) > 0) {
-		switch (opt) {
-		case 't':
-			type = optarg;
-			break;
+		if (verbose) {
+			printf("\nSupported filesystems:\n\n");
+			bus_for_each_driver(&fs_bus, drv) {
+				struct fs_driver_d * fsdrv = drv_to_fs_driver(drv);
+				printf("%s\n", fsdrv->drv.name);
+			}
 		}
+
+		return 0;
 	}
 
 	if (argc < optind + 2)
@@ -77,7 +90,9 @@ static int do_mount(int argc, char *argv[])
 }
 
 BAREBOX_CMD_HELP_START(mount)
-BAREBOX_CMD_HELP_USAGE("mount [[-t <fstype] <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("-v", "be more verbose\n")
 BAREBOX_CMD_HELP_SHORT("Mount a filesystem of a given type to a mountpoint.\n")
 BAREBOX_CMD_HELP_SHORT("If no fstype is specified, try to detect it automatically.\n")
 BAREBOX_CMD_HELP_SHORT("If no argument is given, list mounted filesystems.\n")
diff --git a/include/fs.h b/include/fs.h
index b82c246..5b4ad6f 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -87,6 +87,7 @@ struct fs_driver_d {
 
 extern struct list_head fs_device_list;
 #define for_each_fs_device(f) list_for_each_entry(f, &fs_device_list, list)
+extern struct bus_type fs_bus;
 
 struct fs_device_d {
 	char *backingstore; /* the device we are associated with */
-- 
1.8.4.rc3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 7/9] fs: add cdev mount helpers
  2013-09-29 10:04 fs mounting patches Sascha Hauer
                   ` (5 preceding siblings ...)
  2013-09-29 10:04 ` [PATCH 6/9] mount: implement -v option to print available filesystems Sascha Hauer
@ 2013-09-29 10:04 ` Sascha Hauer
  2013-09-29 10:04 ` [PATCH 8/9] mount: Allow to mount all available partitions Sascha Hauer
  2013-09-29 10:05 ` [PATCH 9/9] mount: use standard mountpath if path is ommitted Sascha Hauer
  8 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2013-09-29 10:04 UTC (permalink / raw)
  To: barebox

Introduce helpers to iterate over cdevs and mount them to a known
path.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 fs/fs.c      | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/fs.h |  3 +++
 2 files changed, 80 insertions(+)

diff --git a/fs/fs.c b/fs/fs.c
index 3434134..784eea4 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -32,6 +32,7 @@
 #include <magicvar.h>
 #include <environment.h>
 #include <libgen.h>
+#include <block.h>
 
 void *read_file(const char *filename, size_t *size)
 {
@@ -1670,3 +1671,79 @@ ssize_t mem_write(struct cdev *cdev, const void *buf, size_t count, loff_t offse
 	return size;
 }
 EXPORT_SYMBOL(mem_write);
+
+/*
+ * cdev_get_mount_path - return the path a cdev is mounted on
+ *
+ * If a cdev is mounted return the path it's mounted on, NULL
+ * otherwise.
+ */
+const char *cdev_get_mount_path(struct cdev *cdev)
+{
+	struct fs_device_d *fsdev;
+
+	for_each_fs_device(fsdev) {
+		if (fsdev->cdev && fsdev->cdev == cdev)
+			return fsdev->path;
+	}
+
+	return NULL;
+}
+
+/*
+ * cdev_mount_default - mount a cdev to the default path
+ *
+ * If a cdev is already mounted return the path it's mounted on, otherwise
+ * mount it to /mnt/<cdevname> and return the path. Returns an error pointer
+ * on failure.
+ */
+const char *cdev_mount_default(struct cdev *cdev)
+{
+	const char *path;
+	char *newpath, *devpath;
+	int ret;
+
+	/*
+	 * If this cdev is already mounted somewhere use this path
+	 * instead of mounting it again to avoid corruption on the
+	 * filesystem.
+	 */
+	path = cdev_get_mount_path(cdev);
+	if (path)
+		return path;
+
+	newpath = asprintf("/mnt/%s", cdev->name);
+	make_directory(newpath);
+
+	devpath = asprintf("/dev/%s", cdev->name);
+
+	ret = mount(devpath, NULL, newpath);
+
+	free(devpath);
+
+	if (ret) {
+		free(newpath);
+		return ERR_PTR(ret);
+	}
+
+	return cdev_get_mount_path(cdev);
+}
+
+/*
+ * mount_all - iterate over block devices and mount all devices we are able to
+ */
+void mount_all(void)
+{
+	struct device_d *dev;
+	struct block_device *bdev;
+
+	for_each_device(dev)
+		device_detect(dev);
+
+	for_each_block_device(bdev) {
+		struct cdev *cdev = &bdev->cdev;
+
+		list_for_each_entry(cdev, &bdev->dev->cdevs, devices_list)
+			cdev_mount_default(cdev);
+	}
+}
diff --git a/include/fs.h b/include/fs.h
index 5b4ad6f..99f1689 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -194,5 +194,8 @@ void automount_print(void);
 int unlink_recursive(const char *path, char **failedpath);
 
 int fsdev_open_cdev(struct fs_device_d *fsdev);
+const char *cdev_get_mount_path(struct cdev *cdev);
+const char *cdev_mount_default(struct cdev *cdev);
+void mount_all(void);
 
 #endif /* __FS_H */
-- 
1.8.4.rc3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 8/9] mount: Allow to mount all available partitions
  2013-09-29 10:04 fs mounting patches Sascha Hauer
                   ` (6 preceding siblings ...)
  2013-09-29 10:04 ` [PATCH 7/9] fs: add cdev mount helpers Sascha Hauer
@ 2013-09-29 10:04 ` Sascha Hauer
  2013-09-29 10:05 ` [PATCH 9/9] mount: use standard mountpath if path is ommitted Sascha Hauer
  8 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2013-09-29 10:04 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/mount.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/commands/mount.c b/commands/mount.c
index 203c4de..96a4164 100644
--- a/commands/mount.c
+++ b/commands/mount.c
@@ -37,7 +37,7 @@ static int do_mount(int argc, char *argv[])
 	const char *type = NULL;
 	const char *mountpoint, *dev;
 
-	while ((opt = getopt(argc, argv, "t:v")) > 0) {
+	while ((opt = getopt(argc, argv, "t:va")) > 0) {
 		switch (opt) {
 		case 't':
 			type = optarg;
@@ -45,6 +45,9 @@ static int do_mount(int argc, char *argv[])
 		case 'v':
 			verbose++;
 			break;
+		case 'a':
+			mount_all();
+			break;
 		}
 	}
 
@@ -92,10 +95,13 @@ 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_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")
 BAREBOX_CMD_HELP_SHORT("Mount a filesystem of a given type to a mountpoint.\n")
 BAREBOX_CMD_HELP_SHORT("If no fstype is specified, try to detect it automatically.\n")
 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_END
 
 /**
-- 
1.8.4.rc3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 9/9] mount: use standard mountpath if path is ommitted
  2013-09-29 10:04 fs mounting patches Sascha Hauer
                   ` (7 preceding siblings ...)
  2013-09-29 10:04 ` [PATCH 8/9] mount: Allow to mount all available partitions Sascha Hauer
@ 2013-09-29 10:05 ` Sascha Hauer
  8 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2013-09-29 10:05 UTC (permalink / raw)
  To: barebox

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


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2013-09-29 10:05 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-29 10:04 fs mounting patches Sascha Hauer
2013-09-29 10:04 ` [PATCH 1/9] copy_file: Add missing O_TRUNC Sascha Hauer
2013-09-29 10:04 ` [PATCH 2/9] fs: cleanup backingstore handling Sascha Hauer
2013-09-29 10:04 ` [PATCH 3/9] mount: print backingstore instead of dev_name Sascha Hauer
2013-09-29 10:04 ` [PATCH 4/9] fs: use bus_for_each_driver Sascha Hauer
2013-09-29 10:04 ` [PATCH 5/9] fs: remove unused field 'name' from struct fs_driver_d Sascha Hauer
2013-09-29 10:04 ` [PATCH 6/9] mount: implement -v option to print available filesystems Sascha Hauer
2013-09-29 10:04 ` [PATCH 7/9] fs: add cdev mount helpers Sascha Hauer
2013-09-29 10:04 ` [PATCH 8/9] mount: Allow to mount all available partitions Sascha Hauer
2013-09-29 10:05 ` [PATCH 9/9] mount: use standard mountpath if path is ommitted Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox