[syslinux] Syslinux search for config file

Gert Hulselmans hulselmansgert at gmail.com
Mon Nov 12 07:03:22 PST 2012


2012/11/12 Matt Fleming <matt at console-pimps.org>:
> 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
>

Hi Mat,



Why is the function called dir_fat_mangle? The Syslinux Windows
installer can install on FAT12/16/32 and NTFS.

Something like dir_backslash_mangle might be a better name.


In win/syslinux.c the part of the code that moves LDLINUX.SYS needs a
small cleanup too,
now that opt.directory always contains a forward slash:

    /* Move the file to the desired location */
    if (opt.directory) {
	char new_ldlinux_name[strlen(opt.directory) + 16];
	char *cp = new_ldlinux_name + 3;
	const char *sd;
	int slash = 1;

	new_ldlinux_name[0] = opt.device[0];
	new_ldlinux_name[1] = ':';
	new_ldlinux_name[2] = '\\';

	for (sd = opt.directory; *sd; sd++) {
	    char c = *sd;

-	    if (c == '/' || c == '\\') {
+	    if (c == '/') {
		if (slash)
		    continue;
		c = '\\';
		slash = 1;
	    } else {
		slash = 0;
	    }

	    *cp++ = c;
	}


This code is also quite similar to the code in dir_fat_mangle.

I don't know if it is worth the effort to make dir_fat_mangle more
general so it can generate
a path with '/' or '\' slashes depending on the second argument:

if (mode == MODE_SYSLINUX_DOSWIN) {
    opt.directory = dir_fat_mangle(optarg, 0);
    opt.backslashesdirectory = dir_fat_mangle(optarg, 1);


win/syslinux.c needs the slash variable later for:

	/* Skip if subdirectory == root */
	if (cp > new_ldlinux_name + 3) {
	    if (!slash)
		*cp++ = '\\';

though.



- Gert



More information about the Syslinux mailing list