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