diff options
author | Helge Deller <deller@gmx.de> | 2022-08-05 16:44:52 +0200 |
---|---|---|
committer | Helge Deller <deller@gmx.de> | 2022-08-05 23:09:53 +0200 |
commit | a53a687d2e61d72a7890560840f444fb6bb8d566 (patch) | |
tree | db4376399b324dd5b5d5e8ee34387bf9931063ce | |
parent | 0f8e7fe47e44751107ad3d343623c0faf0312983 (diff) | |
download | palo-a53a687d2e61d72a7890560840f444fb6bb8d566.tar.gz |
palo: Fix partition detection and support big drives
The partition detection was broken on big drives. Use u64
addresses now, and print partition table like fdisk output.
Signed-off-by: Helge Deller <deller@gmx.de>
-rw-r--r-- | lib/common.h | 4 | ||||
-rw-r--r-- | lib/diskpart.c | 27 |
2 files changed, 18 insertions, 13 deletions
diff --git a/lib/common.h b/lib/common.h index b46c350..62c1fed 100644 --- a/lib/common.h +++ b/lib/common.h @@ -134,9 +134,9 @@ struct firstblock struct diskpartition { /* in honor of the MBR scheme, these are in 512-byte sectors */ - unsigned start; + __u64 start; /* length == 0 means nothing's here */ - unsigned length; + __u64 length; unsigned char id; }; diff --git a/lib/diskpart.c b/lib/diskpart.c index 5fae1b9..999d8ed 100644 --- a/lib/diskpart.c +++ b/lib/diskpart.c @@ -29,7 +29,7 @@ load_partitions(int bootdev, struct diskpartition *mptab, int maxparts) int i; int ex = -1; int extnum = 4; - unsigned offset; + __u64 offset; /* seekread MBR */ if (seekread(bootdev, (char *)&fb, sizeof fb, 0) == -1) @@ -52,14 +52,14 @@ load_partitions(int bootdev, struct diskpartition *mptab, int maxparts) offset = mptab[ex].start; while (extnum < maxparts) { - if (disk_2gb_limit && offset >= (2 * (GB / 512))) { /* weird () to quiet compiler */ - printf("NOTE: Extended partition %d might be beyond reach of IPL\r\n", - extnum + 1); + if (disk_2gb_limit && ((offset * 512) >> 31)) { + // printf("NOTE: Extended partition %d is beyond reach of IPL\r\n", extnum + 1); + break; } fb.dosmagic[0] = 0; // wipe dosmagic flag just to be on the safe side - if (seekread(bootdev, (char *)&fb, sizeof fb, 512ULL * offset) == -1) { - printf("seekread(bootdev,..., 512 * 0x%x) failed!\n\r", offset); + if (seekread(bootdev, (char *)&fb, sizeof fb, 512 * offset) < 0) { + // printf("seekread(bootdev,..., 512 * 0x%x) failed!\n\r", offset); break; } if (fb.dosmagic[0] != 0x55 || fb.dosmagic[1] != 0xaa) @@ -72,7 +72,7 @@ load_partitions(int bootdev, struct diskpartition *mptab, int maxparts) mptab[extnum].length = __le32_to_cpu(ptab[0].nr_sects); mptab[extnum].id = ptab[0].sys_ind; - offset = mptab[extnum].start + __le32_to_cpu(ptab[1].start_sect); + offset += __le32_to_cpu(ptab[1].start_sect); extnum++; if (!is_extended(ptab[1].sys_ind)) @@ -88,15 +88,20 @@ print_ptab_pretty(struct diskpartition *mptab, int maxparts) { int i; const int mbshift = 20 - 9; + const int gbshift = 30 - 9; - printf("Partition Start(MB) End(MB) Id Type\n\r"); + printf("Partition Start End Sectors Size Id Type\n\r"); for (i = 0; i < maxparts; i++) { + unsigned int gb = (mptab[i].length >> gbshift); if (mptab[i].id != 0 && ! is_extended(mptab[i].id)) - printf("%-9x %8d %7d %3x %s\n\r", + printf("%-8x %9lld %9lld %9lld %5d%c %02x %s\n\r", i + 1, - 1 + (mptab[i].start >> mbshift), - (mptab[i].start + mptab[i].length) >> mbshift, + mptab[i].start, + mptab[i].start + mptab[i].length - 1, + mptab[i].length, + gb ? : (unsigned) (mptab[i].length >> mbshift), + gb ? 'G' : 'M', mptab[i].id, mptab[i].id == LINUX_EXT2_PARTITION ? "ext2" : (mptab[i].id == LINUX_SWAP_PARTITION ? "swap" : |