aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Soltys <soltys@ziu.info>2010-08-28 16:13:56 +0200
committerMichal Soltys <soltys@ziu.info>2010-09-28 09:32:53 +0200
commit6284280151651423a8d86672d3773402ba4c0037 (patch)
tree9c0a2a03320a423abd527d917337621d63fb1435
parentd4cbb325b3ef7e999ccf8ed9ac5fe8da102ab5f4 (diff)
downloadsyslinux-6284280151651423a8d86672d3773402ba4c0037.tar.gz
syslinux-6284280151651423a8d86672d3773402ba4c0037.tar.xz
syslinux-6284280151651423a8d86672d3773402ba4c0037.zip
chain/utility.c: Adjust lba2chs
This tiny patch adjusts how lba2chs() deals with unknown geometries. Instead of returning max values of "typical" geometries, it returns chs values calculated from them. Signed-off-by: Michal Soltys <soltys@ziu.info>
-rw-r--r--com32/chain/utility.c55
1 files changed, 29 insertions, 26 deletions
diff --git a/com32/chain/utility.c b/com32/chain/utility.c
index 828c85e2..98249529 100644
--- a/com32/chain/utility.c
+++ b/com32/chain/utility.c
@@ -51,37 +51,40 @@ void wait_key(void)
uint32_t lba2chs(const struct disk_info *di, uint64_t lba)
{
uint32_t c, h, s, t;
+ uint32_t cs, hs, ss;
+ /*
+ * Not much reason here, but if we have no valid chs geometry, we assume
+ * "typical" ones to have something to return.
+ */
if (di->cbios) {
- if (lba >= di->cyl * di->head * di->sect) {
- s = di->sect;
- h = di->head - 1;
- c = di->cyl - 1;
- goto out;
+ cs = di->cyl;
+ hs = di->head;
+ ss = di->sect;
+ } else {
+ if (di->disk & 0x80) {
+ cs = 1024;
+ hs = 255;
+ ss = 63;
+ } else {
+ cs = 80;
+ hs = 2;
+ ss = 18;
}
- s = ((uint32_t)lba % di->sect) + 1;
- t = (uint32_t)lba / di->sect;
- h = t % di->head;
- c = t / di->head;
- } else
- goto fallback;
+ }
-out:
- return h | (s << 8) | ((c & 0x300) << 6) | ((c & 0xFF) << 16);
+ if (lba >= cs*hs*ss) {
+ s = ss;
+ h = hs - 1;
+ c = cs - 1;
+ } else {
+ s = ((uint32_t)lba % ss) + 1;
+ t = (uint32_t)lba / ss;
+ h = t % hs;
+ c = t / hs;
+ }
-fallback:
- if (di->disk & 0x80)
- return 0x00FFFFFE; /* 1023/63/254 */
- else
- /*
- * adjust ?
- * this is somewhat "useful" with partitioned floppy,
- * maybe stick to 2.88mb ?
- */
- return 0x004F1201; /* 79/18/1 */
-#if 0
- return 0x004F2401; /* 79/36/1 */
-#endif
+ return h | (s << 8) | ((c & 0x300) << 6) | ((c & 0xFF) << 16);
}
uint32_t get_file_lba(const char *filename)