Whamcloud - gitweb
- make HEAD from b_post_cmd3
[fs/lustre-release.git] / lustre / obdclass / uuid.c
1 /*
2  * Public include file for the UUID library
3  * 
4  * Copyright (C) 1996, 1997, 1998 Theodore Ts'o.
5  * Copyright (C) 2002 Cluster File System
6  * - changed for use in lustre
7  *
8  * %Begin-Header%
9  * This file may be redistributed under the terms of the GNU 
10  * Library General Public License.
11  * %End-Header%
12  */
13 #define DEBUG_SUBSYSTEM S_CLASS
14
15 #ifndef __KERNEL__
16 # include <liblustre.h>
17 #endif
18
19 #include <obd_support.h>
20 #include <obd_class.h>
21
22 struct uuid {
23         __u32   time_low;
24         __u16   time_mid;
25         __u16   time_hi_and_version;
26         __u16   clock_seq;
27         __u8    node[6];
28 };
29
30 static void uuid_unpack(class_uuid_t in, struct uuid *uu)
31 {
32         __u8    *ptr = in;
33         __u32   tmp;
34
35         tmp = *ptr++;
36         tmp = (tmp << 8) | *ptr++;
37         tmp = (tmp << 8) | *ptr++;
38         tmp = (tmp << 8) | *ptr++;
39         uu->time_low = tmp;
40
41         tmp = *ptr++;
42         tmp = (tmp << 8) | *ptr++;
43         uu->time_mid = tmp;
44
45         tmp = *ptr++;
46         tmp = (tmp << 8) | *ptr++;
47         uu->time_hi_and_version = tmp;
48
49         tmp = *ptr++;
50         tmp = (tmp << 8) | *ptr++;
51         uu->clock_seq = tmp;
52
53         memcpy(uu->node, ptr, 6);
54 }
55
56 void generate_random_uuid(unsigned char uuid_out[16]);
57
58 void class_uuid_unparse(class_uuid_t uu, struct obd_uuid *out)
59 {
60         struct uuid uuid;
61
62         uuid_unpack(uu, &uuid);
63         sprintf(out->uuid,
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]);
69 }