1. 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?

  2. 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 open() it with O_DIRECT, will the tape become sequentially accessible only and not randomly accessible?

  • I’ll say this again: O_DIRECT is irrelevant as far as random access is concerned. – Stephen Kitt Oct 5 '18 at 13:41
  • Thanks. I remember you said with O_DIRECT, random accessiblity is up to the device itself. So I am asking if a device is only sequentially accessible, can driver or filesystem make it look like randomlly accessibly to users? – Tim Oct 5 '18 at 13:43
  • I understand what you’re asking, I don’t understand what O_DIRECT has to do with it and why you mention it in your question. It gives the impression you think that O_DIRECT causes the tape to become sequentially accessible only. – Stephen Kitt Oct 5 '18 at 13:49
  • @StephenKitt I heard that tape is accessible only sequentially. I guess some device driver can make a tape appear randomly accessible to a user. If I open() the device file of the tape with O_DIRECT, it will bypass all or most services from the filesystem and OS (including driver), and then does it mean that the tape becomes sequentially accessible again? – Tim Oct 5 '18 at 14:19
  • O_DIRECT bypasses caches, it doesn’t bypass the driver. See my first comment. – Stephen Kitt Oct 5 '18 at 14:33

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:

  1. 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.
  2. 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.