Device node
From Wikipedia, the free encyclopedia
A device node, device file, or device special file is a type of special file used on many Unix-like operating systems. Device nodes facilitate transparent communication between user space applications and computer hardware. There also exist special device files on DOS variants, most notably MS-DOS.
Contents |
[edit] Implementation
By definition, device nodes correspond to resources that have already been allocated by the operating system kernel. The resources are identified by a major number and a minor number, which are stored as part of the structure of a node. The assignment of these numbers is specific to different operating systems and 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, and is passed to the driver as an argument.
Like other special file types, device nodes are accessed using standard system calls and treated like regular files. There are two standard types of device files, differentiated by the type of hardware with which they are designed to interface and the way the operating system processes input and output operations.
[edit] Character devices
Character special files or character devices are used to correspond to devices through which data is transmitted one character at a time. These device nodes are often used for serial communications devices such as teletype machines, virtual terminals, and serial modems.
In most implementations, character devices use unbuffered input and output routines. Each character is read from, or written to, the device immediately.
[edit] Block devices
Block special files or block devices are used to correspond to devices through which data is transmitted in the form of blocks. These device nodes are often used for parallel communications devices such as hard disks and CD-ROM drives.
The most significant difference between block and character devices is that block devices use buffered input and output routines. The operating system allocates a data buffer to hold a single block each for input and output. When a program sends a request for data to be read from, or written to, the device, each character of that data is stored in the appropriate buffer. When the buffer is full and a complete block is achieved, the appropriate operation is performed and the buffer is cleared.
[edit] Pseudo-devices
Device nodes on Unix-like systems do not necessarily have to correspond to physical devices. Nodes that lack this correspondence are known as pseudo-devices. They are used for various functions that are handled by the operating system. The following are some of the most commonly-used pseudo-devices:
- /dev/null
- Accepts and discards all input; produces no output.
- /dev/random
- Produces a variable-length stream of pseudo-random characters.
- /dev/zero
- Produces a continuous stream of null (zero value) characters.