【原创】Linux系统file_opration结构分析
0赞file_opration操作在linux系统中非常多,今天给大家分析一下这个程序的原理。
file_operations 在内核中定义linux/fs.h
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 *);
unsigned int (*poll) (struct file *, struct poll_table_struct *);
int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);
int (*mmap) (struct file *, struct vm_area_struct *);
int (*open) (struct inode *, struct file *);
int (*release) (struct inode *, struct file *);
int (*fsync) (struct file *, struct dentry *, int datasync);
……
};
其中每个函数的结构及功能如下:
open逆操作
我们自己写的时候按照相关功能调用即可。