1STAT(2)                    Linux Programmer's Manual                   STAT(2)
2
3
4

NAME

6       stat, fstat, lstat, fstatat - get file status
7

SYNOPSIS

9       #include <sys/stat.h>
10
11       int stat(const char *restrict pathname,
12                struct stat *restrict statbuf);
13       int fstat(int fd, struct stat *statbuf);
14       int lstat(const char *restrict pathname,
15                struct stat *restrict statbuf);
16
17       #include <fcntl.h>           /* Definition of AT_* constants */
18       #include <sys/stat.h>
19
20       int fstatat(int dirfd, const char *restrict pathname,
21                struct stat *restrict statbuf, int flags);
22
23   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
24
25       lstat():
26           /* Since glibc 2.20 */ _DEFAULT_SOURCE
27               || _XOPEN_SOURCE >= 500
28               || /* Since glibc 2.10: */ _POSIX_C_SOURCE >= 200112L
29               || /* Glibc 2.19 and earlier */ _BSD_SOURCE
30
31       fstatat():
32           Since glibc 2.10:
33               _POSIX_C_SOURCE >= 200809L
34           Before glibc 2.10:
35               _ATFILE_SOURCE
36

DESCRIPTION

38       These  functions return information about a file, in the buffer pointed
39       to by statbuf.  No permissions are required on the file itself,  but—in
40       the  case of stat(), fstatat(), and lstat()—execute (search) permission
41       is required on all of the directories in  pathname  that  lead  to  the
42       file.
43
44       stat()  and fstatat() retrieve information about the file pointed to by
45       pathname; the differences for fstatat() are described below.
46
47       lstat() is identical to stat(), except that if pathname is  a  symbolic
48       link,  then  it returns information about the link itself, not the file
49       that the link refers to.
50
51       fstat() is identical to stat(), except that the file about which infor‐
52       mation is to be retrieved is specified by the file descriptor fd.
53
54   The stat structure
55       All  of  these system calls return a stat structure, which contains the
56       following fields:
57
58           struct stat {
59               dev_t     st_dev;         /* ID of device containing file */
60               ino_t     st_ino;         /* Inode number */
61               mode_t    st_mode;        /* File type and mode */
62               nlink_t   st_nlink;       /* Number of hard links */
63               uid_t     st_uid;         /* User ID of owner */
64               gid_t     st_gid;         /* Group ID of owner */
65               dev_t     st_rdev;        /* Device ID (if special file) */
66               off_t     st_size;        /* Total size, in bytes */
67               blksize_t st_blksize;     /* Block size for filesystem I/O */
68               blkcnt_t  st_blocks;      /* Number of 512B blocks allocated */
69
70               /* Since Linux 2.6, the kernel supports nanosecond
71                  precision for the following timestamp fields.
72                  For the details before Linux 2.6, see NOTES. */
73
74               struct timespec st_atim;  /* Time of last access */
75               struct timespec st_mtim;  /* Time of last modification */
76               struct timespec st_ctim;  /* Time of last status change */
77
78           #define st_atime st_atim.tv_sec      /* Backward compatibility */
79           #define st_mtime st_mtim.tv_sec
80           #define st_c