一、设备驱动概念
设备驱动完成以下功能:
1.对设备的初始化和释放
2.把数据从内核传送到硬件和从硬件读取数据
3.读取应用程序传送给设备文件和回送应用程序请求的数据
4.检测和处理设备出现的错误
可分为字符设备和块设备。
区别:字符设备发出请求后,实际的I/O要紧接着发生;块设备利用一块系统缓冲区,缓冲区的内容可以满足用户请求,直接返回,不能的话,调用实际I/O。
主设备号:驱动程序
次设备号:同一驱动下不同设备
应用程序通过系统调用来使用驱动程序,系统调用如下:
struct file_operations {
int (*seek) (struct inode * ,struct file *, off_t ,int);
int (*read) (struct inode * ,struct file *, char ,int);
int (*write) (struct inode * ,struct file *, off_t ,int);
int (*readdir) (struct inode * ,struct file *, struct dirent * ,int);
int (*select) (struct inode * ,struct file *, int ,select_table *);
int (*ioctl) (struct inode * ,struct file *, unsined int ,unsigned long
int (*mmap) (struct inode * ,struct file *, struct vm_area_struct *);
int (*open) (struct inode * ,struct file *);
int (*release) (struct inode * ,struct file *);
int (*fsync) (struct inode * ,struct file *);
int (*fasync) (struct inode * ,struct file *,int);
int (*check_media_change) (struct inode * ,struct file *);
int (*revalidate) (dev_t dev);
}
驱动程序主要是实现这些系统调用。