A classical Unix tape gotcha

November 24, 2006

Here's a classical Unix tape gotcha:

mt -f /dev/st0 fsf 5

If you're lucky when you make this mistake, you were fsf'ing the tape to read from it, and it is merely embarrassing and time-wasting.

The difference between normal and no-rewind tape devices is that one rewinds the tape when you use it and the other doesn't. More precisely, the tape is rewound when the tape device is closed for the last time (usually as the device is closed; the close() system call won't return until the tape has completed rewinding, which can lead to surprising lurching pauses in programs).

The gotcha is that many people expect the tape device only to be opened when you're reading or writing actual data to the tape. But on Unix, just getting the tape's status or sending it commands like fsf also means opening and closing the tape device, and thus having the rewind go off.

Life would be a lot simpler if the auto-rewind tape devices just didn't exist, or failing that at least were not the default devices and took an extra letter to use ('/dev/rst0' or something). But by now we are stuck with the situation in the name of tradition.

(So the safe thing to do is never actually use the auto-rewind names, even if you want to rewind the tape and they're a letter shorter. Suck it up, use the nst0 versions, and rewind the tape with an explicit command.)

Written on 24 November 2006.
« Why I don't file bug reports very often
The quest for a nice Linux CD player application »

Page tools: View Source, Add Comment.
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Fri Nov 24 22:56:25 2006
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.