[OpenWrt-Devel] [PATCH] block: support to mount read-only devices

Hua Shao nossiac at 163.com
Sat May 30 22:26:47 EDT 2015


A read-only device will fail to mount without MS_RDONLY flag.

Signed-off-by: Hua Shao <nossiac at 163.com>
---
 block.c | 49 ++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 38 insertions(+), 11 deletions(-)

diff --git a/block.c b/block.c
index 4c8dda9..a3c0ea5 100644
--- a/block.c
+++ b/block.c
@@ -734,11 +734,24 @@ static int mount_device(struct blkid_struct_probe *pr, int hotplug)
 
 		err = mount(pr->dev, target, pr->id->name, m->flags,
 		            (m->options) ? (m->options) : (""));
-		if (err)
-			ULOG_ERR("mounting %s (%s) as %s failed (%d) - %s\n",
-			         pr->dev, pr->id->name, target, err, strerror(err));
-		else
-			handle_swapfiles(true);
+		while (1) {
+			err = mount(pr->dev, target, pr->id->name, mflags,
+						(m->options) ? (m->options) : (""));
+			if (err) {
+				if (!(mflags & MS_RDONLY)) {
+					ERROR("fall back on RO mount. %s.\n", strerror(errno));
+					mflags |= MS_RDONLY;
+					continue;
+				} else {
+					ERROR("mounting %s (%s) as %s failed (%d) - %s\n",
+						pr->dev, pr->id->name, target, err, strerror(errno));
+					break;
+				}
+			} else {
+				handle_swapfiles(true);
+				break;
+			}
+		}
 		return err;
 	}
 
@@ -752,12 +765,26 @@ static int mount_device(struct blkid_struct_probe *pr, int hotplug)
 		if (check_fs)
 			check_filesystem(pr);
 
-		err = mount(pr->dev, target, pr->id->name, 0, "");
-		if (err)
-			ULOG_ERR("mounting %s (%s) as %s failed (%d) - %s\n",
-			         pr->dev, pr->id->name, target, err, strerror(err));
-		else
-			handle_swapfiles(true);
+		err = mount(pr->dev, target, pr->id->name, m->flags,
+		            (m->options) ? (m->options) : (""));
+		while (1) {
+			err = mount(pr->dev, target, pr->id->name, mflags,
+						(m->options) ? (m->options) : (""));
+			if (err) {
+				if (!(mflags & MS_RDONLY)) {
+					ERROR("fall back on RO mount. %s.\n", strerror(errno));
+					mflags |= MS_RDONLY;
+					continue;
+				} else {
+					ERROR("mounting %s (%s) as %s failed (%d) - %s\n",
+						pr->dev, pr->id->name, target, err, strerror(errno));
+					break;
+				}
+			} else {
+				handle_swapfiles(true);
+				break;
+			}
+		}
 		return err;
 	}
 
-- 
1.8.3.1
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list