fs/xattr.c
Source file repositories/reference/linux-study-clean/fs/xattr.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xattr.c- Extension
.c- Size
- 46690 bytes
- Lines
- 1762
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: syscall or user/kernel boundary
- Status
- core 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.
- Defines or participates in a user/kernel boundary; inspect argument validation, copy_from_user/copy_to_user, credentials, and dispatch target.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/fs.hlinux/filelock.hlinux/slab.hlinux/file.hlinux/xattr.hlinux/mount.hlinux/namei.hlinux/security.hlinux/syscalls.hlinux/export.hlinux/fsnotify.hlinux/audit.hlinux/vmalloc.hlinux/posix_acl_xattr.hlinux/rhashtable.hlinux/uaccess.hinternal.h
Detected Declarations
syscall setxattratsyscall setxattrsyscall lsetxattrsyscall fsetxattrsyscall getxattratsyscall getxattrsyscall lgetxattrsyscall fgetxattrsyscall listxattratsyscall listxattrsyscall llistxattrsyscall flistxattrsyscall removexattratsyscall removexattrsyscall lremovexattrsyscall fremovexattrstruct sx_keyfunction strcmp_prefixfunction xattr_resolve_namefunction may_write_xattrfunction xattr_permission_errorfunction xattr_permissionfunction xattr_supports_user_prefixfunction for_each_xattr_handlerfunction __vfs_setxattrfunction __vfs_setxattr_nopermfunction __vfs_setxattr_lockedfunction vfs_setxattrfunction xattr_getsecurityfunction vfs_getxattr_allocfunction __vfs_getxattrfunction vfs_getxattrfunction vfs_listxattrfunction __vfs_removexattrfunction __vfs_removexattr_lockedfunction vfs_removexattrfunction import_xattr_namefunction setxattr_copyfunction do_setxattrfunction file_setxattrfunction filename_setxattrfunction path_setxattratfunction do_getxattrfunction file_getxattrfunction filename_getxattrfunction path_getxattratfunction listxattrfunction file_listxattr
Annotated Snippet
SYSCALL_DEFINE6(setxattrat, int, dfd, const char __user *, pathname, unsigned int, at_flags,
const char __user *, name, const struct xattr_args __user *, uargs,
size_t, usize)
{
struct xattr_args args = {};
int error;
BUILD_BUG_ON(sizeof(struct xattr_args) < XATTR_ARGS_SIZE_VER0);
BUILD_BUG_ON(sizeof(struct xattr_args) != XATTR_ARGS_SIZE_LATEST);
if (unlikely(usize < XATTR_ARGS_SIZE_VER0))
return -EINVAL;
if (usize > PAGE_SIZE)
return -E2BIG;
error = copy_struct_from_user(&args, sizeof(args), uargs, usize);
if (error)
return error;
return path_setxattrat(dfd, pathname, at_flags, name,
u64_to_user_ptr(args.value), args.size,
args.flags);
}
SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
const char __user *, name, const void __user *, value,
size_t, size, int, flags)
{
return path_setxattrat(AT_FDCWD, pathname, 0, name, value, size, flags);
}
SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
const char __user *, name, const void __user *, value,
size_t, size, int, flags)
{
return path_setxattrat(AT_FDCWD, pathname, AT_SYMLINK_NOFOLLOW, name,
value, size, flags);
}
SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
const void __user *,value, size_t, size, int, flags)
{
return path_setxattrat(fd, NULL, AT_EMPTY_PATH, name,
value, size, flags);
}
/*
* Extended attribute GET operations
*/
static ssize_t
do_getxattr(struct mnt_idmap *idmap, struct dentry *d,
struct kernel_xattr_ctx *ctx)
{
ssize_t error;
char *kname = ctx->kname->name;
void *kvalue = NULL;
if (ctx->size) {
if (ctx->size > XATTR_SIZE_MAX)
ctx->size = XATTR_SIZE_MAX;
kvalue = kvzalloc(ctx->size, GFP_KERNEL);
if (!kvalue)
return -ENOMEM;
}
if (is_posix_acl_xattr(kname))
error = do_get_acl(idmap, d, kname, kvalue, ctx->size);
else
error = vfs_getxattr(idmap, d, kname, kvalue, ctx->size);
if (error > 0) {
if (ctx->size && copy_to_user(ctx->value, kvalue, error))
error = -EFAULT;
} else if (error == -ERANGE && ctx->size >= XATTR_SIZE_MAX) {
/* The file system tried to returned a value bigger
than XATTR_SIZE_MAX bytes. Not possible. */
error = -E2BIG;
}
kvfree(kvalue);
return error;
}
ssize_t file_getxattr(struct file *f, struct kernel_xattr_ctx *ctx)
{
audit_file(f);
return do_getxattr(file_mnt_idmap(f), f->f_path.dentry, ctx);
}
ssize_t filename_getxattr(int dfd, struct filename *filename,
unsigned int lookup_flags, struct kernel_xattr_ctx *ctx)
Annotation
- Immediate include surface: `linux/fs.h`, `linux/filelock.h`, `linux/slab.h`, `linux/file.h`, `linux/xattr.h`, `linux/mount.h`, `linux/namei.h`, `linux/security.h`.
- Detected declarations: `syscall setxattrat`, `syscall setxattr`, `syscall lsetxattr`, `syscall fsetxattr`, `syscall getxattrat`, `syscall getxattr`, `syscall lgetxattr`, `syscall fgetxattr`, `syscall listxattrat`, `syscall listxattr`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: core implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.