[syslinux:master] chain.c32: make CHS calculation match core/fs/diskio.c
syslinux-bot for H. Peter Anvin
hpa at zytor.com
Tue Oct 12 22:51:02 PDT 2010
Commit-ID: 901df1bf42caf1d361ee2c1e93f48f079cd57ff9
Gitweb: http://syslinux.zytor.com/commit/901df1bf42caf1d361ee2c1e93f48f079cd57ff9
Author: H. Peter Anvin <hpa at zytor.com>
AuthorDate: Tue, 12 Oct 2010 22:46:15 -0700
Committer: H. Peter Anvin <hpa at zytor.com>
CommitDate: Tue, 12 Oct 2010 22:49:18 -0700
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 at zytor.com>
---
com32/modules/chain.c | 24 ++++++++++--------------
1 files changed, 10 insertions(+), 14 deletions(-)
diff --git a/com32/modules/chain.c b/com32/modules/chain.c
index 13878c7..b93f38e 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);
More information about the Syslinux-commits
mailing list