.TH DEV 4 .SH NAME dev \- device files in /dev .SH DESCRIPTION Device files are the eyes and ears of the system. Through the device files one has access to the disks, terminals and other parts of the machine. Single bytes or disk blocks may be transferred to or from a device with ordinary .BR read (2) or .BR write (2) calls, byte positions set with .BR lseek (2), or more complicated control functions performed with .BR ioctl(2). .PP Device files as found in .B /dev have several attributes that must be considered. Here are two examples as .B "ls \-l" shows them: .PP .RS .nf .if t .ft C brw-rw-rw- 1 root operator 2, 1 Jun 10 1995 fd1 crw--w---- 1 kjb tty 4, 0 May 11 09:41 console .if t .ft P .fi .RE .PP Most attributes are the same as for a regular file and have the same function. The file type and the major and minor device numbers are special to devices. .PP Character devices are marked with a .B c as a file type letter. Any I/O on a character device is sent down to the device driver without any interpretation. This means that a process doing the I/O must know the characteristics of the device and deal with them appropriately. .PP Block devices provoke the file system server into buffering the data on those devices. Data read or written by processes is passed through the file system block cache. Unaligned bytes read or written are extracted or reassembled by the file server from or to whole blocks in the cache. The file server transfers data to or from the device driver as blocks to positions at block size boundaries. These blocks are Minix blocks of 1024 bytes, disk devices usually have a 512 byte block size. Only block devices can be mounted as part of the file system tree if they contain a Minix file system. .PP The major device number (2 for .B fd1 and 4 for .BR console ) are used by FS to find the device driver that manages a device. The minor device number (1 for .B fd1 and 0 for .BR console ) is passed to the driver to select a device among a number of related devices that are all managed by that driver. The device drivers are usually kernel tasks under Minix, small processes that are contained within the address space of the kernel. The following tasks and associated devices exist: .SS "Memory (major 1)" The .BR ram , .BR mem , .BR kmem , .BR null , and .BR zero devices are managed by the memory task. The .B ram device is a block device for a chunk of memory that is the RAM disk. Any byte read from or written to the .B ram device is copied from or to that memory chunk. The .B mem device is a character device for the entire address space of the system, but .B kmem only for the kernel data area. These two devices allow programs like .BR ps (1) to hunt around the system looking for interesting bits. Note that .B mem accesses virtual memory as the kernel sees it, i.e. the first so-many megabytes are mapped 1 to 1 to physical memory, everything above is virtual and may read as zeros if there is no real memory behind the virtual pages. The .B null and .B zero devices are a data sink and a zero byte source respectively. Both devices happily swallow any bytes written to them. Nothing is returned on a read from .BR null , and as many zeros as requested are returned by .BR zero . .SS "Floppy disk (major 2)" The .BR fd0 , .BR fd0a , .BR fd0b , .BR fd0c , and .BR fd0d block devices are the first floppy disk and the four partitions that may exist on a that floppy disk. Likewise are .BR fd1 and .BR fd1[a\-d] the device and partitions for the second floppy disk. The floppy disk devices are described in detail in .BR fd (4). Partitioning in general is explained in .BR hd (4). .SS "Hard disk (major 3)" The first hard disk can be accessed by block device .BR hd0 . This device addresses the entire hard disk from the first to the last sector. A hard disk is normally partitioned in up to four primary partitions, .BR hd1 , .BR hd2 , .BR hd3 , and .BR hd4 . Each of these devices accesses a range of sectors on the .B hd0 device. It is customary to give each operating system on a disk a primary partition. So the MS-DOS C: "drive" can be on .BR hd1 , and Minix can be on .BR hd2 . Minix wants to have several partitions on its own, so .B hd2 can be further subdivided into the subpartitions .BR hd2a , .BR hd2b , .BR hd2c , and .BR hd2d . .B /dev contains devices for the first and second hard disk .RB ( hd0 and .BR hd5 ) their primary partitions .RB ( hd[1\-46\-9] ) and subpartitions thereof .RB ( hd[1\-46\-9][a\-d] ). More detail can be found in .BR hd (4). .SS "Console (minor 4)" The console driver manages the system console device, aptly named .BR console . Through this device one can display characters on a screen attached to a monochrome, Hercules, color, or VGA adapter. The .BR ttyc1 , .BR ttyc2 , etc. devices are the so-called "virtual consoles" that share the one console display. One can select which virtual console is to be visible on the screen and take input from the keyboard. Other devices managed by the console driver are .BR profile , a device used to profile Minix, .BR log , used by daemon processes to write log messages to the console, .BR vga and .BR kbd , used by an X11 server to get raw access to the VGA screen and keyboard, and lastly .BR kbdaux , the auxiliary keyboard device, usually a PS/2 type mouse. See also .BR console (4), and .BR tty (4). .SS "Anonymous TTY (major 5)" This is just one device named .BR tty that is a synonym for the controlling tty of a process. This device is not managed by any device driver, but is handled by FS itself. A process can get access to the terminal it is running under by using .BR /dev/tty . .SS "Line printer (major 6)" The .B lp device sends any bytes written to it to the printer. See .BR lp (4). .SS "TCP/IP (major 7)" The TCP/IP task is not a kernel task, but a separate server. It starts its life as a normal process named .BR inet , executes a few system calls to become a server like MM and FS, and then signs up with FS to manage the TCP/IP devices that happen to be assigned major 7. There is a kernel task involved in this scenario though, the ethernet boards are managed by the kernel task DP8390. (So the TCP/IP task is not completely freestanding.) See also .BR ip (4). .SS "CD-ROM (major 8)" This is the CD-ROM driver for the Mitsumi proprietary CD-ROM interface. The .BR cd0 device addresses the whole CD, with extra .BR cd[1\-4] and .BR cd[1\-4][a\-d] devices for if the CD also contains partitions with Minix file systems. .SS "Pseudo ttys (major 9)" To allow remote login the devices under major 9 offer virtual terminals. These pseudo ttys come in tty, pty pairs that form a pipe between processes running under the tty, and a controlling process attached to the pty side. See .BR tty (4). .SS "SCSI disks and tapes (major 10)" The .B sd* devices are disks in the same way as the .B hd* devices. Except that these disks are SCSI disks attached to an Adaptec 1540 controller or compatible. The driver also manages the .B rst* and .B nrst* tape devices (rewinding or non-rewinding). See .BR sd (4). .SS "Serial lines (major 11)" The serial lines can be accessed through .BR tty00 , .BR tty01 , .BR tty02 , and .BR tty03 . A serial mouse is often attached to .B tty00 with a modem on .BR tty01 , unless you put them somewhere else, but then you probably know where. See .BR tty (4). .SS "DOS virtual disk (major 12)" If one creates a really big file on an MS-DOS file system then this driver can use it as a disk. This DOS virtual disk can be accessed through .BR dosd0 , with partitions .BR dosd1 , .BR dosd2 , .BR dosd3 , and .BR dosd4 . There are no subpartitions offered by this driver. One can use a another DOS file through devices .BR dosd[5\-9] . See .BR dosd (4). .SS "Audio (major 13)" The .B audio device can be used to produce or record air vibrations using a Soundblaster 16 type audio card. See .BR audio (4). .SS "Mixer (major 14)" The .B mixer device is used to control the audio driver. .SS "Virtual disks (major 15)" The virtual disk driver can be used to concatenate any two disk devices to form one big disk. These disks are named .BR vd0 , .BR vd1 , etc. There are no partitions as it makes no sense to first concatenate disks and then to partition the result. See .BR vd (4). .SH FILES .TP 10 .B /dev/* All Minix devices .SH "SEE ALSO" .BR read (2), .BR write (2), .BR lseek (2), .BR ioctl (2), .BR console (4), .BR dosd (4), .BR fd (4), .BR hd (4), .BR ip (4), .BR lp (4), .BR sd (4), .BR tty (4), .BR vd (4), .BR MAKEDEV (8). .SH DIAGNOSTICS There are five prominent errors that processes accessing device files may provoke: .IP "ENODEV \- No such device" 5 There is no driver managing the device class this device belongs to. Either the driver is configured out, or it is not loaded (inet). .IP "ENXIO \- No such device or address" This device is not available. Either the driver does not support it at all, or the hardware isn't available, i.e. accessing the second disk on a system with only one disk. .IP "EACCES \- Permission denied" This error may cause a lot of head scratching if .B ls \-l shows a device file to be writable. The media you are trying to access is simply physically write protected! .IP "EINVAL \- Invalid argument" Devices may not like reads or writes that are not block multiples, or very big transfers, etc. The device manual page should list the limits. .IP "EIO \- I/O error" This may be a real I/O error, i.e. a read or write on the device failing due to a media error. But it may also be the result of an operation that a device can't do, or an empty tape drive, etc. .SH NOTES Some devices are not present by default. The .BR MAKEDEV script knows how to make them. .SS "MS-DOS equivalents" The names of MS-DOS devices map to Minix devices as follows: .PP .RS .nf .ta +10n +16n A: fd0 B: fd1 C: hd1, sd1 (usually the first partition) D: hd6, sd1, sd6 (or an extended partition) CON console COM1 tty00 (UNIX counts from 0) LPT1 lp .fi .RE .SH BUGS Rumours claiming that the .B zero device upsets the balance of zeros and ones in the universe are unfounded and are only vile attempts to discredit the industry. .SH AUTHOR Kees J. Bot (kjb@cs.vu.nl)