summaryrefslogtreecommitdiffstats
path: root/lib/uuid/uuid.c
diff options
context:
space:
mode:
authorJoe Thornber <thornber@redhat.com>2002-01-04 16:55:14 +0000
committerJoe Thornber <thornber@redhat.com>2002-01-04 16:55:14 +0000
commit9640f93d8ccb8b36ae8b24af547783c467449222 (patch)
treed86544c3599e71be80937d054017c5cd00e2603f /lib/uuid/uuid.c
parentb94703a187386ce35204c47348d0a7cac37cd122 (diff)
downloadlvm2-9640f93d8ccb8b36ae8b24af547783c467449222.tar.gz
lvm2-9640f93d8ccb8b36ae8b24af547783c467449222.tar.xz
lvm2-9640f93d8ccb8b36ae8b24af547783c467449222.zip
o Revert to the 6-4-4-4-4-4-6 format for uuid's
o When reading a uuid all -'s are stripped, wherever they are.
Diffstat (limited to 'lib/uuid/uuid.c')
-rw-r--r--lib/uuid/uuid.c48
1 files changed, 35 insertions, 13 deletions
diff --git a/lib/uuid/uuid.c b/lib/uuid/uuid.c
index 92b85d93..75cd747b 100644
--- a/lib/uuid/uuid.c
+++ b/lib/uuid/uuid.c
@@ -11,6 +11,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
+#include <assert.h>
static unsigned char _c[] =
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
@@ -82,32 +83,53 @@ int id_cmp(struct id *lhs, struct id *rhs)
int id_write_format(struct id *id, char *buffer, size_t size)
{
- int i;
+ int i, tot;
+
+ static int group_size[] = {6, 4, 4, 4, 4, 4, 6};
- /* split into 8 groups of four, with dashes in between */
- if (size < (GROUPS * 5))
+ assert(ID_LEN == 32);
+
+ /* split into groups seperated by dashes */
+ if (size < (32 + 6 + 1)) {
+ log_err("Couldn't write uuid, buffer too small.");
return 0;
+ }
- for (i = 0; i < GROUPS; i++) {
- memcpy(buffer + (i * 5), id->uuid + (i * 4), 4);
- buffer[(i * 5) + 4] = '-';
+ for (i = 0, tot = 0; i < 7; i++) {
+ memcpy(buffer, id->uuid + tot, group_size[i]);
+ buffer += group_size[i];
+ tot += group_size[i];
+ *buffer++ = '-';
}
- buffer[(GROUPS * 5) - 1] = '\0';
+ *--buffer = '\0';
return 1;
}
int id_read_format(struct id *id, char *buffer)
{
- int i;
+ int out = 0;
- if (strlen(buffer) < (GROUPS * 5)) {
- log_err("Insufficient characters to be a proper uuid.");
- return 0;
+ /* just strip out any dashes */
+ while (*buffer) {
+
+ if (*buffer == '-') {
+ buffer++;
+ continue;
+ }
+
+ if (out >= ID_LEN) {
+ log_err("Too many characters to be uuid.");
+ return 0;
+ }
+
+ id->uuid[out++] = *buffer++;
}
- for (i = 0; i < ID_LEN; i++)
- id->uuid[i] = buffer[((i / 4) * 5) + (i % 4)];
+ if (out != ID_LEN) {
+ log_err("Couldn't read uuid, incorrect number of characters.");
+ return 0;
+ }
return id_valid(id);
}