Concepts with Symbian OS (779878), страница 37
Текст из файла (страница 37)
Then we coverseveral different file-system implementations.A Generic ViewIt is useful to review the components of a file system and the ways thatwe use those components to build the file-system abstraction. There aresome assumptions we make about file systems and some file and directory176FILE SYSTEMS AND STORAGEApplicationsLogical file systemLogical-to-physical translatorFile systemDevice driversHardware storage deviceFigure 8.2 Generic file-system implementation layerscomponents that we can describe so that we can better discuss specificimplementations later.The file-system abstraction is built up in layers.
Each layer adds somefunctionality and represents an area for implementation. Consider thediagram in Figure 8.2 as a depiction of the layers of a file system.Storage devicesAt the lowest layer lies the storage device. Physical storage can be viewedas a linear sequence of bits or bytes, usually organized into larger unitscalled blocks. Blocks are typically the unit of transfer between a storagedevice and the operating system. There are many different types of storagedevice that are supported by operating systems and each communicatesin a different way.
The I/O-interface controller communicates effectivelywith the bus to which it is connected, but it also has its own commandinterface.IMPLEMENTATION OF A FILE SYSTEM177Storage devices, like memory, give addresses to their data space.For some devices, addresses can be as simple as block number. Forthese devices, a read request must be accompanied by a single number,indicating the block to read. Other devices can have a more complicatedaddressing method. Hard disk drives, for example, are usually organizedin three dimensions.
Disks are made of concentric rings of magneticmedia; one of these rings is called a track. Tracks are usually divided intosmaller storage portions called sectors. Cylinders are formed by mappingthe same track of each disk platter vertically. A read request for a hard diskdrive, then, must be accompanied by three numbers: cylinder, track andsector. Some file-system implementations group several sectors into onesingle logical unit called a cluster, so a request to read data from a diskcan address only a cluster, but not an individual sector.
This techniqueallows manipulation of the size of the smallest addressable storage blockon big storage devices.By virtue of their size and their functionality, smartphones have somespecific requirements when it comes to storage media. These devices allcome with onboard flash memory, which is used by the operating systemas operating memory and by users to store files. Other storage is eitherbuilt-in or removable; built-in secondary storage usually takes the form ofa hard disk drive and removable storage is usually a form of flash memoryin a small form factor.
Flash memory can be accessed faster, but wearsout more quickly; hard-disk space can be greater.Device driversThe level above physical hardware is the device-driver level. Devicedrivers act as translators. They communicate with both the operatingsystem and the storage device, translating operating system requests intothe command interface of the storage device. In addition, device driversinclude interrupt handlers that implement various methods of readingfrom the device – from real-time, byte-level access to direct-memoryaccess. Device drivers can access the hardware of both the storagemedium and the computer’s CPU to transfer data and commands.File systemsThe next level is the file-system layer.
This layer implements the basicsof a file system. It knows hardware information such as block sizes onstorage media but it also knows the logical addressing system used byupper layers. This layer receives logical addresses and translates into the178FILE SYSTEMS AND STORAGEphysical addresses of the storage medium. This layer usually tracks thefree-space on a storage medium and runs space management algorithms.This layer will implement file system management methods that aregeneric enough to be used by any higher-level implementation.Logical file systemsThe logical file-system layer implements specific types of file systems.Concepts such as security, access control, and file typing are different fromfile system to file system and these implementations would be built on topof a generic file system.
Implementations from this layer provide the APIsfor operations common to files: opening, reading, writing, closing, etc.This layer keeps track of files via a file table that uses file control blocks(FCBs) as entries. Like process control blocks, FCBs record informationabout files in use. The information recorded in an FCB is dependent onthe file-system implementation.ApplicationsApplications interface with the logical file system either through theAPIs provided by it or by communicating with file servers.
Even whenapplications need raw, byte-level access to storage, they must workthrough these methods, which pass system calls through the hierarchy. Itis important to remember that system calls are the way that applicationsget kernel-level access to system resources and file systems are a resourcethat must be coordinated by the kernel.Storage Medium StructureThere is a generic structure to the space on a storage medium. In general,there are four components that organize the bits on a storage medium toproduce a file system.The first area on a storage medium is typically the master boot record(MBR).
This is an area that contains information necessary to boot theoperating system and get the computer up and running. Early on, operatingsystem kernel code used to occupy the MBR, but as operating systemsgrew in size and the need to change operating systems became moreobvious, this code was kept somewhere on the storage medium and theaddress of this location was stored in the MBR. On most computingsystems, the MBR is the first set of bytes on the storage medium; thisassumption is made by many operating systems.IMPLEMENTATION OF A FILE SYSTEM179The next area of the storage medium is called the partition-label controlblock (PLCB).
This area contains information about storage mediumpartitions. Such information can include the size of each partition, theposition at which each partition starts and ends on the storage medium,and the number and location of free blocks of storage. Most partitions aredefined here; there can be special partitions (areas of the disk) that aredefined elsewhere.The next area on a storage medium is the directory structure. This areacontains information to organize and find files; we detail this structure inthe next section.The next area is used for file storage. Both FCBs and actual file contentsare stored in this area.
We detail the structure of this space in a latersection.In addition to the structure of the storage media, the operating systemalso keeps track of information for each file system. The structuresmaintained in this way reflect and augment the storage structures onthe storage medium. The operating system usually maintains a partitiontable, a table defining the directory structure, and open-file tables. Thislast structure records where open files are in the operating system byplacing FCBs in a table, kept in memory.
Tables of open files are usuallyalso kept on a per-process basis.Directory structureIn general, a directory must maintain several pieces of information. Adirectory is the central point of file-system information and is the onlyway to find where a file begins on a storage medium. Therefore, it mustmaintain information on all files and where to find them. Sometimes thisinformation is resident in the directory and sometimes directories simplypoint to this information on a storage medium.Directories are really just files of data stored in a file system. A directoryusually holds the following information:• directory name : directories have names, just like files, and thesenames need to be stored with the directory• directory size : the number of files and directories must be stored• FCB information : each file and directory has a control block andthese control blocks are accessible through the directory.
Either thecomplete FCB is stored with the directory structure or the address ofwhere the FCB resides is stored.180FILE SYSTEMS AND STORAGEAs we stated previously, each directory is accessed by other directories.The chain of directories forms a tree. There is, therefore, a root to thedirectory tree, a single directory at which paths to all others start. Thisroot directory is not accessible from other directories, because it is at thetop.