1STATX(2) Linux Programmer's Manual STATX(2)
2
3
4
6 statx - get file status (extended)
7
9 #include <sys/types.h>
10 #include <sys/stat.h>
11 #include <unistd.h>
12 #include <fcntl.h> /* Definition of AT_* constants */
13
14 int statx(int dirfd, const char *pathname, int flags,
15 unsigned int mask, struct statx *statxbuf);
16
17 Note: There is no glibc wrapper for statx(); see NOTES.
18
20 This function returns information about a file, storing it in the buf‐
21 fer pointed to by statxbuf. The returned buffer is a structure of the
22 following type:
23
24 struct statx {
25 __u32 stx_mask; /* Mask of bits indicating
26 filled fields */
27 __u32 stx_blksize; /* Block size for filesystem I/O */
28 __u64 stx_attributes; /* Extra file attribute indicators */
29 __u32 stx_nlink; /* Number of hard links */
30 __u32 stx_uid; /* User ID of owner */
31 __u32 stx_gid; /* Group ID of owner */
32 __u16 stx_mode; /* File type and mode */
33 __u64 stx_ino; /* Inode number */
34 __u64 stx_size; /* Total size in bytes */
35 __u64 stx_blocks; /* Number of 512B blocks allocated */
36 __u64 stx_attributes_mask;
37 /* Mask to show what's supported
38 in stx_attributes */
39
40 /* The following fields are file timestamps */
41 struct statx_timestamp stx_atime; /* Last access */
42 struct statx_timestamp stx_btime; /* Creation */
43 struct statx_timestamp stx_ctime; /* Last status change */
44 struct statx_timestamp stx_mtime; /* Last modification */
45
46 /* If this file represents a device, then the next two
47 fields contain the ID of the device */
48 __u32 stx_rdev_major; /* Major ID */
49 __u32 stx_rdev_minor; /* Minor ID */
50
51 /* The next two fields contain the ID of the device
52 containing the filesystem where the file resides */
53 __u32 stx_dev_major; /* Major ID */
54 __u32 stx_dev_minor; /* Minor ID */
55 };
56
57 The file timestamps are structures of the following type:
58
59 struct statx_timestamp {
60 __s64 tv_sec; /* Seconds since the Epoch (UNIX time) */
61 __u32 tv_nsec; /* Nanoseconds since tv_sec */
62 };
63
64 (Note that reserved space and padding is omitted.)
65
66 Invoking statx():
67 To access a file's status, no permissions are required on the file
68 itself, but in the case of statx() with a pathname, execute (search)
69 permission is required on all of the directories in pathname that lead
70 to the file.
71
72 statx() uses pathname, dirfd, and flags to identify the target file in
73 one of the following ways:
74
75 An absolute pathname
76 If pathname begins with a slash, then it is an absolute pathname
77 that identifies the target file. In this case, dirfd is
78 ignored.
79
80 A relative pathname
81 If pathname is a string that begins with a character other than
82 a slash and dirfd is AT_FDCWD, then pathname is a relative path‐
83 name that is interpreted relative to the process's current work‐
84 ing directory.
85
86 A directory-relative pathname
87 If pathname is a string that begins with a character other than
88 a slash and dirfd is a file descriptor that refers to a direc‐
89 tory, then pathname is a relative pathname that is interpreted
90 relative to the directory referred to by dirfd.
91
92 By file descriptor
93 If pathname is an empty string and the AT_EMPTY_PATH flag is
94 specified in flags (see below), then the target file is the one
95 referred to by the file descriptor dirfd.
96
97 flags can be used to influence a pathname-based lookup. A value for
98 flags is constructed by ORing together zero or more of the following
99 constants:
100
101 AT_EMPTY_PATH
102 If pathname is an empty string, operate on the file referred to
103 by dirfd (which may have been obtained using the open(2) O_PATH
104 flag). In this case, dirfd can refer to any type of file, not
105 just a directory.
106
107 If dirfd is AT_FDCWD, the call operates on the current working
108 directory.
109
110 This flag is Linux-specific; define _GNU_SOURCE to obtain its
111 definition.
112
113 AT_NO_AUTOMOUNT
114 Don't automount the terminal ("basename") component of pathname
115 if it is a directory that is an automount point. This allows
116 the caller to gather attributes of an automount point (rather
117 than the location it would mount). This flag can be used in
118 tools that scan directories to prevent mass-automounting of a
119 directory of automount points. The AT_NO_AUTOMOUNT flag has no
120 effect if the mount point has already been mounted over. This
121 flag is Linux-specific; define _GNU_SOURCE to obtain its defini‐
122 tion.
123
124 AT_SYMLINK_NOFOLLOW
125 If pathname is a symbolic link, do not dereference it: instead
126 return information about the link itself, like lstat(2).
127
128 flags can also be used to control what sort of synchronization the ker‐
129 nel will do when querying a file on a remote filesystem. This is done
130 by ORing in one of the following values:
131
132 AT_STATX_SYNC_AS_STAT
133 Do whatever stat(2) does. This is the default and is very much
134 filesystem-specific.
135
136 AT_STATX_FORCE_SYNC
137 Force the attributes to be synchronized with the server. This
138 may require that a network filesystem perform a data writeback
139 to get the timestamps correct.
140
141 AT_STATX_DONT_SYNC
142 Don't synchronize anything, but rather just take whatever the
143 system has cached if possible. This may mean that the informa‐
144 tion returned is approximate, but, on a network filesystem, it
145 may not involve a round trip to the server - even if no lease is
146 held.
147
148 The mask argument to statx() is used to tell the kernel which fields
149 the caller is interested in. mask is an ORed combination of the fol‐
150 lowing constants:
151
152 STATX_TYPE Want stx_mode & S_IFMT
153 STATX_MODE Want stx_mode & ~S_IFMT
154 STATX_NLINK Want stx_nlink
155 STATX_UID Want stx_uid
156 STATX_GID Want stx_gid
157 STATX_ATIME Want stx_atime
158 STATX_MTIME Want stx_mtime
159 STATX_CTIME Want stx_ctime
160 STATX_INO Want stx_ino
161 STATX_SIZE Want stx_size
162 STATX_BLOCKS Want stx_blocks
163 STATX_BASIC_STATS [All of the above]
164 STATX_BTIME Want stx_btime
165 STATX_ALL [All currently available fields]
166
167 Note that the kernel does not reject values in mask other than the
168 above. Instead, it simply informs the caller which values are sup‐
169 ported by this kernel and filesystem via the statx.stx_mask field.
170 Therefore, do not simply set mask to UINT_MAX (all bits set), as one or
171 more bits may, in the future, be used to specify an extension to the
172 buffer.
173
174 The returned information
175 The status information for the target file is returned in the statx
176 structure pointed to by statxbuf. Included in this is stx_mask which
177 indicates what other information has been returned. stx_mask has the
178 same format as the mask argument and bits are set in it to indicate
179 which fields have been filled in.
180
181 It should be noted that the kernel may return fields that weren't
182 requested and may fail to return fields that were requested, depending
183 on what the backing filesystem supports. (Fields that are given values
184 despite being unrequested can just be ignored.) In either case,
185 stx_mask will not be equal mask.
186
187 If a filesystem does not support a field or if it has an unrepre‐
188 sentable value (for instance, a file with an exotic type), then the
189 mask bit corresponding to that field will be cleared in stx_mask even
190 if the user asked for it and a dummy value will be filled in for com‐
191 patibility purposes if one is available (e.g., a dummy UID and GID may
192 be specified to mount under some circumstances).
193
194 A filesystem may also fill in fields that the caller didn't ask for if
195 it has values for them available and the information is available at no
196 extra cost. If this happens, the corresponding bits will be set in
197 stx_mask.
198
199 Note: for performance and simplicity reasons, different fields in the
200 statx structure may contain state information from different moments
201 during the execution of the system call. For example, if stx_mode or
202 stx_uid is changed by another process by calling chmod(2) or chown(2),
203 stat() might return the old stx_mode together with the new stx_uid, or
204 the old stx_uid together with the new stx_mode.
205
206 Apart from stx_mask (which is described above), the fields in the statx
207 structure are:
208
209 stx_blksize
210 The "preferred" block size for efficient filesystem I/O. (Writ‐
211 ing to a file in smaller chunks may cause an inefficient read-
212 modify-rewrite.)
213
214 stx_attributes
215 Further status information about the file (see below for more
216 information).
217
218 stx_nlink
219 The number of hard links on a file.
220
221 stx_uid
222 This field contains the user ID of the owner of the file.
223
224 stx_gid
225 This field contains the ID of the group owner of the file.
226
227 stx_mode
228 The file type and mode. See inode(7) for details.
229
230 stx_ino
231 The inode number of the file.
232
233 stx_size
234 The size of the file (if it is a regular file or a symbolic
235 link) in bytes. The size of a symbolic link is the length of
236 the pathname it contains, without a terminating null byte.
237
238 stx_blocks
239 The number of blocks allocated to the file on the medium, in
240 512-byte units. (This may be smaller than stx_size/512 when the
241 file has holes.)
242
243 stx_attributes_mask
244 A mask indicating which bits in stx_attributes are supported by
245 the VFS and the filesystem.
246
247 stx_atime
248 The file's last access timestamp.
249
250 stx_btime
251 The file's creation timestamp.
252
253 stx_ctime
254 The file's last status change timestamp.
255
256 stx_mtime
257 The file's last modification timestamp.
258
259 stx_dev_major and stx_dev_minor
260 The device on which this file (inode) resides.
261
262 stx_rdev_major and stx_rdev_minor
263 The device that this file (inode) represents if the file is of
264 block or character device type.
265
266 For further information on the above fields, see inode(7).
267
268 File attributes
269 The stx_attributes field contains a set of ORed flags that indicate
270 additional attributes of the file. Note that any attribute that is not
271 indicated as supported by stx_attributes_mask has no usable value here.
272 The bits in stx_attributes_mask correspond bit-by-bit to
273 stx_attributes.
274
275 The flags are as follows:
276
277 STATX_ATTR_COMPRESSED
278 The file is compressed by the filesystem and may take extra
279 resources to access.
280
281 STATX_ATTR_IMMUTABLE
282 The file cannot be modified: it cannot be deleted or renamed, no
283 hard links can be created to this file and no data can be writ‐
284 ten to it. See chattr(1).
285
286 STATX_ATTR_APPEND
287 The file can only be opened in append mode for writing. Random
288 access writing is not permitted. See chattr(1).
289
290 STATX_ATTR_NODUMP
291 File is not a candidate for backup when a backup program such as
292 dump(8) is run. See chattr(1).
293
294 STATX_ATTR_ENCRYPTED
295 A key is required for the file to be encrypted by the filesys‐
296 tem.
297
299 On success, zero is returned. On error, -1 is returned, and errno is
300 set appropriately.
301
303 EACCES Search permission is denied for one of the directories in the
304 path prefix of pathname. (See also path_resolution(7).)
305
306 EBADF dirfd is not a valid open file descriptor.
307
308 EFAULT pathname or statxbuf is NULL or points to a location outside the
309 process's accessible address space.
310
311 EINVAL Invalid flag specified in flags.
312
313 EINVAL Reserved flag specified in mask.
314
315 ELOOP Too many symbolic links encountered while traversing the path‐
316 name.
317
318 ENAMETOOLONG
319 pathname is too long.
320
321 ENOENT A component of pathname does not exist, or pathname is an empty
322 string and AT_EMPTY_PATH was not specified in flags.
323
324 ENOMEM Out of memory (i.e., kernel memory).
325
326 ENOTDIR
327 A component of the path prefix of pathname is not a directory or
328 pathname is relative and dirfd is a file descriptor referring to
329 a file other than a directory.
330
332 statx() was added to Linux in kernel 4.11.
333
335 statx() is Linux-specific.
336
338 Glibc does not (yet) provide a wrapper for the statx() system call;
339 call it using syscall(2).
340
342 ls(1), stat(1), access(2), chmod(2), chown(2), readlink(2), stat(2),
343 utime(2), capabilities(7), inode(7), symlink(7)
344
346 This page is part of release 4.15 of the Linux man-pages project. A
347 description of the project, information about reporting bugs, and the
348 latest version of this page, can be found at
349 https://www.kernel.org/doc/man-pages/.
350
351
352
353Linux 2017-09-15 STATX(2)