Switch Table

As with any UNIX os,device files are located in the /dev directory in the

root file system.Device files represent the user-level process "handle" into 

the device drivers that control various hardware devices on the system.The device drivers are each assigned a major number is an offset into one of two tables,known as the switch tables,that define the operations that permissible on the devices.We have 2 switch tables:

1.for character devices

2.for block devices.

As we know,it's possible to have a single device with both a character device file and a block device file associated with it,but those operations that are supported are different,and thus the code to perform those operations is also different. 

(1) br------ 2 root root 0,21 Feb 12 15:40 /dev/dsk15
crw-rw-- 2 root root 7,21 Mar 7 09:29 /dev/rdsk15

SAME device accessed through buffer cache (c) or raw (r)

The offset is the same for the two special files

The access method does not change the content of the blocks that are read,

using the character device read the transfer goes directly to the user space, whereas

using the block device there is a double copy (to the buffer cache, and from this buffer ti the user buffer).

Each device special file in Tru64 UNIX is assigned a unique 32-bit device number(dev_t in <sys/types.h>)that consists of the combination of the major and minor numbers.

Major number:for any device special file is an offset into the bloc or character switch table.This is how the os determines which driver to associate with that device.

Minor number:a driver specific number that the driver uses to find a particular device of that class.

(File system)Some file systems are used on local data storage devices;[1] others provide file access via a network protocol (for example, NFS,[2] SMB, or 9P clients). Some file systems are "virtual", in that the "files" supplied are computed on request (e.g. procfs) or are merely a mapping into a different file system used as a backing store. The file system manages access to both the content of files and the metadata about those files.

File Descriptor

In simple words, when you open a file, the operating system creates an entry to represent that file and store the information about that opened file. So if there are 100 files opened in your OS then there will be 100 entries in OS (somewhere in kernel). These entries are represented by integers like (...100, 101, 102....). This entry number is the file descriptor. So it is just an integer number that uniquely represents an opened file in operating system. If your process opens 10 files then your Process table will have 10 entries for file descriptors.

Similarly when you open a network socket, it is also represented by an integer and it is called Socket Descriptor. I hope you understand.

Hear it from the Horse's Mouth : APUE (Richard Stevens).
To the kernel, all open files are referred to by File Descriptors. A file descriptor is a non-negative number.
When we open an existing file or create a new file, the kernel returns a file descriptor to the process. The kernel maintains a table of all open file descriptors, which are in use. The allotment of file descriptors is generally sequential and they are alloted to the file as the next free file descriptor from the pool of free file descriptors. When we closes the file, the file descriptor gets freed and is available for further allotment.
See this image for more details :
Two Process

When we want to read or write a file, we identify the file with the file descriptor that was returned byopen() or create() function call, and use it as an argument to either read() or write().
It is by convention that, UNIX System shells associates the file descriptor 0 with Standard Input of a process, file descriptor 1 with Standard Output, and file desciptor 2 with Standard Error.
File descriptor ranges from 0 to OPEN_MAX.
For more information, go through 3rd chapter of APUE Book.


The BIOS (/