fs/btrfs/misc.h

Source file repositories/reference/linux-study-clean/fs/btrfs/misc.h

File Facts

System
Linux kernel
Corpus path
fs/btrfs/misc.h
Extension
.h
Size
5811 bytes
Lines
228
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

struct rb_simple_node {
	struct rb_node rb_node;
	u64 bytenr;
};

static inline struct rb_node *rb_simple_search(const struct rb_root *root, u64 bytenr)
{
	struct rb_node *node = root->rb_node;
	struct rb_simple_node *entry;

	while (node) {
		entry = rb_entry(node, struct rb_simple_node, rb_node);

		if (bytenr < entry->bytenr)
			node = node->rb_left;
		else if (bytenr > entry->bytenr)
			node = node->rb_right;
		else
			return node;
	}
	return NULL;
}

/*
 * Search @root from an entry that starts or comes after @bytenr.
 *
 * @root:	the root to search.
 * @bytenr:	bytenr to search from.
 *
 * Return the rb_node that start at or after @bytenr.  If there is no entry at
 * or after @bytner return NULL.
 */
static inline struct rb_node *rb_simple_search_first(const struct rb_root *root,
						     u64 bytenr)
{
	struct rb_node *node = root->rb_node, *ret = NULL;
	struct rb_simple_node *entry, *ret_entry = NULL;

	while (node) {
		entry = rb_entry(node, struct rb_simple_node, rb_node);

		if (bytenr < entry->bytenr) {
			if (!ret || entry->bytenr < ret_entry->bytenr) {
				ret = node;
				ret_entry = entry;
			}

			node = node->rb_left;
		} else if (bytenr > entry->bytenr) {
			node = node->rb_right;
		} else {
			return node;
		}
	}

	return ret;
}

static int rb_simple_node_bytenr_cmp(struct rb_node *new, const struct rb_node *existing)
{
	struct rb_simple_node *new_entry = rb_entry(new, struct rb_simple_node, rb_node);
	struct rb_simple_node *existing_entry = rb_entry(existing, struct rb_simple_node, rb_node);

	if (new_entry->bytenr < existing_entry->bytenr)
		return -1;
	else if (new_entry->bytenr > existing_entry->bytenr)
		return 1;

	return 0;
}

static inline struct rb_node *rb_simple_insert(struct rb_root *root,
					       struct rb_simple_node *simple_node)
{
	return rb_find_add(&simple_node->rb_node, root, rb_simple_node_bytenr_cmp);
}

static inline bool bitmap_test_range_all_set(const unsigned long *addr,
					     unsigned long start,
					     unsigned long nbits)
{
	unsigned long found_zero;

	found_zero = find_next_zero_bit(addr, start + nbits, start);
	return (found_zero == start + nbits);
}

static inline bool bitmap_test_range_all_zero(const unsigned long *addr,
					      unsigned long start,
					      unsigned long nbits)

Annotation

Implementation Notes