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

NAME

6       statx - get file status (extended)
7

SYNOPSIS

9       #include <fcntl.h>           /* Definition of AT_* constants */
10       #include <sys/stat.h>
11
12       int statx(int dirfd, const char *restrict pathname, int flags,
13                 unsigned int mask, struct statx *restrict statxbuf);
14

DESCRIPTION

16       This  function returns information about a file, storing it in the buf‐
17       fer pointed to by statxbuf.  The returned buffer is a structure of  the
18       following type:
19
20           struct statx {
21               __u32 stx_mask;        /* Mask of bits indicating
22                                         filled fields */
23               __u32 stx_blksize;     /* Block size for filesystem I/O */
24               __u64 stx_attributes;  /* Extra file attribute indicators */
25               __u32 stx_nlink;       /* Number of hard links */
26               __u32 stx_uid;         /* User ID of owner */
27               __u32 stx_gid;         /* Group ID of owner */
28               __u16 stx_mode;        /* File type and mode */
29               __u64 stx_ino;         /* Inode number */
30               __u64 stx_size;        /* Total size in bytes */
31               __u64 stx_blocks;      /* Number of 512B blocks allocated */
32               __u64 stx_attributes_mask;
33                                      /* Mask to show what's supported
34                                         in stx_attributes */
35
36               /* The following fields are file timestamps */
37               struct statx_timestamp stx_atime;  /* Last access */
38               struct statx_timestamp stx_btime;  /* Creation */
39               struct statx_timestamp stx_ctime;  /* Last status change */
40               struct statx_timestamp stx_mtime;  /* Last modification */
41
42               /* If this file represents a device, then the next two
43                  fields contain the ID of the device */
44               __u32 stx_rdev_major;  /* Major ID */
45               __u32 stx_rdev_minor;  /* Minor ID */
46
47               /* The next two fields contain the ID of the device
48                  containing the filesystem where the file resides */
49               __u32 stx_dev_major;   /* Major ID */
50               __u32 stx_dev_minor;   /* Minor ID */
51               __u64 stx_mnt_id;      /* Mount ID */
52           };
53
54       The file timestamps are structures of the following type:
55
56           struct statx_timestamp {
57               __s64 tv_sec;    /* Seconds since the Epoch (UNIX time) */
58               __u32 tv_nsec;   /* Nanoseconds since tv_sec */
59           };
60
61       (Note that reserved space and padding is omitted.)
62
63   Invoking statx():
64       To  access a file's status, no permissions are required on the file it‐
65       self, but in the case of statx() with a pathname, execute (search) per‐
66       mission  is required on all of the directories in pathname that lead to
67       the file.
68
69       statx() uses pathname, dirfd, and flags to identify the target file  in
70       one of the following ways:
71
72       An absolute pathname
73              If pathname begins with a slash, then it is an absolute pathname
74              that identifies the target file.  In this  case,  dirfd  is  ig‐
75              nored.
76
77       A relative pathname
78              If  pathname is a string that begins with a character other than
79              a slash and dirfd is AT_FDCWD, then pathname is a relative path‐
80              name that is interpreted relative to the process's current work‐
81              ing directory.
82
83       A directory-relative pathname
84              If pathname is a string that begins with a character other  than
85              a  slash  and dirfd is a file descriptor that refers to a direc‐
86              tory, then pathname is a relative pathname that  is  interpreted
87              relative  to the directory referred to by dirfd.  (See openat(2)
88              for an explanation of why this is useful.)
89
90       By file descriptor
91              If pathname is an empty string and  the  AT_EMPTY_PATH  flag  is
92              specified  in flags (see below), then the target file is the one
93              referred to by the file descriptor dirfd.
94
95       flags can be used to influence a pathname-based lookup.   A  value  for
96       flags  is  constructed  by ORing together zero or more of the following
97       constants:
98
99       AT_EMPTY_PATH
100              If pathname is an empty string, operate on the file referred  to
101              by  dirfd (which may have been obtained using the open(2) O_PATH
102              flag).  In this case, dirfd can refer to any type of  file,  not
103              just a directory.
104
105              If  dirfd  is AT_FDCWD, the call operates on the current working
106              directory.
107
108              This flag is Linux-specific; define _GNU_SOURCE  to  obtain  its
109              definition.
110
111       AT_NO_AUTOMOUNT
112              Don't  automount the terminal ("basename") component of pathname
113              if it is a directory that is an automount  point.   This  allows
114              the  caller  to  gather attributes of an automount point (rather
115              than the location it would mount).  This flag  can  be  used  in
116              tools  that  scan  directories to prevent mass-automounting of a
117              directory of automount points.  The AT_NO_AUTOMOUNT flag has  no
118              effect  if  the mount point has already been mounted over.  This
119              flag is Linux-specific; define _GNU_SOURCE to obtain its defini‐
120              tion.
121
122       AT_SYMLINK_NOFOLLOW
123              If  pathname  is a symbolic link, do not dereference it: instead
124              return information about the link itself, like lstat(2).
125
126       flags can also be used to control what sort of synchronization the ker‐
127       nel  will do when querying a file on a remote filesystem.  This is done
128       by ORing in one of the following values:
129
130       AT_STATX_SYNC_AS_STAT
131              Do whatever stat(2) does.  This is the default and is very  much
132              filesystem-specific.
133
134       AT_STATX_FORCE_SYNC
135              Force  the  attributes to be synchronized with the server.  This
136              may require that a network filesystem perform a  data  writeback
137              to get the timestamps correct.
138
139       AT_STATX_DONT_SYNC
140              Don't  synchronize  anything,  but rather just take whatever the
141              system has cached if possible.  This may mean that the  informa‐
142              tion  returned  is approximate, but, on a network filesystem, it
143              may not involve a round trip to the server - even if no lease is
144              held.
145
146       The  mask  argument  to statx() is used to tell the kernel which fields
147       the caller is interested in.  mask is an ORed combination of  the  fol‐
148       lowing constants:
149
150           STATX_TYPE          Want stx_mode & S_IFMT
151           STATX_MODE          Want stx_mode & ~S_IFMT
152           STATX_NLINK         Want stx_nlink
153           STATX_UID           Want stx_uid
154           STATX_GID           Want stx_gid
155           STATX_ATIME         Want stx_atime
156           STATX_MTIME         Want stx_mtime
157           STATX_CTIME         Want stx_ctime
158           STATX_INO           Want stx_ino
159           STATX_SIZE          Want stx_size
160           STATX_BLOCKS        Want stx_blocks
161           STATX_BASIC_STATS   [All of the above]
162           STATX_BTIME         Want stx_btime
163           STATX_MNT_ID        Want stx_mnt_id (since Linux 5.8)
164           STATX_ALL           [All currently available fields]
165
166       Note  that, in general, the kernel does not reject values in mask other
167       than the above.  (For an exception, see EINVAL in errors.)  Instead, it
168       simply informs the caller which values are supported by this kernel and
169       filesystem via the statx.stx_mask field.  Therefore, do not simply  set
170       mask  to  UINT_MAX  (all bits set), as one or more bits may, in the fu‐
171       ture, be used to specify an extension to the buffer.
172
173   The returned information
174       The status information for the target file is  returned  in  the  statx
175       structure  pointed  to by statxbuf.  Included in this is stx_mask which
176       indicates what other information has been returned.  stx_mask  has  the
177       same  format  as  the  mask argument and bits are set in it to indicate
178       which fields have been filled in.
179
180       It should be noted that the kernel may return fields that  weren't  re‐
181       quested and may fail to return fields that were requested, depending on
182       what the backing filesystem supports.  (Fields that  are  given  values
183       despite  being  unrequested  can  just  be  ignored.)   In either case,
184       stx_mask will not be equal mask.
185
186       If a filesystem does not support a field  or  if  it  has  an  unrepre‐
187       sentable  value  (for  instance,  a file with an exotic type), then the
188       mask bit corresponding to that field will be cleared in  stx_mask  even
189       if  the  user asked for it and a dummy value will be filled in for com‐
190       patibility purposes if one is available (e.g., a dummy UID and GID  may
191       be specified to mount under some circumstances).
192
193       A  filesystem may also fill in fields that the caller didn't ask for if
194       it has values for them available and the information is available at no
195       extra  cost.   If  this  happens, the corresponding bits will be set in
196       stx_mask.
197
198       Note: for performance and simplicity reasons, different fields  in  the
199       statx  structure  may  contain state information from different moments
200       during the execution of the system call.  For example, if  stx_mode  or
201       stx_uid  is changed by another process by calling chmod(2) or chown(2),
202       stat() might return the old stx_mode together with the new stx_uid,  or
203       the old stx_uid together with the new stx_mode.
204
205       Apart from stx_mask (which is described above), the fields in the statx
206       structure are:
207
208       stx_blksize
209              The "preferred" block size for efficient filesystem I/O.  (Writ‐
210              ing  to  a file in smaller chunks may cause an inefficient read-
211              modify-rewrite.)
212
213       stx_attributes
214              Further status information about the file (see  below  for  more
215              information).
216
217       stx_nlink
218              The number of hard links on a file.
219
220       stx_uid
221              This field contains the user ID of the owner of the file.
222
223       stx_gid
224              This field contains the ID of the group owner of the file.
225
226       stx_mode
227              The file type and mode.  See inode(7) for details.
228
229       stx_ino
230              The inode number of the file.
231
232       stx_size
233              The  size  of  the  file  (if it is a regular file or a symbolic
234              link) in bytes.  The size of a symbolic link is  the  length  of
235              the pathname it contains, without a terminating null byte.
236
237       stx_blocks
238              The  number  of  blocks  allocated to the file on the medium, in
239              512-byte units.  (This may be smaller than stx_size/512 when the
240              file has holes.)
241
242       stx_attributes_mask
243              A  mask indicating which bits in stx_attributes are supported by
244              the VFS and the filesystem.
245
246       stx_atime
247              The file's last access timestamp.
248
249       stx_btime
250              The file's creation timestamp.
251
252       stx_ctime
253              The file's last status change timestamp.
254
255       stx_mtime
256              The file's last modification timestamp.
257
258       stx_dev_major and stx_dev_minor
259              The device on which this file (inode) resides.
260
261       stx_rdev_major and stx_rdev_minor
262              The device that this file (inode) represents if the file  is  of
263              block or character device type.
264
265       stx_mnt_id
266              The mount ID of the mount containing the file.  This is the same
267              number reported by name_to_handle_at(2) and corresponds  to  the
268              number   in   the   first   field  in  one  of  the  records  in
269              /proc/self/mountinfo.
270
271       For further information on the above fields, see inode(7).
272
273   File attributes
274       The stx_attributes field contains a set of ORed flags that indicate ad‐
275       ditional  attributes  of the file.  Note that any attribute that is not
276       indicated as supported by stx_attributes_mask has no usable value here.
277       The  bits  in  stx_attributes_mask  correspond  bit-by-bit  to  stx_at‐
278       tributes.
279
280       The flags are as follows:
281
282       STATX_ATTR_COMPRESSED
283              The file is compressed by the filesystem and may take extra  re‐
284              sources to access.
285
286       STATX_ATTR_IMMUTABLE
287              The file cannot be modified: it cannot be deleted or renamed, no
288              hard links can be created to this file and no data can be  writ‐
289              ten to it.  See chattr(1).
290
291       STATX_ATTR_APPEND
292              The  file can only be opened in append mode for writing.  Random
293              access writing is not permitted.  See chattr(1).
294
295       STATX_ATTR_NODUMP
296              File is not a candidate for backup when a backup program such as
297              dump(8) is run.  See chattr(1).
298
299       STATX_ATTR_ENCRYPTED
300              A  key  is required for the file to be encrypted by the filesys‐
301              tem.
302
303       STATX_ATTR_VERITY (since Linux 5.5)
304              The file has fs-verity enabled.  It cannot be  written  to,  and
305              all  reads from it will be verified against a cryptographic hash
306              that covers the entire file (e.g., via a Merkle tree).
307
308       STATX_ATTR_DAX (since Linux 5.8)
309              The file is in the DAX (cpu direct access) state.  DAX state at‐
310              tempts  to minimize software cache effects for both I/O and mem‐
311              ory mappings of this file.  It requires a file system which  has
312              been configured to support DAX.
313
314              DAX  generally assumes all accesses are via CPU load / store in‐
315              structions which can minimize overhead for small  accesses,  but
316              may adversely affect CPU utilization for large transfers.
317
318              File  I/O is done directly to/from user-space buffers and memory
319              mapped I/O may be performed with direct memory mappings that by‐
320              pass the kernel page cache.
321
322              While the DAX property tends to result in data being transferred
323              synchronously, it does not  give  the  same  guarantees  as  the
324              O_SYNC flag (see open(2)), where data and the necessary metadata
325              are transferred together.
326
327              A DAX file may support being  mapped  with  the  MAP_SYNC  flag,
328              which  enables  a program to use CPU cache flush instructions to
329              persist CPU store operations without an explicit fsync(2).   See
330              mmap(2) for more information.
331

