aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/support
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
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')
-rw-r--r--fs/xfs/support/debug.c127
-rw-r--r--fs/xfs/support/debug.h72
-rw-r--r--fs/xfs/support/ktrace.c346
-rw-r--r--fs/xfs/support/ktrace.h101
-rw-r--r--fs/xfs/support/move.c66
-rw-r--r--fs/xfs/support/move.h84
-rw-r--r--fs/xfs/support/qsort.c155
-rw-r--r--fs/xfs/support/qsort.h41
-rw-r--r--fs/xfs/support/uuid.c151
-rw-r--r--fs/xfs/support/uuid.h48
10 files changed, 1191 insertions, 0 deletions
diff --git a/fs/xfs/support/debug.c b/fs/xfs/support/debug.c
new file mode 100644
index 000000000000..7d6e1f37df10
--- /dev/null
+++ b/fs/xfs/support/debug.c
@@ -0,0 +1,127 @@
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 "debug.h"
34
35#include <asm/page.h>
36#include <linux/sched.h>
37#include <linux/kernel.h>
38
39int doass = 1;
40static char message[256]; /* keep it off the stack */
41static DEFINE_SPINLOCK(xfs_err_lock);
42
43/* Translate from CE_FOO to KERN_FOO, err_level(CE_FOO) == KERN_FOO */
44#define XFS_MAX_ERR_LEVEL 7
45#define XFS_ERR_MASK ((1 << 3) - 1)
46static char *err_level[XFS_MAX_ERR_LEVEL+1] =
47 {KERN_EMERG, KERN_ALERT, KERN_CRIT,
48 KERN_ERR, KERN_WARNING, KERN_NOTICE,
49 KERN_INFO, KERN_DEBUG};
50
51void
52assfail(char *a, char *f, int l)
53{
54 printk("XFS assertion failed: %s, file: %s, line: %d\n", a, f, l);
55 BUG();
56}
57
58#if ((defined(DEBUG) || defined(INDUCE_IO_ERRROR)) && !defined(NO_WANT_RANDOM))
59
60unsigned long
61random(void)
62{
63 static unsigned long RandomValue = 1;
64 /* cycles pseudo-randomly through all values between 1 and 2^31 - 2 */
65 register long rv = RandomValue;
66 register long lo;
67 register long hi;
68
69 hi = rv / 127773;
70 lo = rv % 127773;
71 rv = 16807 * lo - 2836 * hi;
72 if( rv <= 0 ) rv += 2147483647;
73 return( RandomValue = rv );
74}
75
76int
77get_thread_id(void)
78{
79 return current->pid;
80}
81
82#endif /* DEBUG || INDUCE_IO_ERRROR || !NO_WANT_RANDOM */
83
84void
85cmn_err(register int level, char *fmt, ...)
86{
87 char *fp = fmt;
88 int len;
89 ulong flags;
90 va_list ap;
91
92 level &= XFS_ERR_MASK;
93 if (level > XFS_MAX_ERR_LEVEL)
94 level = XFS_MAX_ERR_LEVEL;
95 spin_lock_irqsave(&xfs_err_lock,flags);
96 va_start(ap, fmt);
97 if (*fmt == '!') fp++;
98 len = vsprintf(message, fp, ap);
99 if (message[len-1] != '\n')
100 strcat(message, "\n");
101 printk("%s%s", err_level[level], message);
102 va_end(ap);
103 spin_unlock_irqrestore(&xfs_err_lock,flags);
104
105 if (level == CE_PANIC)
106 BUG();
107}
108
109
110void
111icmn_err(register int level, char *fmt, va_list ap)
112{
113 ulong flags;
114 int len;
115
116 level &= XFS_ERR_MASK;
117 if(level > XFS_MAX_ERR_LEVEL)
118 level = XFS_MAX_ERR_LEVEL;
119 spin_lock_irqsave(&xfs_err_lock,flags);
120 len = vsprintf(message, fmt, ap);
121 if (message[len-1] != '\n')
122 strcat(message, "\n");
123 spin_unlock_irqrestore(&xfs_err_lock,flags);
124 printk("%s%s", err_level[level], message);
125 if (level == CE_PANIC)
126 BUG();
127}
diff --git a/fs/xfs/support/debug.h b/fs/xfs/support/debug.h
new file mode 100644
index 000000000000..40b0f4c54d9e
--- /dev/null
+++ b/fs/xfs/support/debug.h
@@ -0,0 +1,72 @@
1/*
2 * Copyright (c) 2000-2004 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#ifndef __XFS_SUPPORT_DEBUG_H__
33#define __XFS_SUPPORT_DEBUG_H__
34
35#include <stdarg.h>
36
37#define CE_DEBUG 7 /* debug */
38#define CE_CONT 6 /* continuation */
39#define CE_NOTE 5 /* notice */
40#define CE_WARN 4 /* warning */
41#define CE_ALERT 1 /* alert */
42#define CE_PANIC 0 /* panic */
43
44extern void icmn_err(int, char *, va_list);
45/* PRINTFLIKE2 */
46extern void cmn_err(int, char *, ...);
47
48#ifndef STATIC
49# define STATIC static
50#endif
51
52#ifdef DEBUG
53# ifdef lint
54# define ASSERT(EX) ((void)0) /* avoid "constant in conditional" babble */
55# else
56# define ASSERT(EX) ((!doass||(EX))?((void)0):assfail(#EX, __FILE__, __LINE__))
57# endif /* lint */
58#else
59# define ASSERT(x) ((void)0)
60#endif
61
62extern int doass; /* dynamically turn off asserts */
63extern void assfail(char *, char *, int);
64#ifdef DEBUG
65extern unsigned long random(void);
66extern int get_thread_id(void);
67#endif
68
69#define ASSERT_ALWAYS(EX) ((EX)?((void)0):assfail(#EX, __FILE__, __LINE__))
70#define debug_stop_all_cpus(param) /* param is "cpumask_t *" */
71
72#endif /* __XFS_SUPPORT_DEBUG_H__ */
diff --git a/fs/xfs/support/ktrace.c b/fs/xfs/support/ktrace.c
new file mode 100644
index 000000000000..3dae14c8c55a
--- /dev/null
+++ b/fs/xfs/support/ktrace.c
@@ -0,0 +1,346 @@
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 kmem_zone_t *ktrace_hdr_zone;
36static kmem_zone_t *ktrace_ent_zone;
37static int ktrace_zentries;
38
39void
40ktrace_init(int zentries)
41{
42 ktrace_zentries = zentries;
43
44 ktrace_hdr_zone = kmem_zone_init(sizeof(ktrace_t),
45 "ktrace_hdr");
46 ASSERT(ktrace_hdr_zone);
47
48 ktrace_ent_zone = kmem_zone_init(ktrace_zentries
49 * sizeof(ktrace_entry_t),
50 "ktrace_ent");
51 ASSERT(ktrace_ent_zone);
52}
53
54void
55ktrace_uninit(void)
56{
57 kmem_cache_destroy(ktrace_hdr_zone);
58 kmem_cache_destroy(ktrace_ent_zone);
59}
60
61/*
62 * ktrace_alloc()
63 *
64 * Allocate a ktrace header and enough buffering for the given
65 * number of entries.
66 */
67ktrace_t *
68ktrace_alloc(int nentries, int sleep)
69{
70 ktrace_t *ktp;
71 ktrace_entry_t *ktep;
72
73 ktp = (ktrace_t*)kmem_zone_alloc(ktrace_hdr_zone, sleep);
74
75 if (ktp == (ktrace_t*)NULL) {
76 /*
77 * KM_SLEEP callers don't expect failure.
78 */
79 if (sleep & KM_SLEEP)
80 panic("ktrace_alloc: NULL memory on KM_SLEEP request!");
81
82 return NULL;
83 }
84
85 /*
86 * Special treatment for buffers with the ktrace_zentries entries
87 */
88 if (nentries == ktrace_zentries) {
89 ktep = (ktrace_entry_t*)kmem_zone_zalloc(ktrace_ent_zone,
90 sleep);
91 } else {
92 ktep = (ktrace_entry_t*)kmem_zalloc((nentries * sizeof(*ktep)),
93 sleep);
94 }
95
96 if (ktep == NULL) {
97 /*
98 * KM_SLEEP callers don't expect failure.
99 */
100 if (sleep & KM_SLEEP)
101 panic("ktrace_alloc: NULL memory on KM_SLEEP request!");
102
103 kmem_free(ktp, sizeof(*ktp));
104
105 return NULL;
106 }
107
108 spinlock_init(&(ktp->kt_lock), "kt_lock");
109
110 ktp->kt_entries = ktep;
111 ktp->kt_nentries = nentries;
112 ktp->kt_index = 0;
113 ktp->kt_rollover = 0;
114 return ktp;
115}
116
117
118/*
119 * ktrace_free()
120 *
121 * Free up the ktrace header and buffer. It is up to the caller
122 * to ensure that no-one is referencing it.
123 */
124void
125ktrace_free(ktrace_t *ktp)
126{
127 int entries_size;
128
129 if (ktp == (ktrace_t *)NULL)
130 return;
131
132 spinlock_destroy(&ktp->kt_lock);
133
134 /*
135 * Special treatment for the Vnode trace buffer.
136 */
137 if (ktp->kt_nentries == ktrace_zentries) {
138 kmem_zone_free(ktrace_ent_zone, ktp->kt_entries);
139 } else {
140 entries_size = (int)(ktp->kt_nentries * sizeof(ktrace_entry_t));
141
142 kmem_free(ktp->kt_entries, entries_size);
143 }
144
145 kmem_zone_free(ktrace_hdr_zone, ktp);
146}
147
148
149/*
150 * Enter the given values into the "next" entry in the trace buffer.
151 * kt_index is always the index of the next entry to be filled.
152 */
153void
154ktrace_enter(
155 ktrace_t *ktp,
156 void *val0,
157 void *val1,
158 void *val2,
159 void *val3,
160 void *val4,
161 void *val5,
162 void *val6,
163 void *val7,
164 void *val8,
165 void *val9,
166 void *val10,
167 void *val11,
168 void *val12,
169 void *val13,
170 void *val14,
171 void *val15)
172{
173 static lock_t wrap_lock = SPIN_LOCK_UNLOCKED;
174 unsigned long flags;
175 int index;
176 ktrace_entry_t *ktep;
177
178 ASSERT(ktp != NULL);
179
180 /*
181 * Grab an entry by pushing the index up to the next one.
182 */
183 spin_lock_irqsave(&wrap_lock, flags);
184 index = ktp->kt_index;
185 if (++ktp->kt_index == ktp->kt_nentries)
186 ktp->kt_index = 0;
187 spin_unlock_irqrestore(&wrap_lock, flags);
188
189 if (!ktp->kt_rollover && index == ktp->kt_nentries - 1)
190 ktp->kt_rollover = 1;
191
192 ASSERT((index >= 0) && (index < ktp->kt_nentries));
193
194 ktep = &(ktp->kt_entries[index]);
195
196 ktep->val[0] = val0;
197 ktep->val[1] = val1;
198 ktep->val[2] = val2;
199 ktep->val[3] = val3;
200 ktep->val[4] = val4;
201 ktep->val[5] = val5;
202 ktep->val[6] = val6;
203 ktep->val[7] = val7;
204 ktep->val[8] = val8;
205 ktep->val[9] = val9;
206 ktep->val[10] = val10;
207 ktep->val[11] = val11;
208 ktep->val[12] = val12;
209 ktep->val[13] = val13;
210 ktep->val[14] = val14;
211 ktep->val[15] = val15;
212}
213
214/*
215 * Return the number of entries in the trace buffer.
216 */
217int
218ktrace_nentries(
219 ktrace_t *ktp)
220{
221 if (ktp == NULL) {
222 return 0;
223 }
224
225 return (ktp->kt_rollover ? ktp->kt_nentries : ktp->kt_index);
226}
227
228/*
229 * ktrace_first()
230 *
231 * This is used to find the start of the trace buffer.
232 * In conjunction with ktrace_next() it can be used to
233 * iterate through the entire trace buffer. This code does
234 * not do any locking because it is assumed that it is called
235 * from the debugger.
236 *
237 * The caller must pass in a pointer to a ktrace_snap
238 * structure in which we will keep some state used to
239 * iterate through the buffer. This state must not touched
240 * by any code outside of this module.
241 */
242ktrace_entry_t *
243ktrace_first(ktrace_t *ktp, ktrace_snap_t *ktsp)
244{
245 ktrace_entry_t *ktep;
246 int index;
247 int nentries;
248
249 if (ktp->kt_rollover)
250 index = ktp->kt_index;
251 else
252 index = 0;
253
254 ktsp->ks_start = index;
255 ktep = &(ktp->kt_entries[index]);
256
257 nentries = ktrace_nentries(ktp);
258 index++;
259 if (index < nentries) {
260 ktsp->ks_index = index;
261 } else {
262 ktsp->ks_index = 0;
263 if (index > nentries)
264 ktep = NULL;
265 }
266 return ktep;
267}
268
269/*
270 * ktrace_next()
271 *
272 * This is used to iterate through the entries of the given
273 * trace buffer. The caller must pass in the ktrace_snap_t
274 * structure initialized by ktrace_first(). The return value
275 * will be either a pointer to the next ktrace_entry or NULL
276 * if all of the entries have been traversed.
277 */
278ktrace_entry_t *
279ktrace_next(
280 ktrace_t *ktp,
281 ktrace_snap_t *ktsp)
282{
283 int index;
284 ktrace_entry_t *ktep;
285
286 index = ktsp->ks_index;
287 if (index == ktsp->ks_start) {
288 ktep = NULL;
289 } else {
290 ktep = &ktp->kt_entries[index];
291 }
292
293 index++;
294 if (index == ktrace_nentries(ktp)) {
295 ktsp->ks_index = 0;
296 } else {
297 ktsp->ks_index = index;
298 }
299
300 return ktep;
301}
302
303/*
304 * ktrace_skip()
305 *
306 * Skip the next "count" entries and return the entry after that.
307 * Return NULL if this causes us to iterate past the beginning again.
308 */
309ktrace_entry_t *
310ktrace_skip(
311 ktrace_t *ktp,
312 int count,
313 ktrace_snap_t *ktsp)
314{
315 int index;
316 int new_index;
317 ktrace_entry_t *ktep;
318 int nentries = ktrace_nentries(ktp);
319
320 index = ktsp->ks_index;
321 new_index = index + count;
322 while (new_index >= nentries) {
323 new_index -= nentries;
324 }
325 if (index == ktsp->ks_start) {
326 /*
327 * We've iterated around to the start, so we're done.
328 */
329 ktep = NULL;
330 } else if ((new_index < index) && (index < ktsp->ks_index)) {
331 /*
332 * We've skipped past the start again, so we're done.
333 */
334 ktep = NULL;
335 ktsp->ks_index = ktsp->ks_start;
336 } else {
337 ktep = &(ktp->kt_entries[new_index]);
338 new_index++;
339 if (new_index == nentries) {
340 ktsp->ks_index = 0;
341 } else {
342 ktsp->ks_index = new_index;
343 }
344 }
345 return ktep;
346}
diff --git a/fs/xfs/support/ktrace.h b/fs/xfs/support/ktrace.h
new file mode 100644
index 000000000000..92d1a1a5d04b
--- /dev/null
+++ b/fs/xfs/support/ktrace.h
@@ -0,0 +1,101 @@
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#ifndef __XFS_SUPPORT_KTRACE_H__
33#define __XFS_SUPPORT_KTRACE_H__
34
35#include <spin.h>
36
37/*
38 * Trace buffer entry structure.
39 */
40typedef struct ktrace_entry {
41 void *val[16];
42} ktrace_entry_t;
43
44/*
45 * Trace buffer header structure.
46 */
47typedef struct ktrace {
48 lock_t kt_lock; /* mutex to guard counters */
49 int kt_nentries; /* number of entries in trace buf */
50 int kt_index; /* current index in entries */
51 int kt_rollover;
52 ktrace_entry_t *kt_entries; /* buffer of entries */
53} ktrace_t;
54
55/*
56 * Trace buffer snapshot structure.
57 */
58typedef struct ktrace_snap {
59 int ks_start; /* kt_index at time of snap */
60 int ks_index; /* current index */
61} ktrace_snap_t;
62
63
64#ifdef CONFIG_XFS_TRACE
65
66extern void ktrace_init(int zentries);
67extern void ktrace_uninit(void);
68
69extern ktrace_t *ktrace_alloc(int, int);
70extern void ktrace_free(ktrace_t *);
71
72extern void ktrace_enter(
73 ktrace_t *,
74 void *,
75 void *,
76 void *,
77 void *,
78 void *,
79 void *,
80 void *,
81 void *,
82 void *,
83 void *,
84 void *,
85 void *,
86 void *,
87 void *,
88 void *,
89 void *);
90
91extern ktrace_entry_t *ktrace_first(ktrace_t *, ktrace_snap_t *);
92extern int ktrace_nentries(ktrace_t *);
93extern ktrace_entry_t *ktrace_next(ktrace_t *, ktrace_snap_t *);
94extern ktrace_entry_t *ktrace_skip(ktrace_t *, int, ktrace_snap_t *);
95
96#else
97#define ktrace_init(x) do { } while (0)
98#define ktrace_uninit() do { } while (0)
99#endif /* CONFIG_XFS_TRACE */
100
101#endif /* __XFS_SUPPORT_KTRACE_H__ */
diff --git a/fs/xfs/support/move.c b/fs/xfs/support/move.c
new file mode 100644
index 000000000000..15b5194f16b2
--- /dev/null
+++ b/fs/xfs/support/move.c
@@ -0,0 +1,66 @@
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
35/* Read from kernel buffer at src to user/kernel buffer defined
36 * by the uio structure. Advance the pointer in the uio struct
37 * as we go.
38 */
39int
40uio_read(caddr_t src, size_t len, struct uio *uio)
41{
42 size_t count;
43
44 if (!len || !uio->uio_resid)
45 return 0;
46
47 count = uio->uio_iov->iov_len;
48 if (!count)
49 return 0;
50 if (count > len)
51 count = len;
52
53 if (uio->uio_segflg == UIO_USERSPACE) {
54 if (copy_to_user(uio->uio_iov->iov_base, src, count))
55 return EFAULT;
56 } else {
57 ASSERT(uio->uio_segflg == UIO_SYSSPACE);
58 memcpy(uio->uio_iov->iov_base, src, count);
59 }
60
61 uio->uio_iov->iov_base = (void*)((char*)uio->uio_iov->iov_base + count);
62 uio->uio_iov->iov_len -= count;
63 uio->uio_offset += count;
64 uio->uio_resid -= count;
65 return 0;
66}
diff --git a/fs/xfs/support/move.h b/fs/xfs/support/move.h
new file mode 100644
index 000000000000..3d406dc1c89e
--- /dev/null
+++ b/fs/xfs/support/move.h
@@ -0,0 +1,84 @@
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 * Portions Copyright (c) 1982, 1986, 1993, 1994
33 * The Regents of the University of California. All rights reserved.
34 *
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
37 * are met:
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * 2. Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 * 3. Neither the name of the University nor the names of its contributors
44 * may be used to endorse or promote products derived from this software
45 * without specific prior written permission.
46 *
47 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
48 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 * SUCH DAMAGE.
58 */
59#ifndef __XFS_SUPPORT_MOVE_H__
60#define __XFS_SUPPORT_MOVE_H__
61
62#include <linux/uio.h>
63#include <asm/uaccess.h>
64
65/* Segment flag values. */
66enum uio_seg {
67 UIO_USERSPACE, /* from user data space */
68 UIO_SYSSPACE, /* from system space */
69};
70
71struct uio {
72 struct iovec *uio_iov; /* pointer to array of iovecs */
73 int uio_iovcnt; /* number of iovecs in array */
74 xfs_off_t uio_offset; /* offset in file this uio corresponds to */
75 int uio_resid; /* residual i/o count */
76 enum uio_seg uio_segflg; /* see above */
77};
78
79typedef struct uio uio_t;
80typedef struct iovec iovec_t;
81
82extern int uio_read (caddr_t, size_t, uio_t *);
83
84#endif /* __XFS_SUPPORT_MOVE_H__ */
diff --git a/fs/xfs/support/qsort.c b/fs/xfs/support/qsort.c
new file mode 100644
index 000000000000..1ec824140cf7
--- /dev/null
+++ b/fs/xfs/support/qsort.c
@@ -0,0 +1,155 @@
1/*
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <linux/kernel.h>
31#include <linux/string.h>
32
33/*
34 * Qsort routine from Bentley & McIlroy's "Engineering a Sort Function".
35 */
36#define swapcode(TYPE, parmi, parmj, n) { \
37 long i = (n) / sizeof (TYPE); \
38 register TYPE *pi = (TYPE *) (parmi); \
39 register TYPE *pj = (TYPE *) (parmj); \
40 do { \
41 register TYPE t = *pi; \
42 *pi++ = *pj; \
43 *pj++ = t; \
44 } while (--i > 0); \
45}
46
47#define SWAPINIT(a, es) swaptype = ((char *)a - (char *)0) % sizeof(long) || \
48 es % sizeof(long) ? 2 : es == sizeof(long)? 0 : 1;
49
50static __inline void
51swapfunc(char *a, char *b, int n, int swaptype)
52{
53 if (swaptype <= 1)
54 swapcode(long, a, b, n)
55 else
56 swapcode(char, a, b, n)
57}
58
59#define swap(a, b) \
60 if (swaptype == 0) { \
61 long t = *(long *)(a); \
62 *(long *)(a) = *(long *)(b); \
63 *(long *)(b) = t; \
64 } else \
65 swapfunc(a, b, es, swaptype)
66
67#define vecswap(a, b, n) if ((n) > 0) swapfunc(a, b, n, swaptype)
68
69static __inline char *
70med3(char *a, char *b, char *c, int (*cmp)(const void *, const void *))
71{
72 return cmp(a, b) < 0 ?
73 (cmp(b, c) < 0 ? b : (cmp(a, c) < 0 ? c : a ))
74 :(cmp(b, c) > 0 ? b : (cmp(a, c) < 0 ? a : c ));
75}
76
77void
78qsort(void *aa, size_t n, size_t es, int (*cmp)(const void *, const void *))
79{
80 char *pa, *pb, *pc, *pd, *pl, *pm, *pn;
81 int d, r, swaptype, swap_cnt;
82 register char *a = aa;
83
84loop: SWAPINIT(a, es);
85 swap_cnt = 0;
86 if (n < 7) {
87 for (pm = (char *)a + es; pm < (char *) a + n * es; pm += es)
88 for (pl = pm; pl > (char *) a && cmp(pl - es, pl) > 0;
89 pl -= es)
90 swap(pl, pl - es);
91 return;
92 }
93 pm = (char *)a + (n / 2) * es;
94 if (n > 7) {
95 pl = (char *)a;
96 pn = (char *)a + (n - 1) * es;
97 if (n > 40) {
98 d = (n / 8) * es;
99 pl = med3(pl, pl + d, pl + 2 * d, cmp);
100 pm = med3(pm - d, pm, pm + d, cmp);
101 pn = med3(pn - 2 * d, pn - d, pn, cmp);
102 }
103 pm = med3(pl, pm, pn, cmp);
104 }
105 swap(a, pm);
106 pa = pb = (char *)a + es;
107
108 pc = pd = (char *)a + (n - 1) * es;
109 for (;;) {
110 while (pb <= pc && (r = cmp(pb, a)) <= 0) {
111 if (r == 0) {
112 swap_cnt = 1;
113 swap(pa, pb);
114 pa += es;
115 }
116 pb += es;
117 }
118 while (pb <= pc && (r = cmp(pc, a)) >= 0) {
119 if (r == 0) {
120 swap_cnt = 1;
121 swap(pc, pd);
122 pd -= es;
123 }
124 pc -= es;
125 }
126 if (pb > pc)
127 break;
128 swap(pb, pc);
129 swap_cnt = 1;
130 pb += es;
131 pc -= es;
132 }
133 if (swap_cnt == 0) { /* Switch to insertion sort */
134 for (pm = (char *) a + es; pm < (char *) a + n * es; pm += es)
135 for (pl = pm; pl > (char *) a && cmp(pl - es, pl) > 0;
136 pl -= es)
137 swap(pl, pl - es);
138 return;
139 }
140
141 pn = (char *)a + n * es;
142 r = min(pa - (char *)a, pb - pa);
143 vecswap(a, pb - r, r);
144 r = min((long)(pd - pc), (long)(pn - pd - es));
145 vecswap(pb, pn - r, r);
146 if ((r = pb - pa) > es)
147 qsort(a, r / es, es, cmp);
148 if ((r = pd - pc) > es) {
149 /* Iterate rather than recurse to save stack space */
150 a = pn - r;
151 n = r / es;
152 goto loop;
153 }
154/* qsort(pn - r, r / es, es, cmp);*/
155}
diff --git a/fs/xfs/support/qsort.h b/fs/xfs/support/qsort.h
new file mode 100644
index 000000000000..94263106d716
--- /dev/null
+++ b/fs/xfs/support/qsort.h
@@ -0,0 +1,41 @@
1/*
2 * Copyright (c) 2000-2002 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#ifndef QSORT_H
34#define QSORT_H
35
36extern void qsort (void *const pbase,
37 size_t total_elems,
38 size_t size,
39 int (*cmp)(const void *, const void *));
40
41#endif
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}
diff --git a/fs/xfs/support/uuid.h b/fs/xfs/support/uuid.h
new file mode 100644
index 000000000000..5220ea58ba2b
--- /dev/null
+++ b/fs/xfs/support/uuid.h
@@ -0,0 +1,48 @@
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#ifndef __XFS_SUPPORT_UUID_H__
33#define __XFS_SUPPORT_UUID_H__
34
35typedef struct {
36 unsigned char __u_bits[16];
37} uuid_t;
38
39void uuid_init(void);
40void uuid_create_nil(uuid_t *uuid);
41int uuid_is_nil(uuid_t *uuid);
42int uuid_equal(uuid_t *uuid1, uuid_t *uuid2);
43void uuid_getnodeuniq(uuid_t *uuid, int fsid [2]);
44__uint64_t uuid_hash64(uuid_t *uuid);
45int uuid_table_insert(uuid_t *uuid);
46void uuid_table_remove(uuid_t *uuid);
47
48#endif /* __XFS_SUPPORT_UUID_H__ */