Linux file system Related data

Source: Internet
Author: User

Linux file systems are usually based on the virtual file system (VFS) to cover the specific file system operation differences, for the operation of the upper layer to provide a unified interface. The bottom of the file system is the block read-write interface provided by the system IO cache layer, which realizes the mapping of the logical block to the physical block.  As the underlying storage logic for the application, the purpose of the universal file system is to provide a logical-to-physical disk mapping in the form of directory/file.       A file system is essentially a logical way to organize disk blocks. Ext2 file system uses group descriptor, block bitmap, index node bitmap, index node table, data area and other organization disk space, each index node represents a file, the location of the disk block occupied by the file. In Ext2, a directory is a special kind of file, which is a list of the structures that are made up of ext2_dir_entry.         The directory holds the name and index node number of all directories and files in that directory. VFS provides a unified interface (in fact, the File_operatoin data structure, described later), a specific file system to be supported by Linux, you must follow this interface to write their own operation functions, and their own details of the kernel other subsystems hidden. As a result, all file systems are the same for other subsystems of the kernel and for user programs running on the operating system. In fact, to support a new file system, the main task is to write these interface functions.
Generally speaking, VFS has the following functions:
(1) The data structure of the specific file system is abstracted and managed by a unified data structure.
(2) Accept system calls from the user layer, such as write, open, Stat, link, and so on.
(3) Support for mutual access between various specific file systems.
(4) Accept operational requests from other subsystems of the kernel, especially the memory management subsystem.
Many specific file systems can be supported through Vfs,linux.

In order to support a variety of real file systems, VFS defines the basic, conceptual interfaces and data structures that are supported by all file systems, while the actual file system also provides the abstract interfaces and data structures that VFS expects, in the form of concepts such as files, directories, and the VFS definition. In other words, if an actual filesystem wants to be supported by Linux, it must provide a VFS-compliant interface to work with VFS. The actual file system hides the specific implementation details under a unified interface and data structure, so all file systems are the same in the VFS layer and other parts of the kernel.

The VFS records the currently supported file systems and the currently mounted file systems.
You can use a set of registration functions to dynamically add or remove file systems in Linux. The kernel saves a list of currently supported file systems, which can be viewed in user space through the/proc file system. This virtual file also displays the devices that are currently associated with these file systems. The way to add a new file system to Linux is to call Register_filesystem. The parameter of this function defines a reference to a file system structure (File_system_type) that defines the name of the file system, a set of properties, and two super-block functions. You can also unregister the file system.
When registering a new file system, the file system and its related information are added to the File_systems list (see Linux/include/linux/mount.h). This list defines the file systems that can be supported. You can view this list by entering Cat/proc/filesystems on the command line.

    

For data on a storage device, the logical concept that the operating system provides to the application is "file". When an application stores or accesses data, it simply reads or writes a one-dimensional address space of "file", and the correspondence between this address space and the storage block on the storage device is maintained by the operating system.

The Linux file system interface is implemented as a layered architecture that separates the user interface layer, the file system implementation, and the driver that operates the storage device.

VFS is the primary interface for the underlying file system. 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.
Each file system implementation (such as ext2, JFS, and so on) exports a common set of interfaces for use by VFS.

The two main objects that are dynamically managed in the VFS are Dentry and Inode objects. Caches these two objects to improve the performance of accessing the underlying file system. When a file is opened, the Dentry cache is populated with entries that represent the directory level (the directory level represents the path). In addition, an inode representing the file is created for the object. Creates a dentry cache with a hash table and assigns the cache based on the object name.

The buffer cache caches requests between the file system and related block devices. At the bottom of the file system layer is the buffer cache. 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.
--------------------------------------------------------------------------------------------------------------- -----


Linux treats all file systems in the perspective of a common set of objects. These objects are super blocks (superblock), Inode, Dentry, and files. The super Block describes and maintains the state of the file system on the root of each filesystem. Each object (file or directory) that is managed in the file system is represented as an inode in Linux. 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.

The super block structure represents a file system. It contains the information required to manage the file system, including file system names (such as ext2), file system size and status, block device references and metadata information (such as free lists, and so on). A super block is typically stored on a storage medium, but it can be created in real time if the Super block does not exist. You can find the Super block structure in the./linux/include/linux/fs.h.
One important element in the super block is the definition of the Super block operation. This structure defines a set of functions that are used to manage the inode in this file system. For example, you can use Alloc_inode to allocate inode, and Destroy_inode to delete inode. You can use Read_inode and write_inode to read and write the inode and perform file system synchronization with SYNC_FS. The super_operations structure can be found in./linux/include/linux/fs.h. Each file system provides its own Inode method, which implements the operation and provides a common abstraction to the VFS layer.

