1 This is a rehash of a patch from Andreas Gruenbacher <agruen@suse.de>
2 to have XFS use a kernel-provided qsort function (ie. not it's own).
3 It requires (but does not conflict with) the previous patch I posted
4 adding qsort to the kernel library functions.
11 xfs/linux/xfs_linux.h | 1
12 xfs/support/qsort.c | 155 --------------------------------------------------
13 xfs/support/qsort.h | 41 -------------
14 4 files changed, 1 insertion(+), 197 deletions(-)
18 diff -Nru a/fs/Kconfig b/fs/Kconfig
19 --- a/fs/Kconfig Sun May 9 20:27:31 2004
20 +++ b/fs/Kconfig Sun May 9 20:27:31 2004
24 tristate "XFS filesystem support"
27 XFS is a high performance journaling filesystem which originated
28 on the SGI IRIX platform. It is completely multi-threaded, can
29 diff -Nru a/fs/xfs/linux-2.6/xfs_linux.h b/fs/xfs/linux-2.6/xfs_linux.h
30 --- a/fs/xfs/linux-2.6/xfs_linux.h Sun May 9 20:27:31 2004
31 +++ b/fs/xfs/linux-2.6/xfs_linux.h Sun May 9 20:27:31 2004
36 -#include <support/qsort.h>
37 #include <support/ktrace.h>
38 #include <support/debug.h>
39 #include <support/move.h>
40 diff -Nru a/fs/xfs/support/qsort.c b/fs/xfs/support/qsort.c
41 --- a/fs/xfs/support/qsort.c Sun May 9 20:27:31 2004
42 +++ b/fs/xfs/support/qsort.c Sun May 9 20:27:31 2004
45 - * Copyright (c) 1992, 1993
46 - * The Regents of the University of California. All rights reserved.
48 - * Redistribution and use in source and binary forms, with or without
49 - * modification, are permitted provided that the following conditions
51 - * 1. Redistributions of source code must retain the above copyright
52 - * notice, this list of conditions and the following disclaimer.
53 - * 2. Redistributions in binary form must reproduce the above copyright
54 - * notice, this list of conditions and the following disclaimer in the
55 - * documentation and/or other materials provided with the distribution.
56 - * 3. Neither the name of the University nor the names of its contributors
57 - * may be used to endorse or promote products derived from this software
58 - * without specific prior written permission.
60 - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
61 - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
62 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
63 - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
64 - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
65 - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
66 - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
67 - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
68 - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
69 - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
73 -#include <linux/kernel.h>
74 -#include <linux/string.h>
77 - * Qsort routine from Bentley & McIlroy's "Engineering a Sort Function".
79 -#define swapcode(TYPE, parmi, parmj, n) { \
80 - long i = (n) / sizeof (TYPE); \
81 - register TYPE *pi = (TYPE *) (parmi); \
82 - register TYPE *pj = (TYPE *) (parmj); \
84 - register TYPE t = *pi; \
87 - } while (--i > 0); \
90 -#define SWAPINIT(a, es) swaptype = ((char *)a - (char *)0) % sizeof(long) || \
91 - es % sizeof(long) ? 2 : es == sizeof(long)? 0 : 1;
94 -swapfunc(char *a, char *b, int n, int swaptype)
97 - swapcode(long, a, b, n)
99 - swapcode(char, a, b, n)
102 -#define swap(a, b) \
103 - if (swaptype == 0) { \
104 - long t = *(long *)(a); \
105 - *(long *)(a) = *(long *)(b); \
106 - *(long *)(b) = t; \
108 - swapfunc(a, b, es, swaptype)
110 -#define vecswap(a, b, n) if ((n) > 0) swapfunc(a, b, n, swaptype)
112 -static __inline char *
113 -med3(char *a, char *b, char *c, int (*cmp)(const void *, const void *))
115 - return cmp(a, b) < 0 ?
116 - (cmp(b, c) < 0 ? b : (cmp(a, c) < 0 ? c : a ))
117 - :(cmp(b, c) > 0 ? b : (cmp(a, c) < 0 ? a : c ));
121 -qsort(void *aa, size_t n, size_t es, int (*cmp)(const void *, const void *))
123 - char *pa, *pb, *pc, *pd, *pl, *pm, *pn;
124 - int d, r, swaptype, swap_cnt;
125 - register char *a = aa;
127 -loop: SWAPINIT(a, es);
130 - for (pm = (char *)a + es; pm < (char *) a + n * es; pm += es)
131 - for (pl = pm; pl > (char *) a && cmp(pl - es, pl) > 0;
136 - pm = (char *)a + (n / 2) * es;
139 - pn = (char *)a + (n - 1) * es;
142 - pl = med3(pl, pl + d, pl + 2 * d, cmp);
143 - pm = med3(pm - d, pm, pm + d, cmp);
144 - pn = med3(pn - 2 * d, pn - d, pn, cmp);
146 - pm = med3(pl, pm, pn, cmp);
149 - pa = pb = (char *)a + es;
151 - pc = pd = (char *)a + (n - 1) * es;
153 - while (pb <= pc && (r = cmp(pb, a)) <= 0) {
161 - while (pb <= pc && (r = cmp(pc, a)) >= 0) {
176 - if (swap_cnt == 0) { /* Switch to insertion sort */
177 - for (pm = (char *) a + es; pm < (char *) a + n * es; pm += es)
178 - for (pl = pm; pl > (char *) a && cmp(pl - es, pl) > 0;
184 - pn = (char *)a + n * es;
185 - r = min(pa - (char *)a, pb - pa);
186 - vecswap(a, pb - r, r);
187 - r = min((long)(pd - pc), (long)(pn - pd - es));
188 - vecswap(pb, pn - r, r);
189 - if ((r = pb - pa) > es)
190 - qsort(a, r / es, es, cmp);
191 - if ((r = pd - pc) > es) {
192 - /* Iterate rather than recurse to save stack space */
197 -/* qsort(pn - r, r / es, es, cmp);*/
199 diff -Nru a/fs/xfs/support/qsort.h b/fs/xfs/support/qsort.h
200 --- a/fs/xfs/support/qsort.h Sun May 9 20:27:31 2004
201 +++ b/fs/xfs/support/qsort.h Sun May 9 20:27:31 2004
204 - * Copyright (c) 2000-2002 Silicon Graphics, Inc. All Rights Reserved.
206 - * This program is free software; you can redistribute it and/or modify it
207 - * under the terms of version 2 of the GNU General Public License as
208 - * published by the Free Software Foundation.
210 - * This program is distributed in the hope that it would be useful, but
211 - * WITHOUT ANY WARRANTY; without even the implied warranty of
212 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
214 - * Further, this software is distributed without any warranty that it is
215 - * free of the rightful claim of any third person regarding infringement
216 - * or the like. Any license provided herein, whether implied or
217 - * otherwise, applies only to this software file. Patent licenses, if
218 - * any, provided herein do not apply to combinations of this program with
219 - * other software, or any other product whatsoever.
221 - * You should have received a copy of the GNU General Public License along
222 - * with this program; if not, write the Free Software Foundation, Inc., 59
223 - * Temple Place - Suite 330, Boston MA 02111-1307, USA.
225 - * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
226 - * Mountain View, CA 94043, or:
228 - * http://www.sgi.com
230 - * For further information regarding this notice, see:
232 - * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
238 -extern void qsort (void *const pbase,
239 - size_t total_elems,
241 - int (*cmp)(const void *, const void *));