1 /*
2 Copyright (c) 1982, 1986, 1993
3 The Regents of the University of California.  All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8 1. Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 3. Neither the name of the University nor the names of its contributors
14 may be used to endorse or promote products derived from this software
15 without specific prior written permission.
16 
17 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 SUCH DAMAGE.
28  */
29 #ifndef	_SYS_STAT_H
30 #define	_SYS_STAT_H
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #include <_ansi.h>
37 #include <time.h>
38 #include <sys/cdefs.h>
39 #include <sys/types.h>
40 #include <sys/_timespec.h>
41 
42 /* dj's stat defines _STAT_H_ */
43 #ifndef _STAT_H_
44 
45 /* It is intended that the layout of this structure not change when the
46    sizes of any of the basic types change (short, int, long) [via a compile
47    time option].  */
48 
49 #ifdef __CYGWIN__
50 #include <cygwin/stat.h>
51 #ifdef _LIBC
52 #define stat64 stat
53 #endif
54 #else
55 struct	stat
56 {
57   dev_t		st_dev;
58   ino_t		st_ino;
59   mode_t	st_mode;
60   nlink_t	st_nlink;
61   uid_t		st_uid;
62   gid_t		st_gid;
63 #if defined(__linux) && defined(__x86_64__)
64     int __pad0;
65 #endif
66   dev_t		st_rdev;
67 #if defined(__linux) && !defined(__x86_64__)
68     unsigned short int __pad2;
69 #endif
70   off_t		st_size;
71 #if defined(__linux)
72   blksize_t	st_blksize;
73   blkcnt_t	st_blocks;
74   struct timespec st_atim;
75   struct timespec st_mtim;
76   struct timespec st_ctim;
77 #define st_atime st_atim.tv_sec      /* Backward compatibility */
78 #define st_mtime st_mtim.tv_sec
79 #define st_ctime st_ctim.tv_sec
80 #if defined(__linux) && defined(__x86_64__)
81     __uint64_t __glibc_reserved[3];
82 #endif
83 #else
84 #if defined(__rtems__)
85   struct timespec st_atim;
86   struct timespec st_mtim;
87   struct timespec st_ctim;
88   blksize_t     st_blksize;
89   blkcnt_t	st_blocks;
90 #else
91   /* SysV/sco doesn't have the rest... But Solaris, eabi does.  */
92 #if defined(__svr4__) && !defined(__PPC__) && !defined(__sun__)
93   time_t	st_atime;
94   time_t	st_mtime;
95   time_t	st_ctime;
96 #else
97   struct timespec st_atim;
98   struct timespec st_mtim;
99   struct timespec st_ctim;
100   blksize_t     st_blksize;
101   blkcnt_t	st_blocks;
102 #if !defined(__rtems__)
103   long		st_spare4[2];
104 #endif
105 #endif
106 #endif
107 #endif
108 };
109 
110 struct stat64
111 {
112   __dev_t st_dev;		/* Device.  */
113 #  ifdef __x86_64__
114   __ino64_t st_ino;		/* File serial number.  */
115   __nlink_t st_nlink;		/* Link count.  */
116   __mode_t st_mode;		/* File mode.  */
117 #  else
118   unsigned int __pad1;
119   __ino_t __st_ino;			/* 32bit file serial number.	*/
120   __mode_t st_mode;			/* File mode.  */
121   __nlink_t st_nlink;			/* Link count.  */
122 #  endif
123   __uid_t st_uid;		/* User ID of the file's owner.	*/
124   __gid_t st_gid;		/* Group ID of the file's group.*/
125 #  ifdef __x86_64__
126   int __pad0;
127   __dev_t st_rdev;		/* Device number, if device.  */
128   __off_t st_size;		/* Size of file, in bytes.  */
129 #  else
130   __dev_t st_rdev;			/* Device number, if device.  */
131   unsigned int __pad2;
132   __off64_t st_size;			/* Size of file, in bytes.  */
133 #  endif
134   __blksize_t st_blksize;	/* Optimal block size for I/O.  */
135   __blkcnt64_t st_blocks;	/* Nr. 512-byte blocks allocated.  */
136 #if defined(__svr4__) && !defined(__PPC__) && !defined(__sun__)
137   __time_t st_atime;			/* Time of last access.  */
138   __syscall_ulong_t st_atimensec;	/* Nscecs of last access.  */
139   __time_t st_mtime;			/* Time of last modification.  */
140   __syscall_ulong_t st_mtimensec;	/* Nsecs of last modification.  */
141   __time_t st_ctime;			/* Time of last status change.  */
142   __syscall_ulong_t st_ctimensec;	/* Nsecs of last status change.  */
143 #else
144   /* Nanosecond resolution timestamps are stored in a format
145      equivalent to 'struct timespec'.  This is the type used
146      whenever possible but the Unix namespace rules do not allow the
147      identifier 'timespec' to appear in the <sys/stat.h> header.
148      Therefore we have to handle the use of this header in strictly
149      standard-compliant sources special.  */
150   struct timespec st_atim;		/* Time of last access.  */
151   struct timespec st_mtim;		/* Time of last modification.  */
152   struct timespec st_ctim;		/* Time of last status change.  */
153 #  endif
154 #  ifdef __x86_64__
155   __int64_t __glibc_reserved[3];
156 #  else
157   __ino64_t st_ino;			/* File serial number.		*/
158 #  endif
159 };
160 
161 #if !(defined(__svr4__) && !defined(__PPC__) && !defined(__sun__))
162 #define st_atime st_atim.tv_sec
163 #define st_ctime st_ctim.tv_sec
164 #define st_mtime st_mtim.tv_sec
165 #endif
166 
167 #endif
168 
169 #define	_IFMT		0170000	/* type of file */
170 #define		_IFDIR	0040000	/* directory */
171 #define		_IFCHR	0020000	/* character special */
172 #define		_IFBLK	0060000	/* block special */
173 #define		_IFREG	0100000	/* regular */
174 #define		_IFLNK	0120000	/* symbolic link */
175 #define		_IFSOCK	0140000	/* socket */
176 #define		_IFIFO	0010000	/* fifo */
177 
178 #define 	S_BLKSIZE  1024 /* size of a block */
179 
180 #define	S_ISUID		0004000	/* set user id on execution */
181 #define	S_ISGID		0002000	/* set group id on execution */
182 #define	S_ISVTX		0001000	/* save swapped text even after use */
183 #if __BSD_VISIBLE
184 #define	S_IREAD		0000400	/* read permission, owner */
185 #define	S_IWRITE 	0000200	/* write permission, owner */
186 #define	S_IEXEC		0000100	/* execute/search permission, owner */
187 #define	S_ENFMT 	0002000	/* enforcement-mode locking */
188 #endif	/* !_BSD_VISIBLE */
189 
190 #define	S_IFMT		_IFMT
191 #define	S_IFDIR		_IFDIR
192 #define	S_IFCHR		_IFCHR
193 #define	S_IFBLK		_IFBLK
194 #define	S_IFREG		_IFREG
195 #define	S_IFLNK		_IFLNK
196 #define	S_IFSOCK	_IFSOCK
197 #define	S_IFIFO		_IFIFO
198 
199 #ifdef _WIN32
200 /* The Windows header files define _S_ forms of these, so we do too
201    for easier portability.  */
202 #define _S_IFMT		_IFMT
203 #define _S_IFDIR	_IFDIR
204 #define _S_IFCHR	_IFCHR
205 #define _S_IFIFO	_IFIFO
206 #define _S_IFREG	_IFREG
207 #define _S_IREAD	0000400
208 #define _S_IWRITE	0000200
209 #define _S_IEXEC	0000100
210 #endif
211 
212 #define	S_IRWXU 	(S_IRUSR | S_IWUSR | S_IXUSR)
213 #define		S_IRUSR	0000400	/* read permission, owner */
214 #define		S_IWUSR	0000200	/* write permission, owner */
215 #define		S_IXUSR 0000100/* execute/search permission, owner */
216 #define	S_IRWXG		(S_IRGRP | S_IWGRP | S_IXGRP)
217 #define		S_IRGRP	0000040	/* read permission, group */
218 #define		S_IWGRP	0000020	/* write permission, grougroup */
219 #define		S_IXGRP 0000010/* execute/search permission, group */
220 #define	S_IRWXO		(S_IROTH | S_IWOTH | S_IXOTH)
221 #define		S_IROTH	0000004	/* read permission, other */
222 #define		S_IWOTH	0000002	/* write permission, other */
223 #define		S_IXOTH 0000001/* execute/search permission, other */
224 
225 #if __BSD_VISIBLE
226 #define ACCESSPERMS (S_IRWXU | S_IRWXG | S_IRWXO) /* 0777 */
227 #define ALLPERMS (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO) /* 07777 */
228 #define DEFFILEMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) /* 0666 */
229 #endif
230 
231 #define	S_ISBLK(m)	(((m)&_IFMT) == _IFBLK)
232 #define	S_ISCHR(m)	(((m)&_IFMT) == _IFCHR)
233 #define	S_ISDIR(m)	(((m)&_IFMT) == _IFDIR)
234 #define	S_ISFIFO(m)	(((m)&_IFMT) == _IFIFO)
235 #define	S_ISREG(m)	(((m)&_IFMT) == _IFREG)
236 #define	S_ISLNK(m)	(((m)&_IFMT) == _IFLNK)
237 #define	S_ISSOCK(m)	(((m)&_IFMT) == _IFSOCK)
238 
239 #if defined(__CYGWIN__) || defined(__rtems__)
240 /* Special tv_nsec values for futimens(2) and utimensat(2). */
241 #define UTIME_NOW	-2L
242 #define UTIME_OMIT	-1L
243 #endif
244 
245 int	chmod (const char *__path, mode_t __mode );
246 int     fchmod (int __fd, mode_t __mode);
247 int	fstat (int __fd, struct stat *__sbuf );
248 int	mkdir (const char *_path, mode_t __mode );
249 int	mkfifo (const char *__path, mode_t __mode );
250 int	stat (const char *__restrict __path, struct stat *__restrict __sbuf );
251 mode_t	umask (mode_t __mask );
252 
253 #if defined (__SPU__) || defined(__rtems__) || defined(__CYGWIN__)
254 int	lstat (const char *__restrict __path, struct stat *__restrict __buf );
255 int	mknod (const char *__path, mode_t __mode, dev_t __dev );
256 #endif
257 
258 #if __ATFILE_VISIBLE && !defined(__INSIDE_CYGWIN__)
259 int	fchmodat (int, const char *, mode_t, int);
260 int	fstatat (int, const char *__restrict , struct stat *__restrict, int);
261 int	mkdirat (int, const char *, mode_t);
262 int	mkfifoat (int, const char *, mode_t);
263 int	mknodat (int, const char *, mode_t, dev_t);
264 int	utimensat (int, const char *, const struct timespec [2], int);
265 #endif
266 #if __POSIX_VISIBLE >= 200809 && !defined(__INSIDE_CYGWIN__)
267 int	futimens (int, const struct timespec [2]);
268 #endif
269 
270 /* Provide prototypes for most of the _<systemcall> names that are
271    provided in newlib for some compilers.  */
272 #ifdef _LIBC
273 int	_fstat (int __fd, struct stat *__sbuf );
274 int	_stat (const char *__restrict __path, struct stat *__restrict __sbuf );
275 int	_mkdir (const char *_path, mode_t __mode );
276 #ifdef __LARGE64_FILES
277 struct stat64;
278 int	_stat64 (const char *__restrict __path, struct stat64 *__restrict __sbuf );
279 int	_fstat64 (int __fd, struct stat64 *__sbuf );
280 #endif
281 #endif
282 
283 #endif /* !_STAT_H_ */
284 #ifdef __cplusplus
285 }
286 #endif
287 #endif /* _SYS_STAT_H */
288