fs/fcntl.c
Source file repositories/reference/linux-study-clean/fs/fcntl.c
File Facts
- System
- Linux kernel
- Corpus path
fs/fcntl.c- Extension
.c- Size
- 27090 bytes
- Lines
- 1184
- 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.
- 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/syscalls.hlinux/init.hlinux/mm.hlinux/sched/task.hlinux/fs.hlinux/filelock.hlinux/file.hlinux/capability.hlinux/dnotify.hlinux/slab.hlinux/module.hlinux/pipe_fs_i.hlinux/security.hlinux/ptrace.hlinux/signal.hlinux/rcupdate.hlinux/pid_namespace.hlinux/user_namespace.hlinux/memfd.hlinux/compat.hlinux/mount.hlinux/rw_hint.hlinux/poll.hasm/siginfo.hlinux/uaccess.hinternal.h
Detected Declarations
syscall fcntlsyscall fcntl64function Copyrightfunction file_f_owner_allocatefunction file_f_owner_releasefunction __f_setownfunction f_setownfunction f_delownfunction f_getownfunction f_setown_exfunction f_getown_exfunction f_getowner_uidsfunction f_getowner_uidsfunction rw_hint_validfunction fcntl_get_rw_hintfunction fcntl_set_rw_hintfunction f_dupfd_queryfunction f_created_queryfunction f_owner_sigfunction do_fcntlfunction check_fcntl_cmdfunction get_compat_flockfunction get_compat_flock64function put_compat_flockfunction put_compat_flock64function convert_fcntl_cmdfunction fixup_compat_flockfunction do_compat_fcntl64function sigio_permfunction send_sigio_to_taskfunction send_sigiofunction do_each_pid_taskfunction send_sigurg_to_taskfunction send_sigurgfunction do_each_pid_taskfunction fasync_remove_entryfunction fasync_freefunction fasync_add_entryfunction fasync_insert_entryfunction fasync_helperfunction rcu_read_lockfunction kill_fasyncfunction fcntl_initmodule init fcntl_initexport file_f_owner_allocateexport __f_setownexport f_setownexport fasync_helper
Annotated Snippet
SYSCALL_DEFINE3(fcntl, unsigned int, fd, unsigned int, cmd, unsigned long, arg)
{
CLASS(fd_raw, f)(fd);
long err;
if (fd_empty(f))
return -EBADF;
if (unlikely(fd_file(f)->f_mode & FMODE_PATH)) {
if (!check_fcntl_cmd(cmd))
return -EBADF;
}
err = security_file_fcntl(fd_file(f), cmd, arg);
if (!err)
err = do_fcntl(fd, cmd, arg, fd_file(f));
return err;
}
#if BITS_PER_LONG == 32
SYSCALL_DEFINE3(fcntl64, unsigned int, fd, unsigned int, cmd,
unsigned long, arg)
{
void __user *argp = (void __user *)arg;
CLASS(fd_raw, f)(fd);
struct flock64 flock;
long err;
if (fd_empty(f))
return -EBADF;
if (unlikely(fd_file(f)->f_mode & FMODE_PATH)) {
if (!check_fcntl_cmd(cmd))
return -EBADF;
}
err = security_file_fcntl(fd_file(f), cmd, arg);
if (err)
return err;
switch (cmd) {
case F_GETLK64:
case F_OFD_GETLK:
err = -EFAULT;
if (copy_from_user(&flock, argp, sizeof(flock)))
break;
err = fcntl_getlk64(fd_file(f), cmd, &flock);
if (!err && copy_to_user(argp, &flock, sizeof(flock)))
err = -EFAULT;
break;
case F_SETLK64:
case F_SETLKW64:
case F_OFD_SETLK:
case F_OFD_SETLKW:
err = -EFAULT;
if (copy_from_user(&flock, argp, sizeof(flock)))
break;
err = fcntl_setlk64(fd, fd_file(f), cmd, &flock);
break;
default:
err = do_fcntl(fd, cmd, arg, fd_file(f));
break;
}
return err;
}
#endif
#ifdef CONFIG_COMPAT
/* careful - don't use anywhere else */
#define copy_flock_fields(dst, src) \
(dst)->l_type = (src)->l_type; \
(dst)->l_whence = (src)->l_whence; \
(dst)->l_start = (src)->l_start; \
(dst)->l_len = (src)->l_len; \
(dst)->l_pid = (src)->l_pid;
static int get_compat_flock(struct flock *kfl, const struct compat_flock __user *ufl)
{
struct compat_flock fl;
if (copy_from_user(&fl, ufl, sizeof(struct compat_flock)))
return -EFAULT;
copy_flock_fields(kfl, &fl);
return 0;
}
static int get_compat_flock64(struct flock *kfl, const struct compat_flock64 __user *ufl)
{
struct compat_flock64 fl;
Annotation
- Immediate include surface: `linux/syscalls.h`, `linux/init.h`, `linux/mm.h`, `linux/sched/task.h`, `linux/fs.h`, `linux/filelock.h`, `linux/file.h`, `linux/capability.h`.
- Detected declarations: `syscall fcntl`, `syscall fcntl64`, `function Copyright`, `function file_f_owner_allocate`, `function file_f_owner_release`, `function __f_setown`, `function f_setown`, `function f_delown`, `function f_getown`, `function f_setown_ex`.
- 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.