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.

218 File Structures Chapter 6descriptor (line 22). This pointer is most likely in the form of an index into the filedescriptor array. If we forbid aliasing of files, we don’t need the reference count (line10), and the directory entry for each file can include the file descriptor instead of pointingto it. That is, line 22 would read as follows.22 Descriptor : FileDescriptorType;The reference count (line 10) is maintained by the file manager so that it canreclaim the file descriptor, along with the data blocks in the file, when the last alias forthe file is removed.Multiple versions of a file require the Version field (line 21). Each version of a fileis listed separately in the directory with its own file descriptor or pointer to a file descriptor.If two versions are almost identical, space can be saved on the disk by sharing somefile blocks. Whenever the file is opened for writing, a new version can be constructedwith a new directory entry.Initially, the file descriptor for the new version is an exact copy of the one for theprevious version. Both the previous and the new version have the same Layout field (line11), so they share disk blocks. Whenever a modification is made to a block in the newversion, the entire block is copied, and the descriptor of the new version is updated toshow the location of the new block. That is, blocks of the file are split into separatecopies only when necessary. Special care is needed to avoid splitting when unnecessaryand to postpone reclaiming a disk block until all the versions that use it have beendeleted. We saw a similar copy on write strategy earlier when we were discussing segmentation.To save more disk space, a utility program can detect similarities by comparingversions on a block-by-block basis and discarding redundant blocks as they are found.This operation could be carried out whenever a version is closed. Since it is not critical,it can be performed offline, that is, whenever the opportunity arises, perhaps late at night.Line 24 in the declarations above suggests that a directory is a linear array of directoryentries. This array can be searched sequentially as long as the directory is not toolong. When a file is deleted, its slot in the array can be freed (for example, by putting aspecial value in the Descriptor field, line 22) to be used by the next file that is created. Ifdirectories are very long, as can happen with flat directories, a hashing or tree-basedtechnique may well be better for organizing the entries in the array.To allow the disk to be salvaged, it is important that file descriptors be distinguishablefrom data blocks and from free blocks. A byte at the start of each block could bereserved to indicate the nature of the block, but that would reduce the amount of spaceavailable for data in each data block. That extra byte can get in the way if the disk driverneeds to read several blocks into an extended main-store buffer. Alternatively, a regionof the disk could be reserved for file descriptors. We could call this region the descriptorarea.To promote clustering, the entire disk can be subdivided into subdisks, each composedof a number of consecutive cylinders. Each subdisk has its descriptor area. Thefiles described by those descriptors use data blocks preferably within the same region. Aseparate free-block structure would be appropriate for each subdisk.If we want file descriptors to be recognizable, it is wise to make them all the samesize no matter how large the file they represent. In that way the salvaging operation canbe sure of the location of all file descriptors. Some of the information we might store inthe file descriptor has a constant size: access rights (assuming that we divide the usersinto a fixed number of well-defined groups), creation time, time of last backup, expiration

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

Saved successfully!

Ooh no, something went wrong!