chiark / gitweb /
volume_id: support sub-uuid's and plug in btrfs device uuid
authorKay Sievers <kay.sievers@vrfy.org>
Tue, 9 Dec 2008 17:14:23 +0000 (18:14 +0100)
committerKay Sievers <kay.sievers@vrfy.org>
Tue, 9 Dec 2008 17:14:23 +0000 (18:14 +0100)
extras/volume_id/lib/btrfs.c
extras/volume_id/lib/exported_symbols
extras/volume_id/lib/libvolume_id-private.h
extras/volume_id/lib/libvolume_id.h
extras/volume_id/lib/util.c
extras/volume_id/lib/volume_id.c
extras/volume_id/vol_id.c

index 09b03a68dc4d57e25fecc24c79c65caf3b2b4b17..5ef979f2f07f9c01a55741c65fbf9c721db016d9 100644 (file)
@@ -93,6 +93,7 @@ int volume_id_probe_btrfs(struct volume_id *id, uint64_t off, uint64_t size)
        if (memcmp(bfs->magic, "_BHRfS_M", 8) != 0)
                return -1;
        volume_id_set_uuid(id, bfs->fsid, 0, UUID_DCE);
+       volume_id_set_uuid_sub(id, bfs->dev_item.uuid, 0, UUID_DCE);
        volume_id_set_label_raw(id, bfs->label, 256);
        volume_id_set_label_string(id, bfs->label, 256);
        volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
index d3b925c683031ed5cd94f01bb14fda4dd1236b3c..215a267dad3215bcb2743d64ae6e87d8fbae9733 100644 (file)
@@ -3,6 +3,7 @@ volume_id_get_label
 volume_id_get_label_raw
 volume_id_get_uuid
 volume_id_get_uuid_raw
+volume_id_get_uuid_sub
 volume_id_get_usage
 volume_id_get_type
 volume_id_get_type_version
