块设备驱动 linux3.11.4

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);------------该函数返回数据缓冲区的内核虚拟地址.




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值