Inode and Dentry
The inode represents an object in the file system that has a unique identifier. Each file system provides a way to map file names to unique inode identifiers and Inode references. Figure 5 shows a portion of the inode structure and two related structures. Please pay special attention to inode_operations and file_operations. These structures represent the operations that can be performed on this inode. Inode_operations defines the operations that are performed directly on the Inode, while File_operations defines the methods associated with files and directories (standard system calls).
The inode and the directory cache each hold the most recently used Inode and Dentry. Note that for each inode in the inode cache, there is a corresponding dentry in the directory cache. The inode and dentry structures can be found in./linux/include/linux/fs.h.

Buffer cache
In addition to the individual file system implementations (which can be found in./linux/fs), the bottom of the file system layer is the buffer cache. This component tracks read and write requests from the file system implementation and physical devices (through device drivers). To improve efficiency, Linux caches requests to avoid sending all requests to physical devices. The most recently used buffers (pages) are cached in the cache, which can be quickly provided to individual file systems.

Each block requires its own buffer, which is the RAM memory area used by the kernel to hold block content. When a device driver reads a block from the disk, it fills the corresponding buffer with the value obtained from the hardware device, and similarly, when the device driver writes a block to the disk, it updates the corresponding set of neighboring bytes on the hardware device with the actual value of the associated buffer. The size of the buffer must match the size of the block.

In essence, a file system is a special hierarchical data storage structure that contains files, directories, and related control information. To describe this structure, Linux introduces some basic concepts:
A series of information items that have a logically complete meaning in a set of files. In Linux, in addition to ordinary files, others such as directories, devices, sockets, etc. are also treated as files. In short, "all documents".

In general, the file system under Linux can be divided into three main parts: first, the system call of the upper file system, the second is the virtual file system VFS (Filesystem Switch), and the third is the actual file system attached to the VFS, such as ext2,jffs. The specific file system manages a logical space, which is like a large array, where each element of the array is the basic unit of the file system operation-the logical block, which is numbered starting at 0, and the logical block is contiguous. The logical block is relative to the physical block, the physical block is the data on disk access units, that is, each time I/O operation, the smallest transfer of data size.

------------------------------------------------------------------------------------------

Each directory that is contained in/is used for a particular purpose:
/bin is just one of many catalogs that contain applications and utilities. However,/bin typically contains utilities that are basic to system operations. As a result, shell file manipulation commands such as CP and chmod, compression and decompression, and diagnostic commands are all located in/bin.


/sbin also includes utilities that are critical to system operation and maintenance. However, only Superuser can execute programs in/sbin, so this directory is called "Superuser-bin" or/sbin.


/dev contains all the hardware installed on your system, including the terminal and USB devices (and other peripherals physically connected to the computer), pseudo terminals (for interacting with X terminal windows), and hard drives, and so on.


/etc (often pronounced "etsee") is dedicated to system configuration. The/etc directory contains configuration files for system daemons, startup scripts, system parameters, and more.
/home contains the user's home directory. For example, if your login name is Joe, the directory/home/joe is your personal file repository.


/lib is used to store basic system library files. In modern UNIX, it is common to share system libraries, which means that not every binary file is linked and included (in that case, at least it will waste space), but when the library is needed, it is loaded as needed and can be shared by many applications at the same time. Therefore, the core applications and utilities that are installed with UNIX need to use libraries in/lib, and you need at least a small number of corresponding library files to create new executables from source code. All of these files are critical, and a file that is corrupted or deleted (either intentionally or unintentionally) can make the system unusable.


/MNT is the abbreviation for "Mount" and is the standard location for mounting hard drive partitions and other devices. If you want to see all the devices that are currently mounted and accessible, you only need to run the Mount command.
/tmp or "temporary", which is a system-wide staging store. Your WEB server may save session data files here, and other utilities will use the space in/TMP to cache intermediate results. It is generally assumed that files in/tmp are discarded after they are used. In fact, your system administrator may delete all files that are older than an expiration every night.


/usr is used to store a large number of files. End-user applications (from editors, games, and interfaces to system features) are located in the repository for man pages and more. Some files are valuable, but not necessary for system operation, and you are likely to find it in/usr.


/var is a shorthand for "variable", which is a repository for storing files that typically grow in size over time. You can find mailboxes, log files, printer queues, and databases in/var. You can usually save a Web site in/var because the Web site may accumulate large amounts of data over time.

Linux file system Related data

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.