chiark / gitweb /
volume_id: add internal UUID_STRING
[elogind.git] / extras / volume_id / lib / util.c
index cf5392cf9aba7fe1512b9f0b6b3fa0f15bbd4466..d65fc2c1d653b1be6668c95eb97a2410d65ae88c 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,14 @@ 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;
                break;
        }
        memcpy(id->uuid_raw, buf, count);
@@ -169,10 +178,23 @@ 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;
+       case UUID_FOURINT:
+               sprintf(id->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],
+                       buf[8], buf[9], buf[10], buf[11],
+                       buf[12], buf[13], buf[14],buf[15]);
+               break;
        }
 }
 
@@ -180,7 +202,7 @@ uint8_t *volume_id_get_buffer(struct volume_id *id, uint64_t off, size_t len)
 {
        ssize_t buf_len;
 
-       dbg("get buffer off 0x%llx(%llu), len 0x%zx", (unsigned long long) off, (unsigned long long) off, len);
+       info("get buffer off 0x%llx(%llu), len 0x%zx", (unsigned long long) off, (unsigned long long) off, len);
        /* check if requested area fits in superblock buffer */
        if (off + len <= SB_BUFFER_SIZE) {
                if (id->sbbuf == NULL) {
@@ -193,7 +215,7 @@ uint8_t *volume_id_get_buffer(struct volume_id *id, uint64_t off, size_t len)
 
                /* check if we need to read */
                if ((off + len) > id->sbbuf_len) {
-                       dbg("read sbbuf len:0x%llx", (unsigned long long) (off + len));
+                       info("read sbbuf len:0x%llx", (unsigned long long) (off + len));
                        if (lseek(id->fd, 0, SEEK_SET) < 0) {
                                dbg("lseek failed (%s)", strerror(errno));
                                return NULL;
@@ -229,7 +251,7 @@ uint8_t *volume_id_get_buffer(struct volume_id *id, uint64_t off, size_t len)
 
                /* check if we need to read */
                if ((off < id->seekbuf_off) || ((off + len) > (id->seekbuf_off + id->seekbuf_len))) {
-                       dbg("read seekbuf off:0x%llx len:0x%zx", (unsigned long long) off, len);
+                       info("read seekbuf off:0x%llx len:0x%zx", (unsigned long long) off, len);
                        if (lseek(id->fd, off, SEEK_SET) < 0) {
                                dbg("lseek failed (%s)", strerror(errno));
                                return NULL;