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 .\" %%%LICENSE_START(VERBATIM)
9 .\" Permission is granted to make and distribute verbatim copies of this
10 .\" manual provided the copyright notice and this permission notice are
11 .\" preserved on all copies.
13 .\" Permission is granted to copy and distribute modified versions of this
14 .\" manual under the conditions for verbatim copying, provided that the
15 .\" entire resulting derived work is distributed under the terms of a
16 .\" permission notice identical to this one.
18 .\" Since the Linux kernel and libraries are constantly changing, this
19 .\" manual page may be incorrect or out-of-date. The author(s) assume no
20 .\" responsibility for errors or omissions, or for damages resulting from
21 .\" the use of the information contained herein. The author(s) may not
22 .\" have taken the same level of care in the production of this manual,
23 .\" which is licensed free of charge, as they might when working
26 .\" Formatted or processed versions of this manual, if unaccompanied by
27 .\" the source, must acknowledge the copyright and authors of this work.
30 .TH STATX 2 2021-08-27 "Linux" "Linux Programmer's Manual"
32 statx \- get file status (extended)
35 .BR "#include <fcntl.h> " "/* Definition of " AT_* " constants */"
36 .B #include <sys/stat.h>
38 .BI "int statx(int " dirfd ", const char *restrict " pathname ", int " flags ,
39 .BI " unsigned int " mask ", struct statx *restrict " statxbuf );
42 This function returns information about a file, storing it in the buffer
45 The returned buffer is a structure of the following type:
50 __u32 stx_mask; /* Mask of bits indicating
52 __u32 stx_blksize; /* Block size for filesystem I/O */
53 __u64 stx_attributes; /* Extra file attribute indicators */
54 __u32 stx_nlink; /* Number of hard links */
55 __u32 stx_uid; /* User ID of owner */
56 __u32 stx_gid; /* Group ID of owner */
57 __u16 stx_mode; /* File type and mode */
58 __u64 stx_ino; /* Inode number */
59 __u64 stx_size; /* Total size in bytes */
60 __u64 stx_blocks; /* Number of 512B blocks allocated */
61 __u64 stx_attributes_mask;
62 /* Mask to show what\(aqs supported
65 /* The following fields are file timestamps */
66 struct statx_timestamp stx_atime; /* Last access */
67 struct statx_timestamp stx_btime; /* Creation */
68 struct statx_timestamp stx_ctime; /* Last status change */
69 struct statx_timestamp stx_mtime; /* Last modification */
71 /* If this file represents a device, then the next two
72 fields contain the ID of the device */
73 __u32 stx_rdev_major; /* Major ID */
74 __u32 stx_rdev_minor; /* Minor ID */
76 /* The next two fields contain the ID of the device
77 containing the filesystem where the file resides */
78 __u32 stx_dev_major; /* Major ID */
79 __u32 stx_dev_minor; /* Minor ID */
80 __u64 stx_mnt_id; /* Mount ID */
85 The file timestamps are structures of the following type:
89 struct statx_timestamp {
90 __s64 tv_sec; /* Seconds since the Epoch (UNIX time) */
91 __u32 tv_nsec; /* Nanoseconds since tv_sec */
96 (Note that reserved space and padding is omitted.)
98 Invoking \fBstatx\fR():
99 To access a file's status, no permissions are required on the file itself,
103 execute (search) permission is required on all of the directories in
105 that lead to the file.
113 to identify the target file in one of the following ways:
119 then it is an absolute pathname that identifies the target file.
127 is a string that begins with a character other than a slash and
133 is a relative pathname that is interpreted relative to the process's
134 current working directory.
136 A directory-relative pathname
139 is a string that begins with a character other than a slash and
141 is a file descriptor that refers to a directory, then
143 is a relative pathname that is interpreted relative to the directory
148 for an explanation of why this is useful.)
153 is an empty string and the
158 then the target file is the one referred to by the file descriptor
162 can be used to influence a pathname-based lookup.
165 is constructed by ORing together zero or more of the following constants:
168 .\" commit 65cfc6722361570bfe255698d9cd4dccaf47570d
171 is an empty string, operate on the file referred to by
173 (which may have been obtained using the
179 can refer to any type of file, not just a directory.
185 the call operates on the current working directory.
187 This flag is Linux-specific; define
189 .\" Before glibc 2.16, defining _ATFILE_SOURCE sufficed
190 to obtain its definition.
193 Don't automount the terminal ("basename") component of
195 if it is a directory that is an automount point.
196 This allows the caller to gather attributes of an automount point
197 (rather than the location it would mount).
198 This flag can be used in tools that scan directories
199 to prevent mass-automounting of a directory of automount points.
202 flag has no effect if the mount point has already been mounted over.
203 This flag is Linux-specific; define
205 .\" Before glibc 2.16, defining _ATFILE_SOURCE sufficed
206 to obtain its definition.
208 .B AT_SYMLINK_NOFOLLOW
211 is a symbolic link, do not dereference it:
212 instead return information about the link itself, like
216 can also be used to control what sort of synchronization the kernel will do
217 when querying a file on a remote filesystem.
218 This is done by ORing in one of the following values:
220 .B AT_STATX_SYNC_AS_STAT
224 This is the default and is very much filesystem-specific.
226 .B AT_STATX_FORCE_SYNC
227 Force the attributes to be synchronized with the server.
228 This may require that
229 a network filesystem perform a data writeback to get the timestamps correct.
231 .B AT_STATX_DONT_SYNC
232 Don't synchronize anything, but rather just take whatever
233 the system has cached if possible.
234 This may mean that the information returned is approximate, but,
235 on a network filesystem, it may not involve a round trip to the server - even
242 is used to tell the kernel which fields the caller is interested in.
244 is an ORed combination of the following constants:
249 STATX_TYPE Want stx_mode & S_IFMT
250 STATX_MODE Want stx_mode & \(tiS_IFMT
251 STATX_NLINK Want stx_nlink
252 STATX_UID Want stx_uid
253 STATX_GID Want stx_gid
254 STATX_ATIME Want stx_atime
255 STATX_MTIME Want stx_mtime
256 STATX_CTIME Want stx_ctime
257 STATX_INO Want stx_ino
258 STATX_SIZE Want stx_size
259 STATX_BLOCKS Want stx_blocks
260 STATX_BASIC_STATS [All of the above]
261 STATX_BTIME Want stx_btime
262 STATX_MNT_ID Want stx_mnt_id (since Linux 5.8)
263 STATX_ALL [All currently available fields]
267 Note that, in general, the kernel does
271 other than the above.
272 (For an exception, see
275 Instead, it simply informs the caller which values are supported
276 by this kernel and filesystem via the
286 as one or more bits may, in the future, be used to specify an
287 extension to the buffer.
289 The returned information
290 The status information for the target file is returned in the
292 structure pointed to by
296 which indicates what other information has been returned.
298 has the same format as the
300 argument and bits are set in it to indicate
301 which fields have been filled in.
303 It should be noted that the kernel may return fields that weren't
304 requested and may fail to return fields that were requested,
305 depending on what the backing filesystem supports.
306 (Fields that are given values despite being unrequested can just be ignored.)
312 If a filesystem does not support a field or if it has
313 an unrepresentable value (for instance, a file with an exotic type),
314 then the mask bit corresponding to that field will be cleared in
316 even if the user asked for it and a dummy value will be filled in for
317 compatibility purposes if one is available (e.g., a dummy UID and GID may be
318 specified to mount under some circumstances).
320 A filesystem may also fill in fields that the caller didn't ask for if it has
321 values for them available and the information is available at no extra cost.
322 If this happens, the corresponding bits will be set in
325 .\" Background: inode attributes are modified with i_mutex held, but
326 .\" read by stat() without taking the mutex.
328 for performance and simplicity reasons, different fields in the
330 structure may contain state information from different moments
331 during the execution of the system call.
336 is changed by another process by calling
343 together with the new
347 together with the new
352 (which is described above), the fields in the
357 The "preferred" block size for efficient filesystem I/O.
358 (Writing to a file in
359 smaller chunks may cause an inefficient read-modify-rewrite.)
362 Further status information about the file (see below for more information).
365 The number of hard links on a file.
368 This field contains the user ID of the owner of the file.
371 This field contains the ID of the group owner of the file.
374 The file type and mode.
380 The inode number of the file.
383 The size of the file (if it is a regular file or a symbolic link) in bytes.
384 The size of a symbolic link is the length of the pathname it contains,
385 without a terminating null byte.
388 The number of blocks allocated to the file on the medium, in 512-byte units.
389 (This may be smaller than
391 when the file has holes.)
393 .I stx_attributes_mask
394 A mask indicating which bits in
396 are supported by the VFS and the filesystem.
399 The file's last access timestamp.
402 The file's creation timestamp.
405 The file's last status change timestamp.
408 The file's last modification timestamp.
410 .IR stx_dev_major " and " stx_dev_minor
411 The device on which this file (inode) resides.
413 .IR stx_rdev_major " and " stx_rdev_minor
414 The device that this file (inode) represents if the file is of block or
415 character device type.
418 .\" commit fa2fcf4f1df1559a0a4ee0f46915b496cc2ebf60
419 The mount ID of the mount containing the file.
420 This is the same number reported by
421 .BR name_to_handle_at (2)
422 and corresponds to the number in the first field in one of the records in
423 .IR /proc/self/mountinfo .
425 For further information on the above fields, see
431 field contains a set of ORed flags that indicate additional attributes
433 Note that any attribute that is not indicated as supported by
434 .I stx_attributes_mask
435 has no usable value here.
437 .I stx_attributes_mask
438 correspond bit-by-bit to
441 The flags are as follows:
443 .B STATX_ATTR_COMPRESSED
444 The file is compressed by the filesystem and may take extra resources
447 .B STATX_ATTR_IMMUTABLE
448 The file cannot be modified: it cannot be deleted or renamed,
449 no hard links can be created to this file and no data can be written to it.
454 The file can only be opened in append mode for writing.
455 Random access writing
461 File is not a candidate for backup when a backup program such as
467 .B STATX_ATTR_ENCRYPTED
468 A key is required for the file to be encrypted by the filesystem.
470 .BR STATX_ATTR_VERITY " (since Linux 5.5)"
471 .\" commit 3ad2522c64cff1f5aebb987b00683268f0cc7c29
472 The file has fs-verity enabled.
473 It cannot be written to, and all reads from it will be verified
474 against a cryptographic hash that covers the
475 entire file (e.g., via a Merkle tree).
477 .BR STATX_ATTR_DAX " (since Linux 5.8)"
478 The file is in the DAX (cpu direct access) state.
479 DAX state attempts to
480 minimize software cache effects for both I/O and memory mappings of this file.
481 It requires a file system which has been configured to support DAX.
483 DAX generally assumes all accesses are via CPU load / store instructions
484 which can minimize overhead for small accesses,
485 but may adversely affect CPU utilization for large transfers.
487 File I/O is done directly to/from user-space buffers and memory mapped I/O may
488 be performed with direct memory mappings that bypass the kernel page cache.
490 While the DAX property tends to result in data being transferred synchronously,
491 it does not give the same guarantees as the
495 where data and the necessary metadata are transferred together.
497 A DAX file may support being mapped with the
499 flag, which enables a
500 program to use CPU cache flush instructions to persist CPU store operations
505 for more information.
507 On success, zero is returned.
508 On error, \-1 is returned, and
510 is set to indicate the error.
514 Search permission is denied for one of the directories
515 in the path prefix of
518 .BR path_resolution (7).)
526 nor a valid file descriptor.
532 is NULL or points to a location outside the process's
533 accessible address space.
536 Invalid flag specified in
540 Reserved flag specified in
542 (Currently, there is one such flag, designated by the constant
543 .BR STATX__RESERVED ,
544 with the value 0x80000000U.)
547 Too many symbolic links encountered while traversing the pathname.
558 is an empty string and
564 Out of memory (i.e., kernel memory).
567 A component of the path prefix of
569 is not a directory or
573 is a file descriptor referring to a file other than a directory.
576 was added to Linux in kernel 4.11; library support was added in glibc 2.28.
586 .BR name_to_handle_at (2),
591 .BR capabilities (7),