+sub rewind_raw () {
+ runsystem("mt -f $tape rewind");
+}
+
+sub readtapeid_raw () {
+ open T, ">>TAPEID" or die $!; close T;
+ unlink 'TAPEID' or die $!;
+ rewind_raw();
+ system "mt -f $tape setblk $blocksizebytes"; $? and die $?;
+ system "dd if=$tape bs=${blocksize}b count=10 ".
+ "| tar -b$blocksize -vvxf - TAPEID";
+}
+
+sub runsystem ($) {
+ pboth(" $_[0]\n");
+ system $_[0];
+ $? and die $?;
+}
+
+sub pboth ($) {
+ my ($str) = @_;
+ print LOG $str or die $!;
+ print $str or die $!;
+}
+
+sub nexttapefile ($) {
+ my ($what) = @_;
+ $currenttapefilenumber++;
+ $currenttapefilename= $what;
+ pboth(sprintf "writing tape file #%d (mt fsf %d): %s\n",
+ $currenttapefilenumber, $currenttapefilenumber-1, $what);
+}
+
+sub writetapeid ($$) {
+ open T, ">TAPEID" or die $!;
+ print T "$_[0]\n$_[1]\n" or die $!;
+ close T or die $!;
+
+ $currenttapefilenumber= 0;
+ nexttapefile('TAPEID');
+
+ system "tar -b$blocksize -vvcf TAPEID.tar TAPEID"; $? and die $?;
+ system "dd if=TAPEID.tar of=$ntape bs=${blocksize}b count=10";
+ $? and die $?;
+}
+