aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/support/uuid.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /fs/xfs/support/uuid.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'fs/xfs/support/uuid.c')
-rw-r--r--fs/xfs/support/uuid.c151
1 files changed, 151 insertions, 0 deletions
diff --git a/fs/xfs/support/uuid.c b/fs/xfs/support/uuid.c
new file mode 100644
index 000000000000..81f40cfcb267
--- /dev/null
+++ b/fs/xfs/support/uuid.c
@@ -0,0 +1,151 @@
1/*
2 * Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31 */
32
33#include <xfs.h>
34
35static mutex_t uuid_monitor;
36static int uuid_table_size;
37static uuid_t *uuid_table;
38
39void
40uuid_init(void)
41{
42 mutex_init(&uuid_monitor, MUTEX_DEFAULT, "uuid_monitor");
43}
44
45/*
46 * uuid_getnodeuniq - obtain the node unique fields of a UUID.
47 *
48 * This is not in any way a standard or condoned UUID function;
49 * it just something that's needed for user-level file handles.
50 */
51void
52uuid_getnodeuniq(uuid_t *uuid, int fsid [2])
53{
54 char *uu = (char *)uuid;
55
56 /* on IRIX, this function assumes big-endian fields within
57 * the uuid, so we use INT_GET to get the same result on
58 * little-endian systems
59 */
60
61 fsid[0] = (INT_GET(*(u_int16_t*)(uu+8), ARCH_CONVERT) << 16) +
62 INT_GET(*(u_int16_t*)(uu+4), ARCH_CONVERT);
63 fsid[1] = INT_GET(*(u_int32_t*)(uu ), ARCH_CONVERT);
64}
65
66void
67uuid_create_nil(uuid_t *uuid)
68{
69 memset(uuid, 0, sizeof(*uuid));
70}
71
72int
73uuid_is_nil(uuid_t *uuid)
74{
75 int i;
76 char *cp = (char *)uuid;
77
78 if (uuid == NULL)
79 return 0;
80 /* implied check of version number here... */
81 for (i = 0; i < sizeof *uuid; i++)
82 if (*cp++) return 0; /* not nil */
83 return 1; /* is nil */
84}
85
86int
87uuid_equal(uuid_t *uuid1, uuid_t *uuid2)
88{
89 return memcmp(uuid1, uuid2, sizeof(uuid_t)) ? 0 : 1;
90}
91
92/*
93 * Given a 128-bit uuid, return a 64-bit value by adding the top and bottom
94 * 64-bit words. NOTE: This function can not be changed EVER. Although
95 * brain-dead, some applications depend on this 64-bit value remaining
96 * persistent. Specifically, DMI vendors store the value as a persistent
97 * filehandle.
98 */
99__uint64_t
100uuid_hash64(uuid_t *uuid)
101{
102 __uint64_t *sp = (__uint64_t *)uuid;
103
104 return sp[0] + sp[1];
105}
106
107int
108uuid_table_insert(uuid_t *uuid)
109{
110 int i, hole;
111
112 mutex_lock(&uuid_monitor, PVFS);
113 for (i = 0, hole = -1; i < uuid_table_size; i++) {
114 if (uuid_is_nil(&uuid_table[i])) {
115 hole = i;
116 continue;
117 }
118 if (uuid_equal(uuid, &uuid_table[i])) {
119 mutex_unlock(&uuid_monitor);
120 return 0;
121 }
122 }
123 if (hole < 0) {
124 uuid_table = kmem_realloc(uuid_table,
125 (uuid_table_size + 1) * sizeof(*uuid_table),
126 uuid_table_size * sizeof(*uuid_table),
127 KM_SLEEP);
128 hole = uuid_table_size++;
129 }
130 uuid_table[hole] = *uuid;
131 mutex_unlock(&uuid_monitor);
132 return 1;
133}
134
135void
136uuid_table_remove(uuid_t *uuid)
137{
138 int i;
139
140 mutex_lock(&uuid_monitor, PVFS);
141 for (i = 0; i < uuid_table_size; i++) {
142 if (uuid_is_nil(&uuid_table[i]))
143 continue;
144 if (!uuid_equal(uuid, &uuid_table[i]))
145 continue;
146 uuid_create_nil(&uuid_table[i]);
147 break;
148 }
149 ASSERT(i < uuid_table_size);
150 mutex_unlock(&uuid_monitor);
151}