(1) Internal representation of the file
Fourth, the path name is the conversion of the index node
In the following system calls, such as open, the parameters for the files of the file are the path name of the file. The kernel is looking for a path through a algorithm called Namei and finds an index node of the file. Every time the Namei algorithm analyzes the component in a path name, according to the name and the search directory, each component is converted into the index point, and finally returns the index node of the input path name.
Five, super block
The super block consists of the following fields: 1, the size of the file system 2. Number of space in the file system 3, the free block table 4 available on the file system, the next idle block in the idle block table 5, index node The size of the table 6, the file system hollow idiographic lead node table 7, the number of spaces in the file system 8, the idle index point table of the next idle index node, the lock field of the idle block table And the lock field 10 of the idle index point table, used to identify the flag that the super block has been modified
Note: The idle index point table table mentioned in 6 is located in the file system, which is different from the idle index point table in memory.
The following describes how the kernel is assigned to the new file, and we know that the kernel is the index node of the file already existing by the IGET algorithm. Here the kernel assigns the new file to new files through the Ialloc algorithm. The file system contains a linear index node table. When the type field of the node is 0, this index point is idle, that is, no file occupies this node. When the process creates a new file, it is available when the index node is required, and the cost is too high. To this end, UNIX contains an array in the hyper block and buffers the idle index nodes. When needed, take the index node corresponding to the idle number in this table, and improve the efficiency.
When the air idle index point table is empty, the buffered idle index node is used, the kernel is reset to the disk to search the idle node to fill the idle indexed point table, and the kernel will be "" Bearing to "save the biggest element in the codes of the filling of the idle, so that you can search from the number when searching. When the kernel releases an index node (call the IFREE algorithm), the core of the index node is 0, the kernel compares the node number with the "remember" index node number, if the node number is less than "remember" No., the "remember" = the node number, the purpose of doing this is to prevent omissions from idle index nodes. In theory, this empty idiographic directory is always in the segment of the idiographic idiots, but the exception is there.
Next, IAAALLOC algorithm will be discussed. When the super block is locked, go to sleep until the hyper block is available, then check if there is a space-free knot, if not, lock the super block, search the disk The index node table fills the empty idle index point table and then unlocks the hyper block. Take a number in the idle index point table, minimize the number of idle nodes, then call the Iget algorithm to get the index node, and transfer the node to the memory completed to its initialization, then return to the index point.
6. Distribution of disk blocks
The utility of the system MKFS can generate the array chains of the following figure, each chain is a disk block, including an array in the block, the component is an idle disk block number. There is a disk empty block table in the hyper block, with the number of idle disk blocks, is the same as a simple array with the idle indexed point table, which is the next chain below: ======= ============================================== 90 = 86 = 82 = 78 = 74 = 70 = 66 = 62 = 58 = ....... = ....... ==================== ================================= ================================================================================================================== ==================================== 200 = 196 = 192 = 188 = 184 = 180 = 176 = 172 = ....... = ....... ================================ ====================
============================================================================================================================================================================================================= === 400 = 396 = 392 = 388 = 384 = 380 = ......... = .............. ========= =================================================== The block number is 90, the block number exists is 200, and 200 is the first element in the third column, and it is naturally the first 400 of the next column element. When the first column block is assigned to 86, the first element is assigned, and the next chain is read into the disk idle block table in the hyper block.
The Unix is widely used as a buffer mechanism such as an empty idiographic point table and an idle disk block, improves system efficiency. It is also one of the main ideas of UNIX implementation.
Seven, other file types
UNIX also supports two other file types: pipe files and special files.
The pipe is also a FIFO (First In First Out, the queue), the data can only flow from one end, from one end.
Special documents include special files for block devices and character devices. They all specified for the equipment, so the index nodes do not reference any data, but contain two devices called primary and secondary. The main device number indicates the type of device such as the terminal or disk, and the secondary device number indicates the device number of such devices.
(Fail)