linux字符设备驱动程序相关的数据结构及操作
2006-12-07 11:53
597 查看
以下数据结构以内核2.4.0为例:
file结构(定义在<linux/fs.h>中):
struct file {
struct list_head f_list;
struct dentry *f_dentry;
struct vfsmount *f_vfsmnt;
struct file_operations *f_op;
atomic_t f_count;
unsigned int f_flags;
mode_t f_mode;
loff_t f_pos;
unsigned long f_reada, f_ramax, f_raend, f_ralen, f_rawin;
struct fown_struct f_owner;
unsigned int f_uid, f_gid;
int f_error;
unsigned long f_version;
/* needed for tty driver, and maybe others */
void *private_data;
};
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 *, size_t, loff_t *);
ssize_t (*write) (struct file *, const char *, size_t, 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);
int (*mmap) (struct file *, struct vm_area_struct *);
int (*open) (struct inode *, struct file *);
int (*flush) (struct file *);
int (*release) (struct inode *, struct file *);
int (*fsync) (struct file *, struct dentry *, int datasync);
int (*fasync) (int, struct file *, int);
int (*lock) (struct file *, int, struct file_lock *);
ssize_t (*readv) (struct file *, const struct iovec *, unsigned long, loff_t *);
ssize_t (*writev) (struct file *, const struct iovec *, unsigned long, loff_t *);
};
在2.4.0内核的file和file_operations的结构与O'Reilly的《Linux设备驱动程序》所讲的版本有些不一样:
比如在O'Reilly的书中所讲file结构有一个struct inode成员,而在2.4.0版本中却没有,但是它有个struct dentry成员,而在struct dentry包含了struct inode。
再如file_operations,read, write函数原型同样是四个参数,但2.4.0中,与O'Reilly的书中所讲的版本相比少了inode结构指针的参数,但是多了一个loff_t的文件偏移指针,因此在实际的编写驱动程序时要注意一下内核的版本问题。
file结构(定义在<linux/fs.h>中):
struct file {
struct list_head f_list;
struct dentry *f_dentry;
struct vfsmount *f_vfsmnt;
struct file_operations *f_op;
atomic_t f_count;
unsigned int f_flags;
mode_t f_mode;
loff_t f_pos;
unsigned long f_reada, f_ramax, f_raend, f_ralen, f_rawin;
struct fown_struct f_owner;
unsigned int f_uid, f_gid;
int f_error;
unsigned long f_version;
/* needed for tty driver, and maybe others */
void *private_data;
};
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 *, size_t, loff_t *);
ssize_t (*write) (struct file *, const char *, size_t, 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);
int (*mmap) (struct file *, struct vm_area_struct *);
int (*open) (struct inode *, struct file *);
int (*flush) (struct file *);
int (*release) (struct inode *, struct file *);
int (*fsync) (struct file *, struct dentry *, int datasync);
int (*fasync) (int, struct file *, int);
int (*lock) (struct file *, int, struct file_lock *);
ssize_t (*readv) (struct file *, const struct iovec *, unsigned long, loff_t *);
ssize_t (*writev) (struct file *, const struct iovec *, unsigned long, loff_t *);
};
在2.4.0内核的file和file_operations的结构与O'Reilly的《Linux设备驱动程序》所讲的版本有些不一样:
比如在O'Reilly的书中所讲file结构有一个struct inode成员,而在2.4.0版本中却没有,但是它有个struct dentry成员,而在struct dentry包含了struct inode。
再如file_operations,read, write函数原型同样是四个参数,但2.4.0中,与O'Reilly的书中所讲的版本相比少了inode结构指针的参数,但是多了一个loff_t的文件偏移指针,因此在实际的编写驱动程序时要注意一下内核的版本问题。
相关文章推荐
- Linux设备驱动程序学习(5)-高级字符驱动程序操作〔(2)阻塞型I/O和休眠〕
- Linux设备驱动程序学习 高级字符驱动程序操作[阻塞型I/O和非阻塞I/O]
- 高级字符驱动程序操作(Linux设备驱动程序)
- Linux设备驱动程序——高级字符驱动程序操作(阻塞型I/O)
- Linux设备驱动程序学习(5)-高级字符驱动程序操作[(2)阻塞型I/O和休眠]
- Linux设备驱动程序第三版学习(5)- 高级字符驱动程序操作 - ioctl .
- Linux设备驱动程序第三版学习(5)- 高级字符驱动程序操作 - ioctl .
- Linux设备驱动程序学习(4) -高级字符驱动程序操作[(1)ioctl and llseek]
- 07-S3C2440驱动学习(一)嵌入式linux字符设备驱动-按键驱动程序之异步通知机制+原子操作+互斥信号量+阻塞与非阻塞+定时器去抖
- Linux设备驱动程序第三版学习(6)- 高级字符驱动程序操作(续1)- 进程休眠 .
- Linux设备驱动程序学习(4)-高级字符驱动程序操作[(1)ioctl and llseek]
- Linux设备驱动程序学习(6)-高级字符驱动程序操作-ioctl and llseek
- Linux设备驱动程序学习(6)-高级字符驱动程序操作[(3)设备文件的访问控制]
- Linux设备驱动程序学习(5) -高级字符驱动程序操作[(2)阻塞型I/O和休眠]
- Linux设备驱动程序第三版学习(7)- 高级字符驱动程序操作(续2)- poll/select
- Linux设备驱动程序——高级字符驱动程序操作(poll机制)
- Linux设备驱动程序学习(6)-高级字符驱动程序操作[(4)异步通知fasync]
- Linux设备驱动程序学习(6) -高级字符驱动程序操作[(3)设备文件的访问控制]
- Linux设备驱动程序学习 高级字符驱动程序操作[阻塞型I/O和非阻塞I/O]【转】
- Linux设备驱动程序第三版学习(6)- 高级字符驱动程序操作(续1) - 进程休眠