block: add a sb_bdev_nr_blocks helper
authorChristoph Hellwig <hch@lst.de>
Mon, 18 Oct 2021 10:11:25 +0000 (12:11 +0200)
committerJens Axboe <axboe@kernel.dk>
Mon, 18 Oct 2021 20:43:23 +0000 (14:43 -0600)
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>
Link: https://lore.kernel.org/r/20211018101130.1838532-26-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
include/linux/genhd.h

index 01d27f3..7b03266 100644 (file)
@@ -251,6 +251,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);