新闻中心

EEPW首页 > 嵌入式系统 > 设计应用 > file_operations下函数详解

file_operations下函数详解

作者:时间:2011-06-21来源:网络收藏

struct {

struct module *owner;

// 指向拥有该结构的模块的指针,避免正在操作时被卸载,一般为初始化为THIS_MODULES

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

// llseek用来修改文件当前的读写位置,返回新位置

// loff_t为一个长偏移量。当此指针为空,seek调用将会以不可预期的方式修改file结构中的位置计数器。

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

// 从设备中同步读取数据。读取成功返回读取的字节数。设置为NULL,调用时返回-EINVAL

ssize_t (*aio_read) (struct kiocb *, char __user *, size_t, loff_t);

// 初始化一个异步的读取操作,为NULL时全部通过read处理

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

// 向设备发送数据。

ssize_t (*aio_write) (struct kiocb *, const char __user *, size_t, loff_t);

// 初始化一个异步的写入操作。

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

// 仅用于读取目录,对于设备文件,该字段为 NULL

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

// 返回一个位掩码,用来指出非阻塞的读取或写入是否可能。

// 将pool定义为 NULL,设备会被认为即可读也可写。

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

// 提供一种执行设备特殊命令的方法。不设置入口点,返回-ENOTTY

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 *);

// 用于请求将设备内存映射到进程地址空间。如果无此方法,将访问-ENODEV。

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

// 如果为空,设备的打开操作永远成功,但系统不会通知驱动程序

// 由VFS调用,当VFS打开一个文件,即建立了一个新的struct file,之后调用open方法分配文件结构。open属于struct

inode_operations。

int (*flush) (struct file *);

// 发生在进程关闭设备文件描述符副本,执行并等待,若设置为NULL,内核将忽略用户应用程序的请求。

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

// file结构释放时,将调用此指针函数,release与open相同可设置为NULL

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


上一页 1 2 下一页

评论


相关推荐

技术专区

关闭