fs/ext4/xattr.c
Source file repositories/reference/linux-study-clean/fs/ext4/xattr.c
File Facts
- System
- Linux kernel
- Corpus path
fs/ext4/xattr.c- Extension
.c- Size
- 86167 bytes
- Lines
- 3231
- 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/init.hlinux/fs.hlinux/slab.hlinux/mbcache.hlinux/quotaops.hlinux/iversion.hext4_jbd2.hext4.hxattr.hacl.h
Detected Declarations
struct ext4_xattr_block_findfunction ext4_xattr_inode_set_classfunction ext4_xattr_block_csumfunction ext4_xattr_block_csum_verifyfunction ext4_xattr_block_csum_setfunction check_xattrsfunction __ext4_xattr_check_blockfunction __xattr_check_inodefunction xattr_find_entryfunction ext4_xattr_inode_hashfunction ext4_xattr_inode_get_reffunction ext4_xattr_inode_set_reffunction ext4_xattr_inode_get_hashfunction ext4_xattr_inode_set_hashfunction ext4_xattr_inode_readfunction ext4_xattr_inode_igetfunction iget_lockedfunction EXT4_XATTR_INODE_GET_PARENTfunction ext4_evict_ea_inodefunction ext4_xattr_inode_get_hashfunction ext4_xattr_inode_verify_hashesfunction ext4_xattr_inode_getfunction ext4_xattr_block_getfunction ext4_xattr_ibody_getfunction ext4_xattr_getfunction ext4_xattr_list_entriesfunction ext4_xattr_block_listfunction ext4_xattr_ibody_listfunction listxattrfunction ext4_xattr_update_super_blockfunction ext4_get_inode_usagefunction round_up_clusterfunction ext4_xattr_inode_alloc_quotafunction ext4_xattr_inode_free_quotafunction __ext4_xattr_set_creditsfunction ext4_xattr_inode_update_reffunction ext4_xattr_inode_inc_reffunction ext4_xattr_inode_dec_reffunction ext4_xattr_inode_inc_ref_allfunction ext4_xattr_restart_fnfunction ext4_xattr_inode_dec_ref_allfunction ext4_xattr_release_blockfunction ext4_xattr_block_setfunction ext4_xattr_free_spacefunction ext4_xattr_inode_writefunction ext4_xattr_inode_cache_findfunction minfunction ext4_xattr_block_find
Annotated Snippet
struct ext4_xattr_block_find {
struct ext4_xattr_search s;
struct buffer_head *bh;
};
static int
ext4_xattr_block_find(struct inode *inode, struct ext4_xattr_info *i,
struct ext4_xattr_block_find *bs)
{
struct super_block *sb = inode->i_sb;
int error;
ea_idebug(inode, "name=%d.%s, value=%p, value_len=%ld",
i->name_index, i->name, i->value, (long)i->value_len);
if (EXT4_I(inode)->i_file_acl) {
/* The inode already has an extended attribute block. */
bs->bh = ext4_sb_bread(sb, EXT4_I(inode)->i_file_acl, REQ_PRIO);
if (IS_ERR(bs->bh)) {
error = PTR_ERR(bs->bh);
bs->bh = NULL;
return error;
}
ea_bdebug(bs->bh, "b_count=%d, refcount=%d",
atomic_read(&(bs->bh->b_count)),
le32_to_cpu(BHDR(bs->bh)->h_refcount));
error = ext4_xattr_check_block(inode, bs->bh);
if (error)
return error;
/* Find the named attribute. */
bs->s.base = BHDR(bs->bh);
bs->s.first = BFIRST(bs->bh);
bs->s.end = bs->bh->b_data + bs->bh->b_size;
bs->s.here = bs->s.first;
error = xattr_find_entry(inode, &bs->s.here, bs->s.end,
i->name_index, i->name, 1);
if (error && error != -ENODATA)
return error;
bs->s.not_found = error;
}
return 0;
}
static int
ext4_xattr_block_set(handle_t *handle, struct inode *inode,
struct ext4_xattr_info *i,
struct ext4_xattr_block_find *bs)
{
struct super_block *sb = inode->i_sb;
struct buffer_head *new_bh = NULL;
struct ext4_xattr_search s_copy = bs->s;
struct ext4_xattr_search *s = &s_copy;
struct mb_cache_entry *ce = NULL;
int error = 0;
struct mb_cache *ea_block_cache = EA_BLOCK_CACHE(inode);
struct inode *ea_inode = NULL, *tmp_inode;
size_t old_ea_inode_quota = 0;
unsigned int ea_ino;
#define header(x) ((struct ext4_xattr_header *)(x))
/* If we need EA inode, prepare it before locking the buffer */
if (i->value && i->in_inode) {
WARN_ON_ONCE(!i->value_len);
ea_inode = ext4_xattr_inode_lookup_create(handle, inode,
i->value, i->value_len);
if (IS_ERR(ea_inode)) {
error = PTR_ERR(ea_inode);
ea_inode = NULL;
goto cleanup;
}
}
if (s->base) {
int offset = (char *)s->here - bs->bh->b_data;
BUFFER_TRACE(bs->bh, "get_write_access");
error = ext4_journal_get_write_access(handle, sb, bs->bh,
EXT4_JTR_NONE);
if (error)
goto cleanup;
lock_buffer(bs->bh);
if (header(s->base)->h_refcount == cpu_to_le32(1)) {
__u32 hash = le32_to_cpu(BHDR(bs->bh)->h_hash);
/*
* This must happen under buffer lock for
Annotation
- Immediate include surface: `linux/init.h`, `linux/fs.h`, `linux/slab.h`, `linux/mbcache.h`, `linux/quotaops.h`, `linux/iversion.h`, `ext4_jbd2.h`, `ext4.h`.
- Detected declarations: `struct ext4_xattr_block_find`, `function ext4_xattr_inode_set_class`, `function ext4_xattr_block_csum`, `function ext4_xattr_block_csum_verify`, `function ext4_xattr_block_csum_set`, `function check_xattrs`, `function __ext4_xattr_check_block`, `function __xattr_check_inode`, `function xattr_find_entry`, `function ext4_xattr_inode_hash`.
- 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.