Linux的file结构体和inode结构体怎么用
发表于:2025-11-06 作者:千家信息网编辑
千家信息网最后更新 2025年11月06日,本篇内容介绍了"Linux的file结构体和inode结构体怎么用"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能
千家信息网最后更新 2025年11月06日Linux的file结构体和inode结构体怎么用
本篇内容介绍了"Linux的file结构体和inode结构体怎么用"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
1. file 结构体
file 结构体代表一个打开的文件,系统中每个打开的文件在内核空间都有一个关联的 struct file。
它由内核在打开文件时创建,并传递给在文件上进行操作的任何函数。在文件的所有实例都关闭后,内核释放这个数据结构。
注:在内核和驱动源代码中,struct file 的指针通常被命名为 file 或 filp(即 file pointer)。
struct file { union { struct llist_node fu_llist; struct rcu_head fu_rcuhead; } f_u; struct path f_path; struct inode *f_inode;/* cached value */ const struct file_operations *f_op;/* 和文件关联的操作 */ /* * Protects f_ep_links, f_flags. * Must not be taken from IRQ context. */ spinlock_t f_lock; enum rw_hint f_write_hint; atomic_long_t f_count; unsigned int f_flags;/* 文件标志,如O_RDONLY、O_NONBLOCK、O_SYNC */ fmode_t f_mode;/* 文件读/写模式,FMODE_READ、FMODE_WRITE */ struct mutex f_pos_lock; loff_t f_pos;/* 当前读写位置 */ struct fown_struct f_owner; const struct cred *f_cred; struct file_ra_state f_ra; u64 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; struct list_head f_tfile_llink; #endif /* #ifdef CONFIG_EPOLL */ struct address_space *f_mapping; errseq_t f_wb_err; } __randomize_layout __attribute__((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]; };文件读/写模式 mode、标志 f_flags 都是设备驱动关心的内容,而私有数据指针 private_data 在设备驱动中被广泛应用,大多被指向设备驱动自定义以用于描述设备的结构体。
2. inode 结构体
VFS inode 包含文件访问权限、属主、组、大小、生成时间、访问时间、最后修改事件等信息。它是 Linux 管理文件系统的基本单位,也是文件系统连接任何子目录、文件的桥梁,inode 结构体的定义如下:
struct inode {
umode_t i_mode;
/* inode的权限 */
unsigned short i_opflags;
kuid_t i_uid;
/* inode拥有者的id */
kgid_t i_gid;
/* inode所属的群组id */
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;
/* 若是设备文件,此字段将记录设备的设备号 */
loff_t i_size;
/* inode所代表的文件大小 */
struct timespec i_atime;
/* inode最近一次的存取时间 */
struct timespec i_mtime;
/* inode最近一次的修改时间 */
struct timespec i_ctime;
/* inode的产生时间 */
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;
/* inode所使用的block数,一个block为512字节 */
#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 ->i_op->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;
/* 若是块设备,为其对应的block_device结构体指针 */
struct cdev *i_cdev;
/* 若是字符设备,为其对应的cdev结构体指针 */
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;
"Linux的file结构体和inode结构体怎么用"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!
文件
结构
设备
时间
内核
指针
驱动
内容
数据
系统
若是
设备驱动
代表
大小
更多
权限
标志
模式
知识
关联
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
数据库模型图片大全
软件开发网页设计培训
数据库服务器导入另一个系统
数据库的安全性三个方面
我的世界服务器 村民
数据库窗体选项组的命名
通达信免费版能同步数据库
中国开发地图软件开发
网络基础网络安全好就业吗
网络技术ospf题
房间宽带连接服务器
局机关网络安全工作情况
互联网和高科技有什么区别
软件开发的三本有什么
数据库招聘北京
免费服务器会卡吗
数据库系统依靠
巨杉数据库证书考试
河南软件开发公司联系电话
云服务器 系统盘容量
ibm服务器价格
毕业设计查重数据库包括哪些
计算机软件开发者有署名权
服务器 自动重启
工商银行服务器安全建立失败
为什么原神两个服务器不能一起玩
小程序云数据库建立
北京戴尔服务器维修维保多少钱
济南东忠软件开发有限公司电话
电脑网络安全模式下打开应用