struct block_device_operations {
int (*open) (struct block_device *, fmode_t);
void (*release) (struct gendisk *, fmode_t);
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 *);
unsigned int (*check_events) (struct gendisk *disk,
unsigned int clearing);
/* ->media_changed() is DEPRECATED, use ->check_events() instead */
int (*media_changed) (struct gendisk *);
void (*unlock_native_capacity) (struct gendisk *);
int (*revalidate_disk) (struct gendisk *);
int (*getgeo)(struct block_device *, struct hd_geometry *);
/* this callback is with swap_lock and sometimes page table lock held */
void (*swap_slot_free_notify) (struct block_device *, unsigned long);
struct module *owner;
};
结论:
1 从该结构体定义可以看出,块设备并不提供read() , write()函数,对块设备的读写请求都是以异步方式发送到设备相关的request队列之中。
bio (block io)
通常一个bio对应一个IO请求.IO调度算法可将连续的bio合并成一个请求.所以一个请求包含多个bio.
在内核中,提供了一组函数(宏)用于操作bio
int bio_data_dir(struct bio* bio); -------------该函数用于获得数据传送方向.
int bio_cur_sectors(struct bio* bio ------------该函数返回当前bio_vec要传输的扇区数.
struct page* bio_page(struct bio* bio);----------该函数用于获得目前的页指针.
int bio_offset(struct bio* bio);-----------该函数返回操作对应的当前页的页内偏移,通常块IO操作本身就是页对齐的.
char* bio_data(struct bio* bio);------------该函数返回数据缓冲区的内核虚拟地址.