[9] | 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.
|
---|
| 4 | .\"
|
---|
| 5 | .\" @(#)stat.2 6.5 (Berkeley) 5/12/86
|
---|
| 6 | .\"
|
---|
| 7 | .TH STAT 2 "May 12, 1986"
|
---|
| 8 | .UC 4
|
---|
| 9 | .SH NAME
|
---|
| 10 | stat, lstat, fstat \- get file status
|
---|
| 11 | .SH SYNOPSIS
|
---|
| 12 | .nf
|
---|
| 13 | .ft B
|
---|
| 14 | #include <sys/types.h>
|
---|
| 15 | #include <sys/stat.h>
|
---|
| 16 |
|
---|
| 17 | .ta +54n
|
---|
| 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)
|
---|
| 21 | .fi
|
---|
| 22 | .ft R
|
---|
| 23 | .SH DESCRIPTION
|
---|
| 24 | .B Stat
|
---|
| 25 | obtains information about the file
|
---|
| 26 | .IR path .
|
---|
| 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.
|
---|
| 30 | .PP
|
---|
| 31 | .B Lstat
|
---|
| 32 | is like \fBstat\fP except in the case where the named file is a symbolic link,
|
---|
| 33 | in which case
|
---|
| 34 | .B lstat
|
---|
| 35 | returns information about the link,
|
---|
| 36 | while
|
---|
| 37 | .B stat
|
---|
| 38 | returns information about the file the link references.
|
---|
| 39 | .PP
|
---|
| 40 | .B Fstat
|
---|
| 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.
|
---|
| 47 | .PP
|
---|
| 48 | .I Buf
|
---|
| 49 | is a pointer to a
|
---|
| 50 | .B stat
|
---|
| 51 | structure into which information is placed concerning the file.
|
---|
| 52 | The contents of the structure pointed to by
|
---|
| 53 | .I buf
|
---|
| 54 | is as follows:
|
---|
| 55 | .PP
|
---|
| 56 | .if t .RS
|
---|
| 57 | .nf
|
---|
| 58 | .ta +0.4i +0.8i +1i
|
---|
| 59 | struct stat {
|
---|
| 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 */
|
---|
| 71 | };
|
---|
| 72 | .fi
|
---|
| 73 | .if t .RE
|
---|
| 74 | .DT
|
---|
| 75 | .PP
|
---|
| 76 | .TP 12
|
---|
| 77 | st_atime
|
---|
| 78 | Time when file data was last read or modified. Changed by the following system
|
---|
| 79 | calls:
|
---|
| 80 | .BR mknod (2),
|
---|
| 81 | .BR utime (2),
|
---|
| 82 | .BR read (2),
|
---|
| 83 | and
|
---|
| 84 | .BR write (2).
|
---|
| 85 | For reasons of efficiency,
|
---|
| 86 | st_atime is not set when a directory
|
---|
| 87 | is searched, although this would be more logical.
|
---|
| 88 | .TP 12
|
---|
| 89 | st_mtime
|
---|
| 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:
|
---|
| 93 | .BR mknod (2),
|
---|
| 94 | .BR utime (2),
|
---|
| 95 | .BR write (2).
|
---|
| 96 | .TP 12
|
---|
| 97 | st_ctime
|
---|
| 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:
|
---|
| 101 | .BR chmod (2)
|
---|
| 102 | .BR chown (2),
|
---|
| 103 | .BR link (2),
|
---|
| 104 | .BR mknod (2),
|
---|
| 105 | .BR rename (2),
|
---|
| 106 | .BR unlink (2),
|
---|
| 107 | .BR utime (2),
|
---|
| 108 | .BR write (2).
|
---|
| 109 | .PP
|
---|
| 110 | The file type information in \fBst_mode\fP has bits:
|
---|
| 111 | .PP
|
---|
| 112 | .nf
|
---|
| 113 | .in +5n
|
---|
| 114 | .ta 1.6i 2.5i 3i
|
---|
| 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 */
|
---|
| 122 | .fi
|
---|
| 123 | .in -5n
|
---|
| 124 | .PP
|
---|
| 125 | The mode bits 0007777 encode set-uid/gid bits and
|
---|
| 126 | permission bits (see
|
---|
| 127 | .BR chmod (2)).
|
---|
| 128 | .SH "RETURN VALUE
|
---|
| 129 | Upon successful completion a value of 0 is returned.
|
---|
| 130 | Otherwise, a value of \-1 is returned and
|
---|
| 131 | .B errno
|
---|
| 132 | is set to indicate the error.
|
---|
| 133 | .SH "ERRORS
|
---|
| 134 | .B Stat
|
---|
| 135 | and
|
---|
| 136 | .B lstat
|
---|
| 137 | will fail if one or more of the following are true:
|
---|
| 138 | .TP 15
|
---|
| 139 | [ENOTDIR]
|
---|
| 140 | A component of the path prefix is not a directory.
|
---|
| 141 | .TP 15
|
---|
| 142 | [ENAMETOOLONG]
|
---|
| 143 | The path name exceeds PATH_MAX characters.
|
---|
| 144 | .TP 15
|
---|
| 145 | [ENOENT]
|
---|
| 146 | The named file does not exist.
|
---|
| 147 | .TP 15
|
---|
| 148 | [EACCES]
|
---|
| 149 | Search permission is denied for a component of the path prefix.
|
---|
| 150 | .TP 15
|
---|
| 151 | [ELOOP]
|
---|
| 152 | Too many symbolic links were encountered in translating the pathname.
|
---|
| 153 | .TP 15
|
---|
| 154 | [EFAULT]
|
---|
| 155 | .I Buf
|
---|
| 156 | or
|
---|
| 157 | .I name
|
---|
| 158 | points to an invalid address.
|
---|
| 159 | .TP 15
|
---|
| 160 | [EIO]
|
---|
| 161 | An I/O error occurred while reading from or writing to the file system.
|
---|
| 162 | .PP
|
---|
| 163 | .B Fstat
|
---|
| 164 | will fail if one or both of the following are true:
|
---|
| 165 | .TP 15
|
---|
| 166 | [EBADF]
|
---|
| 167 | .I Fildes
|
---|
| 168 | is not a valid open file descriptor.
|
---|
| 169 | .TP 15
|
---|
| 170 | [EFAULT]
|
---|
| 171 | .I Buf
|
---|
| 172 | points to an invalid address.
|
---|
| 173 | .TP 15
|
---|
| 174 | [EIO]
|
---|
| 175 | An I/O error occurred while reading from or writing to the file system.
|
---|
| 176 | .SH "SEE ALSO"
|
---|
| 177 | .BR chmod (2),
|
---|
| 178 | .BR chown (2),
|
---|
| 179 | .BR utime (2).
|
---|