Device file - Wikipedia
Driver on

Device file – Wikipedia

Interface to a tool driver that seems in a file system as if it had been an unusual file; e.g. /dev/* in Unix-like methods; CON, PRN, NUL in DOS/Home windows

In Unix-like working methods, a gadget file or particular file is an interface to a tool driver that seems in a file system as if it had been an unusual file. There are additionally particular recordsdata in DOS, OS/2, and Home windows. These particular recordsdata enable an software program to work together with a tool by utilizing its gadget driver by way of customary enter/output system calls. Utilizing customary system calls simplifies many programming duties, and results in constant user-space I/O mechanisms no matter gadget options and capabilities.

Machine recordsdata normally present easy interfaces to straightforward units (reminiscent of printers and serial ports), however will also be used to entry particular distinctive sources on these units, reminiscent of disk partitions. Moreover, gadget recordsdata are helpful for accessing system sources that don’t have any reference to any precise gadget, reminiscent of information sinks and random quantity turbines.

There are two basic sorts of gadget recordsdata in Unix-like working methods, generally known as character particular recordsdata and block particular recordsdata. The distinction between them lies in how a lot information is learn and written by the working system and {hardware}. These collectively will be referred to as gadget particular recordsdata in distinction to named pipes, which aren’t linked to a tool however should not unusual recordsdata both.

MS-DOS borrowed the idea of particular recordsdata from Unix however renamed them units.[1] As a result of early variations of MS-DOS didn’t help a listing hierarchy, units had been distinguished from common recordsdata by making their names reserved phrases, chosen for a level of compatibility with CP/M.

In some Unix-like methods, most gadget recordsdata are managed as a part of a digital file system historically mounted at /dev, presumably related to a controlling daemon, which displays {hardware} addition and removing at run time, making corresponding adjustments to the gadget file system if that is not robotically accomplished by the kernel, and presumably invoking scripts in system or consumer house to deal with particular gadget wants. The FreeBSD and DragonFly BSD implementations have named the digital gadget file system devfs and the related daemon devd. Linux primarily makes use of a consumer house implementation generally known as udev, however there are a lot of variants. Darwin, and working methods reminiscent of macOS primarily based on it, have a purely kernel-based gadget file system.

In Unix methods which help chroot course of isolation, reminiscent of Solaris Containers, usually every chroot surroundings wants its personal /dev; these mount factors will probably be seen on the host OS at varied nodes within the international file system tree. By limiting the gadget nodes populated into chroot situations of /dev, {hardware} isolation will be enforced by the chroot surroundings (a program cannot meddle with {hardware} that it may well neither see nor identify—a good stronger type of entry management than Unix file system permissions).

MS-DOS managed {hardware} gadget rivalry (see TSR) by making every gadget file unique open. An software making an attempt to entry a tool already in use would uncover itself unable to open the gadget file node. A wide range of gadget driver semantics are carried out in Unix and Linux regarding concurrent entry.[2]

Unix and Unix-like methods[edit]

A simplified construction of the Linux kernel. File methods are carried out as a part of the I/O subsystem.

Machine nodes correspond to sources that an working system’s kernel has already allotted. Unix identifies these sources by a main quantity and a minor quantity,[3] each saved as a part of the construction of a node. The task of those numbers happens uniquely in numerous working methods and on completely different pc platforms. Typically, the key quantity identifies the gadget driver and the minor quantity identifies a specific gadget (presumably out of many) that the motive force controls:[4] on this case, the system might cross the minor quantity to a driver. Nevertheless, within the presence of dynamic quantity allocation, this will not be the case (e.g. on FreeBSD 5 and up).

As with different particular file sorts, the pc system accesses gadget nodes utilizing customary system calls and treats them like common pc recordsdata. Two customary kinds of gadget recordsdata exist; sadly their names are moderately counter-intuitive for historic causes, and explanations of the distinction between the 2 are sometimes incorrect in consequence.

Character units[edit]

Character particular recordsdata or character units present unbuffered, direct entry to the {hardware} gadget. They don’t essentially enable applications to learn or write single characters at a time; that’s as much as the gadget in query. The character gadget for a tough disk, for instance, will usually require that each one reads and writes be aligned to dam boundaries and most definitely is not going to enable studying a single byte.

Character units are typically generally known as uncooked units to keep away from the confusion surrounding the truth that a personality gadget for a bit of block-based {hardware} will usually require applications to learn and write aligned blocks.

Block units[edit]

Block particular recordsdata or block units present buffered entry to {hardware} units, and supply some abstraction from their specifics.[5] In contrast to character units, block units will at all times enable the programmer to learn or write a block of any measurement (together with single characters/bytes) and any alignment. The draw back is that as a result of block units are buffered, the programmer doesn’t understand how lengthy it can take earlier than written information is handed from the kernel’s buffers to the precise gadget, or certainly in what order two separate writes will arrive on the bodily gadget. Moreover, if the identical {hardware} exposes each character and block units, there’s a threat of knowledge corruption resulting from shoppers utilizing the character gadget being unaware of adjustments made within the buffers of the block gadget.

Most methods create each block and character units to symbolize {hardware} like onerous disks. FreeBSD and Linux notably don’t; the previous has eliminated help for block units,[6] whereas the latter creates solely block units. In Linux, to get a personality gadget for a disk, one should use the “uncooked” driver, although one can get the identical impact as opening a personality gadget by opening the block gadget with the Linux-specific O_DIRECT flag.


Machine nodes on Unix-like methods don’t essentially must correspond to bodily units. Nodes that lack this correspondence kind the group of pseudo-devices. They supply varied capabilities dealt with by the working system. A few of the mostly used (character-based) pseudo-devices embrace:

  • /dev/null – accepts and discards all enter written to it; supplies an end-of-file indication when learn from.
  • /dev/zero – accepts and discards all enter written to it; produces a steady stream of null characters (zero-value bytes) as output when learn from.
  • /dev/full – produces a steady stream of null characters (zero-value bytes) as output when learn from, and generates an ENOSPC (“disk full”) error when making an attempt to write down to it.
  • /dev/random – produces bytes generated by the kernel’s cryptographically safe pseudorandom quantity generator. Its precise conduct varies by implementation, and typically variants reminiscent of /dev/urandom or /dev/arandom are additionally offered.

Moreover, BSD-specific pseudo-devices with an ioctl interface might also embrace:

Node creation[edit]

Nodes are created by the mknod system name. The command-line program for creating nodes can be referred to as mknod. Nodes will be moved or deleted by the same old filesystem system calls (rename, unlink) and instructions (mv, rm).

Some Unix variations embrace a script named makedev or MAKEDEV to create all essential units within the listing /dev. It solely is smart on methods whose units are statically assigned main numbers (e.g. by way of hardcoding it of their kernel module).

Naming conventions [edit]

The next prefixes are used for the names of some units within the /dev hierarchy, to determine the kind of gadget:

Some further prefixes have come into widespread use in some working methods:

  • fb: body buffer
  • fd: (platform) floppy disks, although this similar abbreviation can be generally used to confer with file descriptor
  • hd: (“basic”) IDE driver (beforehand used for ATA onerous disk drive, ATAPI optical disc drives, and so on.)
    • hda: the grasp gadget on the primary ATA channel (normally recognized by main quantity Three and minor quantity 0)
    • hdb: the slave gadget on the primary ATA channel
    • hdc: the grasp gadget on the second ATA channel
    • hdd: the slave gadget on the second ATA channel
  • parport, pp: parallel ports
  • NVMe driver
    • nvme0: first registered gadget’s gadget controller (character gadget)
    • nvme0n1: first registered gadget’s first namespace (block gadget)
    • nvme0n1p1: first registered gadget’s first namespace’s first partition (block gadget)
  • MMC driver
    • mmcblk: storage driver for MMC Media (SD Playing cards, eMMC chips on laptops, and so on.)
      • mmcblk0: first registered gadget
      • mmcblk0p1: first registered gadget’s first partition
  • SCSI driver, additionally utilized by libATA (fashionable PATA/SATA driver), USB, IEEE 1394, and so on.
    • sd: mass-storage driver
      • sda: first registered gadget
      • sdb, sdc, and so on.: second, third, and so on. registered units
    • ses: Enclosure driver
    • sg: generic SCSI layer
    • sr: “ROM” driver (data-oriented optical disc drives; scd is only a secondary alias)
    • st: magnetic tape driver
  • tty: terminals
    • ttyS: (platform) serial port driver
    • ttyUSB: USB serial converters, modems, and so on.

The canonical listing of the prefixes utilized in Linux will be discovered within the Linux Machine Listing, the official registry of allotted gadget numbers and /dev listing nodes for the Linux working system.[8]

For many units, this prefix is adopted by a quantity uniquely figuring out the actual gadget. For onerous drives, a letter is used to determine units and is adopted by a quantity to determine partitions. Thus a file system might “know” an space on a disk as /dev/sda3, for instance, or “see” a networked terminal session as related to /dev/pts/14.

On disks utilizing the standard PC grasp boot report, the gadget numbers of major and the non-compulsory prolonged partition are numbered 1 by 4, whereas the indexes of any logical partitions are 5 and onwards, whatever the format of the previous partitions (their mother or father prolonged partition doesn’t should be the fourth partition on the disk, nor do all 4 major partitions must exist).

Machine names are normally not moveable between completely different Unix-like system variants, for instance, on some BSD methods, the IDE units are named /dev/wd0, /dev/wd1, and so on.


devfs is a selected implementation of a tool file system on Unix-like working methods, used for presenting gadget recordsdata. The underlying mechanism of implementation might differ, relying on the OS.

Sustaining these particular recordsdata on a bodily carried out file system (i.e. harddrive) is inconvenient, and because it wants kernel help anyway, the thought arose of a special-purpose logical file system that isn’t bodily saved.

Additionally, defining when units are prepared to look shouldn’t be solely trivial. The ‘devfs’ method is for the gadget driver to request creation and deletion of ‘devfs’ entries associated to the units it permits and disables.


Working System Filesystem or managing software program Commonplace mount level Creator Notes
Linux 2.3.46pre5–2.6.17 devfsd /dev Richard Gooch Applied absolutely within the kernel. Out of date – customers are inspired emigrate to udev and/or devtmpfs.
Linux 2.5– udev on any fs, however normally tmpfs /dev Greg Kroah-Hartman, Kay Sievers and Dan Stekloff Applied largely in consumer house, gadget data is gathered from sysfs. Machine recordsdata will be saved on a traditional general-purpose file system, or in a reminiscence file system (tmpfs).
Linux 2.6.32– devtmpfs with or with out udev /dev Kay Sievers, Jan Blunck, Greg Kroah-Hartman A hybrid kernel/userspace method of a tool filesystem to supply nodes earlier than udev runs for the primary time[9]
Solaris /units Solar Microsystems Launched with dynamic loaded drivers in Solaris-2.1
FreeBSD 2.0– devfs /dev Poul-Henning Kamp Applied absolutely within the kernel.
DragonFly BSD 2.3.2– devfs /dev Alex Hornung Applied absolutely within the kernel.
macOS devfs /dev Apple Inc. Applied absolutely within the kernel.
HP-UX B.11.31 devfs /dev HP Applied absolutely within the kernel.
Plan 9 # Bell Labs Applied within the kernel.
RISC OS DeviceFS Units: Acorn Computer systems DeviceFS was began in 1991[10] and first appeared in RISC OS 3. It manages a number of gadget like particular recordsdata, mostly: Parallel, Serial, FastParallel, and USB. The SystemDevices module implements the pseudo units reminiscent of: Vdu, Kbd, Null and Printer.
MS-DOS, PC DOS, DR-DOS FAT DEV (and /DEV) varied As carried out within the kernel, character units seem within the digital DEV listing and any disk listing. Beneath MS-DOS/PC DOS 2.x, the CONFIG.SYS AVAILDEV=FALSE directive can be utilized to pressure units to exist solely in DEV.
MagiC, MiNT, MultiTOS U:DEV[11][12] Utility Techniques Heidelberg, Eric R. Smith, Atari Corp. The particular U: drive incorporates a digital DEV listing, inside which one can discover gadget recordsdata.
Home windows 9x units Microsoft
Home windows NT . Microsoft The . prefix makes supporting APIs entry the Win32 gadget namespace as a substitute of the Win32 file namespace. The Win32 gadget namespace itself lives beneath Units within the NT namespace.

PC DOS, TOS, OS/2, and Home windows[edit]

A tool file is a reserved key phrase utilized in PC DOS, TOS, OS/2, and Home windows methods to permit entry to sure ports and units.

MS-DOS borrowed the idea of particular recordsdata from Unix however renamed them units.[1] As a result of early variations of MS-DOS didn’t help a listing hierarchy, units had been distinguished from common recordsdata by making their names reserved phrases. Which means sure file names had been reserved for units, and shouldn’t be used to call new recordsdata or directories.[13]
The reserved names themselves had been chosen to be appropriate with “particular recordsdata” dealing with of PIP command in CP/M. There have been two sorts of units in DOS: Block Units (used for disk drives) and Character Units (typically all different units, together with COM and PRN units).[14]

DOS makes use of gadget recordsdata for accessing printers and ports. Most variations of Home windows additionally comprise this help, which might trigger confusion when making an attempt to make recordsdata and folders of sure names, as they can not have these names.[15] Variations 2.x of MS-DOS present the AVAILDEV CONFIG.SYS parameter that, if set to FALSE, makes these particular names solely energetic if prefixed with DEV, thus permitting unusual recordsdata to be created with these names.[16]

GEMDOS, the DOS-like a part of Atari TOS, supported related gadget names to DOS, however in contrast to DOS it required a trailing “:” character (on DOS, that is non-compulsory) to determine them as units versus regular filenames (thus “CON:” would work on each DOS and TOS, however “CON” would identify an unusual file on TOS however the console gadget on DOS). In MiNT and MagiC, a particular UNIX-like unified filesystem view accessed by way of the “U:” drive letter additionally positioned gadget recordsdata in “U:DEV”.

Machine key phrase[15] Use as enter Use as output
CON Receives typed information till ^Z (Ctrl-Z) is pressed. Prints information to the console.
PRN[17] N/A Prints textual content to the printer, normally redirected to LPT1 or LST. Generally reconfigurable to different units.[18][19][20]
AUX (not in OS/2[17]) Reads information from an auxiliary gadget, normally a serial gadget like COM1. Generally reconfigurable to different units.[18][19][20] Sends information to an auxiliary gadget, normally a serial gadget like COM1. Generally reconfigurable to different units.[18][19][20]
NUL Returns null or no information. Discards acquired information.
CLOCK$ (nonetheless named CLOCK in some variations of MS-DOS 2.11[21][18][19]) N/A N/A
KEYBD$ (solely in multitasking MS-DOS) ? ?
KBD$ (solely in OS/2[17]) ? ?
SCREEN$ (solely in multitasking MS-DOS and OS/2[17]) ? ?
POINTER$ (solely in OS/2[17]) ? ?
MOUSE$ (solely in OS/2[17]) ? ?
$IDLE$ (solely in DR-DOS (since 5.0) and Multiuser DOS (since Concurrent DOS 386) households) N/A N/A
CONFIG$ (solely in MS-DOS 7.Zero and better) N/A N/A
LST (solely in 86-DOS and DOS 1.x, additionally in Hewlett-Packard’s MS-DOS 2.11 for the HP Moveable Plus[18][19]) Returns no information. Sends information to the road printer. (LPT2 for Hewlett-Packard’s MS-DOS 2.11[18][19])
PLT (solely in Hewlett-Packard’s MS-DOS 2.11 for the HP Moveable Plus[18][19]) Returns no information. Sends information to the assigned plotter. The hooked up plotter gadget is reconfigurable.[18][19]
LPT1, LPT2, LPT3, and typically LPT4 (in DR-DOS 7.02 and better and a few variations of Multiuser DOS) N/A Sends information to the chosen parallel port.
COM1, COM2, COM3, COM4 Reads information from the chosen serial port. Sends information to the chosen serial port.
82164A (solely in Hewlett-Packard’s MS-DOS 2.11 for the HP Moveable Plus[18][19]) Redirects to COM2. Redirects to COM2.

Utilizing shell redirection and pipes, information will be despatched to or acquired from a tool. For instance, typing the next will ship the file c:information.txt to the printer:

TYPE c:information.txt > PRN

PIPE, MAILSLOT, and MUP are different customary Home windows units.[22]

The 8-bit working system of Sharp pocket computer systems just like the PC-E500, PC-E500S and so on. consists of a BASIC interpreter, a DOS 2-like File Management System (FCS) implementing a rudimentary 12-bit FAT-like filesystem, and a BIOS-like Enter/Output Management System (IOCS) implementing plenty of customary character and block gadget drivers in addition to particular file units together with STDO:/SCRN: (show), STDI:/KYBD: (keyboard), COM: (serial I/O), STDL:/PRN: (printer), CAS: (cassette tape), E:/F:/G: (reminiscence file), S1:/S2:/S3: (reminiscence card), X:/Y: (floppy), SYSTM: (system), and NIL: (operate).[23]

See additionally[edit]


  1. ^ a b “Home windows for Workgroups: How VSHARE.386 Manages File Sharing”. 1999-09-22. Retrieved 2014-01-22.
  2. ^ Corbet, Jonathan; Kroah-Hartman, Greg; Rubini, Alessandro (2005). “Entry Management on a Machine File”. Linux Machine Drivers, third Version. O’Reilly. Retrieved 2017-04-28. The subsequent step past a single-open gadget is to let a single consumer open a tool in a number of processes however enable just one consumer to have the gadget open at a time.
  3. ^ Kernighan, Brian W.; Pike, Rob (1984). The UNIX Programming Setting. Prentice-Corridor. p. 66. ISBN 0-13-937681-X.
  4. ^ Neil Brown (2010-10-27). “Ghosts of Unix Previous: a historic seek for design patterns”. LWN.internet. Retrieved 2014-03-30.
  5. ^ “IEEE Std 1003.1, 2013 Version”. Retrieved 2014-04-24.
  6. ^ “FreeBSD Structure Handbook”. Retrieved 2013-03-07.
  7. ^ “usr.sbin/envstat/envstat.c”. BSD Cross Reference. NetBSD. Lay abstract.
  8. ^ Linux Assigned Names and Numbers Authority (2009-04-06). “Linux allotted units (2.6+ model)”. Linux kernel (Documentation/units.txt). Archived from the unique on 2016-04-24. Retrieved 2013-06-08.
  9. ^ “Driver Core: devtmpfs – kernel-maintained tmpfs-based /dev”. LWN. Retrieved 2009-08-10.
  10. ^ “Challenge Black change log”. Retrieved 2016-05-15.
  11. ^ “The drive U: in MagiC”. 2016-03-28. Archived from the unique on 2017-01-15. Retrieved 2017-01-09.
  12. ^ “FreeMiNT-Portal – mint.doc”. 2000-04-27. Archived from the unique on 2017-01-15. Retrieved 2017-01-09.
  13. ^ “Keep away from Creating Macintosh Filenames which might be NT Machine Names”. 2006-11-01. Retrieved 2014-01-22.
  14. ^ “gadget attributes”. Retrieved 2014-01-22.
  15. ^ a b “MS-DOS Machine Driver Names Can’t be Used As File Names”. Revision 2.0. Microsoft. 2003-05-12. KB74496, Q74496. Archived from the unique on 2012-07-21.
  16. ^ “Undocumented Instructions”. 4dos.information. Kevtronics. 2002-04-12. Retrieved 2014-05-16.
  17. ^ a b c d e f IBM Working System/2 Technical Reference – Programming Household (PDF). 1 (1st ed.). IBM. September 1987 [1986]. Archived (PDF) from the unique on 2017-01-03.
  18. ^ a b c d e f g h i Hewlett-Packard – Technical Reference Handbook – Moveable PLUS (1 ed.). Corvallis, OR, USA: Hewlett-Packard Firm, Moveable Laptop Division. August 1985. 45559-90001. Retrieved 2016-11-27.
  19. ^ a b c d e f g h i Hewlett-Packard – Technical Reference Handbook – Moveable PLUS (PDF) (2 ed.). Moveable Laptop Division, Corvallis, OR, USA: Hewlett-Packard Firm. December 1986 [August 1985]. 45559-90006. Archived (PDF) from the unique on 2016-11-28. Retrieved 2016-11-27.
  20. ^ a b c Paul, Matthias R. (1997-10-02). “Caldera OpenDOS 7.01/7.02 Replace Alpha Three IBMBIO.COM README.TXT”. Archived from the unique on 2003-10-04. Retrieved 2009-03-29.[1]
  21. ^ Paterson, Tim; Microsoft (2013-12-19) [1983]. “Microsoft DOS V1.1 and V2.0: /msdos/v20supply/SKELIO.TXT, /msdos/v20supply/HRDDRV.ASM”. Laptop Historical past Museum, Microsoft. Retrieved 2014-03-25. (Notice: Whereas the publishers declare this might be MS-DOS 1.1 and a pair of.0, it really is SCP MS-DOS 1.25 and a mix of Altos MS-DOS 2.11 and TeleVideo PC DOS 2.11.)
  22. ^ “REG: CurrentControlSet Entries PART 2: SessionManager”. 2006-11-01. Retrieved 2014-01-22.
  23. ^ Technical Reference Handbook PC-E500 (PDF). Sharp Company, Data Techniques Group, Private Tools Division. March 1990. p. 17. Archived (PDF) from the unique on 2017-03-14. Retrieved 2017-03-14.

Additional studying[edit]

Leave a Reply

Your email address will not be published. Required fields are marked *