Subject: kern/1705: added SCSI tape IOCTL (ERASE) (see also bin/921)
To: None <gnats-bugs@gnats.netbsd.org, rhialto@polder.ubc.kun.nl>
From: Olaf Seibert <rhialto@polder.ubc.kun.nl>
List: netbsd-bugs
Date: 10/30/1995 12:02:21
>Number:         1705
>Category:       kern
>Synopsis:       added SCSI tape IOCTL (ERASE) (see also bin/921)
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    kern-bug-people (Kernel Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Mon Oct 30 06:20:00 1995
>Last-Modified:
>Originator:     Olaf Seibert
>Organization:
___ Olaf 'Rhialto' Seibert      D787B44DFC896063 4CBB95A5BD1DAA96 
\X/ There are no lemurs in this post    rhialto@polder.ubc.kun.nl
>Release:        1.0
>Environment:
	
System: NetBSD polder.ubc.kun.nl 1.0 NetBSD 1.0 (POLDER) #29: Wed Aug 2 17:27:43 MET DST 1995 rhialto@polder.ubc.kun.nl:/home/src/sys/arch/i386/compile/POLDER i386


>Description:

In pr bin/921 I proposed enhancements to the mt command. This pr
gives my local change to implement mt erase. (I know I should have put
part of it in the header file). It would be nice to get this simple
bit in before 1.1 is released.

>How-To-Repeat:
n/a
>Fix:
enclosed diff, with material lifted from FreeBSD and adapted for
different NetBSD structure:

*** st.c.orig	Mon Oct 30 11:54:35 1995
--- st.c	Mon Oct 30 11:53:46 1995
***************
*** 53,58 ****
--- 53,59 ----
   * to be depending on whether we expect to retension or not.
   */
  
+ #define Rhialto 1
  
  #include <sys/types.h>
  #include <sys/param.h>
***************
*** 174,179 ****
--- 175,191 ----
  	    {0, 0, QIC_120}				/* minor 12-15 */
  	}
      },
+ #if Rhialto
+     {"WANGTEK ", "5150ES SCSI FA15\0""01 A", "????",
+ 	0, 0,
+ 	{
+ 	    {0, ST_Q_IGNORE_LOADS, 0},			/* minor 0-3 */
+ 	    {0, 0, 0},					/* minor 4-7 */
+ 	    {0, 0, 0},					/* minor 8-11 */
+ 	    {0, 0, 0}					/* minor 12-15 */
+ 	}
+     },
+ #endif
      {"WangDAT ", "Model 1300", "????",
  	0, 0,
  	{
***************
*** 1160,1165 ****
--- 1172,1183 ----
  			if (!error)
  				error = st_space(st, number, SP_BLKS, flags);
  			break;
+ #if Rhialto
+ 		/* Rhialto: */
+ 		case MTERASE:	/* erase - AKL */
+ 			error = st_erase(st, FALSE, flags);
+ 			break;
+ #endif
  		case MTREW:	/* rewind */
  			error = st_rewind(st, 0, flags);
  			break;
***************
*** 1662,1667 ****
--- 1680,1748 ----
  	    sizeof(cmd), 0, 0, ST_RETRIES, immediate ? 5000 : 300000, NULL,
  	    flags);
  }
+ 
+ #if Rhialto
+ /*
+ ** Tape erase - AKL: Andreas Klemm <andreas@knobel.gun.de>
+ */
+ struct scsi_erase
+ {
+ 	u_char	op_code;
+ 	u_char	byte2;
+ #define	SE_LONG		0x01	/*
+ 				** Archive Viper 2525 doesn't allow short 
+ 				** erase, other tapes possibly don't allow 
+ 				** that, too.
+ 				*/
+ #define	SE_IMMED	0x02
+ 	u_char	unused[3];
+ 	u_char	control;
+ } erase;
+ 
+ #define	ERASE			0x19 /* AKL */
+ 
+ /*
+ **  Erase the device - AKL: Andreas Klemm <andreas@knobel.gun.de>
+ */ 
+ int 
+ st_erase(st, immediate, flags)
+ 	struct st_data *st;
+ 	u_int immediate;
+ 	int flags;
+ {
+ 	struct scsi_erase scsi_cmd;
+ 	int error;
+ 	int nmarks;
+ 
+ 	error = st_check_eod(st, FALSE, &nmarks, flags);
+ 	if (error)
+ 		return (error);
+ 	/*
+ 	** AKL: Archive Viper 2525 technical manual 5.7 (ERASE 19h):
+ 	**	tape has to be positioned to BOT first before erase command
+ 	**	is issued or command is rejected. So we rewind the tape first
+ 	**	and exit with an error, if the tape can't be rewinded.
+ 	*/
+ 	error = st_rewind(st, FALSE, SCSI_SILENT);
+ 	if (error)
+ 		return (error);
+ 	st->flags &= ~ST_PER_ACTION;
+ 	bzero(&scsi_cmd, sizeof(scsi_cmd));
+ 	scsi_cmd.op_code = ERASE;
+ 	scsi_cmd.byte2 = SE_LONG;		/* LONG_ERASE - AKL */
+ 	scsi_cmd.byte2 += immediate ? SE_IMMED : 0; /* immed bit is here the 2nd! */
+ 	return (scsi_scsi_cmd(st->sc_link,
+ 		(struct scsi_generic *) &scsi_cmd,
+ 		sizeof(scsi_cmd),
+ 		0,
+ 		0,
+ 		ST_RETRIES,
+ 		immediate ? 5000 : 300000,	/* 5 sec or 5 min */
+ 		NULL,
+ 		flags));
+ }
+ 
+ #endif
  
  
  /*
>Audit-Trail:
>Unformatted:
An extra SCSI tape IOCTL to erase the tape.