Index: util/getroot.c
===================================================================
--- util/getroot.c (Revision 1777)
+++ util/getroot.c (Arbeitskopie)
@@ -17,6 +17,7 @@
* along with GRUB. If not, see .
*/
+#include
#include
#include
#include
@@ -406,67 +407,40 @@
switch (grub_util_get_dev_abstraction (os_dev))
{
- case GRUB_DEV_ABSTRACTION_LVM:
- grub_dev = xmalloc (strlen (os_dev) - 12 + 1);
+ case GRUB_DEV_ABSTRACTION_LVM:
- strcpy (grub_dev, os_dev + 12);
+ asprintf (&grub_dev, "%s", os_dev + sizeof ("/dev/mapper/") -1);
+ break;
- break;
+ case GRUB_DEV_ABSTRACTION_RAID:
- case GRUB_DEV_ABSTRACTION_RAID:
- grub_dev = xmalloc (20);
+ if (os_dev[7] == '_' && os_dev[8] == 'd')
+ {
+ /* This a partitionable RAID device of the form /dev/md_dNNpMM. */
- if (os_dev[7] == '_' && os_dev[8] == 'd')
- {
- const char *p;
+ char *p;
- /* This a partitionable RAID device of the form /dev/md_dNNpMM. */
- int i;
+ p = strchr (os_dev, 'p');
+ if (p)
+ *p = ',';
- grub_dev[0] = 'm';
- grub_dev[1] = 'd';
- i = 2;
-
- p = os_dev + 9;
- while (*p >= '0' && *p <= '9')
- {
- grub_dev[i] = *p;
- i++;
- p++;
- }
+ asprintf (grub_dev, "md%s", os_dev + sizeof ("/dev/md_d") -1);
+ }
+ else if (os_dev[7] >= '0' && os_dev[7] <= '9')
+ {
+ asprintf (&grub_dev, "md%s", os_dev + sizeof ("/dev/md") -1);
+ }
+ else if (os_dev[7] == '/' && os_dev[8] >= '0' && os_dev[8] <= '9')
+ {
+ asprintf (&grub_dev, "md%s", os_dev + sizeof ("/dev/md/") -1);
+ }
+ else
+ grub_util_error ("Unknown kind of RAID device `%s'", os_dev);
- if (*p == '\0')
- grub_dev[i] = '\0';
- else if (*p == 'p')
- {
- p++;
- grub_dev[i] = ',';
- i++;
+ break;
- while (*p >= '0' && *p <= '9')
- {
- grub_dev[i] = *p;
- i++;
- p++;
- }
-
- grub_dev[i] = '\0';
- }
- else
- grub_util_error ("Unknown kind of RAID device `%s'", os_dev);
- }
- else if (os_dev[7] >= '0' && os_dev[7] <= '9')
- {
- memcpy (grub_dev, os_dev + 5, 7);
- grub_dev[7] = '\0';
- }
- else
- grub_util_error ("Unknown kind of RAID device `%s'", os_dev);
-
- break;
-
- default: /* GRUB_DEV_ABSTRACTION_NONE */
- grub_dev = grub_util_biosdisk_get_grub_dev (os_dev);
+ default: /* GRUB_DEV_ABSTRACTION_NONE */
+ grub_dev = grub_util_biosdisk_get_grub_dev (os_dev);
}
return grub_dev;