1 .\" Copyright (c) 1980, 1991, 1993, 1994
2 .\" The Regents of the University of California. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
12 .\" 3. Neither the name of the University nor the names of its contributors
13 .\" may be used to endorse or promote products derived from this software
14 .\" without specific prior written permission.
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 .\" @(#)stat.2 8.4 (Berkeley) 5/1/95
31 .Dd September 23, 2020
45 .Fn stat "const char * restrict path" "struct stat * restrict sb"
47 .Fn lstat "const char * restrict path" "struct stat * restrict sb"
49 .Fn fstat "int fd" "struct stat *sb"
51 .Fn fstatat "int fd" "const char *path" "struct stat *sb" "int flag"
55 system call obtains information about the file pointed to by
57 Read, write or execute
58 permission of the named file is not required, but all directories
59 listed in the path name leading to the file must be searchable.
65 except when the named file is a symbolic link,
68 returns information about the link,
71 returns information about the file the link references.
75 system call obtains the same information about an open file
76 known by the file descriptor
81 system call is equivalent to
87 specifies a relative path, or the
94 the status is retrieved from a file relative to
95 the directory associated with the file descriptor
97 instead of the current working directory.
102 the status is retrieved from a file specified by the
104 but additional permission checks are performed, see below.
108 are constructed by a bitwise-inclusive OR of flags from this list,
111 .Bl -tag -width indent
112 .It Dv AT_SYMLINK_NOFOLLOW
115 names a symbolic link, the status of the symbolic link is returned.
117 Only stat files and directories below the topping directory.
118 See the description of the
123 .It Dv AT_RESOLVE_BENEATH
124 Only walks paths below the topping directory.
125 See the description of the
126 .Dv O_RESOLVE_BENEATH
134 is passed the special value
138 parameter, the current working directory is used and the behavior is
139 identical to a call to
143 respectively, depending on whether or not the
144 .Dv AT_SYMLINK_NOFOLLOW
150 is called with an absolute
159 is specified with an absolute
161 a directory passed by the
163 argument is used as the topping point for the resolution.
167 argument is a pointer to a
172 and into which information is placed concerning the file.
176 related to the file system are:
177 .Bl -tag -width ".Va st_nlink"
179 Numeric ID of the device containing the file.
181 The file's inode number.
183 Number of hard links to the file.
185 Flags enabled for the file.
188 for the list of flags and their description.
195 fields together identify the file uniquely within the system.
197 The time-related fields of
200 .Bl -tag -width ".Va st_birthtim"
202 Time when file data was last accessed.
203 Changed implicitly by syscalls such as
210 Time when file data was last modified.
211 Changed implicitly by syscalls such as
218 Also, any syscall which modifies directory content changes the
220 for the affected directory.
229 Time when file status was last changed (inode data modification).
230 Changed implicitly by any syscall that affects file metadata, including
240 Also, any syscall which modifies directory content changes the
242 for the affected directory.
251 Time when the inode was created.
254 These time-related macros are defined for compatibility:
256 #define st_atime st_atim.tv_sec
257 #define st_mtime st_mtim.tv_sec
258 #define st_ctime st_ctim.tv_sec
259 #ifndef _POSIX_SOURCE
260 #define st_birthtime st_birthtim.tv_sec
263 #ifndef _POSIX_SOURCE
264 #define st_atimespec st_atim
265 #define st_mtimespec st_mtim
266 #define st_ctimespec st_ctim
267 #define st_birthtimespec st_birthtim
271 Size-related fields of the
274 .Bl -tag -width ".Va st_blksize"
278 Optimal I/O block size for the file.
280 Actual number of blocks allocated for the file in 512-byte units.
281 As short symbolic links are stored in the inode, this number may
285 The access-related fields of
288 .Bl -tag -width ".Va st_mode"
290 User ID of the file's owner.
292 Group ID of the file.
294 Status of the file (see below).
297 The status information word
301 #define S_IFMT 0170000 /* type of file mask */
302 #define S_IFIFO 0010000 /* named pipe (fifo) */
303 #define S_IFCHR 0020000 /* character special */
304 #define S_IFDIR 0040000 /* directory */
305 #define S_IFBLK 0060000 /* block special */
306 #define S_IFREG 0100000 /* regular */
307 #define S_IFLNK 0120000 /* symbolic link */
308 #define S_IFSOCK 0140000 /* socket */
309 #define S_IFWHT 0160000 /* whiteout */
310 #define S_ISUID 0004000 /* set user id on execution */
311 #define S_ISGID 0002000 /* set group id on execution */
312 #define S_ISVTX 0001000 /* save swapped text even after use */
313 #define S_IRWXU 0000700 /* RWX mask for owner */
314 #define S_IRUSR 0000400 /* read permission, owner */
315 #define S_IWUSR 0000200 /* write permission, owner */
316 #define S_IXUSR 0000100 /* execute/search permission, owner */
317 #define S_IRWXG 0000070 /* RWX mask for group */
318 #define S_IRGRP 0000040 /* read permission, group */
319 #define S_IWGRP 0000020 /* write permission, group */
320 #define S_IXGRP 0000010 /* execute/search permission, group */
321 #define S_IRWXO 0000007 /* RWX mask for other */
322 #define S_IROTH 0000004 /* read permission, other */
323 #define S_IWOTH 0000002 /* write permission, other */
324 #define S_IXOTH 0000001 /* execute/search permission, other */
327 For a list of access modes, see
332 These macros are available to test whether a
336 argument corresponds to a file of the specified type:
337 .Bl -tag -width ".Fn S_ISFIFO m"
339 Test for a block special file.
341 Test for a character special file.
343 Test for a directory.
345 Test for a pipe or FIFO special file.
347 Test for a symbolic link.
349 Test for a regular file.
356 The macros evaluate to a non-zero value if the test is true
357 or to the value 0 if the test is false.
361 Previous versions of the system used different types for the
376 system calls will fail if:
379 Search permission is denied for a component of the path prefix.
386 points to an invalid address.
388 An I/O error occurred while reading from or writing to the file system.
390 Corrupted data was detected while reading from the file system.
392 Too many symbolic links were encountered in translating the pathname.
393 .It Bq Er ENAMETOOLONG
394 A component of a pathname exceeded 255 characters,
395 or an entire path name exceeded 1023 characters.
397 The named file does not exist.
399 A component of the path prefix is not a directory.
401 The file size in bytes cannot be
402 represented correctly in the structure pointed to by
408 system call will fail if:
414 is not a valid open file descriptor.
419 points to an invalid address.
421 An I/O error occurred while reading from or writing to the file system.
423 Corrupted data was detected while reading from the file system.
425 The file size in bytes cannot be
426 represented correctly in the structure pointed to by
430 In addition to the errors returned by the
439 argument does not specify an absolute path and the
443 nor a valid file descriptor open for searching.
447 argument is not valid.
451 argument is not an absolute path and
455 nor a file descriptor associated with a directory.
456 .It Bq Er ENOTCAPABLE
459 or contained a ".." component leading to a
460 directory outside of the directory hierarchy specified by
462 and the process is in capability mode.
463 .It Bq Er ENOTCAPABLE
470 does not have its tail fully contained under the topping directory,
489 system calls are expected to conform to
493 system call follows The Open Group Extended API Set 2 specification.
499 system calls appeared in
503 system call appeared in
507 system call appeared in
513 returns a zeroed buffer,
514 except for the blocksize field,
515 and a unique device and inode number.