file_operations结构

/************************************
Linux中字符设备驱动程序的主要功能是实现设备的读写和控制接口。
对于字符设备驱动程序,最核心的就是file_operations结构,它的第个成员函数一般都对应一个系统调用。
用户进程利用系统调用对设备文件进行诸如读和写等操作时,系统调用设备文件的主设备号找到相应的设备驱动程序,并调用相应的驱动程序函数。

如:
struct file_operations *fops;
-----------------------
User(应用程序)
fd = open("/dev/XX");
-----------------------
VFS(虚拟文件系统)
-----------------------
Driver(设备驱动)
fope->open()
-----------------------
Hardware(硬件设备)
-----------------------
************************************/
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(*aro_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);//在不使用BLK的文件系统中ioctl替代
	long (*compat_ioctl)(struct file *, unsigned int, unsigned long);//在64位系统上处理32位的ioctl调用
	int (*mmap)(struct file *, struct vm_area_struct *);//地址映射
	int (*open)(struct inode *, struct file *);//打开
	int (*flush)(struct file *, fl_owner_t id);//执行未0完成的操作
	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);//通知设备FASYNC标志发生变化
	int (*lock)(struct file *, int, struct file_lock *);//文件锁
	ssize_t(*sendpage)(struct file *, struct page *, int, size_t, lofft*, int);//发送数据,一次一页
	unsigned long(*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);//获取未映射区
	int (*check_flags)(int);//检查传递给fcntl(fd, F_SETEL...)调用的标志
	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 **);	
};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值