stat.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  3. *
  4. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  5. */
  6. #ifndef _SYS_STAT_H
  7. # error "Never include <bits/stat.h> directly; use <sys/stat.h> instead."
  8. #endif
  9. #include <bits/align64bit.h>
  10. #include <endian.h>
  11. /* Versions of the `struct stat' data structure. */
  12. #define _STAT_VER_LINUX_OLD 1
  13. #define _STAT_VER_KERNEL 1
  14. #define _STAT_VER_SVR4 2
  15. #define _STAT_VER_LINUX 3
  16. #define _STAT_VER _STAT_VER_LINUX /* The one defined below. */
  17. /* Versions of the `xmknod' interface. */
  18. #define _MKNOD_VER_LINUX 1
  19. #define _MKNOD_VER_SVR4 2
  20. #define _MKNOD_VER _MKNOD_VER_LINUX /* The bits defined below. */
  21. /*
  22. * For 32-bit architectures, this struct is similar to the stat64 but it
  23. * uses 32-bit members along with 32-bit padding. For 64-bit architectures
  24. * this struct is exactly the same with the stat64 one
  25. */
  26. struct stat
  27. {
  28. #ifndef __USE_FILE_OFFSET64
  29. # if __BYTE_ORDER == __LITTLE_ENDIAN
  30. unsigned long st_dev; /* Device. */
  31. unsigned long __pad1;
  32. unsigned long st_ino; /* 32bit file serial number. */
  33. unsigned long __pad2;
  34. unsigned int st_mode; /* File mode. */
  35. unsigned int st_nlink; /* Link count. */
  36. unsigned int st_uid; /* User ID of the file's owner. */
  37. unsigned int st_gid; /* Group ID of the file's group.*/
  38. unsigned long st_rdev; /* Device number, if device. */
  39. unsigned long __pad3;
  40. unsigned long long __pad4;
  41. long st_size; /* SIze of file, in bytes. */
  42. long __pad5;
  43. int st_blksize; /* Optimal block size for I/O. */
  44. int __pad6;
  45. long st_blocks; /* Number 512-byte blocks allocated */
  46. long __pad7;
  47. # else
  48. unsigned long __pad1;
  49. unsigned long st_dev; /* Device. */
  50. unsigned long __pad2;
  51. unsigned long st_ino; /* 32bit file serial number. */
  52. unsigned int st_mode; /* File mode. */
  53. unsigned int st_nlink; /* Link count. */
  54. unsigned int st_uid; /* User ID of the file's owner. */
  55. unsigned int st_gid; /* Group ID of the file's group.*/
  56. unsigned long __pad3;
  57. unsigned long st_rdev; /* Device number, if device. */
  58. unsigned long long __pad4;
  59. long __pad5;
  60. long st_size; /* Size of file, in bytes. */
  61. int st_blksize; /* Optimal block size for I/O. */
  62. int __pad6;
  63. long __pad7;
  64. long st_blocks; /* Number 512-byte blocks allocated */
  65. # endif /* __LITTLE_ENDIAN */
  66. #else
  67. unsigned long long st_dev; /* Device. */
  68. unsigned long long st_ino; /* 32bit file serial number. */
  69. unsigned int st_mode; /* File mode. */
  70. unsigned int st_nlink; /* Link count. */
  71. unsigned int st_uid; /* User ID of the file's owner. */
  72. unsigned int st_gid; /* Group ID of the file's group.*/
  73. unsigned long long st_rdev; /* Device number, if device. */
  74. unsigned long long _pad1;
  75. long long st_size; /* SIze of file, in bytes. */
  76. int st_blksize; /* Optimal block size for I/O. */
  77. int __pad2;
  78. long long st_blocks; /* Number 512-byte blocks allocated */
  79. #endif
  80. #ifdef __USE_MISC
  81. /* Nanosecond resolution timestamps are stored in a format
  82. equivalent to 'struct timespec'. This is the type used
  83. whenever possible but the Unix namespace rules do not allow the
  84. identifier 'timespec' to appear in the <sys/stat.h> header.
  85. Therefore we have to handle the use of this header in strictly
  86. standard-compliant sources special. */
  87. struct timespec st_atim; /* Time of last access. */
  88. struct timespec st_mtim; /* Time of last modification. */
  89. struct timespec st_ctim; /* Time of last status change. */
  90. # define st_atime st_atim.tv_sec /* Backward compatibility. */
  91. # define st_mtime st_mtim.tv_sec
  92. # define st_ctime st_ctim.tv_sec
  93. #else
  94. # ifndef __USE_FILE_OFFSET64
  95. long st_atime; /* Time of last access. */
  96. unsigned long st_atime_nsec;
  97. long st_mtime; /* Time of last modification. */
  98. unsigned long st_mtime_nsec;
  99. long st_ctime; /* Time of last status change. */
  100. unsigned long st_ctime_nsec;
  101. # else
  102. int st_atime; /* Time of last access. */
  103. unsigned int st_atime_nsec;
  104. int st_mtime; /* Time of last modification. */
  105. unsigned int st_mtime_nsec;
  106. int st_ctime; /* Time of last status change. */
  107. unsigned int st_ctime_nsec;
  108. # endif
  109. #endif
  110. unsigned int __unused4;
  111. unsigned int __unused5;
  112. } __ARCH_64BIT_ALIGNMENT__;
  113. #ifdef __USE_LARGEFILE64
  114. struct stat64
  115. {
  116. unsigned long long st_dev; /* Device. */
  117. unsigned long long st_ino; /* 32bit file serial number. */
  118. unsigned int st_mode; /* File mode. */
  119. unsigned int st_nlink; /* Link count. */
  120. unsigned int st_uid; /* User ID of the file's owner. */
  121. unsigned int st_gid; /* Group ID of the file's group.*/
  122. unsigned long long st_rdev; /* Device number, if device. */
  123. unsigned long long __pad3;
  124. long long st_size; /* Size of file, in bytes. */
  125. int st_blksize; /* Optimal block size for I/O. */
  126. int __pad4;
  127. long long st_blocks; /* Number 512-byte blocks allocated */
  128. # ifdef __USE_MISC
  129. /* Nanosecond resolution timestamps are stored in a format
  130. equivalent to 'struct timespec'. This is the type used
  131. whenever possible but the Unix namespace rules do not allow the
  132. identifier 'timespec' to appear in the <sys/stat.h> header.
  133. Therefore we have to handle the use of this header in strictly
  134. standard-compliant sources special. */
  135. struct timespec st_atim; /* Time of last access. */
  136. struct timespec st_mtim; /* Time of last modification. */
  137. struct timespec st_ctim; /* Time of last status change. */
  138. # else
  139. int st_atime; /* Time of last access. */
  140. unsigned int st_atime_nsec;
  141. int st_mtime; /* Time of last modification. */
  142. unsigned int st_mtime_nsec;
  143. int st_ctime; /* Time of last status change. */
  144. unsigned int st_ctime_nsec;
  145. # endif
  146. unsigned int __unused4;
  147. unsigned int __unused5;
  148. };
  149. #endif
  150. /* Tell code we have these members. */
  151. #define _STATBUF_ST_BLKSIZE
  152. #define _STATBUF_ST_RDEV
  153. /* Nanosecond resolution time values are supported. */
  154. #define _STATBUF_ST_NSEC
  155. /* Encoding of the file mode. */
  156. #define __S_IFMT 0170000 /* These bits determine file type. */
  157. /* File types. */
  158. #define __S_IFDIR 0040000 /* Directory. */
  159. #define __S_IFCHR 0020000 /* Character device. */
  160. #define __S_IFBLK 0060000 /* Block device. */
  161. #define __S_IFREG 0100000 /* Regular file. */
  162. #define __S_IFIFO 0010000 /* FIFO. */
  163. #define __S_IFLNK 0120000 /* Symbolic link. */
  164. #define __S_IFSOCK 0140000 /* Socket. */
  165. /* POSIX.1b objects. Note that these macros always evaluate to zero. But
  166. they do it by enforcing the correct use of the macros. */
  167. #define __S_TYPEISMQ(buf) ((buf)->st_mode - (buf)->st_mode)
  168. #define __S_TYPEISSEM(buf) ((buf)->st_mode - (buf)->st_mode)
  169. #define __S_TYPEISSHM(buf) ((buf)->st_mode - (buf)->st_mode)
  170. /* Protection bits. */
  171. #define __S_ISUID 04000 /* Set user ID on execution. */
  172. #define __S_ISGID 02000 /* Set group ID on execution. */
  173. #define __S_ISVTX 01000 /* Save swapped text after use (sticky). */
  174. #define __S_IREAD 0400 /* Read by owner. */
  175. #define __S_IWRITE 0200 /* Write by owner. */
  176. #define __S_IEXEC 0100 /* Execute by owner. */
  177. #ifdef __USE_ATFILE
  178. # define UTIME_NOW ((1l << 30) - 1l)
  179. # define UTIME_OMIT ((1l << 30) - 2l)
  180. #endif