Add Book to My BookshelfPurchase This Book Online

Chapter 5 - Files and Directories

UNIX Systems Programming for SVR4
David A. Curry
 Copyright © 1996 O'Reilly & Associates, Inc.

Filesystem Concepts
A filesystem is the set of data types, data structures, and system calls used by an operating system to store data onto one or more disk drives. The simplest form of a filesystem, called a flat filesystem, is analogous to the “cardboard box” filing system used by some people to keep track of their bills for tax purposes. In the cardboard box method, each bill is simply tossed into a box, with more recent additions being placed on top of earlier ones. There is no sense of order within the box; mortgage bills, credit card bills, and utility bills are all intermixed in a random fashion. The only way to impose any type of order is to use multiple boxes: one for mortgage bills, one for credit card bills, and one for utility bills. A flat filesystem treats the disk like a cardboard box. Each file created in the filesystem is like a bill—it is simply created in an empty place on the disk, with no particular organization. Listing all the files is like dumping the cardboard box on the floor: system files, homework files, correspondence files, program files, and so forth are all mixed together. The only way to impose any type of order on a flat filesystem is to use multiple disks: one for system files, one for homework files, one for correspondence files, and so on.
A flat filesystem is easy to implement. It doesn't require very much computation to figure out where a file is located or where the next file should be stored. It doesn't require very much memory to keep track of the filesystem bookkeeping. In the early days of computers, both of these characteristics were very important: most systems were capable of processing tens of thousands of instructions per second, and usually had memory sizes measured in the tens or perhaps hundreds of Kbytes. Hard disks, which were very expensive, usually held a few Mbytes. Because the disks were not that large, it was not much of a problem to keep separate disks for each group of files, much like keeping separate cardboard boxes for each group of receipts.
Depending on your age, you will recognize the previous paragraph as a description of either the first personal computers of the early 1980s or the first minicomputers of the early 1970s. In either case, later systems had increased processing power, larger memories, and larger disks. This not only made more complex filesystems possible, but also necessary. As disks became larger, the number of files they could store also increased. A flat filesystem was fine for storing a few dozen (or even a hundred or so) files. But now that disks were capable of storing many thousands of files, flat filesystems became too difficult for humans to use.
The operating system designers of the day recognized this, and in response, developed a new tool called a hierarchical filesystem. A hierarchical filesystem is analogous to the “file cabinet” method of filing. In this method, each drawer of the file cabinet is used to hold a different category of files. For example, one drawer is used to store bills, another to store correspondence, and so on. Within each drawer are a number of hanging folders to futher subdivide the files: one for credit card bills, one for bank statements, one for utility bills, and so forth. Within each hanging folder, manila folders are used to further subdivide the bills; there is a folder for the gas company, a folder for the water company, and a folder for the telephone company. The hierarchical filesystem duplicates this structure by using directories to represent the file cabinet drawers and subdirectories to represent the hanging folders and manila folders. Each directory or subdirectory contains other files and subdirectories, allowing a user to organize his data to his heart's content.

Previous SectionNext Section
Books24x7.com, Inc © 2000 –  Feedback