[syslinux] Syslinux search for config file

Matt Fleming matt at console-pimps.org
Mon Nov 12 05:29:39 PST 2012


On Thu, 2012-08-30 at 10:36 +0200, Gert Hulselmans wrote:
> After a closer look at the source code, the following should work:
> 
>   syslinux.exe -maf -d /slax/boot F:
> 
> The forward slashes are replaced with backward slashes after calling
> syslinux_patch.

Is anyone in a position to try out the following patch and see if it
solves this issue?

---

>From db82060c1515a0852b020930f48aa7183866489d Mon Sep 17 00:00:00 2001
From: Matt Fleming <matt.fleming at intel.com>
Date: Thu, 8 Nov 2012 17:51:33 +0000
Subject: [PATCH] libinstaller: Mangle win pathnames into Syslinux pathnames

The Syslinux code deals exclusively with '/' as path component
separators. If a pathname containing '\' is used as the directory
argument during installation, e.g.

    syslinux.exe -d \slax\boot F:

the pathname is inserted into the ADV structure verbatim.
Unfortunately, the config code doesn't understand pathnames with
backslashes and therefore won't search in the installation directory
for the config file.

Mangle the pathname before it's stored in the ADV.

Cc: Gert Hulselmans <hulselmansgert at gmail.com>
Cc: Tomas M <tomas at slax.org>
Signed-off-by: Matt Fleming <matt.fleming at intel.com>
---
 libinstaller/syslxopt.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 43 insertions(+), 1 deletion(-)

diff --git a/libinstaller/syslxopt.c b/libinstaller/syslxopt.c
index b739752..30d846f 100644
--- a/libinstaller/syslxopt.c
+++ b/libinstaller/syslxopt.c
@@ -132,6 +132,41 @@ void __attribute__ ((noreturn)) usage(int rv, enum syslinux_mode mode)
     exit(rv);
 }
 
+/*
+ * Convert backslashes '\\' in a pathname into forward slashes '/'.
+ */
+static char *dir_fat_mangle(const char *dir)
+{
+    const char *sd;
+    char *s, *cp;
+    size_t size;
+    int slash = 1;
+
+    size = strlen(dir) + 1;
+    s = malloc(size);
+    if (!s)
+	return s;
+
+    memset(s, 0, size);
+
+    for (sd = dir, cp = s; *sd; sd++) {
+	char c = *sd;
+
+	if (c == '/' || c == '\\') {
+	    if (slash)
+		continue;
+	    c = '/';
+	    slash = 1;
+	} else {
+	    slash = 0;
+	}
+
+	*cp++ = c;
+    }
+
+    return s;
+}
+
 void parse_options(int argc, char *argv[], enum syslinux_mode mode)
 {
     int o;
@@ -198,7 +233,14 @@ void parse_options(int argc, char *argv[], enum syslinux_mode mode)
 	    opt.set_once = "";
 	    break;
 	case 'd':
-	    opt.directory = optarg;
+	    if (mode == MODE_SYSLINUX_DOSWIN) {
+		opt.directory = dir_fat_mangle(optarg);
+		if (!opt.directory) {
+		    fprintf(stderr, "Failed to mangle directory argument\n");
+		    exit(EX_USAGE);
+		}
+	    } else
+		opt.directory = optarg;
 	    break;
 	case OPT_RESET_ADV:
 	    opt.reset_adv = 1;
-- 
1.7.11.7

-- 
Matt Fleming, Intel Open Source Technology Center




More information about the Syslinux mailing list