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