Skip to contentSkip to conversation

Make grub_efidisk_get_device_name() work on 4K native disks.

PATCH In review Peter Jones 3 participants 5 messages Apr 3, 2013 – Apr 5, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Make grub_efidisk_get_device_name() work on 4K native disks.

When we have 4kB sectors instead of 512b sectors, hd.partition_start and grub_partition_get_start() won't match - the latter assumes 512-byte sectors, and the former gives us the correct number based on the physical media's sector size. So when we have to compare them, we need to compensate.

---
 grub-core/disk/efi/efidisk.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
grub-core/disk/efi/efidisk.c +6 -4
index 77ab5b0..a905b52 100644
@@ -791,11 +791,13 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle)
       auto int find_partition (grub_disk_t disk, const grub_partition_t part);
 
       /* Find the identical partition.  */
-      int find_partition (grub_disk_t disk __attribute__ ((unused)),
-			  const grub_partition_t part)
+      int find_partition (grub_disk_t disk, const grub_partition_t part)
 	{
-	  if (grub_partition_get_start (part) == hd.partition_start
-	      && grub_partition_get_len (part) == hd.partition_size)
+	  struct grub_efidisk_data *d = disk->data;
+	  grub_efi_block_io_media_t *m = d->block_io->media;
+
+	  if (grub_partition_get_start (part) / (m->block_size / 512) == hd.partition_start
+	      && grub_partition_get_len (part) / (m->block_size / 512) == hd.partition_size)
 	    {
 	      partition_name = grub_partition_get_name (part);
 	      return 1;
Signature · 1 line
1.8.1.4
#1 lore raw

В Wed, 3 Apr 2013 11:53:06 -0400
Peter Jones <[email protected]> пишет:

Quoted 16 lines

When we have 4kB sectors instead of 512b sectors, hd.partition_start and grub_partition_get_start() won't match - the latter assumes 512-byte sectors, and the former gives us the correct number based on the physical media's sector size. So when we have to compare them, we need to compensate.

---
 grub-core/disk/efi/efidisk.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
grub-core/disk/efi/efidisk.c +0 -0
index 77ab5b0..a905b52 100644

grub-core/disk/efi/efidisk.c grub_efidisk_get_device_name (grub_efi_handle_t *handle) · line 792

Quoted 2 lines
grub-core/disk/efi/efidisk.c +0 -0
@@ -791,11 +791,13 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle)
       auto int find_partition (grub_disk_t disk, const grub_partition_t part);
 

You need to rebase to current trunk which does not use nested functions anymore. Also in current trunk there is second use of grub_partition_get_start() which looks like it has the same issue.

Quoted 15 lines
grub-core/disk/efi/efidisk.c +6 -4
       /* Find the identical partition.  */
-      int find_partition (grub_disk_t disk __attribute__ ((unused)),
-			  const grub_partition_t part)
+      int find_partition (grub_disk_t disk, const grub_partition_t part)
 	{
-	  if (grub_partition_get_start (part) == hd.partition_start
-	      && grub_partition_get_len (part) == hd.partition_size)
+	  struct grub_efidisk_data *d = disk->data;
+	  grub_efi_block_io_media_t *m = d->block_io->media;
+
+	  if (grub_partition_get_start (part) / (m->block_size / 512) == hd.partition_start
+	      && grub_partition_get_len (part) / (m->block_size / 512) == hd.partition_size)
 	    {
 	      partition_name = grub_partition_get_name (part);
 	      return 1;
#2 lore raw
Quoted 14 lines · Andrey Borzenkov

В Wed, 3 Apr 2013 11:53:06 -0400
Peter Jones <[email protected]> пишет:

Quoted 11 lines

When we have 4kB sectors instead of 512b sectors, hd.partition_start and grub_partition_get_start() won't match - the latter assumes 512-byte sectors, and the former gives us the correct number based on the physical media's sector size. So when we have to compare them, we need to compensate.

---
 grub-core/disk/efi/efidisk.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
Quoted 11 lines

grub-core/disk/efi/efidisk.c grub_efidisk_get_device_name (grub_efi_handle_t *handle) · line 792

Quoted 7 lines
grub-core/disk/efi/efidisk.c +0 -0
index 77ab5b0..a905b52 100644
@@ -791,11 +791,13 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle)
       auto int find_partition (grub_disk_t disk, const grub_partition_t part);
 

You need to rebase to current trunk which does not use nested functions anymore. Also in current trunk there is second use of grub_partition_get_start() which looks like it has the same issue.

Oh, indeed, you're right, that has changed. Although the current tree looks like it already takes this in to consideration.

So nevermind then :)

Thanks for having a look.

Signature · 1 line
        Peter
#3 lore raw

В Thu, 4 Apr 2013 13:52:05 -0400
Peter Jones <[email protected]> пишет:

Quoted 27 lines · Andrey Borzenkov
Quoted 14 lines

В Wed, 3 Apr 2013 11:53:06 -0400
Peter Jones <[email protected]> пишет:

Quoted 11 lines

When we have 4kB sectors instead of 512b sectors, hd.partition_start and grub_partition_get_start() won't match - the latter assumes 512-byte sectors, and the former gives us the correct number based on the physical media's sector size. So when we have to compare them, we need to compensate.

---
 grub-core/disk/efi/efidisk.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
Quoted 11 lines

grub-core/disk/efi/efidisk.c grub_efidisk_get_device_name (grub_efi_handle_t *handle) · line 792

Quoted 7 lines
grub-core/disk/efi/efidisk.c +0 -0
index 77ab5b0..a905b52 100644
@@ -791,11 +791,13 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle)
       auto int find_partition (grub_disk_t disk, const grub_partition_t part);
 

