SA(4)
π SA(4) β SCSI Sequential Access device driver π
Kernel Interfaces Manual β¨ SA(4) β¨
πΈ NAME πΈ
sa β the SCSI Sequential Access device driver. bestie this is the tape driver. yes tapes. they're iconic and they're not going anywhere (they are going somewhere, that's literally what tapes do).
π SYNOPSIS π
device sa
that's it. that's the whole vibe. one line. slay.
π¦ DESCRIPTION π¦
okay so sa is the driver that holds it down for every single SCSI device in the sequential access class that's hooked up to your system through a supported SCSI Host Adapter. and what's in the sequential access class? tape, plus all the other linear access devices out there. if it reads and writes in order and you can't just jump around it like a disk, it's in the club. π
now β a SCSI Host adapter has to be separately configured into the system first, before you can even think about configuring a SCSI sequential access device. adapter first, tape second. the order matters, no cap. π
π MOUNT SESSIONS π
the whole sa driver is built around one concept and it's called a βmount sessionβ. what is it? it's the period between the moment a tape gets mounted, and the moment it gets unmounted. that's the window. π«Ά
any parameters you set during a mount session stay in effect for the rest of that session β or until something replaces them. they don't just wander off. β¨
and there's more than one way to unmount the tape and close the session out. here's the list:
- Closing a
rewind device, which we call sub-mode 00 down below. example:/dev/sa0. π - Using the
MTOFFLioctl(2)command β which you can reach through the βofflineβ command ofmt(1). π
also super important: tape devices are exclusive open devices, with exactly one exception β when a control mode device is opened. in that exception case, exclusive access is only sought when it's actually needed (like, say, to set parameters). so it's not clingy 24/7, only when it has to be. π
β¨ SUB-MODES β¨
bits 0 and 1 of the minor number? those are your βsub-modesβ. and the sub-modes are all about one thing: what happens when the device gets closed. three of them. let's go. π₯
00β a close will rewind the device. and if the tape has been written to, then a file mark gets written before the rewind is requested. the device is unmounted. bye bestie π01β a close will leave the tape mounted. if the tape was written to, a file mark gets written. no other head positioning happens at all. any further reads or writes occur directly after the last read, or after the written file mark. it just keeps going. β10β a close will rewind the device. if the tape has been written to, a file mark gets written before the rewind is requested. and then β on completion of the rewind β an unload command is issued. the device is unmounted. full send. π
π BLOCKING MODES π
SCSI tapes can run in either βvariableβ or βfixedβ block-size mode. that's the split. π«
most QIC-type devices run in fixed block-size mode. meanwhile most nine-track tapes and many new cartridge formats allow variable block-size. and the difference between the two is genuinely this:
Variable block-size: every write you make to the device results in a single logical record written to the tape. you can never read or write part of a record from tape β though you can request a larger block and read a smaller record. and you can't read multiple blocks either. so data from a single write is read by a single read, periodt. the block size used may be any value supported by the device, the SCSI adapter and the system β usually between 1 byte and 64 Kbytes, sometimes more. π
when you're reading a variable record/block from the tape, the head is logically considered to be immediately after the last item read, and before the next item after that. so if the next item is a file mark but it was never read, then the next process to read will immediately hit the file mark and receive an end-of-file notification. rude but consistent. π
Fixed block-size: data written by the user gets passed to the tape as a succession of fixed size blocks. it may be contiguous in memory, but it's considered to be a series of independent blocks. you may never write an amount of data that isn't an exact multiple of the blocksize. π
and here's the fun part β you may read and write the same data as a different set of records. in other words: blocks that were written together may be read separately, and vice-versa. it's giving remix. β¨
if you request more blocks than remain in the file, the drive will encounter the file mark. since there's still some data to return (unless there were no records before the file mark), the read will succeed and return that data. the next read returns immediately with a value of 0. and same as above β if the file mark is never read, it stays there for the next process to read if you're in no-rewind mode. π¦
π BLOCK SIZES π
okay so by default, the driver will NOT accept reads or writes to a tape device that are larger than may be written to or read from the mounted tape using a single write or read request. NOT. capital N-O-T. π
and why is that a good thing? because the application author gets to have confidence that his wishes are respected in terms of the block size written to tape. so like β if the user tries to write a 256KB block to the tape, but the controller can handle no more than 128KB, the write will fail. π
the previous FreeBSD behavior, prior to FreeBSD 10.0, was to break up large reads or writes into smaller blocks when going to the tape. and the problem with that behavior is that it hides the actual on-tape block size from the application writer β at least in variable block mode. sneaky. not slay. π€
if the user would like his large reads and writes broken up into separate pieces, he may set the following loader tunables. but listen β
these tunables WILL GO AWAY in FreeBSD 11.0. they are provided for transition purposes only. they are not the main character, they're the side character with a countdown timer. β³
kern.cam.sa.allow_io_splitβ this variable, when set to1, will configure allsadevices to split large buffers into smaller pieces when needed. π«Άkern.cam.sa.%d.allow_io_splitβ this variable, when set to1, will configure the givensaunit to split large buffers into multiple pieces. and this will override the global setting, if it exists. so the specific one wins. π
and there are several sysctl(8) variables available to view block handling parameters. viewing only. look, don't touch. π
kern.cam.sa.%d.allow_io_splitβ this variable lets the user see, but not modify, the current I/O split setting. and the user is not permitted to modify this setting so that there is no chance of behavior changing for the application while a tape is mounted. it's locked for your own good bestie. πkern.cam.sa.%d.maxioβ this variable shows the maximum I/O size in bytes that is allowed by the combination of kernel tuning parameters (MAXPHYS,DFLTPHYS) and the capabilities of the controller attached to the tape drive. applications may look at this value for a guide on how large an I/O may be permitted β but should keep in mind that the actual maximum may be restricted further by the tape drive via the SCSIREAD BLOCK LIMITScommand. so it's a guide, not a promise. β¨kern.cam.sa.%d.cpi_maxioβ this variable shows the maximum I/O size supported by the controller, in bytes, reported via the CAM Path Inquiry CCB (XPT_PATH_INQ). and if this is0? that means the controller has not reported a maximum I/O size. it said nothing. silent. π€
π FILE MARK HANDLING π
file mark handling on write is automatic. you don't have to think about it. the driver thinks about it for you. π§
so: if the user has written to the tape, and has not done a read since the last write, then a file mark will be written to the tape when the device is closed. π
and if a rewind is requested after a write, then the driver assumes the last file on the tape has been written, and ensures that there are two file marks written to the tape. two. not one. two. βοΈ
the exception to all of this is that there seems to be a standard (which we follow, but do not understand why) that certain types of tape do not actually write two file marks to tape β but when read, they report a `phantom' file mark when the last file is read. spooky. π» these devices include the QIC family of devices.
and, as the original so honestly puts it: it might be that this set of devices is the same set as that of fixed block devices. this has not been determined yet, and they are treated as separate behaviors by the driver at this time. we don't know, and we're not pretending to know. respect. π«‘
β PARAMETERS β
the sa driver supports a number of parameters. here's how you talk to them: πΈ
- the user can query parameters using
mt param -l(which uses theMTIOCPARAMGETioctl) - the user can set parameters using
mt param -s(which uses theMTIOCPARAMSETioctl)
see mt(1) and mtio(4) for more details on the interface. π
and now, the supported parameters. all of them. buckle up. β¨
siliβ the default is0. when set to1, it sets the Suppress Incorrect Length Indicator (SILI) bit on tape reads. here's the tea: tape drives normally return sense data (which contains the residual) when the application reads a block that is not the same length as the amount of data requested. the SILI bit suppresses that notification in most cases. see the SSC-5 spec (available att10.org), specifically the section on theREAD(6)command, for more information. πeot_warnβ the default is0. by default, thesadriver reports entering Programmable Early Warning, Early Warning and End of Media conditions by returning a write with 0 bytes written, anderrnoset to0. ifeot_warnis set to1, thesadriver will seterrnotoENOSPCwhen it enters any of the out of space conditions. so like. do you want the quiet warning or the loud one. your call. π«Άprotection.protection_supportedβ this is a read-only parameter, and it's set to1if the tape drive supports protection information. that's it, that's the whole job. π¦protection.prot_methodβ if protection is supported, set this to the desired protection method supported by the tape drive. as of SSC-5r03 (available att10.org), the protection method values are:0β no protection.1β Reed-Solomon CRC, 4 bytes in length.2β CRC32C, 4 bytes in length.
protection.pi_lengthβ length of the protection information, see above for lengths. πprotection.lbp_wβ if set to1, enable logical block protection on writes. the CRC must be appended to the end of the block written to the tape driver. the tape drive will verify the CRC when it receives the block. βprotection.lbp_rβ if set to1, enable logical block protection on reads. the CRC will be appended to the end of the block read from the tape driver. the application should verify the CRC when it receives the block. πprotection.rdbpβ if set to1, enable logical block protection on theRECOVER BUFFERED DATAcommand. thesadriver does not currently use theRECOVER BUFFERED DATAcommand. so like. it's there. it's vibing. it's not being used. π
π IOCTLS π
the sa driver supports all of the ioctls of mtio(4). all of them. every single one. periodt. π
π FILES π
/dev/[n][e]sa[0-9]β general form:/dev/sa0β Rewind on close/dev/nsa0β No rewind on close/dev/esa0β Eject on close (if capable)/dev/sa0.ctlβ Control mode device (to examine state while another program is accessing the device, e.g.). π«Ά
β¨ and that's part one bestie, there's more coming, don't go anywhere β¨
π©Ί DIAGNOSTICS π©Ί
okay bestie, this part is lowkey the coolest thing ever β the sa driver can inject an End Of Media (EOM) notification, purely to help you with application development and testing. it's like a little simulator mode, and it's giving dev environment slay β¨
EOM gets indicated to your application by returning the read or write with 0 bytes written. that's the signal, that's the vibe check, that's how you know π
and there's more β when EOM is injected, the tape position status gets updated to temporarily show Beyond of the Programmable Early Warning (BPEW) status. yes, BPEW, say it with your chest π£οΈ
to actually see that BPEW status, you use the MTIOCEXTGET ioctl, which is the same one the mt status command uses. iykyk π«Ά
so to inject an EOM notification, you just set this sysctl variable to 1:
kern.cam.sa.%d.inject_eom
and here's the cute part: one EOM notification gets sent, BPEW status is set for one position query, and then the driver state resets back to normal. one and done, no leftovers, no mess, periodt π
π SEE ALSO π
go read those too bestie, they're part of the lore π
π AUTHORS π
the sa driver was written for the CAM SCSI subsystem by Justin T. Gibbs and Kenneth Merry β absolute icons, no cap π«‘
many of the ideas were gleaned from the st device driver, which was written and ported from Mach 2.5 by Julian Elischer. so basically a whole lineage of talented people, and we're all just standing on their shoulders π
the owner of record for many years was Matthew Jacob. the current maintainer is Kenneth Merry. thank you for your service, fr fr πΈ
π BUGS π
okay so, real talk, this driver lacks many of the hacks required to deal with older devices. many older SCSI-1 devices may not work properly with this driver yet. it's giving "we're working on it" energy, and that's honest π
additionally β and this is important, don't skip it β certain tapes (QIC tapes mostly) that were written under FreeBSD 2.X are not automatically read correctly with this driver. so you may need to explicitly set variable block mode, or set it to the blocksize that works best for your device, in order to read tapes written under FreeBSD 2.X. yes bestie, you have to do it manually. it's not automatic. it's giving vintage tape archaeology πΊ
and one more: partitions are only supported for status information and location. it would be nice to add support for creating and editing tape partitions, but that's not a thing right now. manifesting it for a future release tho β¨π¦
and that's the whole page, bestie!! this one came from the Debian crew, dated May 5, 2017, and it's page SA(4) of your friendly neighborhood manual set. go forth and back up your data responsibly, mwah ππ
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 1996 Julian Elischer <julian@FreeBSD.org>. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms