fs/fhandle.c
Source file repositories/reference/linux-study-clean/fs/fhandle.c
File Facts
- System
- Linux kernel
- Corpus path
fs/fhandle.c- Extension
.c- Size
- 13478 bytes
- Lines
- 475
- 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.
- 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/slab.hlinux/fs.hlinux/file.hlinux/mount.hlinux/namei.hlinux/exportfs.hlinux/fs_struct.hlinux/fsnotify.hlinux/personality.hlinux/uaccess.hlinux/compat.hlinux/nsfs.hinternal.hmount.h
Detected Declarations
syscall name_to_handle_atsyscall open_by_handle_atfunction do_sys_name_to_handlefunction get_path_anchorfunction vfs_dentry_acceptablefunction do_handle_to_pathfunction capable_wrt_mountfunction may_decode_fhfunction handle_to_pathfunction do_handle_openfunction open
Annotated Snippet
SYSCALL_DEFINE5(name_to_handle_at, int, dfd, const char __user *, name,
struct file_handle __user *, handle, void __user *, mnt_id,
int, flag)
{
struct path path;
int lookup_flags;
int fh_flags = 0;
int err;
if (flag & ~(AT_SYMLINK_FOLLOW | AT_EMPTY_PATH | AT_HANDLE_FID |
AT_HANDLE_MNT_ID_UNIQUE | AT_HANDLE_CONNECTABLE))
return -EINVAL;
/*
* AT_HANDLE_FID means there is no intention to decode file handle
* AT_HANDLE_CONNECTABLE means there is an intention to decode a
* connected fd (with known path), so these flags are conflicting.
* AT_EMPTY_PATH could be used along with a dfd that refers to a
* disconnected non-directory, which cannot be used to encode a
* connectable file handle, because its parent is unknown.
*/
if (flag & AT_HANDLE_CONNECTABLE &&
flag & (AT_HANDLE_FID | AT_EMPTY_PATH))
return -EINVAL;
else if (flag & AT_HANDLE_FID)
fh_flags |= EXPORT_FH_FID;
else if (flag & AT_HANDLE_CONNECTABLE)
fh_flags |= EXPORT_FH_CONNECTABLE;
lookup_flags = (flag & AT_SYMLINK_FOLLOW) ? LOOKUP_FOLLOW : 0;
CLASS(filename_uflags, filename)(name, flag);
err = filename_lookup(dfd, filename, lookup_flags, &path, NULL);
if (!err) {
err = do_sys_name_to_handle(&path, handle, mnt_id,
flag & AT_HANDLE_MNT_ID_UNIQUE,
fh_flags);
path_put(&path);
}
return err;
}
static int get_path_anchor(int fd, struct path *root)
{
if (fd >= 0) {
CLASS(fd, f)(fd);
if (fd_empty(f))
return -EBADF;
*root = fd_file(f)->f_path;
path_get(root);
return 0;
}
if (fd == AT_FDCWD) {
get_fs_pwd(current->fs, root);
return 0;
}
if (fd == FD_PIDFS_ROOT) {
pidfs_get_root(root);
return 0;
}
if (fd == FD_NSFS_ROOT) {
nsfs_get_root(root);
return 0;
}
return -EBADF;
}
static int vfs_dentry_acceptable(void *context, struct dentry *dentry)
{
struct handle_to_path_ctx *ctx = context;
struct user_namespace *user_ns = current_user_ns();
struct dentry *d, *root = ctx->root.dentry;
struct mnt_idmap *idmap = mnt_idmap(ctx->root.mnt);
int retval = 0;
if (!root)
return 1;
/* Old permission model with global CAP_DAC_READ_SEARCH. */
if (!ctx->flags)
return 1;
/*
* Verify that the decoded dentry itself has a valid id mapping.
* In case the decoded dentry is the mountfd root itself, this
* verifies that the mountfd inode itself has a valid id mapping.
*/
Annotation
- Immediate include surface: `linux/syscalls.h`, `linux/slab.h`, `linux/fs.h`, `linux/file.h`, `linux/mount.h`, `linux/namei.h`, `linux/exportfs.h`, `linux/fs_struct.h`.
- Detected declarations: `syscall name_to_handle_at`, `syscall open_by_handle_at`, `function do_sys_name_to_handle`, `function get_path_anchor`, `function vfs_dentry_acceptable`, `function do_handle_to_path`, `function capable_wrt_mount`, `function may_decode_fh`, `function handle_to_path`, `function do_handle_open`.
- 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.
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.