Skip to contentSkip to conversation

Fix miscalculated total sectors

PATCH New unsik Kim 2 participants 2 messages Feb 13, 2009 – Feb 14, 2009 Block layer

lore
Share & tools
lore

unsik Kim

author
#0 lore raw

PATCH 3/3 Fix miscalculated total sectors

When using CONFIG_MG_DISK_RES, total sectors should be recalculated.

---
 drivers/block/mg_disk.c |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)
drivers/block/mg_disk.c +14 -4
index e1b1a68..193a441 100644
@@ -174,7 +174,7 @@ static int mg_get_disk_id (void)
 {
 	u32 iobuf[(MG_SECTOR_SIZE / sizeof(u32))];
 	hd_driveid_t *iop = (hd_driveid_t *)iobuf;
-	u32 i, err;
+	u32 i, err, res;
 	u16 *buff = (u16 *)iobuf;
 
 	writeb(MG_CMD_ID, MG_BASE + MG_REG_COMMAND);
@@ -214,11 +214,21 @@ static int mg_get_disk_id (void)
 #endif /* __LITTLE_ENDIAN */
 
 #ifdef __BIG_ENDIAN
-	mg_disk_dev.lba = (iop->lba_capacity << 16) | (iop->lba_capacity >> 16);
-#else	/* ! __BIG_ENDIAN */
-	mg_disk_dev.lba = iop->lba_capacity;
+	iop->lba_capacity = (iop->lba_capacity << 16) |
+		(iop->lba_capacity >> 16);
 #endif /* __BIG_ENDIAN */
 
+	if (MG_RES_SEC) {
+		MG_DBG("MG_RES_SEC=%d\n", MG_RES_SEC);
+		iop->cyls = (iop->lba_capacity - MG_RES_SEC) /
+			iop->sectors / iop->heads;
+		res = iop->lba_capacity -
+			iop->cyls * iop->heads * iop->sectors;
+		iop->lba_capacity -= res;
+		printf("mg_disk: %d sectors reserved\n", res);
+	}
+
+	mg_disk_dev.lba = iop->lba_capacity;
 	return MG_ERR_NONE;
 }
 
Signature · 1 line
1.5.6.6