2 * Public include file for the UUID library
4 * Copyright (C) 1996, 1997, 1998 Theodore Ts'o.
5 * Copyright (C) 2002 Cluster File System
6 * - changed for use in lustre
9 * This file may be redistributed under the terms of the GNU
10 * Library General Public License.
13 #define DEBUG_SUBSYSTEM S_CLASS
16 # include <liblustre.h>
19 #include <obd_support.h>
20 #include <obd_class.h>
25 __u16 time_hi_and_version;
30 static void uuid_unpack(class_uuid_t in, struct uuid *uu)
36 tmp = (tmp << 8) | *ptr++;
37 tmp = (tmp << 8) | *ptr++;
38 tmp = (tmp << 8) | *ptr++;
42 tmp = (tmp << 8) | *ptr++;
46 tmp = (tmp << 8) | *ptr++;
47 uu->time_hi_and_version = tmp;
50 tmp = (tmp << 8) | *ptr++;
53 memcpy(uu->node, ptr, 6);
57 static void uuid_pack(struct uuid *uu, class_uuid_t ptr)
60 unsigned char *out = ptr;
63 out[3] = (unsigned char) tmp;
65 out[2] = (unsigned char) tmp;
67 out[1] = (unsigned char) tmp;
69 out[0] = (unsigned char) tmp;
72 out[5] = (unsigned char) tmp;
74 out[4] = (unsigned char) tmp;
76 tmp = uu->time_hi_and_version;
77 out[7] = (unsigned char) tmp;
79 out[6] = (unsigned char) tmp;
82 out[9] = (unsigned char) tmp;
84 out[8] = (unsigned char) tmp;
86 memcpy(out+10, uu->node, 6);
89 int class_uuid_parse(struct obd_uuid in, class_uuid_t uu)
97 for (i=0, cp = in; i <= 36; i++,cp++) {
98 if ((i == 8) || (i == 13) || (i == 18) ||
108 uuid.time_low = simple_strtoul(in, NULL, 16);
109 uuid.time_mid = simple_strtoul(in+9, NULL, 16);
110 uuid.time_hi_and_version = simple_strtoul(in+14, NULL, 16);
111 uuid.clock_seq = simple_strtoul(in+19, NULL, 16);
114 for (i=0; i < 6; i++) {
117 uuid.node[i] = simple_strtoul(buf, NULL, 16);
120 uuid_pack(&uuid, uu);
126 void generate_random_uuid(unsigned char uuid_out[16]);
128 /* We need to have some extra twiddling here because some systems have
129 * no random state when they start up. */
130 void class_generate_random_uuid(class_uuid_t uuid)
135 LASSERT(sizeof(class_uuid_t) % sizeof(*i) == 0);
141 generate_random_uuid(uuid);
143 for (i = (int *)uuid; (char *)i < (char *)uuid + sizeof(class_uuid_t); i++) {
145 j = ((j << 8) & 0xffffff00) | ((j >> 24) & 0x000000ff);
146 k = ((k >> 8) & 0x00ffffff) | ((k << 24) & 0xff000000);
150 void class_uuid_unparse(class_uuid_t uu, struct obd_uuid *out)
154 uuid_unpack(uu, &uuid);
156 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
157 uuid.time_low, uuid.time_mid, uuid.time_hi_and_version,
158 uuid.clock_seq >> 8, uuid.clock_seq & 0xFF,
159 uuid.node[0], uuid.node[1], uuid.node[2],
160 uuid.node[3], uuid.node[4], uuid.node[5]);