xfs_dinode.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. * Copyright (c) 2000,2002,2005 Silicon Graphics, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it would be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write the Free Software Foundation,
  16. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef __XFS_DINODE_H__
  19. #define __XFS_DINODE_H__
  20. #define XFS_DINODE_MAGIC 0x494e /* 'IN' */
  21. #define XFS_DINODE_GOOD_VERSION(v) (((v) == 1 || (v) == 2))
  22. typedef struct xfs_timestamp {
  23. __be32 t_sec; /* timestamp seconds */
  24. __be32 t_nsec; /* timestamp nanoseconds */
  25. } xfs_timestamp_t;
  26. /*
  27. * On-disk inode structure.
  28. *
  29. * This is just the header or "dinode core", the inode is expanded to fill a
  30. * variable size the leftover area split into a data and an attribute fork.
  31. * The format of the data and attribute fork depends on the format of the
  32. * inode as indicated by di_format and di_aformat. To access the data and
  33. * attribute use the XFS_DFORK_PTR, XFS_DFORK_DPTR, and XFS_DFORK_PTR macros
  34. * below.
  35. *
  36. * There is a very similar struct icdinode in xfs_inode which matches the
  37. * layout of the first 96 bytes of this structure, but is kept in native
  38. * format instead of big endian.
  39. */
  40. typedef struct xfs_dinode {
  41. __be16 di_magic; /* inode magic # = XFS_DINODE_MAGIC */
  42. __be16 di_mode; /* mode and type of file */
  43. __u8 di_version; /* inode version */
  44. __u8 di_format; /* format of di_c data */
  45. __be16 di_onlink; /* old number of links to file */
  46. __be32 di_uid; /* owner's user id */
  47. __be32 di_gid; /* owner's group id */
  48. __be32 di_nlink; /* number of links to file */
  49. __be16 di_projid_lo; /* lower part of owner's project id */
  50. __be16 di_projid_hi; /* higher part owner's project id */
  51. __u8 di_pad[6]; /* unused, zeroed space */
  52. __be16 di_flushiter; /* incremented on flush */
  53. xfs_timestamp_t di_atime; /* time last accessed */
  54. xfs_timestamp_t di_mtime; /* time last modified */
  55. xfs_timestamp_t di_ctime; /* time created/inode modified */
  56. __be64 di_size; /* number of bytes in file */
  57. __be64 di_nblocks; /* # of direct & btree blocks used */
  58. __be32 di_extsize; /* basic/minimum extent size for file */
  59. __be32 di_nextents; /* number of extents in data fork */
  60. __be16 di_anextents; /* number of extents in attribute fork*/
  61. __u8 di_forkoff; /* attr fork offs, <<3 for 64b align */
  62. __s8 di_aformat; /* format of attr fork's data */
  63. __be32 di_dmevmask; /* DMIG event mask */
  64. __be16 di_dmstate; /* DMIG state info */
  65. __be16 di_flags; /* random flags, XFS_DIFLAG_... */
  66. __be32 di_gen; /* generation number */
  67. /* di_next_unlinked is the only non-core field in the old dinode */
  68. __be32 di_next_unlinked;/* agi unlinked list ptr */
  69. } __attribute__((packed)) xfs_dinode_t;
  70. #define DI_MAX_FLUSH 0xffff
  71. /*
  72. * The 32 bit link count in the inode theoretically maxes out at UINT_MAX.
  73. * Since the pathconf interface is signed, we use 2^31 - 1 instead.
  74. * The old inode format had a 16 bit link count, so its maximum is USHRT_MAX.
  75. */
  76. #define XFS_MAXLINK ((1U << 31) - 1U)
  77. #define XFS_MAXLINK_1 65535U
  78. /*
  79. * Values for di_format
  80. */
  81. typedef enum xfs_dinode_fmt {
  82. XFS_DINODE_FMT_DEV, /* xfs_dev_t */
  83. XFS_DINODE_FMT_LOCAL, /* bulk data */
  84. XFS_DINODE_FMT_EXTENTS, /* struct xfs_bmbt_rec */
  85. XFS_DINODE_FMT_BTREE, /* struct xfs_bmdr_block */
  86. XFS_DINODE_FMT_UUID /* uuid_t */
  87. } xfs_dinode_fmt_t;
  88. /*
  89. * Inode minimum and maximum sizes.
  90. */
  91. #define XFS_DINODE_MIN_LOG 8
  92. #define XFS_DINODE_MAX_LOG 11
  93. #define XFS_DINODE_MIN_SIZE (1 << XFS_DINODE_MIN_LOG)
  94. #define XFS_DINODE_MAX_SIZE (1 << XFS_DINODE_MAX_LOG)
  95. /*
  96. * Inode size for given fs.
  97. */
  98. #define XFS_LITINO(mp) \
  99. ((int)(((mp)->m_sb.sb_inodesize) - sizeof(struct xfs_dinode)))
  100. #define XFS_BROOT_SIZE_ADJ \
  101. (XFS_BTREE_LBLOCK_LEN - sizeof(xfs_bmdr_block_t))
  102. /*
  103. * Inode data & attribute fork sizes, per inode.
  104. */
  105. #define XFS_DFORK_Q(dip) ((dip)->di_forkoff != 0)
  106. #define XFS_DFORK_BOFF(dip) ((int)((dip)->di_forkoff << 3))
  107. #define XFS_DFORK_DSIZE(dip,mp) \
  108. (XFS_DFORK_Q(dip) ? \
  109. XFS_DFORK_BOFF(dip) : \
  110. XFS_LITINO(mp))
  111. #define XFS_DFORK_ASIZE(dip,mp) \
  112. (XFS_DFORK_Q(dip) ? \
  113. XFS_LITINO(mp) - XFS_DFORK_BOFF(dip) : \
  114. 0)
  115. #define XFS_DFORK_SIZE(dip,mp,w) \
  116. ((w) == XFS_DATA_FORK ? \
  117. XFS_DFORK_DSIZE(dip, mp) : \
  118. XFS_DFORK_ASIZE(dip, mp))
  119. /*
  120. * Return pointers to the data or attribute forks.
  121. */
  122. #define XFS_DFORK_DPTR(dip) \
  123. ((char *)(dip) + sizeof(struct xfs_dinode))
  124. #define XFS_DFORK_APTR(dip) \
  125. (XFS_DFORK_DPTR(dip) + XFS_DFORK_BOFF(dip))
  126. #define XFS_DFORK_PTR(dip,w) \
  127. ((w) == XFS_DATA_FORK ? XFS_DFORK_DPTR(dip) : XFS_DFORK_APTR(dip))
  128. #define XFS_DFORK_FORMAT(dip,w) \
  129. ((w) == XFS_DATA_FORK ? \
  130. (dip)->di_format : \
  131. (dip)->di_aformat)
  132. #define XFS_DFORK_NEXTENTS(dip,w) \
  133. ((w) == XFS_DATA_FORK ? \
  134. be32_to_cpu((dip)->di_nextents) : \
  135. be16_to_cpu((dip)->di_anextents))
  136. #define XFS_BUF_TO_DINODE(bp) ((xfs_dinode_t *)XFS_BUF_PTR(bp))
  137. /*
  138. * For block and character special files the 32bit dev_t is stored at the
  139. * beginning of the data fork.
  140. */
  141. static inline xfs_dev_t xfs_dinode_get_rdev(struct xfs_dinode *dip)
  142. {
  143. return be32_to_cpu(*(__be32 *)XFS_DFORK_DPTR(dip));
  144. }
  145. static inline void xfs_dinode_put_rdev(struct xfs_dinode *dip, xfs_dev_t rdev)
  146. {
  147. *(__be32 *)XFS_DFORK_DPTR(dip) = cpu_to_be32(rdev);
  148. }
  149. /*
  150. * Values for di_flags
  151. * There should be a one-to-one correspondence between these flags and the
  152. * XFS_XFLAG_s.
  153. */
  154. #define XFS_DIFLAG_REALTIME_BIT 0 /* file's blocks come from rt area */
  155. #define XFS_DIFLAG_PREALLOC_BIT 1 /* file space has been preallocated */
  156. #define XFS_DIFLAG_NEWRTBM_BIT 2 /* for rtbitmap inode, new format */
  157. #define XFS_DIFLAG_IMMUTABLE_BIT 3 /* inode is immutable */
  158. #define XFS_DIFLAG_APPEND_BIT 4 /* inode is append-only */
  159. #define XFS_DIFLAG_SYNC_BIT 5 /* inode is written synchronously */
  160. #define XFS_DIFLAG_NOATIME_BIT 6 /* do not update atime */
  161. #define XFS_DIFLAG_NODUMP_BIT 7 /* do not dump */
  162. #define XFS_DIFLAG_RTINHERIT_BIT 8 /* create with realtime bit set */
  163. #define XFS_DIFLAG_PROJINHERIT_BIT 9 /* create with parents projid */
  164. #define XFS_DIFLAG_NOSYMLINKS_BIT 10 /* disallow symlink creation */
  165. #define XFS_DIFLAG_EXTSIZE_BIT 11 /* inode extent size allocator hint */
  166. #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
  167. #define XFS_DIFLAG_NODEFRAG_BIT 13 /* do not reorganize/defragment */
  168. #define XFS_DIFLAG_FILESTREAM_BIT 14 /* use filestream allocator */
  169. #define XFS_DIFLAG_REALTIME (1 << XFS_DIFLAG_REALTIME_BIT)
  170. #define XFS_DIFLAG_PREALLOC (1 << XFS_DIFLAG_PREALLOC_BIT)
  171. #define XFS_DIFLAG_NEWRTBM (1 << XFS_DIFLAG_NEWRTBM_BIT)
  172. #define XFS_DIFLAG_IMMUTABLE (1 << XFS_DIFLAG_IMMUTABLE_BIT)
  173. #define XFS_DIFLAG_APPEND (1 << XFS_DIFLAG_APPEND_BIT)
  174. #define XFS_DIFLAG_SYNC (1 << XFS_DIFLAG_SYNC_BIT)
  175. #define XFS_DIFLAG_NOATIME (1 << XFS_DIFLAG_NOATIME_BIT)
  176. #define XFS_DIFLAG_NODUMP (1 << XFS_DIFLAG_NODUMP_BIT)
  177. #define XFS_DIFLAG_RTINHERIT (1 << XFS_DIFLAG_RTINHERIT_BIT)
  178. #define XFS_DIFLAG_PROJINHERIT (1 << XFS_DIFLAG_PROJINHERIT_BIT)
  179. #define XFS_DIFLAG_NOSYMLINKS (1 << XFS_DIFLAG_NOSYMLINKS_BIT)
  180. #define XFS_DIFLAG_EXTSIZE (1 << XFS_DIFLAG_EXTSIZE_BIT)
  181. #define XFS_DIFLAG_EXTSZINHERIT (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
  182. #define XFS_DIFLAG_NODEFRAG (1 << XFS_DIFLAG_NODEFRAG_BIT)
  183. #define XFS_DIFLAG_FILESTREAM (1 << XFS_DIFLAG_FILESTREAM_BIT)
  184. #ifdef CONFIG_XFS_RT
  185. #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
  186. #else
  187. #define XFS_IS_REALTIME_INODE(ip) (0)
  188. #endif
  189. #define XFS_DIFLAG_ANY \
  190. (XFS_DIFLAG_REALTIME | XFS_DIFLAG_PREALLOC | XFS_DIFLAG_NEWRTBM | \
  191. XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
  192. XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
  193. XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
  194. XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
  195. #endif /* __XFS_DINODE_H__ */