Retensioning tapes through wt(7) under ISC 3.2.2.1
Conor P. Cahill
cpcahil at virtech.uucp
Tue Apr 23 23:04:36 AEST 1991
dag at gorgon.uucp (Daniel A. Glasser) writes:
>I have a 60 meg tape drive (TECMAR QT-60i) connected to a Wangtek PC-60
>controller, and it works just fine with the ISC WT driver. I have been
>retensioning my tapes by booting DOS from a floppy and using the utilities
>that came with the drive. I would like to do it without rebooting my
>machine. I've been trying to write a retension utility that uses the
>wt(7)'s documented RETENS command to ioctl(), but seem to be missing
First off, I don't know why you bother to retension the tapes, I have
been using various QIC tapes for several years and have yet to run into
a problem that would be solved by retensioning (so I dont bother anymore)
Yes, I flirt with danger on a daily basis :-)
Anyway, here is the source for a tape command utility that gives
you the capability to do what you want.
#!/bin/sh
# This is a shell archive (produced by shar 3.49)
# To extract the files from this archive, save it to a file, remove
# everything above the "!/bin/sh" line above, and type "sh file_name".
#
# made 04/23/1991 13:03 UTC by cpcahil at virtech
# Source directory /a/corp/src/cmd/tapecmd
#
# existing files will NOT be overwritten unless -c is specified
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 596 -r--r--r-- Makefile
# 3831 -r--r--r-- tapecmd.c
#
# ============= Makefile ==============
if test -f 'Makefile' -a X"$1" != X"-c"; then
echo 'x - skipping Makefile (File already exists)'
else
echo 'x - extracting Makefile (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'Makefile' &&
#
# (c) Copyright 1991 Conor P. Cahill (uunet!virtech!cpcahil).
# You may copy, distribute, and use this software as long as this
# copyright statement is not removed.
#
#
# This is the Makefile for the tapecmd utility
#
# $Id: Makefile,v 1.2 91/04/23 09:03:03 cpcahil Exp $
#
CC=cc
#DFLAGS=-DDEBUG=40
CFLAGS= -O $(DFLAGS)
LDFLAGS=
LIBS=
INSTDIR=/usr/local/bin
X
SRCS=tapecmd.c
OBJS=$(SRCS:.c=.o)
EXE=tapecmd
X
all: $(EXE)
X
install: $(INSTDIR)/$(EXE)
X
$(INSTDIR)/$(EXE): $(EXE)
X -rm -f $@.old
X -mv -f $@ $@.old
X cp $? $@
X -rm -f $@.old
X
X
$(EXE): $(OBJS)
X $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
X
SHAR_EOF
chmod 0444 Makefile ||
echo 'restore of Makefile failed'
Wc_c="`wc -c < 'Makefile'`"
test 596 -eq "$Wc_c" ||
echo 'Makefile: original size 596, current size' "$Wc_c"
fi
# ============= tapecmd.c ==============
if test -f 'tapecmd.c' -a X"$1" != X"-c"; then
echo 'x - skipping tapecmd.c (File already exists)'
else
echo 'x - extracting tapecmd.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'tapecmd.c' &&
/*
X * (c) Copyright 1990 Conor P. Cahill (uunet!virtech!cpcahil).
X * You may copy, distribute, and use this software as long as this
X * copyright statement is not removed.
X */
#include <sys/types.h>
#include <sys/wtioctl.h>
#include <sys/termio.h>
X
#include <fcntl.h>
#include <stdio.h>
#include <ctype.h>
X
#define SLEEP_TIME 7
#define TAPE_ERASE 0x01
#define TAPE_RETEN 0x02
#define TAPE_REWIND 0x04
#define TAPEFILE_NOREWIND "/dev/rnmt0"
#define TAPEFILE_REWIND "/dev/rmt0"
#define DEFAULT_FILENAME TAPEFILE_REWIND
X
static char rcs_hdr[] = "$Id: tapecmd.c,v 1.4 91/04/23 09:03:05 cpcahil Exp $";
X
int nointeract;
X
main(argc,argv)
X int argc;
X char **argv;
{
X
X char * command;
X int count = 1;
X extern int errno;
X int fd;
X char * filename = DEFAULT_FILENAME;
X int numtapes = 1;
X int tape_cmd;
X int tape_count = 0;
X
X /*
X * if silent (no interaction) mode
X */
X if( (argc > 1) && (strcmp(argv[1],"-n")) == 0 )
X {
X nointeract = 1;
X argc--;
X argv++;
X }
X
X switch(argc)
X {
X case 2:
X command = argv[1];
X break;
X case 3:
X command = argv[1];
X if( isdigit(argv[2][0]) )
X {
X count = atoi(argv[2]);
X }
X else
X {
X filename = argv[2];
X }
X break;
X case 4:
X command = argv[1];
X if( isdigit(argv[2][0]) )
X {
X count = atoi(argv[2]);
X filename = argv[3];
X }
X else
X {
X filename = argv[2];
X count = atoi(argv[3]);
X }
X break;
X default:
X usage(argv[0]);
X break;
X
X } /* switch(argc... */
X
X /*
X * Now check arguments...
X * count must be greater than zero.
X */
X
X if( count <= 0 )
X {
X fprintf(stderr,"Illegal count specified %d\n",count);
X usage(argv[0]);
X }
X if( strncmp(command,"ret",3) == 0 )
X {
X tape_cmd = TAPE_RETEN;
X }
X else if( strncmp(command,"rew",3) == 0)
X {
X tape_cmd = TAPE_REWIND;
X if( strcmp(filename,TAPEFILE_NOREWIND) == 0 )
X {
X if( filename != DEFAULT_FILENAME )
X {
X fprintf(stderr,"File name changed to %d %s\n",
X TAPEFILE_REWIND,
X "to perform rewind");
X }
X filename = TAPEFILE_REWIND;
X }
X }
X else if( command[0] == 'e' )
X {
X tape_cmd = TAPE_ERASE;
X }
X else
X {
X fprintf(stderr,"Illegal command: %s\n", command);
X usage(argv[0]);
X }
X
X
X while( count-- > 0 )
X {
X if( ! nointeract )
X {
X (void) change_tape(++tape_count,tape_cmd);
X }
X
X if( (fd=open(filename,O_RDWR)) == -1 )
X {
X fprintf(stderr,"Failed to open %s, errno = %d\n",
X filename, errno);
X exit(10);
X }
X
X if( tape_cmd != TAPE_REWIND )
X {
X /*
X * make sure the tape has stablized by sleeping a
X * bit before sending the ioctl
X */
X sleep(SLEEP_TIME);
X
X if( ioctl(fd,WTQICMD,tape_cmd) == 1)
X {
X fprintf(stderr,"Ioctl failed, errno = %d\n",
X errno);
X fprintf(stderr,"Operation may not have %s\n",
X "succeeded");
X }
X }
X
X close(fd);
X }
X exit(0);
}
X
usage(pgm)
X char * pgm;
{
X char * ptr;
X char * strrchr();
X
X if( (ptr=strrchr(pgm,'/')) != (char *) 0)
X {
X pgm = ptr+1;
X }
X
X fprintf(stderr,"Usage: %s tape_command [-n] [count] [tapefilename]\n",
X pgm);
X fprintf(stderr,"Where tape_command can be: %s\n",
X "rewind, retension, or erase");
X fprintf(stderr," -n signifies no interaction\n");
X fflush(stderr);
X exit(10);
}
X
change_tape(cnt,cmd)
X int cnt;
X int cmd;
{
X char buffer[120];
X char * job;
X char * suffix;
X
X switch(cnt)
X {
X case 1:
X suffix = "st";
X break;
X case 2:
X suffix = "nd";
X break;
X case 3:
X suffix = "rd";
X break;
X default:
X suffix = "th";
X break;
X
X } /* switch(cnt... */
X
X switch(cmd)
X {
X case TAPE_REWIND:
X job = "rewind";
X break;
X
X case TAPE_RETEN:
X job = "retension";
X break;
X
X default:
X job = "erase";
X break;
X
X } /* switch(cmd... */
X
X fprintf(stdout,"Please place the %d%s tape in the drive and\n",
X cnt, suffix);
X fprintf(stdout,"press <return> to %s it",job);
X fflush(stdout);
X
X (void) ioctl(0,TCFLSH, 0);
X (void) read(0,buffer,120);
}
X
SHAR_EOF
chmod 0444 tapecmd.c ||
echo 'restore of tapecmd.c failed'
Wc_c="`wc -c < 'tapecmd.c'`"
test 3831 -eq "$Wc_c" ||
echo 'tapecmd.c: original size 3831, current size' "$Wc_c"
fi
exit 0
--
Conor P. Cahill (703)430-9247 Virtual Technologies, Inc.
uunet!virtech!cpcahil 46030 Manekin Plaza, Suite 160
Sterling, VA 22170
More information about the Comp.unix.sysv386
mailing list