mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 7/9] fs: add cdev mount helpers
Date: Sun, 29 Sep 2013 12:04:58 +0200	[thread overview]
Message-ID: <1380449100-6295-8-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1380449100-6295-1-git-send-email-s.hauer@pengutronix.de>

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

  parent reply	other threads:[~2013-09-29 10:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Sascha Hauer [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1380449100-6295-8-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox