Device node

From Wikipedia, the free encyclopedia


A device node, device file, or device special file, a type of special file, featured on many Unix-like operating systems. Device nodes make communication between user-space applications and computer hardware transparent. There are also special device files on Microsoft operating systems, such as MS-DOS and Windows.

Contents

[edit] Implementation

By definition, device nodes correspond to resources that an operating-system kernel has already allocated. Unix identified those resources by a major number and a minor number, 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 as an argument.

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.

[edit] Character devices

Character special files or character devices relate to devices through which the system transmits data one character at a time. These device nodes often serve for stream communication with devices such as teletype machines, virtual terminals, and serial modems, and usually do not support random access to data.

In most implementations, character devices use unbuffered input and output routines. The system reads each character from the device immediately or writes each character to the device immediately.

[edit] Block devices

Block special files or block devices correspond to devices through which the system moves data in the form of blocks. These device nodes often represent addressable devices such as hard disks, CD-ROM drives, or memory-regions.

Block devices often support random access and seeking, and generally 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 to read data from or to write data to the device, the system stores each character of that data in the appropriate buffer. When the buffer fills up, the appropriate operation takes place (data transfer) and the system clears the buffer.

[edit] Pseudo-devices

Device nodes on Unix-like systems do not necessarily have to correspond to physical devices. Nodes that lack this correspondence form the group of pseudo-devices. They provide various functions handled by the operating system. Some of the most commonly-used (character-based) pseudo-devices include:

/dev/null
Accepts and discards all input; produces no output.
/dev/full
Always full device.
/dev/loop
loopback disk device
/dev/zero
Produces a continuous stream of NUL (zero value) characters.
/dev/random
Produces a variable-length stream of pseudo-random characters. (Blocking)
/dev/urandom
Produces a variable-length stream of pseudo-random characters. (Non-Blocking)

[edit] Node creation

Nodes are created by the mknod system call. The command-line program for creating nodes has the same name. Nodes can be moved or deleted by the usual filesystem system calls (rename, unlink) and commands (mv, rm). When passed the option -R or -a while copying a device node, the cp command creates a new device node with the same attributes of the original.

Some Unix versions include a script named makedev to create all necessary devices in the directory /dev.

[edit] Naming conventions

The following prefixes have come into common use in Linux-based systems, to identify device nodes generically in the /dev hierarchy[1]:

For most devices, this prefix is followed by a number uniquely identifying the particular device. For hard drives, a letter is used to identify devices and is followed by a number to identify partitions. Thus a file system may "know" an area on a disk as /dev/sda3, for example, or "see" a networked terminal session as associated with /dev/pts/14.

Some Linux distributions use the SCSI layer to access all fixed disks, so that they are made accessible via sd devices even if technically they are not SCSI [1].

[edit] Some device node types

The following are device node types:

[edit] See also

[edit] Footnotes