From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kees Cook Subject: Re: [PATCH 24/29] block: add a sb_bdev_nr_blocks helper Date: Tue, 12 Oct 2021 23:27:42 -0700 Message-ID: <202110122319.3029AE5AA@keescook> References: <20211013051042.1065752-1-hch@lst.de> <20211013051042.1065752-25-hch@lst.de> Mime-Version: 1.0 Return-path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=C7+rA9/qIKI+jEKdGT8jq286cyAFBOUDDboMnfms+Z8=; b=AlEYQ5u0lf8LlpP+7qsCcuJhK1pgOk4qAHuS3VO4jhvcYvvdHIhevJhnSmtjCxYajF GvRWvFMVajscl3jlCv3bKH7RKiMCJHNfpDbORo8xCSB0MCLratUhvvPInP4hPM2sN7/u axF+0KLgxbxN6eO5bdOoxf3QMqBfSL0vk4cKc= Content-Disposition: inline In-Reply-To: <20211013051042.1065752-25-hch-jcswGhMUV9g@public.gmane.org> List-ID: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Christoph Hellwig Cc: Jens Axboe , Coly Li , Mike Snitzer , Song Liu , David Sterba , Josef Bacik , Theodore Ts'o , OGAWA Hirofumi , Dave Kleikamp , Ryusuke Konishi , Anton Altaparmakov , Konstantin Komarov , Phillip Lougher , Jan Kara , linux-block-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, dm-devel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org, drbd-dev-cunTk1MwBs8qoQakbn7OcQ@public.gmane.org, linux-bcache-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-raid-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org, linux-nvme-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org, linux-scsi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, target-devel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org On Wed, Oct 13, 2021 at 07:10:37AM +0200, Christoph Hellwig wrote: > 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. Wouldn't that just need a quick lift into a new header file to be included by genhd.h, blkev.h, and: drivers/mtd/ssfdc.c:#define SECTOR_SHIFT 9 fs/hfsplus/hfsplus_raw.h:#define HFSPLUS_SECTOR_SHIFT 9 I think that's worth doing at some point in this series since genhd.h already has existing open-coded "9"s. And, really, a *lot* of other places too: $ git grep -E '(<<|>>) 9' | grep -E '\b(block|blk|sector|bdev)\b' | wc -l 240 > > Signed-off-by: Christoph Hellwig > --- > include/linux/genhd.h | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/include/linux/genhd.h b/include/linux/genhd.h > index 082a3e5fd8fa1..6eaef8fa78bcd 100644 > --- a/include/linux/genhd.h > +++ b/include/linux/genhd.h > @@ -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); > > -- > 2.30.2 > -- Kees Cook