1、struct file
这个结构体定义在 linuxsource/include/linux/fs.h 中第960行左右
具体成员如下:
1 struct file { 2 /* 3 * fu_list becomes invalid after file_free is called and queued via 4 * fu_rcuhead for RCU freeing 5 */ 6 union { 7 struct list_head fu_list; 8 struct rcu_head fu_rcuhead; 9 } f_u; 10 struct path f_path; 11 #define f_dentry f_path.dentry 12 #define f_vfsmnt f_path.mnt 13 const struct file_operations *f_op; 14 spinlock_t f_lock; /* f_ep_links, f_flags, no IRQ */ 15 #ifdef CONFIG_SMP 16 int f_sb_list_cpu; 17 #endif 18 atomic_long_t f_count; 19 unsigned int f_flags; 20 fmode_t f_mode; 21 loff_t f_pos; 22 struct fown_struct f_owner; 23 const struct cred *f_cred; 24 struct file_ra_state f_ra; 25 26 u64 f_version; 27 #ifdef CONFIG_SECURITY 28 void *f_security; 29 #endif 30 /* needed for tty driver, and maybe others */ 31 void *private_data; 32 33 #ifdef CONFIG_EPOLL 34 /* Used by fs/eventpoll.c to link all the hooks to this file */ 35 struct list_head f_ep_links; 36 #endif /* #ifdef CONFIG_EPOLL */ 37 struct address_space *f_mapping; 38 #ifdef CONFIG_DEBUG_WRITECOUNT 39 unsigned long f_mnt_write_state; 40 #endif 41 };
从内核来看,每一个打开的文件都需要有一个file结构体来描述它
具体查看
http://blog.csdn.net/wangchaoxjtuse/article/details/6036684
2、struct inode
索引节点对象由inode结构体表示,定义文件在linux/fs.h中。
linux 中每一个文件都需要有一个inode节点来描述

1 struct inode { 2 struct hlist_node i_hash; 哈希表 3 struct list_head i_list; 索引节点链表 4 struct list_head i_dentry; 目录项链表 5 unsigned long i_ino; 节点号 6 atomic_t i_count; 引用记数 7 umode_t i_mode; 访问权限控制 8 unsigned int i_nlink; 硬链接数 9 uid_t i_uid; 使用者id 10 gid_t i_gid; 使用者id组 11 kdev_t i_rdev; 实设备标识符 12 loff_t i_size; 以字节为单位的文件大小 13 struct timespec i_atime; 最后访问时间 14 struct timespec i_mtime; 最后修改(modify)时间 15 struct timespec i_ctime; 最后改变(change)时间 16 unsigned int i_blkbits; 以位为单位的块大小 17 unsigned long i_blksize; 以字节为单位的块大小 18 unsigned long i_version; 版本号 19 unsigned long i_blocks; 文件的块数 20 unsigned short i_bytes; 使用的字节数 21 spinlock_t i_lock; 自旋锁 22 struct rw_semaphore i_alloc_sem; 索引节点信号量 23 struct inode_operations *i_op; 索引节点操作表 24 struct file_operations *i_fop; 默认的索引节点操作 25 struct super_block *i_sb; 相关的超级块 26 struct file_lock *i_flock; 文件锁链表 27 struct address_space *i_mapping; 相关的地址映射 28 struct address_space i_data; 设备地址映射 29 struct dquot *i_dquot[MAXQUOTAS];节点的磁盘限额 30 struct list_head i_devices; 块设备链表 31 struct pipe_inode_info *i_pipe; 管道信息 32 struct block_device *i_bdev; 块设备驱动 33 unsigned long i_dnotify_mask;目录通知掩码 34 struct dnotify_struct *i_dnotify; 目录通知 35 unsigned long i_state; 状态标志 36 unsigned long dirtied_when;首次修改时间 37 unsigned int i_flags; 文件系统标志 38 unsigned char i_sock; 套接字 39 atomic_t i_writecount; 写者记数 40 void *i_security; 安全模块 41 __u32 i_generation; 索引节点版本号 42 union { 43 void *generic_ip;文件特殊信息 44 } u; 45 };