Linux 2.6.11 kernel file I/O system Call Details

Source: Internet
Author: User
Article title: Linux 2.6.11 kernel file IO system call details. 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.

1. Introduction

I have been working in the Linux environment for more than two years and have been ignorant. I read the book "Leon's UNIX source code analysis" one year ago. I feel that I have a long way to learn. Inspired by the essence of chinaunix, I plan to take some of the recent kernel call analysis notes and discuss them with my predecessors to learn from each other.

This section describes the 2.6.11 kernel implementation of file I/O operations, including the main data structure, macro definition, and function flow. The following describes the system calls of open, create, close, read, write, and lseek respectively.

2. main references

Leon's UNIX source code analysis

Advanced Programming in UNIX environment

Www.kernel.org

3. main data structure

3.1.FD

For the kernel, all open files are referenced by the file descriptor. The file descriptor is a non-negative integer. When an existing file is opened or a new file is created, the kernel returns a file descriptor to the process.

When reading or writing a file, use the file descriptor returned by open or creat to identify the file and send it as a parameter to read or write. In POSIX.1 applications, the file descriptors are constants 0, 1, and 2, respectively representing STDIN_FILENO, STDOUT_FILENO, and STDERR_FILENO, meaning standard input, standard output, and standard error output, these constants are defined in the header file. .

The file descriptor ranges from 0 ~ OPEN_MAX, which is commonly used in linux systems, is an integer that can be expressed by a 32-bit integer, that is, more on 65535,64-bit machines.

3.2.File

       
        
Struct file {struct list_head f_list; // file linked list pointer struct dentry * f_dentry; // directory structure of the file struct vfsmount * f_vfsmnt; // struct file_operations * f_op; // File operation function pointer: atomic_t f_count; unsigned int f_flags; mode_t f_mode; // File mode: int f_error; loff_t f_pos; // File offset struct fown_struct f_owner; // File owner structure unsigned int f_uid, f_gid; struct file_ra_state f_ra; // Structure pointer that tracks the operation status of the last file size_t f_maxcount; // file size: unsigned long f_version; void * f_security; // hook file operation security structure pointer void * private_data; // tty drive data # ifdef CONFIG_EPOLL struct list_head f_ep_links; // the EPOLL mechanism detects the required chain table structure, such as spinlock_t f_ep_lock; // The flag compatible with earlier gcc bugs # endif/* # ifdef CONFIG_EPOLL */struct address_space * f_mapping; // address ing table}
       

3.3.File _ struct

The File_struct structure stores all the file table data opened by the process.

       
        
Struct files_struct {atomic_t count; // automatic incremental spinlock_t file_lock; // int max_fds; // int max_fdset; // maximum fd set capacity int next_fd; // The next idle fd struct file ** fd; // list of file structure pointers corresponding to the current fd fd_set * close_on_exec; // execute close fd set fd_set * open_fds; // open fd set fd_set close_on_exec_init; // fd_set open_fds_init; struct file * fd_array [NR_OPEN_DEFAULT]; // fd queue enabled by default };
       

[1] [2] [3] [4] [5] [6] [7] Next page

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.