[comp.unix.sysv386] Retensioning tapes through wt

dag@gorgon.uucp (Daniel A. Glasser) (04/22/91)

This is touched on in the FAQ posting, but I've run into a bit of a snag;

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
something.  None of the documentation that came with my system says
anything more about this command to the wt driver beyond the name
of the symbol and that it's supposed to tell the device driver to
retension the tape.  Nothing about what other arguments I might need.

I wrote the program included below to do this, and discovered that I
always get an 'invalid argument' error back from the ioctl().  If I
open /dev/tape, the tape moves a bit but does not retension.  If I
open /dev/ntape (no-rewind) the tape drive seems to go into eternal
retensioning.  I ran the old /dev/tape version to get it to stop.
What's the real scoop on this ioctl() for the wt driver?  Does anyone
have a program to do the retensioning that works and that they are
willing to share with me?  Is more information available on the wt(7)
ioctl()s?

Please reply via e-mail as I don't always get all the news (space problems)
and can't always read all of what I do get.  Thanks.

[.signature is at end]			Daniel A. Glasser
					dag%gorgon@persoft.com
				-or-	dag@persoft.com
				-or-	...!uwvax!persoft!gorgon!dag
				-or-	...!uwvax!persoft!dag

----- Beginning of program ----
#include <stdio.h>
#include <sys/types.h>
#include <sys/wtioctl.h>
#include <fcntl.h>

#ifndef	NOREWIND
#define	TAPE_DEVICE "/dev/tape"
#else
#define	TAPE_DEVICE "/dev/ntape"
#endif

main()
{
	int status;
	int tapefd;
	extern int errno;

	/* Open the tape drive.  This appears to be okay */
	tapefd = open(TAPE_DEVICE, O_RDONLY);
	if (tapefd < 0)
	{
		perror("retens");
		exit(1);
	}
	
	errno = 0;		/* Reset errno... */

	/* Try to retension the tape. */
	status = ioctl(tapefd, RETENS, 0);

	if (status < 0)	perror("retens");	/* On failure, tell all. */

	/* print out the status */
	printf("Status on retension was %d\n", status);

	/* close the drive now. */
	close(tapefd);

	/* leave the program. */
	exit(0);
}
---- end of program -----
-- 
Daniel A. Glasser                       One of those things that goes
dag%gorgon@persoft.com                  "BUMP! (ouch!)" in the night.

support@ism.isc.com (Support Account) (04/23/91)

In article <1991Apr21.174450.26570@gorgon.uucp> dag@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

This is a perfect opportunity to mention a new update disk
for Interactive Unix, SSU7, which includes a new program,
"mt", for manipulating tape devices. This program works with
both the Wangtek QIC-02 devices and SCSI tapes, and will
allow users to rewind, retension, erase tapes, as well as
write and seek file marks.

Also included in this update disk are fixes for the Adaptec
SCSI tape driver and the Wangtek QIC-02 driver. Multiple volume
backups now work with Adaptec SCSI tapes, and multiple tape
drives (up to 4) can now be connected to each Adaptec SCSI interface.

This update will run on Interactive Unix V2.2.1 (if you do not have V2.2.1
you will have to upgrade - V2.2 users can get a free upgrade to V2.2.1).
Users can order this and the other updates listed
below from their distributor or from Interactive's free warranty support
line, (213) 453 8649.

List of available fix disks:
for V2.0.* :