You need to rebase to current trunk which does not use nested functions anymore. Also in current trunk there is second use of grub_partition_get_start() which looks like it has the same issue.

Quoted 3 lines

Oh, indeed, you're right, that has changed. Although the current tree looks like it already takes this in to consideration.

Hmm ... I do not see it. Your change looks still necessary.

Quoted 3 lines

So nevermind then :)

Thanks for having a look.

#4 lore raw
Quoted 30 lines · Andrey Borzenkov

В Thu, 4 Apr 2013 13:52:05 -0400
Peter Jones <[email protected]> пишет:

Quoted 27 lines · Andrey Borzenkov
Quoted 25 lines

В Wed, 3 Apr 2013 11:53:06 -0400
Peter Jones <[email protected]> пишет:

Quoted 16 lines

When we have 4kB sectors instead of 512b sectors, hd.partition_start and grub_partition_get_start() won't match - the latter assumes 512-byte sectors, and the former gives us the correct number based on the physical media's sector size. So when we have to compare them, we need to compensate.

---
 grub-core/disk/efi/efidisk.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
grub-core/disk/efi/efidisk.c +0 -0
index 77ab5b0..a905b52 100644

grub-core/disk/efi/efidisk.c grub_efidisk_get_device_name (grub_efi_handle_t *handle) · line 792

Quoted 2 lines
grub-core/disk/efi/efidisk.c +0 -0
@@ -791,11 +791,13 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle)
       auto int find_partition (grub_disk_t disk, const grub_partition_t part);
 

You need to rebase to current trunk which does not use nested functions anymore. Also in current trunk there is second use of grub_partition_get_start() which looks like it has the same issue.

Quoted 6 lines
Quoted 3 lines

Oh, indeed, you're right, that has changed. Although the current tree looks like it already takes this in to consideration.

Hmm ... I do not see it. Your change looks still necessary.

Probably your copy is a bit old. I adjusted and committed his patch.

Quoted 9 lines
Quoted 3 lines

So nevermind then :)

Thanks for having a look.

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel