File grub-iso-fixes of Package grub
From: Jeff Mahoney <jeffm@suse.com>
Subject: [PATCH] grub: Fix iso sector/offset calculations
This patch fixes iso9660 sector calculations when byte_offset is nonzero
and the device sector size != file system sector. This is due to it
accounting for the byte_offset before left-shifting the sector number
instead of afterwards.
For example, the old code would make the following translation for a device
with 512 byte sectors:
file system device
sector 10, offset 512 sector 44, offset 0
10 * 2048 + 512 = 20992 44 * 512 = 22528
The correct translation is sector 41, offset 0: 41 * 512 = 20992
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
stage2/fsys_iso9660.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
--- a/stage2/fsys_iso9660.c
+++ b/stage2/fsys_iso9660.c
@@ -81,12 +86,12 @@ iso9660_devread (int sector, int byte_of
if (byte_len <= 0)
return 1;
- sector += (byte_offset >> sector_size_lg2);
- byte_offset &= (buf_geom.sector_size - 1);
asm volatile ("shl%L0 %1,%0"
: "=r"(sector)
: "Ic"((int8_t)(ISO_SECTOR_BITS - sector_size_lg2)),
"0"(sector));
+ sector += (byte_offset >> sector_size_lg2);
+ byte_offset &= (buf_geom.sector_size - 1);
#if !defined(STAGE1_5)
if (disk_read_hook && debug)