fs/overlayfs/namei.c
Source file repositories/reference/linux-study-clean/fs/overlayfs/namei.c
File Facts
- System
- Linux kernel
- Corpus path
fs/overlayfs/namei.c- Extension
.c- Size
- 36799 bytes
- Lines
- 1484
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: implementation source
- Status
- source 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.
- 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/fs.hlinux/cred.hlinux/ctype.hlinux/hex.hlinux/namei.hlinux/xattr.hlinux/ratelimit.hlinux/mount.hlinux/exportfs.hoverlayfs.h
Detected Declarations
struct ovl_lookup_datastruct ovl_lookup_ctxfunction ovl_check_redirectfunction ovl_acceptablefunction ovl_check_fb_lenfunction ovl_uuid_matchfunction ovl_lookup_singlefunction ovl_lookup_layerfunction ovl_lookup_data_layerfunction ovl_lookup_data_layersfunction ovl_check_origin_fhfunction ovl_check_originfunction ovl_verify_fhfunction ovl_verify_set_fhfunction ovl_verify_origin_xattrfunction ovl_verify_indexfunction ovl_get_index_name_fhfunction ovl_get_index_namefunction inode_wrong_typefunction ovl_path_nextfunction ovl_fix_originfunction ovl_maybe_validate_verityfunction ovl_maybe_lookup_lowerdatafunction ovl_verify_lowerdatafunction untrustedfunction ovl_lookup_layersfunction ovl_lower_positivefunction with_ovl_creds
Annotated Snippet
struct ovl_lookup_data {
struct super_block *sb;
struct dentry *dentry;
const struct ovl_layer *layer;
struct qstr name;
bool is_dir;
bool opaque;
bool xwhiteouts;
bool stop;
bool last;
char *redirect;
char *upperredirect;
int metacopy;
/* Referring to last redirect xattr */
bool absolute_redirect;
};
static int ovl_check_redirect(const struct path *path, struct ovl_lookup_data *d,
size_t prelen, const char *post)
{
int res;
char *buf;
struct ovl_fs *ofs = OVL_FS(d->sb);
d->absolute_redirect = false;
buf = ovl_get_redirect_xattr(ofs, path, prelen + strlen(post));
if (IS_ERR_OR_NULL(buf))
return PTR_ERR(buf);
if (buf[0] == '/') {
d->absolute_redirect = true;
/*
* One of the ancestor path elements in an absolute path
* lookup in ovl_lookup_layer() could have been opaque and
* that will stop further lookup in lower layers (d->stop=true)
* But we have found an absolute redirect in descendant path
* element and that should force continue lookup in lower
* layers (reset d->stop).
*/
d->stop = false;
} else {
res = strlen(buf) + 1;
memmove(buf + prelen, buf, res);
memcpy(buf, d->name.name, prelen);
}
strcat(buf, post);
kfree(d->redirect);
d->redirect = buf;
d->name.name = d->redirect;
d->name.len = strlen(d->redirect);
return 0;
}
static int ovl_acceptable(void *ctx, struct dentry *dentry)
{
/*
* A non-dir origin may be disconnected, which is fine, because
* we only need it for its unique inode number.
*/
if (!d_is_dir(dentry))
return 1;
/* Don't decode a deleted empty directory */
if (d_unhashed(dentry))
return 0;
/* Check if directory belongs to the layer we are decoding from */
return is_subdir(dentry, ((struct vfsmount *)ctx)->mnt_root);
}
/*
* Check validity of an overlay file handle buffer.
*
* Return 0 for a valid file handle.
* Return -ENODATA for "origin unknown".
* Return <0 for an invalid file handle.
*/
int ovl_check_fb_len(struct ovl_fb *fb, int fb_len)
{
if (fb_len < sizeof(struct ovl_fb) || fb_len < fb->len)
return -EINVAL;
if (fb->magic != OVL_FH_MAGIC)
return -EINVAL;
/* Treat larger version and unknown flags as "origin unknown" */
if (fb->version > OVL_FH_VERSION || fb->flags & ~OVL_FH_FLAG_ALL)
return -ENODATA;
Annotation
- Immediate include surface: `linux/fs.h`, `linux/cred.h`, `linux/ctype.h`, `linux/hex.h`, `linux/namei.h`, `linux/xattr.h`, `linux/ratelimit.h`, `linux/mount.h`.
- Detected declarations: `struct ovl_lookup_data`, `struct ovl_lookup_ctx`, `function ovl_check_redirect`, `function ovl_acceptable`, `function ovl_check_fb_len`, `function ovl_uuid_match`, `function ovl_lookup_single`, `function ovl_lookup_layer`, `function ovl_lookup_data_layer`, `function ovl_lookup_data_layers`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source 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.