本文允许转载,但请标明出处:http://blog.csdn.net/u010944778/article/details/45077565
file_operations:
struct file_operations { ssize_t (*read)(struct file *,char *, size_t, loff_t *);//从设备同步读取数据 ssize_t (*write)(struct file *,const char *, size_t, loff_t *); int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);//执行设备IO控制命令 int (*open) (struct inode *, struct file *);//打开 int (*release)(struct inode *, struct file *);//关闭 };
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
具体到应用程序中:
fd=open("/dev/hello",O_RDWR)
通过系统调用open()来打开设备文件,此设备节点对应有一个设备号。
打开 /dev/hello时,通过主次设备号找到相应的字符驱动程序。即在cdev链表中找到cdev这个结构体,
cdev里面又包含了file_operations结构体,含有对设备的各种操作,打开时即调用里面的.open 函数指针指向的open函数。
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
struct file { mode_t f_mode;//表示文件是否可读或可写,FMODE_READ或FMODE_WRITE dev_ t f_rdev ;// 用于/dev/tty off_t f_ops;//当前文件位移 unsigned short f_flags;//文件标志,O_RDONLY,O_NONBLOCK和O_SYNC unsigned short f_count;//打开的文件数目 unsigned short f_reada; struct inode *f_inode;//指向inode的结构指针 struct file_operations *f_op;//文件索引指针 }
http://liurugongzi.blog.sohu.com/104834407.html
http://blog.csdn.net/dreaming_my_dreams/article/details/8272586