Support (hd0,1,a legacy partition specification

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2010-09-12 14:18:39 +02:00
parent b2b260b9eb
commit 21d7be6612

View file

@ -288,7 +288,7 @@ adjust_file (const char *in, grub_size_t len)
const char *comma, *ptr, *rest; const char *comma, *ptr, *rest;
char *ret, *outptr; char *ret, *outptr;
int overhead = 0; int overhead = 0;
int part; int part = -1, subpart = -1;
if (in[0] != '(') if (in[0] != '(')
return grub_legacy_escape (in, len); return grub_legacy_escape (in, len);
for (ptr = in + 1; ptr < in + len && *ptr && *ptr != ')' for (ptr = in + 1; ptr < in + len && *ptr && *ptr != ')'
@ -299,12 +299,17 @@ adjust_file (const char *in, grub_size_t len)
if (*comma != ',') if (*comma != ',')
return grub_legacy_escape (in, len); return grub_legacy_escape (in, len);
part = grub_strtoull (comma + 1, (char **) &rest, 0); part = grub_strtoull (comma + 1, (char **) &rest, 0);
if (rest[0] == ',' && rest[1] >= 'a' && rest[1] <= 'z')
{
subpart = rest[1] - 'a';
rest += 2;
}
for (ptr = rest; ptr < in + len && *ptr; ptr++) for (ptr = rest; ptr < in + len && *ptr; ptr++)
if (*ptr == '\'' || *ptr == '\\') if (*ptr == '\'' || *ptr == '\\')
overhead++; overhead++;
/* 30 is enough for any number. */ /* 35 is enough for any 2 numbers. */
ret = grub_malloc (ptr - in + overhead + 30); ret = grub_malloc (ptr - in + overhead + 35);
if (!ret) if (!ret)
return NULL; return NULL;
@ -316,7 +321,10 @@ adjust_file (const char *in, grub_size_t len)
*outptr++ = *ptr; *outptr++ = *ptr;
} }
grub_snprintf (outptr, 30, "%d", part + 1); if (subpart != -1)
grub_snprintf (outptr, 35, "%d,%d", part + 1, subpart + 1);
else
grub_snprintf (outptr, 35, "%d", part + 1);
while (*outptr) while (*outptr)
outptr++; outptr++;
for (ptr = rest; ptr < in + len; ptr++) for (ptr = rest; ptr < in + len; ptr++)
@ -378,8 +386,13 @@ grub_legacy_parse (const char *buf, char **entryname, int *suffix)
int len = grub_strlen (buf); int len = grub_strlen (buf);
ret = grub_malloc (len + 2); ret = grub_malloc (len + 2);
grub_memcpy (ret, buf, len); grub_memcpy (ret, buf, len);
ret[len] = '\n'; if (len && ret[len - 1] == '\n')
ret[len + 1] = 0; ret[len] = 0;
else
{
ret[len] = '\n';
ret[len + 1] = 0;
}
return ret; return ret;
} }