summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2021-10-18 12:11:02 +0200
committerJens Axboe <axboe@kernel.dk>2021-10-18 22:43:22 +0200
commit6436bd90f76e75d2c5786a50203b05a9b7f7100d (patch)
tree42be0dddf22b8518f4ca2cd0c6d5d9995844e750
parentblock: move the SECTOR_SIZE related definitions to blk_types.h (diff)
downloadlinux-6436bd90f76e75d2c5786a50203b05a9b7f7100d.tar.xz
linux-6436bd90f76e75d2c5786a50203b05a9b7f7100d.zip
block: add a bdev_nr_bytes helper
Add a helper to query the size of a block device in bytes. This will be used to remove open coded access to ->bd_inode. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/r/20211018101130.1838532-3-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--include/linux/genhd.h7
1 files changed, 6 insertions, 1 deletions
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index cd4038fd5743..01d27f3a970e 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -236,9 +236,14 @@ static inline sector_t get_start_sect(struct block_device *bdev)
return bdev->bd_start_sect;
}
+static inline loff_t bdev_nr_bytes(struct block_device *bdev)
+{
+ return i_size_read(bdev->bd_inode);
+}
+
static inline sector_t bdev_nr_sectors(struct block_device *bdev)
{
- return i_size_read(bdev->bd_inode) >> 9;
+ return bdev_nr_bytes(bdev) >> SECTOR_SHIFT;
}
static inline sector_t get_capacity(struct gendisk *disk)