I. File and file systems
1. Three levels of data composition: data items, the lowest data organization form in the file; records, is a collection of related data items; files can be divided into structured files and non-structured files, A structured file consists of several records. A non-structured file can be viewed as a batch stream. A file is the largest data unit in the file system.
2. File System: file system includes three aspects
(1) objects and their attributes, such as files, directories, and disk buckets;
(2) A collection of software for object manipulation and management, which is the core part of the file management system, including management of file buckets, management of file directories, conversion of logical addresses to physical addresses, file read/write management, and file sharing protection;
(3) file system interface.
Ii. Logical Structure of Files
(1) ordered files
Ordered files are divided into String Structures (unordered keywords) and sequential structures (ordered keywords ). They are only one record followed by one record. The sequential files of string structures can only be compared with keywords one by one until they are found, you can use efficient algorithms such as semi-lookup and interpolation to quickly search ordered files with sequential structures.
(2) index files
Divided into index areas and data areas. The index area includes the keyword (n), record length (m), and record's first address (ptr ). A Data zone is composed of one or more records with an indefinite length. When searching, find the corresponding directory item in the index area through the keyword, and then get m and ptr, and start from the address pointed by ptr (in the data area, read or write data of m length.
(3) index ordered files
Similar to index files, the data zone only consists of a group of fixed-length records, and the index file data zone is composed of an indefinite-length record. The index area of the index sequence file includes the keyword and logical address. After obtaining the logical address, then, starting from the logical address (in the Data zone), compare the keywords of n records in sequence until the record is found.
(4) direct files and hash files
Such files are retrieved by using the hash function and keywords to calculate the logical address, and then read data from the logical address.
Iii. Physical Structure of Files
(1) continuous allocation
The disk block allocated to a file is adjacent and generally located in a track. During reading/writing, the head does not need to be moved. Therefore, the physical file is called a sequential file. In the directory items of the file directory, you only need to provide the first disk block number and the number of disk blocks to read data in sequence.
(2) link allocation
The disk blocks allocated by links are not consecutive. Instead, multiple discrete disk blocks are linked by the pointer before and after each other. data can be read from each disk along the pointer.
Implicit link: in the directory items of the file directory, you only need to provide the first disk block number and the last disk block number, while the intermediate disk block is linked together by pointer.
Explicit link: This method creates a table (FAT) based on the link relationship between all disk blocks. This table is stored in the memory. Each time you find the next disk block, you only need to find the table and then read the data from the corresponding disk block. You only need to provide the first disk block number for the Directory items in the file directory.
(3) index allocation
Index allocation is to make the disk block number used by the file into a table. The table is not in the memory, but in the external storage. The directory items in the file directory only need to provide the disk block number of the table. After reading the table from the disk block to the memory, read the data according to all the disk block numbers given by the table.
Iv. Directory management
(1) file control block
In Linux, the file name is separated from the index node. The file name is placed in the directory items in the memory directory for retrieval. After finding the directory item corresponding to the file name, read the index node from the external store according to the pointer provided by the Directory item.
(2) directory structure
Single-level directory structure
Two-level directory structure
Multi-level directory structure (tree directory structure)
V. File storage space management
(1) idle table method (using sequential table to record the number of idle disk blocks) and idle linked list method (using a pointer to link all idle disk blocks into a linked list)
(2) map (a two-dimensional array storing 0 or 1, 1 indicates allocated, 0 indicates idle)
(3) group Link Method (index method)
Vi. File Sharing
(1) index-based node sharing
(2) Using symbolic chains for file sharing
From Linuxer's Blog