fs/ntfs3/bitfunc.c

Source file repositories/reference/linux-study-clean/fs/ntfs3/bitfunc.c

File Facts

System
Linux kernel
Corpus path
fs/ntfs3/bitfunc.c
Extension
.c
Size
2550 bytes
Lines
129
Domain
Core OS
Bucket
VFS And Filesystem Core
Inferred role
Core OS: implementation source
Status
source implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

if (nbits >= pos * 8) {
			for (nbits -= pos * 8; pos; pos--, map++) {
				if (*map)
					return false;
			}
		}
	}

	for (pos = nbits / BITS_IN_SIZE_T; pos; pos--, map += sizeof(size_t)) {
		if (*((size_t *)map))
			return false;
	}

	for (pos = (nbits % BITS_IN_SIZE_T) >> 3; pos; pos--, map++) {
		if (*map)
			return false;
	}

	pos = nbits & 7;
	if (pos && (*map & fill_mask[pos]))
		return false;

	return true;
}

/*
 * are_bits_set
 *
 * Return: True if all bits [bit, bit+nbits) are ones "1".
 */
bool are_bits_set(const void *lmap, size_t bit, size_t nbits)
{
	u8 mask;
	size_t pos = bit & 7;
	const u8 *map = (u8 *)lmap + (bit >> 3);

	if (pos) {
		if (8 - pos >= nbits) {
			mask = fill_mask[pos + nbits] & zero_mask[pos];
			return !nbits || (*map & mask) == mask;
		}

		mask = zero_mask[pos];
		if ((*map++ & mask) != mask)
			return false;
		nbits -= 8 - pos;
	}

	pos = ((size_t)map) & (sizeof(size_t) - 1);
	if (pos) {
		pos = sizeof(size_t) - pos;
		if (nbits >= pos * 8) {
			for (nbits -= pos * 8; pos; pos--, map++) {
				if (*map != 0xFF)
					return false;
			}
		}
	}

	for (pos = nbits / BITS_IN_SIZE_T; pos; pos--, map += sizeof(size_t)) {
		if (*((size_t *)map) != MINUS_ONE_T)
			return false;
	}

	for (pos = (nbits % BITS_IN_SIZE_T) >> 3; pos; pos--, map++) {
		if (*map != 0xFF)
			return false;
	}

	pos = nbits & 7;
	if (pos) {
		mask = fill_mask[pos];
		if ((*map & mask) != mask)
			return false;
	}

	return true;
}

Annotation

Implementation Notes