2 * uuid.c -- utility routines for manipulating UUID's.
5 * This file may be redistributed under the terms of the GNU Library
6 * General Public License, version 2.
12 #include <ext2fs/ext2_types.h>
19 __u16 time_hi_and_version;
24 /* Returns 1 if the uuid is the NULL uuid */
25 int e2p_is_null_uuid(void *uu)
30 for (i=0, cp = uu; i < 16; i++)
36 static void e2p_unpack_uuid(void *in, struct uuid *uu)
42 tmp = (tmp << 8) | *ptr++;
43 tmp = (tmp << 8) | *ptr++;
44 tmp = (tmp << 8) | *ptr++;
48 tmp = (tmp << 8) | *ptr++;
52 tmp = (tmp << 8) | *ptr++;
53 uu->time_hi_and_version = tmp;
56 tmp = (tmp << 8) | *ptr++;
59 memcpy(uu->node, ptr, 6);
62 void e2p_uuid_to_str(void *uu, char *out)
66 e2p_unpack_uuid(uu, &uuid);
68 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
69 uuid.time_low, uuid.time_mid, uuid.time_hi_and_version,
70 uuid.clock_seq >> 8, uuid.clock_seq & 0xFF,
71 uuid.node[0], uuid.node[1], uuid.node[2],
72 uuid.node[3], uuid.node[4], uuid.node[5]);
75 const char *e2p_uuid2str(void *uu)
79 if (e2p_is_null_uuid(uu))
81 e2p_uuid_to_str(uu, buf);