1 .\" $OpenBSD: stat.2,v 1.3 1997/02/13 05:20:55 millert Exp $
3 .\" Copyright (c) 1980, 1991, 1993, 1994
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. All advertising materials mentioning features or use of this software
15 .\" must display the following acknowledgement:
16 .\" This product includes software developed by the University of
17 .\" California, Berkeley and its contributors.
18 .\" 4. Neither the name of the University nor the names of its contributors
19 .\" may be used to endorse or promote products derived from this software
20 .\" without specific prior written permission.
22 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .\" @(#)stat.2 8.3 (Berkeley) 4/19/94
45 .Fd #include <sys/types.h>
46 .Fd #include <sys/stat.h>
48 .Fn stat "const char *path" "struct stat *sb"
50 .Fn lstat "const char *path" "struct stat *sb"
52 .Fn fstat "int fd" "struct stat *sb"
56 function 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.
65 except in the case where the named file is a symbolic link,
68 returns information about the link,
71 returns information about the file the link references.
72 Unlike other filesystem objects,
73 symbolic links do not have an owner, group, access mode, times, etc.
74 Instead, these attributes are taken from the directory that
76 The only attributes returned from an
78 that refer to the symbolic link itself are the file type (S_IFLNK),
79 size, blocks, and link count (always 1).
83 obtains the same information about an open file
84 known by the file descriptor
89 argument is a pointer to a
95 and into which information is placed concerning the file.
98 dev_t st_dev; /* device inode resides on */
99 ino_t st_ino; /* inode's number */
100 mode_t st_mode; /* inode protection mode */
101 nlink_t st_nlink; /* number or hard links to the file */
102 uid_t st_uid; /* user-id of owner */
103 gid_t st_gid; /* group-id of owner */
104 dev_t st_rdev; /* device type, for special file inode */
105 struct timespec st_atimespec; /* time of last access */
106 struct timespec st_mtimespec; /* time of last data modification */
107 struct timespec st_ctimespec; /* time of last file status change */
108 off_t st_size; /* file size, in bytes */
109 quad_t st_blocks; /* blocks allocated for file */
110 u_long st_blksize;/* optimal file sys I/O ops blocksize */
111 u_long st_flags; /* user defined flags for file */
112 u_long st_gen; /* file generation number */
116 The time-related fields of
119 .Bl -tag -width XXXst_mtime
121 Time when file data last accessed.
129 Time when file data last modified.
137 Time when file status was last changed (inode data modification).
151 The size-related fields of the
154 .Bl -tag -width XXXst_blksize
156 The optimal I/O block size for the file.
158 The actual number of blocks allocated for the file in 512-byte units.
159 As short symbolic links are stored in the inode, this number may
163 The status information word
165 has the following bits:
167 #define S_IFMT 0170000 /* type of file */
168 #define S_IFIFO 0010000 /* named pipe (fifo) */
169 #define S_IFCHR 0020000 /* character special */
170 #define S_IFDIR 0040000 /* directory */
171 #define S_IFBLK 0060000 /* block special */
172 #define S_IFREG 0100000 /* regular */
173 #define S_IFLNK 0120000 /* symbolic link */
174 #define S_IFSOCK 0140000 /* socket */
175 #define S_IFWHT 0160000 /* whiteout */
176 #define S_ISUID 0004000 /* set user id on execution */
177 #define S_ISGID 0002000 /* set group id on execution */
178 #define S_ISVTX 0001000 /* save swapped text even after use */
179 #define S_IRUSR 0000400 /* read permission, owner */
180 #define S_IWUSR 0000200 /* write permission, owner */
181 #define S_IXUSR 0000100 /* execute/search permission, owner */
184 For a list of access modes, see
190 Upon successful completion a value of 0 is returned.
191 Otherwise, a value of -1 is returned and
193 is set to indicate the error.
195 Previous versions of the system used different types for the
212 A component of the path prefix is not a directory.
213 .It Bq Er ENAMETOOLONG
214 A component of a pathname exceeded
216 characters, or an entire path name exceeded
220 The named file does not exist.
222 Search permission is denied for a component of the path prefix.
224 Too many symbolic links were encountered in translating the pathname.
229 points to an invalid address.
231 An I/O error occurred while reading from or writing to the file system.
239 is not a valid open file descriptor.
242 points to an invalid address.
244 An I/O error occurred while reading from or writing to the file system.
247 The file generation number,
249 is only available to the super-user.
251 The fields in the stat structure currently marked
256 are present in preparation for inode time stamps expanding
257 to 64 bits. This, however, can break certain programs that
258 depend on the time stamps being contiguous (in calls to
268 to a socket (and thus to a pipe)
269 returns a zero'd buffer,
270 except for the blocksize field,
271 and a unique device and inode number.
277 function calls are expected to conform to
282 function call appeared in