1.\" $NetBSD: st.4,v 1.15 1999/03/16 01:19:18 garbled Exp $ 2.\" 3.\" Copyright (c) 1996 4.\" Julian Elischer <julian@freebsd.org>. All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 16.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26.\" SUCH DAMAGE. 27.\" 28.Dd August 23, 1996 29.Dt ST 4 30.Os 31.Sh NAME 32.Nm st 33.Nd SCSI tape driver 34.Sh SYNOPSIS 35.Cd st* at scsibus? target ? lun ? 36.Cd st1 at scsibus0 target 4 lun 0 37.Sh DESCRIPTION 38The 39.Nm 40driver provides support for 41.Tn SCSI 42tape drives. 43It allows a tape drive to be run in several different 44modes depending on minor numbers and supports several different 45.Sq sub-modes . 46The device can have both a 47.Em raw 48interface and a 49.Em block 50interface; however, only the raw interface is usually used (or recommended). 51.Pp 52.Tn SCSI 53devices have a relatively high level interface and talk to the system via a 54.Tn SCSI 55adapter and a 56.Tn SCSI 57adapter driver 58(e.g. 59.Xr ahc 4 ) . 60A 61.Tn SCSI 62adapter must also be separately configured into the system before a 63.Tn SCSI 64tape can be configured. 65.Pp 66As the 67.Tn SCSI 68adapter is probed during boot, the 69.Tn SCSI 70bus is scanned for devices. 71Any devices found which answer as 72.Sq Em Sequential 73type devices will be attached to the 74.Nm 75driver. 76.Sh MOUNT SESSIONS 77The 78.Nm 79driver is based around the concept of a 80.Dq Em mount session , 81which is defined as the period between the time that a tape is 82mounted, and the time when it is unmounted. 83Any parameters set during a mount session remain in effect for the 84remainder of the session or until replaced. 85The tape can be unmounted, bringing the session to a close in 86several ways. 87These include: 88.Bl -enum 89.It 90Closing an 91.Sq unmount device , 92referred to as sub-mode 00 below. 93An example is 94.Pa /dev/rst0 . 95.It 96Using the 97.Dv MTOFFL 98.Xr ioctl 2 99command, reachable through the 100.Sq Cm offline 101command of 102.Xr mt 1 . 103.It 104Opening a different mode will implicitly unmount the tape, thereby 105closing off the mode that was previously mounted. 106All parameters will be loaded freshly from the new mode 107(See below for more on modes). 108.El 109.Sh MODES AND SUB-MODES 110There are several different 111.Sq operation 112modes. 113These are controlled by bits 2 and 3 of the minor number 114and are designed to allow users to easily read and write different 115formats of tape on devices that allow multiple formats. 116The parameters for each mode can be set individually by hand with the 117.Xr mt 1 118command. 119When a device corresponding to a particular mode is first 120mounted, The operating parameters for that mount session are copied 121from that mode. 122Further changes to the parameters during the session will change 123those in effect for the session but not those set in the operation mode. 124To change the parameters for an operation mode, one must compile 125them into the 126.Dq Em quirk 127table in the driver's source code. 128.Pp 129In addition to the operating modes mentioned above, bits 0 and 1 130of the minor number are interpreted as 131.Sq sub-modes . 132The sub-modes differ in the action taken when the device is closed: 133.Bl -tag -width XXXX 134.It 00 135A close will rewind the device; if the tape has been written, then 136a file mark will be written before the rewind is requested. 137The device is unmounted. 138.It 01 139A close will leave the tape mounted. 140If the tape was written to, a file mark will be written. 141No other head positioning takes place. 142Any further reads or writes will occur directly after the last 143read, or the written file mark. 144.It 10 145A close will rewind the device. 146If the tape has been written, then a file mark will be written 147before the rewind is requested. 148On completion of the rewind an unload command will be issued. 149The device is unmounted. 150.It 11 151This is Control mode, which allows the tape driver to be opened without a tape 152inserted to allow various ioctls (e.g. MTIOCGET or MTIOCTOP to set density 153or blocksize) and raw SCSI command on 154through. I/O can be done in this mode, if desired, with the same 155rewind/eject behaviour as mode 01. This isn't really an 'action taken 156on close' type of distinction, but this seems to be the place to put 157this mode. 158.El 159.Sh BLOCKING MODES 160.Tn SCSI 161tapes may run in either 162.Sq Em variable 163or 164.Sq Em fixed 165block-size modes. 166Most 167.Tn QIC Ns -type 168devices run in fixed block-size mode, where most nine-track tapes 169and many new cartridge formats allow variable block-size. 170The difference between the two is as follows: 171.Bl -inset 172.It Variable block-size: 173Each write made to the device results in a single logical record 174written to the tape. 175One can never read or write 176.Em part 177of a record from tape (though you may request a larger block and 178read a smaller record); nor can one read multiple blocks. 179Data from a single write is therefore read by a single read. 180The block size used may be any value supported by the device, the 181.Tn SCSI 182adapter and the system (usually between 1 byte and 64 Kbytes, 183sometimes more). 184.Pp 185When reading a variable record/block from the tape, the head is 186logically considered to be immediately after the last item read, 187and before the next item after that. 188If the next item is a file mark, but it was never read, then the 189next process to read will immediately hit the file mark and receive 190an end-of-file notification. 191.It Fixed block-size 192Data written by the user is passed to the tape as a succession of 193fixed size blocks. 194It may be contiguous in memory, but it is considered to be a series 195of independent blocks. 196One may never write an amount of data that is not an exact multiple 197of the blocksize. 198One may read and write the same data as a different set of records, 199In other words, blocks that were written together may be read 200separately, and vice-versa. 201.Pp 202If one requests more blocks than remain in the file, the drive will 203encounter the file mark. 204Because there is some data to return (unless there were no records 205before the file mark), the read will succeed, returning that data. 206The next read will return immediately with an EOF (as above, if 207the file mark is never read, it remains for the next process to 208read if in no-rewind mode). 209.El 210.Sh FILE MARK HANDLING 211The handling of file marks on write is automatic. 212If the user has written to the tape, and has not done a read since 213the last write, then a file mark will be written to the tape when 214the device is closed. 215If a rewind is requested after a write, then the driver assumes 216that the last file on the tape has been written, and ensures that 217there are two file marks written to the tape. 218The exception to this is that there seems to be a standard (which 219we follow, but don't understand why) that certain types of tape do 220not actually write two file marks to tape, but when read, report a 221.Sq phantom 222file mark when the last file is read. 223These devices include the QIC family of devices 224(it might be that this set of devices is 225the same set as that of fixed block devices. 226This has not been determined yet, and they are treated as separate 227behaviors by the driver at this time). 228.Sh EOM HANDLING 229Attempts to write past EOM and how EOM is reported are handled slightly 230differently based upon whether EARLY WARNING recognition is enabled in 231the driver. 232.Pp 233If EARLY WARNING recognitions is \fBnot\fR enabled, then detection 234of EOM (as reported in SCSI Sense Data with an EOM indicator) 235causes the write operation to be flagged with I/O error (EIO). 236This has the effect for the user application of not knowing actually 237how many bytes were read (since the return of the 238.Xr read 2 239system call is set to \(mi1). 240.Pp 241If EARLY WARNING recognition \fBis\fR enabled, then detection of EOM 242(as reported in SCSI Sense Data with an EOM indicator) 243has no immediate effect except that 244the driver notes that EOM has been detected. If the write completing 245didn't transfer all data that was requested, then the residual count 246(counting bytes \fBnot\fR written) 247is returned to the user application. In any event, the next attempt 248to write (if that is the next action the user application takes) 249is immediately completed with no data transferred, and a residual 250returned to the user application indicating that no data was transferred. 251This is the traditional UNIX EOF indication. The state that EOM had 252been seen is then cleared. 253.Pp 254In either mode of operation, the driver does not prohibit the 255user application from writing more data, if it chooses to do so. This 256will continue up until the physical end of media, which is usually 257signalled internally to the driver as a CHECK CONDITION with 258the Sense Key set to VOLUME OVERFLOW. When this or any otherwise 259unhandled error occurs, an error return of EIO will be transmitted 260to the user application. This does indeed mean that if EARLY WARNING 261is enables and the device continues to set EOM indicators prior to 262hitting physical end of media, that an indeterminate number of 'short write 263returns' as described in the previous paragraph will occur. However, the 264expected user application behaviour (in common with other systems) is 265to close the tape and rewind and request another tape upon the receipt 266of the first EOM indicator, possibly after writing one trailer record. 267.Sh KERNEL CONFIGURATION 268Because different tape drives behave differently, there is a 269mechanism within the source to 270.Nm 271to quickly and conveniently recognize and deal with brands and 272models of drive that have special requirements. 273.Pp 274There is a table (called the 275.Dq Em quirk table ) 276in which the identification strings of known errant drives can be stored. 277Alongside each is a set of flags that allows the setting 278of densities and blocksizes for each of the modes, along with a 279set of `QUIRK' flags that can be used to enable or disable sections 280of code within the driver if a particular drive is recognized. 281.Sh IOCTLS 282The following 283.Xr ioctl 2 284calls apply to 285.Tn SCSI 286tapes. 287Some also apply to other tapes. 288They are defined in the header file 289.Aq Pa sys/mtio.h . 290.\" 291.\" Almost all of this discussion belongs in a separate mt(4) 292.\" manual page, since it is common to all magnetic tapes. 293.\" 294.Pp 295.Bl -tag -width MTIOCEEOT 296.It Dv MTIOCGET 297.Pq Li "struct mtget" 298Retrieve the status and parameters of the tape. Error status 299and residual is unlatched and cleared by the driver when it receives 300this ioctl. 301.It Dv MTIOCTOP 302.Pq Li "struct mtop" 303Perform a multiplexed operation. 304The argument structure is as follows: 305.Bd -literal -offset indent 306struct mtop { 307 short mt_op; 308 daddr_t mt_count; 309}; 310.Ed 311.Pp 312The following operation values are defined for 313.Va mt_op : 314.Bl -tag -width MTSELDNSTY 315.It Dv MTWEOF 316Write 317.Va mt_count 318end of file marks at the present head position. 319.It Dv MTFSF 320Skip over 321.Va mt_count 322file marks. 323Leave the head on the EOM side of the last skipped file mark. 324.It Dv MTBSF 325Skip 326.Em backwards 327over 328.Va mt_count 329file marks. 330Leave the head on the BOM (beginning of media) 331side of the last skipped file mark. 332.It Dv MTFSR 333Skip forwards over 334.Va mt_count 335records. 336.It Dv MTBSR 337Skip backwards over 338.Va mt_count 339records. 340.It Dv MTREW 341Rewind the device to the beginning of the media. 342.It Dv MTOFFL 343Rewind the media (and, if possible, eject). 344Even if the device cannot eject the media it will often no longer 345respond to normal requests. 346.It Dv MTNOP 347No-op; set status only. 348.It Dv MTERASE 349Erase the media from current position. If the field 350.Va mt_count 351is nonzero, a full erase is done (from current position to end of 352media). If 353.Va mt_count 354is zero, only an erase gap is written. It is hard to say which 355drives support only one but not the other option 356.It Dv MTCACHE 357Enable controller buffering. 358.It Dv MTNOCACHE 359Disable controller buffering. 360.It Dv MTSETBSIZ 361Set the blocksize to use for the device/mode. 362If the device is capable of variable blocksize operation, and the 363blocksize is set to 0, then the drive will be driven in variable mode. 364This parameter is in effect for the present mount session only, unless 365the device was opened in Control Mode (in which case this set value persists 366until a reboot). 367.It Dv MTSETDNSTY 368Set the density value (see 369.Xr mt 1 ) 370to use when running in the mode opened (minor bits 2 and 3). 371This parameter is in effect for the present 372mount session only, unless the device was opened in Control Mode (in which 373case this set value persists until a reboot). 374Any byte sized value may be specified. Note that 375only a very small number of them will actually usefully work. The 376rest will cause the tape drive to spit up. 377.It Dv MTCMPRESS 378Enable or disable tape drive data compression. 379Typically tape drives will quite contentedly ignore settings on 380reads, and will probably keep you from changing density for writing 381anywhere but BOT. 382.It Dv MTEWARN 383Enable or disable EARLY WARNING at EOM behaviour (using the count 384as a boolean value). 385.El 386.It Dv MTIOCRDSPOS 387.Pq Li "u_int32_t" 388Read device logical block position. 389Not all drives support this option. 390.It Dv MTIOCRDHPOS 391.Pq Li "u_int32_t" 392Read device hardware block position. 393Not all drives support this option. 394.It Dv MTIOCSLOCATE 395.Pq Li "u_int32_t" 396Position the tape to the specified device logical block position. 397.It Dv MTIOCHLOCATE 398.Pq Li "u_int32_t" 399Position the tape to the specified hardware block position. 400Not all drives support this option. 401.El 402.Sh FILES 403.Bl -tag -width /dev/[n][e]rst[0-9] -compact 404.It Pa /dev/[n][e]rst[0-9] 405general form: 406.It Pa /dev/rst0 407Mode 0, Rewind on close 408.It Pa /dev/nrst0 409Mode 1, No rewind on close 410.It Pa /dev/erst0 411Mode 2, Eject on close (if capable) 412.It Pa /dev/enst0 413Mode 3, Control Mode (elsewise like mode 0) 414.El 415.Sh BUGS 416The selection of compression could possibly also be usefully done 417as with a minor device bit. 418.Sh DIAGNOSTICS 419A variety, far too many to list. 420.Sh SEE ALSO 421.Xr mt 1 , 422.Xr intro 4 , 423.Xr mtio 4 , 424.Xr scsi 4 425.Sh HISTORY 426This 427.Nm 428driver was originally written for 429.Tn Mach 4302.5 by Julian Elischer, and was ported to 431.Nx 432by Charles Hannum. 433This man page was edited for 434.Nx 435by Jon Buller. 436