1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2007 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or modify it under the
9 * terms of version 2 of the GNU General Public License as published by the
10 * Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful, but WITHOUT ANY
13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along
18 * with Lustre; if not, write to the Free Software Foundation, Inc., 675 Mass
19 * Ave, Cambridge, MA 02139, USA.
24 #include <libcfs/libcfs.h>
25 #include <libcfs/kp30.h>
26 #include <libcfs/user-bitops.h>
28 #define OFF_BY_START(start) ((start)/BITS_PER_LONG)
30 unsigned long find_next_bit(unsigned long *addr,
31 unsigned long size, unsigned long offset)
33 unsigned long *word, *last;
34 unsigned long first_bit, bit, base;
36 word = addr + OFF_BY_START(offset);
37 last = addr + OFF_BY_START(size-1);
38 first_bit = offset % BITS_PER_LONG;
39 base = offset - first_bit;
44 int tmp = (*word++) & (~0UL << first_bit);
46 if (bit < BITS_PER_LONG)
49 base += BITS_PER_LONG;
51 while (word <= last) {
57 base += BITS_PER_LONG;
64 unsigned long find_next_zero_bit(unsigned long *addr,
65 unsigned long size, unsigned long offset)
67 unsigned long *word, *last;
68 unsigned long first_bit, bit, base;
70 word = addr + OFF_BY_START(offset);
71 last = addr + OFF_BY_START(size-1);
72 first_bit = offset % BITS_PER_LONG;
73 base = offset - first_bit;
78 int tmp = (*word++) & (~0UL << first_bit);
80 if (bit < BITS_PER_LONG)
83 base += BITS_PER_LONG;
85 while (word <= last) {
91 base += BITS_PER_LONG;