]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: bitlocker: add drive label
authorVictor Westerhuis <victor.westerhuis@alliander.com>
Wed, 24 Jul 2024 15:32:28 +0000 (17:32 +0200)
committerVictor Westerhuis <victor.westerhuis@alliander.com>
Thu, 25 Jul 2024 13:13:19 +0000 (15:13 +0200)
libblkid/src/superblocks/bitlocker.c
tests/expected/blkid/low-probe-bitlocker-win7

index e68c2b2300ea2a356d86c2a4d13ab6dab130d6dc..74fa2b3626a74a596ca5b8138adb43f819f9aa54 100644 (file)
@@ -51,6 +51,15 @@ struct bde_fve_metadata_header {
 /*   8 */ uint32_t      header_size;
 /*  12 */ uint32_t      size_copy;
 /*  16 */ unsigned char volume_identifier[16];
+/*  32 */ unsigned char __dummy[48 - 32];
+} __attribute__((packed));
+
+struct bde_fve_metadata_entry {
+/*   0 */ uint16_t      size;
+/*   2 */ uint16_t      entry_type;
+/*   4 */ uint16_t      value_type;
+/*   6 */ uint16_t      version;
+/*   8 */ unsigned char data[];
 } __attribute__((packed));
 
 struct bde_fve_metadata {
@@ -70,6 +79,9 @@ enum {
 
 #define BDE_MAGIC_FVE          "-FVE-FS-"
 
+#define BDE_METADATA_ENTRY_TYPE_DESCRIPTION 0x0007
+#define BDE_METADATA_VALUE_TYPE_STRING      0x0002
+
 static int get_bitlocker_type(const unsigned char *buf)
 {
        size_t i;
@@ -140,8 +152,15 @@ static int get_bitlocker_headers(blkid_probe pr,
        fve = (const struct bde_fve_metadata *) buf;
        if (memcmp(fve->block_header.signature, BDE_MAGIC_FVE, sizeof(fve->block_header.signature)) != 0)
                goto nothing;
-       if (buf_fve)
+
+       if (buf_fve) {
+               buf = blkid_probe_get_buffer(pr, off,
+                       (uint64_t) sizeof(struct bde_fve_metadata_block_header) + le32_to_cpu(fve->header.size));
+               if (!buf)
+                       return errno ? -errno : 1;
+
                *buf_fve = buf;
+       }
 done:
        if (type)
                *type = kind;
@@ -163,7 +182,9 @@ static int probe_bitlocker(blkid_probe pr,
 {
        const unsigned char *buf_fve = NULL;
        const unsigned char *buf_hdr = NULL;
+       const struct bde_fve_metadata_entry *entry;
        int rc, kind;
+       uint64_t off;
 
        rc = get_bitlocker_headers(pr, &kind, &buf_hdr, &buf_fve);
        if (rc)
@@ -174,6 +195,24 @@ static int probe_bitlocker(blkid_probe pr,
 
                blkid_probe_sprintf_version(pr, "%d", le16_to_cpu(fve->block_header.version));
 
+               for (off = sizeof(struct bde_fve_metadata_header);
+                    off + sizeof(struct bde_fve_metadata_entry) < le32_to_cpu(fve->header.size);
+                    off += le16_to_cpu(entry->size)) {
+                       entry = (const struct bde_fve_metadata_entry *) ((const char *) &fve->header + off);
+                       if (off % 2 ||
+                           le16_to_cpu(entry->size) < sizeof(struct bde_fve_metadata_entry) ||
+                           off + le16_to_cpu(entry->size) > le32_to_cpu(fve->header.size))
+                               return -1;
+
+                       if (le16_to_cpu(entry->entry_type) == BDE_METADATA_ENTRY_TYPE_DESCRIPTION &&
+                           le16_to_cpu(entry->value_type) == BDE_METADATA_VALUE_TYPE_STRING) {
+                               blkid_probe_set_utf8label(pr,
+                                       entry->data, le16_to_cpu(entry->size) - sizeof(struct bde_fve_metadata_entry),
+                                       UL_ENCODE_UTF16LE);
+                               break;
+                       }
+               }
+
                /* Microsoft GUID format, interpreted as explained by Raymond Chen:
                 * https://devblogs.microsoft.com/oldnewthing/20220928-00/?p=107221
                 */
index 7ef347c9a2bc264318e71faf48c579fb9a573cc0..c015e4bc5ff61a28ce26d7f5ebd7b6f88c2da7aa 100644 (file)
@@ -1,3 +1,5 @@
+ID_FS_LABEL=DESKTOP-7BHQ0UE_Bitlocker_Win_10_25/07/2024
+ID_FS_LABEL_ENC=DESKTOP-7BHQ0UE\x20Bitlocker\x20Win\x2010\x2025\x2f07\x2f2024
 ID_FS_TYPE=BitLocker
 ID_FS_USAGE=crypto
 ID_FS_UUID=83330ba8-07b7-4ea8-b641-ff7bdf18f6b3