• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * @defgroup stat Stat
3  * @ingroup libc
4  */
5 
6 #ifndef	_SYS_STAT_H
7 #define	_SYS_STAT_H
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 #include <features.h>
13 
14 #define __NEED_dev_t
15 #define __NEED_ino_t
16 #define __NEED_mode_t
17 #define __NEED_nlink_t
18 #define __NEED_uid_t
19 #define __NEED_gid_t
20 #define __NEED_off_t
21 #define __NEED_time_t
22 #define __NEED_blksize_t
23 #define __NEED_blkcnt_t
24 #define __NEED_struct_timespec
25 #ifdef __LITEOS__
26 #define __NEED_int64_t
27 #endif
28 
29 #include <bits/alltypes.h>
30 
31 #include <bits/stat.h>
32 
33 #define st_atime st_atim.tv_sec
34 #define st_mtime st_mtim.tv_sec
35 #define st_ctime st_ctim.tv_sec
36 
37 #define S_IFMT  0170000
38 
39 #define S_IFDIR 0040000
40 #define S_IFCHR 0020000
41 #define S_IFBLK 0060000
42 #define S_IFREG 0100000
43 #define S_IFIFO 0010000
44 #define S_IFLNK 0120000
45 #define S_IFSOCK 0140000
46 
47 #define S_TYPEISMQ(buf)  0
48 #define S_TYPEISSEM(buf) 0
49 #define S_TYPEISSHM(buf) 0
50 #define S_TYPEISTMO(buf) 0
51 
52 #define S_ISDIR(mode)  (((mode) & S_IFMT) == S_IFDIR)
53 #define S_ISCHR(mode)  (((mode) & S_IFMT) == S_IFCHR)
54 #define S_ISBLK(mode)  (((mode) & S_IFMT) == S_IFBLK)
55 #define S_ISREG(mode)  (((mode) & S_IFMT) == S_IFREG)
56 #define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO)
57 #define S_ISLNK(mode)  (((mode) & S_IFMT) == S_IFLNK)
58 #define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK)
59 
60 #ifndef S_IRUSR
61 #define S_ISUID 04000
62 #define S_ISGID 02000
63 #define S_ISVTX 01000
64 #define S_IRUSR 0400
65 #define S_IWUSR 0200
66 #define S_IXUSR 0100
67 #define S_IRWXU 0700
68 #define S_IRGRP 0040
69 #define S_IWGRP 0020
70 #define S_IXGRP 0010
71 #define S_IRWXG 0070
72 #define S_IROTH 0004
73 #define S_IWOTH 0002
74 #define S_IXOTH 0001
75 #define S_IRWXO 0007
76 #endif
77 
78 #ifdef __LITEOS__
79 #define DEFFILEMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
80 #endif
81 
82 #define UTIME_NOW  0x3fffffff
83 #define UTIME_OMIT 0x3ffffffe
84 
85 /**
86  * @ingroup stat
87  *
88  * @par Description:
89  * The stat() function shall obtain information about the named file and write it to the area pointed to by the buf
90  * argument.
91  * @param path  [IN] Points to a pathname naming a file.
92  * @param buf   [IN] A pointer to a stat structure, defined in the <sys/stat.h> header,
93  *                   which stores information related to files.
94  * @attention
95  * <ul>
96  * <li>None.</li>
97  * </ul>
98  *
99  * @retval #0  Upon successful completion.
100  * @retval #-1 Failed and set errno to indicate the error.
101  *
102  * @par Errors
103  * <ul>
104  * <li><b>EINVAL</b>: Invalid argument.</li>
105  * <li><b>ENOENT</b>: A directory component in pathname does not exist or path is an empty string.</li>
106  * <li><b>ENAMETOOLONG</b>: The length of a component of a pathname is longer than {NAME_MAX}.</li>
107  * <li><b>ENOMEM</b>: Out of memory.</li>
108  * <li><b>ENOSYS</b>: No support.</li>
109  * <li><b>EBADF</b>: The fd argument is not a valid file descriptor or or the underlying file system does not support
110  * this operation.</li>
111  * <li><b>EAGAIN</b>: The file list is NULL.</li>
112  * <li><b>EACCES</b>: Permission bits of the file mode do not permit the requested access,
113  * or search permission is denied on a component of the path prefix.</li>
114  * <li><b>EEXIST</b>: The file/directory object is already exist.</li>
115  * <li><b>EIO</b>: An I/O error occurred while reading from or writing to a file system.</li>
116  * <li><b>EROFS</b>: The physical drive is write protected.</li>
117  * <li><b>ENOSPC</b>: No space left on device.</li>
118  * <li><b>ENFILE</b>: The maximum allowable number of files is currently open in the system.</li>
119  * <li><b>ENOTEMPTY</b>: directory not empty.</li>
120  * <li><b>EISDIR</b>: The named file is a directory.</li>
121  * <li><b>ENOTDIR</b>: A component of the path prefix names an existing file that is neither a directory nor a symbolic
122  * link to a directory; or the path argument resolves to a non-directory file.</li>
123  * <li><b>EPERM</b>: Operation not permitted or access denied due to prohibited access or directory full.</li>
124  * <li><b>EBUSY</b>: The operation is rejected according to the file sharing policy.</li>
125  * <li><b>ENOSYS</b>: Not support.</li>
126  * <li><b>EPROTO</b>: Protocol error in nfs.</li>
127  * <li><b>ENODEV</b>: No such device.</li>
128  * <li><b>EFAULT</b>: Bad address.</li>
129  * </ul>
130  *
131  * @par Dependency:
132  * <ul><li>stat.h</li></ul>
133  * @see None
134  */
135 int stat(const char *__restrict, struct stat *__restrict);
136 
137 /**
138  * @ingroup stat
139  *
140  * @par Description:
141  * The fstat() function shall obtain information about an open file associated with the file descriptor fildes, and shall
142  * write it to the area pointed to by buf.
143  * @param fildes [IN] File descriptor fildes.
144  * @param buf    [IN] A pointer to a stat structure, defined in the <sys/stat.h> header,
145  *                    which stores information related to files.
146  * @attention
147  * <ul>
148  * <li>None.</li>
149  * </ul>
150  *
151  * @retval #0  Upon successful completion.
152  * @retval #-1 Failed and set errno to indicate the error.
153  *
154  * @par Errors
155  * <ul>
156  * <li><b>EBADF</b>: The fd argument is not a valid file descriptor.</li>
157  * <li><b>EAGAIN</b>: The file list is NULL.</li>
158  * <li><b>EINVAL</b>: Invalid argument.</li>
159  * <li><b>ENOENT</b>: a directory component in pathname does not exist or path is an empty string.</li>
160  * <li><b>ENAMETOOLONG</b>: The length of a component of a pathname is longer than {NAME_MAX}.</li>
161  * <li><b>ENOMEM</b>: Out of memory.</li>
162  * <li><b>ENOSYS</b>: no support.</li>
163  * <li><b>EBADF</b>: The fd argument is not a valid file descriptor or or the underlying file system does not support
164  * this operation.</li>
165  * <li><b>EAGAIN</b>: The file list is NULL.</li>
166  * <li><b>EACCES</b>: Permission bits of the file mode do not permit the requested access,
167  * or search permission is denied on a component of the path prefix.</li>
168  * <li><b>EEXIST</b>: The file/directory object is already exist.</li>
169  * <li><b>EIO</b>: An I/O error occurred while reading from or writing to a file system.</li>
170  * <li><b>EROFS</b>: The physical drive is write protected.</li>
171  * <li><b>ENOSPC</b>: No space left on device.</li>
172  * <li><b>ENFILE</b>: The maximum allowable number of files is currently open in the system.</li>
173  * <li><b>ENOTEMPTY</b>: directory not empty.</li>
174  * <li><b>EISDIR</b>: The named file is a directory.</li>
175  * <li><b>ENOTDIR</b>: A component of the path prefix names an existing file that is neither a directory nor a symbolic
176  * link to a directory; or the path argument resolves to a non-directory file.</li>
177  * <li><b>EPERM</b>: operation not permitted or access denied due to prohibited access or directory full.</li>
178  * <li><b>EBUSY</b>: The operation is rejected according to the file sharing policy.</li>
179  * <li><b>ENOSYS</b>: not support.</li>
180  * <li><b>EPROTO</b>: Protocol error in nfs.</li>
181  * <li><b>ENODEV</b>: No such device.</li>
182  * <li><b>EFAULT</b>: Bad address.</li>
183  * </ul>
184  *
185  * @par Dependency:
186  * <ul><li>stat.h</li></ul>
187  * @see None
188  */
189 int fstat(int, struct stat *);
190 
191 /**
192  * @ingroup stat
193  *
194  * @par Description:
195  * The lstat() function shall be equivalent to stat(), function shall obtain information about the named file and write
196  * it to the area pointed to by the buf.
197  * argument.
198  * @param path   [IN] Points to a pathname naming a file.
199  * @param buffer [IN] A pointer to a stat structure, defined in the <sys/stat.h> header,
200  *                    which stores information related to files.
201  * @attention
202  * <ul>
203  * <li>None.</li>
204  * </ul>
205  *
206  * @retval #0  Upon successful completion.
207  * @retval #-1 Failed and set errno to indicate the error.
208  *
209  * @par Errors
210  * <ul>
211  * <li><b>EINVAL</b>: Invalid argument.</li>
212  * <li><b>ENOENT</b>: A directory component in pathname does not exist or path is an empty string.</li>
213  * <li><b>ENAMETOOLONG</b>: The length of a component of a pathname is longer than {NAME_MAX}.</li>
214  * <li><b>ENOMEM</b>: Out of memory.</li>
215  * <li><b>ENOSYS</b>: No support.</li>
216  * <li><b>EBADF</b>: The fd argument is not a valid file descriptor or or the underlying file system does not support
217  * this operation.</li>
218  * <li><b>EAGAIN</b>: The file list is NULL.</li>
219  * <li><b>EACCES</b>: Permission bits of the file mode do not permit the requested access,
220  * or search permission is denied on a component of the path prefix.</li>
221  * <li><b>EEXIST</b>: The file/directory object is already exist.</li>
222  * <li><b>EIO</b>: An I/O error occurred while reading from or writing to a file system.</li>
223  * <li><b>EROFS</b>: The physical drive is write protected.</li>
224  * <li><b>ENOSPC</b>: No space left on device.</li>
225  * <li><b>ENFILE</b>: The maximum allowable number of files is currently open in the system.</li>
226  * <li><b>ENOTEMPTY</b>: directory not empty.</li>
227  * <li><b>EISDIR</b>: The named file is a directory.</li>
228  * <li><b>ENOTDIR</b>: A component of the path prefix names an existing file that is neither a directory nor a symbolic
229  * link to a directory; or the path argument resolves to a non-directory file.</li>
230  * <li><b>EPERM</b>: Operation not permitted or access denied due to prohibited access or directory full.</li>
231  * <li><b>EBUSY</b>: The operation is rejected according to the file sharing policy.</li>
232  * <li><b>ENOSYS</b>: Not support.</li>
233  * <li><b>EPROTO</b>: Protocol error in nfs.</li>
234  * <li><b>ENODEV</b>: No such device.</li>
235  * <li><b>EFAULT</b>: Bad address.</li>
236  * </ul>
237  *
238  * @par Dependency:
239  * <ul><li>stat.h</li></ul>
240  * @see None
241  */
242 int lstat(const char *__restrict, struct stat *__restrict);
243 int fstatat(int, const char *__restrict, struct stat *__restrict, int);
244 int chmod(const char *, mode_t);
245 int fchmod(int, mode_t);
246 int fchmodat(int, const char *, mode_t, int);
247 mode_t umask(mode_t);
248 
249 /**
250  * @ingroup stat
251  *
252  * @par Description:
253  * The mkdir() function shall create a new directory with name path. The file permission bits of the new directory shall
254  * be initialized from mode. These file permission bits of the mode argument shall be modified by the process' file
255  * creation mask.
256  * @param pathname [IN] Directory with name path.
257  * @param mode     [IN] File permission bits.
258  * @attention
259  * <ul>
260  * <li>None.</li>
261  * </ul>
262  *
263  * @retval #0  Upon successful completion.
264  * @retval #-1 Failed and set errno to indicate the error.
265  *
266  * @par Errors
267  * <ul>
268  * <li><b>EINVAL</b>: The path is a null pointer or an empty string.</li>
269  * <li><b>EACCES</b>: Permission bits of the file mode do not permit the requested access,
270  * or search permission is denied on a component of the path prefix.</li>
271  * <li><b>ENAMETOOLONG</b>: The length of a component of a pathname is longer than {NAME_MAX}.</li>
272  * <li><b>ENOENT</b>: A directory component in pathname does not exist.</li>
273  * <li><b>EEXIST</b>: The file/directory object is already exist.</li>
274  * <li><b>EIO</b>: An I/O error occurred while reading from or writing to a file system.</li>
275  * <li><b>EROFS</b>: The physical drive is write protected.</li>
276  * <li><b>ENOSPC</b>: No space left on device.</li>
277  * <li><b>ENFILE</b>: The maximum allowable number of files is currently open in the system.</li>
278  * <li><b>ENOTDIR</b>: A component of the path prefix names an existing file that is neither a directory nor a symbolic
279  * link to a directory; or the path argument resolves to a non-directory file.</li>
280  * <li><b>EPERM</b>: Operation not permitted or access denied due to prohibited access or directory full.</li>
281  * <li><b>EBUSY</b>: The operation is rejected according to the file sharing policy.</li>
282  * <li><b>ENOSYS</b>: Not support.</li>
283  * <li><b>EPROTO</b>: Protocol error in nfs.</li>
284  * <li><b>EFAULT</b>: Bad address.</li>
285  * </ul>
286  *
287  * @par Dependency:
288  * <ul><li>stat.h</li></ul>
289  * @see None
290  */
291 int mkdir(const char *, mode_t);
292 int mkfifo(const char *, mode_t);
293 int mkdirat(int, const char *, mode_t);
294 int mkfifoat(int, const char *, mode_t);
295 
296 #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
297 int mknod(const char *, mode_t, dev_t);
298 int mknodat(int, const char *, mode_t, dev_t);
299 #endif
300 
301 int futimens(int, const struct timespec [2]);
302 int utimensat(int, const char *, const struct timespec [2], int);
303 
304 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
305 int lchmod(const char *, mode_t);
306 #define S_IREAD S_IRUSR
307 #define S_IWRITE S_IWUSR
308 #define S_IEXEC S_IXUSR
309 #endif
310 
311 #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
312 #ifdef __LITEOS__
313 #define stat64 stat
314 int fstat64(int, struct stat64 *);
315 int lstat64(const char *, struct stat64 *);
316 int fstatat64(int, const char *, struct stat64 *, int);
317 #define blkcnt64_t blkcnt_t
318 #define fsblkcnt64_t fsblkcnt_t
319 #define fsfilcnt64_t fsfilcnt_t
320 #define ino64_t ino_t
321 #define off64_t int64_t
322 #else
323 #define stat64 stat
324 #define fstat64 fstat
325 #define lstat64 lstat
326 #define fstatat64 fstatat
327 #define blkcnt64_t blkcnt_t
328 #define fsblkcnt64_t fsblkcnt_t
329 #define fsfilcnt64_t fsfilcnt_t
330 #define ino64_t ino_t
331 #define off64_t off_t
332 #endif
333 #endif
334 
335 #if _REDIR_TIME64
336 __REDIR(stat, __stat_time64);
337 __REDIR(fstat, __fstat_time64);
338 __REDIR(lstat, __lstat_time64);
339 __REDIR(fstatat, __fstatat_time64);
340 __REDIR(futimens, __futimens_time64);
341 __REDIR(utimensat, __utimensat_time64);
342 #endif
343 
344 #ifdef __cplusplus
345 }
346 #endif
347 #endif
348 
349 
350