fs/notify/inotify/inotify_user.c
Source file repositories/reference/linux-study-clean/fs/notify/inotify/inotify_user.c
File Facts
- System
- Linux kernel
- Corpus path
fs/notify/inotify/inotify_user.c- Extension
.c- Size
- 22152 bytes
- Lines
- 862
- 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/file.hlinux/fs.hlinux/fsnotify_backend.hlinux/idr.hlinux/init.hlinux/inotify.hlinux/kernel.hlinux/namei.hlinux/sched/signal.hlinux/slab.hlinux/syscalls.hlinux/types.hlinux/anon_inodes.hlinux/uaccess.hlinux/poll.hlinux/wait.hlinux/memcontrol.hlinux/security.hinotify.h../fdinfo.hasm/ioctls.hlinux/sysctl.h
Detected Declarations
syscall inotify_init1syscall inotify_initsyscall inotify_add_watchsyscall inotify_rm_watchfunction inotify_sysctls_initfunction inotify_arg_to_maskfunction inotify_arg_to_flagsfunction inotify_mask_to_argfunction inotify_pollfunction round_event_name_lenfunction copy_event_to_userfunction inotify_readfunction inotify_releasefunction inotify_ioctlfunction list_for_each_entryfunction inotify_find_inodefunction inotify_add_to_idrfunction idrfunction inotify_ignored_and_remove_idrfunction inotify_update_existing_watchfunction inotify_new_watchfunction inotify_update_watchfunction do_inotify_initfunction panicmodule init inotify_user_setup
Annotated Snippet
SYSCALL_DEFINE1(inotify_init1, int, flags)
{
return do_inotify_init(flags);
}
SYSCALL_DEFINE0(inotify_init)
{
return do_inotify_init(0);
}
SYSCALL_DEFINE3(inotify_add_watch, int, fd, const char __user *, pathname,
u32, mask)
{
struct fsnotify_group *group;
struct inode *inode;
struct path path;
int ret;
unsigned flags = 0;
/*
* We share a lot of code with fs/dnotify. We also share
* the bit layout between inotify's IN_* and the fsnotify
* FS_*. This check ensures that only the inotify IN_*
* bits get passed in and set in watches/events.
*/
if (unlikely(mask & ~ALL_INOTIFY_BITS))
return -EINVAL;
/*
* Require at least one valid bit set in the mask.
* Without _something_ set, we would have no events to
* watch for.
*/
if (unlikely(!(mask & ALL_INOTIFY_BITS)))
return -EINVAL;
CLASS(fd, f)(fd);
if (fd_empty(f))
return -EBADF;
/* IN_MASK_ADD and IN_MASK_CREATE don't make sense together */
if (unlikely((mask & IN_MASK_ADD) && (mask & IN_MASK_CREATE)))
return -EINVAL;
/* verify that this is indeed an inotify instance */
if (unlikely(fd_file(f)->f_op != &inotify_fops))
return -EINVAL;
if (!(mask & IN_DONT_FOLLOW))
flags |= LOOKUP_FOLLOW;
if (mask & IN_ONLYDIR)
flags |= LOOKUP_DIRECTORY;
ret = inotify_find_inode(pathname, &path, flags,
(mask & IN_ALL_EVENTS));
if (ret)
return ret;
/* inode held in place by reference to path; group by fget on fd */
inode = path.dentry->d_inode;
group = fd_file(f)->private_data;
/* create/update an inode mark */
ret = inotify_update_watch(group, inode, mask);
path_put(&path);
return ret;
}
SYSCALL_DEFINE2(inotify_rm_watch, int, fd, __s32, wd)
{
struct fsnotify_group *group;
struct inotify_inode_mark *i_mark;
CLASS(fd, f)(fd);
if (fd_empty(f))
return -EBADF;
/* verify that this is indeed an inotify instance */
if (unlikely(fd_file(f)->f_op != &inotify_fops))
return -EINVAL;
group = fd_file(f)->private_data;
i_mark = inotify_idr_find(group, wd);
if (unlikely(!i_mark))
return -EINVAL;
fsnotify_destroy_mark(&i_mark->fsn_mark, group);
/* match ref taken by inotify_idr_find */
fsnotify_put_mark(&i_mark->fsn_mark);
Annotation
- Immediate include surface: `linux/file.h`, `linux/fs.h`, `linux/fsnotify_backend.h`, `linux/idr.h`, `linux/init.h`, `linux/inotify.h`, `linux/kernel.h`, `linux/namei.h`.
- Detected declarations: `syscall inotify_init1`, `syscall inotify_init`, `syscall inotify_add_watch`, `syscall inotify_rm_watch`, `function inotify_sysctls_init`, `function inotify_arg_to_mask`, `function inotify_arg_to_flags`, `function inotify_mask_to_arg`, `function inotify_poll`, `function round_event_name_len`.
- 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.