@rem = '--*-Perl-*-- @set "ErrorLevel=" @if "%OS%" == "Windows_NT" @goto WinNT @perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9 @set ErrorLevel=%ErrorLevel% @goto endofperl :WinNT @perl -x -S %0 %* @set ErrorLevel=%ErrorLevel% @if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" @goto endofperl @if %ErrorLevel% == 9009 @echo You do not have Perl in your PATH. @goto endofperl @rem '; #!/usr/bin/perl #line 16 my $target; my $skip = 0; my $opt; while (1) { $opt = shift @ARGV; if ($opt eq "-x") { $target = shift @ARGV; } elsif ($opt eq '-s') { $skip = 1; } else { $file = $opt; last; } } die "usage tarimd [-x targetdir] [-s] imdfile\n" if $#ARGV >= 0 || ! -f $file; open $in, "<:raw", $file or die "can't open $file\n"; read $in, $sig, 3; die "not IMD file\n" if $sig ne "IMD"; seek $in, 0, 0; { local $/ = "\cZ"; $comment = <$in>; chomp $comment; } my $image = ""; while (read $in, $hdr, 5) { my ($mode, $cyl, $head, $nsec, $ssec) = unpack("C5", $hdr); $ssec = 128 << $ssec; read $in, $cmap, $nsec if ($head & 0x80); # skip over read $in, $hmap, $nsec if ($head & 0x40); warn "cylinder and head map ignored\n" if ($head & 0xC0); read $in, $smap, $nsec; my (@sorder) = unpack("C$nsec", $smap); my $secbase = 1000; map { $secbase = $_ if ($_ < $secbase); } @sorder; undef @sectors; my @missing = (); for ($s = 0; $s < $nsec; $s++) { my $type = ord(getc($in)); my $data; if ($type & 1) { read $in, $data, $ssec; } else { $data = ($type != 0) ? getc($in) : chr(0); $data x= $ssec; } $sectors[$sorder[$s] - $secbase] = $data; push @missing, $sorder[$s] if ($type != 1 && $type != 2); } if ($cyl == 0 && $head == 0 && ($skip || @missing == $nsec)) { print "Skipping boot track\n"; } else { print "CH($cyl,$head) missing sectors(", join(", ", sort(@missing)), ")\n" if $#missing >= 0; $image .= join("", @sectors); } } if ($target) { mkdir $target if !-d $target; open($out, "|-:raw", "tar -f- -C \"$target\" -xv"); } else { open($out, "|-:raw", "tar -tvf-"); } print $out $image; __END__ :endofperl @set "ErrorLevel=" & @goto _undefined_label_ 2>NUL || @"%COMSPEC%" /d/c @exit %ErrorLevel%