chiark / gitweb /
volume_id: add internal UUID_STRING
authorKay Sievers <kay.sievers@vrfy.org>
Fri, 4 May 2007 14:53:19 +0000 (16:53 +0200)
committerKay Sievers <kay.sievers@vrfy.org>
Fri, 4 May 2007 14:53:19 +0000 (16:53 +0200)
15 files changed:
extras/volume_id/lib/ext.c
extras/volume_id/lib/fat.c
extras/volume_id/lib/hfs.c
extras/volume_id/lib/jfs.c
extras/volume_id/lib/linux_raid.c
extras/volume_id/lib/linux_swap.c
extras/volume_id/lib/luks.c
extras/volume_id/lib/netware.c
extras/volume_id/lib/ntfs.c
extras/volume_id/lib/ocfs.c
extras/volume_id/lib/reiserfs.c
extras/volume_id/lib/util.c
extras/volume_id/lib/util.h
extras/volume_id/lib/volume_id.c
extras/volume_id/lib/xfs.c

index 8b3af3a..e5f1e22 100644 (file)
@@ -93,7 +93,7 @@ int volume_id_probe_ext(struct volume_id *id, uint64_t off, uint64_t size)
 
        volume_id_set_label_raw(id, es->s_volume_name, 16);
        volume_id_set_label_string(id, es->s_volume_name, 16);
-       volume_id_set_uuid(id, es->s_uuid, UUID_DCE);
+       volume_id_set_uuid(id, es->s_uuid, 0, UUID_DCE);
        snprintf(id->type_version, sizeof(id->type_version)-1, "%u.%u",
                 le32_to_cpu(es->s_rev_level), le16_to_cpu(es->s_minor_rev_level));
 
index 9a2e478..6ed16cc 100644 (file)
@@ -288,7 +288,7 @@ magic:
                volume_id_set_label_raw(id, vs->type.fat.label, 11);
                volume_id_set_label_string(id, vs->type.fat.label, 11);
        }
-       volume_id_set_uuid(id, vs->type.fat.serno, UUID_DOS);
+       volume_id_set_uuid(id, vs->type.fat.serno, 0, UUID_DOS);
        goto found;
 
 fat32:
@@ -366,7 +366,7 @@ fat32:
                volume_id_set_label_raw(id, vs->type.fat32.label, 11);
                volume_id_set_label_string(id, vs->type.fat32.label, 11);
        }
-       volume_id_set_uuid(id, vs->type.fat32.serno, UUID_DOS);
+       volume_id_set_uuid(id, vs->type.fat32.serno, 0, UUID_DOS);
 
 found:
        volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
index 303ad6b..8156008 100644 (file)
@@ -160,7 +160,7 @@ static void hfsid_set_uuid(struct volume_id *id, const uint8_t *hfs_id)
        volume_id_set_uuid(id, uuid, UUID_DCE);
 #endif
 
-       volume_id_set_uuid(id, hfs_id, UUID_HFS);
+       volume_id_set_uuid(id, hfs_id, 0, UUID_HFS);
 }
 
 int volume_id_probe_hfs_hfsplus(struct volume_id *id, uint64_t off, uint64_t size)
index 6d4124c..00b66cc 100644 (file)
@@ -56,7 +56,7 @@ int volume_id_probe_jfs(struct volume_id *id, uint64_t off, uint64_t size)
 
        volume_id_set_label_raw(id, js->label, 16);
        volume_id_set_label_string(id, js->label, 16);
-       volume_id_set_uuid(id, js->uuid, UUID_DCE);
+       volume_id_set_uuid(id, js->uuid, 0, UUID_DCE);
 
        volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
        id->type = "jfs";
index 6f37e2a..6d1d19c 100644 (file)
@@ -87,7 +87,7 @@ static int volume_id_probe_linux_raid0(struct volume_id *id, uint64_t off, uint6
                        uuid.ints[2] = 0;
                        uuid.ints[3] = 0;
                }
