block_device_operations结构体
struct block_device_operations {
int (*open) (struct block_device *, fmode_t);
int (*release) (struct gendisk *, fmode_t);
int (*locked_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
int (*ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
int (*direct_access) (struct block_device *, sector_t,
void **, unsigned long *);
int (*media_changed) (struct gendisk *);
int (*revalidate_disk) (struct gendisk *);
int (*getgeo)(struct block_device *, struct hd_geometry *);
struct module *owner;
};
1.打开和释放
int (*open)(struct inode *inode ,struct file *filp);
int (*release)(struct inode *inode ,struct file *filp);
当设备打开和关闭时将调用它们。
2.IO控制
int (*ioctl)(struct inode *inode,struct file *filp uusignwd intcmd,unsigned long arg)
上述函数是ioctrl()系统调用的实现,块设备包含大量的标准亲球,这些标准请求有linux块设备层处理,因此大部分块设备驱动的ioctrl()函数相当短。
3.介质改变
int (*check_media_change) (kdev_t);
被内核调用来检查是否驱动器中的介质已经改变,如果是,则返回一个非0值,否则返回0.这个函数进时用于支持可移动介质的驱动器。通常需要在驱动中增加一个表示介质状态时否改变的标志变量,非可移动设备的驱动不需要实现这个方法。
4.使介质有效
int (*revalidate) (kdev_t);
该函数被调用来响应一个介质改变,它给驱动一个机会来进行必要的工作使得新介质准备好。
5.获得驱动信息
int (*getgeo)(struct block_device *,struct hd_geometry *);
该函数根据驱动器的几何信息填充一个hd_geometry结构体,hd_geometry结构体包含磁头,扇区,柱面等信息。
6.模块指针
struct module *owner;
通常初始化成THIS_MODULE