13.07.2015 Views

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Perspective 229Each layer smooths out chunkiness created by the lower levels and produces new structures,as suggested by the Beautification Principle. In the case of files, we can start withthe atomic level, where the disk surface is composed of discrete components (iron atoms,for example). At the aggregate level, these discontinuities are evened out, and we considereach disk surface to be essentially uniform and continuous. The disk controllerintroduces structures by collecting together several platters and subdividing each intotracks, sectors, and bytes. The block layer flattens this hierarchy, leaving only an arrayof disk blocks, each composed of a fixed number of bytes. The byte layer hides diskblocks and the file-descriptor structures in order to introduce byte streams. The file layerorganizes these streams of bytes into chunks called files. Finally, directories convert alinear array of files (indexed by their descriptor numbers) into a tree structure.We can demonstrate these layers of the file manager by tracing their actions whena process executes the following program:1 procedure Example;2 var3 MyFile : FileNumber;4 begin5 MyFile := Open("/a/b",ToWrite);6 Position(MyFile,700); −− skip the first part of the file7 Write(MyFile,"testing",7); −− seven characters8 Close(MyFile);9 end Example;(1) The Open call (line 5) causes a context switch to the kernel, which calls the filelayer of the file manager to open this file.(2) The file layer needs to open / (the root directory) to find file /a, which is itselfa directory. This action involves asking the block layer to bring in the filedescriptor for /. By convention, we use descriptor 0 for this file. The file layercan calculate which disk block contains descriptor 0 by referring to the diskdescriptor, which should be kept in main store at all times. Let us pretend thatdisk block 10 is needed.(3) The block layer checks the cache of file blocks to see if block 10 is currently inmain store. If so, this layer returns immediately, passing back a pointer to wherein main store it has cached block 10. In our situation, a cache hit is very likely,because block 10 is used extremely frequently. If there is a cache miss, the blocklayer selects some cache entry to be overwritten (based, for example, on an LRUstrategy). If the entry it has chosen is dirty, it must first write out that entry.While the necessary transput is in progress, the block layer places the currentprocess on a device-wait list and queues the appropriate read (and write) requestto the lower part of the disk driver. Other processes are allowed to run until thelower part of the disk driver has finished writing, if necessary, and then readingin block 10. Then the calling process, still executing in privileged state inside theblock layer, returns to the file layer. It passes back a pointer to the main storewhere block 10 has been read into the cache. We will ignore how the block layerperforms its job from now on.(4) The file layer reads the descriptor for / from block 10. It determines that thecaller has the necessary access privileges by checking the Permissions field of thedescriptor. From here on, we will ignore all privilege checks. The file layer nowcreates a temporary open-file descriptor for /. Here is a possible format for anopen-file descriptor.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!