Device node
From Wikipedia, the free encyclopedia
It has been suggested that this article or section be merged with Device file. (Discuss) |
It has been suggested that this article or section be merged with Device file system. (Discuss) |
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
It has been suggested that this article or section be merged with devfs. (Discuss) |
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]:
- fd: floppy disks
- hd: IDE hard disks
- lp: printers (compare lp)
- par: parallel ports
- pt: pseudo-terminals (virtual terminals)
- s: SCSI devices in general, notably hard disks (but also SATA and USB disks)
- scd: SCSI audio-oriented optical disc drives
- sd: SCSI hard disks (also SATA or USB disks)
- sg: SCSI generic devices
- sr: SCSI data-oriented optical disc drives
- st: SCSI magnetic tapes
- tty: (physical) terminals
- ttyS: serial ports
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:
- Filesystem in Userspace (Linux, FreeBSD, NetBSD, OpenSolaris and Mac OS X)
- Network block device (Linux and GNU Hurd)
- Loop device (Linux, concept exists in other OSes with different names)
- Raw device (Linux)
[edit] See also
- Block size
- Blocking
- Buffer
- File system
- Hardware abstraction
- Special files
- User space
- Unix file types
- udev
[edit] Footnotes
- ^ Compare for example http://www.yiluda.net/manual/linux/rute/node21.html, retrieved 2007-09-04