Skip to content

Commit 97eeb5f

Browse files
Christoph Hellwigaxboe
authored andcommitted
partitions/ibm: use bdev_nr_sectors instead of open coding it
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]> Link: https://lore.kernel.org/r/[email protected] [axboe: fix comment typo] Signed-off-by: Jens Axboe <[email protected]>
1 parent f9831b8 commit 97eeb5f

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

block/partitions/ibm.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ static int find_lnx1_partitions(struct parsed_partitions *state,
198198
char name[],
199199
union label_t *label,
200200
sector_t labelsect,
201-
loff_t i_size,
201+
sector_t nr_sectors,
202202
dasd_information2_t *info)
203203
{
204204
loff_t offset, geo_size, size;
@@ -213,14 +213,14 @@ static int find_lnx1_partitions(struct parsed_partitions *state,
213213
} else {
214214
/*
215215
* Formated w/o large volume support. If the sanity check
216-
* 'size based on geo == size based on i_size' is true, then
216+
* 'size based on geo == size based on nr_sectors' is true, then
217217
* we can safely assume that we know the formatted size of
218218
* the disk, otherwise we need additional information
219219
* that we can only get from a real DASD device.
220220
*/
221221
geo_size = geo->cylinders * geo->heads
222222
* geo->sectors * secperblk;
223-
size = i_size >> 9;
223+
size = nr_sectors;
224224
if (size != geo_size) {
225225
if (!info) {
226226
strlcat(state->pp_buf, "\n", PAGE_SIZE);
@@ -229,7 +229,7 @@ static int find_lnx1_partitions(struct parsed_partitions *state,
229229
if (!strcmp(info->type, "ECKD"))
230230
if (geo_size < size)
231231
size = geo_size;
232-
/* else keep size based on i_size */
232+
/* else keep size based on nr_sectors */
233233
}
234234
}
235235
/* first and only partition starts in the first block after the label */
@@ -293,7 +293,8 @@ int ibm_partition(struct parsed_partitions *state)
293293
struct gendisk *disk = state->disk;
294294
struct block_device *bdev = disk->part0;
295295
int blocksize, res;
296-
loff_t i_size, offset, size;
296+
loff_t offset, size;
297+
sector_t nr_sectors;
297298
dasd_information2_t *info;
298299
struct hd_geometry *geo;
299300
char type[5] = {0,};
@@ -308,8 +309,8 @@ int ibm_partition(struct parsed_partitions *state)
308309
blocksize = bdev_logical_block_size(bdev);
309310
if (blocksize <= 0)
310311
goto out_symbol;
311-
i_size = i_size_read(bdev->bd_inode);
312-
if (i_size == 0)
312+
nr_sectors = bdev_nr_sectors(bdev);
313+
if (nr_sectors == 0)
313314
goto out_symbol;
314315
info = kmalloc(sizeof(dasd_information2_t), GFP_KERNEL);
315316
if (info == NULL)
@@ -336,7 +337,7 @@ int ibm_partition(struct parsed_partitions *state)
336337
label);
337338
} else if (!strncmp(type, "LNX1", 4)) {
338339
res = find_lnx1_partitions(state, geo, blocksize, name,
339-
label, labelsect, i_size,
340+
label, labelsect, nr_sectors,
340341
info);
341342
} else if (!strncmp(type, "CMS1", 4)) {
342343
res = find_cms1_partitions(state, geo, blocksize, name,
@@ -353,7 +354,7 @@ int ibm_partition(struct parsed_partitions *state)
353354
res = 1;
354355
if (info->format == DASD_FORMAT_LDL) {
355356
strlcat(state->pp_buf, "(nonl)", PAGE_SIZE);
356-
size = i_size >> 9;
357+
size = nr_sectors;
357358
offset = (info->label_block + 1) * (blocksize >> 9);
358359
put_partition(state, 1, offset, size-offset);
359360
strlcat(state->pp_buf, "\n", PAGE_SIZE);

0 commit comments

Comments
 (0)