fs/read_write.c
Source file repositories/reference/linux-study-clean/fs/read_write.c
File Facts
- System
- Linux kernel
- Corpus path
fs/read_write.c- Extension
.c- Size
- 44789 bytes
- Lines
- 1823
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: syscall or user/kernel boundary
- Status
- core 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 or participates in a user/kernel boundary; inspect argument validation, copy_from_user/copy_to_user, credentials, and dispatch target.
- 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.
- 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/filelock.hinternal.hlinux/uaccess.hasm/unistd.h
Detected Declarations
syscall lseeksyscall llseeksyscall readsyscall writesyscall pread64syscall pwrite64syscall readvsyscall writevsyscall preadvsyscall preadv2syscall pwritevsyscall pwritev2syscall sendfilesyscall sendfile64syscall copy_file_rangefunction unsigned_offsetsfunction vfs_setpos_cookiefunction vfs_setposfunction must_set_posfunction readfunction unsynchronizedfunction generic_llseek_cookiefunction generic_file_llseekfunction fixed_size_llseekfunction no_seek_end_llseekfunction no_seek_end_llseek_sizefunction thefunction default_llseekfunction vfs_llseekfunction ksys_lseekfunction rw_verify_areafunction new_sync_readfunction warn_unsupportedfunction __kernel_readfunction kernel_readfunction vfs_readfunction new_sync_writefunction __kernel_write_iterfunction __kernel_writefunction kernel_writefunction vfs_writefunction ksys_readfunction ksys_writefunction ksys_pread64function ksys_pwrite64function do_iter_readv_writevfunction do_loop_readv_writevfunction vfs_iocb_iter_read
Annotated Snippet
SYSCALL_DEFINE3(lseek, unsigned int, fd, off_t, offset, unsigned int, whence)
{
return ksys_lseek(fd, offset, whence);
}
#ifdef CONFIG_COMPAT
COMPAT_SYSCALL_DEFINE3(lseek, unsigned int, fd, compat_off_t, offset, unsigned int, whence)
{
return ksys_lseek(fd, offset, whence);
}
#endif
#if !defined(CONFIG_64BIT) || defined(CONFIG_COMPAT) || \
defined(__ARCH_WANT_SYS_LLSEEK)
SYSCALL_DEFINE5(llseek, unsigned int, fd, unsigned long, offset_high,
unsigned long, offset_low, loff_t __user *, result,
unsigned int, whence)
{
int retval;
CLASS(fd_pos, f)(fd);
loff_t offset;
if (fd_empty(f))
return -EBADF;
if (whence > SEEK_MAX)
return -EINVAL;
offset = vfs_llseek(fd_file(f), ((loff_t) offset_high << 32) | offset_low,
whence);
retval = (int)offset;
if (offset >= 0) {
retval = -EFAULT;
if (!copy_to_user(result, &offset, sizeof(offset)))
retval = 0;
}
return retval;
}
#endif
int rw_verify_area(int read_write, struct file *file, const loff_t *ppos, size_t count)
{
int mask = read_write == READ ? MAY_READ : MAY_WRITE;
int ret;
if (unlikely((ssize_t) count < 0))
return -EINVAL;
if (ppos) {
loff_t pos = *ppos;
if (unlikely(pos < 0)) {
if (!unsigned_offsets(file))
return -EINVAL;
if (count >= -pos) /* both values are in 0..LLONG_MAX */
return -EOVERFLOW;
} else if (unlikely((loff_t) (pos + count) < 0)) {
if (!unsigned_offsets(file))
return -EINVAL;
}
}
ret = security_file_permission(file, mask);
if (ret)
return ret;
return fsnotify_file_area_perm(file, mask, ppos, count);
}
EXPORT_SYMBOL(rw_verify_area);
static ssize_t new_sync_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos)
{
struct kiocb kiocb;
struct iov_iter iter;
ssize_t ret;
init_sync_kiocb(&kiocb, filp);
kiocb.ki_pos = (ppos ? *ppos : 0);
iov_iter_ubuf(&iter, ITER_DEST, buf, len);
ret = filp->f_op->read_iter(&kiocb, &iter);
BUG_ON(ret == -EIOCBQUEUED);
if (ppos)
*ppos = kiocb.ki_pos;
return ret;
}
static int warn_unsupported(struct file *file, const char *op)
{
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: `syscall lseek`, `syscall llseek`, `syscall read`, `syscall write`, `syscall pread64`, `syscall pwrite64`, `syscall readv`, `syscall writev`, `syscall preadv`, `syscall preadv2`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: core 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.