3.strcut file---文件结构体
文件结构体代表一个打开的文件,系统中的每个打开的文件在内核空间都有一个关联的 struct file。
原型如下:
struct file { union { struct list_head fu_list; struct rcu_head fu_rcuhead; } f_u; struct path f_path; #define f_dentry f_path.dentry //该成员是对应的 目录结构 。 #define f_vfsmnt f_path.mnt const struct file_operations *f_op; //该操作 是定义文件关联的操作的。内核在执行open时对这个 指针赋值。
atomic_long_t f_count; unsigned int f_flags; //该成员是文件标志。 mode_t f_mode;loff_t f_pos; struct fown_struct f_owner; unsigned int f_uid, f_gid; 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; spinlock_t f_ep_lock; #endif /* #ifdef CONFIG_EPOLL */ struct address_space *f_mapping; #ifdef CONFIG_DEBUG_WRITECOUNT unsigned long f_mnt_write_state; #endif };