From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1Nbfyt-0006cp-6f for mharc-grub-devel@gnu.org; Sun, 31 Jan 2010 15:01:15 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Nbfyp-0006cN-Ps for grub-devel@gnu.org; Sun, 31 Jan 2010 15:01:11 -0500 Received: from [199.232.76.173] (port=47592 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nbfyo-0006cF-Fz for grub-devel@gnu.org; Sun, 31 Jan 2010 15:01:10 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1Nbfyk-0007gX-Uv for grub-devel@gnu.org; Sun, 31 Jan 2010 15:01:10 -0500 Received: from mail-bw0-f215.google.com ([209.85.218.215]:51033) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Nbfyk-0007g9-5L for grub-devel@gnu.org; Sun, 31 Jan 2010 15:01:06 -0500 Received: by bwz7 with SMTP id 7so2173063bwz.26 for ; Sun, 31 Jan 2010 12:01:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:x-enigmail-version:content-type; bh=f02CV8a2y7OYJ72g1y4fErUqhzAuLXGUNx0gUxpTfEI=; b=DiFX1mAt6NpH15ETU1pXn3YUKO/KInBd1V/CtUBZY6DPDnFG28nLUYlf+wxoIcwMOM xd9XuKNsMLDnMR2XYAL6ZFw/mVsLveoA2Zh/5EBJRloOSOguaHjZWMCpYtj0iTaYYiPf gE+FeY/oSPLwe9Fe/Y4zFK45/sJ/jTUu4VmtI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject :x-enigmail-version:content-type; b=IEnIGXXYRNnZ2gekw+xLWjB2ERxtj9v1HLJx+/BH5v/L82gZwbcU0SnP58LW/jeQ4d s68Y9Vnv/uBWH06uzZO+VXjbWDjJ0FEr8PN8k8+uMahr/cr7z04cOuF2m7sEBSPeiwMp sVHthp5YSgIjmr0CLhPlkZ66q6sl0Ac57Fwyc= Received: by 10.204.20.131 with SMTP id f3mr2106039bkb.162.1264968064732; Sun, 31 Jan 2010 12:01:04 -0800 (PST) Received: from debian.bg45.phnet (gprs41.swisscom-mobile.ch [193.247.250.41]) by mx.google.com with ESMTPS id 16sm1783221bwz.11.2010.01.31.12.01.02 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 31 Jan 2010 12:01:03 -0800 (PST) Message-ID: <4B65E178.4050002@gmail.com> Date: Sun, 31 Jan 2010 21:00:56 +0100 From: =?UTF-8?B?VmxhZGltaXIgJ8+GLWNvZGVyL3BoY29kZXInIFNlcmJpbmVua28=?= User-Agent: Mozilla-Thunderbird 2.0.0.22 (X11/20091109) MIME-Version: 1.0 To: The development of GRUB 2 X-Enigmail-Version: 0.95.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="------------enig6EDAD94D5ADBE1D146C2DC22" X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: [PATCH] Fix a special case when accessing partition on linux X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 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: Sun, 31 Jan 2010 20:01:11 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig6EDAD94D5ADBE1D146C2DC22 Content-Type: multipart/mixed; boundary="------------050301020605080006000607" This is a multi-part message in MIME format. --------------050301020605080006000607 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Because of cache coherency problem grub accesses partitions on linux by hdaX device and not by hda with correct offset. The problem is that because of 4K cache blocks disk.c may read sectors before the partition and hence making hostdisk.c try to read from negative offset. I'm sad that we need such workarounds for free systems. --=20 Regards Vladimir '=CF=86-coder/phcoder' Serbinenko --------------050301020605080006000607 Content-Type: text/x-diff; name="hostpart.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline; filename="hostpart.diff" =3D=3D=3D modified file 'util/hostdisk.c' --- util/hostdisk.c 2010-01-25 17:04:22 +0000 +++ util/hostdisk.c 2010-01-31 11:52:27 +0000 @@ -336,7 +336,8 @@ char dev[PATH_MAX]; =20 strcpy (dev, map[disk->id].device); - if (disk->partition && strncmp (map[disk->id].device, "/dev/", 5) =3D= =3D 0) + if (disk->partition && sector >=3D disk->partition->start + && strncmp (map[disk->id].device, "/dev/", 5) =3D=3D 0) is_partition =3D linux_find_partition (dev, disk->partition->start= ); =20 /* Open the partition. */ @@ -490,6 +491,23 @@ { int fd; =20 + /* Split pre-partition and partition reads. */ + if (disk->partition && sector < disk->partition->start + && sector + size > disk->partition->start) + { + grub_err_t err; + err =3D grub_util_biosdisk_read (disk, sector, + disk->partition->start - sector, + buf); + if (err) + return err; + + return grub_util_biosdisk_read (disk, disk->partition->start, + size - (disk->partition->start - sector), + buf + ((disk->partition->start - sector) + << GRUB_DISK_SECTOR_BITS)); + } + fd =3D open_device (disk, sector, O_RDONLY); if (fd < 0) return grub_errno; @@ -527,6 +545,23 @@ { int fd; =20 + /* Split pre-partition and partition writes. */ + if (disk->partition && sector < disk->partition->start + && sector + size > disk->partition->start) + { + grub_err_t err; + err =3D grub_util_biosdisk_write (disk, sector, + disk->partition->start - sector, + buf); + if (err) + return err; + + return grub_util_biosdisk_write (disk, disk->partition->start, + size - (disk->partition->start - sector), + buf + ((disk->partition->start - sector) + << GRUB_DISK_SECTOR_BITS)); + } + fd =3D open_device (disk, sector, O_WRONLY); if (fd < 0) return grub_errno; --------------050301020605080006000607-- --------------enig6EDAD94D5ADBE1D146C2DC22 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.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iF4EAREKAAYFAktl4XgACgkQNak7dOguQgmaYAD+KHW1IPGV0LS/SQZiEkIHsULO 3oF0b55E/D8RCVoi5EYBAKptzike4df9keRMm0LOBGupKL056BiSr26RYrOHgiBw =vuuD -----END PGP SIGNATURE----- --------------enig6EDAD94D5ADBE1D146C2DC22--