- Device file system
In
Unix-like operating systems , a device file system or special file system allows software to interact with a device driver using standardinput/output system call s, which simplifies many tasks.It includes "device files", "device nodes", or "device special files" which are interfaces for a
device driver that appears in afile system as if it were an ordinary file. There are also special device files onMicrosoft operating systems, such asMS-DOS and 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 sink s andrandom number generator s.MS-DOS borrowed 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 namesreserved word s. 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 inCP/M .There are two general kinds of device nodes in
Unix-like operating 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 tonamed pipe s, which are not connected to a device but are not ordinary files either.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 system s and on differentcomputer platform s. Generally, the major number identifies thedevice 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 call s and treats them like regularcomputer file s. 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.Devices
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 machine s,virtual terminal s, and serial modems, and usually do not supportrandom 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.
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 disk s,CD-ROM drives, or memory-regions.Block devices often support
random access andseeking , and generally use buffered input and output routines. The operating system allocates adata 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.Pseudo-devices
Device nodes on Unix-like systems do not necessarily have to correspond to
physical device s. 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.;/dev/null
:Always full device.;/dev/full
:/dev/loop loopback disk device ;
:Produces a continuous stream of NUL (zero value) characters.;/dev/zero
:Produces a variable-length stream of pseudo-random characters. (Blocking);/dev/random
:Produces a variable-length stream of pseudo-random characters. (Non-Blocking)/dev/urandom 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
.Naming conventions
The following prefixes have come into common use in Linux-based systems, to identify device nodes generically in the
/dev
hierarchy: [Compare for example http://www.yiluda.net/manual/linux/rute/node21.html, retrieved2007-09-04 ]
* fd:floppy disk s
* hd: IDEhard disk s
* lp: printers (compare lp)
* par:parallel port s
* pt: pseudo-terminals (virtual terminals)
* s:SCSI devices in general, notably hard disks (but also SATA and USB disks)
** scd: SCSI audio-orientedoptical disc drive s
** sd: SCSI hard disks (also SATA or USB disks)
** sg: SCSI generic devices
** sr: SCSI data-oriented optical disc drives
** st: SCSImagnetic tape s
* tty: (physical) terminals
** ttyS:serial port sFor 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. [ [http://ubuntuforums.org/archive/index.php/t-518221.html IDE hard disk seen as SCSI [Archive - Ubuntu Forums ] ]devfs
"devfs" is a specific implementation of a device file system on
Unix-like operating systems, used for presentingdevice file s, an abstraction for accessingI/O and otherperipherals . 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.
Implementations
Device files
Some device files for DOS- and Windows-based operating systems are listed below:
Further reading
*
*
*
*
*
*
*
*
*
*
*ee also
*
Sysfs
* Block size
* Blocking
* Buffer
*File system
*Hardware abstraction
*User space
*Unix file types
*udev References
External links
* http://www.atnf.csiro.au/people/rgooch/linux/docs/devfs.html - FAQ about Linux devfs
Wikimedia Foundation. 2010.