diff mbox series

[v5,5/5] partitions/efi: Support non-standard GPT location

Message ID 20210818005547.14497-6-digetx@gmail.com
State Superseded
Headers show
Series [v5,1/5] block: Add alternative_gpt_sector() operation | expand

Commit Message

Dmitry Osipenko Aug. 18, 2021, 12:55 a.m. UTC
Support looking up GPT at a non-standard location specified by a block
device driver.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 block/partitions/efi.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Comments

Christoph Hellwig Aug. 18, 2021, 5:25 a.m. UTC | #1
On Wed, Aug 18, 2021 at 03:55:47AM +0300, Dmitry Osipenko wrote:
> Support looking up GPT at a non-standard location specified by a block
> device driver.
> 
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
> ---
>  block/partitions/efi.c | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/block/partitions/efi.c b/block/partitions/efi.c
> index aaa3dc487cb5..b9509f445b3c 100644
> --- a/block/partitions/efi.c
> +++ b/block/partitions/efi.c
> @@ -585,6 +585,8 @@ static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt,
>  	gpt_header *pgpt = NULL, *agpt = NULL;
>  	gpt_entry *pptes = NULL, *aptes = NULL;
>  	legacy_mbr *legacymbr;
> +	struct gendisk *disk = state->disk;
> +	const struct block_device_operations *fops = disk->fops;
>  	sector_t total_sectors = get_capacity(state->disk);
>  	u64 lastlba;
>  
> @@ -619,6 +621,17 @@ static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt,
>          if (!good_agpt && force_gpt)
>                  good_agpt = is_gpt_valid(state, lastlba, &agpt, &aptes);
>  
> +	if (!good_agpt && force_gpt && fops->alternative_gpt_sector) {
> +		struct block_device *bdev = disk->part0;
> +		sector_t agpt_sector;
> +		int err;
> +
> +		err = fops->alternative_gpt_sector(bdev, &agpt_sector);

Please call the method with the disk as the argument.  I've been moving
the block layer to generally pass the gendisk whenever we're dealing
with the whole device, as that makes the intent very clear.

Also do we really need the force_gpt check?  That is we always require
the user to pass a command line argument to use this?
Dmitry Osipenko Aug. 18, 2021, 5:41 a.m. UTC | #2
18.08.2021 08:25, Christoph Hellwig пишет:
> On Wed, Aug 18, 2021 at 03:55:47AM +0300, Dmitry Osipenko wrote:
>> Support looking up GPT at a non-standard location specified by a block
>> device driver.
>>
>> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
>> ---
>>  block/partitions/efi.c | 13 +++++++++++++
>>  1 file changed, 13 insertions(+)
>>
>> diff --git a/block/partitions/efi.c b/block/partitions/efi.c
>> index aaa3dc487cb5..b9509f445b3c 100644
>> --- a/block/partitions/efi.c
>> +++ b/block/partitions/efi.c
>> @@ -585,6 +585,8 @@ static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt,
>>  	gpt_header *pgpt = NULL, *agpt = NULL;
>>  	gpt_entry *pptes = NULL, *aptes = NULL;
>>  	legacy_mbr *legacymbr;
>> +	struct gendisk *disk = state->disk;
>> +	const struct block_device_operations *fops = disk->fops;
>>  	sector_t total_sectors = get_capacity(state->disk);
>>  	u64 lastlba;
>>  
>> @@ -619,6 +621,17 @@ static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt,
>>          if (!good_agpt && force_gpt)
>>                  good_agpt = is_gpt_valid(state, lastlba, &agpt, &aptes);
>>  
>> +	if (!good_agpt && force_gpt && fops->alternative_gpt_sector) {
>> +		struct block_device *bdev = disk->part0;
>> +		sector_t agpt_sector;
>> +		int err;
>> +
>> +		err = fops->alternative_gpt_sector(bdev, &agpt_sector);
> 
> Please call the method with the disk as the argument.  I've been moving
> the block layer to generally pass the gendisk whenever we're dealing
> with the whole device, as that makes the intent very clear.

I'll change it in v6.

> Also do we really need the force_gpt check?  That is we always require
> the user to pass a command line argument to use this?

User indeed must pass the 'gpt' argument to kernel cmdline. That's what
all those Android devices do. Should be okay to keep that requirement.
diff mbox series

Patch

diff --git a/block/partitions/efi.c b/block/partitions/efi.c
index aaa3dc487cb5..b9509f445b3c 100644
--- a/block/partitions/efi.c
+++ b/block/partitions/efi.c
@@ -585,6 +585,8 @@  static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt,
 	gpt_header *pgpt = NULL, *agpt = NULL;
 	gpt_entry *pptes = NULL, *aptes = NULL;
 	legacy_mbr *legacymbr;
+	struct gendisk *disk = state->disk;
+	const struct block_device_operations *fops = disk->fops;
 	sector_t total_sectors = get_capacity(state->disk);
 	u64 lastlba;
 
@@ -619,6 +621,17 @@  static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt,
         if (!good_agpt && force_gpt)
                 good_agpt = is_gpt_valid(state, lastlba, &agpt, &aptes);
 
+	if (!good_agpt && force_gpt && fops->alternative_gpt_sector) {
+		struct block_device *bdev = disk->part0;
+		sector_t agpt_sector;
+		int err;
+
+		err = fops->alternative_gpt_sector(bdev, &agpt_sector);
+		if (!err)
+			good_agpt = is_gpt_valid(state, agpt_sector,
+						 &agpt, &aptes);
+	}
+
         /* The obviously unsuccessful case */
         if (!good_pgpt && !good_agpt)
                 goto fail;