fs/btrfs/uuid-tree.c
Source file repositories/reference/linux-study-clean/fs/btrfs/uuid-tree.c
File Facts
- System
- Linux kernel
- Corpus path
fs/btrfs/uuid-tree.c- Extension
.c- Size
- 13180 bytes
- Lines
- 567
- 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/kthread.hlinux/uuid.hlinux/unaligned.hmessages.hctree.htransaction.hdisk-io.hfs.haccessors.huuid-tree.hioctl.h
Detected Declarations
function Copyrightfunction btrfs_uuid_tree_lookupfunction btrfs_uuid_tree_addfunction btrfs_uuid_tree_removefunction btrfs_uuid_tree_check_overflowfunction btrfs_uuid_iter_remfunction btrfs_check_uuid_tree_entryfunction btrfs_uuid_tree_iteratefunction btrfs_uuid_scan_kthreadfunction btrfs_create_uuid_tree
Annotated Snippet
if (le64_to_cpu(data) == subid) {
ret = 0;
break;
}
offset += sizeof(data);
item_size -= sizeof(data);
}
return ret;
}
int btrfs_uuid_tree_add(struct btrfs_trans_handle *trans, const u8 *uuid, u8 type,
u64 subid_cpu)
{
struct btrfs_fs_info *fs_info = trans->fs_info;
struct btrfs_root *uuid_root = fs_info->uuid_root;
int ret;
BTRFS_PATH_AUTO_FREE(path);
struct btrfs_key key;
struct extent_buffer *eb;
int slot;
unsigned long offset;
__le64 subid_le;
ret = btrfs_uuid_tree_lookup(uuid_root, uuid, type, subid_cpu);
if (ret != -ENOENT)
return ret;
btrfs_uuid_to_key(uuid, type, &key);
path = btrfs_alloc_path();
if (!path)
return -ENOMEM;
ret = btrfs_insert_empty_item(trans, uuid_root, path, &key,
sizeof(subid_le));
if (ret == 0) {
/* Add an item for the type for the first time */
eb = path->nodes[0];
slot = path->slots[0];
offset = btrfs_item_ptr_offset(eb, slot);
} else if (ret == -EEXIST) {
/*
* An item with that type already exists.
* Extend the item and store the new subid at the end.
*/
btrfs_extend_item(trans, path, sizeof(subid_le));
eb = path->nodes[0];
slot = path->slots[0];
offset = btrfs_item_ptr_offset(eb, slot);
offset += btrfs_item_size(eb, slot) - sizeof(subid_le);
} else {
btrfs_warn(fs_info,
"insert uuid item failed %d (0x%016llx, 0x%016llx) type %u!",
ret, key.objectid, key.offset, type);
return ret;
}
subid_le = cpu_to_le64(subid_cpu);
write_extent_buffer(eb, &subid_le, offset, sizeof(subid_le));
return 0;
}
int btrfs_uuid_tree_remove(struct btrfs_trans_handle *trans, const u8 *uuid, u8 type,
u64 subid)
{
struct btrfs_fs_info *fs_info = trans->fs_info;
struct btrfs_root *uuid_root = fs_info->uuid_root;
int ret;
BTRFS_PATH_AUTO_FREE(path);
struct btrfs_key key;
struct extent_buffer *eb;
int slot;
unsigned long offset;
u32 item_size;
unsigned long move_dst;
unsigned long move_src;
unsigned long move_len;
if (WARN_ON_ONCE(!uuid_root))
return -EINVAL;
btrfs_uuid_to_key(uuid, type, &key);
path = btrfs_alloc_path();
if (!path)
return -ENOMEM;
ret = btrfs_search_slot(trans, uuid_root, &key, path, -1, 1);
if (ret < 0) {
Annotation
- Immediate include surface: `linux/kthread.h`, `linux/uuid.h`, `linux/unaligned.h`, `messages.h`, `ctree.h`, `transaction.h`, `disk-io.h`, `fs.h`.
- Detected declarations: `function Copyright`, `function btrfs_uuid_tree_lookup`, `function btrfs_uuid_tree_add`, `function btrfs_uuid_tree_remove`, `function btrfs_uuid_tree_check_overflow`, `function btrfs_uuid_iter_rem`, `function btrfs_check_uuid_tree_entry`, `function btrfs_uuid_tree_iterate`, `function btrfs_uuid_scan_kthread`, `function btrfs_create_uuid_tree`.
- 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.