fs/btrfs/root-tree.c
Source file repositories/reference/linux-study-clean/fs/btrfs/root-tree.c
File Facts
- System
- Linux kernel
- Corpus path
fs/btrfs/root-tree.c- Extension
.c- Size
- 14457 bytes
- Lines
- 529
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/err.hlinux/uuid.hctree.hfs.hmessages.htransaction.hdisk-io.hqgroup.hspace-info.haccessors.hroot-tree.horphan.h
Detected Declarations
function Copyrightfunction btrfs_find_rootfunction btrfs_set_root_nodefunction btrfs_update_rootfunction btrfs_insert_rootfunction btrfs_find_orphan_rootsfunction btrfs_del_rootfunction btrfs_del_root_reffunction btrfs_add_root_reffunction btrfs_check_and_init_root_itemfunction btrfs_update_root_timesfunction start_transaction
Annotated Snippet
if (btrfs_root_generation_v2(item) != 0) {
btrfs_warn(eb->fs_info,
"mismatching generation and generation_v2 found in root item. This root was probably mounted with an older kernel. Resetting all new fields.");
}
need_reset = true;
}
if (need_reset) {
/* Clear all members from generation_v2 onwards. */
memset_startat(item, 0, generation_v2);
generate_random_guid(item->uuid);
}
}
/*
* Lookup the root by the key.
*
* root: the root of the root tree
* search_key: the key to search
* path: the path we search
* root_item: the root item of the tree we look for
* root_key: the root key of the tree we look for
*
* If ->offset of 'search_key' is -1ULL, it means we are not sure the offset
* of the search key, just lookup the root with the highest offset for a
* given objectid.
*
* If we find something return 0, otherwise > 0, < 0 on error.
*/
int btrfs_find_root(struct btrfs_root *root, const struct btrfs_key *search_key,
struct btrfs_path *path, struct btrfs_root_item *root_item,
struct btrfs_key *root_key)
{
struct btrfs_key found_key;
struct extent_buffer *l;
int ret;
int slot;
ret = btrfs_search_slot(NULL, root, search_key, path, 0, 0);
if (ret < 0)
return ret;
if (search_key->offset != -1ULL) { /* the search key is exact */
if (ret > 0)
goto out;
} else {
/*
* Key with offset -1 found, there would have to exist a root
* with such id, but this is out of the valid range.
*/
if (unlikely(ret == 0)) {
ret = -EUCLEAN;
goto out;
}
if (path->slots[0] == 0)
goto out;
path->slots[0]--;
ret = 0;
}
l = path->nodes[0];
slot = path->slots[0];
btrfs_item_key_to_cpu(l, &found_key, slot);
if (found_key.objectid != search_key->objectid ||
found_key.type != BTRFS_ROOT_ITEM_KEY) {
ret = 1;
goto out;
}
if (root_item)
btrfs_read_root_item(l, slot, root_item);
if (root_key)
memcpy(root_key, &found_key, sizeof(found_key));
out:
btrfs_release_path(path);
return ret;
}
void btrfs_set_root_node(struct btrfs_root_item *item,
struct extent_buffer *node)
{
btrfs_set_root_bytenr(item, node->start);
btrfs_set_root_level(item, btrfs_header_level(node));
btrfs_set_root_generation(item, btrfs_header_generation(node));
}
/*
* copy the data in 'item' into the btree
*/
int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
Annotation
- Immediate include surface: `linux/err.h`, `linux/uuid.h`, `ctree.h`, `fs.h`, `messages.h`, `transaction.h`, `disk-io.h`, `qgroup.h`.
- Detected declarations: `function Copyright`, `function btrfs_find_root`, `function btrfs_set_root_node`, `function btrfs_update_root`, `function btrfs_insert_root`, `function btrfs_find_orphan_roots`, `function btrfs_del_root`, `function btrfs_del_root_ref`, `function btrfs_add_root_ref`, `function btrfs_check_and_init_root_item`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.