/* Return the number of hardware sectors between beginning of bio and an end point indicated by a bio_vec index and an offset within that vector's page.  */
sector_t bio_sector_offset(struct bio *bio, unsigned short index, unsigned int offset)
/* Return the number of hardware sectors between beginning of bio and an end point indicated by a bio_vec index and an offset within that vector's page.  */
sector_t bio_sector_offset(struct bio *bio, unsigned short index, unsigned int offset)
{
	unsigned int sector_sz;
	struct bio_vec *bv;
	sector_t sectors;
	int i;
	sector_sz = queue_logical_block_size(bio->bi_bdev->bd_disk->queue);
	sectors = 0;
	if (index >= bio->bi_idx)
		index = bio->bi_vcnt - 1;
	__bio_for_each_segment(bv, bio, i, 0) {
		if (i == index) {
			if (offset > bv->bv_offset)
				sectors += (offset - bv->bv_offset) / sector_sz;
			break;
		}
		sectors += bv->bv_len / sector_sz;
	}
	return sectors;
}