3 # Catch for sh/csh on systems without #! ability.
4 eval '(exit $?0)' && eval 'exec @PERL@ -S $0 ${1+"$@"}'
5 & eval 'exec @PERL@ -S $0 $argv:q'
9 # A tape changer script for the Robotic Tape Handling system OEM'd
10 # by Andataco (RTH-406) for use with Amanda, the Advanced Maryland
11 # Network Disk Archiver.
13 # Author: Erik Frederick 1/10/97
14 # edf@tyrell.mc.duke.edu
16 # This changer script controls the HP c1553 tape drive via a
17 # Peripheral Vision Inc. SCSI control subsystem that interprets
18 # commands sent on the SCSI bus. It may work with other tape drives
19 # containing the PVI board.
21 # Permission to freely use and distribute is granted.
28 $pname = "rth-changer";
31 $prefix=$prefix; # avoid warnings about possible typo
32 $exec_prefix="@exec_prefix@";
33 $exec_prefix=$exec_prefix; # ditto
35 $libexecdir="@libexecdir@";
36 if ("@USE_VERSION_SUFFIXES@" eq "yes") {
42 if (-x "$sbindir/ammt$SUF") {
43 $MT="$sbindir/ammt$SUF";
47 $MTF="@MT_FILE_FLAG@";
49 print "<none> $pname: mt program not found\n";
53 $tapeDevice=`$sbindir/amgetconf$SUF tapedev`;
57 if (!sysopen(RTH, $tapeDevice, 2)) {
58 print "$currentTape $pname: error in opening `$tapeDevice' for getting current tape: $!\n";
61 if (syswrite(RTH, "Rd_ElS", 6) != 6) {
62 print "$currentTape $pname: error in writing `Rd_ElS' to `$tapeDevice': $!\n";
66 print "$currentTape $pname: error in closing `$tapeDevice' for getting current tape: $!\n";
70 if (!sysopen(RTH, $tapeDevice, 2)) {
71 print "$currentTape $pname: error in opening `$tapeDevice' for getting current tape: $!\n";
74 if (sysread(RTH, $status, 136) != 136) {
75 print "$currentTape $pname: error in reading rth status.\n";
79 print "$currentTape $pname: error in closing `$tapeDevice' for getting current tape: $!\n";
83 @statusBits=unpack("c*",$status);
85 if( ($statusBits[18] == 0x1) || ($statusBits[18]== 0x9)) {
86 return ($statusBits[27]-1);
95 if (!sysopen(RTH, $tapeDevice, 2)) {
96 print "$currentTape $pname: error in opening `$tapeDevice' for getting tape status: $!\n";
99 if (syswrite(RTH, "Rd_ElS", 6) != 6) {
100 print "$currentTape $pname: error in writing `Rd_ElS' to `$tapeDevice': $!\n";
104 print "$currentTape $pname: error in closing `$tapeDevice' for getting tpae status: $!\n";
108 if (!sysopen(RTH, $tapeDevice, 2)) {
109 print "$currentTape $pname: error in opening `$tapeDevice' for getting tape status: $!\n";
112 if (sysread(RTH, $status, 136) != 136) {
113 print "$currentTape $pname: error in reading rth status for tape $currentTape.\n";
117 print "$currentTape $pname: error in closing `$tapeDevice' for getting tape status: $!\n";
121 @statusBits=unpack("c*",$status);
124 for($i=42;$i<187;$i+=16) {
125 if($statusBits[$i] == 0x9) {
126 $slots[$curTape] = 1;
129 $slots[$curTape] = 0;
140 $command = sprintf "GeT%d", $tape;
141 if (!sysopen(RTH, $tapeDevice, 2)) {
142 print "$currentTape $pname: error in opening `$tapeDevice' for loading tape: $!\n";
145 if (syswrite(RTH, $command, 4) != 4) {
146 print "$currentTape $pname: error in loading tape by writing `$command' to `$tapeDevice': $!\n";
150 print "$currentTape $pname: error in closing `$tapeDevice' when trying to load tape: $!\n";
158 $command = sprintf "PuT%d", $tape;
159 if (!sysopen(RTH, $tapeDevice, 2)) {
160 print "$currentTape $pname: error in opening `$tapeDevice' for unloading tape: $!\n";
163 if (syswrite(RTH, $command, 4) != 4) {
164 print "$currentTape $pname: error in unloading tape by writing `$command' to `$tapeDevice': $!\n";
168 print "$currentTape $pname: error in closing `$tapeDevice' when trying to unload tape: $!\n";
176 @slots=getTapeStatus();
178 if($currentTape == $tape) {
182 if($slots[$tape-1] == 0) {
183 print "<none> $pname: no tape in slot requested\n";
187 print $tape," $pname: requested a tape > 6\n";
191 print $tape," $pname: requested a tape < 1\n";
200 if($tape==$currentTape) {
206 if($currentTape==0) {
212 rthUnload($currentTape);
219 $result = &GetOptions("slot=s", "info", "reset", "eject");
221 system($MT, 'rewind');
226 $currentTape=getCurrentTape();
229 if($opt_slot =~ /first/) {
231 print $currentTape, " ", $tapeDevice, "\n";
233 if($opt_slot =~ /last/) {
235 print $currentTape, " ", $tapeDevice, "\n";
237 if($opt_slot =~ /current/) {
238 changeTape($currentTape);
239 print $currentTape, " ", $tapeDevice, "\n";
241 if($opt_slot =~ /next/) {
242 $tape=$currentTape+1;
247 print $currentTape, " ", $tapeDevice,"\n";
249 if($opt_slot =~ /prev/) {
250 $tape=$currentTape-1;
255 print $currentTape, " ", $tapeDevice,"\n";
257 if($opt_slot =~ /\d/) {
258 changeTape($opt_slot);
259 print $currentTape, " ", $tapeDevice,"\n";
261 if($opt_slot =~ /advance/) {
262 $tape=$currentTape+1;
267 rthUnload($currentTape);
269 print $currentTape, " ", "/dev/null","\n";
277 print $currentTape, " 6 1\n";
284 print $currentTape, " ",$tapeDevice,"\n";
290 rthUnload($currentTape);
291 print "0 ",$tapeDevice,"\n";
295 print "0 $pname: drive was not loaded\n";
300 print "$pname: No command was received. Exiting.\n";