Commit | Line | Data |
---|---|---|
2cf6fecc C |
1 | |
2 | ||
3 | ||
4 | STAT(2) UNIX Programmer's Manual STAT(2) | |
5 | ||
6 | ||
7 | ||
8 | N\bNA\bAM\bME\bE | |
9 | stat, lstat, fstat - get file status | |
10 | ||
11 | S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS | |
12 | #\b#i\bin\bnc\bcl\blu\bud\bde\be <\b<s\bsy\bys\bs/\b/t\bty\byp\bpe\bes\bs.\b.h\bh>\b> | |
13 | #\b#i\bin\bnc\bcl\blu\bud\bde\be <\b<s\bsy\bys\bs/\b/s\bst\bta\bat\bt.\b.h\bh>\b> | |
14 | ||
15 | s\bst\bta\bat\bt(\b(p\bpa\bat\bth\bh,\b, b\bbu\buf\bf)\b) | |
16 | c\bch\bha\bar\br *\b*p\bpa\bat\bth\bh;\b; | |
17 | s\bst\btr\bru\buc\bct\bt s\bst\bta\bat\bt *\b*b\bbu\buf\bf;\b; | |
18 | ||
19 | l\bls\bst\bta\bat\bt(\b(p\bpa\bat\bth\bh,\b, b\bbu\buf\bf)\b) | |
20 | c\bch\bha\bar\br *\b*p\bpa\bat\bth\bh;\b; | |
21 | s\bst\btr\bru\buc\bct\bt s\bst\bta\bat\bt *\b*b\bbu\buf\bf;\b; | |
22 | ||
23 | f\bfs\bst\bta\bat\bt(\b(f\bfd\bd,\b, b\bbu\buf\bf)\b) | |
24 | i\bin\bnt\bt f\bfd\bd;\b; | |
25 | s\bst\btr\bru\buc\bct\bt s\bst\bta\bat\bt *\b*b\bbu\buf\bf;\b; | |
26 | ||
27 | D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN | |
28 | _\bS_\bt_\ba_\bt obtains information about the file _\bp_\ba_\bt_\bh. Read, write | |
29 | or execute permission of the named file is not required, but | |
30 | all directories listed in the path name leading to the file | |
31 | must be reachable. | |
32 | ||
33 | _\bL_\bs_\bt_\ba_\bt is like _\bs_\bt_\ba_\bt except in the case where the named file | |
34 | is a symbolic link, in which case _\bl_\bs_\bt_\ba_\bt returns information | |
35 | about the link, while _\bs_\bt_\ba_\bt returns information about the | |
36 | file the link references. | |
37 | ||
38 | _\bF_\bs_\bt_\ba_\bt obtains the same information about an open file refer- | |
39 | enced by the argument descriptor, such as would be obtained | |
40 | by an _\bo_\bp_\be_\bn call. | |
41 | ||
42 | _\bB_\bu_\bf is a pointer to a _\bs_\bt_\ba_\bt structure into which information | |
43 | is placed concerning the file. The contents of the struc- | |
44 | ture pointed to by _\bb_\bu_\bf | |
45 | ||
46 | struct stat { | |
47 | dev_t st_dev; /* device inode resides on */ | |
48 | ino_t st_ino; /* this inode's number */ | |
49 | u_short st_mode;/* protection */ | |
50 | short st_nlink;/* number or hard links to the file */ | |
51 | uid_t st_uid; /* user-id of owner */ | |
52 | gid_t st_gid; /* group-id of owner */ | |
53 | dev_t st_rdev;/* the device type, for inode that is device */ | |
54 | off_t st_size;/* total size of file */ | |
55 | time_t st_atime;/* file last access time */ | |
56 | int st_spare1; | |
57 | time_t st_mtime;/* file last modify time */ | |
58 | int st_spare2; | |
59 | time_t st_ctime;/* file last status change time */ | |
60 | ||
61 | ||
62 | ||
63 | Printed 7/9/88 October 25, 1987 1 | |
64 | ||
65 | ||
66 | ||
67 | ||
68 | ||
69 | ||
70 | STAT(2) UNIX Programmer's Manual STAT(2) | |
71 | ||
72 | ||
73 | ||
74 | int st_spare3; | |
75 | long st_blksize;/* optimal blocksize for file system i/o ops */ | |
76 | long st_blocks;/* actual number of blocks allocated */ | |
77 | long st_spare4[2]; | |
78 | }; | |
79 | ||
80 | st_atime Time when file data was last accessed. Changed | |
81 | by the following system calls: _\bm_\bk_\bn_\bo_\bd(2), | |
82 | _\bu_\bt_\bi_\bm_\be_\bs(2), and _\br_\be_\ba_\bd(2). For reasons of effi- | |
83 | ciency, st_atime is not set when a directory is | |
84 | searched, although this would be more logical. | |
85 | ||
86 | st_mtime Time when data was last modified. It is not set | |
87 | by changes of owner, group, link count, or mode. | |
88 | Changed by the following system calls: _\bm_\bk_\bn_\bo_\bd(2), | |
89 | _\bu_\bt_\bi_\bm_\be_\bs(2), _\bw_\br_\bi_\bt_\be(2). | |
90 | ||
91 | st_ctime Time when file status was last changed. It is | |
92 | set both both by writing and changing the i- | |
93 | node. Changed by the following system calls: | |
94 | _\bc_\bh_\bm_\bo_\bd(2) _\bc_\bh_\bo_\bw_\bn(2), _\bl_\bi_\bn_\bk(2), _\bm_\bk_\bn_\bo_\bd(2), _\br_\be_\bn_\ba_\bm_\be(2), | |
95 | _\bu_\bn_\bl_\bi_\bn_\bk(2), _\bu_\bt_\bi_\bm_\be_\bs(2), _\bw_\br_\bi_\bt_\be(2). | |
96 | ||
97 | The status information word _\bs_\bt__\bm_\bo_\bd_\be has bits: | |
98 | #define S_IFMT 0170000 /* type of file */ | |
99 | #define S_IFDIR 0040000/* directory */ | |
100 | #define S_IFCHR 0020000/* character special */ | |
101 | #define S_IFBLK 0060000/* block special */ | |
102 | #define S_IFREG 0100000/* regular */ | |
103 | #define S_IFLNK 0120000/* symbolic link */ | |
104 | #define S_IFSOCK 0140000/* socket */ | |
105 | #define S_ISUID 0004000 /* set user id on execution */ | |
106 | #define S_ISGID 0002000 /* set group id on execution */ | |
107 | #define S_ISVTX 0001000 /* save swapped text even after use */ | |
108 | #define S_IREAD 0000400 /* read permission, owner */ | |
109 | #define S_IWRITE 0000200/* write permission, owner */ | |
110 | #define S_IEXEC 0000100 /* execute/search permission, owner */ | |
111 | ||
112 | The mode bits 0000070 and 0000007 encode group and others | |
113 | permissions (see _\bc_\bh_\bm_\bo_\bd(2)). | |
114 | ||
115 | R\bRE\bET\bTU\bUR\bRN\bN V\bVA\bAL\bLU\bUE\bE | |
116 | Upon successful completion a value of 0 is returned. Other- | |
117 | wise, a value of -1 is returned and _\be_\br_\br_\bn_\bo is set to indicate | |
118 | the error. | |
119 | ||
120 | E\bER\bRR\bRO\bOR\bRS\bS | |
121 | _\bS_\bt_\ba_\bt and _\bl_\bs_\bt_\ba_\bt will fail if one or more of the following are | |
122 | true: | |
123 | ||
124 | [ENOTDIR] A component of the path prefix is not a | |
125 | directory. | |
126 | ||
127 | ||
128 | ||
129 | Printed 7/9/88 October 25, 1987 2 | |
130 | ||
131 | ||
132 | ||
133 | ||
134 | ||
135 | ||
136 | STAT(2) UNIX Programmer's Manual STAT(2) | |
137 | ||
138 | ||
139 | ||
140 | [EINVAL] The pathname contains a character with the | |
141 | high-order bit set. | |
142 | ||
143 | [ENAMETOOLONG] A component of a pathname exceeded 255 char- | |
144 | acters, or an entire path name exceeded 1023 | |
145 | characters. | |
146 | ||
147 | [ENOENT] The named file does not exist. | |
148 | ||
149 | [EACCES] Search permission is denied for a component | |
150 | of the path prefix. | |
151 | ||
152 | [ELOOP] Too many symbolic links were encountered in | |
153 | translating the pathname. | |
154 | ||
155 | [EFAULT] _\bB_\bu_\bf or _\bn_\ba_\bm_\be points to an invalid address. | |
156 | ||
157 | [EIO] An I/O error occurred while reading from or | |
158 | writing to the file system. | |
159 | ||
160 | _\bF_\bs_\bt_\ba_\bt will fail if one or both of the following are true: | |
161 | ||
162 | [EBADF] _\bF_\bi_\bl_\bd_\be_\bs is not a valid open file descriptor. | |
163 | ||
164 | [EFAULT] _\bB_\bu_\bf points to an invalid address. | |
165 | ||
166 | [EIO] An I/O error occurred while reading from or | |
167 | writing to the file system. | |
168 | ||
169 | C\bCA\bAV\bVE\bEA\bAT\bT | |
170 | The fields in the stat structure currently marked _\bs_\bt__\bs_\bp_\ba_\br_\be_\b1, | |
171 | _\bs_\bt__\bs_\bp_\ba_\br_\be_\b2, and _\bs_\bt__\bs_\bp_\ba_\br_\be_\b3 are present in preparation for | |
172 | inode time stamps expanding to 64 bits. This, however, can | |
173 | break certain programs that depend on the time stamps being | |
174 | contiguous (in calls to _\bu_\bt_\bi_\bm_\be_\bs(2)). | |
175 | ||
176 | S\bSE\bEE\bE A\bAL\bLS\bSO\bO | |
177 | chmod(2), chown(2), utimes(2) | |
178 | ||
179 | B\bBU\bUG\bGS\bS | |
180 | Applying _\bf_\bs_\bt_\ba_\bt to a socket (and thus to a pipe) returns a | |
181 | zero'd buffer, except for the blocksize field, and a unique | |
182 | device and inode number. | |
183 | ||
184 | ||
185 | ||
186 | ||
187 | ||
188 | ||
189 | ||
190 | ||
191 | ||
192 | ||
193 | ||
194 | ||
195 | Printed 7/9/88 October 25, 1987 3 | |
196 | ||
197 | ||
198 |