fs/squashfs/xattr.c
Source file repositories/reference/linux-study-clean/fs/squashfs/xattr.c
File Facts
- System
- Linux kernel
- Corpus path
fs/squashfs/xattr.c- Extension
.c- Size
- 6869 bytes
- Lines
- 272
- 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/init.hlinux/module.hlinux/string.hlinux/fs.hlinux/vfs.hlinux/xattr.hlinux/slab.hsquashfs_fs.hsquashfs_fs_sb.hsquashfs_fs_i.hsquashfs.h
Detected Declarations
function squashfs_listxattrfunction squashfs_xattr_getfunction squashfs_xattr_handler_getfunction squashfs_trusted_xattr_handler_list
Annotated Snippet
if (handler && (!handler->list || handler->list(d))) {
const char *prefix = handler->prefix ?: handler->name;
size_t prefix_size = strlen(prefix);
if (buffer) {
if (prefix_size + name_size + 1 > rest) {
err = -ERANGE;
goto failed;
}
memcpy(buffer, prefix, prefix_size);
buffer += prefix_size;
}
err = squashfs_read_metadata(sb, buffer, &start,
&offset, name_size);
if (err < 0)
goto failed;
if (buffer) {
buffer[name_size] = '\0';
buffer += name_size + 1;
}
rest -= prefix_size + name_size + 1;
} else {
/* no handler or insuffficient privileges, so skip */
err = squashfs_read_metadata(sb, NULL, &start,
&offset, name_size);
if (err < 0)
goto failed;
}
/* skip remaining xattr entry */
err = squashfs_read_metadata(sb, &val, &start, &offset,
sizeof(val));
if (err < 0)
goto failed;
err = squashfs_read_metadata(sb, NULL, &start, &offset,
le32_to_cpu(val.vsize));
if (err < 0)
goto failed;
}
err = buffer_size - rest;
failed:
return err;
}
static int squashfs_xattr_get(struct inode *inode, int name_index,
const char *name, void *buffer, size_t buffer_size)
{
struct super_block *sb = inode->i_sb;
struct squashfs_sb_info *msblk = sb->s_fs_info;
u64 start = SQUASHFS_XATTR_BLK(squashfs_i(inode)->xattr)
+ msblk->xattr_table;
int offset = SQUASHFS_XATTR_OFFSET(squashfs_i(inode)->xattr);
int count = squashfs_i(inode)->xattr_count;
int name_len = strlen(name);
int err, vsize;
char *target = kmalloc(name_len, GFP_KERNEL);
if (target == NULL)
return -ENOMEM;
/* loop reading each xattr name */
for (; count; count--) {
struct squashfs_xattr_entry entry;
struct squashfs_xattr_val val;
int type, prefix, name_size;
err = squashfs_read_metadata(sb, &entry, &start, &offset,
sizeof(entry));
if (err < 0)
goto failed;
name_size = le16_to_cpu(entry.size);
type = le16_to_cpu(entry.type);
prefix = type & SQUASHFS_XATTR_PREFIX_MASK;
if (prefix == name_index && name_size == name_len)
err = squashfs_read_metadata(sb, target, &start,
&offset, name_size);
else
err = squashfs_read_metadata(sb, NULL, &start,
&offset, name_size);
if (err < 0)
goto failed;
if (prefix == name_index && name_size == name_len &&
strncmp(target, name, name_size) == 0) {
Annotation
- Immediate include surface: `linux/init.h`, `linux/module.h`, `linux/string.h`, `linux/fs.h`, `linux/vfs.h`, `linux/xattr.h`, `linux/slab.h`, `squashfs_fs.h`.
- Detected declarations: `function squashfs_listxattr`, `function squashfs_xattr_get`, `function squashfs_xattr_handler_get`, `function squashfs_trusted_xattr_handler_list`.
- 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.