]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/statx.2
Various pages: [GPL-2.0-only] Use SPDX-License-Identifier
[thirdparty/man-pages.git] / man2 / statx.2
CommitLineData
9905e59b
DH
1.\" Copyright (c) 2017 David Howells <dhowells@redhat.com>
2.\"
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>
7.\"
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.
12.\"
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.
17.\"
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
24.\" professionally.
25.\"
26.\" Formatted or processed versions of this manual, if unaccompanied by
27.\" the source, must acknowledge the copyright and authors of this work.
28.\" %%%LICENSE_END
29.\"
6e00b7a8 30.TH STATX 2 2021-08-27 "Linux" "Linux Programmer's Manual"
9905e59b 31.SH NAME
835f4293 32statx \- get file status (extended)
9905e59b
DH
33.SH SYNOPSIS
34.nf
c9f3f849 35.BR "#include <fcntl.h> " "/* Definition of " AT_* " constants */"
9905e59b 36.B #include <sys/stat.h>
dbfe9c70 37.PP
049d7f92
AC
38.BI "int statx(int " dirfd ", const char *restrict " pathname ", int " flags ,
39.BI " unsigned int " mask ", struct statx *restrict " statxbuf );
9905e59b 40.fi
9905e59b 41.SH DESCRIPTION
9905e59b
DH
42This function returns information about a file, storing it in the buffer
43pointed to by
15d1f5ac 44.IR statxbuf .
c8701baf 45The returned buffer is a structure of the following type:
9905e59b
DH
46.PP
47.in +4n
b8302363 48.EX
9905e59b 49struct statx {
77a09ad7
MK
50 __u32 stx_mask; /* Mask of bits indicating
51 filled fields */
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 */
aabbefb4 61 __u64 stx_attributes_mask;
861d36ba 62 /* Mask to show what\(aqs supported
aabbefb4 63 in stx_attributes */
6a4667aa
MK
64
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 */
70
20c8cd9a
MK
71 /* If this file represents a device, then the next two
72 fields contain the ID of the device */
77a09ad7
MK
73 __u32 stx_rdev_major; /* Major ID */
74 __u32 stx_rdev_minor; /* Minor ID */
6a4667aa
MK
75
76 /* The next two fields contain the ID of the device
790314d7 77 containing the filesystem where the file resides */
77a09ad7
MK
78 __u32 stx_dev_major; /* Major ID */
79 __u32 stx_dev_minor; /* Minor ID */
728009a4 80 __u64 stx_mnt_id; /* Mount ID */
9905e59b 81};
b8302363 82.EE
9905e59b
DH
83.in
84.PP
6a4667aa 85The file timestamps are structures of the following type:
9905e59b
DH
86.PP
87.in +4n
b8302363 88.EX
9905e59b 89struct statx_timestamp {
6a4667aa 90 __s64 tv_sec; /* Seconds since the Epoch (UNIX time) */
aabbefb4 91 __u32 tv_nsec; /* Nanoseconds since tv_sec */
9905e59b 92};
b8302363 93.EE
9905e59b
DH
94.in
95.PP
790314d7 96(Note that reserved space and padding is omitted.)
9905e59b
DH
97.SS
98Invoking \fBstatx\fR():
14b5d02a
MK
99To access a file's status, no permissions are required on the file itself,
100but in the case of
9905e59b 101.BR statx ()
835f4293 102with a pathname,
14b5d02a 103execute (search) permission is required on all of the directories in
9905e59b
DH
104.I pathname
105that lead to the file.
106.PP
107.BR statx ()
108uses
6a4667aa
MK
109.IR pathname ,
110.IR dirfd ,
111and
112.IR flags
56a05af6 113to identify the target file in one of the following ways:
9905e59b 114.TP
7e43caf4
MK
115An absolute pathname
116If
9905e59b 117.I pathname
7e43caf4
MK
118begins with a slash,
119then it is an absolute pathname that identifies the target file.
120In this case,
9905e59b 121.I dirfd
14b5d02a 122is ignored.
9905e59b 123.TP
7e43caf4
MK
124A relative pathname
125If
9905e59b 126.I pathname
7e43caf4 127is a string that begins with a character other than a slash and
6a4667aa
MK
128.IR dirfd
129is
7e43caf4
MK
130.BR AT_FDCWD ,
131then
132.I pathname
133is a relative pathname that is interpreted relative to the process's
134current working directory.
9905e59b 135.TP
aabbefb4 136A directory-relative pathname
7e43caf4 137If
9905e59b 138.I pathname
7e43caf4 139is a string that begins with a character other than a slash and
9905e59b 140.I dirfd
7e43caf4
MK
141is a file descriptor that refers to a directory, then
142.I pathname
143is a relative pathname that is interpreted relative to the directory
144referred to by
9905e59b 145.IR dirfd .
717c3a7d
MK
146(See
147.BR openat (2)
148for an explanation of why this is useful.)
9905e59b 149.TP
7e43caf4
MK
150By file descriptor
151If
77a09ad7 152.IR pathname
85dbf7cd 153is an empty string and the
7e43caf4 154.B AT_EMPTY_PATH
85dbf7cd
MK
155flag is specified in
156.IR flags
157(see below),
158then the target file is the one referred to by the file descriptor
159.IR dirfd .
9905e59b
DH
160.PP
161.I flags
835f4293 162can be used to influence a pathname-based lookup.
14b5d02a 163A value for
9905e59b 164.I flags
c8701baf 165is constructed by ORing together zero or more of the following constants:
9905e59b
DH
166.TP
167.BR AT_EMPTY_PATH
168.\" commit 65cfc6722361570bfe255698d9cd4dccaf47570d
169If
170.I pathname
171is an empty string, operate on the file referred to by
172.IR dirfd
173(which may have been obtained using the
174.BR open (2)
175.B O_PATH
176flag).
85dbf7cd
MK
177In this case,
178.I dirfd
179can refer to any type of file, not just a directory.
efeece04 180.IP
9905e59b
DH
181If
182.I dirfd
183is
184.BR AT_FDCWD ,
185the call operates on the current working directory.
efeece04 186.IP
9905e59b
DH
187This flag is Linux-specific; define
188.B _GNU_SOURCE
189.\" Before glibc 2.16, defining _ATFILE_SOURCE sufficed
190to obtain its definition.
191.TP
192.BR AT_NO_AUTOMOUNT
193Don't automount the terminal ("basename") component of
194.I pathname
195if it is a directory that is an automount point.
196This allows the caller to gather attributes of an automount point
197(rather than the location it would mount).
198This flag can be used in tools that scan directories
199to prevent mass-automounting of a directory of automount points.
200The
201.B AT_NO_AUTOMOUNT
202flag has no effect if the mount point has already been mounted over.
203This flag is Linux-specific; define
204.B _GNU_SOURCE
205.\" Before glibc 2.16, defining _ATFILE_SOURCE sufficed
206to obtain its definition.
207.TP
208.B AT_SYMLINK_NOFOLLOW
209If
210.I pathname
211is a symbolic link, do not dereference it:
212instead return information about the link itself, like
6a4667aa 213.BR lstat (2).
9905e59b
DH
214.PP
215.I flags
14b5d02a
MK
216can also be used to control what sort of synchronization the kernel will do
217when querying a file on a remote filesystem.
c8701baf 218This is done by ORing in one of the following values:
9905e59b 219.TP
709f7bb6 220.B AT_STATX_SYNC_AS_STAT
9905e59b 221Do whatever
6a4667aa 222.BR stat (2)
14b5d02a 223does.
56a05af6 224This is the default and is very much filesystem-specific.
9905e59b 225.TP
709f7bb6 226.B AT_STATX_FORCE_SYNC
46711e96 227Force the attributes to be synchronized with the server.
14b5d02a 228This may require that
9905e59b
DH
229a network filesystem perform a data writeback to get the timestamps correct.
230.TP
709f7bb6 231.B AT_STATX_DONT_SYNC
46711e96 232Don't synchronize anything, but rather just take whatever
ffe297ee 233the system has cached if possible.
14b5d02a 234This may mean that the information returned is approximate, but,
9905e59b
DH
235on a network filesystem, it may not involve a round trip to the server - even
236if no lease is held.
237.PP
238The
239.I mask
240argument to
241.BR statx ()
242is used to tell the kernel which fields the caller is interested in.
243.I mask
c8701baf 244is an ORed combination of the following constants:
9905e59b
DH
245.PP
246.in +4n
247.TS
248lB l.
249STATX_TYPE Want stx_mode & S_IFMT
af2d18b2 250STATX_MODE Want stx_mode & \(tiS_IFMT
9905e59b
DH
251STATX_NLINK Want stx_nlink
252STATX_UID Want stx_uid
253STATX_GID Want stx_gid
f4572b65
MK
254STATX_ATIME Want stx_atime
255STATX_MTIME Want stx_mtime
256STATX_CTIME Want stx_ctime
9905e59b
DH
257STATX_INO Want stx_ino
258STATX_SIZE Want stx_size
259STATX_BLOCKS Want stx_blocks
260STATX_BASIC_STATS [All of the above]
f4572b65 261STATX_BTIME Want stx_btime
728009a4 262STATX_MNT_ID Want stx_mnt_id (since Linux 5.8)
9905e59b
DH
263STATX_ALL [All currently available fields]
264.TE
265.in
266.PP
c031ffcc 267Note that, in general, the kernel does
393c5b58
MK
268.I not
269reject values in
270.I mask
271other than the above.
c031ffcc
MK
272(For an exception, see
273.B EINVAL
274in errors.)
393c5b58
MK
275Instead, it simply informs the caller which values are supported
276by this kernel and filesystem via the
277.I statx.stx_mask
278field.
279Therefore,
280.I "do not"
9905e59b
DH
281simply set
282.I mask
709f7bb6
MK
283to
284.B UINT_MAX
393c5b58 285(all bits set),
709f7bb6 286as one or more bits may, in the future, be used to specify an
9905e59b
DH
287extension to the buffer.
288.SS
289The returned information
9905e59b
DH
290The status information for the target file is returned in the
291.I statx
292structure pointed to by
15d1f5ac 293.IR statxbuf .
9905e59b
DH
294Included in this is
295.I stx_mask
296which indicates what other information has been returned.
297.I stx_mask
790314d7
MK
298has the same format as the
299.I mask
300argument and bits are set in it to indicate
9905e59b
DH
301which fields have been filled in.
302.PP
ffe297ee
MK
303It should be noted that the kernel may return fields that weren't
304requested and may fail to return fields that were requested,
305depending on what the backing filesystem supports.
c859dfb5 306(Fields that are given values despite being unrequested can just be ignored.)
14b5d02a 307In either case,
9905e59b
DH
308.I stx_mask
309will not be equal
310.IR mask .
311.PP
ffe297ee
MK
312If a filesystem does not support a field or if it has
313an unrepresentable value (for instance, a file with an exotic type),
314then the mask bit corresponding to that field will be cleared in
9905e59b
DH
315.I stx_mask
316even if the user asked for it and a dummy value will be filled in for
835f4293 317compatibility purposes if one is available (e.g., a dummy UID and GID may be
9905e59b
DH
318specified to mount under some circumstances).
319.PP
320A filesystem may also fill in fields that the caller didn't ask for if it has
835f4293 321values for them available and the information is available at no extra cost.
14b5d02a 322If this happens, the corresponding bits will be set in
9905e59b
DH
323.IR stx_mask .
324.PP
9905e59b
DH
325.\" Background: inode attributes are modified with i_mutex held, but
326.\" read by stat() without taking the mutex.
835f4293
MK
327.IR Note :
328for performance and simplicity reasons, different fields in the
9905e59b
DH
329.I statx
330structure may contain state information from different moments
331during the execution of the system call.
332For example, if
333.IR stx_mode
334or
335.IR stx_uid
336is changed by another process by calling
337.BR chmod (2)
338or
339.BR chown (2),
340.BR stat ()
341might return the old
342.I stx_mode
343together with the new
344.IR stx_uid ,
345or the old
346.I stx_uid
347together with the new
348.IR stx_mode .
349.PP
77a09ad7
MK
350Apart from
351.I stx_mask
352(which is described above), the fields in the
9905e59b
DH
353.I statx
354structure are:
355.TP
13470fd3
MK
356.I stx_blksize
357The "preferred" block size for efficient filesystem I/O.
358(Writing to a file in
359smaller chunks may cause an inefficient read-modify-rewrite.)
360.TP
361.I stx_attributes
362Further status information about the file (see below for more information).
363.TP
364.I stx_nlink
365The number of hard links on a file.
366.TP
367.I stx_uid
368This field contains the user ID of the owner of the file.
369.TP
370.I stx_gid
371This field contains the ID of the group owner of the file.
aabbefb4 372.TP
9905e59b 373.I stx_mode
14b5d02a 374The file type and mode.
19cda35d
MK
375See
376.BR inode (7)
377for details.
9905e59b 378.TP
fc31d730
MK
379.I stx_ino
380The inode number of the file.
381.TP
9905e59b
DH
382.I stx_size
383The size of the file (if it is a regular file or a symbolic link) in bytes.
ffe297ee
MK
384The size of a symbolic link is the length of the pathname it contains,
385without a terminating null byte.
9905e59b
DH
386.TP
387.I stx_blocks
388The number of blocks allocated to the file on the medium, in 512-byte units.
389(This may be smaller than
390.IR stx_size /512
391when the file has holes.)
392.TP
13470fd3
MK
393.I stx_attributes_mask
394A mask indicating which bits in
395.IR stx_attributes
396are supported by the VFS and the filesystem.
9905e59b
DH
397.TP
398.I stx_atime
399The file's last access timestamp.
9905e59b
DH
400.TP
401.I stx_btime
14b5d02a 402The file's creation timestamp.
9905e59b
DH
403.TP
404.I stx_ctime
14b5d02a 405The file's last status change timestamp.
9905e59b
DH
406.TP
407.I stx_mtime
14b5d02a 408The file's last modification timestamp.
13470fd3
MK
409.TP
410.IR stx_dev_major " and " stx_dev_minor
411The device on which this file (inode) resides.
412.TP
413.IR stx_rdev_major " and " stx_rdev_minor
414The device that this file (inode) represents if the file is of block or
415character device type.
728009a4
N
416.TP
417.I stx_mnt_id
418.\" commit fa2fcf4f1df1559a0a4ee0f46915b496cc2ebf60
053132a8
MK
419The mount ID of the mount containing the file.
420This is the same number reported by
728009a4
N
421.BR name_to_handle_at (2)
422and corresponds to the number in the first field in one of the records in
423.IR /proc/self/mountinfo .
9905e59b 424.PP
19cda35d
MK
425For further information on the above fields, see
426.BR inode (7).
14b5d02a 427.\"
9905e59b 428.SS File attributes
9905e59b
DH
429The
430.I stx_attributes
c8701baf 431field contains a set of ORed flags that indicate additional attributes
aabbefb4
MK
432of the file.
433Note that any attribute that is not indicated as supported by
434.I stx_attributes_mask
435has no usable value here.
436The bits in
437.I stx_attributes_mask
438correspond bit-by-bit to
439.IR stx_attributes .
efeece04 440.PP
aabbefb4 441The flags are as follows:
9905e59b 442.TP
77a09ad7 443.B STATX_ATTR_COMPRESSED
56a05af6
MK
444The file is compressed by the filesystem and may take extra resources
445to access.
9905e59b 446.TP
77a09ad7 447.B STATX_ATTR_IMMUTABLE
ffe297ee
MK
448The file cannot be modified: it cannot be deleted or renamed,
449no hard links can be created to this file and no data can be written to it.
709f7bb6
MK
450See
451.BR chattr (1).
9905e59b 452.TP
77a09ad7 453.B STATX_ATTR_APPEND
14b5d02a
MK
454The file can only be opened in append mode for writing.
455Random access writing
456is not permitted.
709f7bb6
MK
457See
458.BR chattr (1).
9905e59b 459.TP
77a09ad7 460.B STATX_ATTR_NODUMP
709f7bb6
MK
461File is not a candidate for backup when a backup program such as
462.BR dump (8)
463is run.
464See
465.BR chattr (1).
9905e59b 466.TP
77a09ad7 467.B STATX_ATTR_ENCRYPTED
9905e59b 468A key is required for the file to be encrypted by the filesystem.
ba2a5200 469.TP
c436f71f
MK
470.BR STATX_ATTR_VERITY " (since Linux 5.5)"
471.\" commit 3ad2522c64cff1f5aebb987b00683268f0cc7c29
472The file has fs-verity enabled.
473It cannot be written to, and all reads from it will be verified
474against a cryptographic hash that covers the
475entire file (e.g., via a Merkle tree).
38ad6a88 476.TP
2e335632 477.BR STATX_ATTR_DAX " (since Linux 5.8)"
c9e6c5ab
MK
478The file is in the DAX (cpu direct access) state.
479DAX state attempts to
38ad6a88
IW
480minimize software cache effects for both I/O and memory mappings of this file.
481It requires a file system which has been configured to support DAX.
2e335632 482.IP
c9e6c5ab
MK
483DAX generally assumes all accesses are via CPU load / store instructions
484which can minimize overhead for small accesses,
485but may adversely affect CPU utilization for large transfers.
2e335632 486.IP
38ad6a88 487File I/O is done directly to/from user-space buffers and memory mapped I/O may
c9e6c5ab 488be performed with direct memory mappings that bypass the kernel page cache.
2e335632 489.IP
38ad6a88 490While the DAX property tends to result in data being transferred synchronously,
c9e6c5ab
MK
491it does not give the same guarantees as the
492.B O_SYNC
493flag (see
494.BR open (2)),
495where data and the necessary metadata are transferred together.
2e335632 496.IP
c9e6c5ab
MK
497A DAX file may support being mapped with the
498.B MAP_SYNC
499flag, which enables a
38ad6a88
IW
500program to use CPU cache flush instructions to persist CPU store operations
501without an explicit
c9e6c5ab 502.BR fsync (2).
38ad6a88 503See
c9e6c5ab 504.BR mmap (2)
38ad6a88 505for more information.
9905e59b
DH
506.SH RETURN VALUE
507On success, zero is returned.
508On error, \-1 is returned, and
509.I errno
f6a4078b 510is set to indicate the error.
9905e59b
DH
511.SH ERRORS
512.TP
9905e59b
DH
513.B EACCES
514Search permission is denied for one of the directories
515in the path prefix of
516.IR pathname .
517(See also
518.BR path_resolution (7).)
519.TP
520.B EBADF
9f4e736a
MK
521.I pathname
522is relative but
9905e59b 523.I dirfd
9f4e736a
MK
524is neither
525.B AT_FDCWD
526nor a valid file descriptor.
9905e59b
DH
527.TP
528.B EFAULT
09ff9f4a
MK
529.I pathname
530or
15d1f5ac 531.I statxbuf
09ff9f4a
MK
532is NULL or points to a location outside the process's
533accessible address space.
9905e59b 534.TP
1b206bd8
MK
535.B EINVAL
536Invalid flag specified in
537.IR flags .
538.TP
aabbefb4
MK
539.B EINVAL
540Reserved flag specified in
541.IR mask .
c031ffcc
MK
542(Currently, there is one such flag, designated by the constant
543.BR STATX__RESERVED ,
544with the value 0x80000000U.)
aabbefb4 545.TP
9905e59b 546.B ELOOP
835f4293 547Too many symbolic links encountered while traversing the pathname.
9905e59b
DH
548.TP
549.B ENAMETOOLONG
550.I pathname
551is too long.
552.TP
553.B ENOENT
554A component of
555.I pathname
556does not exist, or
557.I pathname
c8701baf
MK
558is an empty string and
559.B AT_EMPTY_PATH
560was not specified in
561.IR flags .
9905e59b
DH
562.TP
563.B ENOMEM
564Out of memory (i.e., kernel memory).
565.TP
566.B ENOTDIR
567A component of the path prefix of
568.I pathname
569is not a directory or
570.I pathname
571is relative and
572.I dirfd
573is a file descriptor referring to a file other than a directory.
574.SH VERSIONS
575.BR statx ()
e06763fe 576was added to Linux in kernel 4.11; library support was added in glibc 2.28.
7a192d0d
MK
577.SH CONFORMING TO
578.BR statx ()
56a05af6 579is Linux-specific.
9905e59b
DH
580.SH SEE ALSO
581.BR ls (1),
582.BR stat (1),
583.BR access (2),
584.BR chmod (2),
585.BR chown (2),
728009a4 586.BR name_to_handle_at (2),
9905e59b 587.BR readlink (2),
6edadda6 588.BR stat (2),
9905e59b 589.BR utime (2),
728009a4 590.BR proc (5),
9905e59b 591.BR capabilities (7),
3b363b62 592.BR inode (7),
9905e59b 593.BR symlink (7)