fs/btrfs/tests/free-space-tree-tests.c
Source file repositories/reference/linux-study-clean/fs/btrfs/tests/free-space-tree-tests.c
File Facts
- System
- Linux kernel
- Corpus path
fs/btrfs/tests/free-space-tree-tests.c- Extension
.c- Size
- 14975 bytes
- Lines
- 587
- 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.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/types.hbtrfs-tests.h../ctree.h../disk-io.h../free-space-tree.h../transaction.h../block-group.h../accessors.h
Detected Declarations
struct free_space_extentfunction __check_free_space_extentsfunction check_free_space_extentsfunction test_empty_block_groupfunction test_remove_allfunction test_remove_beginningfunction test_remove_endfunction test_remove_middlefunction test_merge_leftfunction test_merge_rightfunction test_merge_bothfunction test_merge_nonefunction run_testfunction run_test_both_formatsfunction btrfs_test_free_space_tree
Annotated Snippet
struct free_space_extent {
u64 start;
u64 length;
};
static int __check_free_space_extents(struct btrfs_trans_handle *trans,
struct btrfs_fs_info *fs_info,
struct btrfs_block_group *cache,
struct btrfs_path *path,
const struct free_space_extent * const extents,
unsigned int num_extents)
{
struct btrfs_free_space_info *info;
struct btrfs_key key;
int prev_bit = 0, bit;
u64 extent_start = 0, offset, end;
u32 flags, extent_count;
unsigned int i;
int ret;
info = btrfs_search_free_space_info(trans, cache, path, 0);
if (IS_ERR(info)) {
test_err("could not find free space info");
ret = PTR_ERR(info);
goto out;
}
flags = btrfs_free_space_flags(path->nodes[0], info);
extent_count = btrfs_free_space_extent_count(path->nodes[0], info);
if (extent_count != num_extents) {
test_err("extent count is wrong");
ret = -EINVAL;
goto out;
}
if (flags & BTRFS_FREE_SPACE_USING_BITMAPS) {
if (path->slots[0] != 0)
goto invalid;
end = btrfs_block_group_end(cache);
i = 0;
while (++path->slots[0] < btrfs_header_nritems(path->nodes[0])) {
btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
if (key.type != BTRFS_FREE_SPACE_BITMAP_KEY)
goto invalid;
offset = key.objectid;
while (offset < key.objectid + key.offset) {
bit = btrfs_free_space_test_bit(cache, path, offset);
if (prev_bit == 0 && bit == 1) {
extent_start = offset;
} else if (prev_bit == 1 && bit == 0) {
if (i >= num_extents ||
extent_start != extents[i].start ||
offset - extent_start != extents[i].length)
goto invalid;
i++;
}
prev_bit = bit;
offset += fs_info->sectorsize;
}
}
if (prev_bit == 1) {
if (i >= num_extents ||
extent_start != extents[i].start ||
end - extent_start != extents[i].length)
goto invalid;
i++;
}
if (i != num_extents)
goto invalid;
} else {
if (btrfs_header_nritems(path->nodes[0]) != num_extents + 1 ||
path->slots[0] != 0)
goto invalid;
for (i = 0; i < num_extents; i++) {
path->slots[0]++;
btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
if (key.type != BTRFS_FREE_SPACE_EXTENT_KEY ||
key.objectid != extents[i].start ||
key.offset != extents[i].length)
goto invalid;
}
}
ret = 0;
out:
btrfs_release_path(path);
return ret;
invalid:
test_err("free space tree is invalid");
ret = -EINVAL;
goto out;
Annotation
- Immediate include surface: `linux/types.h`, `btrfs-tests.h`, `../ctree.h`, `../disk-io.h`, `../free-space-tree.h`, `../transaction.h`, `../block-group.h`, `../accessors.h`.
- Detected declarations: `struct free_space_extent`, `function __check_free_space_extents`, `function check_free_space_extents`, `function test_empty_block_group`, `function test_remove_all`, `function test_remove_beginning`, `function test_remove_end`, `function test_remove_middle`, `function test_merge_left`, `function test_merge_right`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.