xfs_dinode.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. struct xfs_buf;
  21. struct xfs_mount;
  22. #define XFS_DINODE_VERSION_1 1
  23. #define XFS_DINODE_VERSION_2 2
  24. #define XFS_DINODE_GOOD_VERSION(v) \
  25. (((v) == XFS_DINODE_VERSION_1 || (v) == XFS_DINODE_VERSION_2))
  26. #define XFS_DINODE_MAGIC 0x494e /* 'IN' */
  27. /*
  28. * Disk inode structure.
  29. * This is just the header; the inode is expanded to fill a variable size
  30. * with the last field expanding. It is split into the core and "other"
  31. * because we only need the core part in the in-core inode.
  32. */
  33. typedef struct xfs_timestamp {
  34. __be32 t_sec; /* timestamp seconds */
  35. __be32 t_nsec; /* timestamp nanoseconds */
  36. } xfs_timestamp_t;
  37. /*
  38. * Note: Coordinate changes to this structure with the XFS_DI_* #defines
  39. * below, the offsets table in xfs_ialloc_log_di() and struct xfs_icdinode
  40. * in xfs_inode.h.
  41. */
  42. typedef struct xfs_dinode_core {
  43. __be16 di_magic; /* inode magic # = XFS_DINODE_MAGIC */
  44. __be16 di_mode; /* mode and type of file */
  45. __u8 di_version; /* inode version */
  46. __u8 di_format; /* format of di_c data */
  47. __be16 di_onlink; /* old number of links to file */
  48. __be32 di_uid; /* owner's user id */
  49. __be32 di_gid; /* owner's group id */
  50. __be32 di_nlink; /* number of links to file */
  51. __be16 di_projid; /* owner's project id */
  52. __u8 di_pad[8]; /* unused, zeroed space */
  53. __be16 di_flushiter; /* incremented on flush */
  54. xfs_timestamp_t di_atime; /* time last accessed */
  55. xfs_timestamp_t di_mtime; /* time last modified */
  56. xfs_timestamp_t di_ctime; /* time created/inode modified */
  57. __be64 di_size; /* number of bytes in file */
  58. __be64 di_nblocks; /* # of direct & btree blocks used */
  59. __be32 di_extsize; /* basic/minimum extent size for file */
  60. __be32 di_nextents; /* number of extents in data fork */
  61. __be16 di_anextents; /* number of extents in attribute fork*/
  62. __u8 di_forkoff; /* attr fork offs, <<3 for 64b align */
  63. __s8 di_aformat; /* format of attr fork's data */
  64. __be32 di_dmevmask; /* DMIG event mask */
  65. __be16 di_dmstate; /* DMIG state info */
  66. __be16 di_flags; /* random flags, XFS_DIFLAG_... */
  67. __be32 di_gen; /* generation number */
  68. } xfs_dinode_core_t;
  69. #define DI_MAX_FLUSH 0xffff
  70. typedef struct xfs_dinode
  71. {
  72. xfs_dinode_core_t di_core;
  73. /*
  74. * In adding anything between the core and the union, be
  75. * sure to update the macros like XFS_LITINO below and
  76. * XFS_BMAP_RBLOCK_DSIZE in xfs_bmap_btree.h.
  77. */
  78. __be32 di_next_unlinked;/* agi unlinked list ptr */
  79. union {
  80. xfs_bmdr_block_t di_bmbt; /* btree root block */
  81. xfs_bmbt_rec_32_t di_bmx[1]; /* extent list */
  82. xfs_dir2_sf_t di_dir2sf; /* shortform directory v2 */
  83. char di_c[1]; /* local contents */
  84. __be32 di_dev; /* device for S_IFCHR/S_IFBLK */
  85. uuid_t di_muuid; /* mount point value */
  86. char di_symlink[1]; /* local symbolic link */
  87. } di_u;
  88. union {
  89. xfs_bmdr_block_t di_abmbt; /* btree root block */
  90. xfs_bmbt_rec_32_t di_abmx[1]; /* extent list */
  91. xfs_attr_shortform_t di_attrsf; /* shortform attribute list */
  92. } di_a;
  93. } xfs_dinode_t;
  94. /*
  95. * The 32 bit link count in the inode theoretically maxes out at UINT_MAX.
  96. * Since the pathconf interface is signed, we use 2^31 - 1 instead.
  97. * The old inode format had a 16 bit link count, so its maximum is USHRT_MAX.
  98. */
  99. #define XFS_MAXLINK ((1U << 31) - 1U)
  100. #define XFS_MAXLINK_1 65535U
  101. /*
  102. * Bit names for logging disk inodes only
  103. */
  104. #define XFS_DI_MAGIC 0x0000001
  105. #define XFS_DI_MODE 0x0000002
  106. #define XFS_DI_VERSION 0x0000004
  107. #define XFS_DI_FORMAT 0x0000008
  108. #define XFS_DI_ONLINK 0x0000010
  109. #define XFS_DI_UID 0x0000020
  110. #define XFS_DI_GID 0x0000040
  111. #define XFS_DI_NLINK 0x0000080
  112. #define XFS_DI_PROJID 0x0000100
  113. #define XFS_DI_PAD 0x0000200
  114. #define XFS_DI_ATIME 0x0000400
  115. #define XFS_DI_MTIME 0x0000800
  116. #define XFS_DI_CTIME 0x0001000
  117. #define XFS_DI_SIZE 0x0002000
  118. #define XFS_DI_NBLOCKS 0x0004000
  119. #define XFS_DI_EXTSIZE 0x0008000
  120. #define XFS_DI_NEXTENTS 0x0010000
  121. #define XFS_DI_NAEXTENTS 0x0020000
  122. #define XFS_DI_FORKOFF 0x0040000
  123. #define XFS_DI_AFORMAT 0x0080000
  124. #define XFS_DI_DMEVMASK 0x0100000
  125. #define XFS_DI_DMSTATE 0x0200000
  126. #define XFS_DI_FLAGS 0x0400000
  127. #define XFS_DI_GEN 0x0800000
  128. #define XFS_DI_NEXT_UNLINKED 0x1000000
  129. #define XFS_DI_U 0x2000000
  130. #define XFS_DI_A 0x4000000
  131. #define XFS_DI_NUM_BITS 27
  132. #define XFS_DI_ALL_BITS ((1 << XFS_DI_NUM_BITS) - 1)
  133. #define XFS_DI_CORE_BITS (XFS_DI_ALL_BITS & ~(XFS_DI_U|XFS_DI_A))
  134. /*
  135. * Values for di_format
  136. */
  137. typedef enum xfs_dinode_fmt
  138. {
  139. XFS_DINODE_FMT_DEV, /* CHR, BLK: di_dev */
  140. XFS_DINODE_FMT_LOCAL, /* DIR, REG: di_c */
  141. /* LNK: di_symlink */
  142. XFS_DINODE_FMT_EXTENTS, /* DIR, REG, LNK: di_bmx */
  143. XFS_DINODE_FMT_BTREE, /* DIR, REG, LNK: di_bmbt */
  144. XFS_DINODE_FMT_UUID /* MNT: di_uuid */
  145. } xfs_dinode_fmt_t;
  146. /*
  147. * Inode minimum and maximum sizes.
  148. */
  149. #define XFS_DINODE_MIN_LOG 8
  150. #define XFS_DINODE_MAX_LOG 11
  151. #define XFS_DINODE_MIN_SIZE (1 << XFS_DINODE_MIN_LOG)
  152. #define XFS_DINODE_MAX_SIZE (1 << XFS_DINODE_MAX_LOG)
  153. /*
  154. * Inode size for given fs.
  155. */
  156. #define XFS_LITINO(mp) ((mp)->m_litino)
  157. #define XFS_BROOT_SIZE_ADJ \
  158. (sizeof(xfs_bmbt_block_t) - sizeof(xfs_bmdr_block_t))
  159. /*
  160. * Inode data & attribute fork sizes, per inode.
  161. */
  162. #define XFS_DFORK_Q(dip) ((dip)->di_core.di_forkoff != 0)
  163. #define XFS_DFORK_BOFF(dip) ((int)((dip)->di_core.di_forkoff << 3))
  164. #define XFS_DFORK_DSIZE(dip,mp) \
  165. (XFS_DFORK_Q(dip) ? \
  166. XFS_DFORK_BOFF(dip) : \
  167. XFS_LITINO(mp))
  168. #define XFS_DFORK_ASIZE(dip,mp) \
  169. (XFS_DFORK_Q(dip) ? \
  170. XFS_LITINO(mp) - XFS_DFORK_BOFF(dip) : \
  171. 0)
  172. #define XFS_DFORK_SIZE(dip,mp,w) \
  173. ((w) == XFS_DATA_FORK ? \
  174. XFS_DFORK_DSIZE(dip, mp) : \
  175. XFS_DFORK_ASIZE(dip, mp))
  176. #define XFS_DFORK_DPTR(dip) ((dip)->di_u.di_c)
  177. #define XFS_DFORK_APTR(dip) \
  178. ((dip)->di_u.di_c + XFS_DFORK_BOFF(dip))
  179. #define XFS_DFORK_PTR(dip,w) \
  180. ((w) == XFS_DATA_FORK ? XFS_DFORK_DPTR(dip) : XFS_DFORK_APTR(dip))
  181. #define XFS_DFORK_FORMAT(dip,w) \
  182. ((w) == XFS_DATA_FORK ? \
  183. (dip)->di_core.di_format : \
  184. (dip)->di_core.di_aformat)
  185. #define XFS_DFORK_NEXTENTS(dip,w) \
  186. ((w) == XFS_DATA_FORK ? \
  187. be32_to_cpu((dip)->di_core.di_nextents) : \
  188. be16_to_cpu((dip)->di_core.di_anextents))
  189. #define XFS_BUF_TO_DINODE(bp) ((xfs_dinode_t *)XFS_BUF_PTR(bp))
  190. /*
  191. * Values for di_flags
  192. * There should be a one-to-one correspondence between these flags and the
  193. * XFS_XFLAG_s.
  194. */
  195. #define XFS_DIFLAG_REALTIME_BIT 0 /* file's blocks come from rt area */
  196. #define XFS_DIFLAG_PREALLOC_BIT 1 /* file space has been preallocated */
  197. #define XFS_DIFLAG_NEWRTBM_BIT 2 /* for rtbitmap inode, new format */
  198. #define XFS_DIFLAG_IMMUTABLE_BIT 3 /* inode is immutable */
  199. #define XFS_DIFLAG_APPEND_BIT 4 /* inode is append-only */
  200. #define XFS_DIFLAG_SYNC_BIT 5 /* inode is written synchronously */
  201. #define XFS_DIFLAG_NOATIME_BIT 6 /* do not update atime */
  202. #define XFS_DIFLAG_NODUMP_BIT 7 /* do not dump */
  203. #define XFS_DIFLAG_RTINHERIT_BIT 8 /* create with realtime bit set */
  204. #define XFS_DIFLAG_PROJINHERIT_BIT 9 /* create with parents projid */
  205. #define XFS_DIFLAG_NOSYMLINKS_BIT 10 /* disallow symlink creation */
  206. #define XFS_DIFLAG_EXTSIZE_BIT 11 /* inode extent size allocator hint */
  207. #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
  208. #define XFS_DIFLAG_NODEFRAG_BIT 13 /* do not reorganize/defragment */
  209. #define XFS_DIFLAG_FILESTREAM_BIT 14 /* use filestream allocator */
  210. #define XFS_DIFLAG_REALTIME (1 << XFS_DIFLAG_REALTIME_BIT)
  211. #define XFS_DIFLAG_PREALLOC (1 << XFS_DIFLAG_PREALLOC_BIT)
  212. #define XFS_DIFLAG_NEWRTBM (1 << XFS_DIFLAG_NEWRTBM_BIT)
  213. #define XFS_DIFLAG_IMMUTABLE (1 << XFS_DIFLAG_IMMUTABLE_BIT)
  214. #define XFS_DIFLAG_APPEND (1 << XFS_DIFLAG_APPEND_BIT)
  215. #define XFS_DIFLAG_SYNC (1 << XFS_DIFLAG_SYNC_BIT)
  216. #define XFS_DIFLAG_NOATIME (1 << XFS_DIFLAG_NOATIME_BIT)
  217. #define XFS_DIFLAG_NODUMP (1 << XFS_DIFLAG_NODUMP_BIT)
  218. #define XFS_DIFLAG_RTINHERIT (1 << XFS_DIFLAG_RTINHERIT_BIT)
  219. #define XFS_DIFLAG_PROJINHERIT (1 << XFS_DIFLAG_PROJINHERIT_BIT)
  220. #define XFS_DIFLAG_NOSYMLINKS (1 << XFS_DIFLAG_NOSYMLINKS_BIT)
  221. #define XFS_DIFLAG_EXTSIZE (1 << XFS_DIFLAG_EXTSIZE_BIT)
  222. #define XFS_DIFLAG_EXTSZINHERIT (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
  223. #define XFS_DIFLAG_NODEFRAG (1 << XFS_DIFLAG_NODEFRAG_BIT)
  224. #define XFS_DIFLAG_FILESTREAM (1 << XFS_DIFLAG_FILESTREAM_BIT)
  225. #ifdef CONFIG_XFS_RT
  226. #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
  227. #else
  228. #define XFS_IS_REALTIME_INODE(ip) (0)
  229. #endif
  230. #define XFS_DIFLAG_ANY \
  231. (XFS_DIFLAG_REALTIME | XFS_DIFLAG_PREALLOC | XFS_DIFLAG_NEWRTBM | \
  232. XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
  233. XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
  234. XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
  235. XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
  236. #endif /* __XFS_DINODE_H__ */