From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1VoZFn-0006Ku-Qj for mharc-grub-devel@gnu.org; Thu, 05 Dec 2013 08:46:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35335) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VoZFg-0006K8-QR for grub-devel@gnu.org; Thu, 05 Dec 2013 08:46:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VoZFb-0003FK-2q for grub-devel@gnu.org; Thu, 05 Dec 2013 08:46:00 -0500 Received: from mail-wi0-x22b.google.com ([2a00:1450:400c:c05::22b]:37165) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VoZFa-0003F1-OQ for grub-devel@gnu.org; Thu, 05 Dec 2013 08:45:54 -0500 Received: by mail-wi0-f171.google.com with SMTP id ca18so9905929wib.10 for ; Thu, 05 Dec 2013 05:45:53 -0800 (PST) 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:content-type; bh=NT9c7QOyLMf+3bD1UDWRfFmBSuSLwtvZO7VlBLfgYko=; b=ihBvM1yOE2TQrPFInMbhq7lPGenGGa13waix/jHRCs1OQ9MRBDP3cTV7QQbcgllCBC rUfBEol9cJo554x/HZCNt1u1LHbd2J1T06zzpGMwIE4pVFLpAjaLgiE6qqX9lzg5+oGq hCO8klP4LZC40pXg6OjhmGj6VuoU3TaZT67TdVn1NQ/ZFmeeBbPqP06pq8kYjEkU+z+8 33arOzDzHMPN0Y9XbO5cVCu7bTt2/6IZUhdTo2atoiCKFNUIIfwkkzRn1IcYrhKbFLJv yXe5o1i/BfiKC3ZkyEeF2fMWNOWcJcfTBFRpGwXSEi9J3eWpEOZugoivKg5qSL9X/xfp sdqg== X-Received: by 10.180.74.45 with SMTP id q13mr12103183wiv.47.1386251153067; Thu, 05 Dec 2013 05:45:53 -0800 (PST) Received: from [10.2.56.203] (public-docking-pat-hg-mapped-0039.ethz.ch. [195.176.110.104]) by mx.google.com with ESMTPSA id gb1sm6595287wic.0.2013.12.05.05.45.51 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 05 Dec 2013 05:45:51 -0800 (PST) Message-ID: <52A0838D.3060308@gmail.com> Date: Thu, 05 Dec 2013 14:45:49 +0100 From: =?UTF-8?B?VmxhZGltaXIgJ8+GLWNvZGVyL3BoY29kZXInIFNlcmJpbmVua28=?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131005 Icedove/17.0.9 MIME-Version: 1.0 To: The development of GNU GRUB Subject: Re: [PATCH] On Linux, read partition start offsets from sysfs if possible References: <20131205121723.GN16147@riva.ucam.org> In-Reply-To: <20131205121723.GN16147@riva.ucam.org> X-Enigmail-Version: 1.5.1 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="----enig2EOWABAMEARDGOGPVSPRU" X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::22b 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: Thu, 05 Dec 2013 13:46:06 -0000 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) ------enig2EOWABAMEARDGOGPVSPRU Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Looks good. Go ahead. On 05.12.2013 13:17, Colin Watson wrote: > This lets us cope with block device drivers that don't implement > HDIO_GETGEO. Fixes Ubuntu bug #1237519. >=20 > * grub-core/osdep/linux/hostdisk.c (sysfs_partition_path): New > function. > (sysfs_partition_start): Likewise. > (grub_util_find_partition_start_os): Try sysfs_partition_start > before HDIO_GETGEO. > --- > ChangeLog | 12 ++++++ > grub-core/osdep/linux/hostdisk.c | 89 ++++++++++++++++++++++++++++++++= ++++++++ > 2 files changed, 101 insertions(+) >=20 > diff --git a/ChangeLog b/ChangeLog > index d60acab..d08d841 100644 > --- a/ChangeLog > +++ b/ChangeLog > @@ -1,3 +1,15 @@ > +2013-12-05 Colin Watson > + > + On Linux, read partition start offsets from sysfs if possible, to > + cope with block device drivers that don't implement HDIO_GETGEO. > + Fixes Ubuntu bug #1237519. > + > + * grub-core/osdep/linux/hostdisk.c (sysfs_partition_path): New > + function. > + (sysfs_partition_start): Likewise. > + (grub_util_find_partition_start_os): Try sysfs_partition_start > + before HDIO_GETGEO. > + > 2013-12-05 Vladimir Serbinenko > =20 > Handle unaligned .bss on sparc64. > diff --git a/grub-core/osdep/linux/hostdisk.c b/grub-core/osdep/linux/h= ostdisk.c > index a2c80f3..74d87a4 100644 > --- a/grub-core/osdep/linux/hostdisk.c > +++ b/grub-core/osdep/linux/hostdisk.c > @@ -27,6 +27,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -39,6 +40,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -93,12 +95,99 @@ grub_util_get_fd_size_os (grub_util_fd_t fd, const = char *name, unsigned *log_sec > return nr; > } > =20 > +static char * > +sysfs_partition_path (const char *dev, const char *entry) > +{ > + const char *argv[7]; > + int fd; > + pid_t pid; > + FILE *udevadm; > + char *buf =3D NULL; > + size_t len =3D 0; > + char *path =3D NULL; > + > + argv[0] =3D "udevadm"; > + argv[1] =3D "info"; > + argv[2] =3D "--query"; > + argv[3] =3D "path"; > + argv[4] =3D "--name"; > + argv[5] =3D dev; > + argv[6] =3D NULL; > + > + pid =3D grub_util_exec_pipe (argv, &fd); > + > + if (!pid) > + return NULL; > + > + /* Parent. Read udevadm's output. */ > + udevadm =3D fdopen (fd, "r"); > + if (!udevadm) > + { > + grub_util_warn (_("Unable to open stream from %s: %s"), > + "udevadm", strerror (errno)); > + close (fd); > + goto out; > + } > + > + if (getline (&buf, &len, udevadm) > 0) > + { > + char *newline; > + > + newline =3D strchr (buf, '\n'); > + if (newline) > + *newline =3D '\0'; > + path =3D xasprintf ("/sys%s/%s", buf, entry); > + } > + > +out: > + if (udevadm) > + fclose (udevadm); > + waitpid (pid, NULL, 0); > + free (buf); > + > + return path; > +} > + > +static int > +sysfs_partition_start (const char *dev, grub_disk_addr_t *start) > +{ > + char *path; > + FILE *fp; > + unsigned long long val; > + int ret =3D 0; > + > + path =3D sysfs_partition_path (dev, "start"); > + if (!path) > + return 0; > + > + fp =3D grub_util_fopen (path, "r"); > + if (!fp) > + goto out; > + > + if (fscanf (fp, "%llu", &val) =3D=3D 1) > + { > + *start =3D (grub_disk_addr_t) val; > + ret =3D 1; > + } > + > +out: > + free (path); > + if (fp) > + fclose (fp); > + > + return ret; > +} > + > grub_disk_addr_t > grub_util_find_partition_start_os (const char *dev) > { > + grub_disk_addr_t start; > grub_util_fd_t fd; > struct hd_geometry hdg; > =20 > + if (sysfs_partition_start (dev, &start)) > + return start; > + > fd =3D open (dev, O_RDONLY); > if (fd =3D=3D -1) > { >=20 ------enig2EOWABAMEARDGOGPVSPRU 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.15 (GNU/Linux) Comment: Using GnuPG with Icedove - http://www.enigmail.net/ iF4EAREKAAYFAlKgg44ACgkQmBXlbbo5nOvEcwD/XWtMhLTHseO6o8M0KCMexAXA IWE/MsKdCKfGUKpbrg4A/3PBlFwMQWjBQkaivh/fO8i8qD7cOdBtMFLnQv9nm6NH =5Azt -----END PGP SIGNATURE----- ------enig2EOWABAMEARDGOGPVSPRU--