Changes to update Tomato RAF.
[tomato.git] / release / src / router / busybox / e2fsprogs / old_e2fsprogs / e2p / uuid.c
blob474d64a5a4e317b8938ac3073f563156c0b57811
1 /* vi: set sw=4 ts=4: */
2 /*
3 * uuid.c -- utility routines for manipulating UUID's.
4 */
6 #include <stdio.h>
7 #include <string.h>
8 #include "../ext2fs/ext2_types.h"
10 #include "e2p.h"
12 struct uuid {
13 __u32 time_low;
14 __u16 time_mid;
15 __u16 time_hi_and_version;
16 __u16 clock_seq;
17 __u8 node[6];
20 /* Returns 1 if the uuid is the NULL uuid */
21 int e2p_is_null_uuid(void *uu)
23 __u8 *cp;
24 int i;
26 for (i=0, cp = uu; i < 16; i++)
27 if (*cp)
28 return 0;
29 return 1;
32 static void e2p_unpack_uuid(void *in, struct uuid *uu)
34 __u8 *ptr = in;
35 __u32 tmp;
37 tmp = *ptr++;
38 tmp = (tmp << 8) | *ptr++;
39 tmp = (tmp << 8) | *ptr++;
40 tmp = (tmp << 8) | *ptr++;
41 uu->time_low = tmp;
43 tmp = *ptr++;
44 tmp = (tmp << 8) | *ptr++;
45 uu->time_mid = tmp;
47 tmp = *ptr++;
48 tmp = (tmp << 8) | *ptr++;
49 uu->time_hi_and_version = tmp;
51 tmp = *ptr++;
52 tmp = (tmp << 8) | *ptr++;
53 uu->clock_seq = tmp;
55 memcpy(uu->node, ptr, 6);
58 void e2p_uuid_to_str(void *uu, char *out)
60 struct uuid uuid;
62 e2p_unpack_uuid(uu, &uuid);
63 sprintf(out,
64 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
65 uuid.time_low, uuid.time_mid, uuid.time_hi_and_version,
66 uuid.clock_seq >> 8, uuid.clock_seq & 0xFF,
67 uuid.node[0], uuid.node[1], uuid.node[2],
68 uuid.node[3], uuid.node[4], uuid.node[5]);
71 const char *e2p_uuid2str(void *uu)
73 static char buf[80];
74 if (e2p_is_null_uuid(uu))
75 return "<none>";
76 e2p_uuid_to_str(uu, buf);
77 return buf;