Skip to content

Commit 946e993

Browse files
Christoph Hellwigaxboe
authored andcommitted
block/ioctl: use bdev_nr_sectors and bdev_nr_bytes
Use the proper helper to read the block device size. Signed-off-by: Christoph Hellwig <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent f09313c commit 946e993

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

block/ioctl.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ static int blk_ioctl_discard(struct block_device *bdev, fmode_t mode,
132132
if (len & 511)
133133
return -EINVAL;
134134

135-
if (start + len > i_size_read(bdev->bd_inode))
135+
if (start + len > bdev_nr_bytes(bdev))
136136
return -EINVAL;
137137

138138
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,
164164
return -EINVAL;
165165
if (len & 511)
166166
return -EINVAL;
167-
if (end >= (uint64_t)i_size_read(bdev->bd_inode))
167+
if (end >= (uint64_t)bdev_nr_bytes(bdev))
168168
return -EINVAL;
169169
if (end < start)
170170
return -EINVAL;
@@ -543,7 +543,6 @@ long blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
543543
struct block_device *bdev = I_BDEV(file->f_mapping->host);
544544
void __user *argp = (void __user *)arg;
545545
fmode_t mode = file->f_mode;
546-
loff_t size;
547546
int ret;
548547

549548
/*
@@ -570,18 +569,17 @@ long blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
570569
return put_long(argp,
571570
(bdev->bd_disk->bdi->ra_pages * PAGE_SIZE) / 512);
572571
case BLKGETSIZE:
573-
size = i_size_read(bdev->bd_inode);
574-
if ((size >> 9) > ~0UL)
572+
if (bdev_nr_sectors(bdev) > ~0UL)
575573
return -EFBIG;
576-
return put_ulong(argp, size >> 9);
574+
return put_ulong(argp, bdev_nr_sectors(bdev));
577575

578576
/* The data is compatible, but the command number is different */
579577
case BLKBSZGET: /* get block device soft block size (cf. BLKSSZGET) */
580578
return put_int(argp, block_size(bdev));
581579
case BLKBSZSET:
582580
return blkdev_bszset(bdev, mode, argp);
583581
case BLKGETSIZE64:
584-
return put_u64(argp, i_size_read(bdev->bd_inode));
582+
return put_u64(argp, bdev_nr_bytes(bdev));
585583

586584
/* Incompatible alignment on i386 */
587585
case BLKTRACESETUP:
@@ -615,7 +613,6 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
615613
struct block_device *bdev = I_BDEV(file->f_mapping->host);
616614
struct gendisk *disk = bdev->bd_disk;
617615
fmode_t mode = file->f_mode;
618-
loff_t size;
619616

620617
/*
621618
* O_NDELAY can be altered using fcntl(.., F_SETFL, ..), so we have
@@ -641,18 +638,17 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
641638
return compat_put_long(argp,
642639
(bdev->bd_disk->bdi->ra_pages * PAGE_SIZE) / 512);
643640
case BLKGETSIZE:
644-
size = i_size_read(bdev->bd_inode);
645-
if ((size >> 9) > ~0UL)
641+
if (bdev_nr_sectors(bdev) > ~0UL)
646642
return -EFBIG;
647-
return compat_put_ulong(argp, size >> 9);
643+
return compat_put_ulong(argp, bdev_nr_sectors(bdev));
648644

649645
/* The data is compatible, but the command number is different */
650646
case BLKBSZGET_32: /* get the logical block size (cf. BLKSSZGET) */
651647
return put_int(argp, bdev_logical_block_size(bdev));
652648
case BLKBSZSET_32:
653649
return blkdev_bszset(bdev, mode, argp);
654650
case BLKGETSIZE64_32:
655-
return put_u64(argp, i_size_read(bdev->bd_inode));
651+
return put_u64(argp, bdev_nr_bytes(bdev));
656652

657653
/* Incompatible alignment on i386 */
658654
case BLKTRACESETUP32:

0 commit comments

Comments
 (0)