Writing to tape from C system calls
A message that is not in the archive (sent off-list or not yet received): 033701c3c0ac$97659270$aa00a8c0@ASTERIX
Hi
I'm new to tape devices.
My application requires me to seek to a certain block on the tape device and write data on it (besides being able to retrieve data by reading).
So far, I have no trouble reading from the tape.
When I write to it at any block that block becomes the last block on the device. I am unable to seek to any block after that on the tape. I have tried :
a. Using mt to seek and dd to write
b. Using open / ioctl / write from C
Both with the same results. I am using a Tandberg SDLT for my tests with the linux kernel st drivers.
Is this normal? Is it not possible to use the tape device - and modify data at any block by seeking to it and writing?
Is there some source of information where I can read about programming tape devices from C? So far, I havent been able to find one.
Please advise.
Regards,
Ujval Lodha
Quoted 6 lines
When I write to it at any block that block becomes the last block on the device. I am unable to seek to any block after that on the tape.
Is this normal? Is it not possible to use the tape device - and modify data at any block by seeking to it and writing?
It is completely normal. All modern tape drives work this way. Unlike a disk drive, a block address on tape does not correspond to a predefined location on the medium. The tape drive (re)formats the medium while it writes, which invalidates anything past the last written point on tape. So, you can seek/read/write the tape from the beginning of the tape up to just after the last written block, but the tape medium after that point is not considered to be formatted and cannot be used (again) until it is reached while writing.
As you observed, writing to tape in the middle of valid data will cause the contents of the tape to be truncated at the write point. That's the way the technology works. There is no way to update a block in the middle of the valid data without losing everything that comes after it. The only way around this is to use multiple partitions, but not all tape drives support partitions, and changing partitions takes time.
Quoted 3 lines
Is there some source of information where I can read about programming tape devices from C? So far, I havent been able to find one.
man st
But that's pretty low-level, of course.
Anthony J. Battersby
Cybernetics
Thanks for your reply. That clears up my understanding.
I've already read the man page. That is how I got so far, in fact. It seems to require some understanding of the functionality of tape drives. The description of some of the options seems very cryptic to me - as I dont know much of the jargon associated with tape drives. Any material that would help understand tape devices and tape as a medium - filemarks, setmarks, and the order of operations one is expected to perform.
Also, I wonder if it absolutely not possible to use the tape in the manner I intended. I am using the tape without compression - and I dont mind making 'sub-optimal' use of the capacity of the tape.
Thanks again.
Regards,
Ujval
----- Original Message -----
From: "Tony Battersby" <[email protected]>
To: "'Ujval Lodha'" <[email protected]>; <[email protected]>
Sent: Friday, December 12, 2003 11:14 PM
Subject: RE: Writing to tape from C system calls
Quoted 34 lines
Quoted 6 lines
When I write to it at any block that block becomes the last block on the device. I am unable to seek to any block after that on the tape.
Is this normal? Is it not possible to use the tape device - and modify data at any block by seeking to it and writing?
It is completely normal. All modern tape drives work this way. Unlike a disk drive, a block address on tape does not correspond to a predefined location on the medium. The tape drive (re)formats the medium while it writes, which invalidates anything past the last written point on tape. So, you can seek/read/write the tape from the beginning of the tape up to just after the last written block, but the tape medium after that point is not considered to be formatted and cannot be used (again) until it is reached while writing.
As you observed, writing to tape in the middle of valid data will cause the contents of the tape to be truncated at the write point. That's the way the technology works. There is no way to update a block in the middle of the valid data without losing everything that comes after it. The only way around this is to use multiple partitions, but not all tape drives support partitions, and changing partitions takes time.
Quoted 3 lines
Is there some source of information where I can read about programming tape devices from C? So far, I havent been able to find one.
man st
But that's pretty low-level, of course.
Anthony J. Battersby
Cybernetics
Quoted 3 lines
Any material that would help understand tape devices and tape as a medium - filemarks, setmarks, and the order of operations one is expected to perform.
Try the "SCSI-3 Stream Commands (SSC)" and "SCSI Stream Commands - 2 (SSC-2)" specifications available at http://www.t10.org/drafts.htm.
They give a nice general overview of tape technology in the opening section.
Anthony J. Battersby
Cybernetics