fs/ext2/xattr.c
Source file repositories/reference/linux-study-clean/fs/ext2/xattr.c
File Facts
- System
- Linux kernel
- Corpus path
fs/ext2/xattr.c- Extension
.c- Size
- 29173 bytes
- Lines
- 1060
- 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/buffer_head.hlinux/init.hlinux/printk.hlinux/slab.hlinux/mbcache.hlinux/quotaops.hlinux/rwsem.hlinux/security.hext2.hxattr.hacl.h
Detected Declarations
function ext2_xattr_header_validfunction ext2_xattr_entry_validfunction ext2_xattr_cmp_entryfunction ext2_xattr_getfunction ext2_xattr_listfunction listxattrfunction ext2_xattr_update_super_blockfunction ext2_xattr_setfunction ext2_xattr_release_blockfunction ext2_xattr_setfunction writtenfunction ext2_xattr_delete_inodefunction ext2_xattr_cache_insertfunction ext2_xattr_cmpfunction ext2_xattr_cache_findfunction ext2_xattr_hash_entryfunction ext2_xattr_rehashfunction ext2_xattr_destroy_cache
Annotated Snippet
if (prefix) {
size_t prefix_len = strlen(prefix);
size_t size = prefix_len + entry->e_name_len + 1;
if (buffer) {
if (size > rest) {
error = -ERANGE;
goto cleanup;
}
memcpy(buffer, prefix, prefix_len);
buffer += prefix_len;
memcpy(buffer, entry->e_name, entry->e_name_len);
buffer += entry->e_name_len;
*buffer++ = 0;
}
rest -= size;
}
}
error = buffer_size - rest; /* total size */
cleanup:
brelse(bh);
up_read(&EXT2_I(inode)->xattr_sem);
return error;
}
/*
* Inode operation listxattr()
*
* d_inode(dentry)->i_mutex: don't care
*/
ssize_t
ext2_listxattr(struct dentry *dentry, char *buffer, size_t size)
{
return ext2_xattr_list(dentry, buffer, size);
}
/*
* If the EXT2_FEATURE_COMPAT_EXT_ATTR feature of this file system is
* not set, set it.
*/
static void ext2_xattr_update_super_block(struct super_block *sb)
{
if (EXT2_HAS_COMPAT_FEATURE(sb, EXT2_FEATURE_COMPAT_EXT_ATTR))
return;
spin_lock(&EXT2_SB(sb)->s_lock);
ext2_update_dynamic_rev(sb);
EXT2_SET_COMPAT_FEATURE(sb, EXT2_FEATURE_COMPAT_EXT_ATTR);
spin_unlock(&EXT2_SB(sb)->s_lock);
mark_buffer_dirty(EXT2_SB(sb)->s_sbh);
}
/*
* ext2_xattr_set()
*
* Create, replace or remove an extended attribute for this inode. Value
* is NULL to remove an existing extended attribute, and non-NULL to
* either replace an existing extended attribute, or create a new extended
* attribute. The flags XATTR_REPLACE and XATTR_CREATE
* specify that an extended attribute must exist and must not exist
* previous to the call, respectively.
*
* Returns 0, or a negative error number on failure.
*/
int
ext2_xattr_set(struct inode *inode, int name_index, const char *name,
const void *value, size_t value_len, int flags)
{
struct super_block *sb = inode->i_sb;
struct buffer_head *bh = NULL;
struct ext2_xattr_header *header = NULL;
struct ext2_xattr_entry *here = NULL, *last = NULL;
size_t name_len, free, min_offs = sb->s_blocksize;
int not_found = 1, error;
char *end;
/*
* header -- Points either into bh, or to a temporarily
* allocated buffer.
* here -- The named entry found, or the place for inserting, within
* the block pointed to by header.
* last -- Points right after the last named entry within the block
* pointed to by header.
* min_offs -- The offset of the first value (values are aligned
* towards the end of the block).
* end -- Points right after the block pointed to by header.
*/
Annotation
- Immediate include surface: `linux/buffer_head.h`, `linux/init.h`, `linux/printk.h`, `linux/slab.h`, `linux/mbcache.h`, `linux/quotaops.h`, `linux/rwsem.h`, `linux/security.h`.
- Detected declarations: `function ext2_xattr_header_valid`, `function ext2_xattr_entry_valid`, `function ext2_xattr_cmp_entry`, `function ext2_xattr_get`, `function ext2_xattr_list`, `function listxattr`, `function ext2_xattr_update_super_block`, `function ext2_xattr_set`, `function ext2_xattr_release_block`, `function ext2_xattr_set`.
- 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.