[OpenWrt-Devel] [PATCH fstools 1/2] block: remove mount target file if it's a link

Rafał Miłecki zajec5 at gmail.com
Sat Dec 28 16:07:21 EST 2019


From: Rafał Miłecki <rafal at milecki.pl>

Links like that can remain from using autofs and can cause mounting
errors after switching to non-autofs:

block: mounting /dev/sda1 (vfat) as /mnt/sda1 failed (2) - No such file or directory

Signed-off-by: Rafał Miłecki <rafal at milecki.pl>
---
 block.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/block.c b/block.c
index e07cbc5..06f75d3 100644
--- a/block.c
+++ b/block.c
@@ -1072,6 +1072,7 @@ static int mount_device(struct device *dev, int type)
 {
 	struct mount *m;
 	struct probe_info *pr;
+	struct stat st;
 	char _target[32];
 	char *target;
 	char *device;
@@ -1154,6 +1155,8 @@ static int mount_device(struct device *dev, int type)
 		check_filesystem(pr);
 
 	mkdir_p(target);
+	if (!lstat(target, &st) && S_ISLNK(st.st_mode))
+		unlink(target);
 
 	err = handle_mount(pr->dev, target, pr->type, m);
 	if (err) {
-- 
2.21.0


_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list