fs/namei.c
Source file repositories/reference/linux-study-clean/fs/namei.c
File Facts
- System
- Linux kernel
- Corpus path
fs/namei.c- Extension
.c- Size
- 179289 bytes
- Lines
- 6444
- 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/init.hlinux/export.hlinux/slab.hlinux/wordpart.hlinux/fs.hlinux/filelock.hlinux/namei.hlinux/pagemap.hlinux/sched/mm.hlinux/fsnotify.hlinux/personality.hlinux/security.hlinux/syscalls.hlinux/mount.hlinux/audit.hlinux/capability.hlinux/file.hlinux/fcntl.hlinux/device_cgroup.hlinux/fs_struct.hlinux/posix_acl.hlinux/hash.hlinux/bitops.hlinux/init_task.hlinux/uaccess.hasm/runtime-const.hinternal.hmount.hasm/word-at-a-time.h
Detected Declarations
syscall mknodatsyscall mknodsyscall mkdiratsyscall mkdirsyscall rmdirsyscall unlinkatsyscall unlinksyscall symlinkatsyscall symlinksyscall linkatsyscall linksyscall renameat2syscall renameatsyscall renamestruct nameidatastruct savedenum last_typefunction filename_initfunction free_filenamefunction initnamefunction getname_longfunction do_getnamefunction getname_flagsfunction putnamefunction __delayed_getnamefunction delayed_getnamefunction delayed_getname_uflagsfunction putname_to_delayedfunction dismiss_delayed_filenamefunction check_aclfunction is_uncached_aclfunction acl_permission_checkfunction satisfiedfunction do_inode_permissionfunction sb_permissionfunction inode_permissionfunction may_lookupfunction path_getfunction path_putfunction __set_nameidatafunction set_nameidatafunction restore_nameidatafunction nd_alloc_stackfunction path_connectedfunction drop_linksfunction leave_rcufunction terminate_walkfunction __legitimize_path
Annotated Snippet
SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
unsigned int, dev)
{
CLASS(filename, name)(filename);
return filename_mknodat(dfd, name, mode, dev);
}
SYSCALL_DEFINE3(mknod, const char __user *, filename, umode_t, mode, unsigned, dev)
{
CLASS(filename, name)(filename);
return filename_mknodat(AT_FDCWD, name, mode, dev);
}
/**
* vfs_mkdir - create directory returning correct dentry if possible
* @idmap: idmap of the mount the inode was found from
* @dir: inode of the parent directory
* @dentry: dentry of the child directory
* @mode: mode of the child directory
* @delegated_inode: returns parent inode, if the inode is delegated.
*
* Create a directory.
*
* If the inode has been found through an idmapped mount the idmap of
* the vfsmount must be passed through @idmap. This function will then take
* care to map the inode according to @idmap before checking permissions.
* On non-idmapped mounts or if permission checking is to be performed on the
* raw inode simply pass @nop_mnt_idmap.
*
* In the event that the filesystem does not use the *@dentry but leaves it
* negative or unhashes it and possibly splices a different one returning it,
* the original dentry is dput() and the alternate is returned.
*
* In case of an error the dentry is dput() and an ERR_PTR() is returned.
*/
struct dentry *vfs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
struct dentry *dentry, umode_t mode,
struct delegated_inode *delegated_inode)
{
int error;
unsigned max_links = dir->i_sb->s_max_links;
struct dentry *de;
error = may_create_dentry(idmap, dir, dentry);
if (error)
goto err;
error = -EPERM;
if (!dir->i_op->mkdir)
goto err;
mode = vfs_prepare_mode(idmap, dir, mode, S_IRWXUGO | S_ISVTX, 0);
error = security_inode_mkdir(dir, dentry, mode);
if (error)
goto err;
error = -EMLINK;
if (max_links && dir->i_nlink >= max_links)
goto err;
error = try_break_deleg(dir, LEASE_BREAK_DIR_CREATE, delegated_inode);
if (error)
goto err;
de = dir->i_op->mkdir(idmap, dir, dentry, mode);
error = PTR_ERR(de);
if (IS_ERR(de))
goto err;
if (de) {
dput(dentry);
dentry = de;
}
fsnotify_mkdir(dir, dentry);
return dentry;
err:
end_creating(dentry);
return ERR_PTR(error);
}
EXPORT_SYMBOL(vfs_mkdir);
int filename_mkdirat(int dfd, struct filename *name, umode_t mode)
{
struct dentry *dentry;
struct path path;
int error;
unsigned int lookup_flags = LOOKUP_DIRECTORY;
struct delegated_inode delegated_inode = { };
retry:
Annotation
- Immediate include surface: `linux/init.h`, `linux/export.h`, `linux/slab.h`, `linux/wordpart.h`, `linux/fs.h`, `linux/filelock.h`, `linux/namei.h`, `linux/pagemap.h`.
- Detected declarations: `syscall mknodat`, `syscall mknod`, `syscall mkdirat`, `syscall mkdir`, `syscall rmdir`, `syscall unlinkat`, `syscall unlink`, `syscall symlinkat`, `syscall symlink`, `syscall linkat`.
- 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.