fs/file_attr.c
Source file repositories/reference/linux-study-clean/fs/file_attr.c
File Facts
- System
- Linux kernel
- Corpus path
fs/file_attr.c- Extension
.c- Size
- 12546 bytes
- Lines
- 487
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/fs.hlinux/security.hlinux/fscrypt.hlinux/fsnotify.hlinux/fileattr.hlinux/export.hlinux/syscalls.hlinux/namei.hinternal.h
Detected Declarations
syscall file_getattrsyscall file_setattrfunction fileattr_fill_xflagsfunction fileattr_fill_flagsfunction vfs_fileattr_getfunction fileattr_to_file_attrfunction copy_fsxattr_to_userfunction file_attr_to_fileattrfunction copy_fsxattr_from_userfunction fileattr_set_preparefunction vfs_fileattr_setfunction ioctl_getflagsfunction ioctl_setflagsfunction ioctl_fsgetxattrfunction ioctl_fssetxattrexport fileattr_fill_xflagsexport fileattr_fill_flagsexport vfs_fileattr_getexport copy_fsxattr_to_userexport vfs_fileattr_set
Annotated Snippet
SYSCALL_DEFINE5(file_getattr, int, dfd, const char __user *, filename,
struct file_attr __user *, ufattr, size_t, usize,
unsigned int, at_flags)
{
struct path filepath __free(path_put) = {};
unsigned int lookup_flags = 0;
struct file_attr fattr;
struct file_kattr fa = { .flags_valid = true }; /* hint only */
int error;
BUILD_BUG_ON(sizeof(struct file_attr) < FILE_ATTR_SIZE_VER0);
BUILD_BUG_ON(sizeof(struct file_attr) != FILE_ATTR_SIZE_LATEST);
if ((at_flags & ~(AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH)) != 0)
return -EINVAL;
if (!(at_flags & AT_SYMLINK_NOFOLLOW))
lookup_flags |= LOOKUP_FOLLOW;
if (usize > PAGE_SIZE)
return -E2BIG;
if (usize < FILE_ATTR_SIZE_VER0)
return -EINVAL;
CLASS(filename_maybe_null, name)(filename, at_flags);
if (!name && dfd >= 0) {
CLASS(fd, f)(dfd);
if (fd_empty(f))
return -EBADF;
filepath = fd_file(f)->f_path;
path_get(&filepath);
} else {
error = filename_lookup(dfd, name, lookup_flags, &filepath,
NULL);
if (error)
return error;
}
error = vfs_fileattr_get(filepath.dentry, &fa);
if (error == -ENOIOCTLCMD || error == -ENOTTY)
error = -EOPNOTSUPP;
if (error)
return error;
fileattr_to_file_attr(&fa, &fattr);
error = copy_struct_to_user(ufattr, usize, &fattr,
sizeof(struct file_attr), NULL);
return error;
}
SYSCALL_DEFINE5(file_setattr, int, dfd, const char __user *, filename,
struct file_attr __user *, ufattr, size_t, usize,
unsigned int, at_flags)
{
struct path filepath __free(path_put) = {};
unsigned int lookup_flags = 0;
struct file_attr fattr;
struct file_kattr fa = {};
int error;
BUILD_BUG_ON(sizeof(struct file_attr) < FILE_ATTR_SIZE_VER0);
BUILD_BUG_ON(sizeof(struct file_attr) != FILE_ATTR_SIZE_LATEST);
if ((at_flags & ~(AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH)) != 0)
return -EINVAL;
if (!(at_flags & AT_SYMLINK_NOFOLLOW))
lookup_flags |= LOOKUP_FOLLOW;
if (usize > PAGE_SIZE)
return -E2BIG;
if (usize < FILE_ATTR_SIZE_VER0)
return -EINVAL;
error = copy_struct_from_user(&fattr, sizeof(struct file_attr), ufattr,
usize);
if (error)
return error;
error = file_attr_to_fileattr(&fattr, &fa);
if (error)
return error;
CLASS(filename_maybe_null, name)(filename, at_flags);
if (!name && dfd >= 0) {
CLASS(fd, f)(dfd);
Annotation
- Immediate include surface: `linux/fs.h`, `linux/security.h`, `linux/fscrypt.h`, `linux/fsnotify.h`, `linux/fileattr.h`, `linux/export.h`, `linux/syscalls.h`, `linux/namei.h`.
- Detected declarations: `syscall file_getattr`, `syscall file_setattr`, `function fileattr_fill_xflags`, `function fileattr_fill_flags`, `function vfs_fileattr_get`, `function fileattr_to_file_attr`, `function copy_fsxattr_to_user`, `function file_attr_to_fileattr`, `function copy_fsxattr_from_user`, `function fileattr_set_prepare`.
- 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.
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.