Special Files

A special file is a file that has no associated storage but can be used to gain access to a device. The goal here is to be able to access a device using the same mechanisms by which regular files and directories can be accessed. Thus, callers are able to invoke open(), read(), and write() in the same way that these system calls can be used on regular files.

One noticeable difference between special files and other file types can be seen by issuing an ls command as follows:

$ ls -l /dev/vx/*dsk/homedg/h
brw------  1 root  root  142,4002 Jun 5  1999  /dev/vx/dsk/homedg/h
crw------  1 root  root  142,4002 Dec 5  21:48 /dev/vx/rdsk/homedg/h

In this example there are two device files denoted by the b and c as the first character displayed on each line. This letter indicates the type of device that this file represents. Block devices are represented by the letter b while character devices are represented by the letter c. For block devices, data is accessed in fixed-size blocks while for character devices data can be accessed in multiple different sized blocks ranging from a single character upwards.

Device special files are created with the mknod command as follows:

mknod name b major minor
mknod name c major minor

For example, to create the above two files, execute the following commands:

# mknod /dev/vx/dsk/homedg/h b 142 4002
# mknod /dev/vx/rdsk/homedg/h c 142 4002

The major number is used to point to the device driver that controls the device, while the minor number is ...

Get UNIX Filesystems: Evolution, Design, and Implementation now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.