diff mbox series

[25/30] block: add a sb_bdev_nr_blocks helper

Message ID 20211018101130.1838532-26-hch@lst.de (mailing list archive)
State New, archived
Headers show
Series [01/30] block: move the SECTOR_SIZE related definitions to blk_types.h | expand

Commit Message

Christoph Hellwig Oct. 18, 2021, 10:11 a.m. UTC
Add a helper to return the size of sb->s_bdev in sb->s_blocksize_bits
based unites.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 include/linux/genhd.h | 6 ++++++
 1 file changed, 6 insertions(+)
diff mbox series

Patch

diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index b560aee1d69f0..7a48d3ac725f3 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -250,6 +250,12 @@  static inline sector_t get_capacity(struct gendisk *disk)
 	return bdev_nr_sectors(disk->part0);
 }
 
+static inline u64 sb_bdev_nr_blocks(struct super_block *sb)
+{
+	return bdev_nr_sectors(sb->s_bdev) >>
+		(sb->s_blocksize_bits - SECTOR_SHIFT);
+}
+
 int bdev_disk_changed(struct gendisk *disk, bool invalidate);
 void blk_drop_partitions(struct gendisk *disk);