Contents File and file system overview Logical organization of file File directories and file sharing Physical organization of file (secondary storage management)
5.1 File and File System Overview • Basic Concept (pp501) • Field • Record • File • Database • File Management System • Database Management System
Field • A field is the basic element of data • Field may be fixed length or variable length • Attribution of field include name, length, type, default…
Record • A record is a collection of related fields that can be treated as a unit by some application programs. • A record may be fixed length or variable length. • Key field: can be seen as the identify of the record.
File • A file is a collection of similar records or a streaming of byte. • Access control restrictions may apply at file or record or field.
File Attribution • Name • Length • Access control • Create time , modify time • Physical address • Where they are?
Database • Database is a collection of related data. • The database itself consists of one or more types of files.
Database Operations • Retrieve_all • Retrieve_one • Retrieve_next • Retrieve_previous • Insert_one • Delete_one • Update_one • Retrieve_few
File Management Systems (p503) • A set of system software to manage files of the system and provides services to users and applications in the use of files.
File Management Systems • A separate file management systems may provide for some special storage systems. • Mostly, the entire file management system is considered part of the operating system.
Database Management Systems • It can be independent of operation system. • It can have an independent file system or use file systems of operation system. • Database file is referred as structure file.
Objectives for a File System pp503 • To meet(满足) the management requirements of the user. • To guarantee the data in file are valid. • To optimize performance of the file access. • To support for a variety of storage device type.
Objectives for a File System • To eliminate the potential for lost data. • To provide a standardized set of I/O interface. • To provide I/O support for multiple users.
Minimum Requirement • Create、delete and update file. • Each user may have controlled access to other users’ files. • Each user may control what type of accesses are allowed to the users’ files. • Each user should be able to restructure the user’s files in a form appropriate to the problem.
Minimum Requirement • Each user should be able to move data between files. • Each user should be able to backup and recover the user’s files in case of damage. • To access the user’s files by a symbolic(符号) name.
Example : FAT • BOOT section • FDT（file directory table） • FAT1/FAT2（file allocation table) • DATA section
操作流程 磁盘参数表 磁盘目录表 FDT 文件位置分配 表FAT 文件名 磁盘基数表 扇区物理 操作 磁盘扇区 定位
File Operations • Read/write • Lseek • Lstate • Unlink • Open • Close • ……
File Management Function pp505 • Identify and locate the selected file: Lookup（查找） the directories of the file systems to get the location of the file.(按名存取) • In sharing file systems, accessing control should be verified.
File Management Function • To map the logical unit (record/byte) to physical unit (block) . • To allocate free block for files. • To manage the free block of secondary storage.
Device Drivers • Lowest level. • Communicates directly with peripheral devices(外设). • Responsible for starting I/O operations on a device. • Processes the completion of an I/O request.
Basic File System • Physical I/O. • Deals with exchanging blocks of data. • Concerned with the placement of blocks between disk-cash and memory.
Basic I/O Supervisor • Responsible for file I/O initiation and termination. • Control structures (e.g.SDT) are maintained. • Concerned with scheduling access to optimize performance. • Part of the operating system.
Logical I/O • Enables users and applications to access records. • Provides general-purpose record I/O capability.
Access Method • Reflect different file structures. • Different ways to store and process data.
Criteria for File Organization(p507) • Rapid Access • Needed when accessing a single record. • Not needed for batch mode. • Ease of update • File on CD-ROM will not be updated, so this is not a concern.
Criteria for File Organization • Economy of storage • Should be minimum redundancy in the data. • Redundancy can be used to speed access such as an index. • Simple maintenance. • Reliability.
5.2 Logical Organization of File • The pile. • The sequential file. • The indexed sequential file. • The indexed file. • The direct, or hashed file.
The Pile • Data are collected in the order they arrive. • Purpose is to accumulate a mass of data and save it. • Records may have different fields. • No structure. • Record access is by exhaustive search.
The Sequential File • Fixed format used for records so records are the same length. • All fields the same (order and length). • Field names and lengths are attributes of the file. • One field is the key field. • Uniquely identifies the record. • Records are stored in key sequence.
The Sequential File • Is the only type that is easily stored on tape as well as disk. • Poor performance. • New records are placed in a log file or transaction file. • Batch update is performed to merge the log file with the master file.
Indexed Sequential File • Index provides a lookup(查找) capability to quickly reach the vicinity（邻近） of the desired record. • Contains key field and a pointer to the main file. • Indexed is searched to find highest key value that is equal or less than the desired key value. • Search continues in the main file at the location indicated by the pointer.
Comparison of Sequential and Indexed Sequential • Example: a file contains 1 million records • On average 500,000 accesses are required to find a record in a sequential file • If an index contains 1000 entries, it will take on average 500 accesses to find the key, followed by 500 accesses in the main file. Now on average it is 1000 accesses.
Indexed Sequential File (Insert) • New records are added to an overflow file. • Record in main file that precedes it is updated to contain a pointer to the new record. • The overflow is merged with the main file during a batch update. • Efficiency is not high , and only one index.
Indexed File • Uses multiple indexes for different key fields. • May contain an exhaustive（ 耗尽） index that contains one entry for every record in the main file. • May contain a partial index. • The index is a sequential file with fixed records.
Hashed File • Directly access a block at a known address • Key field required for each record
5.3 File Directories (table 12.2) • Contains information about files • Attributes • Location • Ownership • Directory itself is a file owned by the operating system • Provides mapping between file names and the files themselves
Simple Structure for a Directory • It may only include the key elements: name,address,size and organization. • So most of the files’ directory can cash to memory to improve the search speed.
Basic Operations • Search（lookup） • Create file • Delete file • List directory
Type of Directory • Single-level • Two-level • Multi-level
Single Level • List of entries, one for each file. • Sequential file with the name of the file serving as the key. • Provides no help in organizing the files. • Forces user to be careful not to use the same name for two different files.(不能重名)
Two Level • One directory for each user and a master directory（主目录）. • Master directory contains entry for each user. • Provides address and access control information • Each user directory is a simple list of files for that user. • Still provides no help in structuring collections of files.