- Device file system
Unix-like operating systems, a device file system or special file system allows software to interact with a device driver using standard input/output system calls, which simplifies many tasks.
It includes "device files", "device nodes", or "device special files" which are interfaces for a
device driverthat appears in a file systemas if it were an ordinary file. There are also special device files on Microsoftoperating systems, such as MS-DOSand Windows.
Device files often provide simple interfaces to peripheral devices, such as printers. But they can also be used to access specific resources on those devices, such as disk partitions. Finally, device files are useful for accessing system resources that have no connection with any actual device such as
data sinks and random number generators. MS-DOSborrowed the concept of special files from Unix, but renamed them "device files". Because early versions of MS-DOS did not support a directory hierarchy, device files were distinguished from regular files by making their names reserved words. This means that certain file names are reserved for device files, and cannot be used to name new files or directories.The reserved names themselves are chosen to be compatible with "special files" handling of PIP command in CP/M.
There are two general kinds of device nodes in
Unix-likeoperating systems, known as "character special files" and "block special files". The difference between them lies in how data written to them and read from them is processed by the operating system and hardware. These together can be called device special files in contrast to named pipes, which are not connected to a device but are not ordinary files either.
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 driverand 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.
"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 accessto 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.
"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-ROMdrives, or memory-regions.
Block devices often support
random accessand seeking, and generally use buffered input and output routines. The operating system allocates a data bufferto 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.
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:
:Accepts and discards all input; produces no output.;
:Always full device.;
/dev/loop loopback disk device;
:Produces a continuous stream of NUL (zero value) characters.;
:Produces a variable-length stream of pseudo-random characters. (Blocking);
:Produces a variable-length stream of pseudo-random characters. (Non-Blocking)
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
-awhile 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
The following prefixes have come into common use in Linux-based systems, to identify device nodes generically in the
/devhierarchy: [Compare for example http://www.yiluda.net/manual/linux/rute/node21.html, retrieved
* hd: IDE
* lp: printers (compare lp)
* pt: pseudo-terminals (virtual terminals)
SCSIdevices 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
* tty: (physical) terminals
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
Some Linux distributions use the SCSI layer to access all fixed disks, so that they are made accessible via
sddevices even if technically they are not SCSI. [ [http://ubuntuforums.org/archive/index.php/t-518221.html IDE hard disk seen as SCSI [Archive - Ubuntu Forums ] ]
"devfs" is a specific implementation of a device file system on
Unix-likeoperating systems, used for presenting device files, an abstraction for accessing I/Oand other peripherals. The underlying mechanism of implementation may vary, depending on the OS.
Maintaining these special files on a general-purpose file system is inconvenient, and as it needs kernel assistance anyway, the idea of a special-purpose file system that is not stored on disk arose.
Also defining when devices are ready to appear is not entirely trivial. The 'devfs' approach is for the device driver to request synchronously creation and deletion of 'devfs' entries related to the devices it enables and disables, and this makes it much simpler and with easier to understand semantics than systems like udev that have complicated asynchronous notifications.
Another advantage is that unlike udev it does not require any user-space daemon, thus making for a simpler and quicker boot, it does support one to allow user-space actions on device file creation and deletion.
Some device files for DOS- and Windows-based operating systems are listed below:
* Block size
Unix file types
* http://www.atnf.csiro.au/people/rgooch/linux/docs/devfs.html - FAQ about Linux devfs
Wikimedia Foundation. 2010.