FX00001-2Z   5.25"   X0  Update   - Bell Technologies ICC board fix - 2.0
FX00002-2Z    3.5"   X0  Update
FX00004-2Z   5.25"   X1  Update   - tbl program fix; release 2.0 of TPW
FX00003-2Z    3.5"   X1  Update
FX00006-2Z   5.25"   X2  Update   - SCO Foxbase+ file & record locking fix
FX00005-2Z    3.5"   X2  Update              rel. 2.0.*
FX00008-2Z   5.25"   X3  Update   - VGA Server support under 1.0 rel. X11
FX00007-2Z    3.5"   X3  Update
FX00010-2Z   5.25"   X4  Update   - SCO Professional 2.0 fix; release 2.0.*
FX00009-2Z    3.5"   X4  Update
FX00012-2Z   5.25"   X5  Update   - asy fix - rel. 2.0.* fixes
FX00011-2Z    3.5"   X5  Update     bidirectional modem control
FX00014-2Z   5.25"   X6  Update   - ttymap fixes for Europe - release 2.0.*
FX00013-2Z    3.5"   X6  Update
FX00016-2Z   5.25"   X8  Update   - Psuedo-TTY drivers for PCI - 2.0.*
FX00015-2Z    3.5"   X8  Update
FX00018-2Z   5.25"   X7  Update   - sendmail fix - release 2.0.*
FX00017-2Z    3.5"   X7  Update      fixes many sendmail problems
FX00028-2Z   5.25"   Y1  Update      poll-on-pipes enhancement - release 2.0.*
FX00029-2Z    3.5"   Y1  Update
FX00027-2Z    3.5"   Y3  Update      dossette fix - 2.0.*  support for 3.5" media

for V2.2:

FX00019-2Z   5.25"   SSU.1a  Update  Posix Fixes (OS only) user becomes
FX00023-2Z    3.5"   SSU.1a  Update  Posix compliant
FX00020-2Z   5.25"   SSU.1b  Update  Posix Fixes (SDS portion) libc.a fix
FX00024-2Z    3.5"   SSU.1b  Update
FX00021-2Z   5.25"   SSU.2  Update   msg.h Fix msgctl call was changed to
FX00025-2Z    3.5"   SSU.2  Update   an int from an unshort.
FX00022-2Z   5.25"   SSU.3  Update   VP/ix - Windows 3.0 Support
FX00026-2Z    3.5"   SSU.3  Update
FX00032-2Z   5.25"   SSU.4a  Update  TCP/ip Update fixed sockets with
FX00033-2Z    3.5"   SSU.4a  Update  KEEPALIVE option
FX00034-2Z   5.25"   SSU.4b  Update  NFS Update (requires SSU.4a)
FX00035-2Z    3.5"   SSU.4b  Update  fixed lockd core dumping
FX00030-2Z   5.25"   SSU.5  Update   Dossette fix - 2.2 "floppy not present"
FX00031-2Z    3.5"   SSU.5  Update
FX00038-2Z   5.25"   SSU.6  Update   Timezone fix (non-US timezone fix,
FX00039-2Z    3.5"   SSU.6  Update   system would be unusable)
FX00042-2Z   5.25"   SSU.8  Update   Kconfig fix - limit of 100 devices
FX00043-2Z    3.5"   SSU.8  Update   in mdevice file
FX00036-2Z   5.25"   SSU.10 Update   New Looking Glass Product
FX00037-2Z    3.5"   SSU.10 Update
FX00044-2Z   5.25"   SSU.14 Update   LP Scheduler fix - Print service will
FX00045-2Z    3.5"   SSU.14 Update   not remain on-line after printer fault.
NT00001      5.25"   Network Drivers
NT00002       3.5"   Network Drivers
UP00242      5.25"   2.2.1 Update
UP00244       3.5"   2.2.1 Update
SP00025      5.25"   EISA Update
SP00026       3.5"   EISA Update
FX00046-2Z   5.25"   OS Security Update (2.0.2, 2.2, 2.2.1)
FX00047-2Z    3.5"   OS Security Update
FX00048-2Z   5.25"   SDS Security Update (2.0.2, 2.2, 2.2.1)
FX00049-2Z    3.5"   SDS Security Update
FX00050      5.25    SSU.7 Update Adaptec SCSI tape, Wangtek tape,
FX00051       3.5    mt tape utility program

...
ISC support

cpcahil@virtech.uucp (Conor P. Cahill) (04/23/91)

dag@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@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