Linux-2.6open () opening file involves kernel processing and data structure analysis

Source: Internet
Author: User
Linux-26 file opening process involves data structure analysis: http: blogcsdnnetordeder

Linux-2.6 file opening process involves data structure analysis:

Link: http://blog.csdn.net/ordeder/article/details/24420637

User level

The file is opened in the following structure:

Fd = open (path, flag, mode)

Kernel layer

After the open function is trapped in the kernel space, perform the following operations:

The system traverses the path based on the path. In linux, everything is a file, including directories, which are also considered as files. Each file has an entry structure to indicate dentry {}. if dentry records a directory file, dentry-> d_inode describes the storage information of subdirectories in the current directory. otherwise, if dentry records files, dentry-> d_inode records file-related storage information. In linux, there is a path_walk, which searches for and traverses directories based on the fields in the path parameter and dentry-> d_name. path-> dentry-> d_inode searches for subdirectory information and traverses the directories cyclically, until the dentry of the target file is found. The inode of the target file is the node pointed to by dentry-> d_inode.

3. construct the description structure file {} of the open file. after finding the I node of the target file, initialize the new file structure, as shown in the blue arrow,
File-> f_path = * path;
File-> f_inode = path-> dentry-> d_inode;
File-> f_mapping = path-> dentry-> d_inode-> I _mapping;
File-> f_mode = mode;
File-> f_op = fop;
...

4. build the relationship between fd and file and record the file address in task_struct-> files-> fd_array [fd] = & file

After the summary process opens a file, the kernel constructs a file {} structure for it to describe the file read/write mode, flag, the current read/write location f_pos, and the file operation interface f_op. The process uses task_struct-> files-> fd_array [] to record all opened files. each opened file is uniquely identified by the subscript of the array, this subscript is the return value of our open function fd (int type)

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.