Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 8: The Virtual Filesystem


Most pointer names reveal the task that they perform(there are also many identically named system calls
that invoke the corresponding function in a more direct way).

❑ readandwriteread and write data — How could it be otherwise? They make use of the file
descriptor, a buffer (in which the Read/Write data reside) and an offset to specify the position
within the file. A further pointer indicates the number of bytes to be read or written.
❑ aio_readis used for asynchronous read operations.
❑ openopens a file; this corresponds to associating afileobject with an inode.
❑ releaseis invoked when the usage counter of afileobject reaches 0; in other words, when
no one is using the file. This allows low-level implementations to release memory and cache
contents no longer needed.
❑ Files can be accessed very easily if their contents are mapped into the virtual address space of a
process. This is done bymmap, whose mode of operation is discussed in Chapter 3.
❑ readdirreads the contents of directories and is therefore only available for objects of this type.
❑ ioctlis used to communicate with hardware devices and can therefore only be applied to
device files (not to other objects because these contain a null pointer). This method is used when
it is necessary to send control commands to a device (thewritefunction is used to send data).
Even though the function has the same name and the same call syntax for all peripherals, the
actual commands differ depending on the hardware-specific situation.
❑ pollis used with thepollandselectsystem calls needed to implement synchronous I/O mul-
tiplexing. What does this mean? Thereadfunction is used when a process is waiting for input
data from a file object. If no data are available (this may be the case when the process is read-
ing from an external interface), the call blocks until data become available. This could result
in unacceptable situations if there are no more data to be read and thereadfunction blocks
forever.
Theselectsystem call, which is also based on thepollmethod, comes to the rescue. It sets a
time-out to abort a read operation after a certain period during which no new data arrive. This
ensures that program flow is resumed if no further data are available.
❑ flushis invoked when a file descriptor is closed, which goes hand in hand with decrementing a
usage counter — this time the counter need not be 0 (as withrelease). This function is required
by network filesystems to conclude transmissions.
❑ fsyncis used by thefsyncandfdatasyncsystem calls to initiate synchronization of file data in
memory with that on a storage medium.
❑ fasyncis needed to enable and disable signal-controlled input and output (processes are notified
of changes in the file object by means of signals).
❑ readvandwritevare used in the implementation of the system calls of the same name for read-
ing and writing vectors.Vectorsare basically structures that provide a non-contiguous memory
area to hold results or initial data. This technique is known asfast scatter-gather.Itisusedtodis-
pense with the need for multiplereadandwritecalls that would impair performance.
❑ Thelockfunction enables files to be locked. It synchronizes concurrent file access by several
processes.
❑ revalidateis used by network filesystems to ensure consistency of remote data after a media
change.
Free download pdf