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 <linux/ctype.h>
17 # include <linux/kernel.h>
18 # include <linux/sched.h>
19 # include <linux/smp_lock.h>
21 # include <liblustre.h>
24 #include <linux/obd_support.h>
25 #include <linux/obd_class.h>
26 #include <linux/obd_ost.h> /* for LUSTRE_OST_NAME */
27 #include <linux/lustre_mds.h> /* for LUSTRE_MDC_NAME */
32 __u16 time_hi_and_version;
37 static void uuid_unpack(class_uuid_t in, struct uuid *uu)
43 tmp = (tmp << 8) | *ptr++;
44 tmp = (tmp << 8) | *ptr++;
45 tmp = (tmp << 8) | *ptr++;
49 tmp = (tmp << 8) | *ptr++;
53 tmp = (tmp << 8) | *ptr++;
54 uu->time_hi_and_version = tmp;
57 tmp = (tmp << 8) | *ptr++;
60 memcpy(uu->node, ptr, 6);
64 static void uuid_pack(struct uuid *uu, class_uuid_t ptr)
67 unsigned char *out = ptr;
70 out[3] = (unsigned char) tmp;
72 out[2] = (unsigned char) tmp;
74 out[1] = (unsigned char) tmp;
76 out[0] = (unsigned char) tmp;
79 out[5] = (unsigned char) tmp;
81 out[4] = (unsigned char) tmp;
83 tmp = uu->time_hi_and_version;
84 out[7] = (unsigned char) tmp;
86 out[6] = (unsigned char) tmp;
89 out[9] = (unsigned char) tmp;
91 out[8] = (unsigned char) tmp;
93 memcpy(out+10, uu->node, 6);
96 int class_uuid_parse(struct obd_uuid in, class_uuid_t uu)
102 if (strlen(in) != 36)
104 for (i=0, cp = in; i <= 36; i++,cp++) {
105 if ((i == 8) || (i == 13) || (i == 18) ||
115 uuid.time_low = simple_strtoul(in, NULL, 16);
116 uuid.time_mid = simple_strtoul(in+9, NULL, 16);
117 uuid.time_hi_and_version = simple_strtoul(in+14, NULL, 16);
118 uuid.clock_seq = simple_strtoul(in+19, NULL, 16);
121 for (i=0; i < 6; i++) {
124 uuid.node[i] = simple_strtoul(buf, NULL, 16);
127 uuid_pack(&uuid, uu);
132 void class_uuid_unparse(class_uuid_t uu, struct obd_uuid *out)
136 uuid_unpack(uu, &uuid);
138 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
139 uuid.time_low, uuid.time_mid, uuid.time_hi_and_version,
140 uuid.clock_seq >> 8, uuid.clock_seq & 0xFF,
141 uuid.node[0], uuid.node[1], uuid.node[2],
142 uuid.node[3], uuid.node[4], uuid.node[5]);