fs/xfs/xfs_exchrange.c
Source file repositories/reference/linux-study-clean/fs/xfs/xfs_exchrange.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/xfs_exchrange.c- Extension
.c- Size
- 26208 bytes
- Lines
- 924
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
xfs_platform.hxfs_shared.hxfs_format.hxfs_log_format.hxfs_trans_resv.hxfs_mount.hxfs_defer.hxfs_inode.hxfs_trans.hxfs_quota.hxfs_bmap_util.hxfs_reflink.hxfs_trace.hxfs_exchrange.hxfs_exchmaps.hxfs_sb.hxfs_icache.hxfs_log.hxfs_rtbitmap.hlinux/fsnotify.h
Detected Declarations
struct xfs_commit_range_freshfunction Copyrightfunction xfs_exchrange_iunlockfunction xfs_exchrange_estimatefunction xfs_exchrange_check_freshnessfunction xfs_exchrange_reserve_quotafunction xfs_exchrange_mappingsfunction xfs_exchange_range_checksfunction xfs_exchange_range_prepfunction xfs_exchange_range_finishfunction xfs_exchrange_check_rtalignfunction xfs_exchrange_prepfunction xfs_exchrange_contentsfunction xfs_exchange_rangefunction xfs_ioc_exchange_rangefunction xfs_ioc_start_commitfunction xfs_ioc_commit_range
Annotated Snippet
struct xfs_commit_range_fresh {
xfs_fsid_t fsid; /* m_fixedfsid */
__u64 file2_ino; /* inode number */
__s64 file2_mtime; /* modification time */
__s64 file2_ctime; /* change time */
__s32 file2_mtime_nsec; /* mod time, nsec */
__s32 file2_ctime_nsec; /* change time, nsec */
__u32 file2_gen; /* inode generation */
__u32 magic; /* zero */
};
#define XCR_FRESH_MAGIC 0x444F524B /* DORK */
/* Set up a commitrange operation by sampling file2's write-related attrs */
long
xfs_ioc_start_commit(
struct file *file,
struct xfs_commit_range __user *argp)
{
struct xfs_commit_range args = { };
struct kstat kstat = { };
struct xfs_commit_range_fresh *kern_f;
struct xfs_commit_range_fresh __user *user_f;
struct inode *inode2 = file_inode(file);
struct xfs_inode *ip2 = XFS_I(inode2);
const unsigned int lockflags = XFS_IOLOCK_SHARED |
XFS_MMAPLOCK_SHARED |
XFS_ILOCK_SHARED;
BUILD_BUG_ON(sizeof(struct xfs_commit_range_fresh) !=
sizeof(args.file2_freshness));
kern_f = (struct xfs_commit_range_fresh *)&args.file2_freshness;
memcpy(&kern_f->fsid, ip2->i_mount->m_fixedfsid, sizeof(xfs_fsid_t));
xfs_ilock(ip2, lockflags);
/* Force writing of a distinct ctime if any writes happen. */
fill_mg_cmtime(&kstat, STATX_CTIME | STATX_MTIME, inode2);
kern_f->file2_ctime = kstat.ctime.tv_sec;
kern_f->file2_ctime_nsec = kstat.ctime.tv_nsec;
kern_f->file2_mtime = kstat.mtime.tv_sec;
kern_f->file2_mtime_nsec = kstat.mtime.tv_nsec;
kern_f->file2_ino = inode2->i_ino;
kern_f->file2_gen = inode2->i_generation;
kern_f->magic = XCR_FRESH_MAGIC;
xfs_iunlock(ip2, lockflags);
user_f = (struct xfs_commit_range_fresh __user *)&argp->file2_freshness;
if (copy_to_user(user_f, kern_f, sizeof(*kern_f)))
return -EFAULT;
return 0;
}
/*
* Exchange file1 and file2 contents if file2 has not been written since the
* start commit operation.
*/
long
xfs_ioc_commit_range(
struct file *file,
struct xfs_commit_range __user *argp)
{
struct xfs_exchrange fxr = {
.file2 = file,
};
struct xfs_commit_range args;
struct xfs_commit_range_fresh *kern_f;
struct xfs_inode *ip2 = XFS_I(file_inode(file));
struct xfs_mount *mp = ip2->i_mount;
kern_f = (struct xfs_commit_range_fresh *)&args.file2_freshness;
if (copy_from_user(&args, argp, sizeof(args)))
return -EFAULT;
if (args.flags & ~XFS_EXCHANGE_RANGE_ALL_FLAGS)
return -EINVAL;
if (kern_f->magic != XCR_FRESH_MAGIC)
return -EBUSY;
if (memcmp(&kern_f->fsid, mp->m_fixedfsid, sizeof(xfs_fsid_t)))
return -EBUSY;
fxr.file1_offset = args.file1_offset;
fxr.file2_offset = args.file2_offset;
fxr.length = args.length;
fxr.flags = args.flags | __XFS_EXCHANGE_RANGE_CHECK_FRESH2;
fxr.file2_ino = kern_f->file2_ino;
fxr.file2_gen = kern_f->file2_gen;
fxr.file2_mtime.tv_sec = kern_f->file2_mtime;
fxr.file2_mtime.tv_nsec = kern_f->file2_mtime_nsec;
Annotation
- Immediate include surface: `xfs_platform.h`, `xfs_shared.h`, `xfs_format.h`, `xfs_log_format.h`, `xfs_trans_resv.h`, `xfs_mount.h`, `xfs_defer.h`, `xfs_inode.h`.
- Detected declarations: `struct xfs_commit_range_fresh`, `function Copyright`, `function xfs_exchrange_iunlock`, `function xfs_exchrange_estimate`, `function xfs_exchrange_check_freshness`, `function xfs_exchrange_reserve_quota`, `function xfs_exchrange_mappings`, `function xfs_exchange_range_checks`, `function xfs_exchange_range_prep`, `function xfs_exchange_range_finish`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
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.