xfs_inode_fork.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * Copyright (c) 2000-2003,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_INODE_FORK_H__
  19. #define __XFS_INODE_FORK_H__
  20. struct xfs_inode_log_item;
  21. struct xfs_dinode;
  22. /*
  23. * File incore extent information, present for each of data & attr forks.
  24. */
  25. typedef struct xfs_ifork {
  26. int if_bytes; /* bytes in if_u1 */
  27. int if_real_bytes; /* bytes allocated in if_u1 */
  28. struct xfs_btree_block *if_broot; /* file's incore btree root */
  29. short if_broot_bytes; /* bytes allocated for root */
  30. unsigned char if_flags; /* per-fork flags */
  31. int if_height; /* height of the extent tree */
  32. union {
  33. void *if_root; /* extent tree root */
  34. char *if_data; /* inline file data */
  35. } if_u1;
  36. } xfs_ifork_t;
  37. /*
  38. * Per-fork incore inode flags.
  39. */
  40. #define XFS_IFINLINE 0x01 /* Inline data is read in */
  41. #define XFS_IFEXTENTS 0x02 /* All extent pointers are read in */
  42. #define XFS_IFBROOT 0x04 /* i_broot points to the bmap b-tree root */
  43. /*
  44. * Fork handling.
  45. */
  46. #define XFS_IFORK_Q(ip) ((ip)->i_d.di_forkoff != 0)
  47. #define XFS_IFORK_BOFF(ip) ((int)((ip)->i_d.di_forkoff << 3))
  48. #define XFS_IFORK_PTR(ip,w) \
  49. ((w) == XFS_DATA_FORK ? \
  50. &(ip)->i_df : \
  51. ((w) == XFS_ATTR_FORK ? \
  52. (ip)->i_afp : \
  53. (ip)->i_cowfp))
  54. #define XFS_IFORK_DSIZE(ip) \
  55. (XFS_IFORK_Q(ip) ? \
  56. XFS_IFORK_BOFF(ip) : \
  57. XFS_LITINO((ip)->i_mount, (ip)->i_d.di_version))
  58. #define XFS_IFORK_ASIZE(ip) \
  59. (XFS_IFORK_Q(ip) ? \
  60. XFS_LITINO((ip)->i_mount, (ip)->i_d.di_version) - \
  61. XFS_IFORK_BOFF(ip) : \
  62. 0)
  63. #define XFS_IFORK_SIZE(ip,w) \
  64. ((w) == XFS_DATA_FORK ? \
  65. XFS_IFORK_DSIZE(ip) : \
  66. ((w) == XFS_ATTR_FORK ? \
  67. XFS_IFORK_ASIZE(ip) : \
  68. 0))
  69. #define XFS_IFORK_FORMAT(ip,w) \
  70. ((w) == XFS_DATA_FORK ? \
  71. (ip)->i_d.di_format : \
  72. ((w) == XFS_ATTR_FORK ? \
  73. (ip)->i_d.di_aformat : \
  74. (ip)->i_cformat))
  75. #define XFS_IFORK_FMT_SET(ip,w,n) \
  76. ((w) == XFS_DATA_FORK ? \
  77. ((ip)->i_d.di_format = (n)) : \
  78. ((w) == XFS_ATTR_FORK ? \
  79. ((ip)->i_d.di_aformat = (n)) : \
  80. ((ip)->i_cformat = (n))))
  81. #define XFS_IFORK_NEXTENTS(ip,w) \
  82. ((w) == XFS_DATA_FORK ? \
  83. (ip)->i_d.di_nextents : \
  84. ((w) == XFS_ATTR_FORK ? \
  85. (ip)->i_d.di_anextents : \
  86. (ip)->i_cnextents))
  87. #define XFS_IFORK_NEXT_SET(ip,w,n) \
  88. ((w) == XFS_DATA_FORK ? \
  89. ((ip)->i_d.di_nextents = (n)) : \
  90. ((w) == XFS_ATTR_FORK ? \
  91. ((ip)->i_d.di_anextents = (n)) : \
  92. ((ip)->i_cnextents = (n))))
  93. #define XFS_IFORK_MAXEXT(ip, w) \
  94. (XFS_IFORK_SIZE(ip, w) / sizeof(xfs_bmbt_rec_t))
  95. struct xfs_ifork *xfs_iext_state_to_fork(struct xfs_inode *ip, int state);
  96. int xfs_iformat_fork(struct xfs_inode *, struct xfs_dinode *);
  97. void xfs_iflush_fork(struct xfs_inode *, struct xfs_dinode *,
  98. struct xfs_inode_log_item *, int);
  99. void xfs_idestroy_fork(struct xfs_inode *, int);
  100. void xfs_idata_realloc(struct xfs_inode *, int, int);
  101. void xfs_iroot_realloc(struct xfs_inode *, int, int);
  102. int xfs_iread_extents(struct xfs_trans *, struct xfs_inode *, int);
  103. int xfs_iextents_copy(struct xfs_inode *, struct xfs_bmbt_rec *,
  104. int);
  105. void xfs_init_local_fork(struct xfs_inode *, int, const void *, int);
  106. xfs_extnum_t xfs_iext_count(struct xfs_ifork *ifp);
  107. void xfs_iext_insert(struct xfs_inode *, struct xfs_iext_cursor *cur,
  108. struct xfs_bmbt_irec *, int);
  109. void xfs_iext_remove(struct xfs_inode *, struct xfs_iext_cursor *,
  110. int);
  111. void xfs_iext_destroy(struct xfs_ifork *);
  112. bool xfs_iext_lookup_extent(struct xfs_inode *ip,
  113. struct xfs_ifork *ifp, xfs_fileoff_t bno,
  114. struct xfs_iext_cursor *cur,
  115. struct xfs_bmbt_irec *gotp);
  116. bool xfs_iext_lookup_extent_before(struct xfs_inode *ip,
  117. struct xfs_ifork *ifp, xfs_fileoff_t *end,
  118. struct xfs_iext_cursor *cur,
  119. struct xfs_bmbt_irec *gotp);
  120. bool xfs_iext_get_extent(struct xfs_ifork *ifp,
  121. struct xfs_iext_cursor *cur,
  122. struct xfs_bmbt_irec *gotp);
  123. void xfs_iext_update_extent(struct xfs_inode *ip, int state,
  124. struct xfs_iext_cursor *cur,
  125. struct xfs_bmbt_irec *gotp);
  126. void xfs_iext_first(struct xfs_ifork *, struct xfs_iext_cursor *);
  127. void xfs_iext_last(struct xfs_ifork *, struct xfs_iext_cursor *);
  128. void xfs_iext_next(struct xfs_ifork *, struct xfs_iext_cursor *);
  129. void xfs_iext_prev(struct xfs_ifork *, struct xfs_iext_cursor *);
  130. static inline bool xfs_iext_next_extent(struct xfs_ifork *ifp,
  131. struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *gotp)
  132. {
  133. xfs_iext_next(ifp, cur);
  134. return xfs_iext_get_extent(ifp, cur, gotp);
  135. }
  136. static inline bool xfs_iext_prev_extent(struct xfs_ifork *ifp,
  137. struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *gotp)
  138. {
  139. xfs_iext_prev(ifp, cur);
  140. return xfs_iext_get_extent(ifp, cur, gotp);
  141. }
  142. /*
  143. * Return the extent after cur in gotp without updating the cursor.
  144. */
  145. static inline bool xfs_iext_peek_next_extent(struct xfs_ifork *ifp,
  146. struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *gotp)
  147. {
  148. struct xfs_iext_cursor ncur = *cur;
  149. xfs_iext_next(ifp, &ncur);
  150. return xfs_iext_get_extent(ifp, &ncur, gotp);
  151. }
  152. /*
  153. * Return the extent before cur in gotp without updating the cursor.
  154. */
  155. static inline bool xfs_iext_peek_prev_extent(struct xfs_ifork *ifp,
  156. struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *gotp)
  157. {
  158. struct xfs_iext_cursor ncur = *cur;
  159. xfs_iext_prev(ifp, &ncur);
  160. return xfs_iext_get_extent(ifp, &ncur, gotp);
  161. }
  162. #define for_each_xfs_iext(ifp, ext, got) \
  163. for (xfs_iext_first((ifp), (ext)); \
  164. xfs_iext_get_extent((ifp), (ext), (got)); \
  165. xfs_iext_next((ifp), (ext)))
  166. extern struct kmem_zone *xfs_ifork_zone;
  167. extern void xfs_ifork_init_cow(struct xfs_inode *ip);
  168. #endif /* __XFS_INODE_FORK_H__ */