1 .\" $NetBSD: stat.2,v 1.56 2013/10/15 11:43:21 njoly 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
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"
54 .Fn fstatat "int fd" "const char *path" "struct stat *sb" "int flag"
58 function obtains information about the file pointed to by
60 Read, write or execute
61 permission of the named file is not required, but all directories
62 listed in the path name leading to the file must be searchable.
68 except in the case where the named file is a symbolic link,
71 returns information about the link,
74 returns information about the file the link references.
77 function obtains the same information about an open file
78 known by the file descriptor
87 .Dv AT_SYMLINK_NOFOLLOW
93 In that case, it is looked up from a directory whose file
94 descriptor was passed as
96 Search permission is required on this directory.
97 .\" (These alternatives await a decision about the semantics of O_SEARCH)
98 .\" Search permission is required on this directory
101 .\" was opened with the
105 .\" This file descriptor must have been opened with the
111 in order to specify the current directory.
115 argument is a pointer to a
120 and into which information is placed concerning the file.
121 .Ss The Standard Structure
122 The following standards-compliant fields are defined in the structure:
123 .Bl -column -offset indent \
124 "nlink_t " "st_nlink " "Description"
125 .It Sy Type Ta Sy Entry Ta Sy Description
126 .It Vt dev_t Ta st_dev Ta device ID containing the file
127 .It Vt ino_t Ta st_ino Ta serial number of the file
128 .It Vt mode_t Ta st_mode Ta mode of the file
129 .It Vt nlink_t Ta st_nlink Ta number of hard links to the file
130 .It Vt uid_t Ta st_uid Ta user ID of the owner
131 .It Vt gid_t Ta st_gid Ta group ID of the owner
132 .It Vt dev_t Ta st_rdev Ta device type (character or block special)
133 .It Vt off_t Ta st_size Ta size of the file in bytes
134 .It Vt time_t Ta st_atime Ta time of last access
135 .It Vt time_t Ta st_mtime Ta time of last data modification
136 .It Vt time_t Ta st_ctime Ta time of last file status change
137 .It Vt blksize_t Ta st_blksize Ta preferred I/O block size (fs-specific)
138 .It Vt blkcnt_t Ta st_blocks Ta blocks allocated for the file
141 These are specified in the
148 fields taken together uniquely identify the file within the system.
149 Most of the types are defined in
152 The time-related fields are:
153 .Bl -tag -width st_blksize -offset indent
155 Time when file data was last accessed.
163 Time when file data was last modified.
171 Time when file status was last changed (file metadata modification).
186 The size-related fields of the
189 .Bl -tag -width st_blksize -offset indent
191 The size of the file in bytes.
192 The meaning of the size reported for a directory is file system
194 Some file systems (e.g. FFS) return the total size used for the
195 directory metadata, possibly including free slots; others (notably
196 ZFS) return the number of entries in the directory.
197 Some may also return other things or always report zero.
199 The optimal I/O block size for the file.
201 The actual number of blocks allocated for the file in 512-byte units.
202 As short symbolic links are stored in the inode, this number may
206 The status information word
208 contains bits that define the access mode (see
213 The following macros can be used to test
214 whether a file is of the specified type.
217 supplied to the macros is the value of
219 .Bl -tag -width "S_ISSOCK(m)" -offset indent
221 Test for a block special file.
223 Test for a character special file.
225 Test for a directory.
227 Test for a pipe or FIFO special file.
229 Test for a regular file.
231 Test for a symbolic link.
236 The macros evaluate to a non-zero value if the test
237 is true or to the value 0 if the test is false.
238 .Ss NetBSD Extensions
239 The following additional
241 specific fields are present:
242 .Bl -column -offset indent \
243 "uint32_t" "st_birthtimensec" "Description"
244 .It Sy Type Ta Sy Entry Ta Sy Description
245 .It Vt long Ta st_atimensec Ta last access (nanoseconds)
246 .It Vt long Ta st_mtimensec Ta last modification (nanoseconds)
247 .It Vt long Ta st_ctimensec Ta last status change (nanoseconds)
248 .It Vt time_t Ta st_birthtime Ta time of inode creation
249 .It Vt long Ta st_birthtimensec Ta inode creation (nanoseconds)
250 .It Vt uint32_t Ta st_flags Ta user defined flags for the file
251 .It Vt uint32_t Ta st_gen Ta file generation number
253 .\" XXX: What is this?
255 .It Vt uint32_t Ta st_spare[2] Ta implementation detail
260 is furthermore defined, instead of the above,
261 the following are present in the structure:
262 .Bl -column -offset indent \
263 "struct timespec " "st_birthtimensec" "Description"
264 .It Sy Type Ta Sy Entry Ta Sy Description
265 .It Vt struct timespec Ta st_atimespec Ta time of last access
266 .It Vt struct timespec Ta st_mtimespec Ta time of last modification
267 .It Vt struct timespec Ta st_birthtimespec Ta time of creation
268 .It Vt uint32_t Ta st_flags Ta user defined flags
269 .It Vt uint32_t Ta st_gen Ta file generation number
271 .\" XXX: What is this?
273 .It Vt uint32_t Ta st_spare[2] Ta implementation detail
276 In this case the following macros are provided for convenience:
277 .Bd -literal -offset indent
278 #if defined(_NETBSD_SOURCE)
279 #define st_atime st_atimespec.tv_sec
280 #define st_atimensec st_atimespec.tv_nsec
281 #define st_mtime st_mtimespec.tv_sec
282 #define st_mtimensec st_mtimespec.tv_nsec
283 #define st_ctime st_ctimespec.tv_sec
284 #define st_ctimensec st_ctimespec.tv_nsec
285 #define st_birthtime st_birthtimespec.tv_sec
286 #define st_birthtimensec st_birthtimespec.tv_nsec
290 The status information word
292 has the following bits:
293 .Bl -column -offset indent \
294 "struct timespec " "st_birthtimensec"
295 .It Sy Constant Ta Sy Description
296 .It Dv UF_NODUMP Ta do not dump a file
297 .It Dv UF_IMMUTABLE Ta file may not be changed
298 .It Dv UF_APPEND Ta writes to file may only append
299 .It Dv UF_OPAQUE Ta directory is opaque wrt. union
300 .It Dv SF_ARCHIVED Ta file is archived
301 .It Dv SF_IMMUTABLE Ta file may not be changed
302 .It Dv SF_APPEND Ta writes to file may only append
305 For a description of the flags, see
308 .Rv -std stat lstat fstat fstatat
310 Previous versions of the system used different types for the
328 Search permission is denied for a component of the path prefix.
330 A badly formed vnode was encountered.
331 This can happen if a file system information node is incorrect.
336 points to an invalid address.
338 An I/O error occurred while reading from or writing to the file system.
340 Too many symbolic links were encountered in translating the pathname.
341 .It Bq Er ENAMETOOLONG
342 A component of a pathname exceeded
344 characters, or an entire path name exceeded
348 The named file does not exist.
350 A component of the path prefix is not a directory.
352 The named file is a character special or block
353 special file, and the device associated with this special file
363 does not specify an absolute path and
367 nor a valid file descriptor open for reading or searching.
370 is not an absolute path and
372 is a file descriptor associated with a non-directory file.
380 is not a valid open file descriptor.
383 points to an invalid address.
385 An I/O error occurred while reading from or writing to the file system.
408 function call appeared in
412 function call appeared in
417 to a socket (and thus to a pipe)
418 returns a zero'd buffer,
419 except for the blocksize field,
420 and a unique device and file serial number.