The linux kernel controls the hardware drivers as modules or linked-in. It's part of the UNIX philosphy that "everything is a file". Through files in /dev the kernel provides an interface for programs to access hardware.
The files in /dev are special because they are not normal files, even though they live in the filesystem. All files in the filesystem have a inode, which contains information about it: last-modified time, creation time, where the contents of the file are on the disk, so it also knows the size of the file.
The files in /dev have some of these inode attributes used for different purpose: instead of the size of the file they have numbers by which the kernel recognizes them, so it knows which driver to use when a file in /dev is accessed by some program. The kernel also uses these numbers to decide which modules to load automatically when a program reads/writes to a /dev file.
Because of this the files need to be created by the special utility "mknod". Most distributions provide a script in /dev called "MAKEDEV" that calls mknod and which is easier to use.
When you ls -l normal files, the first character on each lines indicates that the file is a directory 'd', a named pipe 'p', a regular file '-', etc. In /dev the files have 'c' for character devices and 'b' for block devices.
So they are the link between the kernel and programs for devices.
Programs refer to the hardware devices by their filename, and the kernel by numbers in the inode of the file, which would normally indicate the filesize.
There are some files in /dev that are not (directly) referring to hardware, but are handled by the kernel the same way (as devices):
/dev/zero contains infinite zero-bytes
/dev/random for infinite random bytes
/dev/tty for the current terminal
/dev/null which eats everything written to it, and is always empty
/dev/full that acts like a full disk.
Last edited by Hko; 09-17-2003 at 03:13 PM.
|