fs/btrfs/file.c
Source file repositories/reference/linux-study-clean/fs/btrfs/file.c
File Facts
- System
- Linux kernel
- Corpus path
fs/btrfs/file.c- Extension
.c- Size
- 113957 bytes
- Lines
- 3890
- 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.
- 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/fs.hlinux/pagemap.hlinux/time.hlinux/init.hlinux/string.hlinux/backing-dev.hlinux/falloc.hlinux/filelock.hlinux/writeback.hlinux/compat.hlinux/slab.hlinux/btrfs.hlinux/uio.hlinux/iversion.hlinux/fsverity.hctree.hdirect-io.hdisk-io.htransaction.hbtrfs_inode.htree-log.hlocking.hqgroup.hcompression.hdelalloc-space.hreflink.hsubpage.hfs.haccessors.hextent-tree.hfile-item.hioctl.h
Detected Declarations
struct falloc_rangefunction Copyrightfunction copy_folio_from_iter_atomicfunction statfunction createdfunction btrfs_del_itemsfunction extent_mergeablefunction btrfs_mark_extent_writtenfunction prepare_uptodate_foliofunction btrfs_read_foliofunction get_prepare_gfp_flagsfunction prepare_one_foliofunction lock_and_cleanup_extent_if_needfunction blockfunction btrfs_check_nocow_unlockfunction btrfs_write_checkfunction release_spacefunction reserve_spacefunction shrink_reserved_spacefunction calc_write_bytesfunction copy_one_rangefunction btrfs_buffered_writefunction btrfs_encoded_writefunction btrfs_do_write_iterfunction btrfs_file_write_iterfunction btrfs_release_filefunction start_ordered_opsfunction skip_inode_loggingfunction btrfs_sync_filefunction btrfs_need_log_full_commitfunction btrfs_page_mkwritefunction btrfs_file_mmap_preparefunction hole_mergeablefunction fill_holesfunction find_first_non_holefunction filemap_range_has_pagefunction btrfs_punch_hole_lock_rangefunction btrfs_insert_replace_extentfunction inclusivefunction btrfs_punch_holefunction add_falloc_rangefunction btrfs_fallocate_update_isizefunction btrfs_zero_range_check_range_boundaryfunction btrfs_zero_rangefunction btrfs_fallocatefunction btrfs_find_delalloc_in_rangefunction delallocfunction delalloc
Annotated Snippet
const struct file_operations btrfs_file_operations = {
.llseek = btrfs_file_llseek,
.read_iter = btrfs_file_read_iter,
.splice_read = btrfs_file_splice_read,
.write_iter = btrfs_file_write_iter,
.splice_write = iter_file_splice_write,
.mmap_prepare = btrfs_file_mmap_prepare,
.open = btrfs_file_open,
.release = btrfs_release_file,
.get_unmapped_area = thp_get_unmapped_area,
.fsync = btrfs_sync_file,
.fallocate = btrfs_fallocate,
.unlocked_ioctl = btrfs_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = btrfs_compat_ioctl,
#endif
.remap_file_range = btrfs_remap_file_range,
.uring_cmd = btrfs_uring_cmd,
.fop_flags = FOP_BUFFER_RASYNC | FOP_BUFFER_WASYNC,
.setlease = generic_setlease,
};
int btrfs_fdatawrite_range(struct btrfs_inode *inode, loff_t start, loff_t end)
{
struct address_space *mapping = inode->vfs_inode.i_mapping;
int ret;
/*
* So with compression we will find and lock a dirty page and clear the
* first one as dirty, setup an async extent, and immediately return
* with the entire range locked but with nobody actually marked with
* writeback. So we can't just filemap_write_and_wait_range() and
* expect it to work since it will just kick off a thread to do the
* actual work. So we need to call filemap_fdatawrite_range _again_
* since it will wait on the page lock, which won't be unlocked until
* after the pages have been marked as writeback and so we're good to go
* from there. We have to do this otherwise we'll miss the ordered
* extents and that results in badness. Please Josef, do not think you
* know better and pull this out at some point in the future, it is
* right and you are wrong.
*/
ret = filemap_fdatawrite_range(mapping, start, end);
if (!ret && test_bit(BTRFS_INODE_HAS_ASYNC_EXTENT, &inode->runtime_flags))
ret = filemap_fdatawrite_range(mapping, start, end);
return ret;
}
Annotation
- Immediate include surface: `linux/fs.h`, `linux/pagemap.h`, `linux/time.h`, `linux/init.h`, `linux/string.h`, `linux/backing-dev.h`, `linux/falloc.h`, `linux/filelock.h`.
- Detected declarations: `struct falloc_range`, `function Copyright`, `function copy_folio_from_iter_atomic`, `function stat`, `function created`, `function btrfs_del_items`, `function extent_mergeable`, `function btrfs_mark_extent_written`, `function prepare_uptodate_folio`, `function btrfs_read_folio`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: pattern 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.