part: Fix bug where an improper buffer size was allocated when indexing all partitions
diff --git a/limine-pxe.bin b/limine-pxe.bin
index f231d397..202ab6e6 100644
Binary files a/limine-pxe.bin and b/limine-pxe.bin differ
diff --git a/limine.bin b/limine.bin
index 663827f8..616c69d6 100644
Binary files a/limine.bin and b/limine.bin differ
diff --git a/stage2.map b/stage2.map
index c530b7d1..4cc10920 100644
Binary files a/stage2.map and b/stage2.map differ
diff --git a/stage2/lib/part.c b/stage2/lib/part.c
index 1796ceb5..4f3541ad 100644
--- a/stage2/lib/part.c
+++ b/stage2/lib/part.c
@@ -232,6 +232,8 @@ static struct part *part_index = NULL;
static size_t part_index_i = 0;
void part_create_index(void) {
+ size_t part_count = 0;
+
for (uint8_t drive = 0x80; drive < 0x8f; drive++) {
struct rm_regs r = {0};
struct bios_drive_params drive_params;
@@ -252,29 +254,48 @@ void part_create_index(void) {
print(" ... %X total %u-byte sectors\n",
drive_params.lba_count, drive_params.bytes_per_sect);
- size_t part_count = 0;
-
-load_up:
for (int part = 0; ; part++) {
struct part p;
int ret = part_get(&p, drive, part);
- if (ret == END_OF_TABLE)
+ if (ret == END_OF_TABLE || ret == INVALID_TABLE)
break;
if (ret == NO_PARTITION)
continue;
- if (part_index)
- part_index[part_index_i++] = p;
- else
- part_count++;
+ part_count++;
}
+ }
+
+ part_index = ext_mem_alloc(sizeof(struct part) * part_count);
+
+ for (uint8_t drive = 0x80; drive < 0x8f; drive++) {
+ struct rm_regs r = {0};
+ struct bios_drive_params drive_params;
+
+ r.eax = 0x4800;
+ r.edx = drive;
+ r.ds = rm_seg(&drive_params);
+ r.esi = rm_off(&drive_params);
+
+ drive_params.buf_size = sizeof(struct bios_drive_params);
+
+ rm_int(0x13, &r, &r);
+
+ if (r.eflags & EFLAGS_CF)
+ continue;
+
+ for (int part = 0; ; part++) {
+ struct part p;
+ int ret = part_get(&p, drive, part);
- if (part_index)
- return;
+ if (ret == END_OF_TABLE || ret == INVALID_TABLE)
+ break;
+ if (ret == NO_PARTITION)
+ continue;
- part_index = ext_mem_alloc(sizeof(struct part) * part_count);
- goto load_up;
+ part_index[part_index_i++] = p;
+ }
}
}