index 8a5c327aeac89388424a1152db32caacfd503495..046a1e39ed65255243b41c30b40f8f3b5c4eb479 100644 (file)
@@ -107,6 +107,9 @@ struct volume_id {
        uint8_t         uuid_raw[VOLUME_ID_UUID_SIZE];
        size_t          uuid_raw_len;
        char            uuid[VOLUME_ID_UUID_SIZE+1];
+       uint8_t         uuid_sub_raw[VOLUME_ID_UUID_SIZE];
+       size_t          uuid_sub_raw_len;
+       char            uuid_sub[VOLUME_ID_UUID_SIZE+1];
        enum            volume_id_usage usage_id;
        char            *usage;
        char            *type;
@@ -129,6 +132,7 @@ extern void volume_id_set_label_raw(struct volume_id *id, const uint8_t *buf, si
 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, size_t len, enum uuid_format format);
+extern void volume_id_set_uuid_sub(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 e830504697dac7176b26d414dfa312df05f9eec3..24c9c4e7eb806c30a14cf513531f7b2207ebb6a3 100644 (file)
@@ -45,6 +45,7 @@ extern void volume_id_all_probers(all_probers_fn_t all_probers_fn,
 extern int volume_id_get_label(struct volume_id *id, const char **label);
 extern int volume_id_get_label_raw(struct volume_id *id, const uint8_t **label, size_t *len);
 extern int volume_id_get_uuid(struct volume_id *id, const char **uuid);
+extern int volume_id_get_uuid_sub(struct volume_id *id, const char **uuid);
 extern int volume_id_get_uuid_raw(struct volume_id *id, const uint8_t **uuid, size_t *len);
 extern int volume_id_get_usage(struct volume_id *id, const char **usage);
 extern int volume_id_get_type(struct volume_id *id, const char **type);
index 9844e5e97cf2bbd58b2436e72aa5b4daf1af351c..ea5ff16e911da69750c709e04bb564bd014dcb9d 100644 (file)
@@ -250,14 +250,12 @@ void volume_id_set_label_unicode16(struct volume_id *id, const uint8_t *buf, enu
         volume_id_set_unicode16((uint8_t *)id->label, sizeof(id->label), buf, endianess, count);
 }
 
-void volume_id_set_uuid(struct volume_id *id, const uint8_t *buf, size_t len, enum uuid_format format)
+static void set_uuid(const uint8_t *buf, size_t len, enum uuid_format format,
+                    char *uuid, uint8_t *uuid_raw, size_t *uuid_raw_len)
 {
        unsigned int i;
        unsigned int count = 0;
 
-       if (len > sizeof(id->uuid_raw))
-               len = sizeof(id->uuid_raw);
-
        switch(format) {
        case UUID_STRING:
                count = len;
@@ -281,8 +279,8 @@ void volume_id_set_uuid(struct volume_id *id, const uint8_t *buf, size_t len, en
                count = 32;
                break;
        }
-       memcpy(id->uuid_raw, buf, count);
-       id->uuid_raw_len = count;
+       memcpy(uuid_raw, buf, count);
+       *uuid_raw_len = count;
 
        /* if set, create string in the same format, the native platform uses */
        for (i = 0; i < count; i++)
@@ -293,16 +291,16 @@ void volume_id_set_uuid(struct volume_id *id, const uint8_t *buf, size_t len, en
 set:
        switch(format) {
        case UUID_DOS:
-               sprintf(id->uuid, "%02X%02X-%02X%02X",
+               sprintf(uuid, "%02X%02X-%02X%02X",
                        buf[3], buf[2], buf[1], buf[0]);
                break;
        case UUID_64BIT_LE:
-               sprintf(id->uuid,"%02X%02X%02X%02X%02X%02X%02X%02X",
+               sprintf(uuid,"%02X%02X%02X%02X%02X%02X%02X%02X",
                        buf[7], buf[6], buf[5], buf[4],
                        buf[3], buf[2], buf[1], buf[0]);
                break;
        case UUID_DCE:
-               sprintf(id->uuid,
+               sprintf(uuid,
                        "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
                        buf[0], buf[1], buf[2], buf[3],
                        buf[4], buf[5],
@@ -312,18 +310,18 @@ set:
                break;
        case UUID_HEX_STRING:
                /* translate A..F to a..f */
-               memcpy(id->uuid, buf, count);
+               memcpy(uuid, buf, count);
                for (i = 0; i < count; i++)
-                       if (id->uuid[i] >= 'A' && id->uuid[i] <= 'F')
-                               id->uuid[i] = (id->uuid[i] - 'A') + 'a';
-               id->uuid[count] = '\0';
+                       if (uuid[i] >= 'A' && uuid[i] <= 'F')
+                               uuid[i] = (uuid[i] - 'A') + 'a';
+               uuid[count] = '\0';
                break;
        case UUID_STRING:
-               memcpy(id->uuid, buf, count);
-               id->uuid[count] = '\0';
+               memcpy(uuid, buf, count);
+               uuid[count] = '\0';
                break;
        case UUID_MD:
-               sprintf(id->uuid,
+               sprintf(uuid,
                        "%02x%02x%02x%02x:%02x%02x%02x%02x:%02x%02x%02x%02x:%02x%02x%02x%02x",
                        buf[0], buf[1], buf[2], buf[3],
                        buf[4], buf[5], buf[6], buf[7],
@@ -331,7 +329,7 @@ set:
                        buf[12], buf[13], buf[14],buf[15]);
                break;
        case UUID_LVM:
-               sprintf(id->uuid,
+               sprintf(uuid,
                        "%c%c%c%c%c%c-%c%c%c%c-%c%c%c%c-%c%c%c%c-%c%c%c%c-%c%c%c%c-%c%c%c%c%c%c",
                        buf[0], buf[1], buf[2], buf[3], buf[4], buf[5],
                        buf[6], buf[7], buf[8], buf[9],
@@ -344,6 +342,22 @@ set:
        }
 }
 
+void volume_id_set_uuid(struct volume_id *id, const uint8_t *buf, size_t len, enum uuid_format format)
+{
+       if (len > sizeof(id->uuid_raw))
+               len = sizeof(id->uuid_raw);
+
+       set_uuid(buf, len, format, id->uuid, id->uuid_raw, &id->uuid_raw_len);
+}
+
+void volume_id_set_uuid_sub(struct volume_id *id, const uint8_t *buf, size_t len, enum uuid_format format)
+{
+       if (len > sizeof(id->uuid_sub_raw))
+               len = sizeof(id->uuid_sub_raw);
+
+       set_uuid(buf, len, format, id->uuid_sub, id->uuid_sub_raw, &id->uuid_sub_raw_len);
+}
+
 uint8_t *volume_id_get_buffer(struct volume_id *id, uint64_t off, size_t len)
 {
        ssize_t buf_len;
index 8bbbc38c3200c975de29290d24c019e4c0b86b59..48bfd88624d323b7922370d9b68950bee41f54b5 100644 (file)
@@ -219,6 +219,19 @@ int volume_id_get_uuid_raw(struct volume_id *id, const uint8_t **uuid, size_t *l
        return 1;
 }
 
+int volume_id_get_uuid_sub(struct volume_id *id, const char **uuid)
+{
+       if (id == NULL)
+               return 0;
+       if (uuid == NULL)
+               return 0;
+       if (id->usage_id == VOLUME_ID_UNUSED)
+               return 0;
+
+       *uuid = id->uuid_sub;
+       return 1;
+}
+
 /**
  * volume_id_get_usage:
  * @id: Probing context.
index 889bd3483da174b13f8dac46b55a2cb332720bea..3e44c3b069794b81a1e61338c98eef0fa7671bf3 100644 (file)
@@ -110,6 +110,7 @@ int main(int argc, char *argv[])
        char label_enc[256];
        char uuid_safe[256];
        char uuid_enc[256];
+       char uuid_sub_enc[256];
        char type_enc[256];
        char type_version_enc[256];
        uint64_t size = 0;
@@ -118,7 +119,7 @@ int main(int argc, char *argv[])
        uint64_t offset = 0;
        const char *node;
        int fd;
-       const char *label, *uuid, *type, *type_version, *usage;
+       const char *label, *uuid, *uuid_sub, *type, *type_version, *usage;
        int retval;
        int rc = 0;
 
@@ -261,7 +262,8 @@ int main(int argc, char *argv[])
            !volume_id_get_usage(vid, &usage) ||
            !volume_id_get_type(vid, &type) ||
            !volume_id_get_type_version(vid, &type_version) ||
-           !volume_id_get_uuid(vid, &uuid)) {
+           !volume_id_get_uuid(vid, &uuid) ||
+           !volume_id_get_uuid_sub(vid, &uuid_sub)) {
                rc = 4;
                goto exit;
        }
@@ -274,6 +276,8 @@ int main(int argc, char *argv[])
        udev_util_replace_chars(uuid_safe, UDEV_ALLOWED_CHARS_INPUT);
        volume_id_encode_string(uuid, uuid_enc, sizeof(uuid_enc));
 
+       volume_id_encode_string(uuid_sub, uuid_sub_enc, sizeof(uuid_sub_enc));
+
        volume_id_encode_string(type, type_enc, sizeof(type_enc));
        volume_id_encode_string(type_version, type_version_enc, sizeof(type_version_enc));
 
@@ -284,6 +288,8 @@ int main(int argc, char *argv[])
                printf("ID_FS_VERSION=%s\n", type_version_enc);
                printf("ID_FS_UUID=%s\n", uuid_safe);
                printf("ID_FS_UUID_ENC=%s\n", uuid_enc);
+               if (uuid_sub_enc[0] != '\0')
+                       printf("ID_FS_UUID_SUB_ENC=%s\n", uuid_sub_enc);
                printf("ID_FS_LABEL=%s\n", label_safe);
                printf("ID_FS_LABEL_ENC=%s\n", label_enc);
                break;