If a device offers only sequential access not random access, can a device driver or a file system make the device look like randomly accessible to users?
If yes, is this done by providing buffer/cache to the device?
For example, here is what I heard but not sure if correct:
rewind-only tape offers only sequential access
for such a tape device, any movement backward from the current position might require rewinding the tape to the beginning and then moving forward
What makes such a tape randomly accessible: changing the device itself at device/hardware level, a device driver of the tape, or something else?
Given such a tape made randomly accessible , if I
O_DIRECT, will the tape become sequentially accessible only and not randomly accessible?
If the device can move back and forth without external intervention, then yes, you could make a device driver make it appear to be random access. You could do that in a few ways:
- If the device is small with respect to the amount of main memory available, you could mirror the content of the device in memory where random access possible.
- If the device is too big to store in main memory, you could page it -- basically do (1) but on segments of the underlying content. Any read/write to a page not currently in memory would be extremely slow because the "old" page would need to get flushed and the new page would need to be read into memory.
Any writes would eventually need to be flushed back to the underlying media. That'd likely be an extremely slow process, and would raise questions like "does the media support partials updates" (i.e., can the OS overwrite only the data that was updated, or does it need to re-write the entire media)?
All that said, it being "doable" doesn't make it a good idea. You're confined to the behavior of the hardware. If it doesn't provide true random access, faking it will be very slow.