-               volume_id_set_uuid(id, uuid.bytes, UUID_FOURINT);
+               volume_id_set_uuid(id, uuid.bytes, 0, UUID_FOURINT);
                snprintf(id->type_version, sizeof(id->type_version)-1, "%u.%u.%u",
                         le32_to_cpu(mdp0->major_version),
                         le32_to_cpu(mdp0->minor_version),
@@ -103,7 +103,7 @@ static int volume_id_probe_linux_raid0(struct volume_id *id, uint64_t off, uint6
                        uuid.ints[2] = 0;
                        uuid.ints[3] = 0;
                }
-               volume_id_set_uuid(id, uuid.bytes, UUID_FOURINT);
+               volume_id_set_uuid(id, uuid.bytes, 0, UUID_FOURINT);
                snprintf(id->type_version, sizeof(id->type_version)-1, "%u.%u.%u",
                         be32_to_cpu(mdp0->major_version),
                         be32_to_cpu(mdp0->minor_version),
@@ -131,7 +131,7 @@ static int volume_id_probe_linux_raid1(struct volume_id *id, uint64_t off, uint6
        if (le32_to_cpu(mdp1->magic) != MD_SB_MAGIC)
                return -1;
 
-       volume_id_set_uuid(id, mdp1->set_uuid, UUID_FOURINT);
+       volume_id_set_uuid(id, mdp1->set_uuid, 0, UUID_FOURINT);
        volume_id_set_label_raw(id, mdp1->set_name, 32);
        volume_id_set_label_string(id, mdp1->set_name, 32);
        snprintf(id->type_version, sizeof(id->type_version)-1, "%u", le32_to_cpu(mdp1->major_version));
index 8aca564..50d43cc 100644 (file)
@@ -81,7 +81,7 @@ found_label:
        if (sw != NULL) {
                volume_id_set_label_raw(id, sw->volume_name, 16);
                volume_id_set_label_string(id, sw->volume_name, 16);
-               volume_id_set_uuid(id, sw->uuid, UUID_DCE);
+               volume_id_set_uuid(id, sw->uuid, 0, UUID_DCE);
        }
 
 found:
index a141a0f..231374e 100644 (file)
 #define LUKS_SALTSIZE                  32
 #define LUKS_NUMKEYS                   8
 
+#define LUKS_MAGIC_L                   6
+#define LUKS_PHDR_SIZE                 (sizeof(struct luks_phdr)/SECTOR_SIZE+1)
+#define UUID_STRING_L                  40
 static const uint8_t LUKS_MAGIC[] = {'L','U','K','S', 0xba, 0xbe};
-#define LUKS_MAGIC_L 6
-#define LUKS_PHDR_SIZE (sizeof(struct luks_phdr)/SECTOR_SIZE+1)
-#define UUID_STRING_L 40
 
 struct luks_phdr {
        uint8_t         magic[LUKS_MAGIC_L];
@@ -74,9 +74,7 @@ int volume_id_probe_luks(struct volume_id *id, uint64_t off, uint64_t size)
                return -1;
 
        volume_id_set_usage(id, VOLUME_ID_CRYPTO);
-       volume_id_set_uuid(id, header->uuid, UUID_DCE_STRING);
-
+       volume_id_set_uuid(id, header->uuid, 36, UUID_HEX_STRING);
        id->type = "crypto_LUKS";
-
        return 0;
 }
index 67af561..4d157aa 100644 (file)
@@ -91,7 +91,7 @@ int volume_id_probe_netware(struct volume_id *id, uint64_t off, uint64_t size)
        if (memcmp(nw->SBH_Signature, "SPB5", 4) != 0)
                return -1;
 
-       volume_id_set_uuid(id, nw->SBH_PoolID, UUID_DCE);
+       volume_id_set_uuid(id, nw->SBH_PoolID, 0, UUID_DCE);
 
        snprintf(id->type_version, sizeof(id->type_version)-1, "%u.%02u",
                 le16_to_cpu(nw->SBH_VersionMediaMajor), le16_to_cpu(nw->SBH_VersionMediaMinor));
index f7675a3..6e91db6 100644 (file)
@@ -114,7 +114,7 @@ int volume_id_probe_ntfs(struct volume_id *id, uint64_t off, uint64_t size)
        if (memcmp(ns->oem_id, "NTFS", 4) != 0)
                return -1;
 
-       volume_id_set_uuid(id, ns->volume_serial, UUID_NTFS);
+       volume_id_set_uuid(id, ns->volume_serial, 0, UUID_NTFS);
 
        sector_size = le16_to_cpu(ns->bytes_per_sector);
        cluster_size = ns->sectors_per_cluster * sector_size;
index 349527b..9f251f1 100644 (file)
@@ -156,7 +156,7 @@ int volume_id_probe_ocfs1(struct volume_id *id, uint64_t off, uint64_t size)
                volume_id_set_label_string(id, osl->label, 64);
        }
        if (osl->vol_id_len == 16)
-               volume_id_set_uuid(id, osl->vol_id, UUID_DCE);
+               volume_id_set_uuid(id, osl->vol_id, 0, UUID_DCE);
        id->type = "ocfs";
        return 0;
 }
@@ -184,7 +184,7 @@ int volume_id_probe_ocfs2(struct volume_id *id, uint64_t off, uint64_t size)
                volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
                volume_id_set_label_raw(id, os->s_label, 64);
                volume_id_set_label_string(id, os->s_label, 64);
-               volume_id_set_uuid(id, os->s_uuid, UUID_DCE);
+               volume_id_set_uuid(id, os->s_uuid, 0, UUID_DCE);
                snprintf(id->type_version, sizeof(id->type_version)-1,
                         "%u.%u", os->s_major_rev_level, os->s_minor_rev_level);
                id->type = "ocfs2";
index 1f219e5..18db638 100644 (file)
@@ -88,7 +88,7 @@ int volume_id_probe_reiserfs(struct volume_id *id, uint64_t off, uint64_t size)
                strcpy(id->type_version, "4");
                volume_id_set_label_raw(id, rs4->label, 16);
                volume_id_set_label_string(id, rs4->label, 16);
-               volume_id_set_uuid(id, rs4->uuid, UUID_DCE);
+               volume_id_set_uuid(id, rs4->uuid, 0, UUID_DCE);
                id->type = "reiser4";
                goto found;
        }
