mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH] fs: implement cdev_mount()
Date: Fri, 30 Sep 2022 17:40:17 +0200	[thread overview]
Message-ID: <20220930154017.750867-1-a.fatoum@pengutronix.de> (raw)

EFI loaders provide both block device and file system access to software
running under it. For file system access, we will just want to get a
mount if available and mount at a default location if not. Provide a
helper that does just that.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 fs/fs.c      | 19 +++++++++++++++++++
 include/fs.h |  1 +
 2 files changed, 20 insertions(+)

diff --git a/fs/fs.c b/fs/fs.c
index 78878e7112d5..a314a49b2db7 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -999,6 +999,25 @@ const char *cdev_mount_default(struct cdev *cdev, const char *fsoptions)
 	return cdev_get_mount_path(cdev);
 }
 
+/*
+ * cdev_mount - return existing mount or mount a cdev to the default path
+ *
+ * If a cdev is already mounted anywhere 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(struct cdev *cdev)
+{
+	const char *path;
+
+	path = cdev_get_mount_path(cdev);
+	if (path)
+		return path;
+
+	return cdev_mount_default(cdev, NULL);
+}
+
 /*
  * mount_all - iterate over block devices and mount all devices we are able to
  */
diff --git a/include/fs.h b/include/fs.h
index 894cae3e4c2f..9ea522dc2cc3 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -164,6 +164,7 @@ int fs_init_legacy(struct fs_device_d *fsdev);
 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, const char *fsoptions);
+const char *cdev_mount(struct cdev *cdev);
 void mount_all(void);
 
 void fsdev_set_linux_rootarg(struct fs_device_d *fsdev, const char *str);
-- 
2.30.2




             reply	other threads:[~2022-09-30 15:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-30 15:40 Ahmad Fatoum [this message]
2022-10-04  9:52 ` 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=20220930154017.750867-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@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