fs/exportfs/expfs.c
Source file repositories/reference/linux-study-clean/fs/exportfs/expfs.c
File Facts
- System
- Linux kernel
- Corpus path
fs/exportfs/expfs.c- Extension
.c- Size
- 15847 bytes
- Lines
- 611
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/exportfs.hlinux/fs.hlinux/file.hlinux/module.hlinux/mount.hlinux/namei.hlinux/sched.hlinux/cred.h
Detected Declarations
struct getdents_callbackfunction exportfs_get_namefunction find_acceptable_aliasfunction dentry_connectedfunction clear_disconnectedfunction necessaryfunction filldir_onefunction get_namefunction exportfs_encode_ino64_fidfunction exportfs_encode_inode_fhfunction exportfs_encode_fhfunction exportfs_decode_fh_rawfunction intexport exportfs_encode_inode_fhexport exportfs_encode_fhexport exportfs_decode_fh_rawexport exportfs_decode_fh
Annotated Snippet
struct getdents_callback {
struct dir_context ctx;
char *name; /* name that was found. It already points to a
buffer NAME_MAX+1 is size */
u64 ino; /* the inum we are looking for */
int found; /* inode matched? */
int sequence; /* sequence counter */
};
/*
* A rather strange filldir function to capture
* the name matching the specified inode number.
*/
static bool filldir_one(struct dir_context *ctx, const char *name, int len,
loff_t pos, u64 ino, unsigned int d_type)
{
struct getdents_callback *buf =
container_of(ctx, struct getdents_callback, ctx);
buf->sequence++;
if (buf->ino == ino && len <= NAME_MAX &&
!name_is_dot_dotdot(name, len)) {
memcpy(buf->name, name, len);
buf->name[len] = '\0';
buf->found = 1;
return false; // no more
}
return true;
}
/**
* get_name - default export_operations->get_name function
* @path: the directory in which to find a name
* @name: a pointer to a %NAME_MAX+1 char buffer to store the name
* @child: the dentry for the child directory.
*
* calls readdir on the parent until it finds an entry with
* the same inode number as the child, and returns that.
*/
static int get_name(const struct path *path, char *name, struct dentry *child)
{
const struct cred *cred = current_cred();
struct inode *dir = path->dentry->d_inode;
int error;
struct file *file;
struct kstat stat;
struct path child_path = {
.mnt = path->mnt,
.dentry = child,
};
struct getdents_callback buffer = {
.ctx.actor = filldir_one,
.ctx.count = INT_MAX,
.name = name,
};
error = -ENOTDIR;
if (!dir || !S_ISDIR(dir->i_mode))
goto out;
error = -EINVAL;
if (!dir->i_fop)
goto out;
/*
* inode->i_ino is unsigned long, kstat->ino is u64, so the
* former would be insufficient on 32-bit hosts when the
* filesystem supports 64-bit inode numbers. So we need to
* actually call ->getattr, not just read i_ino:
*/
error = vfs_getattr_nosec(&child_path, &stat,
STATX_INO, AT_STATX_SYNC_AS_STAT);
if (error)
return error;
buffer.ino = stat.ino;
/*
* Open the directory ...
*/
file = dentry_open(path, O_RDONLY, cred);
error = PTR_ERR(file);
if (IS_ERR(file))
goto out;
error = -EINVAL;
if (!file->f_op->iterate_shared)
goto out_close;
buffer.sequence = 0;
while (1) {
int old_seq = buffer.sequence;
error = iterate_dir(file, &buffer.ctx);
Annotation
- Immediate include surface: `linux/exportfs.h`, `linux/fs.h`, `linux/file.h`, `linux/module.h`, `linux/mount.h`, `linux/namei.h`, `linux/sched.h`, `linux/cred.h`.
- Detected declarations: `struct getdents_callback`, `function exportfs_get_name`, `function find_acceptable_alias`, `function dentry_connected`, `function clear_disconnected`, `function necessary`, `function filldir_one`, `function get_name`, `function exportfs_encode_ino64_fid`, `function exportfs_encode_inode_fh`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: integration implementation candidate.
- 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.