]> www.infradead.org Git - users/hch/block.git/commitdiff
block: add a sb_bdev_nr_blocks helper
authorChristoph Hellwig <hch@lst.de>
Mon, 11 Oct 2021 14:45:59 +0000 (16:45 +0200)
committerChristoph Hellwig <hch@lst.de>
Tue, 12 Oct 2021 08:29:35 +0000 (10:29 +0200)
Add a helper to return the size of sb->s_bdev in sb->s_blocksize_bits
based unites.  Note that SECTOR_SHIFT has to be open coded due to
include dependency issues for now, but I have a plan to sort that out
eventually.

Signed-off-by: Christoph Hellwig <hch@lst.de>
include/linux/genhd.h

index c1639c16b74c3ac2544ebe7896e0dd3ba75ff6bd..24ba63995fe47a1b117218165cc05d3a991e32f3 100644 (file)
@@ -245,6 +245,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 - 9 /* SECTOR_SHIFT */);
+}
+
 int bdev_disk_changed(struct gendisk *disk, bool invalidate);
 void blk_drop_partitions(struct gendisk *disk);