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>
27 #include <string.h> /* for ffs - confirm POSIX */
29 #define BITS_PER_WORD 32
30 #define OFF_BY_START(start) ((start)/BITS_PER_WORD)
32 unsigned long find_next_bit(const unsigned int *addr,
33 unsigned long size, unsigned long offset)
35 uint32_t *word, *last;
36 unsigned int first_bit, bit, base;
38 word = addr + OFF_BY_START(offset);
39 last = addr + OFF_BY_START(size-1);
40 first_bit = offset % BITS_PER_WORD;
41 base = offset - first_bit;
46 int tmp = (*word++) & (~0UL << first_bit);
48 if (bit < BITS_PER_WORD)
51 base += BITS_PER_WORD;
53 while (word <= last) {
59 base += BITS_PER_WORD;
66 unsigned long find_next_zero_bit(const unsigned int *addr,
67 unsigned long size, unsigned long offset)
69 uint32_t *word, *last;
70 unsigned int first_bit, bit, base;
72 word = addr + OFF_BY_START(offset);
73 last = addr + OFF_BY_START(size-1);
74 first_bit = offset % BITS_PER_WORD;
75 base = offset - first_bit;
80 int tmp = (*word++) & (~0UL << first_bit);
82 if (bit < BITS_PER_WORD)
85 base += BITS_PER_WORD;
87 while (word <= last) {
93 base += BITS_PER_WORD;