1 .\" Copyright (c) 1980 Regents of the University of California.
2 .\" All rights reserved. The Berkeley software License Agreement
3 .\" specifies the terms and conditions for redistribution.
5 .\" @(#)stat.2 6.5 (Berkeley) 5/12/86
7 .TH STAT 2 "May 12, 1986"
10 stat, lstat, fstat \- get file status
14 #include <sys/types.h>
18 int stat(const char *\fIpath\fP, struct stat *\fIbuf\fP)
19 int lstat(const char *\fIpath\fP, struct stat *\fIbuf\fP)
20 int fstat(int \fIfd\fP, struct stat *\fIbuf\fP)
25 obtains information about the file
27 Read, write or execute
28 permission of the named file is not required, but all directories
29 listed in the path name leading to the file must be reachable.
32 is like \fBstat\fP except in the case where the named file is a symbolic link,
35 returns information about the link,
38 returns information about the file the link references.
41 obtains the same information about an open file
42 referenced by the argument descriptor, such as would
43 be obtained by an \fBopen\fP call. Pipe descriptors
44 look like named pipes with a link count of zero. The
45 st_size field of pipes or named pipes shows the amount of
46 bytes currently buffered in the pipe.
51 structure into which information is placed concerning the file.
52 The contents of the structure pointed to by
60 dev_t st_dev; /* device inode resides on */
61 ino_t st_ino; /* this inode's number */
62 mode_t st_mode; /* file mode, protection bits, etc. */
63 nlink_t st_nlink; /* number or hard links to the file */
64 uid_t st_uid; /* user-id of the file's owner */
65 gid_t st_gid; /* group-id of the file's owner */
66 dev_t st_rdev; /* the device type, for inode that is device */
67 off_t st_size; /* total size of file */
68 time_t st_atime; /* time of last access */
69 time_t st_mtime; /* time of last data modification */
70 time_t st_ctime; /* time of last file status change */
78 Time when file data was last read or modified. Changed by the following system
85 For reasons of efficiency,
86 st_atime is not set when a directory
87 is searched, although this would be more logical.
90 Time when data was last modified.
91 It is not set by changes of owner, group, link count, or mode.
92 Changed by the following system calls:
98 Time when file status was last changed.
99 It is set both both by writing and changing the i-node.
100 Changed by the following system calls:
110 The file type information in \fBst_mode\fP has bits:
115 #define S_IFMT 0170000 /* type of file */
116 #define\ \ \ \ S_IFIFO 0010000 /* named pipe */
117 #define\ \ \ \ S_IFCHR 0020000 /* character special */
118 #define\ \ \ \ S_IFDIR 0040000 /* directory */
119 #define\ \ \ \ S_IFBLK 0060000 /* block special */
120 #define\ \ \ \ S_IFREG 0100000 /* regular */
121 #define\ \ \ \ S_IFLNK 0120000 /* symbolic link */
125 The mode bits 0007777 encode set-uid/gid bits and
129 Upon successful completion a value of 0 is returned.
130 Otherwise, a value of \-1 is returned and
132 is set to indicate the error.
137 will fail if one or more of the following are true:
140 A component of the path prefix is not a directory.
143 The path name exceeds PATH_MAX characters.
146 The named file does not exist.
149 Search permission is denied for a component of the path prefix.
152 Too many symbolic links were encountered in translating the pathname.
158 points to an invalid address.
161 An I/O error occurred while reading from or writing to the file system.
164 will fail if one or both of the following are true:
168 is not a valid open file descriptor.
172 points to an invalid address.
175 An I/O error occurred while reading from or writing to the file system.