@@ -109,7 +109,7 @@ int volume_id_probe_reiserfs(struct volume_id *id, uint64_t off, uint64_t size)
 found_label:
        volume_id_set_label_raw(id, rs->label, 16);
        volume_id_set_label_string(id, rs->label, 16);
-       volume_id_set_uuid(id, rs->uuid, UUID_DCE);
+       volume_id_set_uuid(id, rs->uuid, 0, UUID_DCE);
 
 found:
        volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
index 762e84e..d65fc2c 100644 (file)
@@ -115,11 +115,14 @@ void volume_id_set_label_unicode16(struct volume_id *id, const uint8_t *buf, enu
         volume_id_set_unicode16(id->label, sizeof(id->label), buf, endianess, count);
 }
 
-void volume_id_set_uuid(struct volume_id *id, const uint8_t *buf, enum uuid_format format)
+void volume_id_set_uuid(struct volume_id *id, const uint8_t *buf, size_t len, enum uuid_format format)
 {
        unsigned int i;
        unsigned int count = 0;
 
+       if (len > sizeof(id->uuid_raw))
+               len = sizeof(id->uuid_raw);
+
        switch(format) {
        case UUID_DOS:
                count = 4;
@@ -131,8 +134,11 @@ void volume_id_set_uuid(struct volume_id *id, const uint8_t *buf, enum uuid_form
        case UUID_DCE:
                count = 16;
                break;
-       case UUID_DCE_STRING:
-               count = 36;
+       case UUID_HEX_STRING:
+               count = len;
+               break;
+       case UUID_STRING:
+               count = len;
                break;
        case UUID_FOURINT:
                count = 35;
@@ -172,7 +178,12 @@ set:
                        buf[8], buf[9],
                        buf[10], buf[11], buf[12], buf[13], buf[14],buf[15]);
                break;
-       case UUID_DCE_STRING:
+       case UUID_HEX_STRING:
+               for (i = 0; i < count; i++)
+                       id->uuid[i] = tolower(buf[i]);
+               id->uuid[count] = '\0';
+               break;
+       case UUID_STRING:
                memcpy(id->uuid, buf, count);
                id->uuid[count] = '\0';
                break;
index 964e701..cd8dac5 100644 (file)
@@ -63,7 +63,8 @@
 #endif /* __BYTE_ORDER */
 
 enum uuid_format {
-       UUID_DCE_STRING,
+       UUID_HEX_STRING,
+       UUID_STRING,
        UUID_DCE,
        UUID_DOS,
        UUID_NTFS,
@@ -81,7 +82,7 @@ extern void volume_id_set_usage(struct volume_id *id, enum volume_id_usage usage
 extern void volume_id_set_label_raw(struct volume_id *id, const uint8_t *buf, size_t count);
 extern void volume_id_set_label_string(struct volume_id *id, const uint8_t *buf, size_t count);
 extern void volume_id_set_label_unicode16(struct volume_id *id, const uint8_t *buf, enum endian endianess, size_t count);
-extern void volume_id_set_uuid(struct volume_id *id, const uint8_t *buf, enum uuid_format format);
+extern void volume_id_set_uuid(struct volume_id *id, const uint8_t *buf, size_t len, enum uuid_format format);
 extern uint8_t *volume_id_get_buffer(struct volume_id *id, uint64_t off, size_t len);
 extern void volume_id_free_buffer(struct volume_id *id);
 
index bf009c7..a66b4a5 100644 (file)
@@ -146,6 +146,9 @@ int volume_id_probe_raid(struct volume_id *id, uint64_t off, uint64_t size)
                if (volume_id_probe_linux_raid(id, off, size) == 0)
                        goto found;
 
+               if (volume_id_probe_ddf_raid(id, off, size) == 0)
+                       goto found;
+
                if (volume_id_probe_intel_software_raid(id, off, size) == 0)
                        goto found;
 
index 5c1a82e..9eac827 100644 (file)
@@ -56,7 +56,7 @@ int volume_id_probe_xfs(struct volume_id *id, uint64_t off, uint64_t size)
 
        volume_id_set_label_raw(id, xs->fname, 12);
        volume_id_set_label_string(id, xs->fname, 12);
-       volume_id_set_uuid(id, xs->uuid, UUID_DCE);
+       volume_id_set_uuid(id, xs->uuid, 0, UUID_DCE);
 
        volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
        id->type = "xfs";