#!/usr/bin//perl

$TAPE="/dev/nst0";
$CMD0=" dd of=hoge";

open(HOGE, ">/tmp/aho");
select(HOGE);
$| = 0;

select(STDOUT);

@blocks=();

$run = 1;
system("mt -f $TAPE rewind");
system("mt -f $TAPE setblk 0");
while( $run ) {


        system("dd if=$TAPE bs=512 count=1 ");

	$last = `dmesg | tail -1`;
	$last =~/^(.*) st0: Failed to read ([0-9]+) byte block with 512 byte transfer./;

	$key = $1;
	$block = $2;
	if (! defined $bb{$key}	) {
	   print STDERR "block ",$count++," $1 $2\n";
           $bb{$key} = $block;
	   push(@blocks, $block);
	   system("mt -f $TAPE bsr 1");
           system("dd if=$TAPE bs=$block count=1 ");
	   print HOGE $_,"\n";
	} else {
           $run = 0;
	}
}

