diff options
author | Joe Thornber <thornber@redhat.com> | 2001-10-12 10:32:06 +0000 |
---|---|---|
committer | Joe Thornber <thornber@redhat.com> | 2001-10-12 10:32:06 +0000 |
commit | 72a5e12b5c19e9c85561fa8e946a9bc2e67501e1 (patch) | |
tree | d5f933b663a66541b4e2429266155cfefd21932c /lib/uuid | |
parent | 03505a0f58040672af119ae8674a7352463641c7 (diff) | |
download | lvm2-72a5e12b5c19e9c85561fa8e946a9bc2e67501e1.tar.gz |
o pvcreate
o added uuid unit
o stubbed partition stuff
Diffstat (limited to 'lib/uuid')
-rw-r--r-- | lib/uuid/uuid.c | 49 | ||||
-rw-r--r-- | lib/uuid/uuid.h | 22 |
2 files changed, 71 insertions, 0 deletions
diff --git a/lib/uuid/uuid.c b/lib/uuid/uuid.c new file mode 100644 index 000000000..a96b5ad67 --- /dev/null +++ b/lib/uuid/uuid.c @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2001 Sistina Software (UK) Limited. + * + * This file is released under the GPL. + */ + +#include "uuid.h" +#include "log.h" + +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <unistd.h> + +static unsigned char _c[] = + "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + +int id_create(struct id *id) +{ + int random, i, len = sizeof(id->uuid); + + memset(id->uuid, 0, len); + if ((random = open("/dev/urandom", O_RDONLY)) < 0) { + log_sys_error("open", "id_create"); + return 0; + } + + if (read(random, id->uuid, len) != len) { + log_sys_error("read", "id_create"); + return 0; + } + close(random); + + for (i = 0; i < len; i++) + id->uuid[i] = _c[id->uuid[i] % (sizeof(_c) - 1)]; + + return 1; +} + +int id_valid(struct id *id) +{ + log_err("Joe hasn't written id_valid yet"); + return 1; +} + +int id_cmp(struct id *lhs, struct id *rhs) +{ + return memcmp(lhs->uuid, rhs->uuid, sizeof(lhs->uuid)); +} diff --git a/lib/uuid/uuid.h b/lib/uuid/uuid.h new file mode 100644 index 000000000..15de1b7de --- /dev/null +++ b/lib/uuid/uuid.h @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2001 Sistina Software (UK) Limited. + * + * This file is released under the GPL. + */ + +#ifndef _LVM_UUID_H +#define _LVM_UUID_H + +#include "lvm-types.h" + +#define ID_LEN 32 + +struct id { + uint8_t uuid[ID_LEN]; +}; + +int id_create(struct id *id); +int id_valid(struct id *id); +int id_cmp(struct id *lhs, struct id *rhs); + +#endif |