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
44 .Fn stat "const char * restrict path" "struct stat * restrict sb"
46 .Fn lstat "const char * restrict path" "struct stat * restrict sb"
48 .Fn fstat "int fd" "struct stat *sb"
50 .Fn fstatat "int fd" "const char *path" "struct stat *sb" "int flag"
54 system call obtains information about the file pointed to by
56 Read, write or execute
57 permission of the named file is not required, but all directories
58 listed in the path name leading to the file must be searchable.
64 except when the named file is a symbolic link,
67 returns information about the link,
70 returns information about the file the link references.
74 system call obtains the same information about an open file
75 known by the file descriptor
80 system call is equivalent to
86 specifies a relative path.
91 the status is retrieved from a file relative to
92 the directory associated with the file descriptor
94 instead of the current working directory.
98 are constructed by a bitwise-inclusive OR of flags from this list,
101 .Bl -tag -width indent
102 .It Dv AT_SYMLINK_NOFOLLOW
105 names a symbolic link, the status of the symbolic link is returned.
106 .It Dv AT_RESOLVE_BENEATH
107 Only walk paths below the starting directory.
108 See the description of the
109 .Dv O_RESOLVE_BENEATH
116 argument is an empty string, operate on the file or directory
117 referenced by the descriptor
123 operate on the current working directory.
128 is passed the special value
132 parameter, the current working directory is used and the behavior is
133 identical to a call to
137 respectively, depending on whether or not the
138 .Dv AT_SYMLINK_NOFOLLOW
144 is called with an absolute
152 argument is a pointer to a
157 and into which information is placed concerning the file.
161 related to the file system are:
162 .Bl -tag -width ".Va st_nlink"
164 Numeric ID of the device containing the file.
166 The file's inode number.
168 Number of hard links to the file.
170 Flags enabled for the file.
173 for the list of flags and their description.
180 fields together identify the file uniquely within the system.
182 The time-related fields of
185 .Bl -tag -width ".Va st_birthtim"
187 Time when file data was last accessed.
188 Changed implicitly by syscalls such as
195 Time when file data was last modified.
196 Changed implicitly by syscalls such as
203 Also, any syscall which modifies directory content changes the
205 for the affected directory.
214 Time when file status was last changed (inode data modification).
215 Changed implicitly by any syscall that affects file metadata, including
225 Also, any syscall which modifies directory content changes the
227 for the affected directory.
236 Time when the inode was created.
239 These time-related macros are defined for compatibility:
241 #define st_atime st_atim.tv_sec
242 #define st_mtime st_mtim.tv_sec
243 #define st_ctime st_ctim.tv_sec
244 #ifndef _POSIX_SOURCE
245 #define st_birthtime st_birthtim.tv_sec
248 #ifndef _POSIX_SOURCE
249 #define st_atimespec st_atim
250 #define st_mtimespec st_mtim
251 #define st_ctimespec st_ctim
252 #define st_birthtimespec st_birthtim
256 Size-related fields of the
259 .Bl -tag -width ".Va st_blksize"
263 Optimal I/O block size for the file.
265 Actual number of blocks allocated for the file in 512-byte units.
266 As short symbolic links are stored in the inode, this number may
270 The access-related fields of
273 .Bl -tag -width ".Va st_mode"
275 User ID of the file's owner.
277 Group ID of the file.
279 Status of the file (see below).
282 The status information word
286 #define S_IFMT 0170000 /* type of file mask */
287 #define S_IFIFO 0010000 /* named pipe (fifo) */
288 #define S_IFCHR 0020000 /* character special */
289 #define S_IFDIR 0040000 /* directory */
290 #define S_IFBLK 0060000 /* block special */
291 #define S_IFREG 0100000 /* regular */
292 #define S_IFLNK 0120000 /* symbolic link */
293 #define S_IFSOCK 0140000 /* socket */
294 #define S_IFWHT 0160000 /* whiteout */
295 #define S_ISUID 0004000 /* set user id on execution */
296 #define S_ISGID 0002000 /* set group id on execution */
297 #define S_ISVTX 0001000 /* save swapped text even after use */
298 #define S_IRWXU 0000700 /* RWX mask for owner */
299 #define S_IRUSR 0000400 /* read permission, owner */
300 #define S_IWUSR 0000200 /* write permission, owner */
301 #define S_IXUSR 0000100 /* execute/search permission, owner */
302 #define S_IRWXG 0000070 /* RWX mask for group */
303 #define S_IRGRP 0000040 /* read permission, group */
304 #define S_IWGRP 0000020 /* write permission, group */
305 #define S_IXGRP 0000010 /* execute/search permission, group */
306 #define S_IRWXO 0000007 /* RWX mask for other */
307 #define S_IROTH 0000004 /* read permission, other */
308 #define S_IWOTH 0000002 /* write permission, other */
309 #define S_IXOTH 0000001 /* execute/search permission, other */
312 For a list of access modes, see
317 These macros are available to test whether a
321 argument corresponds to a file of the specified type:
322 .Bl -tag -width ".Fn S_ISFIFO m"
324 Test for a block special file.
326 Test for a character special file.
328 Test for a directory.
330 Test for a pipe or FIFO special file.
332 Test for a symbolic link.
334 Test for a regular file.
341 The macros evaluate to a non-zero value if the test is true
342 or to the value 0 if the test is false.
346 Previous versions of the system used different types for the
361 system calls will fail if:
364 Search permission is denied for a component of the path prefix.
371 points to an invalid address.
373 An I/O error occurred while reading from or writing to the file system.
375 Corrupted data was detected while reading from the file system.
377 Too many symbolic links were encountered in translating the pathname.
378 .It Bq Er ENAMETOOLONG
379 A component of a pathname exceeded 255 characters,
380 or an entire path name exceeded 1023 characters.
382 The named file does not exist.
384 A component of the path prefix is not a directory.
386 The file size in bytes cannot be
387 represented correctly in the structure pointed to by
393 system call will fail if:
399 is not a valid open file descriptor.
404 points to an invalid address.
406 An I/O error occurred while reading from or writing to the file system.
408 Corrupted data was detected while reading from the file system.
410 The file size in bytes cannot be
411 represented correctly in the structure pointed to by
415 In addition to the errors returned by the
424 argument does not specify an absolute path and the
428 nor a valid file descriptor open for searching.
432 argument is not valid.
436 argument is not an absolute path and
440 nor a file descriptor associated with a directory.
441 .It Bq Er ENOTCAPABLE
444 or contained a ".." component leading to a
445 directory outside of the directory hierarchy specified by
447 and the process is in capability mode or the
448 .Dv AT_RESOLVE_BENEATH
465 system calls are expected to conform to
469 system call follows The Open Group Extended API Set 2 specification.
475 system calls appeared in
479 system call appeared in
483 system call appeared in
489 returns a zeroed buffer,
490 except for the blocksize field,
491 and a unique device and inode number.