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 #include <linux/ctype.h>
14 #include <linux/kernel.h>
16 #define DEBUG_SUBSYSTEM S_CLASS
18 #include <linux/obd_support.h>
19 #include <linux/obd_class.h>
20 #include <linux/smp_lock.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);
125 void class_uuid_unparse(class_uuid_t uu, struct obd_uuid *out)
129 uuid_unpack(uu, &uuid);
131 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
132 uuid.time_low, uuid.time_mid, uuid.time_hi_and_version,
133 uuid.clock_seq >> 8, uuid.clock_seq & 0xFF,
134 uuid.node[0], uuid.node[1], uuid.node[2],
135 uuid.node[3], uuid.node[4], uuid.node[5]);