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 #include <sys/cdefs.h>
33 #include <sys/_types.h>
34 #include <sys/_timespec.h>
35 
36 _BEGIN_STD_C
37 
38 #ifndef _BLKCNT_T_DECLARED
39 typedef	__blkcnt_t	blkcnt_t;
40 #define	_BLKCNT_T_DECLARED
41 #endif
42 
43 #ifndef _BLKSIZE_T_DECLARED
44 typedef	__blksize_t	blksize_t;
45 #define	_BLKSIZE_T_DECLARED
46 #endif
47 
48 #ifndef _DEV_T_DECLARED
49 typedef	__dev_t		dev_t;		/* device number or struct cdev */
50 #define	_DEV_T_DECLARED
51 #endif
52 
53 #ifndef _INO_T_DECLARED
54 typedef	__ino_t		ino_t;		/* inode number */
55 #define	_INO_T_DECLARED
56 #endif
57 
58 #ifndef _MODE_T_DECLARED
59 typedef	__mode_t	mode_t;		/* permissions */
60 #define	_MODE_T_DECLARED
61 #endif
62 
63 #ifndef _NLINK_T_DECLARED
64 typedef	__nlink_t	nlink_t;	/* link count */
65 #define	_NLINK_T_DECLARED
66 #endif
67 
68 #ifndef _UID_T_DECLARED
69 typedef	__uid_t		uid_t;		/* user id */
70 #define	_UID_T_DECLARED
71 #endif
72 
73 #ifndef _GID_T_DECLARED
74 typedef	__gid_t		gid_t;		/* group id */
75 #define	_GID_T_DECLARED
76 #endif
77 
78 #ifndef _OFF_T_DECLARED
79 typedef	__off_t		off_t;		/* file offset */
80 #define	_OFF_T_DECLARED
81 #endif
82 
83 #ifndef _TIME_T_DECLARED
84 typedef	_TIME_T_	time_t;
85 #define	_TIME_T_DECLARED
86 #endif
87 
88 /* dj's stat defines _STAT_H_ */
89 #ifndef _STAT_H_
90 
91 /* It is intended that the layout of this structure not change when the
92    sizes of any of the basic types change (short, int, long) [via a compile
93    time option].  */
94 
95 struct	stat
96 {
97   dev_t		st_dev;
98   ino_t		st_ino;
99   mode_t	st_mode;
100   nlink_t	st_nlink;
101   uid_t		st_uid;
102   gid_t		st_gid;
103 #if defined(__linux) && defined(__x86_64__)
104     int __pad0;
105 #endif
106   dev_t		st_rdev;
107 #if defined(__linux) && !defined(__x86_64__)
108     unsigned short int __pad2;
109 #endif
110   off_t		st_size;
111 #if defined(__linux)
112   blksize_t	st_blksize;
113   blkcnt_t	st_blocks;
114   struct timespec st_atim;
115   struct timespec st_mtim;
116   struct timespec st_ctim;
117 #define st_atime st_atim.tv_sec      /* Backward compatibility */
118 #define st_mtime st_mtim.tv_sec
119 #define st_ctime st_ctim.tv_sec
120 #if defined(__linux) && defined(__x86_64__)
121     __uint64_t __glibc_reserved[3];
122 #endif
123 #else
124 #if defined(__rtems__)
125   struct timespec st_atim;
126   struct timespec st_mtim;
127   struct timespec st_ctim;
128   blksize_t     st_blksize;
129   blkcnt_t	st_blocks;
130 #else
131   /* SysV/sco doesn't have the rest... But Solaris, eabi does.  */
132 #if defined(__svr4__) && !defined(__PPC__) && !defined(__sun__)
133   time_t	st_atime;
134   time_t	st_mtime;
135   time_t	st_ctime;
136 #else
137   struct timespec st_atim;
138   struct timespec st_mtim;
139   struct timespec st_ctim;
140   blksize_t     st_blksize;
141   blkcnt_t	st_blocks;
142 #if !defined(__rtems__)
143   long		st_spare4[2];
144 #endif
145 #endif
146 #endif
147 #endif
148 };
149 
150 #if __LARGEFILE64_VISIBLE
151 struct stat64
152 {
153   __dev_t st_dev;		/* Device.  */
154 #  ifdef __x86_64__
155   __ino64_t st_ino;		/* File serial number.  */
156   __nlink_t st_nlink;		/* Link count.  */
157   __mode_t st_mode;		/* File mode.  */
158 #  else
159   unsigned int __pad1;
160   __ino_t __st_ino;			/* 32bit file serial number.	*/
161   __mode_t st_mode;			/* File mode.  */
162   __nlink_t st_nlink;			/* Link count.  */
163 #  endif
164   __uid_t st_uid;		/* User ID of the file's owner.	*/
165   __gid_t st_gid;		/* Group ID of the file's group.*/
166 #  ifdef __x86_64__
167   int __pad0;
168   __dev_t st_rdev;		/* Device number, if device.  */
169   __off_t st_size;		/* Size of file, in bytes.  */
170 #  else
171   __dev_t st_rdev;			/* Device number, if device.  */
172   unsigned int __pad2;
173   __off64_t st_size;			/* Size of file, in bytes.  */
174 #  endif
175   __blksize_t st_blksize;	/* Optimal block size for I/O.  */
176   __blkcnt64_t st_blocks;	/* Nr. 512-byte blocks allocated.  */
177 #if defined(__svr4__) && !defined(__PPC__) && !defined(__sun__)
178   __time_t st_atime;			/* Time of last access.  */
179   __syscall_ulong_t st_atimensec;	/* Nscecs of last access.  */
180   __time_t st_mtime;			/* Time of last modification.  */
181   __syscall_ulong_t st_mtimensec;	/* Nsecs of last modification.  */
182   __time_t st_ctime;			/* Time of last status change.  */
183   __syscall_ulong_t st_ctimensec;	/* Nsecs of last status change.  */
184 #else
185   /* Nanosecond resolution timestamps are stored in a format
186      equivalent to 'struct timespec'.  This is the type used
187      whenever possible but the Unix namespace rules do not allow the
188      identifier 'timespec' to appear in the <sys/stat.h> header.
189      Therefore we have to handle the use of this header in strictly
190      standard-compliant sources special.  */
191   struct timespec st_atim;		/* Time of last access.  */
192   struct timespec st_mtim;		/* Time of last modification.  */
193   struct timespec st_ctim;		/* Time of last status change.  */
194 #  endif
195 #  ifdef __x86_64__
196   __int64_t __glibc_reserved[3];
197 #  else
198   __ino64_t st_ino;			/* File serial number.		*/
199 #  endif
200 };
201 #endif
202 
203 #if !(defined(__svr4__) && !defined(__PPC__) && !defined(__sun__))
204 #define st_atime st_atim.tv_sec
205 #define st_ctime st_ctim.tv_sec
206 #define st_mtime st_mtim.tv_sec
207 #endif
208 
209 
210 #define	_IFMT		0170000	/* type of file */
211 #define		_IFDIR	0040000	/* directory */
212 #define		_IFCHR	0020000	/* character special */
213 #define		_IFBLK	0060000	/* block special */
214 #define		_IFREG	0100000	/* regular */
215 #define		_IFLNK	0120000	/* symbolic link */
216 #define		_IFSOCK	0140000	/* socket */
217 #define		_IFIFO	0010000	/* fifo */
218 
219 #define 	S_BLKSIZE  1024 /* size of a block */
220 
221 #define	S_ISUID		0004000	/* set user id on execution */
222 #define	S_ISGID		0002000	/* set group id on execution */
223 #define	S_ISVTX		0001000	/* save swapped text even after use */
224 #if __BSD_VISIBLE
225 #define	S_IREAD		0000400	/* read permission, owner */
226 #define	S_IWRITE 	0000200	/* write permission, owner */
227 #define	S_IEXEC		0000100	/* execute/search permission, owner */
228 #define	S_ENFMT 	0002000	/* enforcement-mode locking */
229 #endif	/* !_BSD_VISIBLE */
230 
231 #define	S_IFMT		_IFMT
232 #define	S_IFDIR		_IFDIR
233 #define	S_IFCHR		_IFCHR
234 #define	S_IFBLK		_IFBLK
235 #define	S_IFREG		_IFREG
236 #define	S_IFLNK		_IFLNK
237 #define	S_IFSOCK	_IFSOCK
238 #define	S_IFIFO		_IFIFO
239 
240 #ifdef _WIN32
241 /* The Windows header files define _S_ forms of these, so we do too
242    for easier portability.  */
243 #define _S_IFMT		_IFMT
244 #define _S_IFDIR	_IFDIR
245 #define _S_IFCHR	_IFCHR
246 #define _S_IFIFO	_IFIFO
247 #define _S_IFREG	_IFREG
248 #define _S_IREAD	0000400
249 #define _S_IWRITE	0000200
250 #define _S_IEXEC	0000100
251 #endif
252 
253 #define	S_IRWXU 	(S_IRUSR | S_IWUSR | S_IXUSR)
254 #define		S_IRUSR	0000400	/* read permission, owner */
255 #define		S_IWUSR	0000200	/* write permission, owner */
256 #define		S_IXUSR 0000100/* execute/search permission, owner */
257 #define	S_IRWXG		(S_IRGRP | S_IWGRP | S_IXGRP)
258 #define		S_IRGRP	0000040	/* read permission, group */
259 #define		S_IWGRP	0000020	/* write permission, grougroup */
260 #define		S_IXGRP 0000010/* execute/search permission, group */
261 #define	S_IRWXO		(S_IROTH | S_IWOTH | S_IXOTH)
262 #define		S_IROTH	0000004	/* read permission, other */
263 #define		S_IWOTH	0000002	/* write permission, other */
264 #define		S_IXOTH 0000001/* execute/search permission, other */
265 
266 #if __BSD_VISIBLE
267 #define ACCESSPERMS (S_IRWXU | S_IRWXG | S_IRWXO) /* 0777 */
268 #define ALLPERMS (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO) /* 07777 */
269 #define DEFFILEMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) /* 0666 */
270 #endif
271 
272 #define	S_ISBLK(m)	(((m)&_IFMT) == _IFBLK)
273 #define	S_ISCHR(m)	(((m)&_IFMT) == _IFCHR)
274 #define	S_ISDIR(m)	(((m)&_IFMT) == _IFDIR)
275 #define	S_ISFIFO(m)	(((m)&_IFMT) == _IFIFO)
276 #define	S_ISREG(m)	(((m)&_IFMT) == _IFREG)
277 #define	S_ISLNK(m)	(((m)&_IFMT) == _IFLNK)
278 #define	S_ISSOCK(m)	(((m)&_IFMT) == _IFSOCK)
279 
280 #if defined(__CYGWIN__) || defined(__rtems__)
281 /* Special tv_nsec values for futimens(2) and utimensat(2). */
282 #define UTIME_NOW	-2L
283 #define UTIME_OMIT	-1L
284 #endif
285 
286 int	chmod (const char *__path, mode_t __mode );
287 int     fchmod (int __fd, mode_t __mode);
288 int	fstat (int __fd, struct stat *__sbuf );
289 int	mkdir (const char *_path, mode_t __mode );
290 int	mkfifo (const char *__path, mode_t __mode );
291 int	stat (const char *__restrict __path, struct stat *__restrict __sbuf );
292 mode_t	umask (mode_t __mask );
293 
294 #if __LARGEFILE64_VISIBLE
295 int	stat64 (const char *__restrict __path, struct stat64 *__restrict __sbuf );
296 int	fstat64 (int __fd, struct stat64 *__sbuf );
297 #endif
298 
299 #if defined (__SPU__) || defined(__rtems__) || defined(__CYGWIN__)
300 int	lstat (const char *__restrict __path, struct stat *__restrict __buf );
301 int	mknod (const char *__path, mode_t __mode, dev_t __dev );
302 #endif
303 
304 #if __ATFILE_VISIBLE
305 int	fchmodat (int, const char *, mode_t, int);
306 int	fstatat (int, const char *__restrict , struct stat *__restrict, int);
307 int	mkdirat (int, const char *, mode_t);
308 int	mkfifoat (int, const char *, mode_t);
309 int	mknodat (int, const char *, mode_t, dev_t);
310 int	utimensat (int, const char *, const struct timespec [2], int);
311 #endif
312 #if __POSIX_VISIBLE >= 200809
313 int	futimens (int, const struct timespec [2]);
314 #endif
315 
316 #endif /* !_STAT_H_ */
317 
318 _END_STD_C
319 
320 #endif /* _SYS_STAT_H */
321