fs/ioctl.c
Source file repositories/reference/linux-study-clean/fs/ioctl.c
File Facts
- System
- Linux kernel
- Corpus path
fs/ioctl.c- Extension
.c- Size
- 17348 bytes
- Lines
- 703
- 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/syscalls.hlinux/mm.hlinux/capability.hlinux/compat.hlinux/file.hlinux/fs.hlinux/security.hlinux/export.hlinux/uaccess.hlinux/writeback.hlinux/buffer_head.hlinux/falloc.hlinux/sched/signal.hlinux/fiemap.hlinux/mount.hlinux/fscrypt.hlinux/fileattr.hinternal.hasm/ioctls.h
Detected Declarations
syscall ioctlfunction vfs_ioctlfunction ioctl_fibmapfunction fiemap_fill_next_extentfunction fiemap_prepfunction ioctl_fiemapfunction ioctl_file_clonefunction ioctl_file_clone_rangefunction ioctl_preallocatefunction compat_ioctl_preallocatefunction file_ioctlfunction ioctl_fionbiofunction ioctl_fioasyncfunction ioctl_fsfreezefunction ioctl_fsthawfunction ioctl_file_dedupe_rangefunction ioctl_getfsuuidfunction ioctl_get_fs_sysfs_pathfunction do_vfs_ioctlfunction compat_ptrexport fiemap_fill_next_extentexport fiemap_prepexport compat_ptr_ioctl
Annotated Snippet
SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, unsigned long, arg)
{
CLASS(fd, f)(fd);
int error;
if (fd_empty(f))
return -EBADF;
error = security_file_ioctl(fd_file(f), cmd, arg);
if (error)
return error;
error = do_vfs_ioctl(fd_file(f), fd, cmd, arg);
if (error == -ENOIOCTLCMD)
error = vfs_ioctl(fd_file(f), cmd, arg);
return error;
}
#ifdef CONFIG_COMPAT
/**
* compat_ptr_ioctl - generic implementation of .compat_ioctl file operation
* @file: The file to operate on.
* @cmd: The ioctl command number.
* @arg: The argument to the ioctl.
*
* This is not normally called as a function, but instead set in struct
* file_operations as
*
* .compat_ioctl = compat_ptr_ioctl,
*
* On most architectures, the compat_ptr_ioctl() just passes all arguments
* to the corresponding ->ioctl handler. The exception is arch/s390, where
* compat_ptr() clears the top bit of a 32-bit pointer value, so user space
* pointers to the second 2GB alias the first 2GB, as is the case for
* native 32-bit s390 user space.
*
* The compat_ptr_ioctl() function must therefore be used only with ioctl
* functions that either ignore the argument or pass a pointer to a
* compatible data type.
*
* If any ioctl command handled by fops->unlocked_ioctl passes a plain
* integer instead of a pointer, or any of the passed data types
* is incompatible between 32-bit and 64-bit architectures, a proper
* handler is required instead of compat_ptr_ioctl.
*/
long compat_ptr_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
if (!file->f_op->unlocked_ioctl)
return -ENOIOCTLCMD;
return file->f_op->unlocked_ioctl(file, cmd, (unsigned long)compat_ptr(arg));
}
EXPORT_SYMBOL(compat_ptr_ioctl);
COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
compat_ulong_t, arg)
{
CLASS(fd, f)(fd);
int error;
if (fd_empty(f))
return -EBADF;
error = security_file_ioctl_compat(fd_file(f), cmd, arg);
if (error)
return error;
switch (cmd) {
/* FICLONE takes an int argument, so don't use compat_ptr() */
case FICLONE:
error = ioctl_file_clone(fd_file(f), arg, 0, 0, 0);
break;
#if defined(CONFIG_X86_64)
/* these get messy on amd64 due to alignment differences */
case FS_IOC_RESVSP_32:
case FS_IOC_RESVSP64_32:
error = compat_ioctl_preallocate(fd_file(f), 0, compat_ptr(arg));
break;
case FS_IOC_UNRESVSP_32:
case FS_IOC_UNRESVSP64_32:
error = compat_ioctl_preallocate(fd_file(f), FALLOC_FL_PUNCH_HOLE,
compat_ptr(arg));
break;
case FS_IOC_ZERO_RANGE_32:
error = compat_ioctl_preallocate(fd_file(f), FALLOC_FL_ZERO_RANGE,
compat_ptr(arg));
break;
#endif
Annotation
- Immediate include surface: `linux/syscalls.h`, `linux/mm.h`, `linux/capability.h`, `linux/compat.h`, `linux/file.h`, `linux/fs.h`, `linux/security.h`, `linux/export.h`.
- Detected declarations: `syscall ioctl`, `function vfs_ioctl`, `function ioctl_fibmap`, `function fiemap_fill_next_extent`, `function fiemap_prep`, `function ioctl_fiemap`, `function ioctl_file_clone`, `function ioctl_file_clone_range`, `function ioctl_preallocate`, `function compat_ioctl_preallocate`.
- 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.