File struct and inode struct

Source: Internet
Author: User

(1) struct
The file struct is defined in include/Linux/fs. h. A file struct represents an opened file. Each opened file in the system is associated with a file in the kernel space.
Struct
File. 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. Create a driver in the kernel and use the driver source code.
, Struct file pointer is 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;
};
(2) struct dentry
Dentry
The Chinese name of is a directory item, 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 (can be understood as ext2
Inode) corresponds to a specific object on a physical disk. dentry is a memory entity. The d_inode Member points to the corresponding inode. That is to say, an inode can
Multiple dentry connections are linked during running, while d_count records the number of connections.
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

};

(3) The index Node object is represented by the inode struct, And the definition file is in Linux/fs. h.

Struct inode {
Struct hlist_node I _hash; hash table
Struct list_head I _list; index node linked list
Struct list_head I _dentry; directory linked list
Unsigned long I _ino; node number
Atomic_t I _count; reference count
Umode_t I _mode; access control
Unsigned int I _nlink; number of hard links
Uid_t I _uid; User ID
Gid_t I _gid; User ID Group
Kdev_t I _rdev; real device identifier
Loff_t I _size; file size in bytes
Struct timespec I _atime; last access time
Struct timespec I _mtime; last modify time
Struct timespec I _ctime; last change time
Unsigned int I _blkbits; block size in bits
Unsigned long I _blksize; block size in bytes
Unsigned long I _version; version number
Unsigned long I _blocks; number of file blocks
Unsigned short I _bytes; number of bytes used
Spinlock_t I _lock; spin lock
Struct rw_semaphore I _alloc_sem; index node semaphore
Struct inode_operations * I _op; index node operation table
Struct file_operations * I _fop; default index node operations
Struct super_block * I _sb; related super block
Struct file_lock * I _flock; file lock linked list
Struct address_space * I _mapping; address ing
Struct address_space I _data; device address ing
Struct dquot * I _dquot [maxquotas]; Disk Quota of nodes
Struct list_head I _devices; block device linked list
Struct pipe_inode_info * I _pipe; MPS queue Information
Struct block_device * I _bdev; block Device Driver
Unsigned long I _dpolicy_mask; Directory Notification mask
Struct dnotify_struct * I _dnotify; Directory Notification
Unsigned long I _state; Status flag
Unsigned long dirtied_when; first modification time
Unsigned int I _flags; File System flag
Unsigned char I _sock; socket
Atomic_t I _writecount; writer count
Void * I _security; Security Module
_ U32 I _generation; index node version number
Union {
Void * generic_ip; special file information
} U;
};

Inode is an index node. Partition of each storage device or storage device (the storage device is a hard disk, a floppy disk, or a USB flash disk ......
After being formatted as a file system, there should be two parts: one is inode, the other is block, and the block is used to store data. Inode is used to store these numbers.
Data, including the file size, owner, user group, and read/write permissions. Inode indexes information for each file, so there is an inode value. The operating system depends on the command,
Find the corresponding file with the fastest inode value.
To make a metaphor, for example, a book, a storage device or partition is equivalent to this book. Block is equivalent to every page in the book, and inode is equivalent to the directory before this book. A book has a lot of content, if you want to find a part of the content, you can first check the directory to find the content we want to see as quickly as possible.
When we use ls to view a directory or file, if we add the-I parameter, we can see the inode node. For example, LS-Li lsfile. Sh, the first value is the inode information.

Http://blog.csdn.net/sealyao/archive/2009/10/11/4626875.aspx ()

Http://blog.csdn.net/wangdeng1314/archive/2009/06/10/4254132.aspx ()

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.