Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the file structure and inode structure of Linux

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge of "how to use the file structure and inode structure of Linux". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. File structure

The file structure represents an open file, and each open file in the system has an associated struct file in 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 of the file are closed, the kernel releases this data structure.

Note: in kernel and driver source code, the pointer to struct file is usually named file or filp (that is, file pointer).

Struct file {union {struct llist_node fu_llist; struct rcu_head fu_rcuhead;} favou; struct path fancipaths; struct inode * fanciinodeterTrans * cached value * / const struct file_operations * f_op / * the operation associated with the file * / / * * Protects f_ep_links, f_flags. * Must not be taken from IRQ context. * / spinlock_t flocklock; enum rw_hint favored writeware hint; atomic_long_t favored count; unsigned int favored accounts * * file logos such as O_RDONLY, O_NONBLOCK, O_SYNC * / fmode_t f_mode / * File read / write mode, FMODE_READ, FMODE_WRITE * / struct mutex flockout; loff_t flocker * current read / write location * / struct fown_struct frankowner; const struct cred * flockcredit; struct file_ra_state f_ra U64 ifdef CONFIG_EPOLL; # ifdef CONFIG_SECURITY void * Used by fs/eventpoll.c to link all the hooks to this file security; # endif / * needed for tty driver, and maybe others * / void * private_data; / * file private data * / # ifdef CONFIG_EPOLL / * Used by fs/eventpoll.c to link all the hooks to this file * / struct list_head f_ep_links Struct list_head _ randomize_layout _ attribute__ ((aligned (4); # endif / * # ifdef CONFIG_EPOLL * / struct address_space * frankmapping; errseq_t favowbailerr ((aligned (4); / * lest something weird decides that 2 is OK * / struct file_handle {_ u32 handle_bytes; int handle_type / * file identifier * / unsigned char f_handle [0];}

File read / write mode mode and flag f_flags are all concerned by device drivers, while private data pointer private_data is widely used in device drivers, mostly pointing to device driver customization to describe the structure of the device.

2. Inode structure

VFS inode contains information about file access permissions, ownership, group, size, generation time, access time, last modification event, and so on. It is the basic unit for Linux to manage the file system, and it is also the bridge for the file system to connect any subdirectories and files. The definition of inode structure is as follows:

Struct inode {

Umode_t i_mode

/ * permissions for inode * /

Unsigned short i_opflags

Kuid_t i_uid

/ * id of the inode owner * /

Kgid_t i_gid

/ * the group id to which inode belongs * /

Unsigned int i_flags

# ifdef CONFIG_FS_POSIX_ACL

Struct posix_acl * i_acl

Struct posix_acl * i_default_acl

# endif

Const struct inode_operations * i_op

Struct super_block * i_sb

Struct address_space * i_mapping

# ifdef CONFIG_SECURITY

Void * i_security

# endif

/ * Stat data, not accessed from path walking * /

Unsigned long i_ino

/ *

* Filesystems may only read i_nlink directly. They shall use the

* following functions for modification:

*

* (set | clear | inc | drop) _ nlink

* inode_ (inc | dec) _ link_count

, /

Union {

Const unsigned int i_nlink

Unsigned int _ _ i_nlink

}

Dev_t i_rdev

/ * if it is a device file, this field will record the device number of the device * /

Loff_t i_size

/ * File size represented by inode * /

Struct timespec i_atime

/ * the last access time of inode * /

Struct timespec i_mtime

/ * the last modification time of inode * /

Struct timespec i_ctime

/ * time when inode is generated * /

Spinlock_t i_lock

/ * i_blocks, i_bytes, maybe i_size * /

Unsigned short i_bytes

Unsigned int i_blkbits

Enum rw_hint i_write_hint

Blkcnt_t i_blocks

/ * the number of block used by inode. A block is 512 bytes * /

# ifdef _ _ NEED_I_SIZE_ORDERED

Seqcount_t i_size_seqcount

# endif

/ * Misc * /

Unsigned long i_state

Struct rw_semaphore i_rwsem

Unsigned long dirtied_when

/ * jiffies of first dirtying * /

Unsigned long dirtied_time_when

Struct hlist_node i_hash

Struct list_head i_io_list

/ * backing dev IO list * /

# ifdef CONFIG_CGROUP_WRITEBACK

Struct bdi_writeback * i_wb

/ * the associated cgroup wb * /

/ * foreign inode detection, see wbc_detach_inode () *

Int i_wb_frn_winner

U16 i_wb_frn_avg_time

U16 i_wb_frn_history

# endif

Struct list_head i_lru

/ * inode LRU list * /

Struct list_head i_sb_list

Struct list_head i_wb_list

/ * backing dev writeback list * /

Union {

Struct hlist_head i_dentry

Struct rcu_head i_rcu

}

U64 i_version

Atomic_t i_count

Atomic_t i_dio_count

Atomic_t i_writecount

# ifdef CONFIG_IMA

Atomic_t i_readcount

/ * struct files open RO * /

# endif

Const struct file_operations * i_fop

/ * former-> iPop-> default_file_ops * /

Struct file_lock_context * i_flctx

Struct address_space i_data

Struct list_head i_devices

Union {

Struct pipe_inode_info * i_pipe

Struct block_device * i_bdev

/ * if it is a block device, it is the corresponding block_device structure pointer * /

Struct cdev * i_cdev

/ * in the case of a character device, the pointer to its corresponding cdev structure * /

Char * i_link

Unsigned i_dir_seq

}

_ _ u32 i_generation

# ifdef CONFIG_FSNOTIFY

_ _ u32 i_fsnotify_mask

/ * all events this inode cares about * /

Struct fsnotify_mark_connector _ _ rcu * i_fsnotify_marks

# endif

# if IS_ENABLED (CONFIG_FS_ENCRYPTION)

Struct fscrypt_info * i_crypt_info

# endif

Void * i_private

/ * fs or device private pointer * /

} _ _ randomize_layout

This is the end of the content of "how to use the file structure and inode structure of Linux". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report