1 .\" $NetBSD: stat.2,v 1.47 2010/11/25 20:53:23 dholland 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. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)stat.2 8.4 (Berkeley) 5/1/95
45 .Fn stat "const char *path" "struct stat *sb"
47 .Fn lstat "const char *path" "struct stat *sb"
49 .Fn fstat "int fd" "struct stat *sb"
53 function obtains information about the file pointed to by
55 Read, write or execute
56 permission of the named file is not required, but all directories
57 listed in the path name leading to the file must be searchable.
63 except in the case where the named file is a symbolic link,
66 returns information about the link,
69 returns information about the file the link references.
72 function obtains the same information about an open file
73 known by the file descriptor
78 argument is a pointer to a
83 and into which information is placed concerning the file.
84 .Ss The Standard Structure
85 The following standards-compliant fields are defined in the structure:
86 .Bl -column -offset indent \
87 "nlink_t " "st_nlink " "Description"
88 .It Sy Type Ta Sy Entry Ta Sy Description
89 .It Vt dev_t Ta st_dev Ta device ID containing the file
90 .It Vt ino_t Ta st_ino Ta serial number of the file
91 .It Vt mode_t Ta st_mode Ta mode of the file
92 .It Vt nlink_t Ta st_nlink Ta number of hard links to the file
93 .It Vt uid_t Ta st_uid Ta user ID of the owner
94 .It Vt gid_t Ta st_gid Ta group ID of the owner
95 .It Vt dev_t Ta st_rdev Ta device type (character or block special)
96 .It Vt off_t Ta st_size Ta size of the file in bytes
97 .It Vt time_t Ta st_atime Ta time of last access
98 .It Vt time_t Ta st_mtime Ta time of last data modification
99 .It Vt time_t Ta st_ctime Ta time of last file status change
100 .It Vt blksize_t Ta st_blksize Ta preferred I/O block size (fs-specific)
101 .It Vt blkcnt_t Ta st_block Ta blocks allocated for the file
104 These are specified in the
111 fields taken together to uniquely identify the file within the system.
112 Most of the types are defined in
115 The time-related fields are:
116 .Bl -tag -width st_blksize -offset indent
118 Time when file data was last accessed.
126 Time when file data was last modified.
134 Time when file status was last changed (file metadata modification).
149 The size-related fields of the
152 .Bl -tag -width st_blksize -offset indent
154 The size of the file in bytes.
155 The meaning of the size reported for a directory is file system
157 Some file systems (e.g. FFS) return the total size used for the
158 directory metadata, possibly including free slots; others (notably
159 ZFS) return the number of entries in the directory.
160 Some may also return other things or always report zero.
162 The optimal I/O block size for the file.
164 The actual number of blocks allocated for the file in 512-byte units.
165 As short symbolic links are stored in the inode, this number may
169 The status information word
171 contains bits that define the access mode (see
176 The following macros can be used to test
177 whether a file is of the specified type.
180 supplied to the macros is the value of
182 .Bl -tag -width "S_ISSOCK(m)" -offset indent
184 Test for a block special file.
186 Test for a character special file.
188 Test for a directory.
190 Test for a pipe or FIFO special file.
192 Test for a regular file.
194 Test for a symbolic link.
199 The macros evaluate to a non-zero value if the test
200 is true or to the value 0 if the test is false.
201 .Ss NetBSD Extensions
202 The following additional
204 specific fields are present:
205 .Bl -column -offset indent \
206 "uint32_t" "st_birthtimensec" "Description"
207 .It Sy Type Ta Sy Entry Ta Sy Description
208 .It Vt long Ta st_atimensec Ta last access (nanoseconds)
209 .It Vt long Ta st_mtimensec Ta last modification (nanoseconds)
210 .It Vt long Ta st_ctimensec Ta last status change (nanoseconds)
211 .It Vt time_t Ta st_birthtime Ta time of inode creation
212 .It Vt long Ta st_birthtimensec Ta inode creation (nanoseconds)
213 .It Vt uint32_t Ta st_flags Ta user defined flags for the file
214 .It Vt uint32_t Ta st_gen Ta file generation number
216 .\" XXX: What is this?
218 .It Vt uint32_t Ta st_spare[2] Ta implementation detail
223 is furthermore defined, instead of the above,
224 the following are present in the structure:
225 .Bl -column -offset indent \
226 "struct timespec " "st_birthtimensec" "Description"
227 .It Sy Type Ta Sy Entry Ta Sy Description
228 .It Vt struct timespec Ta st_atimespec Ta time of last access
229 .It Vt struct timespec Ta st_mtimespec Ta time of last modification
230 .It Vt struct timespec Ta st_birthtimespec Ta time of creation
231 .It Vt uint32_t Ta st_flags Ta user defined flags
232 .It Vt uint32_t Ta st_gen Ta file generation number
234 .\" XXX: What is this?
236 .It Vt uint32_t Ta st_spare[2] Ta implementation detail
239 In this case the following macros are provided for convenience:
240 .Bd -literal -offset indent
241 #if defined(_NETBSD_SOURCE)
242 #define st_atime st_atimespec.tv_sec
243 #define st_atimensec st_atimespec.tv_nsec
244 #define st_mtime st_mtimespec.tv_sec
245 #define st_mtimensec st_mtimespec.tv_nsec
246 #define st_ctime st_ctimespec.tv_sec
247 #define st_ctimensec st_ctimespec.tv_nsec
248 #define st_birthtime st_birthtimespec.tv_sec
249 #define st_birthtimensec st_birthtimespec.tv_nsec
253 The status information word
255 has the following bits:
256 .Bl -column -offset indent \
257 "struct timespec " "st_birthtimensec"
258 .It Sy Constant Ta Sy Description
259 .It Dv UF_NODUMP Ta do not dump a file
260 .It Dv UF_IMMUTABLE Ta file may not be changed
261 .It Dv UF_APPEND Ta writes to file may only append
262 .It Dv UF_OPAQUE Ta directory is opaque wrt. union
263 .It Dv SF_ARCHIVED Ta file is archived
264 .It Dv SF_IMMUTABLE Ta file may not be changed
265 .It Dv SF_APPEND Ta writes to file may only append
268 For a description of the flags, see
271 Upon successful completion a value of 0 is returned.
272 Otherwise, a value of \-1 is returned and
274 is set to indicate the error.
276 Previous versions of the system used different types for the
293 Search permission is denied for a component of the path prefix.
295 A badly formed v-node was encountered.
296 This can happen if a file system information node is incorrect.
301 points to an invalid address.
303 An I/O error occurred while reading from or writing to the file system.
305 Too many symbolic links were encountered in translating the pathname.
306 .It Bq Er ENAMETOOLONG
307 A component of a pathname exceeded
309 characters, or an entire path name exceeded
313 The named file does not exist.
315 A component of the path prefix is not a directory.
317 The named file is a character special or block
318 special file, and the device associated with this special file
327 is not a valid open file descriptor.
330 points to an invalid address.
332 An I/O error occurred while reading from or writing to the file system.
343 The described functions conform to
348 function call appeared in
352 function call appeared in
357 to a socket (and thus to a pipe)
358 returns a zero'd buffer,
359 except for the blocksize field,
360 and a unique device and file serial number.