intro (4)
Leading comments
Copyright (c) 1996 David E. O'Brien, Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documen...
NAME
intro - introduction to devices and device driversDESCRIPTION
This section contains information related to devices, device drivers and miscellaneous hardware.The device abstraction
Device is a term used mostly for hardware-related stuff that belongs to the system, like disks, printers, or a graphics display with its keyboard. There are also so-called pseudo-devices where a device driver emulates the behaviour of a device in software without any particular underlying hardware. A typical example for the latter class is /dev/mem a loophole where the physical memory can be accessed using the regular file access semantics.The device abstraction generally provides a common set of system calls layered on top of them, which are dispatched to the corresponding device driver by the upper layers of the kernel. The set of system calls available for devices is chosen from open(2), close(2), read(2), write(2), ioctl(2), select(2), and mmap(2). Not all drivers implement all system calls, for example, calling mmap(2) on terminal devices is likely to be not useful at all.
Accessing Devices
Most of the devices in a UNIX -like operating system are accessed through so-called device nodes sometimes also called special files They are usually located under the directory /dev in the file system hierarchy (see also hier(7)).Note that this could lead to an inconsistent state, where either there are device nodes that do not have a configured driver associated with them, or there may be drivers that have successfully probed for their devices, but cannot be accessed since the corresponding device node is still missing. In the first case, any attempt to reference the device through the device node will result in an error, returned by the upper layers of the kernel, usually Er ENXIO . In the second case, the device node needs to be created before the driver and its device will be usable.
Some devices come in two flavors: block and character devices, or to use better terms, buffered and unbuffered (raw) devices. The traditional names are reflected by the letters `b' and `c' as the file type identification in the output of `ls' -l . Buffered devices are being accessed through the buffer cache of the operating system, and they are solely intended to layer a file system on top of them. They are normally implemented for disks and disk-like devices only and, for historical reasons, for tape devices.
Raw devices are available for all drivers, including those that also implement a buffered device. For the latter group of devices, the differentiation is conventionally done by prepending the letter `r' to the path name of the device node, for example /dev/rda0 denotes the raw device for the first SCSI disk, while /dev/da0 is the corresponding device node for the buffered device.
Unbuffered devices should be used for all actions that are not related to file system operations, even if the device in question is a disk device. This includes making backups of entire disk partitions, or to raw floppy disks (i.e., those used like tapes).
Access restrictions to device nodes are usually subject to the regular file permissions of the device node entry, instead of being enforced directly by the drivers in the kernel.