[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PROCFS 3/5] cryptodisk: Add crypto disk name and source device names to
From: |
Glenn Washburn |
Subject: |
[PROCFS 3/5] cryptodisk: Add crypto disk name and source device names to (proc)/luks_script |
Date: |
Fri, 19 Mar 2021 18:17:44 -0500 |
It can be difficult to determine what device backs a particular (cryptoN)
device because they are automatically generated. This allows users to see
in the grub shell which devices back which crypto devices.
Signed-off-by: Glenn Washburn <development@efficientek.com>
---
grub-core/disk/cryptodisk.c | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c
index bb9e1a946..be97dfab9 100644
--- a/grub-core/disk/cryptodisk.c
+++ b/grub-core/disk/cryptodisk.c
@@ -1211,25 +1211,36 @@ hex (grub_uint8_t val)
}
/* Open a file named NAME and initialize FILE. */
+#define STR(s) #s
+#define MAX_ID_PRINT 10000
static char *
luks_script_get (grub_size_t *sz)
{
grub_cryptodisk_t i;
grub_size_t size = 0;
char *ptr, *ret;
+ static char errmsg[] = N_("Can not list more than " STR(MAX_ID_PRINT)
+ " crypto devices.\n");
*sz = 0;
for (i = cryptodisk_list; i != NULL; i = i->next)
- if (grub_strcmp (i->modname, "luks") == 0 ||
- grub_strcmp (i->modname, "luks2") == 0)
+ if (i->id >= MAX_ID_PRINT)
+ {
+ *sz = sizeof (errmsg);
+ return errmsg;
+ }
+ else if (grub_strcmp (i->modname, "luks") == 0 ||
+ grub_strcmp (i->modname, "luks2") == 0)
{
size += grub_strlen (i->modname);
size += sizeof ("_mount");
+ size += sizeof ("crypto");
+ size += grub_strlen (i->source);
size += grub_strlen (i->uuid);
size += grub_strlen (i->cipher->cipher->name);
- /* mode + mode_iv + spaces + offset + sector size + ??? + '\n' */
- size += 5 + 8 + 5 + 20 + 4 + 16 + 1;
+ /* spaces + maxidlen + mode + mode_iv + offset + sector size + ??? +
'\n' */
+ size += 7 + sizeof (STR(MAX_ID_PRINT)) + 5 + 8 + 20 + 4 + 16 + 1;
if (i->essiv_hash)
size += grub_strlen (i->essiv_hash->name);
size += i->keysize * 2;
@@ -1249,6 +1260,9 @@ luks_script_get (grub_size_t *sz)
const char *iptr;
ptr = grub_stpcpy (ptr, i->modname);
ptr = grub_stpcpy (ptr, "_mount ");
+ ptr += grub_snprintf (ptr, 8 + sizeof (STR(MAX_ID_PRINT)), "crypto%lu
", i->id);
+ ptr = grub_stpcpy (ptr, i->source);
+ *ptr++ = ' ';
ptr = grub_stpcpy (ptr, i->uuid);
*ptr++ = ' ';
ptr += grub_snprintf (ptr, 21, "%" PRIuGRUB_UINT64_T " ",
--
2.27.0