Linux disk and file System (iii) Linux file system

Source: Internet
Author: User

I. Composition of the file system

Linux common file system types are REISERFS,EXT2,EXT3,EXT4,VFAT,XFS, etc., file system is a storage device on the data and metadata to organize the mechanism. His ultimate goal is to organize large amounts of data into persistent storage devices, such as hard disks and disks. The file system is the logical organization of the file, and he stores the files in a clearer way. The data is stored in a partition. A typical Linux partition consists of the following sections:

  

Boot Block: The first block of any partition that holds the system's boot program.

Super BLOCK: Holds global information for the entire partition: 1. How many block groups are there 2. Each block group contains the number of blocks 3. Block size 4. Free disk block, used disk block 5. Idle inode, used inode.

Meta-data: inode is stored

Inode: The identity of each file, the inode contains the inode number, permissions, belong to the main group, timestamp, file size and so on. Inodes is the key to implementing file storage. In Linux, each object (file or directory) that is managed in the file system is represented as an inode. The inode contains all the metadata that is required to manage the objects in the file system, including the operations that can be performed on the object. In a Linux system, a file can be divided into several blocks of data stored in a partition. In order to collect each chunk of data, we need the inode for that file. Each file corresponds to an inode. This inode contains multiple pointers to the individual data blocks that belong to the file. When the operating system needs to read the file, only need to find the corresponding inode, collect scattered data blocks, you can harvest our files. Note: Metadata and inode are not one by one corresponding, when the disk is large files, the inode can be set proportionally, less. If the disk is a small fragmented file, the number of inode must be sufficient

Data area: Divides a file into blocks, called a disk block. (Logical block, n bytes of size 2, generally only 1024,2048,4096). Storage is usually two types of files, respectively, the normal file and directory files, a disk can belong to multiple files (hard link), a file can have a different path (soft link). The contents of the file cannot be stored on the same disk.

In-memory space is divided into page blocks, which are typically 4K in size (different for different CPUs) Note: Disk occupies space and file actual size

  

Ext2 differs from ext3: ext3 is a log file system. The log is the third independent region (data area, metadata area) of the disk partition. The inode is created in the log area, not the metadata area. After creating the Inode data, if the data is stored in half of the power outage, you only need to check the log area. Because the data that has not been saved, including the file being modified, has moved his inode to the log area, so just check the log area to fix the inode. If there is no power outage, simply put the data back into the metadata area. The downside is that it takes more than one IO operation. Ext2 is used for files with low file integrity requirements.

Second, inode read file

The inode reads the file as follows:

1. root directory file Inode:2, used to find the Inode ID of Var

inode:10747905 of the 2.var catalog file to find the Inode ID of the Test.txt

inode:10749034 of the 3.text.txt file, used to locate the data blocks

  

Therefore, when we read a file, we actually found the inode number of the file in the directory, and then, based on the inode pointers, we put together the data blocks and put them into memory for further processing. When we create a file, we assign a blank inode to the file, write its inode number into the directory where the file belongs, then select the blank block, let the inode pointer point to the data block, and put the data in memory.

III. structure of the file system

  

The user space contains applications (for example, the users of the file system) and the GNU C Library (GLIBC), which provide a user interface for file system calls (open, read, write, and close). The system invocation interface acts like a switch that sends system calls from the user space to the appropriate endpoints in the kernel space.

VFS is the primary interface for the underlying file system, which is a software abstraction layer in the Linux kernel. This component exports a set of interfaces and then abstracts them into individual file systems, and the behavior of individual file systems can vary greatly. There are two caches (Inode and Dentry) for file system objects. They cache recently used file system objects. Due to the existence of VFS, Linux allows many different file systems to coexist and supports file operations across file systems. It provides an interface mechanism to actual file systems such as Ext2,vfat through some data structures and their methods.

Each file system implementation (such as ext2, JFS, and so on) exports a common set of interfaces for use by VFS. The buffer cache caches requests between the file system and related block devices. For example, read and write requests to the underlying device driver are passed through the buffer cache. This allows requests to be cached in, reducing the number of times a physical device is accessed and speeding up access. You can use sync commands to send requests in the buffer cache to the storage media (forcing all the uncommitted data to be sent to the device driver, which is then sent to the storage device)

    

Four, VFS (virtual file system)

Linux allows for coexistence of many different file systems, such as EXT2,EXT3. Any file in Linux can be manipulated using the same set of file IO system calls without regard to the specific file system format in which the operation of the file is performed across the file system. , we can use the CP command to copy data from a hard disk in the Vfat file system format to a hard disk in the Ext3 file system format, which involves two different file systems.

  

Procedure: The VFS calls the VFAT Read file method to read the A.txt data into memory, and then maps a.txt in-memory data to b.txt corresponding memory space, the VFS call Ext3 Write file method will b.txt write to disk, thus achieve the final cross-file system copy operation. VFS looks like an intermediary, shielding the differences between different file systems, enabling the execution of commands across file systems.

  

  

Linux disk and file System (iii) Linux file system

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.