stat(2) System Calls Manual stat(2) stat, fstat, lstat, fstatat - (libc -lc) #include int stat(const char *restrict path, struct stat *restrict statbuf); int fstat(int fd, struct stat *statbuf); int lstat(const char *restrict path, struct stat *restrict statbuf); #include /* AT_* */ #include int fstatat(int dirfd, const char *restrict path, struct stat *restrict statbuf, int flags); glibc ( feature_test_macros(7)): lstat(): /* glibc 2.20 */ _DEFAULT_SOURCE || _XOPEN_SOURCE >= 500 || /* glibc 2.10: */ _POSIX_C_SOURCE >= 200112L || /* glibc 2.19 */ _BSD_SOURCE fstatat(): glibc 2.10: _POSIX_C_SOURCE >= 200809L glibc 2.10: _ATFILE_SOURCE statbuf. -- stat() fstatat() lstat()-- () path . stat() fstatat() path fstatat() . lstat() stat() path . fstat() stat() fd. stat stat ( stat(3type)). : stat . st_mode st_uid chmod(2) chown(2) stat() st_mode st_uid st_uid st_mode . fstatat() fstatat() stat() lstat() fstat() . path dirfd ( stat() lstat() ). path dirfd AT_FDCWD path ( stat() lstat()). path dirfd. flags 0 OR: AT_EMPTY_PATH ( 2.6.39) path ( NULL Linux 6.11) dirfd ( open(2) O_PATH). dirfd fstatat() fstat(). dirfd AT_FDCWD . Linux _GNU_SOURCE . AT_NO_AUTOMOUNT ( Linux 2.6.38) ("basename") path. Linux 3.1 . Linux 4.11 . AT_SYMLINK_NOFOLLOW path : lstat(). ( fstatat() stat().) openat(2) fstatat(). . -1 errno . EACCES path. ( path_resolution(7).) EBADF fd . EBADF (fstatat()) path dirfd AT_FDCWD . EFAULT . EINVAL (fstatat()) flags. ELOOP . ENAMETOOLONG path . ENOENT path . ENOENT path AT_EMPTY_PATH flags. ENOMEM ( ). ENOTDIR path . ENOTDIR (fstatat()) path dirfd . EOVERFLOW path fd inode off_t ino_t blkcnt_t . 32 -D_FILE_OFFSET_BITS=64 stat() (1<<31)-1 . POSIX.1-2024. stat() fstat() lstat() SVr4 4.3BSD POSIX.1-2001. fstatat() POSIX.1-2008. 2.6.16 glibc 2.4. POSIX.1-2001 lstat() st_size st_mode stat. POSIX.1-2008 lstat() (mode bits) st_mode. st_blocks st_blksize . ( BSD. NFS.) C stat stat(): sys_stat() ( __NR_oldstat) sys_newstat() ( __NR_stat) sys_stat64() ( __NR_stat64) 32- i386. 1.0 ( ) 2.4. fstat() lstat(). stat : __old_kernel_stat (padding). stat st_ino . stat64 st_ino st_uid st_gid -2.4 UIDs GIDs 32 . ( 2.6 (device IDs) 32 .) stat() glibc . 64- : stat() stat . fstatat() glibc fstatat64() newfstatat() . lstat() stat . #include #include #include #include #include #include int main(int argc, char *argv[]) { struct stat sb; if (argc != 2) { fprintf(stderr, "Usage: %s \n", argv[0]); exit(EXIT_FAILURE); } if (lstat(argv[1], &sb) == -1) { perror("lstat"); exit(EXIT_FAILURE); } printf(" : [%x,%x]\n", major(sb.st_dev), minor(sb.st_dev)); printf(" : "); switch (sb.st_mode & S_IFMT) { case S_IFBLK: printf(" \n"); break; case S_IFCHR: printf(" \n"); break; case S_IFDIR: printf("\n"); break; case S_IFIFO: printf("FIFO/\n"); break; case S_IFLNK: printf(" \n"); break; case S_IFREG: printf(" \n"); break; case S_IFSOCK: printf("\n"); break; default: printf(" \n"); break; } printf(" -: %ju\n", (uintmax_t) sb.st_ino); printf(": %jo ()\n", (uintmax_t) sb.st_mode); printf(" : %ju\n", (uintmax_t) sb.st_nlink); printf(": UID=%ju GID=%ju\n", (uintmax_t) sb.st_uid, (uintmax_t) sb.st_gid); printf(" / : %jd \n", (intmax_t) sb.st_blksize); printf(" : %jd \n", (intmax_t) sb.st_size); printf(" : %jd\n", (intmax_t) sb.st_blocks); printf(" : %s", ctime(&sb.st_ctime)); printf(" : %s", ctime(&sb.st_atime)); printf(" : %s", ctime(&sb.st_mtime)); exit(EXIT_SUCCESS); } ls(1) stat(1) access(2) chmod(2) chown(2) readlink(2) statx(2) utime(2) stat(3type) capabilities(7) inode(7) symlink(7) 3 . . : . 6.18 8 2026 stat(2)