stat.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /* Copyright (C) 1992, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2009
  2. Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef _SYS_STAT_H
  16. # error "Never include <bits/stat.h> directly; use <sys/stat.h> instead."
  17. #endif
  18. #include <bits/wordsize.h>
  19. /* Versions of the `struct stat' data structure. */
  20. #define _STAT_VER_LINUX_OLD 1
  21. #define _STAT_VER_KERNEL 1
  22. #define _STAT_VER_SVR4 2
  23. #define _STAT_VER_LINUX 3
  24. #if __WORDSIZE == 32
  25. # define _STAT_VER _STAT_VER_LINUX
  26. #else
  27. # define _STAT_VER _STAT_VER_KERNEL
  28. #endif
  29. /* Versions of the `xmknod' interface. */
  30. #define _MKNOD_VER_LINUX 1
  31. #define _MKNOD_VER_SVR4 2
  32. #define _MKNOD_VER _MKNOD_VER_LINUX /* The bits defined below. */
  33. #if __WORDSIZE == 32
  34. struct stat
  35. {
  36. __dev_t st_dev; /* Device. */
  37. # ifndef __USE_FILE_OFFSET64
  38. unsigned short int __pad1;
  39. __ino_t st_ino; /* File serial number. */
  40. # else
  41. __ino64_t st_ino; /* File serial number. */
  42. # endif
  43. __mode_t st_mode; /* File mode. */
  44. __nlink_t st_nlink; /* Link count. */
  45. __uid_t st_uid; /* User ID of the file's owner. */
  46. __gid_t st_gid; /* Group ID of the file's group.*/
  47. __dev_t st_rdev; /* Device number, if device. */
  48. unsigned short int __pad2;
  49. # ifndef __USE_FILE_OFFSET64
  50. __off_t st_size; /* Size of file, in bytes. */
  51. # else
  52. __off64_t st_size; /* Size of file, in bytes. */
  53. # endif
  54. __blksize_t st_blksize; /* Optimal block size for I/O. */
  55. # ifndef __USE_FILE_OFFSET64
  56. __blkcnt_t st_blocks; /* Number 512-byte blocks allocated. */
  57. # else
  58. __blkcnt64_t st_blocks; /* Number 512-byte blocks allocated. */
  59. # endif
  60. #ifdef __USE_MISC
  61. /* Nanosecond resolution timestamps are stored in a format
  62. equivalent to 'struct timespec'. This is the type used
  63. whenever possible but the Unix namespace rules do not allow the
  64. identifier 'timespec' to appear in the <sys/stat.h> header.
  65. Therefore we have to handle the use of this header in strictly
  66. standard-compliant sources special. */
  67. struct timespec st_atim; /* Time of last access. */
  68. struct timespec st_mtim; /* Time of last modification. */
  69. struct timespec st_ctim; /* Time of last status change. */
  70. # define st_atime st_atim.tv_sec /* Backward compatibility. */
  71. # define st_mtime st_mtim.tv_sec
  72. # define st_ctime st_ctim.tv_sec
  73. #else
  74. __time_t st_atime; /* Time of last access. */
  75. unsigned long int st_atimensec; /* Nscecs of last access. */
  76. __time_t st_mtime; /* Time of last modification. */
  77. unsigned long int st_mtimensec; /* Nsecs of last modification. */
  78. __time_t st_ctime; /* Time of last status change. */
  79. unsigned long int st_ctimensec; /* Nsecs of last status change. */
  80. #endif
  81. unsigned long int __unused4;
  82. unsigned long int __unused5;
  83. };
  84. # ifdef __USE_LARGEFILE64
  85. struct stat64
  86. {
  87. __dev_t st_dev; /* Device. */
  88. __ino64_t st_ino; /* File serial number. */
  89. __mode_t st_mode; /* File mode. */
  90. __nlink_t st_nlink; /* Link count. */
  91. __uid_t st_uid; /* User ID of the file's owner. */
  92. __gid_t st_gid; /* Group ID of the file's group.*/
  93. __dev_t st_rdev; /* Device number, if device. */
  94. unsigned short int __pad2;
  95. __off64_t st_size; /* Size of file, in bytes. */
  96. __blksize_t st_blksize; /* Optimal block size for I/O. */
  97. __blkcnt64_t st_blocks; /* Number 512-byte blocks allocated. */
  98. #ifdef __USE_MISC
  99. /* Nanosecond resolution timestamps are stored in a format
  100. equivalent to 'struct timespec'. This is the type used
  101. whenever possible but the Unix namespace rules do not allow the
  102. identifier 'timespec' to appear in the <sys/stat.h> header.
  103. Therefore we have to handle the use of this header in strictly
  104. standard-compliant sources special. */
  105. struct timespec st_atim; /* Time of last access. */
  106. struct timespec st_mtim; /* Time of last modification. */
  107. struct timespec st_ctim; /* Time of last status change. */
  108. # define st_atime st_atim.tv_sec /* Backward compatibility. */
  109. # define st_mtime st_mtim.tv_sec
  110. # define st_ctime st_ctim.tv_sec
  111. #else
  112. __time_t st_atime; /* Time of last access. */
  113. unsigned long int st_atimensec; /* Nscecs of last access. */
  114. __time_t st_mtime; /* Time of last modification. */
  115. unsigned long int st_mtimensec; /* Nsecs of last modification. */
  116. __time_t st_ctime; /* Time of last status change. */
  117. unsigned long int st_ctimensec; /* Nsecs of last status change. */
  118. #endif
  119. unsigned long int __unused4;
  120. unsigned long int __unused5;
  121. };
  122. # endif /* __USE_LARGEFILE64 */
  123. #else /* __WORDSIZE == 32 */
  124. struct stat
  125. {
  126. __dev_t st_dev; /* Device. */
  127. # ifndef __USE_FILE_OFFSET64
  128. __ino_t st_ino; /* File serial number. */
  129. # else
  130. __ino64_t st_ino; /* File serial number. */
  131. # endif
  132. __nlink_t st_nlink; /* Link count. */
  133. __mode_t st_mode; /* File mode. */
  134. __uid_t st_uid; /* User ID of the file's owner. */
  135. __gid_t st_gid; /* Group ID of the file's group.*/
  136. int __pad2;
  137. __dev_t st_rdev; /* Device number, if device. */
  138. # ifndef __USE_FILE_OFFSET64
  139. __off_t st_size; /* Size of file, in bytes. */
  140. # else
  141. __off64_t st_size; /* Size of file, in bytes. */
  142. # endif
  143. __blksize_t st_blksize; /* Optimal block size for I/O. */
  144. # ifndef __USE_FILE_OFFSET64
  145. __blkcnt_t st_blocks; /* Number 512-byte blocks allocated. */
  146. # else
  147. __blkcnt64_t st_blocks; /* Number 512-byte blocks allocated. */
  148. # endif
  149. #ifdef __USE_MISC
  150. /* Nanosecond resolution timestamps are stored in a format
  151. equivalent to 'struct timespec'. This is the type used
  152. whenever possible but the Unix namespace rules do not allow the
  153. identifier 'timespec' to appear in the <sys/stat.h> header.
  154. Therefore we have to handle the use of this header in strictly
  155. standard-compliant sources special. */
  156. struct timespec st_atim; /* Time of last access. */
  157. struct timespec st_mtim; /* Time of last modification. */
  158. struct timespec st_ctim; /* Time of last status change. */
  159. # define st_atime st_atim.tv_sec /* Backward compatibility. */
  160. # define st_mtime st_mtim.tv_sec
  161. # define st_ctime st_ctim.tv_sec
  162. #else
  163. __time_t st_atime; /* Time of last access. */
  164. unsigned long int st_atimensec; /* Nscecs of last access. */
  165. __time_t st_mtime; /* Time of last modification. */
  166. unsigned long int st_mtimensec; /* Nsecs of last modification. */
  167. __time_t st_ctime; /* Time of last status change. */
  168. unsigned long int st_ctimensec; /* Nsecs of last status change. */
  169. #endif
  170. unsigned long int __unused4;
  171. unsigned long int __unused5;
  172. unsigned long int __unused6;
  173. };
  174. # ifdef __USE_LARGEFILE64
  175. struct stat64
  176. {
  177. __dev_t st_dev; /* Device. */
  178. __ino64_t st_ino; /* File serial number. */
  179. __nlink_t st_nlink; /* Link count. */
  180. __mode_t st_mode; /* File mode. */
  181. __uid_t st_uid; /* User ID of the file's owner. */
  182. __gid_t st_gid; /* Group ID of the file's group.*/
  183. int __pad2;
  184. __dev_t st_rdev; /* Device number, if device. */
  185. __off64_t st_size; /* Size of file, in bytes. */
  186. __blksize_t st_blksize; /* Optimal block size for I/O. */
  187. __blkcnt64_t st_blocks; /* Number 512-byte blocks allocated. */
  188. #ifdef __USE_MISC
  189. /* Nanosecond resolution timestamps are stored in a format
  190. equivalent to 'struct timespec'. This is the type used
  191. whenever possible but the Unix namespace rules do not allow the
  192. identifier 'timespec' to appear in the <sys/stat.h> header.
  193. Therefore we have to handle the use of this header in strictly
  194. standard-compliant sources special. */
  195. struct timespec st_atim; /* Time of last access. */
  196. struct timespec st_mtim; /* Time of last modification. */
  197. struct timespec st_ctim; /* Time of last status change. */
  198. # define st_atime st_atim.tv_sec /* Backward compatibility. */
  199. # define st_mtime st_mtim.tv_sec
  200. # define st_ctime st_ctim.tv_sec
  201. #else
  202. __time_t st_atime; /* Time of last access. */
  203. unsigned long int st_atimensec; /* Nscecs of last access. */
  204. __time_t st_mtime; /* Time of last modification. */
  205. unsigned long int st_mtimensec; /* Nsecs of last modification. */
  206. __time_t st_ctime; /* Time of last status change. */
  207. unsigned long int st_ctimensec; /* Nsecs of last status change. */
  208. #endif
  209. unsigned long int __unused4;
  210. unsigned long int __unused5;
  211. unsigned long int __unused6;
  212. };
  213. # endif /* __USE_LARGEFILE64 */
  214. #endif
  215. /* Tell code we have these members. */
  216. #define _STATBUF_ST_BLKSIZE
  217. #define _STATBUF_ST_RDEV
  218. /* Nanosecond resolution time values are supported. */
  219. #define _STATBUF_ST_NSEC
  220. /* Encoding of the file mode. */
  221. #define __S_IFMT 0170000 /* These bits determine file type. */
  222. /* File types. */
  223. #define __S_IFDIR 0040000 /* Directory. */
  224. #define __S_IFCHR 0020000 /* Character device. */
  225. #define __S_IFBLK 0060000 /* Block device. */
  226. #define __S_IFREG 0100000 /* Regular file. */
  227. #define __S_IFIFO 0010000 /* FIFO. */
  228. #define __S_IFLNK 0120000 /* Symbolic link. */
  229. #define __S_IFSOCK 0140000 /* Socket. */
  230. /* POSIX.1b objects. Note that these macros always evaluate to zero. But
  231. they do it by enforcing the correct use of the macros. */
  232. #define __S_TYPEISMQ(buf) ((buf)->st_mode - (buf)->st_mode)
  233. #define __S_TYPEISSEM(buf) ((buf)->st_mode - (buf)->st_mode)
  234. #define __S_TYPEISSHM(buf) ((buf)->st_mode - (buf)->st_mode)
  235. /* Protection bits. */
  236. #define __S_ISUID 04000 /* Set user ID on execution. */
  237. #define __S_ISGID 02000 /* Set group ID on execution. */
  238. #define __S_ISVTX 01000 /* Save swapped text after use (sticky). */
  239. #define __S_IREAD 0400 /* Read by owner. */
  240. #define __S_IWRITE 0200 /* Write by owner. */
  241. #define __S_IEXEC 0100 /* Execute by owner. */
  242. #ifdef __USE_ATFILE
  243. # define UTIME_NOW ((1l << 30) - 1l)
  244. # define UTIME_OMIT ((1l << 30) - 2l)
  245. #endif