[syslinux] [PATCH 22/28] com32/chain: partiter: rename start_lba

Michal Soltys soltys at ziu.info
Tue Jan 29 06:06:09 PST 2013


disk.c also uses start_lba and it can mean few different things
depending on context (disk relative, BEBR relative, current EBR
relative).

partiter's main offset is always a disk relative value. To make it more
distinct and avoid suggestion the value is simply a copy of the one from
disk_dos_part_entry, we rename it to more fitting abs_lba.

Signed-off-by: Michal Soltys <soltys at ziu.info>
---
 com32/chain/chain.c    |   20 ++++++++++----------
 com32/chain/mangle.c   |   14 +++++++-------
 com32/chain/partiter.c |   10 +++++-----
 com32/chain/partiter.h |    2 +-
 4 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/com32/chain/chain.c b/com32/chain/chain.c
index 0c83a5a..9379602 100644
--- a/com32/chain/chain.c
+++ b/com32/chain/chain.c
@@ -347,7 +347,7 @@ int find_dp(struct part_iter **_iter)
 	/* 'fs' => we should lookup the syslinux partition number and use it */
 	if (!strcmp(opt.drivename, "fs")) {
 	    while (!pi_next(iter)) {
-		if (iter->start_lba == fs_lba)
+		if (iter->abs_lba == fs_lba)
 		    break;
 	    }
 	    /* broken part structure or other problems */
@@ -426,16 +426,16 @@ static int setup_handover(const struct part_iter *iter,
 	    critm();
 	    goto bail;
 	}
-	lba2chs(&ha->start, &iter->di, iter->start_lba, L2C_CADD);
-	lba2chs(&ha->end, &iter->di, iter->start_lba + iter->length - 1, L2C_CADD);
+	lba2chs(&ha->start, &iter->di, iter->abs_lba, L2C_CADD);
+	lba2chs(&ha->end, &iter->di, iter->abs_lba + iter->length - 1, L2C_CADD);
 	ha->active_flag = 0x80;
 	ha->ostype = 0xED;
 	/* All bits set by default */
 	ha->start_lba = ~0u;
 	ha->length = ~0u;
 	/* If these fit the precision, pass them on */
-	if (iter->start_lba < ha->start_lba)
-	    ha->start_lba = iter->start_lba;
+	if (iter->abs_lba < ha->start_lba)
+	    ha->start_lba = iter->abs_lba;
 	if (iter->length < ha->length)
 	    ha->length = iter->length;
 	/* Next comes the GPT partition record length */
@@ -458,9 +458,9 @@ static int setup_handover(const struct part_iter *iter,
 	}
 	memcpy(ha, iter->record, synth_size);
 	/* make sure these match bios imaginations and are ebr agnostic */
-	lba2chs(&ha->start, &iter->di, iter->start_lba, L2C_CADD);
-	lba2chs(&ha->end, &iter->di, iter->start_lba + iter->length - 1, L2C_CADD);
-	ha->start_lba = iter->start_lba;
+	lba2chs(&ha->start, &iter->di, iter->abs_lba, L2C_CADD);
+	lba2chs(&ha->end, &iter->di, iter->abs_lba + iter->length - 1, L2C_CADD);
+	ha->start_lba = iter->abs_lba;
 	ha->length = iter->length;
 
 #ifdef DEBUG
@@ -543,7 +543,7 @@ int main(int argc, char *argv[])
 	    error("The sector cannot be loaded at such high address.");
 	    goto bail;
 	}
-	if (!(sdat.data = disk_read_sectors(&iter->di, iter->start_lba, 1))) {
+	if (!(sdat.data = disk_read_sectors(&iter->di, iter->abs_lba, 1))) {
 	    error("Couldn't read the sector.");
 	    goto bail;
 	}
@@ -625,7 +625,7 @@ int main(int argc, char *argv[])
 	iter->di.lbacnt, iter->di.cyl * iter->di.head * iter->di.spt,
 	iter->di.cyl, iter->di.head, iter->di.spt);
     dprintf("iter idx: %d\n", iter->index);
-    dprintf("iter lba: %"PRIu64"\n", iter->start_lba);
+    dprintf("iter lba: %"PRIu64"\n", iter->abs_lba);
     if (opt.hand)
 	dprintf("hand lba: %u\n",
 		((struct disk_dos_part_entry *)hdat.data)->start_lba);
