]>
Commit | Line | Data |
---|---|---|
9bccf70c A |
1 | .\" $OpenBSD: stat.2,v 1.3 1997/02/13 05:20:55 millert Exp $ |
2 | .\" | |
3 | .\" Copyright (c) 1980, 1991, 1993, 1994 | |
4 | .\" The Regents of the University of California. All rights reserved. | |
5 | .\" | |
6 | .\" Redistribution and use in source and binary forms, with or without | |
7 | .\" modification, are permitted provided that the following conditions | |
8 | .\" are met: | |
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. | |
21 | .\" | |
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 | |
32 | .\" SUCH DAMAGE. | |
33 | .\" | |
34 | .\" @(#)stat.2 8.3 (Berkeley) 4/19/94 | |
35 | .\" | |
36 | .Dd April 19, 1994 | |
37 | .Dt STAT 2 | |
38 | .Os BSD 4 | |
39 | .Sh NAME | |
2d21ac55 | 40 | .Nm fstat , |
9bccf70c | 41 | .Nm lstat , |
593a1d5f | 42 | .Nm stat |
9bccf70c A |
43 | .Nd get file status |
44 | .Sh SYNOPSIS | |
9bccf70c A |
45 | .Fd #include <sys/stat.h> |
46 | .Ft int | |
2d21ac55 A |
47 | .Fo fstat |
48 | .Fa "int fildes" | |
49 | .Fa "struct stat *buf" | |
50 | .Fc | |
51 | .Ft int | |
2d21ac55 A |
52 | .Fo lstat |
53 | .Fa "const char *restrict path" | |
54 | .Fa "struct stat *restrict buf" | |
55 | .Fc | |
9bccf70c | 56 | .Ft int |
2d21ac55 A |
57 | .Fo stat |
58 | .Fa "const char *restrict path" | |
59 | .Fa "struct stat *restrict buf" | |
60 | .Fc | |
9bccf70c A |
61 | .Sh DESCRIPTION |
62 | The | |
63 | .Fn stat | |
593a1d5f | 64 | family of functions obtain information about a file. The |
2d21ac55 | 65 | .Fn stat |
9bccf70c A |
66 | function obtains information about the file pointed to by |
67 | .Fa path . | |
68 | Read, write or execute | |
69 | permission of the named file is not required, but all directories | |
70 | listed in the path name leading to the file must be searchable. | |
71 | .Pp | |
72 | .Fn Lstat | |
73 | is like | |
74 | .Fn stat | |
75 | except in the case where the named file is a symbolic link, | |
76 | in which case | |
77 | .Fn lstat | |
78 | returns information about the link, | |
79 | while | |
80 | .Fn stat | |
81 | returns information about the file the link references. | |
82 | Unlike other filesystem objects, | |
83 | symbolic links do not have an owner, group, access mode, times, etc. | |
84 | Instead, these attributes are taken from the directory that | |
85 | contains the link. | |
86 | The only attributes returned from an | |
87 | .Fn lstat | |
88 | that refer to the symbolic link itself are the file type (S_IFLNK), | |
89 | size, blocks, and link count (always 1). | |
90 | .Pp | |
91 | The | |
92 | .Fn fstat | |
93 | obtains the same information about an open file | |
94 | known by the file descriptor | |
2d21ac55 | 95 | .Fa fildes . |
9bccf70c A |
96 | .Pp |
97 | The | |
2d21ac55 | 98 | .Fa buf |
9bccf70c | 99 | argument is a pointer to a |
2d21ac55 | 100 | .Fa stat |
2d21ac55 | 101 | structure |
9bccf70c A |
102 | as defined by |
103 | .Aq Pa sys/stat.h | |
9bccf70c A |
104 | and into which information is placed concerning the file. |
105 | .Bd -literal | |
106 | struct stat { | |
2d21ac55 A |
107 | dev_t st_dev; /* ID of device containing file */ |
108 | mode_t st_mode; /* Mode of file (see below) */ | |
109 | nlink_t st_nlink; /* Number of hard links */ | |
593a1d5f | 110 | ino_t st_ino; /* File serial number */ |
2d21ac55 A |
111 | uid_t st_uid; /* User ID of the file */ |
112 | gid_t st_gid; /* Group ID of the file */ | |
113 | dev_t st_rdev; /* Device ID */ | |
114 | struct timespec st_atimespec; /* time of last access */ | |
115 | struct timespec st_mtimespec; /* time of last data modification */ | |
116 | struct timespec st_ctimespec; /* time of last status change */ | |
117 | struct timespec st_birthtimespec; /* time of file creation(birth) */ | |
118 | off_t st_size; /* file size, in bytes */ | |
119 | blkcnt_t st_blocks; /* blocks allocated for file */ | |
120 | blksize_t st_blksize; /* optimal blocksize for I/O */ | |
121 | uint32_t st_flags; /* user defined flags for file */ | |
122 | uint32_t st_gen; /* file generation number */ | |
123 | int32_t st_lspare; /* RESERVED: DO NOT USE! */ | |
124 | int64_t st_qspare[2]; /* RESERVED: DO NOT USE! */ | |
125 | }; | |
126 | ||
127 | ||
9bccf70c A |
128 | .Ed |
129 | .Pp | |
130 | The time-related fields of | |
131 | .Fa struct stat | |
132 | are as follows: | |
2d21ac55 | 133 | .Bl -tag -width XXXst_birthtime |
9bccf70c A |
134 | .It st_atime |
135 | Time when file data last accessed. | |
136 | Changed by the | |
137 | .Xr mknod 2 , | |
138 | .Xr utimes 2 | |
139 | and | |
140 | .Xr read 2 | |
141 | system calls. | |
142 | .It st_mtime | |
143 | Time when file data last modified. | |
144 | Changed by the | |
145 | .Xr mknod 2 , | |
146 | .Xr utimes 2 | |
147 | and | |
148 | .Xr write 2 | |
149 | system calls. | |
150 | .It st_ctime | |
151 | Time when file status was last changed (inode data modification). | |
152 | Changed by the | |
153 | .Xr chmod 2 , | |
154 | .Xr chown 2 , | |
155 | .Xr link 2 , | |
156 | .Xr mknod 2 , | |
157 | .Xr rename 2 , | |
158 | .Xr unlink 2 , | |
159 | .Xr utimes 2 | |
160 | and | |
161 | .Xr write 2 | |
162 | system calls. | |
2d21ac55 | 163 | .It st_birthtime |
593a1d5f A |
164 | Time of file creation. Only set once when the file is created. |
165 | On filesystems where birthtime is not available, this field holds the | |
2d21ac55 A |
166 | .Fa ctime |
167 | instead. | |
9bccf70c A |
168 | .El |
169 | .Pp | |
2d21ac55 | 170 | The size-related fields of the structures are as follows: |
9bccf70c A |
171 | .Bl -tag -width XXXst_blksize |
172 | .It st_blksize | |
173 | The optimal I/O block size for the file. | |
174 | .It st_blocks | |
175 | The actual number of blocks allocated for the file in 512-byte units. | |
176 | As short symbolic links are stored in the inode, this number may | |
177 | be zero. | |
178 | .El | |
179 | .Pp | |
180 | The status information word | |
181 | .Fa st_mode | |
182 | has the following bits: | |
183 | .Bd -literal | |
184 | #define S_IFMT 0170000 /* type of file */ | |
185 | #define S_IFIFO 0010000 /* named pipe (fifo) */ | |
186 | #define S_IFCHR 0020000 /* character special */ | |
187 | #define S_IFDIR 0040000 /* directory */ | |
188 | #define S_IFBLK 0060000 /* block special */ | |
189 | #define S_IFREG 0100000 /* regular */ | |
190 | #define S_IFLNK 0120000 /* symbolic link */ | |
191 | #define S_IFSOCK 0140000 /* socket */ | |
192 | #define S_IFWHT 0160000 /* whiteout */ | |
193 | #define S_ISUID 0004000 /* set user id on execution */ | |
194 | #define S_ISGID 0002000 /* set group id on execution */ | |
195 | #define S_ISVTX 0001000 /* save swapped text even after use */ | |
196 | #define S_IRUSR 0000400 /* read permission, owner */ | |
197 | #define S_IWUSR 0000200 /* write permission, owner */ | |
198 | #define S_IXUSR 0000100 /* execute/search permission, owner */ | |
199 | .Ed | |
200 | .Pp | |
201 | For a list of access modes, see | |
202 | .Aq Pa sys/stat.h , | |
203 | .Xr access 2 | |
204 | and | |
205 | .Xr chmod 2 . | |
2d21ac55 A |
206 | .Pp |
207 | For a list of the file flags in the | |
208 | .Fa st_flags | |
209 | field, see | |
210 | .Aq Pa sys/stat.h | |
211 | and | |
212 | .Xr chflags 2 . | |
9bccf70c A |
213 | .Sh RETURN VALUES |
214 | Upon successful completion a value of 0 is returned. | |
215 | Otherwise, a value of -1 is returned and | |
216 | .Va errno | |
217 | is set to indicate the error. | |
218 | .Sh COMPATIBILITY | |
219 | Previous versions of the system used different types for the | |
220 | .Li st_dev , | |
221 | .Li st_uid , | |
222 | .Li st_gid , | |
223 | .Li st_rdev , | |
224 | .Li st_size , | |
225 | .Li st_blksize | |
226 | and | |
227 | .Li st_blocks | |
228 | fields. | |
229 | .Sh ERRORS | |
2d21ac55 A |
230 | .Bl -tag -width Er |
231 | The | |
232 | .Fn fstat | |
233 | system call will fail if: | |
234 | .\" =========== | |
235 | .It Bq Er EBADF | |
236 | .Fa fildes | |
237 | is not a valid open file descriptor. | |
238 | .\" =========== | |
239 | .It Bq Er EFAULT | |
240 | .Fa Sb | |
241 | points to an invalid address. | |
242 | .\" =========== | |
243 | .It Bq Er EIO | |
244 | An I/O error occurs while reading from or writing to the file system. | |
245 | .El | |
246 | .Pp | |
247 | The | |
9bccf70c | 248 | .Fn lstat |
2d21ac55 A |
249 | and |
250 | .Fn stat | |
251 | system calls will fail if: | |
9bccf70c | 252 | .Bl -tag -width Er |
2d21ac55 | 253 | .\" =========== |
9bccf70c A |
254 | .It Bq Er EACCES |
255 | Search permission is denied for a component of the path prefix. | |
2d21ac55 | 256 | .\" =========== |
9bccf70c A |
257 | .It Bq Er EFAULT |
258 | .Fa Sb | |
259 | or | |
260 | .Em name | |
261 | points to an invalid address. | |
2d21ac55 | 262 | .\" =========== |
9bccf70c | 263 | .It Bq Er EIO |
2d21ac55 A |
264 | An I/O error occurs while reading from or writing to the file system. |
265 | .\" =========== | |
266 | .It Bq Er ELOOP | |
267 | Too many symbolic links are encountered in translating the pathname. | |
268 | This is taken to be indicative of a looping symbolic link. | |
269 | .\" =========== | |
270 | .It Bq Er ENAMETOOLONG | |
271 | A component of a pathname exceeds | |
272 | .Dv {NAME_MAX} | |
273 | characters, or an entire path name exceeds | |
274 | .Dv {PATH_MAX} | |
275 | characters. | |
276 | .\" =========== | |
277 | .It Bq Er ENOENT | |
278 | The named file does not exist. | |
279 | .\" =========== | |
280 | .It Bq Er ENOTDIR | |
281 | A component of the path prefix is not a directory. | |
9bccf70c A |
282 | .El |
283 | .Pp | |
2d21ac55 A |
284 | The |
285 | .Fn fstat , | |
286 | .Fn lstat , | |
287 | and | |
288 | .Fn stat | |
289 | system calls will fail if: | |
9bccf70c | 290 | .Bl -tag -width Er |
2d21ac55 A |
291 | .\" =========== |
292 | .It Bq Er EOVERFLOW | |
293 | The file size in bytes | |
294 | or the number of blocks allocated to the file | |
295 | or the file serial number cannot be represented correctly | |
296 | in the structure pointed to by | |
297 | .Fa buf . | |
9bccf70c A |
298 | .El |
299 | .Sh CAVEATS | |
300 | The file generation number, | |
301 | .Fa st_gen , | |
302 | is only available to the super-user. | |
9bccf70c | 303 | .Sh SEE ALSO |
2d21ac55 | 304 | .Xr chflags 2 , |
9bccf70c A |
305 | .Xr chmod 2 , |
306 | .Xr chown 2 , | |
2d21ac55 A |
307 | .Xr utimes 2 , |
308 | .Xr compat 5 , | |
9bccf70c A |
309 | .Xr symlink 7 |
310 | .Sh BUGS | |
311 | Applying | |
312 | .Xr fstat | |
313 | to a socket (and thus to a pipe) | |
314 | returns a zero'd buffer, | |
315 | except for the blocksize field, | |
316 | and a unique device and inode number. | |
317 | .Sh STANDARDS | |
318 | The | |
319 | .Fn stat | |
320 | and | |
321 | .Fn fstat | |
322 | function calls are expected to conform to | |
323 | .St -p1003.1-88 . | |
324 | .Sh HISTORY | |
325 | An | |
326 | .Fn lstat | |
327 | function call appeared in | |
328 | .Bx 4.2 . |