fs/overlayfs/inode.c
Source file repositories/reference/linux-study-clean/fs/overlayfs/inode.c
File Facts
- System
- Linux kernel
- Corpus path
fs/overlayfs/inode.c- Extension
.c- Size
- 36271 bytes
- Lines
- 1299
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/fs.hlinux/slab.hlinux/cred.hlinux/xattr.hlinux/ratelimit.hlinux/fiemap.hlinux/fileattr.hlinux/security.hlinux/namei.hlinux/posix_acl.hlinux/posix_acl_xattr.hoverlayfs.h
Detected Declarations
function Copyrightfunction ovl_map_dev_inofunction ovl_real_getattr_nosecfunction ovl_getattrfunction vfs_getattrfunction ovl_permissionfunction ovl_idmap_posix_aclfunction ovl_set_or_remove_aclfunction with_ovl_credsfunction ovl_set_aclfunction clearedfunction ovl_update_timefunction ovl_fiemapfunction security_file_ioctlfunction ovl_real_fileattr_setfunction ovl_fileattr_setfunction with_ovl_credsfunction ovl_fileattr_prot_flagsfunction ovl_real_fileattr_getfunction ovl_fileattr_getfunction ovl_lockdep_annotate_inode_mutex_keyfunction ovl_next_inofunction ovl_map_inofunction ovl_map_dev_inofunction ovl_inode_initfunction ovl_fill_inodefunction ovl_set_nlink_commonfunction ovl_set_nlink_upperfunction ovl_set_nlink_lowerfunction ovl_get_nlinkfunction ovl_inode_testfunction ovl_inode_setfunction ovl_verify_inodefunction ovl_lookup_trap_inodefunction ovl_verify_inodefunction ovl_hash_bylower
Annotated Snippet
if (attr->ia_valid & ATTR_SIZE) {
winode = d_inode(upperdentry);
err = get_write_access(winode);
if (err)
goto out;
}
if (attr->ia_valid & (ATTR_KILL_SUID|ATTR_KILL_SGID))
attr->ia_valid &= ~ATTR_MODE;
/*
* We might have to translate ovl file into real file object
* once use cases emerge. For now, simply don't let underlying
* filesystem rely on attr->ia_file
*/
attr->ia_valid &= ~ATTR_FILE;
/*
* If open(O_TRUNC) is done, VFS calls ->setattr with ATTR_OPEN
* set. Overlayfs does not pass O_TRUNC flag to underlying
* filesystem during open -> do not pass ATTR_OPEN. This
* disables optimization in fuse which assumes open(O_TRUNC)
* already set file size to 0. But we never passed O_TRUNC to
* fuse. So by clearing ATTR_OPEN, fuse will be forced to send
* setattr request to server.
*/
attr->ia_valid &= ~ATTR_OPEN;
err = ovl_want_write(dentry);
if (err)
goto out_put_write;
inode_lock(upperdentry->d_inode);
with_ovl_creds(dentry->d_sb)
err = ovl_do_notify_change(ofs, upperdentry, attr);
if (!err)
ovl_copyattr(dentry->d_inode);
inode_unlock(upperdentry->d_inode);
ovl_drop_write(dentry);
out_put_write:
if (winode)
put_write_access(winode);
}
out:
return err;
}
static void ovl_map_dev_ino(struct dentry *dentry, struct kstat *stat, int fsid)
{
struct ovl_fs *ofs = OVL_FS(dentry->d_sb);
bool samefs = ovl_same_fs(ofs);
unsigned int xinobits = ovl_xino_bits(ofs);
unsigned int xinoshift = 64 - xinobits;
if (samefs) {
/*
* When all layers are on the same fs, all real inode
* number are unique, so we use the overlay st_dev,
* which is friendly to du -x.
*/
stat->dev = dentry->d_sb->s_dev;
return;
} else if (xinobits) {
/*
* All inode numbers of underlying fs should not be using the
* high xinobits, so we use high xinobits to partition the
* overlay st_ino address space. The high bits holds the fsid
* (upper fsid is 0). The lowest xinobit is reserved for mapping
* the non-persistent inode numbers range in case of overflow.
* This way all overlay inode numbers are unique and use the
* overlay st_dev.
*/
if (likely(!(stat->ino >> xinoshift))) {
stat->ino |= ((u64)fsid) << (xinoshift + 1);
stat->dev = dentry->d_sb->s_dev;
return;
} else if (ovl_xino_warn(ofs)) {
pr_warn_ratelimited("inode number too big (%pd2, ino=%llu, xinobits=%d)\n",
dentry, stat->ino, xinobits);
}
}
/* The inode could not be mapped to a unified st_ino address space */
if (S_ISDIR(dentry->d_inode->i_mode)) {
/*
* Always use the overlay st_dev for directories, so 'find
* -xdev' will scan the entire overlay mount and won't cross the
* overlay mount boundaries.
*
Annotation
- Immediate include surface: `linux/fs.h`, `linux/slab.h`, `linux/cred.h`, `linux/xattr.h`, `linux/ratelimit.h`, `linux/fiemap.h`, `linux/fileattr.h`, `linux/security.h`.
- Detected declarations: `function Copyright`, `function ovl_map_dev_ino`, `function ovl_real_getattr_nosec`, `function ovl_getattr`, `function vfs_getattr`, `function ovl_permission`, `function ovl_idmap_posix_acl`, `function ovl_set_or_remove_acl`, `function with_ovl_creds`, `function ovl_set_acl`.
- 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.