In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "how the linux system manages files". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how the linux system manages files.
What is a file system?
Before that, it is necessary to understand the concept of a file system-it is the method and data structure that the operating system uses to explicitly store files on a device or partition; that is, a method of organizing files on a storage device. Therefore, the software structure responsible for managing and storing file information in the operating system is called the file management system, referred to as the file system (the file system is the organization and allocation of the space of the file storage device, the system responsible for the storage of files and the protection and retrieval of stored files. When the house is built, when you move in, you have to consider the size of the space and so on. The file system here is your own idea. )
2. Inode structure:
1. Before I talk about this, I think all my friends who have come into contact with Linux will hear this sentence: under the linux system, everything is a file. This is indeed, how to say, I don't know if you have noticed, under windows, we can see the hard disk partition: C disk, D disk, E disk, etc., but you can't see such partition identifiers under linux. But it needs a hard disk to provide storage management (after that, I feel a little stupid, everyone knows to need physical memory). A physical hard disk can be divided into two areas: one is the content storage management table item of the hard disk, and the other is the area where the content is actually stored. When the operating system accesses the hard disk, it first reads the hard disk content management table (as an index to find a file storage path) to find the sector-level information of the file we want to access, and then use this information to query the area where the real content is stored, and finally get the file we want.
2. What is inode? To understand inode, start with file storage. Files are stored on the hard disk, and the smallest storage unit of the hard disk is called the Sector. Each sector stores 512 bytes (equivalent to 0.5KB). When the operating system reads the hard disk, it will not read it sector by sector, which is too inefficient, but read multiple sectors in succession at one time, that is, read a block (block) at one time. The area in which meta-information is stored is called inode, which is translated into Chinese as "index node". The inode (index node) table contains a list of all files for the file system
3. Under the linux system, the initial information obtained by the operating system is the file name, and the final information is the file content. The first step is to query the hard disk content management table, which records all kinds of information about each file in units of files, and each file has an information list data structure (we call it inode structure, I node, which is essentially a structure, which has many elements, each of which records some information about the file. These include the file name, the corresponding sector number and block number of the file on the hard disk.
Note: hard disk management is based on files, each file has an inode structure, each inode has a number, corresponding to a structure, the structure records a variety of information. After we get a file name, our operating system will use the file name cycle to match the file information node inode in the hard disk content management table. How to match? I think the file name should be used to match a structure pointing to the element in the node, which is almost the same as constructing a structure variable in the c language, and then accessing the content of the structure through this structure variable).
4. Summary: I node is a data structure used in our operating system to record all kinds of information (storage, size, etc.) of files. This data structure allows us to manage the storage files on the hard disk.
3. Vnode structure:
1. Before we talk about this, we still want to talk about what a file descriptor is. I just briefly talked about the previous article, and I would like to add here:
A. The essence of the file descriptor (fd) is a number, which is essentially an item of the file descriptor table in the process table. The process uses the file descriptor as an index to index and look up the table to get the file table pointer, and then indirectly access the corresponding file table.
B. According to the operating system, fd increases successively from 0. Fd also has maximum limitations. In earlier versions of linux, the maximum fd was 20, so a maximum of 20 files were allowed to be opened by a process at that time. The file descriptor table in linux is an array (not a linked list), so the file descriptor table is actually an array, fd is index, and the file table pointer is value.
C, fd 0, 1, 2 have been occupied by the system by default, so the user process gets the smallest fd is 3. It is useful that the linux kernel occupies 0,1,2 fd. When we run a program to get a process, three files have been opened internally by default, and the corresponding fd of these three files are 0,1,2. These three files are called stdin, stdout, and stderr. That is, standard input, standard output, and standard error, so the smallest fd the user process gets is 3.
2. The running of a program is a process, and the file we open in the program belongs to a certain process. Each process has a data structure to record all the information about the process (called the process information table). There is a pointer in the process information table, which points to a file management table. the file management table records all files opened by the current process and their related information. The index used to index each open file in the file management table is the file descriptor fd. What we finally find is a management structure vnode of the opened file (that is, vnode is specially used to manage the opened file). A vnode records all kinds of information about an open file (such as file size, file location in memory), and as long as we know the file's fd, we can easily find the file's vnode and perform various operations on the file.
3. Summary:
The file management table finds a specific open file through the file descriptor fd. For a specific open file, all kinds of information (storage location in memory, storage size, etc.) of the file is managed by vnode. Vnode is a structure with the element of file pointer, which indicates which location of the file stream we are currently operating.
At this point, I believe you have a deeper understanding of "how the linux system manages files". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.