From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1SLDWH-0005Ji-6I for mharc-grub-devel@gnu.org; Fri, 20 Apr 2012 09:05:01 -0400 Received: from eggs.gnu.org ([208.118.235.92]:52547) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SLDW6-00054L-Oo for grub-devel@gnu.org; Fri, 20 Apr 2012 09:04:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SLDVw-0000zE-Si for grub-devel@gnu.org; Fri, 20 Apr 2012 09:04:50 -0400 Received: from mail-wi0-f177.google.com ([209.85.212.177]:41742) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SLDVw-0000yX-GM for grub-devel@gnu.org; Fri, 20 Apr 2012 09:04:40 -0400 Received: by wibhj13 with SMTP id hj13so499742wib.12 for ; Fri, 20 Apr 2012 06:04:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:x-enigmail-version:content-type; bh=b8GiIxWU9fdVTdkDayJUiN8oh3it4qzuwXF4ReJbvQ4=; b=Ks8zb/koqx5YNeAIirWOUTNmWh3Xal1C6JN+7eN4GPUKaUvI0eVO4h+Hw8Q7rv7beP BofPTphU32njgnifE0cVUJDNoPWx0/Xj7gcy+IIY71M+dpna35e2rbBrK4CJxpJZGW5y P0FK0Br9SlyP0tvIivym3dtxbxs3eR03Ykro0JQOayiGUByZqn9rp/Sf1gd8pW1iXya5 irrTL8Ohe7I7yT20s+hCIl83QriA6lRY4VgTrNRHHHgnLE/i3ImscWgA14nogrV2MgRn uOeFViublrNBaZVw0/R7Ve1lw/AJJwLAIa1TUt4N1WOx2Dr2kHGCjoSyhN5WXbpVy5U/ fAHg== Received: by 10.180.107.104 with SMTP id hb8mr5796690wib.8.1334927078297; Fri, 20 Apr 2012 06:04:38 -0700 (PDT) Received: from debian.x201.phnet (39-232.197-178.cust.bluewin.ch. [178.197.232.39]) by mx.google.com with ESMTPS id ex2sm8581223wib.8.2012.04.20.06.04.35 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 20 Apr 2012 06:04:36 -0700 (PDT) Message-ID: <4F915EDE.4070508@gmail.com> Date: Fri, 20 Apr 2012 15:04:30 +0200 From: =?UTF-8?B?VmxhZGltaXIgJ8+GLWNvZGVyL3BoY29kZXInIFNlcmJpbmVua28=?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.3) Gecko/20120329 Icedove/10.0.3 MIME-Version: 1.0 To: The development of GNU GRUB Subject: Re: [PATCH] fix grub-probe fail on by-(id|uuid|path) device names References: <20120420114048.GA31890@linux-dsax.tai.apac.novell.com> In-Reply-To: <20120420114048.GA31890@linux-dsax.tai.apac.novell.com> X-Enigmail-Version: 1.4 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="------------enig9FB8CF93D1CB5C83B87455FA" X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.212.177 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Apr 2012 13:04:58 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig9FB8CF93D1CB5C83B87455FA Content-Type: multipart/mixed; boundary="------------080003080901070707080608" This is a multi-part message in MIME format. --------------080003080901070707080608 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 20.04.2012 13:40, Michael Chang wrote: > This patch fixes grub-probe fails on probing devices under > /dev/disk/by-id and other similar mount-by alias names. The method > used to determine the whole disk is by it's name without numeric > character end, but this may be wrong for the by-(id|uuid|path) names > as they are not necessary ended without numeric character. For > instance, my disk was named > "/dev/disk/by-id/ata-WDC_WD1600BEKT-60V5T1_WD-WXK0A69Y4761". > > The fix is use resolved link to kernel device names (like /dev/sda) > instead of these alias names. > > Downstream bug: > https://bugzilla.novell.com/show_bug.cgi?id=3D757746 > > > > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > https://lists.gnu.org/mailman/listinfo/grub-devel --=20 Regards Vladimir '=CF=86-coder/phcoder' Serbinenko --------------080003080901070707080608 Content-Type: text/x-diff; name="getroot.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="getroot.diff" =3D=3D=3D modified file 'util/getroot.c' --- util/getroot.c 2012-03-31 10:27:10 +0000 +++ util/getroot.c 2012-04-20 13:01:53 +0000 @@ -1642,10 +1642,14 @@ } =20 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 =3D xmalloc (PATH_MAX); + + *is_part =3D 0; + if (! realpath (os_dev, path)) return NULL; =20 @@ -1658,7 +1662,10 @@ { p =3D strstr (p, "part"); if (p) - strcpy (p, "disc"); + { + *is_part =3D 1; + strcpy (p, "disc"); + } =20 return path; } @@ -1668,7 +1675,10 @@ { p =3D strstr (p, "part"); if (p) - strcpy (p, "disc"); + { + *is_part =3D 1; + strcpy (p, "disc"); + } =20 return path; } @@ -1679,7 +1689,10 @@ /* /dev/rd/c[0-9]+d[0-9]+(p[0-9]+)? */ p =3D strchr (p, 'p'); if (p) - *p =3D '\0'; + { + *is_part =3D 1; + *p =3D '\0'; + } =20 return path; } @@ -1690,7 +1703,10 @@ /* /dev/rd/c[0-9]+d[0-9]+(p[0-9]+)? */ p =3D strchr (p, 'p'); if (p) - *p =3D '\0'; + { + *is_part =3D 1; + *p =3D '\0'; + } =20 return path; } @@ -1700,7 +1716,10 @@ /* /dev/cciss/c[0-9]+d[0-9]+(p[0-9]+)? */ p =3D strchr (p, 'p'); if (p) - *p =3D '\0'; + { + *is_part =3D 1; + *p =3D '\0'; + } =20 return path; } @@ -1711,7 +1730,10 @@ /* /dev/ida/c[0-9]+d[0-9]+(p[0-9]+)? */ p =3D strchr (p, 'p'); if (p) - *p =3D '\0'; + { + *is_part =3D 1; + *p =3D '\0'; + } =20 return path; } @@ -1720,6 +1742,8 @@ if (strncmp ("i2o/hd", p, sizeof ("i2o/hd") - 1) =3D=3D 0) { /* /dev/i2o/hd[a-z]([0-9]+)? */ + if (p[sizeof ("i2o/hda") - 1]) + *is_part =3D 1; p[sizeof ("i2o/hda") - 1] =3D '\0'; return path; } @@ -1730,7 +1754,10 @@ /* /dev/mmcblk[0-9]+(p[0-9]+)? */ p =3D strchr (p, 'p'); if (p) - *p =3D '\0'; + { + *is_part =3D 1; + *p =3D '\0'; + } =20 return path; } @@ -1741,6 +1768,8 @@ char *ptr =3D p + 2; while (*ptr >=3D '0' && *ptr <=3D '9') ptr++; + if (*ptr) + *is_part =3D 1; *ptr =3D 0; return path; } @@ -1750,6 +1779,8 @@ && p[5] >=3D 'a' && p[5] <=3D 'z') { /* /dev/vdisk[a-z][0-9]* */ + if (p[6]) + *is_part =3D 1; p[6] =3D '\0'; return path; } @@ -1761,6 +1792,8 @@ char *pp =3D p + 2; while (*pp >=3D 'a' && *pp <=3D 'z') pp++; + if (*pp) + *is_part =3D 1; /* /dev/[hsv]d[a-z]+[0-9]* */ *pp =3D '\0'; return path; @@ -1772,16 +1805,16 @@ char *pp =3D p + 3; while (*pp >=3D 'a' && *pp <=3D 'z') pp++; + if (*pp) + *is_part =3D 1; /* /dev/xvd[a-z]+[0-9]* */ *pp =3D '\0'; return path; } =20 #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) =3D=3D 0)) + if ((strncmp ("/dev/mapper/", path, sizeof ("/dev/mapper/") - 1) =3D= =3D 0) + || (strncmp ("/dev/dm-", path, sizeof ("/dev/dm-") - 1) =3D=3D 0)) { struct dm_tree *tree; uint32_t maj, min; @@ -1843,6 +1876,7 @@ && grub_util_get_dm_node_linear_info (node_name, &major, &minor)) { + *is_part =3D 1; if (tree) dm_tree_free (tree); free (path); @@ -1914,14 +1948,21 @@ { char *p =3D strchr (path + 7, 's'); if (p) - *p =3D '\0'; + { + *is_part =3D 1; + *p =3D '\0'; + } } return path; =20 #elif defined(__CYGWIN__) char *path =3D xstrdup (os_dev); - if (strncmp ("/dev/sd", path, 7) =3D=3D 0 && 'a' <=3D path[7] && path[= 7] <=3D 'z') - path[8] =3D 0; + if (strncmp ("/dev/sd", path, 7) =3D=3D 0 && 'a' <=3D path[7] && path[= 7] <=3D 'z' + && path[8]) + { + *is_part =3D 1; + path[8] =3D 0; + } return path; =20 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) @@ -1930,6 +1971,8 @@ return xstrdup (os_dev); grub_util_follow_gpart_up (os_dev + sizeof ("/dev/") - 1, NULL, &out);= =20 + if (grub_strcmp (os_dev + sizeof ("/dev/") - 1, out) !=3D 0) + *is_part =3D 1; out2 =3D xasprintf ("/dev/%s", out); free (out); =20 @@ -1944,7 +1987,10 @@ { p =3D strpbrk (p, "sp"); if (p) - *p =3D '\0'; + { + *is_part =3D 1; + *p =3D '\0'; + } break; } } @@ -1980,6 +2026,7 @@ close (fd); return xstrdup (os_dev); } + *is_part =3D (dkw.dkw_offset !=3D 0); close (fd); return xasprintf ("/dev/r%s%c", dkw.dkw_parent, 'a' + rawpart); } @@ -1997,6 +2044,8 @@ p++; if ((*p >=3D 'a' && *p <=3D 'z') && (*(p+1) =3D=3D '\0')) { + if (*p !=3D 'a' + rawpart) + *is_part =3D 1; /* path matches the required regular expression and p points to its last character. */ *p =3D 'a' + rawpart; @@ -2013,6 +2062,8 @@ && colon) { char *ret =3D xmalloc (colon - os_dev + sizeof (":q,raw")); + if (grub_strcmp (colon, ":q,raw") !=3D 0) + *is_part =3D 1; grub_memcpy (ret, os_dev, colon - os_dev); grub_memcpy (ret + (colon - os_dev), ":q,raw", sizeof (":q,raw"));= return ret; @@ -2030,9 +2081,10 @@ { char *os_disk; const char *drive; + int is_part; =20 if (convert) - os_disk =3D convert_system_partition_to_system_disk (os_dev, st); + os_disk =3D convert_system_partition_to_system_disk (os_dev, st, &is= _part); else os_disk =3D xstrdup (os_dev); if (! os_disk) @@ -2076,76 +2128,11 @@ return ret; } =20 -#if defined(__sun__) -static int -device_is_wholedisk (const char *os_dev) -{ - if (grub_memcmp (os_dev, "/devices/", sizeof ("/devices/") - 1) !=3D 0= ) - return 1; - if (grub_memcmp (os_dev + strlen (os_dev) - (sizeof (":q,raw") - 1), - ":q,raw", (sizeof (":q,raw") - 1)) =3D=3D 0) - return 1; - return 0; -} -#endif - -#if defined(__linux__) || defined(__CYGWIN__) -static int -device_is_wholedisk (const char *os_dev) -{ - int len =3D 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 d= isk. - This function should give in most cases a definite answer, but it may= - actually give an approximate one in the following sense: if the retur= n - 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 =3D strlen (os_dev); - int rawpart =3D -1; - -# ifdef HAVE_GETRAWPARTITION - rawpart =3D getrawpartition(); -# endif /* HAVE_GETRAWPARTITION */ - if (rawpart < 0) - return 1; - return (os_dev[len - 1] =3D=3D ('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) !=3D 0) - return 0; - - for (p =3D 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__) */ - char * grub_util_get_os_disk (const char *os_dev) { struct stat st; + int is_part; =20 grub_util_info ("Looking for %s", os_dev); =20 @@ -2158,7 +2145,7 @@ return 0; } =20 - return convert_system_partition_to_system_disk (os_dev, &st); + return convert_system_partition_to_system_disk (os_dev, &st, &is_part)= ; } =20 char * @@ -2167,6 +2154,7 @@ struct stat st; const char *drive; char *sys_disk; + int is_part; =20 grub_util_info ("Looking for %s", os_dev); =20 @@ -2180,7 +2168,7 @@ } =20 drive =3D find_system_device (os_dev, &st, 1, 1); - sys_disk =3D convert_system_partition_to_system_disk (os_dev, &st); + sys_disk =3D convert_system_partition_to_system_disk (os_dev, &st, &is= _part); if (grub_strcmp (os_dev, sys_disk) =3D=3D 0) { free (sys_disk); @@ -2252,7 +2240,7 @@ =20 grub_util_info ("%s starts from %" PRIuGRUB_UINT64_T, os_dev, start)= ; =20 - if (start =3D=3D 0 && device_is_wholedisk (os_dev)) + if (start =3D=3D 0 && !is_part) return name; =20 grub_util_info ("opening the device %s", name); --------------080003080901070707080608-- --------------enig9FB8CF93D1CB5C83B87455FA Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iF4EAREKAAYFAk+RXt4ACgkQNak7dOguQgkXvQD+Iz6qZC6McHtVuH3EdyIY36R/ 3LmpFtp1GuZ+iTWsdlwA/05YY0TjWTO1F92YyiKtCJgBNzT4CV2Wz9IUl0tLNTh9 =sAXO -----END PGP SIGNATURE----- --------------enig9FB8CF93D1CB5C83B87455FA--