[syslinux:master] partiter: Add raw iterators

syslinux-bot for Michal Soltys soltys at ziu.info
Mon Mar 26 15:03:06 PDT 2012


Commit-ID:  d9c1e7d5352cc9365c8be425ca87e04a79f46109
Gitweb:     http://www.syslinux.org/commit/d9c1e7d5352cc9365c8be425ca87e04a79f46109
Author:     Michal Soltys <soltys at ziu.info>
AuthorDate: Sun, 15 Aug 2010 14:24:06 +0200
Committer:  Michal Soltys <soltys at ziu.info>
CommitDate: Mon, 16 Aug 2010 00:41:44 +0200

partiter: Add raw iterators

As iterators cover the whole disk now, it's possible to be able to still
boot "something" from the 1st sector, even if it has no valid mbr or gpt
layout. This patch adds "raw" iterator, updating necessary code.

Signed-off-by: Michal Soltys <soltys at ziu.info>

---
 com32/chain/chain.c    |    2 +-
 com32/chain/partiter.c |   38 +++++++++++++++++++++++++++-----------
 com32/chain/partiter.h |    1 +
 3 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/com32/chain/chain.c b/com32/chain/chain.c
index 369e3a3..5c2dd9f 100644
--- a/com32/chain/chain.c
+++ b/com32/chain/chain.c
@@ -1031,7 +1031,7 @@ int main(int argc, char *argv[])
 	    disk_dos_part_dump(hand_area);
 	    disk_gpt_part_dump((struct disk_gpt_part_entry *)(plen + 1));
 #endif
-	} else {
+	} else if (cur_part->type == typedos) {
 	    /* MBR handover protocol */
 	    /* Allocate the hand-over record */
 	    hand_area = malloc(sizeof(struct disk_dos_part_entry));
diff --git a/com32/chain/partiter.c b/com32/chain/partiter.c
index f217c8e..9de72f7 100644
--- a/com32/chain/partiter.c
+++ b/com32/chain/partiter.c
@@ -55,11 +55,13 @@ static void error(const char *msg)
 
 /* forwards */
 
+static int iter_ctor(struct part_iter *, va_list *);
 static int iter_dos_ctor(struct part_iter *, va_list *);
 static int iter_gpt_ctor(struct part_iter *, va_list *);
 static void iter_dtor(struct part_iter *);
 static struct part_iter *pi_dos_next(struct part_iter *);
 static struct part_iter *pi_gpt_next(struct part_iter *);
+static struct part_iter *pi_raw_next(struct part_iter *);
 
 static struct itertype types[] = {
    [0] = {
@@ -70,10 +72,15 @@ static struct itertype types[] = {
 	.ctor = &iter_gpt_ctor,
 	.dtor = &iter_dtor,
 	.next = &pi_gpt_next,
+}, [2] = {
+	.ctor = &iter_ctor,
+	.dtor = &iter_dtor,
+	.next = &pi_raw_next,
 }};
 
 const struct itertype * const typedos = types;
 const struct itertype * const typegpt = types+1;
+const struct itertype * const typeraw = types+2;
 
 #ifdef DEBUG
 static int inv_type(const void *type)
@@ -434,12 +441,12 @@ static struct part_iter *pi_dos_next(struct part_iter *iter)
     /* look for primary partitions */
     if (iter->sub.dos.index0 < 4 &&
 	    pi_dos_next_mbr(iter, &start_lba, &dos_part))
-        return pi_del(&iter);
+	goto out;
 
     /* look for logical partitions */
     if (iter->sub.dos.index0 >= 4 &&
 	    pi_dos_next_ebr(iter, &start_lba, &dos_part))
-	return pi_del(&iter);
+	goto out;
 
     /* dos_part and start_lba are guaranteed to be valid here */
 
@@ -452,6 +459,8 @@ static struct part_iter *pi_dos_next(struct part_iter *iter)
 #endif
 
     return iter;
+out:
+    return pi_del(&iter);
 }
 
 static void gpt_conv_label(struct part_iter *iter)
@@ -505,6 +514,11 @@ out:
     return pi_del(&iter);
 }
 
+static struct part_iter *pi_raw_next(struct part_iter *iter)
+{
+    return pi_del(&iter);
+}
+
 static int check_crc(uint32_t crc_match, const uint8_t *buf, unsigned int siz)
 {
     uint32_t crc;
@@ -655,21 +669,21 @@ struct part_iter *pi_begin(const struct disk_info *di)
 
     /* Read MBR */
     if (!(mbr = disk_read_sectors(di, 0, 1))) {
-	error("Couldn't read MBR sector.");
+	error("Couldn't read first disk sector.\n");
 	goto out;
     }
 
     /* Check for MBR magic*/
     if (mbr->sig != disk_mbr_sig_magic) {
 	error("No MBR magic.\n");
-	goto out;
+	goto raw;
     }
 
     /* Check for GPT protective MBR */
     if (mbr->table[0].ostype == 0xEE) {
 	if (!(gpth = disk_read_sectors(di, 1, 1))) {
-	    error("Couldn't read GPT header.");
-	    goto out;
+	    error("Couldn't read potential GPT header.\n");
+	    goto raw;
 	}
     }
 
@@ -684,7 +698,7 @@ struct part_iter *pi_begin(const struct disk_info *di)
 #endif
 	/* Verify checksum, fallback to backup, then bail if invalid */
 	if (gpt_check_hdr_crc(di, &gpth))
-	    goto out;
+	    goto raw;
 
 	gpt_loff = gpth->lba_table;
 	gpt_lsiz = (uint64_t)gpth->part_size*gpth->part_count;
@@ -696,16 +710,16 @@ struct part_iter *pi_begin(const struct disk_info *di)
 	if (!gpt_loff || !gpt_lsiz || gpt_lsiz > MAXGPTPTSIZE ||
 		gpth->part_size < sizeof(struct disk_gpt_part_entry)) {
 	    error("Invalid GPT header's lba_table/part_count/part_size values.\n");
-	    goto out;
+	    goto raw;
 	}
 	if (!(gptl = disk_read_sectors(di, gpt_loff, (uint8_t)((gpt_lsiz+SECTOR-1)/SECTOR)))) {
 	    error("Couldn't read GPT partition list.\n");
-	    goto out;
+	    goto raw;
 	}
 	/* Check array checksum. */
 	if (check_crc(gpth->table_chksum, (const uint8_t *)gptl, (unsigned int)gpt_lsiz)) {
 	    error("GPT partition list checksum invalid.\n");
-	    goto out;
+	    goto raw;
 	}
 	/* allocate iterator and exit */
 	if (!(iter = pi_new(typegpt, di, gpth, gptl)))
@@ -716,7 +730,9 @@ struct part_iter *pi_begin(const struct disk_info *di)
 	    goto out;
     }
 
-    /* we do not do first iteration ! */
+raw:
+    error("WARNING: treating disk as raw.\n");
+    iter = pi_new(typeraw, di);
 
 out:
     free(mbr);
diff --git a/com32/chain/partiter.h b/com32/chain/partiter.h
index 2b95cf6..f32543e 100644
--- a/com32/chain/partiter.h
+++ b/com32/chain/partiter.h
@@ -83,6 +83,7 @@ struct part_iter {
 
 extern const struct itertype * const typedos;
 extern const struct itertype * const typegpt;
+extern const struct itertype * const typeraw;
 
 struct part_iter *pi_begin(const struct disk_info *);
 struct part_iter *pi_new(const struct itertype *, ...);


More information about the Syslinux-commits mailing list