linux-brain/fs/xfs/libxfs/xfs_bit.c
Dave Chinner 0b61f8a407 xfs: convert to SPDX license tags
Remove the verbose license text from XFS files and replace them
with SPDX tags. This does not change the license of any of the code,
merely refers to the common, up-to-date license files in LICENSES/

This change was mostly scripted. fs/xfs/Makefile and
fs/xfs/libxfs/xfs_fs.h were modified by hand, the rest were detected
and modified by the following command:

for f in `git grep -l "GNU General" fs/xfs/` ; do
	echo $f
	cat $f | awk -f hdr.awk > $f.new
	mv -f $f.new $f
done

And the hdr.awk script that did the modification (including
detecting the difference between GPL-2.0 and GPL-2.0+ licenses)
is as follows:

$ cat hdr.awk
BEGIN {
	hdr = 1.0
	tag = "GPL-2.0"
	str = ""
}

/^ \* This program is free software/ {
	hdr = 2.0;
	next
}

/any later version./ {
	tag = "GPL-2.0+"
	next
}

/^ \*\// {
	if (hdr > 0.0) {
		print "// SPDX-License-Identifier: " tag
		print str
		print $0
		str=""
		hdr = 0.0
		next
	}
	print $0
	next
}

/^ \* / {
	if (hdr > 1.0)
		next
	if (hdr > 0.0) {
		if (str != "")
			str = str "\n"
		str = str $0
		next
	}
	print $0
	next
}

/^ \*/ {
	if (hdr > 0.0)
		next
	print $0
	next
}

// {
	if (hdr > 0.0) {
		if (str != "")
			str = str "\n"
		str = str $0
		next
	}
	print $0
}

END { }
$

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
2018-06-06 14:17:53 -07:00

107 lines
2.2 KiB
C

// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2000-2005 Silicon Graphics, Inc.
* All Rights Reserved.
*/
#include "xfs.h"
#include "xfs_log_format.h"
#include "xfs_bit.h"
/*
* XFS bit manipulation routines, used in non-realtime code.
*/
/*
* Return whether bitmap is empty.
* Size is number of words in the bitmap, which is padded to word boundary
* Returns 1 for empty, 0 for non-empty.
*/
int
xfs_bitmap_empty(uint *map, uint size)
{
uint i;
for (i = 0; i < size; i++) {
if (map[i] != 0)
return 0;
}
return 1;
}
/*
* Count the number of contiguous bits set in the bitmap starting with bit
* start_bit. Size is the size of the bitmap in words.
*/
int
xfs_contig_bits(uint *map, uint size, uint start_bit)
{
uint * p = ((unsigned int *) map) + (start_bit >> BIT_TO_WORD_SHIFT);
uint result = 0;
uint tmp;
size <<= BIT_TO_WORD_SHIFT;
ASSERT(start_bit < size);
size -= start_bit & ~(NBWORD - 1);
start_bit &= (NBWORD - 1);
if (start_bit) {
tmp = *p++;
/* set to one first offset bits prior to start */
tmp |= (~0U >> (NBWORD-start_bit));
if (tmp != ~0U)
goto found;
result += NBWORD;
size -= NBWORD;
}
while (size) {
if ((tmp = *p++) != ~0U)
goto found;
result += NBWORD;
size -= NBWORD;
}
return result - start_bit;
found:
return result + ffz(tmp) - start_bit;
}
/*
* This takes the bit number to start looking from and
* returns the next set bit from there. It returns -1
* if there are no more bits set or the start bit is
* beyond the end of the bitmap.
*
* Size is the number of words, not bytes, in the bitmap.
*/
int xfs_next_bit(uint *map, uint size, uint start_bit)
{
uint * p = ((unsigned int *) map) + (start_bit >> BIT_TO_WORD_SHIFT);
uint result = start_bit & ~(NBWORD - 1);
uint tmp;
size <<= BIT_TO_WORD_SHIFT;
if (start_bit >= size)
return -1;
size -= result;
start_bit &= (NBWORD - 1);
if (start_bit) {
tmp = *p++;
/* set to zero first offset bits prior to start */
tmp &= (~0U << start_bit);
if (tmp != 0U)
goto found;
result += NBWORD;
size -= NBWORD;
}
while (size) {
if ((tmp = *p++) != 0U)
goto found;
result += NBWORD;
size -= NBWORD;
}
return -1;
found:
return result + ffs(tmp) - 1;
}