1 .\" Copyright (c) 1980, 1991, 1993, 1994
2 .\" The Regents of the University of California. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\" must display the following acknowledgement:
14 .\" This product includes software developed by the University of
15 .\" California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\" may be used to endorse or promote products derived from this software
18 .\" without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .\" @(#)stat.2 8.4 (Berkeley) 5/1/95
33 .\" $FreeBSD: src/lib/libc/sys/stat.2,v 1.16.2.7 2001/12/14 18:34:01 ru Exp $
34 .\" $DragonFly: src/lib/libc/sys/stat.2,v 1.6 2008/09/28 16:33:35 swildner Exp $
36 .Dd September 28, 2008
50 .Fn stat "const char *path" "struct stat *sb"
52 .Fn lstat "const char *path" "struct stat *sb"
54 .Fn fstat "int fd" "struct stat *sb"
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.
67 except in the case where the named file is a symbolic link,
70 returns information about the link,
73 returns information about the file the link references.
77 obtains the same information about an open file
78 known by the file descriptor
83 argument is a pointer to a
89 and into which information is placed concerning the file.
92 dev_t st_dev; /* inode's device */
93 ino_t st_ino; /* inode's number */
94 mode_t st_mode; /* inode protection mode */
95 nlink_t st_nlink; /* number of hard links */
96 uid_t st_uid; /* user ID of the file's owner */
97 gid_t st_gid; /* group ID of the file's group */
98 dev_t st_rdev; /* device type */
100 struct timespec st_atimespec; /* time of last access */
101 struct timespec st_mtimespec; /* time of last data modification */
102 struct timespec st_ctimespec; /* time of last file status change */
104 time_t st_atime; /* time of last access */
105 long st_atimensec; /* nsec of last access */
106 time_t st_mtime; /* time of last data modification */
107 long st_mtimensec; /* nsec of last data modification */
108 time_t st_ctime; /* time of last file status change */
109 long st_ctimensec; /* nsec of last file status change */
111 off_t st_size; /* file size, in bytes */
112 int64_t st_blocks; /* blocks allocated for file */
113 u_int32_t st_blksize; /* optimal blocksize for I/O */
114 u_int32_t st_flags; /* user defined flags for file */
115 u_int32_t st_gen; /* file generation number */
119 The time-related fields of
122 .Bl -tag -width XXXst_mtime
124 Time when file data last accessed.
134 Time when file data last modified.
142 Time when file status was last changed (inode data modification).
158 is not defined, the time-related fields are defined as:
160 #ifndef _POSIX_SOURCE
161 #define st_atime st_atimespec.tv_sec
162 #define st_mtime st_mtimespec.tv_sec
163 #define st_ctime st_ctimespec.tv_sec
167 The size-related fields of the
170 .Bl -tag -width XXXst_blksize
172 The optimal I/O block size for the file.
174 The actual number of blocks allocated for the file in 512-byte units.
175 As short symbolic links are stored in the inode, this number may
179 The status information word
181 has the following bits:
183 #define S_IFMT 0170000 /* type of file */
184 #define S_IFIFO 0010000 /* named pipe (fifo) */
185 #define S_IFCHR 0020000 /* character special */
186 #define S_IFDIR 0040000 /* directory */
187 #define S_IFBLK 0060000 /* block special */
188 #define S_IFREG 0100000 /* regular */
189 #define S_IFLNK 0120000 /* symbolic link */
190 #define S_IFSOCK 0140000 /* socket */
191 #define S_IFWHT 0160000 /* whiteout */
192 #define S_ISUID 0004000 /* set user id on execution */
193 #define S_ISGID 0002000 /* set group id on execution */
194 #define S_ISVTX 0001000 /* save swapped text even after use */
195 #define S_IRUSR 0000400 /* read permission, owner */
196 #define S_IWUSR 0000200 /* write permission, owner */
197 #define S_IXUSR 0000100 /* execute/search permission, owner */
200 For a list of access modes, see
208 Previous versions of the system used different types for the
225 Search permission is denied for a component of the path prefix.
227 An I/O error occurred while reading from or writing to the file system.
229 Too many symbolic links were encountered in translating the pathname.
230 .It Bq Er ENAMETOOLONG
231 A component of a pathname exceeded 255 characters,
232 or an entire path name exceeded 1023 characters.
234 The named file does not exist.
236 A component of the path prefix is not a directory.
241 points to an invalid address.
249 is not a valid open file descriptor.
252 points to an invalid address.
254 An I/O error occurred while reading from or writing to the file system.
269 function calls are expected to conform to
276 function call appeared in
280 function call appeared in
285 to a socket (and thus to a pipe)
286 returns a zeroed buffer,
287 except for the blocksize field,
288 and a unique device and inode number.