aboutsummaryrefslogtreecommitdiffstats
path: root/com32
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2010-10-12 22:46:15 -0700
committerH. Peter Anvin <hpa@zytor.com>2010-10-12 22:49:18 -0700
commit901df1bf42caf1d361ee2c1e93f48f079cd57ff9 (patch)
tree2a88d52c1e7fa9ee555a6ded3c473a912104cad9 /com32
parent0d738aa71b053f185cf5fbc126b1bbb6fb8d478b (diff)
downloadsyslinux-901df1bf42caf1d361ee2c1e93f48f079cd57ff9.tar.gz
syslinux-901df1bf42caf1d361ee2c1e93f48f079cd57ff9.tar.xz
syslinux-901df1bf42caf1d361ee2c1e93f48f079cd57ff9.zip
chain.c32: make CHS calculation match core/fs/diskio.c
Use the same format for the CHS calculation as in core/fs/diskio.c; also, apply the correct limits, and propagate the fix to the write routine. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'com32')
-rw-r--r--com32/modules/chain.c24
1 files changed, 10 insertions, 14 deletions
diff --git a/com32/modules/chain.c b/com32/modules/chain.c
index 13878c70..b93f38ed 100644
--- a/com32/modules/chain.c
+++ b/com32/modules/chain.c
@@ -266,23 +266,21 @@ static void *read_sectors(uint64_t lba, uint8_t count)
if (lba)
return NULL; /* Can only read MBR */
- s = 1;
- h = 0;
- c = 0;
+ s = h = c = 0;
} else {
- s = (lba % disk_info.sect) + 1;
+ s = lba % disk_info.sect;
t = lba / disk_info.sect; /* Track = head*cyl */
h = t % disk_info.head;
c = t / disk_info.head;
}
- if (s > 63 || h > 256 || c > 1023)
+ if (s >= 63 || h >= 256 || c >= 1024)
return NULL;
inreg.eax.b[0] = count;
inreg.eax.b[1] = 0x02; /* Read */
- inreg.ecx.b[1] = c & 0xff;
- inreg.ecx.b[0] = ((c >> 2) & 0xc0) + s;
+ inreg.ecx.b[1] = c;
+ inreg.ecx.b[0] = ((c & 0x300) >> 2) | (s+1);
inreg.edx.b[1] = h;
inreg.edx.b[0] = disk_info.disk;
inreg.ebx.w[0] = OFFS(buf);
@@ -327,22 +325,20 @@ static int write_sector(unsigned int lba, const void *data)
if (lba)
return -1; /* Can only write MBR */
- s = 1;
- h = 0;
- c = 0;
+ s = h = c = 0;
} else {
- s = (lba % disk_info.sect) + 1;
+ s = lba % disk_info.sect;
t = lba / disk_info.sect; /* Track = head*cyl */
h = t % disk_info.head;
c = t / disk_info.head;
}
- if (s > 63 || h > 256 || c > 1023)
+ if (s >= 63 || h >= 256 || c >= 1024)
return -1;
inreg.eax.w[0] = 0x0301; /* Write one sector */
- inreg.ecx.b[1] = c & 0xff;
- inreg.ecx.b[0] = s + (c >> 6);
+ inreg.ecx.b[1] = c;
+ inreg.ecx.b[0] = ((c & 0x300) >> 2) | (s+1);
inreg.edx.b[1] = h;
inreg.edx.b[0] = disk_info.disk;
inreg.ebx.w[0] = OFFS(buf);