#!/usr/bin/perl # # lspartab # # Read, parse and list an MSDOS labeled disc partition table # # Copyright 2007 Simtec Electronics # # Permission is hereby granted, free of charge, to any person # obtaining a copy of this software and associated documentation # files (the "Software"), to deal in the Software without # restriction, including without limitation the rights to use, copy, # modify, merge, publish, distribute, sublicense, and/or sell copies # of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. $F = $ARGV[0] or die "Usage: lspartab "; open PARTTAB, "<", $F; binmode PARTTAB; my @partstarts = (446,462,478,494); $extended = 4; sub scanparts { my $secoffset = shift; my $pnum = shift; my $isext = shift; $buffer = " "; foreach $partstart (@partstarts) { seek(PARTTAB, (512 * $secoffset) + $partstart, 0); sysread PARTTAB, $buffer, 16; $pnum++; ($type, $b1, $b2, $b3, $sys, $e1, $e2, $e3, $start, $count) = unpack("CCCCCCCCLL", $buffer); if ($sys == 5 || $sys == 15 || $sys == 0x85) { if ($secoffset == 0) { scanparts($isext+$start, $extended, $secoffset+$start); } else { scanparts($isext+$start, $extended, $isext); } } $extended++ if $isext; if( $count == 0 ) { $pnum++; next; } print $pnum," ", $secoffset+$start, " ", $count, " ", $sys, "\n"; } return $pnum; } scanparts(0,0,0); close PARTTAB;