Chinaunix首页 | 论坛 | 博客
  • 博客访问: 426201
  • 博文数量: 47
  • 博客积分: 1669
  • 博客等级: 上尉
  • 技术积分: 585
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-04 23:27
文章分类

全部博文(47)

文章存档

2011年(23)

2010年(24)

分类: LINUX

2010-11-06 21:16:45

 

file_operations结构体定义在中,其中包含了一组函数指针,每个打开的文件(在内部由一个file_operations结构的表示)和一组函数关联(通过包含指向一个file_operations结构的f_op字段)。这些操作主要用来实现系统调用,命名为openread等等。我们可以认为文件时一个“对象”,而操作它的函数是“方法”,如果采用面向对象编程的术语来表达iushi:对象申明的动作将作用域本身。

下边是摘自Linux内核的源码:

struct file_operations {

1188         struct module *owner;

1189         loff_t (*llseek) (struct file *, loff_t, int);

1190         ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);

1191         ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);

1192         ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t);

1193         ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t);

1194         int (*readdir) (struct file *, void *, filldir_t);

1195         unsigned int (*poll) (struct file *, struct poll_table_struct *);

1196         int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);

1197         long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);

1198         long (*compat_ioctl) (struct file *, unsigned int, unsigned long);

1199         int (*mmap) (struct file *, struct vm_area_struct *);

1200         int (*open) (struct inode *, struct file *);

1201         int (*flush) (struct file *, fl_owner_t id);

1202         int (*release) (struct inode *, struct file *);

1203         int (*fsync) (struct file *, struct dentry *, int datasync);

1204         int (*aio_fsync) (struct kiocb *, int datasync);

1205         int (*fasync) (int, struct file *, int);

1206         int (*lock) (struct file *, int, struct file_lock *);

1207         ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);

1208         unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);

1209         int (*check_flags)(int);

1210         int (*dir_notify)(struct file *filp, unsigned long arg);

1211         int (*flock) (struct file *, int, struct file_lock *);

1212         ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);

1213         ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);

1214         int (*setlease)(struct file *, long, struct file_lock **);

1215 };

 

其中的重要参数解释如下:

按照惯例,file_operations结构或指向这类结构的指针称为fops(或者相关的其他叫法)。这个结构体中的每一个字段都必须指向驱动程序中实现特定操作的函数,对于不支持的操作,对应的字段可以设置为NULL管理员在2009年8月13日编辑了该文章文章。

-->
阅读(1871) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-11-07 19:02:33

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com