From Wiki-UX.info

Raw disk devices vs regular ones
Jump to: navigation, search

Raw disk devices vs regular ones

People have sometimes asked me what is the difference between regular disk devices and raw ones in HP-UX systems; as an example, take /dev/dsk/c0t0d0 (/dev/disk/disk0) and its corresponding /dev/rdsk/c0t0d0 (/dev/rdisk/disk0).

While reading The Design and Implementation of the 4.4BSD Operating System during past month, I found the explanation that applies to all UNIX implementations.

Raw devices are provided for direct access to the device they represent. On the first hand, this means that the data transferred to | from them does not pass through the system caches. On the other hand, the data is copied directly from the device driver into the user buffer, without previously passing through an intermediate kernel area.
As the kernel does not do buffering nor caching, the user must allocate buffers whose size matches the expectations of the underlying device. For example, if you were to read data from a floppy disk, your buffer's size could need to be a multiple of 512 bytes (the sector size), and all reads and writes could need to use that length for their transfers. Given this, these devices are used by programs which need direct access to devices and can't afford the consistency problems that intermediate caches could bring in (e.g., fsck(8) or newfs(8)). Note that they need deep knowledge of the underlying hardware.
As you can imagine, regular devices are the opposite of raw ones. The system has buffers to transfer data to | from them and caches this data as appropriate to avoid unnecessary requests to the device. When the user works with them, he can request data transfers of any size (which do no need to match the block size), because the system will do all necessary steps to provide him with the data he really asked for.

Reference

This page was last modified on 6 January 2009, at 16:45. This page has been accessed 1,451 times.