Page 443 - DCAP103_Principle of operating system
P. 443

Principles of Operating Systems



                   Notes         characters, or bytes of data, support for random access makes little sense. One exception is the
                                 use of line disciplines. A line discipline can be associated with a terminal device, represented
                                 via the structure tty_ struct, and it represents an interpreter for the data exchanged with the
                                 terminal device. For instance, local line editing can be done (i.e., erased characters and lines
                                 can be removed), carriage returns can be mapped onto line feeds, and other special processing
                                 can be completed. However, if a process wants to interact on every character, it can put the
                                 line in raw mode, in which case the line discipline will be bypassed. Output works in a similar
                                 way, expanding tabs to spaces, converting line feeds to carriage returns + line feeds, adding
                                 filler characters following carriage returns on slow mechanical terminals, and so on. Like input,
                                 output can go through the line discipline (cooked mode) or bypass it (raw mode). Raw mode is
                                 especially useful when sending binary data to other computers over a serial line and for GUIs.
                                 Here, no conversions are desired.
                                 The interaction  with  network  devices  is  somewhat different.  While  network  devices  also
                                 produce/consume streams of characters, their asynchronous nature makes them less suitable
                                 for easy integration under the same interface as other character devices. The networking
                                 device  driver  produces  packets  consisting  of  multiple  bytes  of  data,  along  with  network
                                 headers. These packets are then routed through a series of network protocol drivers, and
                                 ultimately are passed to the user space application. A key data structure is the socket buffer
                                 structure, skbuff, which is used to represent portions of memory filled with packet data. The
                                 data in an skbuff buffer does not always start at the start of buffer. As it is being processed
                                 by various protocols in the networking stack, protocol headers may be removed, or added.
                                 The user processes interact with networking devices via sockets, which in Linux support the
                                 original BSD socket API. The protocol drivers can be bypassed and direct access to the underlying
                                 network device is enabled via raw sockets. Only superusers are allowed to create raw sockets.
                                 14.5.5 Modules in Linux

                                 For decades, UNIX device drivers have been statically linked into the kernel so they were
                                 all present in memory when the system was booted every time. Given the environment in
                                 which UNIX grew up, mostly departmental minicomputers and then high-end workstations,
                                 with their small and unchanging sets of I/O devices, this scheme worked well. Basically,
                                 a computer center built a kernel containing drivers for the I/O devices and that was it. If
                                 next year it bought a new disk, it relinked the kernel. With the arrival of Linux on the PC
                                 platform, suddenly all that changed. The number of I/O devices available on the PC is orders
                                 of magnitude larger than on any minicomputer. In addition, although all Linux users have
                                 (or can easily get) the full source code, probably the vast majority would have considerable
                                 difficulty adding a driver, updating the all device-driver related data structures, relinking
                                 the kernel, and then installing it as the bootable system (not to mention dealing with the
                                 aftermath of building a kernel that does not boot).
                                 Linux solved this problem with the concept of loadable modules. These are chunks of code that
                                 can be loaded into the kernel while the system is running. Most commonly these are character
                                 or block device drivers, but they can also be entire file systems, network protocols, performance
                                 monitoring tools, or anything else desired. When a module is loaded, several things have to
                                 happen. First, the module has to be relocated on-the-fly, during loading. Second, the system has
                                 to check to see if the resources the driver needs are available (e.g., interrupt request levels) and if
                                 so, mark them as in use. Third, any interrupt vectors that are needed must be set up. Fourth, the
                                 appropriate driver switch table has to be updated to handle the new major device type. Finally,
                                 the driver is allowed to run to perform any device-specific initialization it may need. Once
                                 all these steps are completed, the driver is fully installed, the same as any statically installed
                                 driver. Some modern UNIX systems also support loadable modules now, too.
                                 14.6 Linux File System


                                 The most visible part of any operating system, including Linux, is the file system. In the following
                                 sections we will examine the basic ideas behind the Linux file system, the system calls, and how



        436                               LOVELY PROFESSIONAL UNIVERSITY
   438   439   440   441   442   443   444   445   446   447   448