The Linux File Manager defines a single internal view of the file that the application uses to read and modify files on all storage devices. Each type of storage device implements the same view in its file management program.
The File Manager is responsible for taking the block that contains the byte stream part that the application reads and writes. Whenever you read any part of the stream, it determines which disk block should be read and written.
The Linux file management program is designed to allow applications to manipulate files using a set of fixed functions that are set by POSIX. Open,close,lseek,read,write,ioctl and so on. A part of the file management program that is separate from the file system handles common work parts, such as checking access rights and deciding when to read and write disk blocks. The other part of the file management program handles all the work related to the file system, such as determining the location of the block on disk and knowing that the device driver reads and writes to a specific block. Two parts together. When working with files on disk, Linux provides a fixed set of operations at the API level, where files are written using Windows Os/minix or other operating systems.
The Linux File Manager API CV is on the abstract file model of the virtual file system VFS output. VFS performs a separate file operation with the system, and the operating system designer provides the VFS with extensions to complete the file system-related operations that are required. Release 2.x can read and write disk files in a variety of formats, including Ms-dos,minix,/proc, and Linux-specific formats and other formats called ext2. Of course, in version 2.2.12, it contains a specific file system-related missing to translate VFS operations and formats between the various external formats supported.
The core of VFS is conversion. Convert switch provides the standard File Manager API and resume internal interface for user space programs. This excuse is used by different file system translation programs that support MS-DOS/MINIX/EXT2 and other documents. Support for a new file system can be provided by implementing a new file system-related (translation program) missing. Each of these translation programs provides the ability to invoke the VFS conversion. and can reduce the external file expression form into the internal form of the function. Therefore, the translation process is responsible for:
Determine the policy used to organize disk blocks on disk devices
Read and Write Disk properties
Read and write external file descriptor information
Read and write disk blocks containing file data
The VFS file system model mimics the traditional UNIX file system, a VFS file descriptor called an inode (although he has his own unique format for supporting multi-file system methods). Although the VFS contains a file descriptor of its own format, each system-related file translator converts the contents of the external descriptor into the VFS inode format when the file is opened. So it assumes that the external file directory contains at least each name stored in the directory file and the address of its file descriptor.
The VFS has at least the following structure about the disk organization:
The first mountain on disk is the boot block used to store the bootstrapper. The file system does not use this boot block, but it assumes that the boot block exists on each file system. A super fast contains disk-related information, such as the number of bytes in a disk block
The external file descriptor on the disk describes the attributes of each file.
The data block is linked to each file that contains the data.
Before VFS manages a particular file system, it is necessary to write the type of translation and register it in the VFS. The Register_filesystem () function of the VFS informs the VFS of the basic information it needs, including the name of the file system type and the entry point of the file system Read_super () function, which is used when the file system is loaded.
When loading the file system, VFS creates an example of the Sturck super_block data structure to accommodate the information needed to manage the new file system. The VFS then invokes the Read_super () function of the newsroom to obtain information that is contained in a similar super block in the file system, translates the information, and saves it in a struct SUPER_BLOCK data structure.
The Super block contains the various fields that VFS needs to manage the file system, especially the fields
struct Super_operations *s_op;
This s_op field sets up a set of functions used to write back the super block to the disk/read-write disk inode/Check the status of the Super block, and so on. So Read_super () is the boot function that is bound to the VFS when the file system type is registered. At mount time, after the VFS reads the super block, it can use the Super_operation function to manipulate the super block on the disk when needed. Super_operations defines a public interface for private, super-block abstract data types on disk. This allows the conversion to Xu to implement the Super block and Inode according to its choice.
In order to open a file, the File Manager searches the storage system for the specified path name. The search may be an extended process. This is because it requires, for example, to open each directory in the pathname (starting with the highest directory in the path), search the path name for the path to the next file or directory, and which directory or file to open. If the search encounters an installation point, it moves from one file system to another and continues the search. Therefore the search may start from, for example, the Ext2 file, but eventually find the file in an MS-DOS file system.
Once the file manager has located the file in a directory, VFS checks the file and user permissions to ensure that the user has permission to open the file. If the process has the correct permissions, VFS will resume various table entries to manage I/O. First, create a table entry in the file description schedule of the process. Each process has a file descriptor table. Two each open file has a table entry in the table. A table entry is identified by a small integer value returned by a call. The value is then used for references to the file. Note When you create a process, the file descriptor table that you create has the following three entries:
StdIn with table entry identifier 0
StdOut has a value of 1
STDERR has a value of 2
The successful open () and pipe () calls are then dropped at the file descriptor table up to 3 to create a list item.
The table entries in the File descriptor table point to a table entry in the Open File table called the file structure (struct file). The File structure table entry holds state information related to the process that opened the file, such as the file location value used by the process. If two different processes open the same file, then each process will have its own file structure table entry, thus having its own copy of the file location. After the file structure table is worn in storage, it references the inode of the VFS.
The VFS passes through the inode in memory by reading the external file descriptor (by using the Read_inode () function specified in the Super block S_op list and translates it into the VFS inode format. As the Super block provides a field for the Super_operation list, the Inode provides the following fields to define an Inode action list):
struct Inode_operations *i_op;
struct Inode_operations is a list of operations that VFS needs to manipulate file blocks, such as Create () Lookuo () Link () and mkdir (). Colleagues also provide a list of default actions that are used when the I_op list does not provide actions.
The inode allocated in the VFS is assigned to a single large list of links. Whenever the VFS intends to scan all the inode when it is swimming, however, the access slows down when the VFS wants to reference a particular inode. So inode references are also loaded into an open hash table, where they are accessed through some (and possibly one) table probes (probe).
When the file manager changes the in-memory Inode version, these changes are not copied to the external file descriptor on the storage device. Conversely, when a file is closed or the application generates a SYC command, the inode version in memory is Ono with the periodic separate fee on the external file descriptor on the renewal secondary. When a file is opened and recent changes are made to the inode, the machine is down and the inode version in memory may be different from the external file descriptor on the disk, resulting in inconsistent file systems because of the loss of the latest information about the file when the inode in memory is corrupted. For example, if a block pointer in memory Indoe has changed (and a corresponding change has been made to the disk block), there may be an external file descriptor on disk that is inconsistent with the various storage block pointers on the disk.
When the file is opened, create an instance of the struct file (the table entry in the document structure table). In this file, the field struct file_operations *f_ops;
Specifies the entry points for read (), write (), Lseek (), select (), and so on, which are used to perform and system-related I/O operations. A colleague includes a Haiyo set of default file_operations specified in the inode so that if any particular file system (such as Lseek ()) is not specified in the F_ops list, the functions from the default list are used.
The real goal of these routines is to move information between the user's space address and the secondary memory block. Read () invokes file system-related operations to transfer data from disk to system buffer. Where data is written to disk. These routines must also arrange and distribute byte streams.
A file is organized as contiguous bytes left. This indicates that the application usually reads and writes the file as a byte stream, and the second is not random access to the characters in the file. As a result, the use of buffering methods can greatly improve the performance of the system. In the degree buffer, the file system reads before the bytes are left, removing the disk blocks that appear in the byte stream after the current file pointer. In write cache, a full disk block is ready to write whenever a disk device is available. Therefore, the application does not have to wait for the buffer to enter because it is already read when they are referenced. In addition, you do not have to wait for a write operation, because after the bytes are written to the stream in the application logic, they will occur as a post-action.
Linux attempts to use the maximum amount of memory to provide I/O buffers. It creates a dynamic buffer that tells the cache that its size depends on the number of page boxes currently required to provide virtual storage. Pages that are not required by the virtual storage system can be used as buffer caches. When a page fault error occurs, the buffer tells the cache that it is one of the places where the virtual storage system first searches the pages box.
Block caching is a relatively complex task. This section of the file management program must meet each of the following constraints:
Each file opened for a read operation should have one or more buffers that contain information that has been read from disk before the process time request information.
Each file opened for a write operation has a set of buffers that contain information that is written to the device when the device is available.
The same full output block as the block on the storage device should not be written back.
When virtual memory does not require all physical memory, the buffer tells the buffer to be enlarged. When virtual memory requires more physical memory, the buffer cache should be reduced (but does not affect the I/O that will be made)
Variable buffer size
Buffers can be shared between processes
EXT2 File System
The Ext2 file system mimics the BSD fast file system. Each disk is formatted to accommodate a set of block groups, each consisting of a super block, a group descriptor information, a table of file Inode in a block group, and a data block.
The Super block contains the following information:
Inode number
Number of idle Inode
Block details
Allocation limits
Last installation time and last write time
Errors and Status
Additional Management information
The block descriptor contains details about the blocks in a particular block group. For the descriptor of a block with a disk block size of 1024 bytes (1024=ext2_min_block_size<ext2_block_size<ext2_max_block_size=4096 per block size), A block may hold up to 8,192. The block descriptor also contains the Inode collection of files in the block group.
The inode uses a variant of the index allocation scheme to organize the block, which includes pointers to 15 different storage blocks. The file's money 12 blocks are directly indexed from the first 12 of the 15 pointers in the Inode, and the last three pointers are used as introduction pointers through the index block. If the file Manager is configured with a maximum size of 4KB per block, the 12 direct pointers in the inode can hold up to 48KB of files. If a file requests more than 12 blocks. Then the file system allocates an index block and links it to an indirect (13th) pointer. Therefore, the block 13~k from the inode indirect address by the indirect block determined by the 13th pointer in the inode. Similarly, a larger file uses the 14th pointer to point to a two-time indirect block, and the two largest file uses the 15th pointer only to think of a three-time indirect block.
Linux file system