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