Linux core-10. File system

Source: Internet
Author: User
Article title: Linux core-10. file system. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Original: David A Rusling
Translation: Banyan & fifa
Chapter 9 file systems
  
This chapter describes how Linux core supports the file system, virtual file system (VFS), and Linux core supports the actual file system.
One of the most important features of Linux is its support for multiple file systems. In this way, it is more flexible and can coexist with many other operating systems. At the time of writing this article, Linux has supported 15 file systems: ext, ext2, xia, minix, umsdos, msdos, vfat, proc, smb, ncp, iso9660, sysv, hpfs, affs and ufs. There is no doubt that the supported file system types will be added in the future.
Linux and Unix do not use device identifiers (such as device numbers or drive names) to access an independent file system. Instead, they are accessed by a hierarchical tree structure that represents a single object. Each time a file system is installed in Linux (mount), it is added to the file system hierarchy tree. Regardless of the type of the file system, it is connected to a directory and the files on this file system will replace the existing files in this directory. This directory is called the installation point or installation directory. When the file system is uninstalled, the original files in the installation directory will appear again.
  
When the disk is initialized (using fdisk), a partition structure describing the logical structure of the physical disk is added to the disk. Each partition can have an independent file system such as EXT2. The file system organizes files into logical hierarchies that contain directories, soft connections, and other physical block devices. A device that contains a file system is called a block device. The Linux file system regards these block devices as a simple linear block set and does not care about or understand the underlying physical disk structure. This is done by the block device driver, which maps requests to a specific block to the correct device; the corresponding track, sector, and number of cylinders of the disk where the disk is located are saved. No matter which device holds the block, the file system must use the same method to find and manipulate the block. The Linux file system (at least for system users) has different controllers that control different physical media and there are several different file systems on these physical media. The file system can even be stored on a remote hard disk connected through a network instead of the local system. There is a SCSI hard disk with the following contents in the root directory:
  
A e boot etc lib opt tmp usr
C f cdrom fd proc root var sbin
D bin dev home mnt lost + found
  
At this time, neither the user nor the program needs to know that the/C files they manipulate are actually located on the first IDE hard disk of the system and the VFAT file system has been installed. In this example,/E represents the primary IDE hard disk on the second IDE controller in the system. The first IDE controller is the PCI controller and the second is the ISA controller that controls the ide cdrom. When modem is used to dial in the network through the PPP network protocol, you can install the Alpha AXP Linux file system in the/mnt/remote directory.
  
Files in the file system are a collection of data. files containing the content in this chapter are an ASCII file named filesystems. tex. The file system contains not only the data in the file but also the structure of the file system. All files, directories, soft connections, and file protection information seen by Linux users and programs are stored. In addition, the file system must contain security information to maintain the basic integrity of the operating system. No one is willing to use an operating system that will lose data and files at will.
  
The earliest file system in Linux is Minix, which is very limited and has low performance. The file name cannot exceed 14 characters (although better than the 8.3 file name) and the maximum file size is 64 MB. 64 MB bytes looks very large, but in fact a medium database will exceed this size. The first File System specifically designed for Linux is called Extended File System or EXT. It appeared in April 1992. although it can solve some problems, its performance is still poor. In 1993, the second or EXT2 extension file system was designed and added to Linux. It is a file system that will be discussed in detail in this chapter.
  
Adding the EXT file system to Linux has a major impact. Each actual file system is separated from the operating system and system service and communicates with each other through an interface layer: virtual file system or VFS.
  
VFS allows Linux to support multiple different file systems, each representing a common VFS interface. Because the software converts all the details of the Linux file system, the other parts of the Linux core and the programs running in the system will see the unified file system. Linux's virtual file system allows users to transparently install many different file systems at the same time.
  
The virtual file system is designed to provide fast and efficient file access services for Linux users. At the same time, it must ensure the correctness of the file and its data. These two targets may conflict with each other. When a file system is installed and used, Linux VFS caches relevant information for it. If the data in the cache is modified during file creation, writing, and deletion, the corresponding content in the file system must be updated with caution. If you can see the data structure of the file system in the running core, you can see the data blocks that are being read and written by the file system. The data structure of the file and directory is constantly created and deleted, and the device driver keeps reading and writing data. The most important of these caches is the Buffer Cache, which is integrated into the routines for independent file systems to access the underlying block devices. When block access is performed, the data block is first put into the Buffer Cache and saved in each queue according to its status. This Buffer Cache not only caches data but also helps manage asynchronous interfaces in block device drivers.
  
  
9.1 Second generation extended file system (EXT2)
  
