1 .\" $NetBSD: stat.2,v 1.37 2009/03/11 13:39:14 joerg 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.
62 except in the case where the named file is a symbolic link,
65 returns information about the link,
68 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
84 and into which information is placed concerning the file.
87 dev_t st_dev; /* device containing the file */
88 ino_t st_ino; /* file's serial number */
89 mode_t st_mode; /* file's mode (protection and type) */
90 nlink_t st_nlink; /* number of hard links to the file */
91 uid_t st_uid; /* user-id of owner */
92 gid_t st_gid; /* group-id of owner */
93 dev_t st_rdev; /* device type, for device special file */
94 #if defined(_NETBSD_SOURCE)
95 struct timespec st_atimespec; /* time of last access */
96 struct timespec st_mtimespec; /* time of last data modification */
97 struct timespec st_ctimespec; /* time of last file status change */
99 time_t st_atime; /* time of last access */
100 long st_atimensec; /* nsec of last access */
101 time_t st_mtime; /* time of last data modification */
102 long st_mtimensec; /* nsec of last data modification */
103 time_t st_ctime; /* time of last file status change */
104 long st_ctimensec; /* nsec of last file status change */
106 off_t st_size; /* file size, in bytes */
107 blkcnt_t st_blocks; /* blocks allocated for file */
108 blksize_t st_blksize; /* optimal file sys I/O ops blocksize */
109 uint32_t st_flags; /* user defined flags for file */
110 uint32_t st_gen; /* file generation number */
111 #if defined(_NETBSD_SOURCE)
112 struct timespec st_birthtimespec; /* time of inode creation */
114 time_t st_birthtime; /* time of inode creation */
115 long st_birthtimensec; /* nsec of inode creation */
120 The time-related fields of
123 .Bl -tag -width XXXst_birthtime
125 Time when file data was last accessed.
133 Time when file data was last modified.
141 Time when file status was last changed (file metadata modification).
155 Time when the inode was created.
160 is defined, the time-related fields are defined as:
162 #if defined(_NETBSD_SOURCE)
163 #define st_atime st_atimespec.tv_sec
164 #define st_atimensec st_atimespec.tv_nsec
165 #define st_mtime st_mtimespec.tv_sec
166 #define st_mtimensec st_mtimespec.tv_nsec
167 #define st_ctime st_ctimespec.tv_sec
168 #define st_ctimensec st_ctimespec.tv_nsec
169 #define st_birthtime st_birthtimespec.tv_sec
170 #define st_birthtimensec st_birthtimespec.tv_nsec
174 The size-related fields of the
177 .Bl -tag -width XXXst_blksize
179 The size of the file in bytes.
180 A directory will be a multiple of the size of the
183 Some filesystems (notably ZFS) return the number of enties in the directory
184 instead of the size in bytes.
186 The optimal I/O block size for the file.
188 The actual number of blocks allocated for the file in 512-byte units.
189 As short symbolic links are stored in the inode, this number may
193 The status information word
195 has the following bits:
197 #define S_IFMT 0170000 /* type of file */
198 #define S_IFIFO 0010000 /* named pipe (fifo) */
199 #define S_IFCHR 0020000 /* character special */
200 #define S_IFDIR 0040000 /* directory */
201 #define S_IFBLK 0060000 /* block special */
202 #define S_IFREG 0100000 /* regular */
203 #define S_IFLNK 0120000 /* symbolic link */
204 #define S_IFSOCK 0140000 /* socket */
205 #define S_IFWHT 0160000 /* whiteout */
206 #define S_ISUID 0004000 /* set user id on execution */
207 #define S_ISGID 0002000 /* set group id on execution */
208 #define S_ISVTX 0001000 /* save swapped text even after use */
209 #define S_IRUSR 0000400 /* read permission, owner */
210 #define S_IWUSR 0000200 /* write permission, owner */
211 #define S_IXUSR 0000100 /* execute/search permission, owner */
212 #define S_IRGRP 0000040 /* read permission, group */
213 #define S_IWGRP 0000020 /* write permission, group */
214 #define S_IXGRP 0000010 /* execute/search permission, group */
215 #define S_IROTH 0000004 /* read permission, other */
216 #define S_IWOTH 0000002 /* write permission, other */
217 #define S_IXOTH 0000001 /* execute/search permission, other */
220 For a list of access modes, see
226 The status information word
228 has the following bits:
230 #define UF_NODUMP 0x00000001 /* do not dump file */
231 #define UF_IMMUTABLE 0x00000002 /* file may not be changed */
232 #define UF_APPEND 0x00000004 /* writes to file may only append */
233 #define UF_OPAQUE 0x00000008 /* directory is opaque wrt. union */
234 #define SF_ARCHIVED 0x00010000 /* file is archived */
235 #define SF_IMMUTABLE 0x00020000 /* file may not be changed */
236 #define SF_APPEND 0x00040000 /* writes to file may only append */
239 For a description of the flags, see
242 Upon successful completion a value of 0 is returned.
243 Otherwise, a value of \-1 is returned and
245 is set to indicate the error.
247 Previous versions of the system used different types for the
264 Search permission is denied for a component of the path prefix.
266 A badly formed v-node was encountered.
267 This can happen if a file system information node is incorrect.
272 points to an invalid address.
274 An I/O error occurred while reading from or writing to the file system.
276 Too many symbolic links were encountered in translating the pathname.
277 .It Bq Er ENAMETOOLONG
278 A component of a pathname exceeded
280 characters, or an entire path name exceeded
284 The named file does not exist.
286 A component of the path prefix is not a directory.
288 The named file is a character special or block
289 special file, and the device associated with this special file
298 is not a valid open file descriptor.
301 points to an invalid address.
303 An I/O error occurred while reading from or writing to the file system.
322 function call appeared in
327 to a socket (and thus to a pipe)
328 returns a zero'd buffer,
329 except for the blocksize field,
330 and a unique device and file serial number.