RETURN VALUE

333       On  success,  zero is returned.  On error, -1 is returned, and errno is
334       set to indicate the error.
335

ERRORS

337       EACCES Search permission is denied for one of the  directories  in  the
338              path prefix of pathname.  (See also path_resolution(7).)
339
340       EBADF  pathname  is  relative but dirfd is neither AT_FDCWD nor a valid
341              file descriptor.
342
343       EFAULT pathname or statxbuf is NULL or points to a location outside the
344              process's accessible address space.
345
346       EINVAL Invalid flag specified in flags.
347
348       EINVAL Reserved  flag specified in mask.  (Currently, there is one such
349              flag, designated by the constant STATX__RESERVED, with the value
350              0x80000000U.)
351
352       ELOOP  Too  many  symbolic links encountered while traversing the path‐
353              name.
354
355       ENAMETOOLONG
356              pathname is too long.
357
358       ENOENT A component of pathname does not exist, or pathname is an  empty
359              string and AT_EMPTY_PATH was not specified in flags.
360
361       ENOMEM Out of memory (i.e., kernel memory).
362
363       ENOTDIR
364              A component of the path prefix of pathname is not a directory or
365              pathname is relative and dirfd is a file descriptor referring to
366              a file other than a directory.
367

VERSIONS

369       statx() was added to Linux in kernel 4.11; library support was added in
370       glibc 2.28.
371

CONFORMING TO

373       statx() is Linux-specific.
374

SEE ALSO

376       ls(1), stat(1), access(2),  chmod(2),  chown(2),  name_to_handle_at(2),
377       readlink(2),  stat(2),  utime(2),  proc(5),  capabilities(7), inode(7),
378       symlink(7)
379

COLOPHON

381       This page is part of release 5.13 of the Linux  man-pages  project.   A
382       description  of  the project, information about reporting bugs, and the
383       latest    version    of    this    page,    can     be     found     at
384       https://www.kernel.org/doc/man-pages/.
385
386
387
388Linux                             2021-08-27                          STATX(2)
Impressum