Figure 9.1 physical distribution of the EXT2 file system
The second generation of extended file systems, designed by Rey Card, aims to provide a powerful extensible file system for Linux. It is also the most successful file system in Linux.
Like many file systems, EXT2 is built on the premise that the data is stored in the file in the data block. These data blocks are of the same length and can be changed. the block size of an EXT2 file system is set when mke2fs is created. The size of each file is exactly the same as that of its block size. If the block size is 1024 bytes and a 1025-byte file occupies two 1024-byte blocks. In this way, you have to waste almost normal space. We usually need to compromise between CPU memory utilization and disk space usage. Most operating systems, including Linux, are forced to choose a relatively low disk space utilization to reduce CPU workload. Not every block in the file contains data. some of these blocks are used to include information about the system structure of the file. EXT2 uses an inode structure to describe files in the file system and determine the topology of the file system. The inode structure describes the block occupied by the data in the file, the access permission of the file, the file modification time, and the file type. Each file in the EXT2 file system is represented by an inode and each inode has a unique number. All inodes in the file system are stored in the inode table. The EXT2 directory is only a special file containing a pointer to its directory entry (also expressed in inode ).
  
Figure 9.1 shows the layout of the EXT2 file system that occupies a series of data blocks. For a file system, a file is only a series of data blocks that can be read and written. File systems do not need to know where data blocks should be placed on physical media. these are all device-driven tasks. Whenever the file system needs to read information or data from the block device that contains it, it will request the underlying device driver to read a data block of an integer multiple of the basic block size. The EXT2 file system divides the logical partitions it uses into data block groups. Each data block Group copies the information that is most important to the integrity of the file system, and regards the actual files and directories as information and data blocks. In order to fix the file system in the event of a catastrophic event, these copies are necessary. The following section describes the content of each data block group.
9.1.1 The EXT2 Inode
Figure 9.2 EXT2 Inode
  
Inode is a basic block in the EXT2 file system. each file and directory in the file system is described by a unique inode. The EXT2 inode of each data block group is saved in the inode table, and a bitmap is used by the system to track the allocated and unallocated inode. Figure 9.2 shows the EXT2 inode format, which contains the following fields:
Mode
It contains two types of information: inode content and user permission. Inode in EXT2 can represent a file, directory, symbolic connection, block device, character device, or FIFO.
Owner Information
Indicates the user and group identifier of the file or directory owner. The file system can perform proper access based on it.
Size
File size in bytes.
Timestamps
The time when inode was created and last modified.
Datablocks
Point to the block pointer that contains data described in this inode. The first 12 pointers point to the physical block that is described by inode, and the last three pointers contain multi-level indirect pointers. For example, two levels of indirect pointers point to a pointer, and these pointers point to some data blocks. This means that files with sizes less than or equal to 12 data blocks will be much faster than accessing large files.
EXT2 inode can also describe special device files. Although they are not real files, they can be used to access devices. All the device files in/dev can be used to access Linux devices. For example, the mount program can take the device file as a parameter.
9.1.2 EXT2 superblock
The hyperblock contains information about the basic size and form of the file system. The file system manager uses them to use and maintain the file system. Generally, when a file system is installed, only the superblocks in data block group 0 are read. to prevent the file system from being damaged, each data block group contains a copy. The Superblock contains the following information:
Magic Number
The file system installation software is used to check whether it is a real EXT2 file system superblock. The current EXT2 version is 0xEF53.
Revision Level
This master-slave revision version allows the installation code to determine whether the file system supports attributes that only exist in a specific version of the file system. At the same time, it is also a feature compatibility flag to help the installation code determine whether the new features of the file system can be safely used.
Mount Count and Maximum Mount Count
The system uses them to determine whether to perform a comprehensive check on the file system. Each time a file system is installed, the installation count increases. when it is equal to the maximum number of installation records, the system displays a warning message "maxumal mount count reached, running e2fsck is recommended ".
Block Group Number
Ultra-block copy.
Block Size
The size of a file system block in bytes, for example, 1024 bytes.
Blocks per Group
The number of blocks in each group. This block size is fixed when the file system is created.
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.