more bdev_nr_sectors / bdev_nr_bytes conversions
Subsystems (5)
Hi Jens,
these somehow slipped into a different branch, so here is another small batch.
Diffstat:
ioctl.c | 20 ++++++++------------ partitions/efi.c | 2 +- partitions/ibm.c | 19 ++++++++++--------- 3 files changed, 19 insertions(+), 22 deletions(-)
PATCH 1/3 block/ioctl: use bdev_nr_sectors and bdev_nr_bytes
Use the proper helper to read the block device size.
--- block/ioctl.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)
block/ioctl.c +8 -12
@@ -132,7 +132,7 @@ static int blk_ioctl_discard(struct block_device *bdev, fmode_t mode,if (len &511 )return -EINVAL ; -if (start + len >i_size_read (bdev->bd_inode)) +if (start + len >bdev_nr_bytes (bdev))return -EINVAL ; err =truncate_bdev_range (bdev, mode, start, start + len -1 );
@@ -164,7 +164,7 @@ static int blk_ioctl_zeroout(struct block_device *bdev, fmode_t mode,return -EINVAL ;if (len &511 )return -EINVAL ; -if (end >= (uint64_t )i_size_read (bdev->bd_inode)) +if (end >= (uint64_t )bdev_nr_bytes (bdev))return -EINVAL ;if (end < start)return -EINVAL ;
@@ -543,7 +543,6 @@ long blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)struct block_device *bdev =I_BDEV (file->f_mapping->host);void __user *argp = (void __user *)arg;fmode_t mode = file->f_mode; -loff_t size;int ret;/*
@@ -570,10 +569,9 @@ long blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)return put_long (argp, (bdev->bd_disk->bdi->ra_pages *PAGE_SIZE ) /512 );case BLKGETSIZE : - size =i_size_read (bdev->bd_inode); -if ((size >>9 ) > ~0UL ) +if (bdev_nr_sectors (bdev) > ~0UL )return -EFBIG ; -return put_ulong (argp, size >>9 ); +return put_ulong (argp,bdev_nr_sectors (bdev));/* The data is compatible, but the command number is different */ case BLKBSZGET :/* get block device soft block size (cf. BLKSSZGET) */
@@ -581,7 +579,7 @@ long blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)case BLKBSZSET :return blkdev_bszset (bdev, mode, argp);case BLKGETSIZE64 : -return put_u64 (argp,i_size_read (bdev->bd_inode)); +return put_u64 (argp,bdev_nr_bytes (bdev));/* Incompatible alignment on i386 */ case BLKTRACESETUP :
@@ -615,7 +613,6 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)struct block_device *bdev =I_BDEV (file->f_mapping->host);struct gendisk *disk = bdev->bd_disk;fmode_t mode = file->f_mode; -loff_t size;/* * O_NDELAY can be altered using fcntl(.., F_SETFL, ..), so we have
@@ -641,10 +638,9 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)return compat_put_long (argp, (bdev->bd_disk->bdi->ra_pages *PAGE_SIZE ) /512 );case BLKGETSIZE : - size =i_size_read (bdev->bd_inode); -if ((size >>9 ) > ~0UL ) +if (bdev_nr_sectors (bdev) > ~0UL )return -EFBIG ; -return compat_put_ulong (argp, size >>9 ); +return compat_put_ulong (argp,bdev_nr_sectors (bdev));/* The data is compatible, but the command number is different */ case BLKBSZGET_32 :/* get the logical block size (cf. BLKSSZGET) */
@@ -652,7 +648,7 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)case BLKBSZSET_32 :return blkdev_bszset (bdev, mode, argp);case BLKGETSIZE64_32 : -return put_u64 (argp,i_size_read (bdev->bd_inode)); +return put_u64 (argp,bdev_nr_bytes (bdev));/* Incompatible alignment on i386 */ case BLKTRACESETUP32 :
Signature · 1 line
2.30.2
PATCH 2/3 partitions/efi: use bdev_nr_bytes instead of open coding it
In reply to Christoph HellwigUse the proper helper to read the block device size.
--- block/partitions/efi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/partitions/efi.c +1 -1
@@ -133,7 +133,7 @@ efi_crc32(const void *buf, unsigned long len)*/ static u64 last_lba (struct gendisk *disk) { -return div_u64 (disk->part0->bd_inode->i_size, +return div_u64 (bdev_nr_bytes (disk->part0),queue_logical_block_size (disk->queue)) -1ULL ; }
Signature · 1 line
2.30.2
PATCH 3/3 partitions/ibm: use bdev_nr_sectors instead of open coding it
In reply to Christoph HellwigUse the proper helper to read the block device size and switch various places to pass the size in terms of sectors which is more practical.
--- block/partitions/ibm.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
block/partitions/ibm.c +10 -9
@@ -198,7 +198,7 @@ static int find_lnx1_partitions(struct parsed_partitions *state,char name[], union label_t *label, sector_t labelsect, - loff_t i_size, + sector_t nr_sectors, dasd_information2_t *info) { loff_t offset, geo_size, size;
@@ -213,14 +213,14 @@ static int find_lnx1_partitions(struct parsed_partitions *state, }else {/* * Formated w/o large volume support. If the sanity check -* 'size based on geo == size based on i_size' is true, then +* 'size based on geo == size based on br_sectors' is true, then * we can safely assume that we know the formatted size of * the disk, otherwise we need additional information * that we can only get from a real DASD device. */ geo_size = geo->cylinders * geo->heads * geo->sectors * secperblk; - size = i_size >>9 ; + size = nr_sectors;if (size != geo_size) {if (!info) {strlcat (state->pp_buf,"\n" ,PAGE_SIZE );
@@ -229,7 +229,7 @@ static int find_lnx1_partitions(struct parsed_partitions *state,if (!strcmp (info->type,"ECKD" ))if (geo_size < size) size = geo_size; -/* else keep size based on i_size */ +/* else keep size based on nr_sectors */ } }/* first and only partition starts in the first block after the label */
@@ -293,7 +293,8 @@ int ibm_partition(struct parsed_partitions *state)struct gendisk *disk = state->disk;struct block_device *bdev = disk->part0;int blocksize, res; -loff_t i_size, offset, size; +loff_t offset, size; +sector_t nr_sectors;dasd_information2_t *info;struct hd_geometry *geo;char type[5 ] = {0 ,};
@@ -308,8 +309,8 @@ int ibm_partition(struct parsed_partitions *state) blocksize =bdev_logical_block_size (bdev);if (blocksize <=0 ) goto out_symbol; - i_size =i_size_read (bdev->bd_inode); -if (i_size ==0 ) + nr_sectors =bdev_nr_sectors (bdev); +if (nr_sectors ==0 ) goto out_symbol; info =kmalloc (sizeof (dasd_information2_t),GFP_KERNEL );if (info ==NULL )
@@ -336,7 +337,7 @@ int ibm_partition(struct parsed_partitions *state) label); }else if (!strncmp (type,"LNX1" ,4 )) { res =find_lnx1_partitions (state, geo, blocksize, name, - label, labelsect, i_size, + label, labelsect, nr_sectors, info); }else if (!strncmp (type,"CMS1" ,4 )) { res = find_cms1_partitions(state, geo, blocksize, name,
@@ -353,7 +354,7 @@ int ibm_partition(struct parsed_partitions *state) res =1 ;if (info->format ==DASD_FORMAT_LDL ) {strlcat (state->pp_buf,"(nonl)" ,PAGE_SIZE ); - size = i_size >>9 ; + size = nr_sectors; offset = (info->label_block +1 ) * (blocksize >>9 );put_partition (state,1 , offset, size-offset);strlcat (state->pp_buf,"\n" ,PAGE_SIZE );
Signature · 1 line
2.30.2
Ard Biesheuvel
maintainerRe: [PATCH 3/3] partitions/ibm: use bdev_nr_sectors instead of open coding it
Quoted 23 lines · Christoph Hellwig
Use the proper helper to read the block device size and switch various places to pass the size in terms of sectors which is more practical.
Signed-off-by Christoph Hellwig <[email protected]>--- block/partitions/ibm.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)block/partitions/ibm.c +1
-1@@ -198,7 +198,7 @@ static int find_lnx1_partitions(struct parsed_partitions *state,char name[], union label_t *label, sector_t labelsect, - loff_t i_size, + sector_t nr_sectors, dasd_information2_t *info) { loff_t offset, geo_size, size;
block/partitions/ibm.c static int find_lnx1_partitions(struct parsed_partitions *state, · line 216
Quoted 5 lines
block/partitions/ibm.c +1
-1@@ -213,14 +213,14 @@ static int find_lnx1_partitions(struct parsed_partitions *state, }else {/* * Formated w/o large volume support. If the sanity check -* 'size based on geo == size based on i_size' is true, then +* 'size based on geo == size based on br_sectors' is true,
nr_sectors
Quoted 62 lines
block/partitions/ibm.c +8
-8* we can safely assume that we know the formatted size of * the disk, otherwise we need additional information * that we can only get from a real DASD device. */ geo_size = geo->cylinders * geo->heads * geo->sectors * secperblk; - size = i_size >>9 ; + size = nr_sectors;if (size != geo_size) {if (!info) {strlcat (state->pp_buf,"\n" ,PAGE_SIZE );@@ -229,7 +229,7 @@ static int find_lnx1_partitions(struct parsed_partitions *state,if (!strcmp (info->type,"ECKD" ))if (geo_size < size) size = geo_size; -/* else keep size based on i_size */ +/* else keep size based on nr_sectors */ } }/* first and only partition starts in the first block after the label */ @@ -293,7 +293,8 @@ int ibm_partition(struct parsed_partitions *state)struct gendisk *disk = state->disk;struct block_device *bdev = disk->part0;int blocksize, res; -loff_t i_size, offset, size; +loff_t offset, size; +sector_t nr_sectors;dasd_information2_t *info;struct hd_geometry *geo;char type[5 ] = {0 ,};@@ -308,8 +309,8 @@ int ibm_partition(struct parsed_partitions *state) blocksize =bdev_logical_block_size (bdev);if (blocksize <=0 ) goto out_symbol; - i_size =i_size_read (bdev->bd_inode); -if (i_size ==0 ) + nr_sectors =bdev_nr_sectors (bdev); +if (nr_sectors ==0 ) goto out_symbol; info =kmalloc (sizeof (dasd_information2_t),GFP_KERNEL );if (info ==NULL )@@ -336,7 +337,7 @@ int ibm_partition(struct parsed_partitions *state) label); }else if (!strncmp (type,"LNX1" ,4 )) { res =find_lnx1_partitions (state, geo, blocksize, name, - label, labelsect, i_size, + label, labelsect, nr_sectors, info); }else if (!strncmp (type,"CMS1" ,4 )) { res = find_cms1_partitions(state, geo, blocksize, name,@@ -353,7 +354,7 @@ int ibm_partition(struct parsed_partitions *state) res =1 ;if (info->format ==DASD_FORMAT_LDL ) {strlcat (state->pp_buf,"(nonl)" ,PAGE_SIZE ); - size = i_size >>9 ; + size = nr_sectors; offset = (info->label_block +1 ) * (blocksize >>9 );put_partition (state,1 , offset, size-offset);strlcat (state->pp_buf,"\n" ,PAGE_SIZE ); --2.30.2
Quoted 10 lines · Christoph Hellwig
these somehow slipped into a different branch, so here is another small batch.
Diffstat:
ioctl.c | 20 ++++++++------------ partitions/efi.c | 2 +- partitions/ibm.c | 19 ++++++++++--------- 3 files changed, 19 insertions(+), 22 deletions(-)[...]
Applied, thanks!
[1/3] block/ioctl: use bdev_nr_sectors and bdev_nr_bytes
commit: 946e99373037be4841e8b42dcd136e03093c9fd5
[2/3] partitions/efi: use bdev_nr_bytes instead of open coding it
commit: f9831b885709978ed9d16833ceeb3a2ec174a2d2
[3/3] partitions/ibm: use bdev_nr_sectors instead of open coding it
commit: 97eeb5fc14cc4b2091df8b841a07a1ac69f2d762Best regards,
Signature · 1 line
Jens Axboe