source: trunk/minix/man/man2/stat.2@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 4.4 KB
Line 
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
10stat, 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
18int stat(const char *\fIpath\fP, struct stat *\fIbuf\fP)
19int lstat(const char *\fIpath\fP, struct stat *\fIbuf\fP)
20int fstat(int \fIfd\fP, struct stat *\fIbuf\fP)
21.fi
22.ft R
23.SH DESCRIPTION
24.B Stat
25obtains information about the file
26.IR path .
27Read, write or execute
28permission of the named file is not required, but all directories
29listed in the path name leading to the file must be reachable.
30.PP
31.B Lstat
32is like \fBstat\fP except in the case where the named file is a symbolic link,
33in which case
34.B lstat
35returns information about the link,
36while
37.B stat
38returns information about the file the link references.
39.PP
40.B Fstat
41obtains the same information about an open file
42referenced by the argument descriptor, such as would
43be obtained by an \fBopen\fP call. Pipe descriptors
44look like named pipes with a link count of zero. The
45st_size field of pipes or named pipes shows the amount of
46bytes currently buffered in the pipe.
47.PP
48.I Buf
49is a pointer to a
50.B stat
51structure into which information is placed concerning the file.
52The contents of the structure pointed to by
53.I buf
54is as follows:
55.PP
56.if t .RS
57.nf
58.ta +0.4i +0.8i +1i
59struct 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
77st_atime
78Time when file data was last read or modified. Changed by the following system
79calls:
80.BR mknod (2),
81.BR utime (2),
82.BR read (2),
83and
84.BR write (2).
85For reasons of efficiency,
86st_atime is not set when a directory
87is searched, although this would be more logical.
88.TP 12
89st_mtime
90Time when data was last modified.
91It is not set by changes of owner, group, link count, or mode.
92Changed by the following system calls:
93.BR mknod (2),
94.BR utime (2),
95.BR write (2).
96.TP 12
97st_ctime
98Time when file status was last changed.
99It is set both both by writing and changing the i-node.
100Changed 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
110The 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
125The mode bits 0007777 encode set-uid/gid bits and
126permission bits (see
127.BR chmod (2)).
128.SH "RETURN VALUE
129Upon successful completion a value of 0 is returned.
130Otherwise, a value of \-1 is returned and
131.B errno
132is set to indicate the error.
133.SH "ERRORS
134.B Stat
135and
136.B lstat
137will fail if one or more of the following are true:
138.TP 15
139[ENOTDIR]
140A component of the path prefix is not a directory.
141.TP 15
142[ENAMETOOLONG]
143The path name exceeds PATH_MAX characters.
144.TP 15
145[ENOENT]
146The named file does not exist.
147.TP 15
148[EACCES]
149Search permission is denied for a component of the path prefix.
150.TP 15
151[ELOOP]
152Too many symbolic links were encountered in translating the pathname.
153.TP 15
154[EFAULT]
155.I Buf
156or
157.I name
158points to an invalid address.
159.TP 15
160[EIO]
161An I/O error occurred while reading from or writing to the file system.
162.PP
163.B Fstat
164will fail if one or both of the following are true:
165.TP 15
166[EBADF]
167.I Fildes
168is not a valid open file descriptor.
169.TP 15
170[EFAULT]
171.I Buf
172points to an invalid address.
173.TP 15
174[EIO]
175An 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).
Note: See TracBrowser for help on using the repository browser.