-2

Operating System Concepts says:

Devices vary on many dimensions, as illustrated in Figure 13.7.

• Character-stream or block. A character-stream device transfers bytes one by one, whereas a block device transfers a block of bytes as a unit.

• Sequential or random access. A sequential device transfers data in a fixed order determined by the device, whereas the user of a random-access device can instruct the device to seek to any of the available data storage locations

enter image description here

Does block device imply random access?

Does random access imply block device?

Does character device imply sequential access?

Does sequential access imply character device?

Thanks.

Tim
  • 101,790
  • Block devices are seekable, which means random access from the point of view of the user. The actual implementation may be sequential, for example some tape device where any movement backward from the current position might require rewinding the tape to the beginning and then moving forward. A character device may or may not be seekable. – Mark Plotnick Oct 02 '18 at 16:40
  • @MarkPlotnick Thanks. Do you mean that a user of a device should notice the difference between block and character devices, but not the difference between sequential and random access? – Tim Oct 02 '18 at 16:47
  • @Mark Will a user of linux or programmer of Linux API notice the difference between block and character devices, but not the difference between sequential and random access? – Tim Oct 02 '18 at 17:20
  • Block and character devices overlap in only a few areas - tapes and disks - and the only real visible difference is that block devices use the buffer cache and character devices don't. (And some block device drivers may offer the option of bypassing the buffer cache on a per-file basis). A user/programmer may or may not notice that a device is random access or sequential. It's up to the driver to either hide or expose the device's seekability. – Mark Plotnick Oct 02 '18 at 17:55
  • @Mark Thanks. "Block devices are seekable, which means random access from the point of view of the user. The actual implementation may be sequential," Is it correct that block/character device is at a higher level than sequential/random access? If a user can notice sequential/random access of a device, then he can also see whether the device is block/character device? But not the other way around? – Tim Oct 02 '18 at 17:58
  • Yes, they're at different levels. As for your second and third questions, you can't always infer the type of a device driver from the characteristics of the device, but I've never seen an Ethernet or a serial terminal device with anything but a character driver. – Mark Plotnick Oct 02 '18 at 18:09
  • @Mark Thanks. "the only real visible difference is that block devices use the buffer cache and character devices don't. (And some block device drivers may offer the option of bypassing the buffer cache on a per-file basis)." Is the buffer cache used by block devices provided by file systems, or by hardware (either the device or device controller)? – Tim Oct 04 '18 at 03:18
  • The buffer cache is just a set of structures and buffers provided by the kernel and is in-memory. It used to be independent of any filesystem, but it's possible that there is filesystem-specific code in it nowadays; I don't know. – Mark Plotnick Oct 04 '18 at 14:32
  • @Mark Since the buffer cache for a block device is not provided by the device itself, is a device being block or character device determined not purely by the device itself, but by OS which uses it? https://unix.stackexchange.com/questions/473230/is-a-device-being-a-block-or-character-device-determined-purely-by-hardware – Tim Oct 04 '18 at 14:54
  • The choice of whether a device is character or block is made by the programmer who writes the driver. Some hardware devices (such as disks on older versions of Unix) have both block and character device drivers available. Users can choose to access /dev/dsk/c0t0d0s0 or /dev/rdsk/c0t0d0s0. – Mark Plotnick Oct 04 '18 at 17:00

1 Answers1

2

Does block device imply random access?

No, e.g. rewind-only tape with block structure.

Does random access imply block device?

No, though I can't think of an existing character-stream device with random access. But SSDs and Flash-ROMs in general allow character-specific reading and writing, though only block-specific erasing (which shows that devices can vary in even more dimensions).

Does character device imply sequential access?

That's equivalent to the second implication (by contraposition).

Does sequential access imply character device?

This is equivalent to the first implication.

dirkt
  • 32,309