|
|
1.1 root 1:
2:
3: fstat() General Function fstat()
4:
5:
6:
7:
8: Find file attributes
9:
10: #include <sys/stat.h>
11: ffssttaatt(_d_e_s_c_r_i_p_t_o_r, _s_t_a_t_p_t_r) iinntt _d_e_s_c_r_i_p_t_o_r; ssttrruucctt ssttaatt *_s_t_a_t_p_t_r;
12:
13: fstat returns a structure that contains the attributes of a file
14: including protection information, file type, and file size.
15: descriptor is the file descriptor for the open file, and statptr
16: points to a structure of the type stat, which is defined in the
17: header file stat.h.
18:
19: The following summarizes the structure stat and defines the per-
20: mission and file type bits.
21:
22:
23: struct stat {
24: dev_t st_dev;
25: ino_t st_ino;
26: unsigned short st_mode;
27: short st_nlink;
28: short st_uid;
29: short st_gid;
30: dev_t st_rdev;
31: size_t st_size;
32: time_t st_atime;
33: time_t st_mtime;
34: time_t st_ctime;
35: };
36:
37:
38:
39: #define S_IFMT 0170000 /* file types */
40: #define S_IFREG 0100000/* ordinary file */
41: #define S_IFDIR 0040000/* directory */
42: #define S_IFCHR 0020000/* character special */
43: #define S_IFBLK 0060000/* block special */
44: #define S_ISUID 0004000/* set user id */
45: #define S_ISGID 0002000/* set group id */
46: #define S_ISVTX 0001000/* save text bit */
47: #define S_IREAD 0000400/* owner read permission */
48: #define S_IWRITE 000200/* owner write permission */
49: #define S_IEXEC 0000100/* owner execute permission */
50:
51:
52: The entries st_dev and st_ino together form a unique description
53: of the file. The former is the device on which the file and its
54: i-node reside, whereas the latter is the index number of the
55: file. The entry st_mode gives the permission bits, as outlined
56: above. The entry st_nlink gives the number of links to the file.
57: The user id and group id of the owner are st_uid and st_gid,
58: respectively. The entry st_rdev, valid only for special files,
59: holds the major and minor numbers for the file.
60:
61:
62:
63:
64: COHERENT Lexicon Page 1
65:
66:
67:
68:
69: fstat() General Function fstat()
70:
71:
72:
73: The entry st_size gives the size of the file, in bytes. For a
74: pipe, the size is the number of bytes waiting to be read from the
75: pipe.
76:
77: Three entries for each file give the last occurrences of various
78: events in the file's history. st_atime gives time the file was
79: last read or written to. st_mtime gives the time of the last
80: modification, write for files, create or delete entry for direc-
81: tories. st_ctime gives the last change to the attributes, not
82: including times and size.
83:
84: ***** Example *****
85:
86: For an example of how to use this function, see the entry for
87: pipe.
88:
89: ***** Files *****
90:
91: <sys/stat.h>
92:
93: ***** See Also *****
94:
95: chmod(), chown(), COHERENT system calls, ls, open(), stat()
96:
97: ***** Notes *****
98:
99: fstat differs from the related function stat mainly in that it
100: accesses the file through its descriptor, which was returned by a
101: successful call to open, whereas stat takes the file's path name
102: and opens it itself before checking its status.
103:
104: ***** Diagnostics *****
105:
106: fstat returns -1 if the file is not found or if statptr is in-
107: valid.
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130: COHERENT Lexicon Page 2
131:
132:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.