1.\" Copyright (c) 1996 2.\" Julian Elischer <julian@freebsd.org>. All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 10.\" 2. Redistributions in binary form must reproduce the above copyright 11.\" notice, this list of conditions and the following disclaimer in the 12.\" documentation and/or other materials provided with the distribution. 13.\" 14.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24.\" SUCH DAMAGE. 25.\" 26.Dd January 17, 1996 27.Dt ST 4 28.Os FreeBSD 29.Sh NAME 30.Nm st 31.Nd SCSI tape driver 32.Sh SYNOPSIS 33.Cd tape st 34.Cd device st1 at scbus0 target 4 lun 0 35.Sh DESCRIPTION 36The 37.Nm 38driver provides support for a 39.Tn SCSI 40tape. It allows the tape 41to be run in up to four different modes depending on minor numbers 42and supports several different `sub-modes'. 43The device can have both a 44.Em raw 45interface 46and a 47.Em block 48interface; however, only the raw interface is usually used (or recommended). 49In general the interfaces are similar to those described by 50.Xr wt 4 51or 52.Xr mt 4 . 53.Pp 54Where the 55.Xr wt 4 56device has a fairly low level interface to the system, 57.Tn SCSI 58devices have a much higher level interface and talk to the system via 59a 60.Tn SCSI 61adapter and a 62.Tn SCSI 63adapter driver 64(e.g., 65.Xr ahc 4 ) . 66A 67.Tn SCSI 68adapter must also be separately configured into the system 69before a 70.Tn SCSI 71tape can be configured. 72.Pp 73As the 74.Tn SCSI 75adapter is probed during boot, the 76.Tn SCSI 77bus is scanned for devices. Any devices found which answer as 78.Sq Em Sequential 79type devices will be attached to the 80.Nm 81driver. 82In 83.Tn FreeBSD 84releases prior to 2.1, the first found is attached as 85.Em st0 86and the next, 87.Em st1 , 88etc. 89Beginning in 90.Fx 2.1 91it is possible to specify what 92.Nm 93unit a device should 94come on line as; refer to 95.Xr scsi 4 96for details on kernel configuration. 97.Sh MOUNT SESSIONS 98The 99.Nm 100driver is based around the concept of a 101.Dq Em mount session , 102which is defined as the period between the time that a tape is 103mounted, and the time when it is unmounted. Any parameters set during 104a mount session remain in effect for the remainder of the session or 105until replaced. The tape can be unmounted, bringing the session to a 106close in several ways. These include: 107.Bl -enum 108.It 109Closing an `unmount device', 110referred to as sub-mode 00 below. An example is 111.Pa /dev/rst0 . 112.It 113Using the MTOFFL 114.Xr ioctl 2 115command, reachable through the 116.Sq Cm offline 117command of 118.Xr st 1 . 119.It 120Opening a different mode will implicitly unmount the tape, thereby closing 121off the mode that was previously mounted. All parameters will be loaded 122freshly from the new mode. (See below for more on modes.) 123.El 124.Pp 125Parameters that are required to last across the unmounting of a tape 126should be set on the control device. This is sub-mode 3 (see below) and is 127reached through a file with a name of the form 128.Sm off 129.No Xo 130.Pa /dev/st 131.Ar Y 132.Pa ctl. 133.Ar X 134.Xc , 135.Sm on 136where 137.Ar Y 138is the drive number and 139.Ar X 140is the mode number. 141.Sh MODES AND SUB-MODES 142There are four 143.Sq operation 144modes. These are controlled by bits 2 and 3 of the minor number and 145are designed to allow users to easily read and write different formats 146of tape on devices that allow multiple formats. The parameters for 147each mode can be set individually by hand with the 148.Xr mt 1 149command. When a device corresponding to a particular mode is first 150mounted, The operating parameters for that 151mount session 152are copied from that mode. Further changes to the parameters during the 153session will change those in effect for the session but not those set 154in the operation mode. To change the parameters for an operation mode, 155one must either assign the parameters to the control device, or compile 156them into the 157.Dq Em Rogues Gallery 158table in the driver's source code. 159.Pp 160In addition to the four operating modes mentioned above, 161bits 0 and 1 of the minor number are interpreted as 162.Sq sub-modes . 163The sub-modes differ in the action taken when the device is closed: 164.Bl -tag -width XXXX 165.It 00 166A close will rewind the device; if the tape has been 167written, then a file mark will be written before the rewind is requested. 168The device is unmounted. 169.It 01 170A close will leave the tape mounted. 171If the tape was written to, a file mark will be written. 172No other head positioning takes place. 173Any further reads or writes will occur directly after the 174last read, or the written file mark. 175.It 10 176A close will rewind the device. If the tape has been 177written, then a file mark will be written before the rewind is requested. 178On completion of the rewind an unload command will be issued. 179The device is unmounted. 180.It 11 181This is a special mode, known as the 182.Dq control device 183for the mode. Parameters set for the mode while in this sub-mode will 184be remembered from one mount to the next. This allows the system 185administrator to set different characteristics (e.g., density, 186blocksize) 187.\" (and eventually compression) 188on each mode, and have the different modes keep those parameters 189independent of any parameter changes a user may invoke during a single 190mount session. At the completion of the user's mount session, drive 191parameters will revert to those set by the administrator. I/O 192operations cannot be performed on this device/sub-mode. General 193.Xr scsi 4 194ioctls can 195.Em only 196be performed against the control device. 197.El 198.Sh BLOCKING MODES 199.Tn SCSI 200tapes may run in either 201.Sq Em variable 202or 203.Sq Em fixed 204block-size modes. Most 205.Tn QIC Ns -type 206devices run in fixed block-size mode, where most nine-track tapes and 207many new cartridge formats allow variable block-size. The difference 208between the two is as follows: 209.Bl -inset 210.It Variable block-size: 211Each write made to the device results in a single logical record 212written to the tape. One can never read or write 213.Em part 214of a record from tape (though you may request a larger block and read 215a smaller record); nor can one read multiple blocks. Data from a 216single write is therefore read by a single read. The block size used 217may be any value supported by the device, the 218.Tn SCSI 219adapter and the system (usually between 1 byte and 64 Kbytes, 220sometimes more). 221.Pp 222When reading a variable record/block from the tape, the head is 223logically considered to be immediately after the last item read, 224and before the next item after that. If the next item is a file mark, 225but it was never read, then the next 226process to read will immediately hit the file mark and receive an end-of-file notification. 227.It Fixed block-size 228Data written by the user is passed to the tape as a succession of 229fixed size blocks. It may be contiguous in memory, but it is 230considered to be a series of independent blocks. One may never write 231an amount of data that is not an exact multiple of the blocksize. One 232may read and write the same data as a different set of records, In 233other words, blocks that were written together may be read separately, 234and vice-versa. 235.Pp 236If one requests more blocks than remain in the file, the drive will 237encounter the file mark. Because there is some data to return (unless 238there were no records before the file mark), the read will succeed, 239returning that data, The next read will return immediately with an 240EOF. (As above, if the file mark is never read, it remains for the next process to read if in no-rewind mode.) 241.El 242.Sh FILE MARK HANDLING 243The handling of file marks on write is automatic. If the user has 244written to the tape, and has not done a read since the last write, 245then a file mark will be written to the tape when the device is 246closed. If a rewind is requested after a write, then the driver 247assumes that the last file on the tape has been written, and ensures 248that there are two file marks written to the tape. The exception to 249this is that there seems to be a standard (which we follow, but don't 250understand why) that certain types of tape do not actually write two 251file marks to tape, but when read, report a `phantom' file mark when the 252last file is read. These devices include the QIC family of devices. 253(It might be that this set of devices is the same set as that of fixed 254block devices. This has not been determined yet, and they are treated 255as separate behaviors by the driver at this time.) 256.Sh KERNEL CONFIGURATION 257Because different tape drives behave differently, there is a mechanism 258within the source to 259.Nm 260to quickly and conveniently recognize and deal 261with brands and models of drive that have special requirements. 262.Pp 263There is a table (called the 264.Dq Em Rogues Gallery ) 265in which the identification 266strings of known errant drives can be stored. Alongside each is 267a set of flags that allows the setting of densities and blocksizes for each 268of the four modes, along with a set of `QUIRK' flags that can be 269used to enable or disable sections of code within the driver if a particular 270drive is recognized. 271.Sh IOCTLS 272The following 273.Xr ioctl 2 274calls apply to 275.Tn SCSI 276tapes. Some also apply to other tapes. They are defined 277in the header file 278.Aq Pa /sys/mtio.h . 279.\" 280.\" Almost all of this discussion belongs in a separate mt(4) 281.\" manual page, since it is common to all magnetic tapes. 282.\" 283.Pp 284.Bl -tag -width MTIOCEEOT 285.It Dv MTIOCGET 286.Pq Li "struct mtget" 287Retrieve the status and parameters of the tape. 288.It Dv MTIOCTOP 289.Pq Li "struct mtop" 290Perform a multiplexed operation. The argument structure is as follows: 291.Bd -literal -offset indent 292struct mtop { 293 short mt_op; 294 daddr_t mt_count; 295}; 296.Ed 297.Pp 298The following operation values are defined for 299.Va mt_op : 300.Bl -tag -width MTSELDNSTY 301.It Dv MTWEOF 302Write 303.Va mt_count 304end of file marks at the present head position. 305.It Dv MTFSF 306Skip over 307.Va mt_count 308file marks. Leave the head on the EOM side of the last skipped 309file mark. 310.It Dv MTBSF 311Skip 312.Em backwards 313over 314.Va mt_count 315file marks. Leave the head on the BOM (beginning of media) 316side of the last skipped file mark. 317.It Dv MTFSR 318Skip forwards over 319.Va mt_count 320records. 321.It Dv MTBSR 322Skip backwards over 323.Va mt_count 324records. 325.It Dv MTREW 326Rewind the device to the beginning of the media. 327.It Dv MTOFFL 328Rewind the media (and, if possible, eject). Even if the device cannot 329eject the media it will often no longer respond to normal requests. 330.It Dv MTNOP 331No-op; set status only. 332.It Dv MTCACHE 333Enable controller buffering. 334.It Dv MTNOCACHE 335Disable controller buffering. 336.It Dv MTSETBSIZ 337Set the blocksize to use for the device/mode. If the device is capable of 338variable blocksize operation, and the blocksize is set to 0, then the drive 339will be driven in variable mode. This parameter is in effect for the present 340mount session only, unless set on the control device. 341.It Dv MTSETDNSTY 342Set the density value (see 343.Xr mt 1 ) 344to use when running in the mode opened (minor bits 2 and 3). 345This parameter is in effect for the present 346mount session only, unless set on the control device. 347.El 348.It Dv MTIOCIEOT 349Set end-of-tape processing (not presently supported for 350.Nm 351devices). 352.It Dv MTIOCEEOT 353Set end-of-tape processing (not presently supported for 354.Nm 355devices). 356.El 357.Pp 358In addition, the 359.Nm 360driver will allow the use of any of the general 361.Xr scsi 4 362.Fn ioctl 363commands, on the control device only. 364.Sh FILES 365.Bl -tag -width /dev/[n][e]rst[0-9].[0-3] -compact 366.It Pa /dev/[n][e]rst[0-9].[0-3] 367general form: 368.It Pa /dev/rst0.0 369Mode 0, rewind on close 370.It Pa /dev/nrst0.2 371Mode 2, No rewind on close 372.It Pa /dev/erst0.3 373Mode 3, Eject on close (if capable) 374.It Pa /dev/rst0 375Another name for rst0.0 376.It Pa /dev/nrst0 377Another name for nrst0.0 378.It Pa /dev/st0ctl.0 379Parameters set to this device become the default parameters for [en]rst0.0 380.It Pa /dev/st0ctl.1 381Parameters set to this device become the default parameters for [en]rst0.1 382.It Pa /dev/st0ctl.2 383Parameters set to this device become the default parameters for [en]rst0.2 384.It Pa /dev/st0ctl.3 385Parameters set to this device become the default parameters for [en]rst0.3 386.El 387.Sh DIAGNOSTICS 388None. 389.Sh SEE ALSO 390.Xr mt 1 , 391.Xr scsi 4 , 392.Xr st 9 393.Sh HISTORY 394This 395.Nm 396driver was originally written for 397.Tn Mach 3982.5, and was ported to 399.Tn FreeBSD 400by Julian Elischer. 401