mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] fs: Fix default mount when device already mounted
@ 2021-03-16 12:35 Stefan Riedmueller
  2021-03-17  9:31 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Stefan Riedmueller @ 2021-03-16 12:35 UTC (permalink / raw)
  To: barebox; +Cc: Stefan Riedmueller

Let cdev_mount_default return an error in case the device is already
mounted to a different location than the default mount point.

Otherwise the automount routine can get stuck in an infinite loop
spamming:

mounted /dev/mmc0.0 on /mnt/mmc
mounted /dev/mmc0.0 on /mnt/mmc
mounted /dev/mmc0.0 on /mnt/mmc

Signed-off-by: Stefan Riedmueller <s.riedmueller@phytec.de>
---
 fs/fs.c | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index 3db24b7b6822..4f2345d22544 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -951,9 +951,10 @@ const char *cdev_get_mount_path(struct cdev *cdev)
 /*
  * 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.
+ * If a cdev is already mounted to the default mount path return the path
+ * it's mounted on. If it is mounted to any other path return EBUSY.
+ * 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 *fsoptions)
 {
@@ -962,15 +963,24 @@ const char *cdev_mount_default(struct cdev *cdev, const char *fsoptions)
 	int ret;
 
 	/*
-	 * If this cdev is already mounted somewhere use this path
-	 * instead of mounting it again to avoid corruption on the
-	 * filesystem. Note this ignores eventual fsoptions though.
+	 * If this cdev is already mounted somewhere other than the
+	 * default mount path return -EBUSY instead of mounting it
+	 * again to avoid corruption on the filesystem. Note this
+	 * ignores eventual fsoptions though. If the cdev is already
+	 * mounted on the default path just return that path.
 	 */
 	path = cdev_get_mount_path(cdev);
-	if (path)
-		return path;
-
 	newpath = basprintf("/mnt/%s", cdev->name);
+
+	if (path) {
+		if (strcmp(newpath, path)) {
+			free(newpath);
+			return ERR_PTR(-EBUSY);
+		} else {
+			return path;
+		}
+	}
+
 	make_directory(newpath);
 
 	devpath = basprintf("/dev/%s", cdev->name);
-- 
2.25.1


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


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

end of thread, other threads:[~2021-03-17  9:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-16 12:35 [PATCH] fs: Fix default mount when device already mounted Stefan Riedmueller
2021-03-17  9:31 ` Sascha Hauer

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