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/user-bitops.h>
27 #define OFF_BY_START(start) ((start)/BITS_PER_LONG)
29 unsigned long find_next_bit(unsigned long *addr,
30 unsigned long size, unsigned long offset)
32 unsigned long *word, *last;
33 unsigned long first_bit, bit, base;
35 word = addr + OFF_BY_START(offset);
36 last = addr + OFF_BY_START(size-1);
37 first_bit = offset % BITS_PER_LONG;
38 base = offset - first_bit;
43 int tmp = (*word++) & (~0UL << first_bit);
45 if (bit < BITS_PER_LONG)
48 base += BITS_PER_LONG;
50 while (word <= last) {
56 base += BITS_PER_LONG;
63 unsigned long find_next_zero_bit(unsigned long *addr,
64 unsigned long size, unsigned long offset)
66 unsigned long *word, *last;
67 unsigned long first_bit, bit, base;
69 word = addr + OFF_BY_START(offset);
70 last = addr + OFF_BY_START(size-1);
71 first_bit = offset % BITS_PER_LONG;
72 base = offset - first_bit;
77 int tmp = (*word++) & (~0UL << first_bit);
79 if (bit < BITS_PER_LONG)
82 base += BITS_PER_LONG;
84 while (word <= last) {
90 base += BITS_PER_LONG;