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