Smartphone Operating System (779883), страница 36
Текст из файла (страница 36)
We start with the basic building blocks of file systems – names, attributes and operations – and move on to file systemimplementation, giving examples in several forms. We then look at filesystems on mobile devices, using Symbian OS as an example. Finally,we examine security issues involved in file system implementation.8.1 Files and DirectoriesComputers store information in many ways on many different media.There are magnetic tapes, CD-ROMs, disk drives, flash memory andothers. One of an operating system’s jobs is to provide a consistent,convenient interface to all these storage media. The idea of a file wasinvented as a structural unit to help provide this interface.
A file is a logicalconcept that is translated onto a physical device. This section introducesfiles and other organizational concepts, along with their properties.168FILE SYSTEMS AND STORAGEBasic ConceptsA file is a collection of information formed by bits of data on a storagemedium. It is the foundation unit of storage in a computer system.
Asusers work with storage, files are the units of manipulation they use.The information held in a file is at the discretion of the file’s owner. Filescan contain any kind of information; they are simply a collection of bytes.The same file may be interpreted in several different ways, depending onthe application that reads the information it contains. In fact, files canhave many different kinds of information kept inside, organized howeverthe creator wishes. Again, the interpretation of the bits contained withina file depends on the application that reads the information.Files can have a specific type of information with certain properties.Files of a specific type are said to have a specific structure.
Some filestructures are quite common and recognizable. Text files have charactersin them that are organized in a line-by-line format. A file is typicallycalled a binary file if the contents are not readable by humans (i.e., not atext file). There are many structured binary files, for which the structureis documented by some standard body.
Image files contain picture datain many different formats: Jpeg, Gif and PNG, to name a few. Files cancontain execution data of a compiled program that can be transferredbit-for-bit to memory and executed. A binary file could be a database,with its contents readable by a database server application.A directory is an organizational tool that groups files together in ahierarchy. A directory is analogous to a folder: a directory can hold filesor other directories and folders. Because they hold other directories, adirectory structure forms a tree of directories, with a specific directory atthe top of the tree called the root.
The navigation through the directorytree from root to file is called a path; paths through a directory tree haveunique names – path names – that reflect the unique path through thedirectory structure.Another way to look at a directory is as a table of contents. It is a table,whose contents are files and directories, kept on the storage medium.It is through this table that access to files is allowed.
The directory isthe only way to find the files it holds; no data on those files is keptelsewhere. In fact, all searches for files begin at the root of a file system,and proceed through the file system by looking up directories in the pathto a file, opening those directories, and finding the next file or directoryin the path.Disk drives are also organized by partitions. A partition – often called avolume or a minidisk – is a subsection of a disk drive that is regarded as itsFILES AND DIRECTORIES169own contained space.
A disk drive may be a host to a number of differentfile systems, each of which is usually created within an individual diskpartition. Files and directories cannot span partition boundaries. When apartition is full, other partitions cannot contribute file space. In essence,each partition is its own storage device.
Partitions are often enforced bybeing implemented by the storage medium hardware. There is at leastone partition per medium; if not otherwise split up, all storage is kept onone partition.What if There Were no Directories?The concept of files has been around almost as long as the concept ofexternal storage. One of the first uses of a file was in 1956, when IBMintroduced the IBM 350 disk file. At the time, the entire disk was a file.Soon, the idea began to catch on that multiple files could exist on astorage medium. However, the idea of files preceded the invention ofdirectories. Files started to proliferate and their organization started to getconfusing. Short names were used, but names were also used to reflectorganization.Directories were invented to aid organization.
But imagine how allthe files on a computer were grouped without the benefit of directories.Without directories, there would only be one flat file space, with all filesorganized by the names they were given. When you consider the numberof files on a typical modern computer, be grateful for directories.AttributesFiles and directories have many properties – often called attributes – thathelp identify and organize them. Certain attributes also help with managing various aspects of file systems, such as security.Files are identified by their names.
Names are mostly a conveniencefor humans, but they are used by operating systems as well. A name iscomposed of alphanumeric characters; the case of letters is sometimessignificant, depending on the operating system. The length of a name issometimes bound; for example, early versions of MS-DOS had the 8.3limitation: eight characters in the name of the file and three characters inthe extension, separated by a period.
The file extension is the suffix on afile and is often used to categorize the type of file it is: .doc files mightbe document files while .txt files might be text files.The file extension often classifies the file type. A file’s type determinesthe kind of data contained within it. Various operating systems support170FILE SYSTEMS AND STORAGEfile types in various ways. Microsoft Windows, for example, associates anapplication with a file type (.doc files are usually opened with MicrosoftWord). Linux, on the other hand, almost always completely ignores fileextensions, depending instead on the contents of the file to determinehow it is supported.A file has a size, i.e., the number of bytes it contains.
A file’s sizeis usually determined by its contents, but sometimes a file may take upspace on a storage medium but be empty. An empty file is usually azero-length file, but a file could be filled with meaningless data, therebyhaving a size but still being considered ‘empty’. This is a good exampleof the difference between physical size and logical size, where a file’sphysical size is marked by bytes occupied on a storage medium and itslogical size is marked by usable content.A file often has an owner and also has a group identification. Thesetwo attributes are used by operating system security features to regulatewhich processes and users may have access to the contents of a file.These attributes are given by the operating system upon a file’s creationand can be changed throughout a file’s lifetime.
The owner of a file is theuser ID of the user on whose behalf the file was created. The group IDidentifies a group of users that may access this file.In addition to owner and group IDs, a file may also have additionalprotection attributes. These attributes inform the access control mechanisms of an operating system about how a file may be used. This accesscontrol information often specifies one of three access methods – reading,writing or executing – in one of several categories, for example, owner,group and ‘other’ (users who are not the owner or in a file’s group).The date and time of access is usually an attribute of a file.
The accesstype is usually recorded with the date and time. It is common to recordtime of creation, time of reading and time of modification.The information about a file is kept in a directory structure on the storage medium (see Figure 8.1). The directory – the table of contents – holdsthe name of the file and the location where the file starts on the disk. Afile’s starting point is usually not the start of its contents, but rather a datastructure holding the rest of the file’s information. Part of this informationis the starting location of the file’s contents.Much of this same information is stored for directories themselves.Directory information includes name, owner, group, size, access information and access times.
In addition, as indicated above, they contain atable of contents that point to locations on the storage medium where fileinformation is held.FILES AND DIRECTORIES171DirectoryDirectory informationFile information nodereadme.txtOwner informationGroup informationSize informationDate/time informationDate/time of readDate/time of modificationDate/time of readAccess permissionsContents...readme.txt...Figure 8.1File contentsStorage of directory and file informationNamesThe naming of files and file paths is an interesting issue. Obviously,file names need enough characters so that the name can be descriptive.However, directory information space is limited, so names cannot haveinfinite length.File names typically consist of letters and numbers, with some punctuation.
File names are typically restricted to some limit, say 256 characters,with a suffix of some sort. While the historical convention is to have asuffix of three characters, suffices can be of any length.The pathname of a file is constructed as follows:<root> <directory list> <filename>The root of a file-system tree is designated in many ways. In Linux,the root is always the same, designated simply as ‘/’. In MicrosoftWindows and Symbian OS, the root is dependent on the storagemedium, which is designated by a letter followed by a colon, and a‘\’ character to designate the root.
The listing of the directory pathdiffers between operating systems. So the path to ‘readme.txt’ mightbe designated /software/graphics/readme.txt on Linux andC:\software\graphics\readme.txt on Symbian OS.StructureThe internal structure of a file must match the structure expected by theapplication that uses it. In addition, the file structure must match what172FILE SYSTEMS AND STORAGEthe operating system expects, if the operating system is to understand thatstructure.Some operating systems put very little emphasis on file structure.Linux has very few expectations of a file: it treats all files as a set ofbytes without any particular structure. Microsoft Windows has a similarphilosophy. Operating systems like these associate applications withcertain files, but that association is not determined by how the data insidea file is structured.Other operating systems, on the other hand, do indeed pay attention tofile structure. If a file structure is recognized, these operating systems havespecial operations that can be performed on the file.