Partition dump MBR
#!/usr/bin/env perl6 | |
# Reference: | |
# https://wiki.osdev.org/Partition_Table | |
my %ids = 0x00 => "Empty", 0x0b => "W95 FAT32", 0x0c => "W95 FAT32 (LBA)", | |
0x82 => "Linux swap", 0x83 => "Linux", 0x93 => "Amoeba"; | |
sub MAIN($filename) { | |
say "Disk: $filename"; | |
say "NB: addesses given in (decimal) blocks of 512 bytes each"; | |
say "Part Boot Start End Size Id Type"; | |
my $fh = IO::Handle.new(:path($filename.IO.path)).open; | |
$fh.seek(0x01BE); | |
my $entry; | |
sub eat() { return $entry.shift; } | |
for 1..4 { | |
$entry = $fh.read(16); | |
my $boo = eat; | |
$boo = $boo == 0x80 ?? "*" !! " "; | |
for 1..3 { eat; } | |
my $sid = eat; | |
for 1..3 { eat; } | |
my $start = $entry.read-uint32(0, LittleEndian); | |
last if $start == 0; | |
my $size = $entry.read-uint32(4, LittleEndian); | |
my $end = $start + $size -1 ; | |
my $name = %ids{$sid} || "Unknown"; | |
printf "%d %8.8s %8d %8d %8d 0x%.2X %s\n", $_, $boo, $start,$end, $size, $sid, $name; | |
} | |
$fh.close; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment