Device File - Implementation

Implementation

By definition, device nodes correspond to resources that an operating-system kernel has already allocated. Unix identifies those resources by a major number and a minor number (e.g. where the major and minor number of /dev/urandom is 1 and 9 respectively which may be ascertained using stat /dev/urandom, see mknod), both stored as part of the structure of a node. The assignment of these numbers occurs uniquely in different operating systems and on different computer platforms. Generally, the major number identifies the device driver and the minor number identifies a particular device (possibly out of many) that the driver controls: in this case, the system may pass the minor number to a driver. However, in the presence of dynamic number allocation, this may not be the case (e.g. on FreeBSD 5 and up).

As with other special file types, the computer system accesses device nodes using standard system calls and treats them like regular computer files. Two standard types of device files exist, differentiated by the type of hardware with which they interface and the way the operating system processes input and output operations: character devices and block devices.

Read more about this topic:  Device File