#!/usr/bin/perl -w
use strict;

add_file("tapefile1", 512);
end_file();
add_file("tapefile2", 512);
end_file();
add_file("tapefile3", 512);
end_file();
add_file("tapefile4", 512);
end_file();
add_file("tapefile5", 512);
end_file();
add_file("tapefile6", 10240);
end_file();
add_file("tapefile7.tar", 10240);
end_file();
add_file("tapefile7.tar", 10240);
end_file();
end_tape();

sub end_file {
  print "\x00\x00\x00\x00";
}

sub end_tape {
  print "\xff\xff\xff\xff";
}

sub add_file {
  my($filename, $blocksize) = @_;
  my($block, $bytes_read, $length);

  open(FILE, $filename) || die("Can't open $filename: $!");
  while($bytes_read = read(FILE, $block, $blocksize)) {
    if($bytes_read < $blocksize) {
      $block .= "\x00" x ($blocksize - $bytes_read);
      $bytes_read = $blocksize;
    }
    $length = pack("V", $bytes_read);
    print $length, $block, $length;
  }
  close(FILE);
}

