Common file structures in Linux

Source: Internet
Author: User
Article Title: common file structures in Linux. 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.1 struct file

Struct file struct is defined in include/linux/fs. h. A file struct represents an opened file. Each opened file in the system has an associated struct file in the kernel space. It is created by the kernel when the file is opened and passed to any function that operates on the file. After all instances in the file are closed, the kernel releases the data structure. In kernel creation and driver source code, struct file pointers are usually named file or filp. As follows:

Struct file {

Union {

Struct list_head fu_list; file object linked list pointer linux/include/linux/list. h

Struct rcu_head fu_rcuhead; RCU (Read-Copy Update) is a new lock mechanism in Linux 2.6 kernel.

} F_u;

Struct path f_path; contains dentry and mnt members, used to determine the file path

# Define f_dentry f_path.dentry f_path

# Define f_vfsmnt f_path.mnt indicates the Mount root directory of the file system where the current file is located

Const struct file_operations * f_op; operation functions associated with the file

Atomic_t f_count; file reference count (How many processes open the file)

Unsigned int f_flags; corresponds to the flag specified during open

Mode_t f_mode; read/write mode: open mod_t mode Parameter

Off_t f_pos; file offset of the file in the current process

Struct fown_struct f_owner; this structure is used to send I/O time notification data through signals.

Unsigned int f_uid, f_gid; file owner id, owner group id

Struct file_ra_state f_ra; defined in linux/include/linux/fs. h, file pre-read related

Unsigned long f_version;

# Ifdef CONFIG_SECURITY

Void * f_security;

# Endif

/* Needed for tty driver, and maybe others */

Void * private_data;

# Ifdef CONFIG_EPOLL

/* Used by fs/eventpoll. c to link all the hooks to this file */

Struct list_head f_ep_links;

Spinlock_t f_ep_lock;

# Endif/* # ifdef CONFIG_EPOLL */

Struct address_space * f_mapping;

};

1.2 struct dentry

The Chinese name of dentry is a directory, which is a link to an index node (inode) in the Linux File System. This index node can be a file or a directory. Inode (which can be understood as ext2 inode) corresponds to a specific object on a physical disk. dentry is a memory entity, where the d_inode Member points to the corresponding inode. That is to say, an inode can link Multiple dentry while running, while d_count records the number of this link.

Struct dentry {

Atomic_t d_count; the directory item object uses counters, and there can be unused States, using states and negative States

Unsigned int d_flags; directory entry flag

Struct inode * d_inode; the index node associated with the file name

Struct dentry * d_parent; directory item object of parent directory

Struct list_head d_hash; pointer of table items in the hash table

Struct list_head d_lru; the linked list pointer is not used.

Struct list_head d_child; pointer to the linked list of the Directory item object in the parent directory

Struct list_head d_subdirs; indicates the linked list of the sub-directory item object.

Struct list_head d_alias; linked list of related index nodes (alias)

Int d_mounted; indicates the root entry of the installed file system.

Struct qstr d_name; file name

Unsigned long d_time;/* used by d_revalidate */

Struct dentry_operations * d_op; directory item method

Struct super_block * d_sb; super block object of the file

Vunsigned long d_vfs_flags;

Void * d_fsdata; file system-related data

Unsigned char d_iname [DNAME_INLINE_LEN]; stores short file names

};

1.3 struct files_struct

Each process contains a files_struct structure to record the usage of file descriptors, which is defined in include/linux/file. h.

Struct files_struct

{

Atomic_t count; number of processes in the table

Struct fdtable * fdt;

Struct fdtable fdtab;

Spinlock_t file_lock ____ cacheline_aligned_in_smp;

Int next_fd; the file descriptor of the last closed file with the smallest value, the next available file descriptor

Struct embedded_fd_set close_on_exec_init; the file descriptor initial value set to be closed when exec is executed

Struct embedded_fd_set open_fds_init; A set of initial values of shielded characters in the file descriptor

Struct file * fd_array [NR_OPEN_DEFAULT]; fd queue opened by default

};

Struct fdtable {

Unsigned int max_fds;

Struct file ** fd; pointer to the opened file descriptor list, pointing to fd_array at the beginning,

When max_fds is exceeded, the address is reassigned.

Fd_set * close_on_exec; execute the file descriptor bitmap to be closed by exec (fork, exec is the file inherited by the non-quilt process)

Descriptor)

Fd_set * open_fds; open file descriptor bitmap

Struct rcu_head rcu;

Struct fdtable * next;

};

[1] [2] Next page

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.