improved english
[unix-history] / usr / src / lib / libc / sys / stat.2
CommitLineData
924d83cf
KM
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.\"
eff6446c 5.\" @(#)stat.2 6.3 (Berkeley) %G%
924d83cf 6.\"
9d2e549b 7.TH STAT 2 ""
924d83cf
KM
8.UC 4
9.SH NAME
7b1f0e33 10stat, lstat, fstat \- get file status
924d83cf
KM
11.SH SYNOPSIS
12.nf
7b1f0e33
KM
13.ft B
14#include <sys/types.h>
15#include <sys/stat.h>
924d83cf 16.PP
7b1f0e33
KM
17.ft B
18stat(path, buf)
19char *path;
20struct stat *buf;
924d83cf 21.PP
7b1f0e33
KM
22.ft B
23lstat(path, buf)
24char *path;
25struct stat *buf;
26.PP
27.ft B
28fstat(fd, buf)
29int fd;
30struct stat *buf;
924d83cf 31.fi
7b1f0e33 32.ft R
924d83cf
KM
33.SH DESCRIPTION
34.I Stat
7b1f0e33
KM
35obtains information about the file
36.IR path .
37Read, write or execute
38permission of the named file is not required, but all directories
39listed in the path name leading to the file must be reachable.
40.PP
41.I Lstat
42is like \fIstat\fP except in the case where the named file is a symbolic link,
43in which case
44.I lstat
45returns information about the link,
46while
47.I stat
48returns information about the file the link references.
49.PP
924d83cf
KM
50.I Fstat
51obtains the same information about an open file
7b1f0e33
KM
52referenced by the argument descriptor, such as would
53be obtained by an \fIopen\fP call.
924d83cf 54.PP
7b1f0e33
KM
55.I Buf
56is a pointer to a
57.I stat
58structure into which information is placed concerning the file.
59The contents of the structure pointed to by
924d83cf 60.I buf
924d83cf
KM
61.PP
62.nf
7b1f0e33
KM
63.ta 1i 1.7i 2.5i
64 struct stat {
65 dev_t st_dev; /* device inode resides on */
66 ino_t st_ino; /* this inode's number */
67 u_short st_mode; /* protection */
68 short st_nlink; /* number or hard links to the file */
69 short st_uid; /* user-id of owner */
70 short st_gid; /* group-id of owner */
71 dev_t st_rdev; /* the device type, for inode that is device */
72 off_t st_size; /* total size of file */
73 time_t st_atime; /* file last access time */
74 int st_spare1;
75 time_t st_mtime; /* file last modify time */
76 int st_spare2;
77 time_t st_ctime; /* file last status change time */
78 int st_spare3;
79 long st_blksize; /* optimal blocksize for file system i/o ops */
80 long st_blocks; /* actual number of blocks allocated */
81 long st_spare4[2];
82 };
924d83cf
KM
83.fi
84.DT
85.PP
7b1f0e33
KM
86.TP 12
87st_atime
88Time when file data was last read or modified. Changed by the following system
89calls:
90.IR mknod (2),
91.IR utimes (2),
92.IR read (2),
93and
94.IR write (2).
95For reasons of efficiency,
96st_atime is not set when a directory
97is searched, although this would be more logical.
98.TP 12
99st_mtime
100Time when data was last modified.
101It is not set by changes of owner, group, link count, or mode.
102Changed by the following system calls:
103.IR mknod (2),
104.IR utimes (2),
105.IR write (2).
106.TP 12
107st_ctime
108Time when file status was last changed.
109It is set both both by writing and changing the i-node.
110Changed by the following system calls:
111.IR chmod (2)
112.IR chown (2),
113.IR link (2),
114.IR mknod (2),
115.IR unlink (2),
116.IR utimes (2),
117.IR write (2).
118.PP
119The status information word \fIst_mode\fP has bits:
120.nf
121.in +5n
122.ta 1.6i 2.5i 3i
123#define S_IFMT 0170000 /* type of file */
124#define\ \ \ \ S_IFDIR 0040000 /* directory */
125#define\ \ \ \ S_IFCHR 0020000 /* character special */
126#define\ \ \ \ S_IFBLK 0060000 /* block special */
127#define\ \ \ \ S_IFREG 0100000 /* regular */
128#define\ \ \ \ S_IFLNK 0120000 /* symbolic link */
129#define\ \ \ \ S_IFSOCK 0140000 /* socket */
130#define S_ISUID 0004000 /* set user id on execution */
131#define S_ISGID 0002000 /* set group id on execution */
132#define S_ISVTX 0001000 /* save swapped text even after use */
133#define S_IREAD 0000400 /* read permission, owner */
134#define S_IWRITE 0000200 /* write permission, owner */
135#define S_IEXEC 0000100 /* execute/search permission, owner */
136.fi
137.in -5n
138.PP
924d83cf
KM
139The mode bits 0000070 and 0000007 encode group and
140others permissions (see
141.IR chmod (2)).
7b1f0e33
KM
142.SH "RETURN VALUE
143Upon successful completion a value of 0 is returned.
144Otherwise, a value of \-1 is returned and
145.I errno
146is set to indicate the error.
147.SH "ERRORS
148.I Stat
149and
150.I lstat
151will fail if one or more of the following are true:
152.TP 15
153[ENOTDIR]
154A component of the path prefix is not a directory.
155.TP 15
b5984ffe 156[EINVAL]
7b1f0e33
KM
157The pathname contains a character with the high-order bit set.
158.TP 15
b5984ffe
KM
159[ENAMETOOLONG]
160A component of a pathname exceeded 255 characters,
161or an entire path name exceeded 1023 characters.
7b1f0e33
KM
162.TP 15
163[ENOENT]
164The named file does not exist.
165.TP 15
166[EACCES]
167Search permission is denied for a component of the path prefix.
168.TP 15
b5984ffe
KM
169[ELOOP]
170Too many symbolic links were encountered in translating the pathname.
171.TP 15
7b1f0e33
KM
172[EFAULT]
173.I Buf
174or
175.I name
176points to an invalid address.
924d83cf 177.PP
7b1f0e33
KM
178.I Fstat
179will fail if one or both of the following are true:
180.TP 15
181[EBADF]
182.I Fildes
183is not a valid open file descriptor.
184.TP 15
185[EFAULT]
186.I Buf
187points to an invalid address.
7b1f0e33
KM
188.SH CAVEAT
189The fields in the stat structure currently marked
190.IR st_spare1 ,
191.IR st_spare2 ,
192and
193.I st_spare3
194are present in preparation for inode time stamps expanding
eff6446c 195to 64 bits. This, however, can break certain programs that
7b1f0e33
KM
196depend on the time stamps being contiguous (in calls to
197.IR utimes (2)).
924d83cf 198.SH "SEE ALSO"
7b1f0e33
KM
199chmod(2), chown(2), utimes(2)
200.SH BUGS
201Applying
202.I fstat
9d2e549b
KM
203to a socket (and thus to a pipe)
204returns a zero'd buffer, except for the blocksize field.
924d83cf 205.PP
eff6446c 206The list of calls that modify the various fields should be carefully
7b1f0e33 207checked with reality.