Files as a Universal Interface

Unix is based on just a few judiciously selected paradigms. A very important "metaphor" threads its way through the kernel (and particularly through the VFS), particularly with regard to the implementation of input and output mechanisms.

Everything is a file.

OK, let's admit it: There are, of course, a few exceptions to this rule (e.g., network devices), but most functions exported by the kernel and employed by user programs can be reached via the file interface defined by the VFS. The following is a selection of kernel subsystems that use files as their central means of communication:

□ Character and block devices

□ Pipes between processes

2Communication with files is carried out not only by means of file descriptors but also with the help of streams. The latter provide a convenient interface. They are, however, implemented in the C standard library and not in the kernel. Internally they make use of normal file descriptors.

□ Sockets for all network protocols

□ Terminals for interactive input and output

Note that some of the objects are not necessarily linked with an entry in a filesystem. Pipes, for instance, are generated by special system calls and then managed by the kernel in the data structures of the VFS without having a ''real'' filesystem entry that can be accessed with typical commands such as rm, ls, and so on.3

Of particular interest (above all, in the context of Chapter 6) are device files to access block and character devices. These are real files that typically reside in the /dev directory. Their contents are generated dynamically by the associated device driver when a read or write operation is performed.

Continue reading here: File Representation

Was this article helpful?

0 0