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