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 .\" 4. 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
46 .Fn stat "const char *path" "struct stat *sb"
48 .Fn lstat "const char *path" "struct stat *sb"
50 .Fn fstat "int fd" "struct stat *sb"
52 .Fn fstatat "int fd" "const char *path" "struct stat *buf" "int flag"
56 system call obtains information about the file pointed to by
58 Read, write or execute
59 permission of the named file is not required, but all directories
60 listed in the path name leading to the file must be searchable.
66 except in the case where the named file is a symbolic link,
69 returns information about the link,
72 returns information about the file the link references.
76 system call obtains the same information about an open file
77 known by the file descriptor
82 system call is equivalent to
86 except in the case where the
88 specifies a relative path.
89 In this case the status is retrieved from a file relative to
90 the directory associated with the file descriptor
92 instead of the current working directory.
96 are constructed by a bitwise-inclusive OR of flags from the following list,
99 .Bl -tag -width indent
100 .It Dv AT_SYMLINK_NOFOLLOW
103 names a symbolic link, the status of the symbolic link is returned.
108 is passed the special value
112 parameter, the current working directory is used and the behavior is
113 identical to a call to
117 respectively, depending on whether or not the
118 .Dv AT_SYMLINK_NOFOLLOW
124 argument is a pointer to a
129 and into which information is placed concerning the file.
133 related to the file system are as follows:
134 .Bl -tag -width ".Va st_nlink"
136 The numeric ID of the device containing the file.
138 The file's inode number.
140 The number of hard links to the file.
147 fields together identify the file uniquely within the system.
149 The time-related fields of
152 .Bl -tag -width ".Va st_birthtim"
154 Time when file data last accessed.
163 Time when file data last modified.
174 Time when file status was last changed (inode data modification).
195 Time when the inode was created.
198 The following time-related macros are defined for compatibility:
200 #define st_atime st_atim.tv_sec
201 #define st_mtime st_mtim.tv_sec
202 #define st_ctime st_ctim.tv_sec
203 #ifndef _POSIX_SOURCE
204 #define st_birthtime st_birthtim.tv_sec
207 #ifndef _POSIX_SOURCE
208 #define st_atimespec st_atim
209 #define st_mtimespec st_mtim
210 #define st_ctimespec st_ctim
211 #define st_birthtimespec st_birthtim
215 The size-related fields of the
218 .Bl -tag -width ".Va st_blksize"
220 The file size in bytes.
222 The optimal I/O block size for the file.
224 The actual number of blocks allocated for the file in 512-byte units.
225 As short symbolic links are stored in the inode, this number may
229 The access-related fields of
232 .Bl -tag -width ".Va st_mode"
234 The user ID of the file's owner.
236 The group ID of the file.
238 Status of the file (see below).
241 The status information word
243 has the following bits:
245 #define S_IFMT 0170000 /* type of file mask */
246 #define S_IFIFO 0010000 /* named pipe (fifo) */
247 #define S_IFCHR 0020000 /* character special */
248 #define S_IFDIR 0040000 /* directory */
249 #define S_IFBLK 0060000 /* block special */
250 #define S_IFREG 0100000 /* regular */
251 #define S_IFLNK 0120000 /* symbolic link */
252 #define S_IFSOCK 0140000 /* socket */
253 #define S_IFWHT 0160000 /* whiteout */
254 #define S_ISUID 0004000 /* set user id on execution */
255 #define S_ISGID 0002000 /* set group id on execution */
256 #define S_ISVTX 0001000 /* save swapped text even after use */
257 #define S_IRWXU 0000700 /* RWX mask for owner */
258 #define S_IRUSR 0000400 /* read permission, owner */
259 #define S_IWUSR 0000200 /* write permission, owner */
260 #define S_IXUSR 0000100 /* execute/search permission, owner */
261 #define S_IRWXG 0000070 /* RWX mask for group */
262 #define S_IRGRP 0000040 /* read permission, group */
263 #define S_IWGRP 0000020 /* write permission, group */
264 #define S_IXGRP 0000010 /* execute/search permission, group */
265 #define S_IRWXO 0000007 /* RWX mask for other */
266 #define S_IROTH 0000004 /* read permission, other */
267 #define S_IWOTH 0000002 /* write permission, other */
268 #define S_IXOTH 0000001 /* execute/search permission, other */
271 For a list of access modes, see
276 The following macros are available to test whether a
280 argument corresponds to a file of the specified type:
281 .Bl -tag -width ".Fn S_ISFIFO m"
283 Test for a block special file.
285 Test for a character special file.
287 Test for a directory.
289 Test for a pipe or FIFO special file.
291 Test for a symbolic link.
293 Test for a regular file.
300 The macros evaluate to a non-zero value if the test is true
301 or to the value 0 if the test is false.
305 Previous versions of the system used different types for the
320 system calls will fail if:
323 Search permission is denied for a component of the path prefix.
330 points to an invalid address.
332 An I/O error occurred while reading from or writing to the file system.
334 Too many symbolic links were encountered in translating the pathname.
335 .It Bq Er ENAMETOOLONG
336 A component of a pathname exceeded 255 characters,
337 or an entire path name exceeded 1023 characters.
339 The named file does not exist.
341 A component of the path prefix is not a directory.
343 The file size in bytes cannot be
344 represented correctly in the structure pointed to by
350 system call will fail if:
356 is not a valid open file descriptor.
361 points to an invalid address.
363 An I/O error occurred while reading from or writing to the file system.
365 The file size in bytes cannot be
366 represented correctly in the structure pointed to by
370 In addition to the errors returned by the
379 argument does not specify an absolute path and the
383 nor a valid file descriptor open for searching.
387 argument is not valid.
391 argument is not an absolute path and
395 nor a file descriptor associated with a directory.
411 system calls are expected to conform to
415 system call follows The Open Group Extended API Set 2 specification.
421 system calls appeared in
425 system call appeared in
429 system call appeared in
435 returns a zeroed buffer,
436 except for the blocksize field,
437 and a unique device and inode number.