linux内核 结构体 图,UNIX内核file结构体详解

file结构如下所示:struct file

{union

{struct list_head

fu_list; 文件对象链表指针linux/include/linux/list.hstruct rcu_head fu_rcuhead;

RCU(Read-Copy Update)是Linux 2.6内核中新的锁机制} f_u;struct path f_path;

包含dentry和mnt两个成员,用于确定文件路径#define f_dentry f_path.dentry

f_path的成员之一,当前文件的dentry结构#define f_vfsmnt f_path.mnt

表示当前文件所在文件系统的挂载根目录const struct file_operations

*f_op; 与该文件相关联的操作函数atomic_t f_count;

文件的引用计数(有多少进程打开该文件)unsigned int f_flags;

对应于open时指定的flagmode_t f_mode; 读写模式:open的mod_t mode参数off_t f_pos; 该文件在当前进程中的文件偏移量struct fown_struct f_owner;

该结构的作用是通过信号进行I/O时间通知的数据。unsigned int f_uid, f_gid;

文件所有者id,所有者组idstruct file_ra_state f_ra;

在linux/include/linux/fs.h中定义,文件预读相关unsigned long

f_version;#ifdef

CONFIG_SECURITYvoid

*f_security;#endifvoid

*private_data;#ifdef

CONFIG_EPOLLstruct list_head

f_ep_links;spinlock_t

f_ep_lock;#endif struct address_space

*f_mapping;};1.2 struct

dentrydentry的中文名称是目录项,是Linux文件系统中某个索引节点(inode)的链接。这个索引节点可以是文件,也可以是目录。inode(可理解为ext2 inode)对应于物理磁盘上的具体对象,dentry是一个内存实体,其中的d_inode成员指向对应的inode。也就是说,一个inode可以在运行的时候链接多个dentry,而d_count记录了这个链接的数量。struct dentry

{atomic_t

d_count; 目录项对象使用计数器,可以有未使用态,使用态和负状态unsigned int d_flags;

目录项标志struct inode * d_inode;

与文件名关联的索引节点struct dentry * d_parent;

父目录的目录项对象struct list_head d_hash;

散列表表项的指针struct list_head d_lru;

未使用链表的指针struct list_head d_child;

父目录中目录项对象的链表的指针struct list_head d_subdirs;

对目录而言,表示子目录目录项对象的链表struct list_head d_alias;

相关索引节点(别名)的链表int d_mounted; 对于安装点而言,表示被安装文件系统根项struct qstr d_name;

文件名unsigned long d_time;

struct dentry_operations

*d_op; 目录项方法struct super_block * d_sb;

文件的超级块对象vunsigned long

d_vfs_flags;void * d_fsdata; 与文件系统相关的数据unsigned char d_iname

[DNAME_INLINE_LEN]; 存放短文件名};1.3 struct

files_struct对于每个进程,包含一个files_struct结构,用来记录文件描述符的使用情况,定义在include/linux/file.h中struct

files_struct{atomic_t count; 使用该表的进程数struct fdtable

*fdt;struct fdtable

fdtab;spinlock_t file_lock

____cacheline_aligned_in_smp;int next_fd; 数值最小的最近关闭文件的文件描述符,下一个可用的文件描述符struct embedded_fd_set

close_on_exec_init; 执行exec时需要关闭的文件描述符初值集合struct embedded_fd_set

open_fds_init; 文件描述符的屏蔽字初值集合struct file *

fd_array[NR_OPEN_DEFAULT]; 默认打开的fd队列};struct fdtable

{unsigned int

max_fds;struct file ** fd;

指向打开的文件描述符列表的指针,开始的时候指向fd_array,当超过max_fds时,重新分配地址fd_set *close_on_exec;

执行exec需要关闭的文件描述符位图(fork,exec即不被子进程继承的文件描述符)fd_set *open_fds;

打开的文件描述符位图struct rcu_head

rcu;struct fdtable

*next;};1.4 struct

fs_structstruct fs_struct

{atomic_t

count; 计数器rwlock_t lock; 读写锁int umask;struct dentry * root, * pwd, *

altroot;根目录("/"),当前目录以及替换根目录struct vfsmount * rootmnt, * pwdmnt,

* altrootmnt;};1.5 struct

inode索引节点对象由inode结构体表示,定义文件在linux/fs.h中。struct inode

{struct

hlist_node i_hash; 哈希表struct list_head i_list;

索引节点链表struct list_head i_dentry;

目录项链表unsigned long i_ino;

节点号atomic_t i_count;

引用记数umode_t i_mode; 访问权限控制unsigned int i_nlink;

硬链接数uid_t i_uid; 使用者idgid_t i_gid; 使用者id组kdev_t i_rdev; 实设备标识符loff_t i_size; 以字节为单位的文件大小struct timespec i_atime;

最后访问时间struct timespec i_mtime;

最后修改(modify)时间struct timespec i_ctime;

最后改变(change)时间unsigned int i_blkbits;

以位为单位的块大小unsigned long i_blksize;

以字节为单位的块大小unsigned long

i_version; 版本号unsigned long i_blocks;

文件的块数unsigned short i_bytes;

使用的字节数spinlock_t i_lock;

自旋锁struct rw_semaphore

i_alloc_sem; 索引节点信号量struct inode_operations

*i_op; 索引节点操作表struct file_operations

*i_fop; 默认的索引节点操作struct super_block *i_sb;

相关的超级块struct file_lock *i_flock;

文件锁链表struct address_space

*i_mapping; 相关的地址映射struct address_space i_data;

设备地址映射struct dquot

*i_dquot[MAXQUOTAS];节点的磁盘限额struct list_head i_devices;

块设备链表struct pipe_inode_info

*i_pipe; 管道信息struct block_device *i_bdev;

块设备驱动unsigned long

i_dnotify_mask;目录通知掩码struct dnotify_struct

*i_dnotify; 目录通知unsigned long i_state;

状态标志unsigned long

dirtied_when;首次修改时间unsigned int i_flags;

文件系统标志unsigned char i_sock;

套接字atomic_t i_writecount;

写者记数void *i_security;

安全模块__u32 i_generation;

索引节点版本号union {void *generic_ip;文件特殊信息} u;};

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值