As mentioned in Chapter 1, Unix-like operating systems are based on the notion of a file, which is just an information container structured as a sequence of bytes. According to this approach, I/O devices are treated as files; thus, the same system calls used to interact with regular files on disk can be used to directly interact with I/O devices. As an example, the same write( ) system call may be used to write data into a regular file, or to send it to a printer by writing to the /dev/lp0 device file. Let's now examine in more detail how this schema is carried out.
Device files are used to represent most of the I/O devices supported by Linux. Besides its name, each device file has three main attributes:
Either block or character (we'll discuss the difference shortly).
A number ranging from 1 to 255 that identifies the device type. Usually, all device files having the same major number and the same type share the same set of file operations, since they are handled by the same device driver.
A number that identifies a specific device among a group of devices that share the same major number.
The mknod( ) system call is used to create device files. It receives the name of the device file, its type, and the major and minor numbers as parameters. The last two parameters are merged in a 16-bit dev_t number: the eight most significant bits identify the major number, while the remaining ones ...