From ba4703b5206b863d81998fc729555a33636dd7a3 Mon Sep 17 00:00:00 2001 From: Will Sowerbutts Date: Thu, 8 Jan 2015 22:03:49 +0000 Subject: [PATCH] mbr: Do not assume little-endian --- Kernel/cpu-z80/cpu.h | 2 ++ Kernel/dev/mbr.c | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Kernel/cpu-z80/cpu.h b/Kernel/cpu-z80/cpu.h index 5c2e9565..437d4a23 100644 --- a/Kernel/cpu-z80/cpu.h +++ b/Kernel/cpu-z80/cpu.h @@ -57,6 +57,8 @@ typedef union { /* this structure is endian dependent */ #define cpu_to_le16(x) (x) #define le16_to_cpu(x) (x) +#define cpu_to_le32(x) (x) +#define le32_to_cpu(x) (x) #define DISCARDABLE static void DISCARDSEG(void) __naked { __asm .area _DISCARD __endasm; } #endif diff --git a/Kernel/dev/mbr.c b/Kernel/dev/mbr.c index 89e03265..1bd672d7 100644 --- a/Kernel/dev/mbr.c +++ b/Kernel/dev/mbr.c @@ -33,7 +33,7 @@ void mbr_parse(blkdev_t *blk, char letter) br = (boot_record_t *)tmpbuf(); do{ - if(!blk->transfer(blk->drive_number, lba, br, true) || br->signature != MBR_SIGNATURE) + if(!blk->transfer(blk->drive_number, lba, br, true) || le16_to_cpu(br->signature) != MBR_SIGNATURE) break; /* avoid an infinite loop where extended boot records form a loop */ @@ -60,18 +60,18 @@ void mbr_parse(blkdev_t *blk, char letter) /* Extended boot record, or chained table; in principle a drive should contain at most one extended partition so this code is OK even for parsing the MBR. Chained EBR addresses are relative to the start of the extended partiton. */ - lba = ep_offset + br->partition[i].lba_first; + lba = ep_offset + le32_to_cpu(br->partition[i].lba_first); if(next >= 4) break; /* we include all primary partitions but we deliberately knobble the size in order to prevent catastrophic accidents */ - br->partition[i].lba_count = 2; + br->partition[i].lba_count = cpu_to_le32(2); /* fall through */ default: /* Regular partition: In EBRs these are relative to the EBR (not the disk, nor the extended partition) */ - blk->lba_first[next] = br_offset + br->partition[i].lba_first; - blk->lba_count[next] = br->partition[i].lba_count; + blk->lba_first[next] = br_offset + le32_to_cpu(br->partition[i].lba_first); + blk->lba_count[next] = le32_to_cpu(br->partition[i].lba_count); next++; kprintf("hd%c%d ", letter, next); } -- 2.34.1