fs/btrfs/file-item.c
Source file repositories/reference/linux-study-clean/fs/btrfs/file-item.c
File Facts
- System
- Linux kernel
- Corpus path
fs/btrfs/file-item.c- Extension
.c- Size
- 40184 bytes
- Lines
- 1410
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bio.hlinux/slab.hlinux/pagemap.hlinux/highmem.hlinux/sched/mm.hmessages.hctree.hdisk-io.htransaction.hbio.hcompression.hfs.haccessors.hfile-item.hvolumes.h
Detected Declarations
function Copyrightfunction btrfs_inode_set_file_extent_rangefunction btrfs_inode_clear_file_extent_rangefunction bytes_to_csum_sizefunction csum_size_to_bytesfunction max_ordered_sum_bytesfunction btrfs_ordered_sum_sizefunction btrfs_insert_hole_extentfunction btrfs_lookup_csumfunction btrfs_lookup_file_extentfunction search_csum_treefunction btrfs_lookup_bio_sumsfunction scheduledfunction btrfs_lookup_csums_listfunction btrfs_lookup_csums_listfunction csum_one_biofunction btrfs_bio_for_each_blockfunction csum_one_bio_workfunction btrfs_csum_one_biofunction btrfs_alloc_dummy_sumfunction truncate_one_csumfunction btrfs_del_csumsfunction find_next_csum_offsetfunction btrfs_insert_data_csumsfunction btrfs_mark_extent_writtenfunction btrfs_extent_item_to_extent_mapfunction offset
Annotated Snippet
if (csum_offset == csums_in_item) {
ret = -EFBIG;
goto fail;
} else if (csum_offset > csums_in_item) {
goto fail;
}
}
item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_csum_item);
item = (struct btrfs_csum_item *)((unsigned char *)item +
csum_offset * csum_size);
return item;
fail:
if (ret > 0)
ret = -ENOENT;
return ERR_PTR(ret);
}
int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
struct btrfs_path *path, u64 objectid,
u64 offset, int mod)
{
struct btrfs_key file_key;
int ins_len = mod < 0 ? -1 : 0;
int cow = mod != 0;
file_key.objectid = objectid;
file_key.type = BTRFS_EXTENT_DATA_KEY;
file_key.offset = offset;
return btrfs_search_slot(trans, root, &file_key, path, ins_len, cow);
}
/*
* Find checksums for logical bytenr range [disk_bytenr, disk_bytenr + len) and
* store the result to @dst.
*
* Return >0 for the number of sectors we found.
* Return 0 for the range [disk_bytenr, disk_bytenr + sectorsize) has no csum
* for it. Caller may want to try next sector until one range is hit.
* Return <0 for fatal error.
*/
static int search_csum_tree(struct btrfs_fs_info *fs_info,
struct btrfs_path *path, u64 disk_bytenr,
u64 len, u8 *dst)
{
struct btrfs_root *csum_root;
struct btrfs_csum_item *item = NULL;
struct btrfs_key key;
const u32 sectorsize = fs_info->sectorsize;
const u32 csum_size = fs_info->csum_size;
u32 itemsize;
int ret;
u64 csum_start;
u64 csum_len;
ASSERT(IS_ALIGNED(disk_bytenr, sectorsize) &&
IS_ALIGNED(len, sectorsize));
/* Check if the current csum item covers disk_bytenr */
if (path->nodes[0]) {
item = btrfs_item_ptr(path->nodes[0], path->slots[0],
struct btrfs_csum_item);
btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
itemsize = btrfs_item_size(path->nodes[0], path->slots[0]);
csum_start = key.offset;
csum_len = (itemsize / csum_size) * sectorsize;
if (in_range(disk_bytenr, csum_start, csum_len))
goto found;
}
/* Current item doesn't contain the desired range, search again */
btrfs_release_path(path);
csum_root = btrfs_csum_root(fs_info, disk_bytenr);
if (unlikely(!csum_root)) {
btrfs_err(fs_info,
"missing csum root for extent at bytenr %llu",
disk_bytenr);
return -EUCLEAN;
}
item = btrfs_lookup_csum(NULL, csum_root, path, disk_bytenr, 0);
if (IS_ERR(item)) {
ret = PTR_ERR(item);
goto out;
}
btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
itemsize = btrfs_item_size(path->nodes[0], path->slots[0]);
Annotation
- Immediate include surface: `linux/bio.h`, `linux/slab.h`, `linux/pagemap.h`, `linux/highmem.h`, `linux/sched/mm.h`, `messages.h`, `ctree.h`, `disk-io.h`.
- Detected declarations: `function Copyright`, `function btrfs_inode_set_file_extent_range`, `function btrfs_inode_clear_file_extent_range`, `function bytes_to_csum_size`, `function csum_size_to_bytes`, `function max_ordered_sum_bytes`, `function btrfs_ordered_sum_size`, `function btrfs_insert_hole_extent`, `function btrfs_lookup_csum`, `function btrfs_lookup_file_extent`.
- 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.