Device file system
From Wikipedia, the free encyclopedia
| This article needs additional citations for verification. Please help improve this article by adding reliable references. Unsourced material may be challenged and removed. (June 2008) |
In 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 driver that appears in a file system as if it were an ordinary file. There are also special device files on Microsoft operating systems, such as MS-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 sinks and random number generators.
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 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-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 to named pipes, which are not connected to a device but are not ordinary files either.
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] Devices
[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 (random in Linux) 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 (see also /dev/hda)
- 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.[2]
[edit] devfs
devfs is a specific implementation of a device file system on Unix-like operating systems, used for presenting device files, an abstraction for accessing I/O and 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.
[edit] Implementations
| Operating System | Device file system | Standard mount-point | Author | Notes |
|---|---|---|---|---|
| Linux 2.4–2.6.18 | devfs | /dev | Richard Gooch | Implemented fully in the kernel. DEPRECATED: Users are encouraged to migrate to udev. |
| Linux 2.6.15– | udev | /dev | Greg Kroah-Hartman, Kay Sievers and Dan Stekloff | Implemented largely in user space, device information is gathered from sysfs. Device files can be stored on a conventional general-purpose file system, or in a memory file system (tmpfs). |
| Solaris | devfs | /devices | Sun Microsystems | |
| FreeBSD 2.0– | devfs | /dev | ? | Implemented fully in the kernel. |
| Mac OS X | devfs | /dev | ? | Implemented fully in the kernel. |
| Plan 9 | # | ? | Implemented in kernel. Can not be mounted elsewhere or unmounted. |
[edit] Device files
Some device files for DOS- and Windows-based operating systems are listed below:
| File name | Purpose |
|---|---|
| CON | Console device |
| PRN | Printer |
| AUX | Auxiliary device |
| COM0 COM1 COM2 COM3 COM4 COM5 COM6 COM7 COM8 COM9 | Serial ports |
| LPT0 LPT1 LPT2 LPT3 LPT4 LPT5 LPT6 LPT7 LPT8 LPT9 | Parallel ports |
| NUL | Bit bucket |
[edit] Further reading
- Philip Streck (2002-09-24). "devfs for Management and Administration", Linux Journal.
- Daniel Robbins (2001-10-01). "Part 4: Introduction to devfs". Common threads: Advanced filesystem implementor's guide. IBM.
- Daniel Robbins (2001-10-01). "Part 5: Setting up devfs". Common threads: Advanced filesystem implementor's guide. IBM.
- Daniel Robbins (2001-10-01). "Part 6: Implementing devfs (using the init wrapper)". Common threads: Advanced filesystem implementor's guide. IBM.
- Doug Gilbert (2001-01-22). "DEVFS and SCSI".
- "3.3. Device Names in devfs". The Linux 2.4 SCSI subsystem HOWTO: Chapter 3. Names and Addresses. Linux Documentation Project.
- "Device File System Guide". Gentoo Linux Documentation. Gentoo Foundation, Inc..
- Mark Ellis (2003-09-23). "How to use kernel module autoloading with devfs and devfsd". Linux From Scratch Hints.
- Martial Daumas (2003-09-18). "How to create a basic mk_initrd command that works nice with LFS and devfs". Linux From Scratch Hints.
- Jeroen Coumans (2003-04-19). "How to setup devfs with your current LFS-configuration using devfsd. How you can use devfs from scratch.". Linux From Scratch Hints.
- Tushar Teredesai (2003-03-05). "Using devfs and devfsd". Linux From Scratch Hints.
[edit] See also
[edit] References
- ^ Compare for example http://www.yiluda.net/manual/linux/rute/node21.html, retrieved 2007-09-04
- ^ IDE hard disk seen as SCSI [Archive] - Ubuntu Forums
[edit] External links
- http://www.atnf.csiro.au/people/rgooch/linux/docs/devfs.html - FAQ about Linux devfs

