2 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 static mutex_t uuid_monitor;
21 static int uuid_table_size;
22 static uuid_t *uuid_table;
24 /* IRIX interpretation of an uuid_t */
34 * uuid_getnodeuniq - obtain the node unique fields of a UUID.
36 * This is not in any way a standard or condoned UUID function;
37 * it just something that's needed for user-level file handles.
40 uuid_getnodeuniq(uuid_t *uuid, int fsid [2])
42 xfs_uu_t *uup = (xfs_uu_t *)uuid;
44 fsid[0] = (be16_to_cpu(uup->uu_clockseq) << 16) |
45 be16_to_cpu(uup->uu_timemid);
46 fsid[1] = be32_to_cpu(uup->uu_timelow);
50 uuid_create_nil(uuid_t *uuid)
52 memset(uuid, 0, sizeof(*uuid));
56 uuid_is_nil(uuid_t *uuid)
59 char *cp = (char *)uuid;
63 /* implied check of version number here... */
64 for (i = 0; i < sizeof *uuid; i++)
65 if (*cp++) return 0; /* not nil */
66 return 1; /* is nil */
70 uuid_equal(uuid_t *uuid1, uuid_t *uuid2)
72 return memcmp(uuid1, uuid2, sizeof(uuid_t)) ? 0 : 1;
76 * Given a 128-bit uuid, return a 64-bit value by adding the top and bottom
77 * 64-bit words. NOTE: This function can not be changed EVER. Although
78 * brain-dead, some applications depend on this 64-bit value remaining
79 * persistent. Specifically, DMI vendors store the value as a persistent
83 uuid_hash64(uuid_t *uuid)
85 __uint64_t *sp = (__uint64_t *)uuid;
91 uuid_table_insert(uuid_t *uuid)
95 mutex_lock(&uuid_monitor);
96 for (i = 0, hole = -1; i < uuid_table_size; i++) {
97 if (uuid_is_nil(&uuid_table[i])) {
101 if (uuid_equal(uuid, &uuid_table[i])) {
102 mutex_unlock(&uuid_monitor);
107 uuid_table = kmem_realloc(uuid_table,
108 (uuid_table_size + 1) * sizeof(*uuid_table),
109 uuid_table_size * sizeof(*uuid_table),
111 hole = uuid_table_size++;
113 uuid_table[hole] = *uuid;
114 mutex_unlock(&uuid_monitor);
119 uuid_table_remove(uuid_t *uuid)
123 mutex_lock(&uuid_monitor);
124 for (i = 0; i < uuid_table_size; i++) {
125 if (uuid_is_nil(&uuid_table[i]))
127 if (!uuid_equal(uuid, &uuid_table[i]))
129 uuid_create_nil(&uuid_table[i]);
132 ASSERT(i < uuid_table_size);
133 mutex_unlock(&uuid_monitor);
139 mutex_init(&uuid_monitor);