blob: 1dbfc5904c8ad010bacbe6747210e6f4a9e2e0f8 [file] [log] [blame]
Theodore Ts'o1e3472c1997-04-29 14:53:37 +00001/*
2 * uuid.c -- utility routines for manipulating UUID's.
3 */
4
5#include <stdio.h>
Theodore Ts'o21c84b71997-04-29 16:15:03 +00006#include <string.h>
Theodore Ts'o73f17cf1999-01-04 07:35:45 +00007#include <asm/types.h>
Theodore Ts'o1e3472c1997-04-29 14:53:37 +00008
Theodore Ts'o21c84b71997-04-29 16:15:03 +00009#include "e2p.h"
10
Theodore Ts'o1e3472c1997-04-29 14:53:37 +000011struct uuid {
12 __u32 time_low;
13 __u16 time_mid;
14 __u16 time_hi_and_version;
15 __u16 clock_seq;
16 __u8 node[6];
17};
18
19/* Returns 1 if the uuid is the NULL uuid */
20int e2p_is_null_uuid(void *uu)
21{
22 __u8 *cp;
23 int i;
24
25 for (i=0, cp = uu; i < 16; i++)
26 if (*cp)
27 return 0;
28 return 1;
29}
30
31static void e2p_unpack_uuid(void *in, struct uuid *uu)
32{
33 __u8 *ptr = in;
34 __u32 tmp;
35
36 tmp = *ptr++;
37 tmp = (tmp << 8) | *ptr++;
38 tmp = (tmp << 8) | *ptr++;
39 tmp = (tmp << 8) | *ptr++;
40 uu->time_low = tmp;
41
42 tmp = *ptr++;
43 tmp = (tmp << 8) | *ptr++;
44 uu->time_mid = tmp;
45
46 tmp = *ptr++;
47 tmp = (tmp << 8) | *ptr++;
48 uu->time_hi_and_version = tmp;
49
50 tmp = *ptr++;
51 tmp = (tmp << 8) | *ptr++;
52 uu->clock_seq = tmp;
53
54 memcpy(uu->node, ptr, 6);
55}
56
57void e2p_uuid_to_str(void *uu, char *out)
58{
59 struct uuid uuid;
60
61 e2p_unpack_uuid(uu, &uuid);
62 sprintf(out,
63 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
64 uuid.time_low, uuid.time_mid, uuid.time_hi_and_version,
65 uuid.clock_seq >> 8, uuid.clock_seq & 0xFF,
66 uuid.node[0], uuid.node[1], uuid.node[2],
67 uuid.node[3], uuid.node[4], uuid.node[5]);
68}