[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: cryptodisk: teach grub_cryptodisk_insert() about partitions (bug #45
From: |
TJ |
Subject: |
Re: cryptodisk: teach grub_cryptodisk_insert() about partitions (bug #45889) |
Date: |
Wed, 09 Sep 2015 02:18:55 +0100 |
User-agent: |
Roundcube Webmail/RCMAIL_VERSION |
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;