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