diff mbox

[OpenWrt-Devel,v2,3/3] mount_root: Also handle new overlay= option in done()

Message ID 1461867621-4055-3-git-send-email-josua.mayer97@gmail.com
State Changes Requested
Delegated to: John Crispin
Headers show

Commit Message

Josua Mayer April 28, 2016, 6:20 p.m. UTC
From: Josua Mayer <privacy@not.given>

The done()-function is used both to initialize rootfs_data when there is
no filesystem yet, but also to set ready-state on fresh filesystems.

Make sure to also do that when a non-standard overlay device is specified.

Signed-off-by: Josua Mayer <josua.mayer97@gmail.com>
---
 mount_root.c | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/mount_root.c b/mount_root.c
index 9d2c0de..e9b2cf3 100644
--- a/mount_root.c
+++ b/mount_root.c
@@ -124,8 +124,39 @@  stop(int argc, char *argv[1])
 static int
 done(int argc, char *argv[1])
 {
-	struct volume *v = volume_find("rootfs_data");
+	struct volume *v = NULL;
+	FILE *fp;
+	char buffer[100] = {0};
 
+	/*
+	 * First check if there is an overlay device hint in cmdline
+	 */
+	fp = fopen("/proc/cmdline", "r");
+	while(!feof(fp)) {
+		if(fscanf(fp, "overlay=%s", buffer))
+			break;
+
+		fseek(fp, 1, SEEK_CUR);
+	}
+	fclose(fp);
+	if(buffer[0]) {
+		// strip /dev/ prefix if any
+		int offset = 0;
+		if(strstr(buffer, "/dev/"))
+			offset = 5;
+
+		v = volume_find(buffer + offset);
+	}
+
+	/*
+	 * Now look for standard overlay device name
+	 */
+	if(!v)
+		v = volume_find("rootfs_data");
+
+	/*
+	 * If no overlay device exists, then there is nothing to do here
+	 */
 	if (!v)
 		return -1;