All of lore.kernel.org
 help / color / mirror / Atom feed
From: TJ <grub-devel@iam.tj>
To: The development of GNU GRUB <grub-devel@gnu.org>
Subject: Re: cryptodisk: teach grub_cryptodisk_insert() about partitions (bug #45889)
Date: Wed, 09 Sep 2015 02:18:55 +0100	[thread overview]
Message-ID: <fb1060aac2973a78f86dd4a39b1707d1@iam.tj> (raw)
In-Reply-To: <55EF0EFB.5060103@gmail.com>

On 08-09-2015 17:38, Vladimir 'φ-coder/phcoder' Serbinenko wrote:
> On 06.09.2015 21:10, TJ wrote:
>> https://savannah.gnu.org/bugs/index.php?45889
>> +      if ((disk->partition && disk->partition->number ==
>> dev->partition_number) ||
>> +          (!disk->partition && dev->partition_number == 0))
>> +        return dev;
> Please store and compare partition start, not parition number as the
> same partition can be available several times through different 
> partiton
> schemes under different numbers. Additionally this allows to use
> get_partition_start which already has the logic of handling empty 
> partitions

Done and tested. Works perfectly.

------
diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c
index 82a3dcb..f4cd81b 100644
--- a/grub-core/disk/cryptodisk.c
+++ b/grub-core/disk/cryptodisk.c
@@ -25,6 +25,7 @@
  #include <grub/fs.h>
  #include <grub/file.h>
  #include <grub/procfs.h>
+#include <grub/partition.h>

  #ifdef GRUB_UTIL
  #include <grub/emu/hostdisk.h>
@@ -718,6 +719,7 @@ grub_cryptodisk_insert (grub_cryptodisk_t newdev, 
const char *name,
    newdev->id = last_cryptodisk_id++;
    newdev->source_id = source->id;
    newdev->source_dev_id = source->dev->id;
+  newdev->partition_start = grub_partition_get_start 
(source->partition);
    newdev->next = cryptodisk_list;
    cryptodisk_list = newdev;

@@ -740,7 +742,9 @@ grub_cryptodisk_get_by_source_disk (grub_disk_t 
disk)
    grub_cryptodisk_t dev;
    for (dev = cryptodisk_list; dev != NULL; dev = dev->next)
      if (dev->source_id == disk->id && dev->source_dev_id == 
disk->dev->id)
-      return dev;
+      if ((disk->partition && grub_partition_get_start 
(disk->partition) == dev->partition_start) ||
+          (!disk->partition && dev->partition_start == 0))
+        return dev;
    return NULL;
  }

@@ -761,6 +765,7 @@ grub_cryptodisk_cheat_insert (grub_cryptodisk_t 
newdev, const char *name,
    newdev->cheat_fd = GRUB_UTIL_FD_INVALID;
    newdev->source_id = source->id;
    newdev->source_dev_id = source->dev->id;
+  newdev->partition_start = grub_partition_get_start 
(source->partition);
    newdev->id = last_cryptodisk_id++;
    newdev->next = cryptodisk_list;
    cryptodisk_list = newdev;
diff --git a/include/grub/cryptodisk.h b/include/grub/cryptodisk.h
index f2ad2a7..32f564a 100644
--- a/include/grub/cryptodisk.h
+++ b/include/grub/cryptodisk.h
@@ -97,6 +97,7 @@ struct grub_cryptodisk
    grub_uint8_t rekey_key[64];
    grub_uint64_t last_rekey;
    int rekey_derived_size;
+  grub_disk_addr_t partition_start;
  };
  typedef struct grub_cryptodisk *grub_cryptodisk_t;




  reply	other threads:[~2015-09-09  1:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-07  4:10 cryptodisk: teach grub_cryptodisk_insert() about partitions (bug #45889) TJ
2015-09-08 16:38 ` Vladimir 'φ-coder/phcoder' Serbinenko
2015-09-09  1:18   ` TJ [this message]
2015-09-11 14:11     ` Andrei Borzenkov
2015-09-11 14:54       ` TJ
2015-11-07 15:54         ` Andrei Borzenkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fb1060aac2973a78f86dd4a39b1707d1@iam.tj \
    --to=grub-devel@iam.tj \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.