]>
Commit | Line | Data |
---|---|---|
b168057a | 1 | /* Copyright (C) 2011-2015 Free Software Foundation, Inc. |
a63c7fa1 CM |
2 | This file is part of the GNU C Library. |
3 | Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011. | |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
6 | modify it under the terms of the GNU Lesser General Public | |
7 | License as published by the Free Software Foundation; either | |
8 | version 2.1 of the License, or (at your option) any later version. | |
9 | ||
10 | The GNU C Library is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | Lesser General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU Lesser General Public | |
ab84e3ff PE |
16 | License along with the GNU C Library. If not, see |
17 | <http://www.gnu.org/licenses/>. */ | |
a63c7fa1 CM |
18 | |
19 | #if !defined _SYS_STAT_H && !defined _FCNTL_H | |
20 | # error "Never include <bits/stat.h> directly; use <sys/stat.h> instead." | |
21 | #endif | |
22 | ||
23 | #ifndef _BITS_STAT_H | |
24 | #define _BITS_STAT_H 1 | |
25 | ||
26 | #include <endian.h> | |
27 | #include <bits/wordsize.h> | |
28 | ||
29 | /* 64-bit libc uses the kernel's 'struct stat', accessed via the | |
30 | stat() syscall; 32-bit libc uses the kernel's 'struct stat64' | |
31 | and accesses it via the stat64() syscall. All the various | |
32 | APIs offered by libc use the kernel shape for their struct stat | |
33 | structure; the only difference is that 32-bit programs not | |
34 | using __USE_FILE_OFFSET64 only see the low 32 bits of some | |
35 | of the fields (specifically st_ino, st_size, and st_blocks). */ | |
36 | #define _STAT_VER_KERNEL 0 | |
37 | #define _STAT_VER_LINUX 0 | |
38 | #define _STAT_VER _STAT_VER_KERNEL | |
39 | ||
40 | /* Versions of the `xmknod' interface. */ | |
41 | #define _MKNOD_VER_LINUX 0 | |
42 | ||
43 | #if defined __USE_FILE_OFFSET64 | |
44 | # define __field64(type, type64, name) type64 name | |
45 | #elif __WORDSIZE == 64 | |
46 | # define __field64(type, type64, name) type name | |
47 | #elif __BYTE_ORDER == __LITTLE_ENDIAN | |
48 | # define __field64(type, type64, name) \ | |
7cf8ac4c | 49 | type name __attribute__((__aligned__ (__alignof__ (type64)))); int __##name##_pad |
a63c7fa1 CM |
50 | #else |
51 | # define __field64(type, type64, name) \ | |
7cf8ac4c | 52 | int __##name##_pad __attribute__((__aligned__ (__alignof__ (type64)))); type name |
a63c7fa1 CM |
53 | #endif |
54 | ||
55 | struct stat | |
56 | { | |
57 | __dev_t st_dev; /* Device. */ | |
58 | __field64(__ino_t, __ino64_t, st_ino); /* File serial number. */ | |
59 | __mode_t st_mode; /* File mode. */ | |
60 | __nlink_t st_nlink; /* Link count. */ | |
61 | __uid_t st_uid; /* User ID of the file's owner. */ | |
62 | __gid_t st_gid; /* Group ID of the file's group.*/ | |
63 | __dev_t st_rdev; /* Device number, if device. */ | |
64 | __dev_t __pad1; | |
65 | __field64(__off_t, __off64_t, st_size); /* Size of file, in bytes. */ | |
66 | __blksize_t st_blksize; /* Optimal block size for I/O. */ | |
67 | int __pad2; | |
68 | __field64(__blkcnt_t, __blkcnt64_t, st_blocks); /* 512-byte blocks */ | |
a06b40cd | 69 | #ifdef __USE_XOPEN2K8 |
a63c7fa1 CM |
70 | /* Nanosecond resolution timestamps are stored in a format |
71 | equivalent to 'struct timespec'. This is the type used | |
72 | whenever possible but the Unix namespace rules do not allow the | |
73 | identifier 'timespec' to appear in the <sys/stat.h> header. | |
74 | Therefore we have to handle the use of this header in strictly | |
75 | standard-compliant sources special. */ | |
76 | struct timespec st_atim; /* Time of last access. */ | |
77 | struct timespec st_mtim; /* Time of last modification. */ | |
78 | struct timespec st_ctim; /* Time of last status change. */ | |
79 | # define st_atime st_atim.tv_sec /* Backward compatibility. */ | |
80 | # define st_mtime st_mtim.tv_sec | |
81 | # define st_ctime st_ctim.tv_sec | |
82 | #else | |
83 | __time_t st_atime; /* Time of last access. */ | |
84 | unsigned long int st_atimensec; /* Nscecs of last access. */ | |
85 | __time_t st_mtime; /* Time of last modification. */ | |
86 | unsigned long int st_mtimensec; /* Nsecs of last modification. */ | |
87 | __time_t st_ctime; /* Time of last status change. */ | |
88 | unsigned long int st_ctimensec; /* Nsecs of last status change. */ | |
89 | #endif | |
d1d9eaf4 | 90 | int __glibc_reserved[2]; |
a63c7fa1 CM |
91 | }; |
92 | ||
93 | #undef __field64 | |
94 | ||
95 | #ifdef __USE_LARGEFILE64 | |
96 | struct stat64 | |
97 | { | |
98 | __dev_t st_dev; /* Device. */ | |
99 | __ino64_t st_ino; /* File serial number. */ | |
100 | __mode_t st_mode; /* File mode. */ | |
101 | __nlink_t st_nlink; /* Link count. */ | |
102 | __uid_t st_uid; /* User ID of the file's owner. */ | |
103 | __gid_t st_gid; /* Group ID of the file's group.*/ | |
104 | __dev_t st_rdev; /* Device number, if device. */ | |
105 | __dev_t __pad1; | |
106 | __off64_t st_size; /* Size of file, in bytes. */ | |
107 | __blksize_t st_blksize; /* Optimal block size for I/O. */ | |
108 | int __pad2; | |
109 | __blkcnt64_t st_blocks; /* Nr. 512-byte blocks allocated. */ | |
a06b40cd | 110 | #ifdef __USE_XOPEN2K8 |
a63c7fa1 CM |
111 | /* Nanosecond resolution timestamps are stored in a format |
112 | equivalent to 'struct timespec'. This is the type used | |
113 | whenever possible but the Unix namespace rules do not allow the | |
114 | identifier 'timespec' to appear in the <sys/stat.h> header. | |
115 | Therefore we have to handle the use of this header in strictly | |
116 | standard-compliant sources special. */ | |
117 | struct timespec st_atim; /* Time of last access. */ | |
118 | struct timespec st_mtim; /* Time of last modification. */ | |
119 | struct timespec st_ctim; /* Time of last status change. */ | |
120 | #else | |
121 | __time_t st_atime; /* Time of last access. */ | |
122 | unsigned long int st_atimensec; /* Nscecs of last access. */ | |
123 | __time_t st_mtime; /* Time of last modification. */ | |
124 | unsigned long int st_mtimensec; /* Nsecs of last modification. */ | |
125 | __time_t st_ctime; /* Time of last status change. */ | |
126 | unsigned long int st_ctimensec; /* Nsecs of last status change. */ | |
127 | #endif | |
d1d9eaf4 | 128 | int __glibc_reserved[2]; |
a63c7fa1 CM |
129 | }; |
130 | #endif | |
131 | ||
132 | /* Tell code we have these members. */ | |
133 | #define _STATBUF_ST_BLKSIZE | |
134 | #define _STATBUF_ST_RDEV | |
135 | /* Nanosecond resolution time values are supported. */ | |
136 | #define _STATBUF_ST_NSEC | |
137 | ||
138 | /* Encoding of the file mode. */ | |
139 | ||
140 | #define __S_IFMT 0170000 /* These bits determine file type. */ | |
141 | ||
142 | /* File types. */ | |
143 | #define __S_IFDIR 0040000 /* Directory. */ | |
144 | #define __S_IFCHR 0020000 /* Character device. */ | |
145 | #define __S_IFBLK 0060000 /* Block device. */ | |
146 | #define __S_IFREG 0100000 /* Regular file. */ | |
147 | #define __S_IFIFO 0010000 /* FIFO. */ | |
148 | #define __S_IFLNK 0120000 /* Symbolic link. */ | |
149 | #define __S_IFSOCK 0140000 /* Socket. */ | |
150 | ||
151 | /* POSIX.1b objects. Note that these macros always evaluate to zero. But | |
152 | they do it by enforcing the correct use of the macros. */ | |
153 | #define __S_TYPEISMQ(buf) ((buf)->st_mode - (buf)->st_mode) | |
154 | #define __S_TYPEISSEM(buf) ((buf)->st_mode - (buf)->st_mode) | |
155 | #define __S_TYPEISSHM(buf) ((buf)->st_mode - (buf)->st_mode) | |
156 | ||
157 | /* Protection bits. */ | |
158 | ||
159 | #define __S_ISUID 04000 /* Set user ID on execution. */ | |
160 | #define __S_ISGID 02000 /* Set group ID on execution. */ | |
161 | #define __S_ISVTX 01000 /* Save swapped text after use (sticky). */ | |
162 | #define __S_IREAD 0400 /* Read by owner. */ | |
163 | #define __S_IWRITE 0200 /* Write by owner. */ | |
164 | #define __S_IEXEC 0100 /* Execute by owner. */ | |
165 | ||
166 | #ifdef __USE_ATFILE | |
167 | # define UTIME_NOW ((1l << 30) - 1l) | |
168 | # define UTIME_OMIT ((1l << 30) - 2l) | |
169 | #endif | |
170 | ||
171 | #endif /* bits/stat.h */ |