Linux File System Learning (a) Related concepts???

Source: Internet
Author: User

"Everything is a document" is one of the basic philosophies of unix/linux. Not only ordinary files, directories, character devices, block devices, sockets, etc. are treated as files in Unix/linux, although they are of different types, but they are provided with the same set of operating interfaces. Another so-called block device: A storage device that supports random access, which corresponds to a character device, which only supports sequential access. In addition, Linux will be related to the file information and the file itself to distinguish between the two concepts, both on disk need to store, the former is often referred to as the Inode node, the latter is the actual file content, but must pass through the former to find the actual location of the disk, and operation method.

VFS allows arbitrary files in Linux to be manipulated by using the same set of file I/O system calls without regard to the specific file system format in which it resides, and further, the operation of the file can be performed across the file system. If 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, this operation involves two different file systems. Different file system block sizes may vary (as defined in the Super Block), and most file systems typically use 512B. VFS is a virtual file system is an abstract software layer in the Linux file system, because of its support, many different real file systems can be stored in Linux, cross-file system operation can be achieved. With its four main data structures, the Super block, the index node, the catalog item and the file object, and some auxiliary data structures, VFS provides the same interface for Linux, such as open, read/write, close and so on, whether it is a normal file or a directory, a device, or a socket. Only when the control is passed to the actual file system does the actual file system make a distinction and perform different operations on different file types. Thus, it is with the existence of VFS, cross-file system operation can be executed, unix/linux in the "Everything is a file" slogan can be achieved. (Unified IO interface for different file systems)

Such as:

What is VFS
VFS is software, what kind of software? is a software for managing multiple actual file systems
For example, Linux system has two actual file system, a FAT32 type disk A, a ext3 type disk B, if I want to copy a file on a 1.txt to B, I just need to hit command CP Path1/1.txt in the middle end path2
Yes, and how does the bottom layer do it?
1. Locate the corresponding 1.txt file identifier (Inode 1) according to Path1
2. Call the Inode 1 corresponding copy function (this copy function corresponds to the FAT32 type) and read the 1.txt contents of the disk into the cache
3. Find the Inode 2 for the corresponding destination according to path2
4. Call the Inode 2 corresponding copy function (this copy function corresponds to the ext3 type) and copy the 1.txt contents of the cache to the destination specified by path2
The 1-4 process is part of the VFS

Figure VFS Synergies with other kernel modules in the kernel

Three operating procedures for the file system:

Register: report to the kernel and declare that you can be supported by the kernel. It is usually registered when the kernel is compiled, or it can be loaded manually. The registration process is actually an instantiation of the struct file_system_type representing the data structure of each actual file system.

Create: The process of formatting a disk in some way is the process of building a file system on top of it. When you create a document system, you write control information about the file system at a specific location on the disk, that is, writing a super block to the disk.

Installation: That is, we are familiar with the mount operation, the file system is added to the Linux root file system directory tree structure, so that the file system can be accessed through the directory to find.

--

①file_operations and VFS

Each function pointer in the FILE_OPERATIONS structure is required to pass in an Inode table entry structure;

②device----Driver

One place to note after add Platform_device is here that add is called through the system initialization inside call Platform_add_devices put allall Platform_device successive calls Platform_device_register in the board-level Platform_device array are added to the system, Platform_device_register will call Platform_device_add (note: This is essentially different from platform_add_devices), all add to the system, you canaccess to resource resources in Platform_device, such as addresses, interrupt numbers, etc. via the platform operator InterfaceFor Request_memregion, Ioremap (theThe physical address of the resource assignment is mapped to the virtual space of the kernel to) and REQUEST_IRQ operations. The operating interfaces of the platform include:

@||| Platform_get_irq
@||| Platform_get_irq_byname
@||| Platform_get_resource
@||| Platform_get_resource_byname

The add operation iscompleted at System initialization, so in the subsequent device hanging on the platform virtual bus in the driver module Insmod to the system, the driver code inside can be obtained by the above function to the corresponding Platform_device resource, for example, in Module_ In init we call Plarform_driver_register, which refers to the probe function in Platform_driver, while the probe function allows for Cdev initialization and cdev_add operations, before these operations , the Get_resource can be used to obtain the register physical base address, and then ioremap to kernel virtual space, so that the driver can formally manipulate the device's register.

As for the Platform_driver registration process, and when to invoke the probe function, it is clear that the following reference is made to the invocation relationship in kernel:

When the driver is registered Platform_driver_register ()->driver_register ()->bus_add_driver ()->driver_Attach()->bus_for_each_dev () for each device that hangs on a virtual platform bus __driver_Attach()->driver_probe_device ()->drv->bus->Match() ==platform_match ()-& gt; comparestrncmp (Pdev->name, Drv->name, bus_id_size), call Platform_drv_probe ()->driver->probe () if it matches, ifprobe successfully binds the device to the drive

③driver---probe

The implementation principle of the hash table in the Kobj_map function is almost identical to that of the preceding registration allocation device number, and the index value of the probes array is obtained by major (Dev ) of the device to which the system is to be joined. (i = major% 255), and then adds a node object of type struct probe to the linked list managed by Probes[i], as shown in 2-6. The darker part of the rectangular block in which the struct probe is located is what we focus on, and the information about the character device object currently being added to the system is recorded. Where Dev is its device number, range is the number of devices that start continuously from the secondary device number, and data is a void * variable that points to the device object pointer p that is currently joining the system. Figure 2-6 shows the two character devices that meet the main device number major% 255 = 2 by calling Cdev_add after the Cdev_map shows the state of the data structure.

----

Linux File System Learning (a) related concepts???

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.