Support escaped commas in hostdisk.

* grub-core/kern/emu/hostdisk.c (unescape_cmp): New function.
	(find_grub_drive): Use unescape_cmp.
	(make_device_name): Escape commas.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2011-11-08 12:15:57 +01:00
parent 78e08dc3cb
commit cac14fb663
2 changed files with 49 additions and 17 deletions

View file

@ -1,3 +1,11 @@
2011-11-08 Vladimir Serbinenko <phcoder@gmail.com>
Support escaped commas in hostdisk.
* grub-core/kern/emu/hostdisk.c (unescape_cmp): New function.
(find_grub_drive): Use unescape_cmp.
(make_device_name): Escape commas.
2011-11-08 Vladimir Serbinenko <phcoder@gmail.com> 2011-11-08 Vladimir Serbinenko <phcoder@gmail.com>
* util/grub.d/10_kfreebsd.in: Use ${grub_mkrelpath} not grub-mkrelpath. * util/grub.d/10_kfreebsd.in: Use ${grub_mkrelpath} not grub-mkrelpath.

View file

@ -184,6 +184,27 @@ configure_device_driver (int fd)
} }
#endif /* defined(__NetBSD__) */ #endif /* defined(__NetBSD__) */
static int
unescape_cmp (const char *a, const char *b_escaped)
{
while (*a || *b_escaped)
{
if (*b_escaped == '\\' && b_escaped[1] != 0)
b_escaped++;
if (*a < *b_escaped)
return -1;
if (*a > *b_escaped)
return +1;
a++;
b_escaped++;
}
if (*a)
return +1;
if (*b_escaped)
return -1;
return 0;
}
static int static int
find_grub_drive (const char *name) find_grub_drive (const char *name)
{ {
@ -192,7 +213,7 @@ find_grub_drive (const char *name)
if (name) if (name)
{ {
for (i = 0; i < ARRAY_SIZE (map); i++) for (i = 0; i < ARRAY_SIZE (map); i++)
if (map[i].drive && ! strcmp (map[i].drive, name)) if (map[i].drive && unescape_cmp (map[i].drive, name) == 0)
return i; return i;
} }
@ -1140,25 +1161,28 @@ grub_util_biosdisk_fini (void)
static char * static char *
make_device_name (int drive, int dos_part, int bsd_part) make_device_name (int drive, int dos_part, int bsd_part)
{ {
char *ret; char *ret, *ptr, *end;
char *dos_part_str = NULL; const char *iptr;
char *bsd_part_str = NULL;
ret = xmalloc (strlen (map[drive].drive) * 2
+ sizeof (",XXXXXXXXXXXXXXXXXXXXXXXXXX"
",XXXXXXXXXXXXXXXXXXXXXXXXXX"));
end = (ret + strlen (map[drive].drive) * 2
+ sizeof (",XXXXXXXXXXXXXXXXXXXXXXXXXX"
",XXXXXXXXXXXXXXXXXXXXXXXXXX"));
ptr = ret;
for (iptr = map[drive].drive; *iptr; iptr++)
{
if (*iptr == ',')
*ptr++ = '\\';
*ptr++ = *iptr;
}
*ptr = 0;
if (dos_part >= 0) if (dos_part >= 0)
dos_part_str = xasprintf (",%d", dos_part + 1); snprintf (ptr, end - ptr, ",%d", dos_part + 1);
ptr += strlen (ptr);
if (bsd_part >= 0) if (bsd_part >= 0)
bsd_part_str = xasprintf (",%d", bsd_part + 1); snprintf (ptr, end - ptr, ",%d", bsd_part + 1);
ret = xasprintf ("%s%s%s", map[drive].drive,
dos_part_str ? : "",
bsd_part_str ? : "");
if (dos_part_str)
free (dos_part_str);
if (bsd_part_str)
free (bsd_part_str);
return ret; return ret;
} }