#!/usr/bin/perl

$dev = $ARGV[0];
open(IN,"<$dev") || die "failed to open $dev: $!\n";
sysread(IN,$buf,512) || die "failed to read first sector of $dev: $!\n";

print("Partition Table for $dev\n");
print("\n");
print("         ---Starting---      ----Ending----   Start Number of\n");
print(" # Flags Head Sect Cyl   ID  Head Sect Cyl   Sector  Sectors\n");
print("-- ----- ---- ---- ---- ---- ---- ---- ---- ------- ---------\n");

for ($i = 0; $i < 4; $i++) {
    printf("%2d  0x%02X %4d %4d %4d 0x%02X %4d %4d %4d %7u %7u\n",
	   part_info($buf, $i));
}

sub part_info {
    ($block, $num) = @_;
    (($num+1), unpack(sprintf("x%dCCCCCCCCLL", 446 + 16 * $num), $block));
}
