aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/bio.c36
-rw-r--r--include/linux/bio.h1
2 files changed, 37 insertions, 0 deletions
diff --git a/fs/bio.c b/fs/bio.c
index e56e7685af9c..a5af5809f566 100644
--- a/fs/bio.c
+++ b/fs/bio.c
@@ -1300,6 +1300,42 @@ struct bio_pair *bio_split(struct bio *bi, mempool_t *pool, int first_sectors)
1300 return bp; 1300 return bp;
1301} 1301}
1302 1302
1303/**
1304 * bio_sector_offset - Find hardware sector offset in bio
1305 * @bio: bio to inspect
1306 * @index: bio_vec index
1307 * @offset: offset in bv_page
1308 *
1309 * Return the number of hardware sectors between beginning of bio
1310 * and an end point indicated by a bio_vec index and an offset
1311 * within that vector's page.
1312 */
1313sector_t bio_sector_offset(struct bio *bio, unsigned short index,
1314 unsigned int offset)
1315{
1316 unsigned int sector_sz = queue_hardsect_size(bio->bi_bdev->bd_disk->queue);
1317 struct bio_vec *bv;
1318 sector_t sectors;
1319 int i;
1320
1321 sectors = 0;
1322
1323 if (index >= bio->bi_idx)
1324 index = bio->bi_vcnt - 1;
1325
1326 __bio_for_each_segment(bv, bio, i, 0) {
1327 if (i == index) {
1328 if (offset > bv->bv_offset)
1329 sectors += (offset - bv->bv_offset) / sector_sz;
1330 break;
1331 }
1332
1333 sectors += bv->bv_len / sector_sz;
1334 }
1335
1336 return sectors;
1337}
1338EXPORT_SYMBOL(bio_sector_offset);
1303 1339
1304/* 1340/*
1305 * create memory pools for biovec's in a bio_set. 1341 * create memory pools for biovec's in a bio_set.
diff --git a/include/linux/bio.h b/include/linux/bio.h
index d86d39d490e6..fe12d0f9ebaa 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -327,6 +327,7 @@ extern int bio_add_page(struct bio *, struct page *, unsigned int,unsigned int);
327extern int bio_add_pc_page(struct request_queue *, struct bio *, struct page *, 327extern int bio_add_pc_page(struct request_queue *, struct bio *, struct page *,
328 unsigned int, unsigned int); 328 unsigned int, unsigned int);
329extern int bio_get_nr_vecs(struct block_device *); 329extern int bio_get_nr_vecs(struct block_device *);
330extern sector_t bio_sector_offset(struct bio *, unsigned short, unsigned int);
330extern struct bio *bio_map_user(struct request_queue *, struct block_device *, 331extern struct bio *bio_map_user(struct request_queue *, struct block_device *,
331 unsigned long, unsigned int, int, gfp_t); 332 unsigned long, unsigned int, int, gfp_t);
332struct sg_iovec; 333struct sg_iovec;