fs/stat.c
Source file repositories/reference/linux-study-clean/fs/stat.c
File Facts
- System
- Linux kernel
- Corpus path
fs/stat.c- Extension
.c- Size
- 27228 bytes
- Lines
- 969
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/blkdev.hlinux/export.hlinux/mm.hlinux/errno.hlinux/file.hlinux/highuid.hlinux/fs.hlinux/namei.hlinux/security.hlinux/cred.hlinux/syscalls.hlinux/pagemap.hlinux/compat.hlinux/iversion.hlinux/uaccess.hasm/unistd.htrace/events/timestamp.hinternal.hmount.h
Detected Declarations
syscall statsyscall lstatsyscall fstatsyscall newstatsyscall newlstatsyscall newfstatatsyscall newfstatsyscall readlinkatsyscall readlinksyscall stat64syscall lstat64syscall fstat64syscall fstatat64syscall statxfunction Copyrightfunction generic_fillattrfunction generic_fill_statx_attrfunction generic_fill_statx_atomic_writesfunction vfs_getattr_nosecfunction vfs_getattrfunction vfs_getattrfunction statx_lookup_flagsfunction vfs_statx_pathfunction vfs_statx_fdfunction vfs_getattrfunction vfs_fstatatfunction cp_old_statfunction cp_new_statfunction do_readlinkatfunction readlinkfunction cp_new_stat64function cp_statxfunction do_statxfunction do_statx_fdfunction fstatfunction cp_compat_statfunction __inode_add_bytesfunction inode_add_bytesfunction __inode_sub_bytesfunction inode_sub_bytesfunction inode_get_bytesfunction inode_set_bytesexport fill_mg_cmtimeexport generic_fillattrexport generic_fill_statx_attrexport generic_fill_statx_atomic_writesexport vfs_getattr_nosecexport vfs_getattr
Annotated Snippet
SYSCALL_DEFINE2(stat, const char __user *, filename,
struct __old_kernel_stat __user *, statbuf)
{
struct kstat stat;
int error;
error = vfs_stat(filename, &stat);
if (unlikely(error))
return error;
return cp_old_stat(&stat, statbuf);
}
SYSCALL_DEFINE2(lstat, const char __user *, filename,
struct __old_kernel_stat __user *, statbuf)
{
struct kstat stat;
int error;
error = vfs_lstat(filename, &stat);
if (unlikely(error))
return error;
return cp_old_stat(&stat, statbuf);
}
SYSCALL_DEFINE2(fstat, unsigned int, fd, struct __old_kernel_stat __user *, statbuf)
{
struct kstat stat;
int error;
error = vfs_fstat(fd, &stat);
if (unlikely(error))
return error;
return cp_old_stat(&stat, statbuf);
}
#endif /* __ARCH_WANT_OLD_STAT */
#ifdef __ARCH_WANT_NEW_STAT
#ifndef INIT_STRUCT_STAT_PADDING
# define INIT_STRUCT_STAT_PADDING(st) memset(&st, 0, sizeof(st))
#endif
static int cp_new_stat(struct kstat *stat, struct stat __user *statbuf)
{
struct stat tmp;
if (sizeof(tmp.st_dev) < 4 && !old_valid_dev(stat->dev))
return -EOVERFLOW;
if (sizeof(tmp.st_rdev) < 4 && !old_valid_dev(stat->rdev))
return -EOVERFLOW;
#if BITS_PER_LONG == 32
if (stat->size > MAX_NON_LFS)
return -EOVERFLOW;
#endif
INIT_STRUCT_STAT_PADDING(tmp);
tmp.st_dev = new_encode_dev(stat->dev);
tmp.st_ino = stat->ino;
if (sizeof(tmp.st_ino) < sizeof(stat->ino) && tmp.st_ino != stat->ino)
return -EOVERFLOW;
tmp.st_mode = stat->mode;
tmp.st_nlink = stat->nlink;
if (tmp.st_nlink != stat->nlink)
return -EOVERFLOW;
SET_UID(tmp.st_uid, from_kuid_munged(current_user_ns(), stat->uid));
SET_GID(tmp.st_gid, from_kgid_munged(current_user_ns(), stat->gid));
tmp.st_rdev = new_encode_dev(stat->rdev);
tmp.st_size = stat->size;
tmp.st_atime = stat->atime.tv_sec;
tmp.st_mtime = stat->mtime.tv_sec;
tmp.st_ctime = stat->ctime.tv_sec;
#ifdef STAT_HAVE_NSEC
tmp.st_atime_nsec = stat->atime.tv_nsec;
tmp.st_mtime_nsec = stat->mtime.tv_nsec;
tmp.st_ctime_nsec = stat->ctime.tv_nsec;
#endif
tmp.st_blocks = stat->blocks;
tmp.st_blksize = stat->blksize;
return copy_to_user(statbuf,&tmp,sizeof(tmp)) ? -EFAULT : 0;
}
SYSCALL_DEFINE2(newstat, const char __user *, filename,
struct stat __user *, statbuf)
{
struct kstat stat;
int error;
Annotation
- Immediate include surface: `linux/blkdev.h`, `linux/export.h`, `linux/mm.h`, `linux/errno.h`, `linux/file.h`, `linux/highuid.h`, `linux/fs.h`, `linux/namei.h`.
- Detected declarations: `syscall stat`, `syscall lstat`, `syscall fstat`, `syscall newstat`, `syscall newlstat`, `syscall newfstatat`, `syscall newfstat`, `syscall readlinkat`, `syscall readlink`, `syscall stat64`.
- 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.