fs/remap_range.c
Source file repositories/reference/linux-study-clean/fs/remap_range.c
File Facts
- System
- Linux kernel
- Corpus path
fs/remap_range.c- Extension
.c- Size
- 14415 bytes
- Lines
- 568
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/slab.hlinux/stat.hlinux/sched/xacct.hlinux/fcntl.hlinux/file.hlinux/uio.hlinux/fsnotify.hlinux/security.hlinux/export.hlinux/syscalls.hlinux/pagemap.hlinux/splice.hlinux/compat.hlinux/mount.hlinux/fs.hlinux/dax.hlinux/overflow.hinternal.hlinux/uaccess.hasm/unistd.h
Detected Declarations
function generic_remap_checksfunction remap_verify_areafunction generic_remap_check_lenfunction vfs_lock_two_foliosfunction vfs_unlock_two_foliosfunction vfs_dedupe_file_range_comparefunction __generic_remap_file_range_prepfunction generic_remap_file_range_prepfunction vfs_clone_file_rangefunction may_dedupe_filefunction vfs_dedupe_file_range_onefunction vfs_dedupe_file_rangeexport remap_verify_areaexport generic_remap_file_range_prepexport vfs_clone_file_rangeexport vfs_dedupe_file_range_oneexport vfs_dedupe_file_range
Annotated Snippet
if (IS_ERR(src_folio)) {
error = PTR_ERR(src_folio);
goto out_error;
}
dst_folio = vfs_dedupe_get_folio(dest, dstoff);
if (IS_ERR(dst_folio)) {
error = PTR_ERR(dst_folio);
folio_put(src_folio);
goto out_error;
}
vfs_lock_two_folios(src_folio, dst_folio);
/*
* Now that we've locked both folios, make sure they're still
* mapped to the file data we're interested in. If not,
* someone is invalidating pages on us and we lose.
*/
if (!folio_test_uptodate(src_folio) || !folio_test_uptodate(dst_folio) ||
src_folio->mapping != src->f_mapping ||
dst_folio->mapping != dest->f_mapping) {
same = false;
goto unlock;
}
src_addr = kmap_local_folio(src_folio,
offset_in_folio(src_folio, srcoff));
dst_addr = kmap_local_folio(dst_folio,
offset_in_folio(dst_folio, dstoff));
flush_dcache_folio(src_folio);
flush_dcache_folio(dst_folio);
if (memcmp(src_addr, dst_addr, cmp_len))
same = false;
kunmap_local(dst_addr);
kunmap_local(src_addr);
unlock:
vfs_unlock_two_folios(src_folio, dst_folio);
folio_put(dst_folio);
folio_put(src_folio);
if (!same)
break;
srcoff += cmp_len;
dstoff += cmp_len;
len -= cmp_len;
}
*is_same = same;
return 0;
out_error:
return error;
}
/*
* Check that the two inodes are eligible for cloning, the ranges make
* sense, and then flush all dirty data. Caller must ensure that the
* inodes have been locked against any other modifications.
*
* If there's an error, then the usual negative error code is returned.
* Otherwise returns 0 with *len set to the request length.
*/
int
__generic_remap_file_range_prep(struct file *file_in, loff_t pos_in,
struct file *file_out, loff_t pos_out,
loff_t *len, unsigned int remap_flags,
const struct iomap_ops *dax_read_ops)
{
struct inode *inode_in = file_inode(file_in);
struct inode *inode_out = file_inode(file_out);
bool same_inode = (inode_in == inode_out);
int ret;
/* Don't touch certain kinds of inodes */
if (IS_IMMUTABLE(inode_out))
return -EPERM;
if (IS_SWAPFILE(inode_in) || IS_SWAPFILE(inode_out))
return -ETXTBSY;
/* Don't reflink dirs, pipes, sockets... */
if (S_ISDIR(inode_in->i_mode) || S_ISDIR(inode_out->i_mode))
return -EISDIR;
if (!S_ISREG(inode_in->i_mode) || !S_ISREG(inode_out->i_mode))
return -EINVAL;
Annotation
- Immediate include surface: `linux/slab.h`, `linux/stat.h`, `linux/sched/xacct.h`, `linux/fcntl.h`, `linux/file.h`, `linux/uio.h`, `linux/fsnotify.h`, `linux/security.h`.
- Detected declarations: `function generic_remap_checks`, `function remap_verify_area`, `function generic_remap_check_len`, `function vfs_lock_two_folios`, `function vfs_unlock_two_folios`, `function vfs_dedupe_file_range_compare`, `function __generic_remap_file_range_prep`, `function generic_remap_file_range_prep`, `function vfs_clone_file_range`, `function may_dedupe_file`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: integration 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.