1statx(2)                      System Calls Manual                     statx(2)
2
3
4

NAME

6       statx - get file status (extended)
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #define _GNU_SOURCE          /* See feature_test_macros(7) */
13       #include <fcntl.h>           /* Definition of AT_* constants */
14       #include <sys/stat.h>
15
16       int statx(int dirfd, const char *restrict pathname, int flags,
17                 unsigned int mask, struct statx *restrict statxbuf);
18

DESCRIPTION

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

RETURN VALUE

361       On  success,  zero is returned.  On error, -1 is returned, and errno is
362       set to indicate the error.
363

ERRORS

365       EACCES Search permission is denied for one of the  directories  in  the
366              path prefix of pathname.  (See also path_resolution(7).)
367
368       EBADF  pathname  is  relative but dirfd is neither AT_FDCWD nor a valid
369              file descriptor.
370
371       EFAULT pathname or statxbuf is NULL or points to a location outside the
372              process's accessible address space.
373
374       EINVAL Invalid flag specified in flags.
375
376       EINVAL Reserved  flag specified in mask.  (Currently, there is one such
377              flag, designated by the constant STATX__RESERVED, with the value
378              0x80000000U.)
379
380       ELOOP  Too  many  symbolic links encountered while traversing the path‐
381              name.
382
383       ENAMETOOLONG
384              pathname is too long.
385
386       ENOENT A component of pathname does not exist, or pathname is an  empty
387              string and AT_EMPTY_PATH was not specified in flags.
388
389       ENOMEM Out of memory (i.e., kernel memory).
390
391       ENOTDIR
392              A component of the path prefix of pathname is not a directory or
393              pathname is relative and dirfd is a file descriptor referring to
394              a file other than a directory.
395

STANDARDS

397       Linux.
398

HISTORY

400       Linux 4.11, glibc 2.28.
401

SEE ALSO

403       ls(1),  stat(1),  access(2),  chmod(2), chown(2), name_to_handle_at(2),
404       readlink(2), stat(2),  utime(2),  proc(5),  capabilities(7),  inode(7),
405       symlink(7)
406
407
408
409Linux man-pages 6.04              2023-03-30                          statx(2)
Impressum