partitions/ibm: use bdev_nr_sectors instead of open coding it
authorChristoph Hellwig <hch@lst.de>
Tue, 19 Oct 2021 06:20:24 +0000 (08:20 +0200)
committerJens Axboe <axboe@kernel.dk>
Tue, 19 Oct 2021 12:17:33 +0000 (06:17 -0600)
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 <hch@lst.de>
Link: https://lore.kernel.org/r/20211019062024.2171074-4-hch@lst.de
[axboe: fix comment typo]
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/partitions/ibm.c

index 9bca396aef4adbba2a4b7b6045ec3e438a6c040a..403756dbd50d9aeb6b2f51266d2b875844ef18d2 100644 (file)
@@ -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 nr_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);