Wandering Thoughts archives

2006-11-24

A classical Unix tape gotcha

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.)

sysadmin/TapeRewindGotcha written at 22:56:25; Add Comment


Page tools: See As Normal.
Search:
Login: Password:
Atom Syndication: Recent Pages, Recent Comments.

This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.