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