




已阅读5页,还剩1页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Linux 2.6.17.9内核文件系统调用详解本部分主要讲述的是文件I/O操作的2.6.17.9内核版本实现,包括了主要的数据结构、宏定义和函数流程。以下分别讲述open,create,close,read,write,lseek系统调用。1 重要数据结构1.1 struct filestruct file /* * fu_list becomes invalid after file_free is called and queued via * fu_rcuhead for RCU freeing */ union struct list_head fu_list; /文件链表指针 struct rcu_head fu_rcuhead; /rcu链表 f_u; struct dentry *f_dentry; / 文件对应的目录结构 struct vfsmount *f_vfsmnt; / 虚拟文件系统挂载点 const struct file_operations *f_op; / 文件操作函数指针 atomic_t f_count; / 引用计数 unsigned int f_flags; mode_t f_mode; / 文件模式 loff_t f_pos; / 文件offset struct fown_struct f_owner; /文件owner 结构 unsigned int f_uid, f_gid;/文件用户id,组id struct file_ra_state f_ra; / 跟踪上次文件操作状态的结构指针 unsigned long f_version; void *f_security; / hook 文件操作的security结构指针 /* needed for tty driver, and maybe others */ void *private_data; / tty 驱动器所需数据#ifdef CONFIG_EPOLL /* Used by fs/eventpoll.c to link all the hooks to this file */ struct list_head f_ep_links; / EPOLL 机制检测所需链表结构 spinlock_t f_ep_lock; / 兼容早期gcc bug 的标志#endif /* #ifdef CONFIG_EPOLL */ struct address_space *f_mapping; / 地址映射表;1.2 struct fown_structstruct fown_struct rwlock_t lock; /* protects pid, uid, euid fields */ int pid; /* pid or -pgrp where SIGIO should be sent */ uid_t uid, euid; /* uid/euid of process setting the owner */ void *security; /*hook 文件操作的security结构指针*/ int signum; /* posix.1b rt signal to be delivered on IO */;1.3 struct file_ra_state/* Track a single files readahead state*/struct file_ra_state unsigned long start; /* Current window */ unsigned long size; unsigned long flags; /* ra flags RA_FLAG_xxx*/ unsigned long cache_hit; /* cache hit count*/ unsigned long prev_page; /* Cache last read() position */ unsigned long ahead_start; /* Ahead window */ unsigned long ahead_size; unsigned long ra_pages; /* Maximum readahead window */ unsigned long mmap_hit; /* Cache hit stat for mmap accesses */ unsigned long mmap_miss; /* Cache miss stat for mmap accesses */;1.4 struct address_spacestruct address_space struct inode *host; /* owner: inode, block_device */ struct radix_tree_root page_tree; /* radix tree of all pages */ rwlock_t tree_lock; /* and rwlock protecting it */ unsigned int i_mmap_writable;/* count VM_SHARED mappings */ struct prio_tree_root i_mmap; /* tree of private and shared mappings */ struct list_head i_mmap_nonlinear;/*list VM_NONLINEAR mappings */ spinlock_t i_mmap_lock; /* protect tree, count, list */ unsigned int truncate_count; /* Cover race condition with truncate */ unsigned long nrpages; /* number of total pages */ pgoff_t writeback_index;/* writeback starts here */ struct address_space_operations *a_ops; /* methods */ unsigned long flags; /* error bits/gfp mask */ struct backing_dev_info *backing_dev_info; /* device readahead, etc */ spinlock_t private_lock; /* for use by the address_space */ struct list_head private_list; /* ditto */ struct address_space *assoc_mapping; /* ditto */ _attribute_(aligned(sizeof(long);struct address_space_operations int (*writepage)(struct page *page, struct writeback_control *wbc); int (*readpage)(struct file *, struct page *); void (*sync_page)(struct page *); /* Write back some dirty pages from this mapping. */ int (*writepages)(struct address_space *, struct writeback_control *); /* Set a page dirty. Return true if this dirtied it */ int (*set_page_dirty)(struct page *page); int (*readpages)(struct file *filp, struct address_space *mapping, struct list_head *pages, unsigned nr_pages); /* * ext3 requires that a successful prepare_write() call be followed * by a commit_write() call - they must be balanced */ int (*prepare_write)(struct file *, struct page *, unsigned, unsigned); int (*commit_write)(struct file *, struct page *, unsigned, unsigned); /* Unfortunately this kludge is needed for FIBMAP. Dont use it */ sector_t (*bmap)(struct address_space *, sector_t); void (*invalidatepage) (struct page *, unsigned long); int (*releasepage) (struct page *, gfp_t); ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov, loff_t offset, unsigned long nr_segs); struct page* (*get_xip_page)(struct address_space *, sector_t, int); /* migrate the contents of a page to the specified target */ int (*migratepage) (struct page *, struct page *);1.5 struct block_devicestruct block_device dev_t bd_dev; /* not a kdev_t - its a search key */ struct inode * bd_inode; /* will die */ int bd_openers; struct mutex bd_mutex; /* open/close mutex */ struct mutex bd_mount_mutex; /* mount mutex */ struct list_head bd_inodes; void * bd_holder; int bd_holders;#ifdef CONFIG_SYSFS struct list_head bd_holder_list;#endif struct block_device * bd_contains; unsigned bd_block_size; struct hd_struct * bd_part; /* number of times partitions within this device have been opened. */ unsigned bd_part_count; int bd_invalidated; struct gendisk * bd_disk; struct list_head bd_list; struct backing_dev_info *bd_inode_backing_dev_info; /* * Private data. You must have bd_claimed the block_device * to use this. NOTE: bd_claim allows an owner to claim * the same device multiple times, the owner must take special * care to not mess up bd_private for that case. */ unsigned long bd_private;1.6 struct backing_dev_infostruct backing_dev_info unsigned long ra_pages; /* max readahead in PAGE_CACHE_SIZE units */ unsigned long state; /* Always use atomic bitops on this */ unsigned int capabilities; /* Device capabilities */ congested_fn *congested_fn; /* Function pointer if device is md/dm */ void *congested_data; /* Pointer to aux data for congested func */ void (*unplug_io_fn)(struct backing_dev_info *, struct page *); void *unplug_io_data;1.7 struct files_struct对于内核而言,所有打开文件都由文件描述符引用。文件描述符是一个非负整数。当打开一个现存文件或创建一个新文件时,内核向进程返回一个文件描述符。 当读、写一个文件时,用open或creat返回的文件描述符标识该文件,将其作为参数传送给read或write。在POSIX.1应用程序中,文件描述符为常数0、1和2分别代表STDIN_FILENO、STDOUT_FILENO和STDERR_FILENO,意即标准输入,标准输出和标准出错输出,这些常数都定义在头文件;中。 文件描述符的范围是0OPEN_MAX,在目前常用的linux系统中,是32位整形所能表示的整数,即65535,64位机上则更多。/* Open file table structure*/struct files_struct /* * read mostly part */ atomic_t count; /* 引用计数 */ struct fdtable *fdt; /* 文件表指针,指向fdtab */ struct fdtable fdtab;/* 文件表 *
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 骨科四肢创伤术后护理
- 物业经理年终总结
- 网络广告投放合同(样式三)7篇
- 运营类工作汇报
- 腰椎结核病历汇报
- 缺氧性脑病的护理查房
- 全职助理合同5篇
- 公司环卫安全培训课件
- 黑龙江省2025年全国成人高等学校招生统一考试数学(文)复习题库及答案
- 黑龙江省2025年全国成人高等学校招生统一考试英语(高起点)综合练习题及答案
- 幕墙深化设计合同范本
- JJF1033-2023计量标准考核规范
- 人教版三年级下册数学计算题天天练附答案(30天)
- 2024年03月中国工商银行湖南分行2024年度春季校园招考笔试历年参考题库附带答案详解
- 纪委谈话记录模板
- 统编版选择性必修上册7《兼爱》同步练习
- 《儿科病历书写规范》课件
- IDC机房机架装机管理作业指导书
- 2024年内蒙古人力资源和社会保障厅事业单位笔试真题
- 食堂员工服务培训
- 提升心理抗压能力的技巧
评论
0/150
提交评论