fs/btrfs/inode.c
Source file repositories/reference/linux-study-clean/fs/btrfs/inode.c
File Facts
- System
- Linux kernel
- Corpus path
fs/btrfs/inode.c- Extension
.c- Size
- 312092 bytes
- Lines
- 10609
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: operation-table or driver-model contract
- Status
- pattern 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 an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/kernel.hlinux/bio.hlinux/blk-cgroup.hlinux/file.hlinux/filelock.hlinux/fs.hlinux/fs_struct.hlinux/pagemap.hlinux/highmem.hlinux/time.hlinux/init.hlinux/string.hlinux/backing-dev.hlinux/writeback.hlinux/compat.hlinux/xattr.hlinux/posix_acl.hlinux/falloc.hlinux/slab.hlinux/ratelimit.hlinux/btrfs.hlinux/blkdev.hlinux/posix_acl_xattr.hlinux/uio.hlinux/magic.hlinux/iversion.hlinux/swap.hlinux/migrate.hlinux/sched/mm.hlinux/iomap.hlinux/unaligned.hmisc.h
Detected Declarations
struct btrfs_iget_argsstruct btrfs_rename_ctxstruct data_reloc_warnstruct async_extentstruct async_chunkstruct async_cowstruct can_nocow_file_extent_argsstruct dir_entrystruct btrfs_delalloc_workstruct btrfs_encoded_read_privatestruct btrfs_swap_infofunction data_reloc_print_warning_inodefunction print_data_reloc_errorfunction btrfs_print_data_csum_errorfunction btrfs_inode_lockfunction btrfs_inode_lockfunction btrfs_run_delalloc_rangefunction btrfs_init_inode_securityfunction insert_inline_extentfunction can_cow_file_range_inlinefunction can_cow_file_range_inlinefunction add_async_extentfunction inode_need_compressfunction inode_should_defragfunction extent_range_clear_dirty_for_iofunction offset_in_offsetfunction round_up_last_blockfunction compress_file_rangefunction submit_uncompressed_rangefunction submit_one_async_extentfunction btrfs_get_extent_allocation_hintfunction cow_one_rangefunction btrfs_reloc_clone_csumsfunction cow_file_rangefunction rangefunction rangefunction submit_compressed_extentsfunction run_delalloc_compressedfunction run_delalloc_cowfunction fallback_to_cowfunction can_nocow_file_extentfunction nocow_one_rangefunction run_delalloc_nocowfunction should_nocowfunction run_delalloc_inlinefunction allocationfunction btrfs_split_delalloc_extentfunction btrfs_merge_delalloc_extent
Annotated Snippet
static const struct file_operations btrfs_dir_file_operations;
static struct kmem_cache *btrfs_inode_cachep;
static int btrfs_setsize(struct inode *inode, struct iattr *attr);
static int btrfs_truncate(struct btrfs_inode *inode, bool skip_writeback);
static noinline int run_delalloc_cow(struct btrfs_inode *inode,
struct folio *locked_folio, u64 start,
u64 end, struct writeback_control *wbc,
bool pages_dirty);
static int data_reloc_print_warning_inode(u64 inum, u64 offset, u64 num_bytes,
u64 root, void *warn_ctx)
{
struct data_reloc_warn *warn = warn_ctx;
struct btrfs_fs_info *fs_info = warn->fs_info;
struct extent_buffer *eb;
struct btrfs_inode_item *inode_item;
struct inode_fs_paths *ipath __free(inode_fs_paths) = NULL;
struct btrfs_root *local_root;
struct btrfs_key key;
unsigned int nofs_flag;
u32 nlink;
int ret;
local_root = btrfs_get_fs_root(fs_info, root, true);
if (IS_ERR(local_root)) {
ret = PTR_ERR(local_root);
goto err;
}
/* This makes the path point to (inum INODE_ITEM ioff). */
key.objectid = inum;
key.type = BTRFS_INODE_ITEM_KEY;
key.offset = 0;
ret = btrfs_search_slot(NULL, local_root, &key, &warn->path, 0, 0);
if (ret) {
btrfs_put_root(local_root);
btrfs_release_path(&warn->path);
goto err;
}
eb = warn->path.nodes[0];
inode_item = btrfs_item_ptr(eb, warn->path.slots[0], struct btrfs_inode_item);
nlink = btrfs_inode_nlink(eb, inode_item);
btrfs_release_path(&warn->path);
nofs_flag = memalloc_nofs_save();
ipath = init_ipath(4096, local_root, &warn->path);
memalloc_nofs_restore(nofs_flag);
if (IS_ERR(ipath)) {
btrfs_put_root(local_root);
ret = PTR_ERR(ipath);
ipath = NULL;
/*
* -ENOMEM, not a critical error, just output an generic error
* without filename.
*/
btrfs_warn(fs_info,
"checksum error at logical %llu mirror %u root %llu, inode %llu offset %llu",
warn->logical, warn->mirror_num, root, inum, offset);
return ret;
}
ret = paths_from_inode(inum, ipath);
if (ret < 0) {
btrfs_put_root(local_root);
goto err;
}
/*
* We deliberately ignore the bit ipath might have been too small to
* hold all of the paths here
*/
for (int i = 0; i < ipath->fspath->elem_cnt; i++) {
btrfs_warn(fs_info,
"checksum error at logical %llu mirror %u root %llu inode %llu offset %llu length %u links %u (path: %s)",
warn->logical, warn->mirror_num, root, inum, offset,
fs_info->sectorsize, nlink,
(char *)(unsigned long)ipath->fspath->val[i]);
}
btrfs_put_root(local_root);
return 0;
err:
btrfs_warn(fs_info,
"checksum error at logical %llu mirror %u root %llu inode %llu offset %llu, path resolving failed with ret=%d",
warn->logical, warn->mirror_num, root, inum, offset, ret);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/bio.h`, `linux/blk-cgroup.h`, `linux/file.h`, `linux/filelock.h`, `linux/fs.h`, `linux/fs_struct.h`, `linux/pagemap.h`.
- Detected declarations: `struct btrfs_iget_args`, `struct btrfs_rename_ctx`, `struct data_reloc_warn`, `struct async_extent`, `struct async_chunk`, `struct async_cow`, `struct can_nocow_file_extent_args`, `struct dir_entry`, `struct btrfs_delalloc_work`, `struct btrfs_encoded_read_private`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.