1 .\" Copyright (c) 2017 David Howells <dhowells@redhat.com>
3 .\" Derived from the stat.2 manual page:
4 .\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
5 .\" Parts Copyright (c) 1995 Nicolai Langfeldt (janl@ifi.uio.no), 1/1/95
6 .\" and Copyright (c) 2006, 2007, 2014 Michael Kerrisk <mtk.manpages@gmail.com>
8 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
10 .TH STATX 2 2021-08-27 "Linux" "Linux Programmer's Manual"
12 statx \- get file status (extended)
15 .RI ( libc ", " \-lc )
18 .BR "#include <fcntl.h> " "/* Definition of " AT_* " constants */"
19 .B #include <sys/stat.h>
21 .BI "int statx(int " dirfd ", const char *restrict " pathname ", int " flags ,
22 .BI " unsigned int " mask ", struct statx *restrict " statxbuf );
25 This function returns information about a file, storing it in the buffer
28 The returned buffer is a structure of the following type:
33 __u32 stx_mask; /* Mask of bits indicating
35 __u32 stx_blksize; /* Block size for filesystem I/O */
36 __u64 stx_attributes; /* Extra file attribute indicators */
37 __u32 stx_nlink; /* Number of hard links */
38 __u32 stx_uid; /* User ID of owner */
39 __u32 stx_gid; /* Group ID of owner */
40 __u16 stx_mode; /* File type and mode */
41 __u64 stx_ino; /* Inode number */
42 __u64 stx_size; /* Total size in bytes */
43 __u64 stx_blocks; /* Number of 512B blocks allocated */
44 __u64 stx_attributes_mask;
45 /* Mask to show what\(aqs supported
48 /* The following fields are file timestamps */
49 struct statx_timestamp stx_atime; /* Last access */
50 struct statx_timestamp stx_btime; /* Creation */
51 struct statx_timestamp stx_ctime; /* Last status change */
52 struct statx_timestamp stx_mtime; /* Last modification */
54 /* If this file represents a device, then the next two
55 fields contain the ID of the device */
56 __u32 stx_rdev_major; /* Major ID */
57 __u32 stx_rdev_minor; /* Minor ID */
59 /* The next two fields contain the ID of the device
60 containing the filesystem where the file resides */
61 __u32 stx_dev_major; /* Major ID */
62 __u32 stx_dev_minor; /* Minor ID */
63 __u64 stx_mnt_id; /* Mount ID */
68 The file timestamps are structures of the following type:
72 struct statx_timestamp {
73 __s64 tv_sec; /* Seconds since the Epoch (UNIX time) */
74 __u32 tv_nsec; /* Nanoseconds since tv_sec */
79 (Note that reserved space and padding is omitted.)
81 Invoking \fBstatx\fR():
82 To access a file's status, no permissions are required on the file itself,
86 execute (search) permission is required on all of the directories in
88 that lead to the file.
96 to identify the target file in one of the following ways:
102 then it is an absolute pathname that identifies the target file.
110 is a string that begins with a character other than a slash and
116 is a relative pathname that is interpreted relative to the process's
117 current working directory.
119 A directory-relative pathname
122 is a string that begins with a character other than a slash and
124 is a file descriptor that refers to a directory, then
126 is a relative pathname that is interpreted relative to the directory
131 for an explanation of why this is useful.)
136 is an empty string and the
141 then the target file is the one referred to by the file descriptor
145 can be used to influence a pathname-based lookup.
148 is constructed by ORing together zero or more of the following constants:
151 .\" commit 65cfc6722361570bfe255698d9cd4dccaf47570d
154 is an empty string, operate on the file referred to by
156 (which may have been obtained using the
162 can refer to any type of file, not just a directory.
168 the call operates on the current working directory.
170 This flag is Linux-specific; define
172 .\" Before glibc 2.16, defining _ATFILE_SOURCE sufficed
173 to obtain its definition.
176 Don't automount the terminal ("basename") component of
178 if it is a directory that is an automount point.
179 This allows the caller to gather attributes of an automount point
180 (rather than the location it would mount).
181 This flag has no effect if the mount point has already been mounted over.
185 flag can be used in tools that scan directories
186 to prevent mass-automounting of a directory of automount points.
197 This flag is Linux-specific; define
199 .\" Before glibc 2.16, defining _ATFILE_SOURCE sufficed
200 to obtain its definition.
202 .B AT_SYMLINK_NOFOLLOW
205 is a symbolic link, do not dereference it:
206 instead return information about the link itself, like
210 can also be used to control what sort of synchronization the kernel will do
211 when querying a file on a remote filesystem.
212 This is done by ORing in one of the following values:
214 .B AT_STATX_SYNC_AS_STAT
218 This is the default and is very much filesystem-specific.
220 .B AT_STATX_FORCE_SYNC
221 Force the attributes to be synchronized with the server.
222 This may require that
223 a network filesystem perform a data writeback to get the timestamps correct.
225 .B AT_STATX_DONT_SYNC
226 Don't synchronize anything, but rather just take whatever
227 the system has cached if possible.
228 This may mean that the information returned is approximate, but,
229 on a network filesystem, it may not involve a round trip to the server - even
236 is used to tell the kernel which fields the caller is interested in.
238 is an ORed combination of the following constants:
243 STATX_TYPE Want stx_mode & S_IFMT
244 STATX_MODE Want stx_mode & \(tiS_IFMT
245 STATX_NLINK Want stx_nlink
246 STATX_UID Want stx_uid
247 STATX_GID Want stx_gid
248 STATX_ATIME Want stx_atime
249 STATX_MTIME Want stx_mtime
250 STATX_CTIME Want stx_ctime
251 STATX_INO Want stx_ino
252 STATX_SIZE Want stx_size
253 STATX_BLOCKS Want stx_blocks
254 STATX_BASIC_STATS [All of the above]
255 STATX_BTIME Want stx_btime
256 STATX_MNT_ID Want stx_mnt_id (since Linux 5.8)
257 STATX_ALL [All currently available fields]
261 Note that, in general, the kernel does
265 other than the above.
266 (For an exception, see
269 Instead, it simply informs the caller which values are supported
270 by this kernel and filesystem via the
280 as one or more bits may, in the future, be used to specify an
281 extension to the buffer.
283 The returned information
284 The status information for the target file is returned in the
286 structure pointed to by
290 which indicates what other information has been returned.
292 has the same format as the
294 argument and bits are set in it to indicate
295 which fields have been filled in.
297 It should be noted that the kernel may return fields that weren't
298 requested and may fail to return fields that were requested,
299 depending on what the backing filesystem supports.
300 (Fields that are given values despite being unrequested can just be ignored.)
306 If a filesystem does not support a field or if it has
307 an unrepresentable value (for instance, a file with an exotic type),
308 then the mask bit corresponding to that field will be cleared in
310 even if the user asked for it and a dummy value will be filled in for
311 compatibility purposes if one is available (e.g., a dummy UID and GID may be
312 specified to mount under some circumstances).
314 A filesystem may also fill in fields that the caller didn't ask for if it has
315 values for them available and the information is available at no extra cost.
316 If this happens, the corresponding bits will be set in
319 .\" Background: inode attributes are modified with i_mutex held, but
320 .\" read by stat() without taking the mutex.
322 for performance and simplicity reasons, different fields in the
324 structure may contain state information from different moments
325 during the execution of the system call.
330 is changed by another process by calling
337 together with the new
341 together with the new
346 (which is described above), the fields in the
351 The "preferred" block size for efficient filesystem I/O.
352 (Writing to a file in
353 smaller chunks may cause an inefficient read-modify-rewrite.)
356 Further status information about the file (see below for more information).
359 The number of hard links on a file.
362 This field contains the user ID of the owner of the file.
365 This field contains the ID of the group owner of the file.
368 The file type and mode.
374 The inode number of the file.
377 The size of the file (if it is a regular file or a symbolic link) in bytes.
378 The size of a symbolic link is the length of the pathname it contains,
379 without a terminating null byte.
382 The number of blocks allocated to the file on the medium, in 512-byte units.
383 (This may be smaller than
385 when the file has holes.)
387 .I stx_attributes_mask
388 A mask indicating which bits in
390 are supported by the VFS and the filesystem.
393 The file's last access timestamp.
396 The file's creation timestamp.
399 The file's last status change timestamp.
402 The file's last modification timestamp.
404 .IR stx_dev_major " and " stx_dev_minor
405 The device on which this file (inode) resides.
407 .IR stx_rdev_major " and " stx_rdev_minor
408 The device that this file (inode) represents if the file is of block or
409 character device type.
412 .\" commit fa2fcf4f1df1559a0a4ee0f46915b496cc2ebf60
413 The mount ID of the mount containing the file.
414 This is the same number reported by
415 .BR name_to_handle_at (2)
416 and corresponds to the number in the first field in one of the records in
417 .IR /proc/self/mountinfo .
419 For further information on the above fields, see
425 field contains a set of ORed flags that indicate additional attributes
427 Note that any attribute that is not indicated as supported by
428 .I stx_attributes_mask
429 has no usable value here.
431 .I stx_attributes_mask
432 correspond bit-by-bit to
435 The flags are as follows:
437 .B STATX_ATTR_COMPRESSED
438 The file is compressed by the filesystem and may take extra resources
441 .B STATX_ATTR_IMMUTABLE
442 The file cannot be modified: it cannot be deleted or renamed,
443 no hard links can be created to this file and no data can be written to it.
448 The file can only be opened in append mode for writing.
449 Random access writing
455 File is not a candidate for backup when a backup program such as
461 .B STATX_ATTR_ENCRYPTED
462 A key is required for the file to be encrypted by the filesystem.
464 .BR STATX_ATTR_VERITY " (since Linux 5.5)"
465 .\" commit 3ad2522c64cff1f5aebb987b00683268f0cc7c29
466 The file has fs-verity enabled.
467 It cannot be written to, and all reads from it will be verified
468 against a cryptographic hash that covers the
469 entire file (e.g., via a Merkle tree).
471 .BR STATX_ATTR_DAX " (since Linux 5.8)"
472 The file is in the DAX (cpu direct access) state.
473 DAX state attempts to
474 minimize software cache effects for both I/O and memory mappings of this file.
475 It requires a file system which has been configured to support DAX.
477 DAX generally assumes all accesses are via CPU load / store instructions
478 which can minimize overhead for small accesses,
479 but may adversely affect CPU utilization for large transfers.
481 File I/O is done directly to/from user-space buffers and memory mapped I/O may
482 be performed with direct memory mappings that bypass the kernel page cache.
484 While the DAX property tends to result in data being transferred synchronously,
485 it does not give the same guarantees as the
489 where data and the necessary metadata are transferred together.
491 A DAX file may support being mapped with the
493 flag, which enables a
494 program to use CPU cache flush instructions to persist CPU store operations
499 for more information.
501 On success, zero is returned.
502 On error, \-1 is returned, and
504 is set to indicate the error.
508 Search permission is denied for one of the directories
509 in the path prefix of
512 .BR path_resolution (7).)
520 nor a valid file descriptor.
526 is NULL or points to a location outside the process's
527 accessible address space.
530 Invalid flag specified in
534 Reserved flag specified in
536 (Currently, there is one such flag, designated by the constant
537 .BR STATX__RESERVED ,
538 with the value 0x80000000U.)
541 Too many symbolic links encountered while traversing the pathname.
552 is an empty string and
558 Out of memory (i.e., kernel memory).
561 A component of the path prefix of
563 is not a directory or
567 is a file descriptor referring to a file other than a directory.
570 was added to Linux in kernel 4.11; library support was added in glibc 2.28.
580 .BR name_to_handle_at (2),
585 .BR capabilities (7),