Chinaunix首页 | 论坛 | 博客
  • 博客访问: 350903
  • 博文数量: 77
  • 博客积分: 1447
  • 博客等级: 中尉
  • 技术积分: 885
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-21 21:48
文章分类

全部博文(77)

文章存档

2021年(2)

2020年(2)

2016年(3)

2015年(1)

2014年(4)

2013年(1)

2012年(23)

2011年(15)

2010年(26)

分类: LINUX

2012-05-21 20:47:16

include\linux\fs.h
/*
 * NOTE:
 * read, write, poll, fsync, readv, writev, unlocked_ioctl and compat_ioctl
 * can be called without the big kernel lock held in all filesystems.
 */
struct file_operations {
struct module *owner;
loff_t (*llseek) (struct file *, loff_t, int);
ssize_t (*read) (struct file *, char __user *, size_t, loff_t *); 
ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t);
ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t);
int (*readdir) (struct file *, void *, filldir_t);
unsigned int (*poll) (struct file *, struct poll_table_struct *);
int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);
long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
long (*compat_ioctl) (struct file *, unsigned int, unsigned long);
int (*mmap) (struct file *, struct vm_area_struct *);
int (*open) (struct inode *, struct file *);
int (*flush) (struct file *, fl_owner_t id);
int (*release) (struct inode *, struct file *);
int (*fsync) (struct file *, struct dentry *, int datasync);
int (*aio_fsync) (struct kiocb *, int datasync);
int (*fasync) (int, struct file *, int);
int (*lock) (struct file *, int, struct file_lock *);
ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
int (*check_flags)(int);
int (*flock) (struct file *, int, struct file_lock *);
ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
int (*setlease)(struct file *, long, struct file_lock **);
};

struct module   *owner  :  它是指“拥有”该结构的模块的指针。内核使用这个字段避免在模块的操作正在被使用时卸载该模块。几乎在所有情况下,该成员都会被初始化为THIS_MODULE,  其定义在

int (*open) (struct inode *inode, struct file *filp)  :  始终是对设备文件执行的第一个操作,打开设备准备进行I/O操作,第一个参数是一个具体的设备(在内核中表示文件),第二个参数表示一个内核文件对象(打开的文件描述符)。对于单个文件,可能会有许多表示打开的文件描述符的file结构,但它们都指向单个的inode结构。 返回 0 表示打开成功, 返回负数表示失败。如果驱动程序没有提供open 入口(将open设置为NULL),则只要/dev/driver文件存在就认为打开成功。 

int (*release) (struct inode *inode, struct file *filp)  :  这是关闭文件句柄的操作,第一个参数是一个具体的设备(在内核中表示文件),第二个参数表示一个内核文件对象(打开的文件描述符),也可以将release设置为NULL

ssize_t (*read) (struct file *filp, char --user *buf, size_t count, loff_t* f_pos)  : 用来从设备中读取数据。该函数指针被告赋值为NULL时,将导致read 系统调用出错,并返回-EINVAL. 第一个参数是指一个打开的内核文件对象, 第二个参数,表示用户空间的输出缓冲区,每三个参数表示要读取的大小,第四个参数表示,从文件头起的偏大移位置,即读取的位置。函数返回非负值表示成功读取的字节数。

ssize_t (*write) (struct file *filp, const char __user *buf, size_t count, loff_t *f_pos) : 用来向设备写入数据。该函数指针被告赋值为NULL时,将导致write系统调用出错,并返回-EINVAL.第一个参数是指一个打开的内核文件对象, 第二个参数,表示用户空间的输入缓冲区,每三个参数表示要写入的大小,第四个参数表示,从文件头起的偏大移位置,即写入的位置。函数返回非负值表示成功写入的字节数。

loff_t (*llseek) (struct file *filp, loff_t, int)  : 此方法用来修改文件当前的读写位置,并将新位置(正的)做为返回值返回,第一个参数是指一个打开的内核文件对象, 每二个参数是一个长偏移量(在32佯系统也当用64位的数据宽度),第三个参数表示设置方式
SEEK_SET 0
SEEK_CUR 1
SEEK_END 2
出错时返回一个负值,如果将些函数指针设为NULL,对seek的调用将会以某种不可预期的的方式修改file结构中的位置计数器。

阅读(1024) | 评论(0) | 转发(0) |
0

上一篇:MKDEV

下一篇:struct file

给主人留下些什么吧!~~