Block and character special files

What is the difference in semantics between block and character special files on Mac OS X?

In the olden days, character special files were intended for serial character-oriented devices such as teletypes, printers, modems etc. not capable of seeking and block special files were intended for seekable block-oriented devices such as winchester disks etc.

But nowadays, Apple uses /dev/rdisk* as the raw (unbuffered) hard disk device, and it is a character special file, and it is seekable. /dev/disk* on the other hand, is buffered, slower, and a block character special file.

Is there still any semantic difference at any O.S. level between these two kinds of special files, or is it all entirely up to the driver designer and it only effectively provides us with one more bit for the device number?

iBook G4, Mac OS X (10.4.10)

Posted on Nov 14, 2007 7:45 AM

Reply
4 replies

Nov 14, 2007 10:05 AM in response to Dr. T

Hi,

Is there still any semantic difference at any O.S. level between these two kinds of special files


As you write, a block device is bufferd by OS, while a character device is not bufferd by OS (=raw device).

In the olden days, character special files were intended for serial character-oriented devices


Even in olden days, I guess a seekable mass storage had both block and character devices; the latter is for partitioning, disk diagnose, backup, etc. Only block devices can be mounted.

Serial (un-seekable) device can only be a character device, I guess.

Nov 14, 2007 10:58 AM in response to Dr. T

Excellent, thank you. So to sum it up, block special files +have to be+ seek capable, whereas character special files may be seek capable, and I/O to block special files is buffered by the OS but I/O to character special files is not.

That seems clear enough.

Is there anywhere where these things are documented, and where (in kernel sources etc.) might one look for the differences in the handling of the two? I'm assuming you can control the buffering of block special files?

Nov 14, 2007 11:16 AM in response to Dr. T

I'd also be interested. For example, sometimes I would like to be able to mount the joliet partition of a hybrid cd to access files that are not included on the hfs partition. My optical drive is /dev/disk1, its media is /dev/disk1s1, then I think disk1s1s1 and disk1s1s2 are file systems. Does /dev/disk1s1s2 represent the joliet file system? I'd love to have a better understanding of these devices.

--
Cole

Nov 15, 2007 4:02 AM in response to Dr. T

I don't know any detail about Darwin kernel. You may get better answer in dawrin-dev or darwin-kernel mailig list. For example,
http://lists.apple.com/archives/Darwin-kernel/2006/Jul/msg00030.html
As mentioned in this thread, it seems buffering can be disabled for a specific open file by using F_NOCACHE command in fcntl(2). (I guess there is no way to control the buffering of whole the mounted disk.) F_RDAHEAD command would also be of interest.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Block and character special files

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.