(1) Internal representation of the file system
The distribution of file systems on the disk in UNIX is as follows:
============================================= 引 - - Super block - Index node table ---- data block ======================================== ==
The super block and the index node table are focused.
First, index node table
Index Node (INDE) is the core content of the file system and the most important data structure of the kernel. One file in UNIX has only one inode corresponding to it, and it is stored in the index knot table of the disk. The index node table is a linear array. The contents of each domain of the index node are as follows: 1. The identification number of the file owner. 2, file type. 3. Access permission of the file. 4, the access time of the file. 5, the number of files. 6. The location of the file on the disk. 7, file size.
(Note: The index node does not indicate the path of the file)
When the index node is referenced by a process, it is transferred into memory. There is another index node list (in-core inode list) and an idle index point table in memory. When the index node is transferred to memory (using an IGET algorithm in the kernel), the index point is placed in the internal storage collision point table, and the number plus it will be added 1.
In addition to the contents of the disk index node, the data field in the memory index is described below, and the following new domain: 1, the state of the memory index point 2, the logical device number of the file system containing the file. 3, the index node number. (Index Node Index in the disk) 4, pointing to the pointer to other memory index points. 5, reference number.
The kernel use file system and index node number identifies a particular index node, and the system call request is used to use the IGET algorithm to allocate a memory copy of an index node, that is, the memory index point. The kernel independent manipulation index is tangled and the number of references. Lock is locked during the system call execution, preventing other processes from using this node during this period, and unlocks after the call is completed. The node between the two system calls is not locked.
The IGET algorithm is mainly completed: the index node number is parameter. If the index point is in the memory index point table, the number plus 1, return to the index point, if the bit node is in the idle index point table (this The reference number of the index nodes in the table is 0), then the index junction is removed from the table, put it in the internal storage collision point table, and references the number plus 1, if there is no in both tables The index node, then remove a new index node in the idle table, find the node in the disk index point table, read into the internal memory index point table, and then return the index node.
When the kernel releases the index point, the reference number is reduced. If the reference number falls to 0, and the memory copy is different from the disk copy, the write disk operation is performed, and the index junction is placed in the idle table. The algorithm used here is IPUT. If the file is associated with 0, the kernel releases all data blocks of the file and releases the file's disk index. Second, a formal file structure
The index node contains a list of documents on the disk. Each block of the disk is compiled. In UNIX system V, the size of the block is 1K, (4K in Windows), the index endpoint contains pointers to each data block, which is directly block, 1 inter-block, 1 2 times Indirect fast, 1 3 inter-block blocks, if you use 3 indirect, the size of a single file can be up to 16G, when accessing the file, the kernel calls the BMAP algorithm to map the byte offset of the logical file to the file system. Block.
Third, catalog
The directory is those files that make the file system have a tree structure. The directory is the file, it is only the file of some directory entry, each of the directory tables, and the file names in this directory, the path is composed of / divided into individual components. The read authority of the directory is allowed to read the directory, write permissions to allow the process to create subdirectory or delete subdirectories, and perform permission to search for the entire directory for the process to search for files.
Note: The difference between read rights and execution permissions.
(Fail)