misc: Remove 512-byte sector assumptions from various places
diff --git a/limine.bin b/limine.bin
index 510a48fb..86366a3f 100644
Binary files a/limine.bin and b/limine.bin differ
diff --git a/stage2/drivers/disk.c b/stage2/drivers/disk.c
index 693a3363..7d8a32fe 100644
--- a/stage2/drivers/disk.c
+++ b/stage2/drivers/disk.c
@@ -61,7 +61,7 @@ static int cache_block(int drive, uint64_t block, int sector_size) {
return 0;
}
-int read(int drive, void *buffer, uint64_t loc, uint64_t count) {
+int disk_get_sector_size(int drive) {
struct rm_regs r = {0};
struct bios_drive_params drive_params;
@@ -79,7 +79,11 @@ int read(int drive, void *buffer, uint64_t loc, uint64_t count) {
panic("Disk error %x. Drive %x.\n", ah, drive);
}
- int sector_size = drive_params.bytes_per_sect;
+ return drive_params.bytes_per_sect;
+}
+
+int read(int drive, void *buffer, uint64_t loc, uint64_t count) {
+ int sector_size = disk_get_sector_size(drive);
uint64_t progress = 0;
while (progress < count) {
diff --git a/stage2/drivers/disk.h b/stage2/drivers/disk.h
index 843d0fac..3fa02449 100644
--- a/stage2/drivers/disk.h
+++ b/stage2/drivers/disk.h
@@ -16,6 +16,7 @@ struct bios_drive_params {
uint32_t edd;
} __attribute__((packed));
+int disk_get_sector_size(int drive);
int read(int drive, void *buffer, uint64_t loc, uint64_t count);
int read_partition(int drive, struct part *part, void *buffer, uint64_t loc, uint64_t count);
diff --git a/stage2/lib/part.c b/stage2/lib/part.c
index a2cf71a4..56e047f3 100644
--- a/stage2/lib/part.c
+++ b/stage2/lib/part.c
@@ -57,8 +57,10 @@ struct gpt_entry {
static int gpt_get_part(struct part *ret, int drive, int partition) {
struct gpt_table_header header = {0};
+ int sector_size = disk_get_sector_size(drive);
+
// read header, located after the first block
- read(drive, &header, 512, sizeof(header));
+ read(drive, &header, sector_size * 1, sizeof(header));
// check the header
// 'EFI PART'
@@ -71,14 +73,15 @@ static int gpt_get_part(struct part *ret, int drive, int partition) {
struct gpt_entry entry = {0};
read(drive, &entry,
- (header.partition_entry_lba * 512) + (partition * sizeof(entry)),
+ (header.partition_entry_lba * sector_size) + (partition * sizeof(entry)),
sizeof(entry));
if (entry.unique_partition_guid.low == 0 &&
entry.unique_partition_guid.high == 0) return NO_PARTITION;
- ret->first_sect = entry.starting_lba;
- ret->sect_count = (entry.ending_lba - entry.starting_lba) + 1;
+ ret->first_sect = entry.starting_lba;
+ ret->sect_count = (entry.ending_lba - entry.starting_lba) + 1;
+ ret->sector_size = sector_size;
return 0;
}
@@ -109,8 +112,10 @@ static int mbr_get_part(struct part *ret, int drive, int partition) {
if (entry.type == 0)
return NO_PARTITION;
- ret->first_sect = entry.first_sect;
- ret->sect_count = entry.sect_count;
+ ret->first_sect = entry.first_sect;
+ ret->sect_count = entry.sect_count;
+ ret->sector_size = disk_get_sector_size(drive);
+
return 0;
}
diff --git a/stage2/lib/part.h b/stage2/lib/part.h
index ad142af5..5cabced7 100644
--- a/stage2/lib/part.h
+++ b/stage2/lib/part.h
@@ -6,6 +6,7 @@
struct part {
uint64_t first_sect;
uint64_t sect_count;
+ int sector_size;
};
int get_part(struct part *part, int drive, int partition);
