首页 百科知识 文件操作函数

文件操作函数

时间:2022-10-09 百科知识 版权反馈
【摘要】:file中f_op指向的file_operations结构是面向文件进行操作的接口是VFS提供的向各种物理文件系统的文件操作函数进行转换的统一接口。dirent类似于EXT2文件的目录项结构ext2_dir_entry。inode和file指定了操作对象的设备文件,type指定操作类型:type =SEL_IN为从设备读取,type =SEL_OUT为向设备写入。该操作函数应该属于inode_operations结构,把它置于file_operations之中是因为通过file结构更便于对文件的操作。

6.4.3 文件操作函数

file中f_op指向的file_operations结构是面向文件进行操作的接口是VFS提供的向各种物理文件系统的文件操作函数进行转换的统一接口。

struct file_operations {

 int (*lseek) (struct inode *, struct file *, off_t, int);

 int (*read) (struct inode *, struct file *, char *, int);

 int (*write) (struct inode *, struct file *, const char *, int);

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

 int (*select) (struct inode *, struct file *, int, select_table *);

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

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

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

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

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

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

 int (*check_media_change) (kdev_t dev);

 int (*revalidate) (kdev_t dev);

};

lseek(inode, file, offset,origin):文件定位函数,用于改变文件内部位置指针的值。

read(inode,file,buffer,count):读文件函数,读取inode对应的文件,count指定了读取的字节数,读取的数据置入以buffer为首址的内存区域。

write(inode,file,buffer,count):写文件函数,把内存buffer缓冲区的数据写入inode对应文件中,count为写入数据的字节数。

readdir(inode,file,dirent,count):读目录函数,从inode对应的目录项结构体dirent中读取数据。dirent类似于EXT2文件的目录项结构ext2_dir_entry。

select(inode,file,type,wait):文件读写检测函数,检测能否对设备进行读或写操作。inode和file指定了操作对象的设备文件,type指定操作类型:type =SEL_IN为从设备读取,type =SEL_OUT为向设备写入。当wait不为NULL时,在设备可以利用之前进程等待。

ioctl(inode, file,cmd,arg):参数变更函数,用于对设备文件的某些参数的变更。

mmap(inode, file, vm_area):文件映射函数,把文件的一部分映射到用户的虚拟内存区域。vm_area是映射文件对应的vm_area_struct结构体。

open(inode, file):文件打开函数。在进程打开一个文件调用。该操作函数应该属于inode_operations结构,把它置于file_operations之中是因为通过file结构更便于对文件的操作。

release(inode, file):file结构释放函数,当file结构的f_count为0时调用此函数释放该结构体。

fsync(inode, file):文件同步函数,当文件在缓冲区中的内容被修改时,调用该函数把其内容写回外存的该文件中。

fasync(inode,file,on):文件异步函数,用于终端设备和网络套接口的异步I/O操作。

check_media_change(dev):媒体检测函数,检测非固定连接媒体的设备是否已发生变更,若已变更返值为1,无变更返值为0。

revalidate(dev):媒体重置函数,当非固定连接媒体设备发生变更时,调用该函数重新设置该媒体对应的各个数据结构中的有关数据。

免责声明:以上内容源自网络,版权归原作者所有,如有侵犯您的原创版权请告知,我们将尽快删除相关内容。

我要反馈