Commit a08aa9bc authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe
Browse files

block: store a gendisk in struct parsed_partitions



Partition scanning only happens on the whole device, so pass a
struct gendisk instead of the whole device block_device to the scanners.
This allows to simplify printing the device name in various places as the
disk name is available in disk->name.

Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarStefan Haberland <sth@linux.ibm.com>
Link: https://lore.kernel.org/r/20210810154512.1809898-2-hch@lst.de


Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 50b4aecf
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -275,7 +275,7 @@ int adfspart_check_ADFS(struct parsed_partitions *state)
	/*
	 * Work out start of non-adfs partition.
	 */
	nr_sects = (state->bdev->bd_inode->i_size >> 9) - start_sect;
	nr_sects = get_capacity(state->disk) - start_sect;

	if (start_sect) {
		switch (id) {
@@ -540,7 +540,7 @@ int adfspart_check_EESOX(struct parsed_partitions *state)
	if (i != 0) {
		sector_t size;

		size = get_capacity(state->bdev->bd_disk);
		size = get_capacity(state->disk);
		put_partition(state, slot++, start, size - start);
		strlcat(state->pp_buf, "\n", PAGE_SIZE);
	}
+2 −18
Original line number Diff line number Diff line
@@ -66,22 +66,6 @@ struct pvd {

#define LVM_MAXLVS 256

/**
 * last_lba(): return number of last logical block of device
 * @bdev: block device
 *
 * Description: Returns last LBA value on success, 0 on error.
 * This is stored (by sd and ide-geometry) in
 *  the part[0] entry for this disk, and is the number of
 *  physical sectors available on the disk.
 */
static u64 last_lba(struct block_device *bdev)
{
	if (!bdev || !bdev->bd_inode)
		return 0;
	return (bdev->bd_inode->i_size >> 9) - 1ULL;
}

/**
 * read_lba(): Read bytes from disk, starting at given LBA
 * @state
@@ -89,7 +73,7 @@ static u64 last_lba(struct block_device *bdev)
 * @buffer
 * @count
 *
 * Description:  Reads @count bytes from @state->bdev into @buffer.
 * Description:  Reads @count bytes from @state->disk into @buffer.
 * Returns number of bytes read on success, 0 on error.
 */
static size_t read_lba(struct parsed_partitions *state, u64 lba, u8 *buffer,
@@ -97,7 +81,7 @@ static size_t read_lba(struct parsed_partitions *state, u64 lba, u8 *buffer,
{
	size_t totalreadcount = 0;

	if (!buffer || lba + count / 512 > last_lba(state->bdev))
	if (!buffer || lba + count / 512 > get_capacity(state->disk) - 1ULL)
		return 0;

	while (count) {
+3 −4
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@ int amiga_partition(struct parsed_partitions *state)
	int start_sect, nr_sects, blk, part, res = 0;
	int blksize = 1;	/* Multiplier for disk block size */
	int slot = 1;
	char b[BDEVNAME_SIZE];

	for (blk = 0; ; blk++, put_dev_sector(sect)) {
		if (blk == RDB_ALLOCATION_LIMIT)
@@ -42,7 +41,7 @@ int amiga_partition(struct parsed_partitions *state)
		data = read_part_sector(state, blk, &sect);
		if (!data) {
			pr_err("Dev %s: unable to read RDB block %d\n",
			       bdevname(state->bdev, b), blk);
			       state->disk->disk_name, blk);
			res = -1;
			goto rdb_done;
		}
@@ -64,7 +63,7 @@ int amiga_partition(struct parsed_partitions *state)
		}

		pr_err("Dev %s: RDB in block %d has bad checksum\n",
		       bdevname(state->bdev, b), blk);
		       state->disk->disk_name, blk);
	}

	/* blksize is blocks per 512 byte standard block */
@@ -84,7 +83,7 @@ int amiga_partition(struct parsed_partitions *state)
		data = read_part_sector(state, blk, &sect);
		if (!data) {
			pr_err("Dev %s: unable to read partition block %d\n",
			       bdevname(state->bdev, b), blk);
			       state->disk->disk_name, blk);
			res = -1;
			goto rdb_done;
		}
+2 −2
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ int atari_partition(struct parsed_partitions *state)
	 * ATARI partition scheme supports 512 lba only.  If this is not
	 * the case, bail early to avoid miscalculating hd_size.
	 */
	if (bdev_logical_block_size(state->bdev) != 512)
	if (queue_logical_block_size(state->disk->queue) != 512)
		return 0;

	rs = read_part_sector(state, 0, &sect);
@@ -55,7 +55,7 @@ int atari_partition(struct parsed_partitions *state)
		return -1;

	/* Verify this is an Atari rootsector: */
	hd_size = state->bdev->bd_inode->i_size >> 9;
	hd_size = get_capacity(state->disk);
	if (!VALID_PARTITION(&rs->part[0], hd_size) &&
	    !VALID_PARTITION(&rs->part[1], hd_size) &&
	    !VALID_PARTITION(&rs->part[2], hd_size) &&
+1 −1
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@
 * description.
 */
struct parsed_partitions {
	struct block_device *bdev;
	struct gendisk *disk;
	char name[BDEVNAME_SIZE];
	struct {
		sector_t from;
Loading