fs/erofs/xattr.c
Source file repositories/reference/linux-study-clean/fs/erofs/xattr.c
File Facts
- System
- Linux kernel
- Corpus path
fs/erofs/xattr.c- Extension
.c- Size
- 17665 bytes
- Lines
- 650
- 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.
- 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/security.hlinux/xxhash.hxattr.h
Detected Declarations
struct erofs_xattr_iterfunction erofs_init_inode_xattrsfunction nowfunction erofs_xattr_copy_to_bufferfunction erofs_listxattr_foreachfunction erofs_getxattr_foreachfunction erofs_xattr_iter_inlinefunction erofs_xattr_iter_sharedfunction erofs_getxattrfunction erofs_listxattrfunction erofs_xattr_user_listfunction erofs_xattr_trusted_listfunction erofs_xattr_generic_getfunction erofs_xattr_prefixes_cleanupfunction erofs_xattr_prefixes_initfunction erofs_inode_has_noaclfunction erofs_xattr_fill_inode_fingerprint
Annotated Snippet
struct erofs_xattr_iter {
struct super_block *sb;
struct erofs_buf buf;
erofs_off_t pos;
void *kaddr;
char *buffer;
int buffer_size, buffer_ofs;
/* getxattr */
int index, infix_len;
struct qstr name;
/* listxattr */
struct dentry *dentry;
};
static const char *erofs_xattr_prefix(unsigned int idx, struct dentry *dentry);
static int erofs_init_inode_xattrs(struct inode *inode)
{
struct erofs_buf buf = __EROFS_BUF_INITIALIZER;
struct erofs_inode *vi = EROFS_I(inode);
struct super_block *sb = inode->i_sb;
const struct erofs_xattr_ibody_header *ih;
__le32 *xattr_id;
erofs_off_t pos;
unsigned int i;
int ret = 0;
if (!vi->xattr_isize)
return -ENODATA;
/* the most case is that xattrs of this inode are initialized. */
if (test_bit(EROFS_I_EA_INITED_BIT, &vi->flags)) {
/*
* paired with smp_mb() at the end of the function to ensure
* fields will only be observed after the bit is set.
*/
smp_mb();
return 0;
}
if (wait_on_bit_lock(&vi->flags, EROFS_I_BL_XATTR_BIT, TASK_KILLABLE))
return -ERESTARTSYS;
/* someone has initialized xattrs for us? */
if (test_bit(EROFS_I_EA_INITED_BIT, &vi->flags))
goto out_unlock;
/*
* bypass all xattr operations if ->xattr_isize is not greater than
* sizeof(struct erofs_xattr_ibody_header), in detail:
* 1) it is not enough to contain erofs_xattr_ibody_header then
* ->xattr_isize should be 0 (it means no xattr);
* 2) it is just to contain erofs_xattr_ibody_header, which is on-disk
* undefined right now (maybe use later with some new sb feature).
*/
if (vi->xattr_isize == sizeof(struct erofs_xattr_ibody_header)) {
erofs_err(sb, "xattr_isize %d of nid %llu is not supported yet",
vi->xattr_isize, vi->nid);
ret = -EOPNOTSUPP;
goto out_unlock;
} else if (vi->xattr_isize < sizeof(struct erofs_xattr_ibody_header)) {
erofs_err(sb, "bogus xattr ibody @ nid %llu", vi->nid);
DBG_BUGON(1);
ret = -EFSCORRUPTED;
goto out_unlock;
}
pos = erofs_iloc(inode) + vi->inode_isize;
ih = erofs_read_metabuf(&buf, sb, pos, erofs_inode_in_metabox(inode));
if (IS_ERR(ih)) {
ret = PTR_ERR(ih);
goto out_unlock;
}
vi->xattr_name_filter = le32_to_cpu(ih->h_name_filter);
vi->xattr_shared_count = ih->h_shared_count;
if ((u32)vi->xattr_shared_count * sizeof(__le32) >
vi->xattr_isize - sizeof(struct erofs_xattr_ibody_header)) {
erofs_err(sb, "invalid h_shared_count %u @ nid %llu",
vi->xattr_shared_count, vi->nid);
ret = -EFSCORRUPTED;
goto out_unlock;
}
vi->xattr_shared_xattrs = kmalloc_objs(uint, vi->xattr_shared_count);
if (!vi->xattr_shared_xattrs) {
ret = -ENOMEM;
goto out_unlock;
}
Annotation
- Immediate include surface: `linux/security.h`, `linux/xxhash.h`, `xattr.h`.
- Detected declarations: `struct erofs_xattr_iter`, `function erofs_init_inode_xattrs`, `function now`, `function erofs_xattr_copy_to_buffer`, `function erofs_listxattr_foreach`, `function erofs_getxattr_foreach`, `function erofs_xattr_iter_inline`, `function erofs_xattr_iter_shared`, `function erofs_getxattr`, `function erofs_listxattr`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
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.