2 * Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved.
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.
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.
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.
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.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
35 static mutex_t uuid_monitor
;
36 static int uuid_table_size
;
37 static uuid_t
*uuid_table
;
42 mutex_init(&uuid_monitor
, MUTEX_DEFAULT
, "uuid_monitor");
46 * uuid_getnodeuniq - obtain the node unique fields of a UUID.
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.
52 uuid_getnodeuniq(uuid_t
*uuid
, int fsid
[2])
54 char *uu
= (char *)uuid
;
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
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
);
67 uuid_create_nil(uuid_t
*uuid
)
69 memset(uuid
, 0, sizeof(*uuid
));
73 uuid_is_nil(uuid_t
*uuid
)
76 char *cp
= (char *)uuid
;
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 */
87 uuid_equal(uuid_t
*uuid1
, uuid_t
*uuid2
)
89 return memcmp(uuid1
, uuid2
, sizeof(uuid_t
)) ? 0 : 1;
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
100 uuid_hash64(uuid_t
*uuid
)
102 __uint64_t
*sp
= (__uint64_t
*)uuid
;
104 return sp
[0] + sp
[1];
108 uuid_table_insert(uuid_t
*uuid
)
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
])) {
118 if (uuid_equal(uuid
, &uuid_table
[i
])) {
119 mutex_unlock(&uuid_monitor
);
124 uuid_table
= kmem_realloc(uuid_table
,
125 (uuid_table_size
+ 1) * sizeof(*uuid_table
),
126 uuid_table_size
* sizeof(*uuid_table
),
128 hole
= uuid_table_size
++;
130 uuid_table
[hole
] = *uuid
;
131 mutex_unlock(&uuid_monitor
);
136 uuid_table_remove(uuid_t
*uuid
)
140 mutex_lock(&uuid_monitor
, PVFS
);
141 for (i
= 0; i
< uuid_table_size
; i
++) {
142 if (uuid_is_nil(&uuid_table
[i
]))
144 if (!uuid_equal(uuid
, &uuid_table
[i
]))
146 uuid_create_nil(&uuid_table
[i
]);
149 ASSERT(i
< uuid_table_size
);
150 mutex_unlock(&uuid_monitor
);