分类: LINUX
2010-11-06 21:16:45
file_operations结构体定义在
下边是摘自Linux内核的源码:
struct file_operations {
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日编辑了该文章文章。
chinaunix网友2010-11-07 19:02:33
很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com