diff options
author | Stefan Riedmueller <s.riedmueller@phytec.de> | 2021-03-16 13:35:46 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2021-03-17 10:29:06 +0100 |
commit | 6b4a5ffdeeef3acef674d54e303bb76ea299295d (patch) | |
tree | 67afab89dd624986cfe455979e691f322ed9e763 /fs | |
parent | 7dc73d3618a15f0d858d5409574f38f9f83905ef (diff) | |
download | barebox-6b4a5ffdeeef3acef674d54e303bb76ea299295d.tar.gz barebox-6b4a5ffdeeef3acef674d54e303bb76ea299295d.tar.xz |
fs: Fix default mount when device already mounted
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>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/fs.c | 28 |
1 files changed, 19 insertions, 9 deletions
@@ -950,9 +950,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) { @@ -961,15 +962,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); |