53aee3d6df
- grub2-automake-1-11-2.patch : fix grub2 build error on newer autotools (automake >= 1.11.2) - call ./autogen.sh - grub2-probe-disk-mountby.patch : fix grub2-probe fails on probing mount-by devices under /dev/disk/by-(id|uuid|path). (bnc#757746) OBS-URL: https://build.opensuse.org/request/show/116247 OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/grub2?expand=0&rev=33
317 lines
7.6 KiB
Diff
317 lines
7.6 KiB
Diff
Index: grub-1.99/grub-core/kern/emu/hostdisk.c
|
|
===================================================================
|
|
--- grub-1.99.orig/grub-core/kern/emu/hostdisk.c
|
|
+++ grub-1.99/grub-core/kern/emu/hostdisk.c
|
|
@@ -1150,10 +1150,14 @@ make_device_name (int drive, int dos_par
|
|
}
|
|
|
|
static char *
|
|
-convert_system_partition_to_system_disk (const char *os_dev, struct stat *st)
|
|
+convert_system_partition_to_system_disk (const char *os_dev, struct stat *st,
|
|
+ int *is_part)
|
|
{
|
|
#if defined(__linux__)
|
|
char *path = xmalloc (PATH_MAX);
|
|
+
|
|
+ *is_part = 0;
|
|
+
|
|
if (! realpath (os_dev, path))
|
|
return NULL;
|
|
|
|
@@ -1166,7 +1170,10 @@ convert_system_partition_to_system_disk
|
|
{
|
|
p = strstr (p, "part");
|
|
if (p)
|
|
- strcpy (p, "disc");
|
|
+ {
|
|
+ *is_part = 1;
|
|
+ strcpy (p, "disc");
|
|
+ }
|
|
|
|
return path;
|
|
}
|
|
@@ -1176,7 +1183,10 @@ convert_system_partition_to_system_disk
|
|
{
|
|
p = strstr (p, "part");
|
|
if (p)
|
|
- strcpy (p, "disc");
|
|
+ {
|
|
+ *is_part = 1;
|
|
+ strcpy (p, "disc");
|
|
+ }
|
|
|
|
return path;
|
|
}
|
|
@@ -1187,7 +1197,10 @@ convert_system_partition_to_system_disk
|
|
/* /dev/rd/c[0-9]+d[0-9]+(p[0-9]+)? */
|
|
p = strchr (p, 'p');
|
|
if (p)
|
|
- *p = '\0';
|
|
+ {
|
|
+ *is_part = 1;
|
|
+ *p = '\0';
|
|
+ }
|
|
|
|
return path;
|
|
}
|
|
@@ -1198,7 +1211,10 @@ convert_system_partition_to_system_disk
|
|
/* /dev/rd/c[0-9]+d[0-9]+(p[0-9]+)? */
|
|
p = strchr (p, 'p');
|
|
if (p)
|
|
- *p = '\0';
|
|
+ {
|
|
+ *is_part = 1;
|
|
+ *p = '\0';
|
|
+ }
|
|
|
|
return path;
|
|
}
|
|
@@ -1208,7 +1224,10 @@ convert_system_partition_to_system_disk
|
|
/* /dev/cciss/c[0-9]+d[0-9]+(p[0-9]+)? */
|
|
p = strchr (p, 'p');
|
|
if (p)
|
|
- *p = '\0';
|
|
+ {
|
|
+ *is_part = 1;
|
|
+ *p = '\0';
|
|
+ }
|
|
|
|
return path;
|
|
}
|
|
@@ -1219,7 +1238,10 @@ convert_system_partition_to_system_disk
|
|
/* /dev/ida/c[0-9]+d[0-9]+(p[0-9]+)? */
|
|
p = strchr (p, 'p');
|
|
if (p)
|
|
- *p = '\0';
|
|
+ {
|
|
+ *is_part = 1;
|
|
+ *p = '\0';
|
|
+ }
|
|
|
|
return path;
|
|
}
|
|
@@ -1228,6 +1250,8 @@ convert_system_partition_to_system_disk
|
|
if (strncmp ("i2o/hd", p, sizeof ("i2o/hd") - 1) == 0)
|
|
{
|
|
/* /dev/i2o/hd[a-z]([0-9]+)? */
|
|
+ if (p[sizeof ("i2o/hda") - 1])
|
|
+ *is_part = 1;
|
|
p[sizeof ("i2o/hda") - 1] = '\0';
|
|
return path;
|
|
}
|
|
@@ -1238,7 +1262,10 @@ convert_system_partition_to_system_disk
|
|
/* /dev/mmcblk[0-9]+(p[0-9]+)? */
|
|
p = strchr (p, 'p');
|
|
if (p)
|
|
- *p = '\0';
|
|
+ {
|
|
+ *is_part = 1;
|
|
+ *p = '\0';
|
|
+ }
|
|
|
|
return path;
|
|
}
|
|
@@ -1249,6 +1276,8 @@ convert_system_partition_to_system_disk
|
|
char *ptr = p + 2;
|
|
while (*ptr >= '0' && *ptr <= '9')
|
|
ptr++;
|
|
+ if (*ptr)
|
|
+ *is_part = 1;
|
|
*ptr = 0;
|
|
return path;
|
|
}
|
|
@@ -1258,6 +1287,8 @@ convert_system_partition_to_system_disk
|
|
&& p[5] >= 'a' && p[5] <= 'z')
|
|
{
|
|
/* /dev/vdisk[a-z][0-9]* */
|
|
+ if (p[6])
|
|
+ *is_part = 1;
|
|
p[6] = '\0';
|
|
return path;
|
|
}
|
|
@@ -1269,6 +1300,8 @@ convert_system_partition_to_system_disk
|
|
char *pp = p + 2;
|
|
while (*pp >= 'a' && *pp <= 'z')
|
|
pp++;
|
|
+ if (*pp)
|
|
+ *is_part = 1;
|
|
/* /dev/[hsv]d[a-z]+[0-9]* */
|
|
*pp = '\0';
|
|
return path;
|
|
@@ -1280,16 +1313,16 @@ convert_system_partition_to_system_disk
|
|
char *pp = p + 3;
|
|
while (*pp >= 'a' && *pp <= 'z')
|
|
pp++;
|
|
+ if (*pp)
|
|
+ *is_part = 1;
|
|
/* /dev/xvd[a-z]+[0-9]* */
|
|
*pp = '\0';
|
|
return path;
|
|
}
|
|
|
|
#ifdef HAVE_DEVICE_MAPPER
|
|
- /* If this is a DM-RAID device.
|
|
- Compare os_dev rather than path here, since nodes under
|
|
- /dev/mapper/ are often symlinks. */
|
|
- if ((strncmp ("/dev/mapper/", os_dev, 12) == 0))
|
|
+ if ((strncmp ("/dev/mapper/", path, sizeof ("/dev/mapper/") - 1) == 0)
|
|
+ || (strncmp ("/dev/dm-", path, sizeof ("/dev/dm-") - 1) == 0))
|
|
{
|
|
struct dm_tree *tree;
|
|
uint32_t maj, min;
|
|
@@ -1388,14 +1421,21 @@ devmapper_out:
|
|
{
|
|
char *p = strchr (path + 7, 's');
|
|
if (p)
|
|
- *p = '\0';
|
|
+ {
|
|
+ *is_part = 1;
|
|
+ *p = '\0';
|
|
+ }
|
|
}
|
|
return path;
|
|
|
|
#elif defined(__CYGWIN__)
|
|
char *path = xstrdup (os_dev);
|
|
- if (strncmp ("/dev/sd", path, 7) == 0 && 'a' <= path[7] && path[7] <= 'z')
|
|
- path[8] = 0;
|
|
+ if (strncmp ("/dev/sd", path, 7) == 0 && 'a' <= path[7] && path[7] <= 'z'
|
|
+ && path[8])
|
|
+ {
|
|
+ *is_part = 1;
|
|
+ path[8] = 0;
|
|
+ }
|
|
return path;
|
|
|
|
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
|
@@ -1404,6 +1444,8 @@ devmapper_out:
|
|
return xstrdup (os_dev);
|
|
follow_geom_up (os_dev + sizeof ("/dev/") - 1, NULL, &out);
|
|
|
|
+ if (grub_strcmp (os_dev + sizeof ("/dev/") - 1, out) != 0)
|
|
+ *is_part = 1;
|
|
out2 = xasprintf ("/dev/%s", out);
|
|
free (out);
|
|
|
|
@@ -1418,7 +1460,10 @@ devmapper_out:
|
|
{
|
|
p = strpbrk (p, "sp");
|
|
if (p)
|
|
- *p = '\0';
|
|
+ {
|
|
+ *is_part = 1;
|
|
+ *p = '\0';
|
|
+ }
|
|
break;
|
|
}
|
|
}
|
|
@@ -1445,7 +1490,11 @@ devmapper_out:
|
|
rawpart = getrawpartition();
|
|
# endif /* HAVE_GETRAWPARTITION */
|
|
if (rawpart >= 0)
|
|
- *p = 'a' + rawpart;
|
|
+ {
|
|
+ if (*p != 'a' + rawpart)
|
|
+ *is_part = 1;
|
|
+ *p = 'a' + rawpart;
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
@@ -1457,67 +1506,15 @@ devmapper_out:
|
|
#endif
|
|
}
|
|
|
|
-#if defined(__linux__) || defined(__CYGWIN__)
|
|
-static int
|
|
-device_is_wholedisk (const char *os_dev)
|
|
-{
|
|
- int len = strlen (os_dev);
|
|
-
|
|
- if (os_dev[len - 1] < '0' || os_dev[len - 1] > '9')
|
|
- return 1;
|
|
- return 0;
|
|
-}
|
|
-#endif
|
|
-
|
|
-#if defined(__NetBSD__)
|
|
-/* Try to determine whether a given device name corresponds to a whole disk.
|
|
- This function should give in most cases a definite answer, but it may
|
|
- actually give an approximate one in the following sense: if the return
|
|
- value is 0 then the device name does not correspond to a whole disk. */
|
|
-static int
|
|
-device_is_wholedisk (const char *os_dev)
|
|
-{
|
|
- int len = strlen (os_dev);
|
|
- int rawpart = -1;
|
|
-
|
|
-# ifdef HAVE_GETRAWPARTITION
|
|
- rawpart = getrawpartition();
|
|
-# endif /* HAVE_GETRAWPARTITION */
|
|
- if (rawpart < 0)
|
|
- return 1;
|
|
- return (os_dev[len - 1] == ('a' + rawpart));
|
|
-}
|
|
-#endif /* defined(__NetBSD__) */
|
|
-
|
|
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
|
-static int
|
|
-device_is_wholedisk (const char *os_dev)
|
|
-{
|
|
- const char *p;
|
|
-
|
|
- if (strncmp (os_dev, "/dev/", sizeof ("/dev/") - 1) != 0)
|
|
- return 0;
|
|
-
|
|
- for (p = os_dev + sizeof ("/dev/") - 1; *p; ++p)
|
|
- if (grub_isdigit (*p))
|
|
- {
|
|
- if (strchr (p, 's'))
|
|
- return 0;
|
|
- break;
|
|
- }
|
|
-
|
|
- return 1;
|
|
-}
|
|
-#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) */
|
|
-
|
|
static int
|
|
find_system_device (const char *os_dev, struct stat *st, int convert, int add)
|
|
{
|
|
unsigned int i;
|
|
char *os_disk;
|
|
+ int is_part;
|
|
|
|
if (convert)
|
|
- os_disk = convert_system_partition_to_system_disk (os_dev, st);
|
|
+ os_disk = convert_system_partition_to_system_disk (os_dev, st, &is_part);
|
|
else
|
|
os_disk = xstrdup (os_dev);
|
|
if (! os_disk)
|
|
@@ -1560,6 +1557,7 @@ grub_util_biosdisk_get_grub_dev (const c
|
|
{
|
|
struct stat st;
|
|
int drive;
|
|
+ int is_part;
|
|
|
|
if (stat (os_dev, &st) < 0)
|
|
{
|
|
@@ -1578,7 +1576,7 @@ grub_util_biosdisk_get_grub_dev (const c
|
|
}
|
|
|
|
if (grub_strcmp (os_dev,
|
|
- convert_system_partition_to_system_disk (os_dev, &st)) == 0)
|
|
+ convert_system_partition_to_system_disk (os_dev, &st, &is_part)) == 0)
|
|
return make_device_name (drive, -1, -1);
|
|
|
|
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__APPLE__) || defined(__NetBSD__)
|
|
@@ -1645,7 +1643,7 @@ grub_util_biosdisk_get_grub_dev (const c
|
|
|
|
grub_util_info ("%s starts from %lu", os_dev, start);
|
|
|
|
- if (start == 0 && device_is_wholedisk (os_dev))
|
|
+ if (start == 0 && !is_part)
|
|
return name;
|
|
|
|
grub_util_info ("opening the device %s", name);
|