diff --git a/com32/chain/mangle.c b/com32/chain/mangle.c
index a506e79..a49fcfb 100644
--- a/com32/chain/mangle.c
+++ b/com32/chain/mangle.c
@@ -280,18 +280,18 @@ static int mangle_bpb(const struct part_iter *iter, struct data_area *data, cons
 
     /* BPB: hidden sectors 64bit - exFAT only for now */
     if (type == bpbEXF)
-	    *(uint64_t *) ((char *)data->data + 0x40) = iter->start_lba;
+	    *(uint64_t *) ((char *)data->data + 0x40) = iter->abs_lba;
     /* BPB: hidden sectors 32bit*/
     else if (bpbV34 <= type && type <= bpbV70) {
-	if (iter->start_lba < ~0u)
-	    *(uint32_t *) ((char *)data->data + 0x1c) = iter->start_lba;
+	if (iter->abs_lba < ~0u)
+	    *(uint32_t *) ((char *)data->data + 0x1c) = iter->abs_lba;
 	else
 	    /* won't really help much, but ... */
 	    *(uint32_t *) ((char *)data->data + 0x1c) = ~0u;
     /* BPB: hidden sectors 16bit*/
     } else if (bpbV30 <= type && type <= bpbV32) {
-	if (iter->start_lba < 0xFFFF)
-	    *(uint16_t *) ((char *)data->data + 0x1c) = iter->start_lba;
+	if (iter->abs_lba < 0xFFFF)
+	    *(uint16_t *) ((char *)data->data + 0x1c) = iter->abs_lba;
 	else
 	    /* won't really help much, but ... */
 	    *(uint16_t *) ((char *)data->data + 0x1c) = (uint16_t)~0u;
@@ -398,7 +398,7 @@ int mangles_save(const struct part_iter *iter, const struct data_area *data, voi
 	return 0;
 
     if (memcmp(org, data->data, data->size)) {
-	if (disk_write_sectors(&iter->di, iter->start_lba, data->data, 1)) {
+	if (disk_write_sectors(&iter->di, iter->abs_lba, data->data, 1)) {
 	    error("Cannot write the updated sector.");
 	    goto bail;
 	}
@@ -586,7 +586,7 @@ static int updchs(struct part_iter *iter, int ext)
     dp = (struct disk_dos_part_entry *)iter->record;
     if (!ext) {
 	/* primary or logical */
-	lba = (uint32_t)iter->start_lba;
+	lba = (uint32_t)iter->abs_lba;
     } else {
 	/* extended */
 	dp += 1;
diff --git a/com32/chain/partiter.c b/com32/chain/partiter.c
index 0c11457..a4dc13d 100644
--- a/com32/chain/partiter.c
+++ b/com32/chain/partiter.c
@@ -449,7 +449,7 @@ static int pi_next_(struct part_iter *iter)
 
 static int pi_dos_next(struct part_iter *iter)
 {
-    uint32_t start_lba = 0;
+    uint32_t abs_lba = 0;
     struct disk_dos_part_entry *dos_part = NULL;
 
     if (iter->status)
@@ -457,12 +457,12 @@ static int pi_dos_next(struct part_iter *iter)
 
     /* look for primary partitions */
     if (iter->index0 < 4 &&
-	    dos_next_mbr(iter, &start_lba, &dos_part) < 0)
+	    dos_next_mbr(iter, &abs_lba, &dos_part) < 0)
 	return iter->status;
 
     /* look for logical partitions */
     if (iter->index0 >= 4 &&
-	    dos_next_ebr(iter, &start_lba, &dos_part) < 0)
+	    dos_next_ebr(iter, &abs_lba, &dos_part) < 0)
 	return iter->status;
 
     /*
@@ -475,7 +475,7 @@ static int pi_dos_next(struct part_iter *iter)
 	iter->index = -1;
     else
 	iter->index = iter->index0 + 1 - iter->dos.logskipcnt;
-    iter->start_lba = start_lba;
+    iter->abs_lba = abs_lba;
     iter->length = dos_part->length;
     iter->record = (char *)dos_part;
 
@@ -512,7 +512,7 @@ static int pi_gpt_next(struct part_iter *iter)
     }
     /* gpt_part is guaranteed to be valid here */
     iter->index = iter->index0 + 1;
-    iter->start_lba = gpt_part->lba_first;
+    iter->abs_lba = gpt_part->lba_first;
     iter->length = gpt_part->lba_last - gpt_part->lba_first + 1;
     iter->record = (char *)gpt_part;
     memcpy(&iter->gpt.part_guid, &gpt_part->uid, sizeof(struct guid));
diff --git a/com32/chain/partiter.h b/com32/chain/partiter.h
index 31df785..3d2a151 100644
--- a/com32/chain/partiter.h
+++ b/com32/chain/partiter.h
@@ -64,7 +64,7 @@ struct part_iter {
     const struct itertype *type;
     char *data;
     char *record;
-    uint64_t start_lba;
+    uint64_t abs_lba;
     uint64_t length;
     int index0;	    /* including holes, from -1 (disk, then parts from 0) */
     int index;	    /* excluding holes, from  0 (disk, then parts from 1), -1 means hole, if PIF_STEPALL is set */
-- 
1.7.10.4



More information about the Syslinux mailing list