xfs_inode_fork.h 5.8 KB

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