xfs_inode_fork.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. * The following xfs_ext_irec_t struct introduces a second (top) level
  24. * to the in-core extent allocation scheme. These structs are allocated
  25. * in a contiguous block, creating an indirection array where each entry
  26. * (irec) contains a pointer to a buffer of in-core extent records which
  27. * it manages. Each extent buffer is 4k in size, since 4k is the system
  28. * page size on Linux i386 and systems with larger page sizes don't seem
  29. * to gain much, if anything, by using their native page size as the
  30. * extent buffer size. Also, using 4k extent buffers everywhere provides
  31. * a consistent interface for CXFS across different platforms.
  32. *
  33. * There is currently no limit on the number of irec's (extent lists)
  34. * allowed, so heavily fragmented files may require an indirection array
  35. * which spans multiple system pages of memory. The number of extents
  36. * which would require this amount of contiguous memory is very large
  37. * and should not cause problems in the foreseeable future. However,
  38. * if the memory needed for the contiguous array ever becomes a problem,
  39. * it is possible that a third level of indirection may be required.
  40. */
  41. typedef struct xfs_ext_irec {
  42. xfs_bmbt_rec_host_t *er_extbuf; /* block of extent records */
  43. xfs_extnum_t er_extoff; /* extent offset in file */
  44. xfs_extnum_t er_extcount; /* number of extents in page/block */
  45. } xfs_ext_irec_t;
  46. /*
  47. * File incore extent information, present for each of data & attr forks.
  48. */
  49. #define XFS_IEXT_BUFSZ 4096
  50. #define XFS_LINEAR_EXTS (XFS_IEXT_BUFSZ / (uint)sizeof(xfs_bmbt_rec_t))
  51. #define XFS_INLINE_EXTS 2
  52. #define XFS_INLINE_DATA 32
  53. typedef struct xfs_ifork {
  54. int if_bytes; /* bytes in if_u1 */
  55. int if_real_bytes; /* bytes allocated in if_u1 */
  56. struct xfs_btree_block *if_broot; /* file's incore btree root */
  57. short if_broot_bytes; /* bytes allocated for root */
  58. unsigned char if_flags; /* per-fork flags */
  59. union {
  60. xfs_bmbt_rec_host_t *if_extents;/* linear map file exts */
  61. xfs_ext_irec_t *if_ext_irec; /* irec map file exts */
  62. char *if_data; /* inline file data */
  63. } if_u1;
  64. union {
  65. xfs_bmbt_rec_host_t if_inline_ext[XFS_INLINE_EXTS];
  66. /* very small file extents */
  67. char if_inline_data[XFS_INLINE_DATA];
  68. /* very small file data */
  69. xfs_dev_t if_rdev; /* dev number if special */
  70. uuid_t if_uuid; /* mount point value */
  71. } if_u2;
  72. } xfs_ifork_t;
  73. /*
  74. * Per-fork incore inode flags.
  75. */
  76. #define XFS_IFINLINE 0x01 /* Inline data is read in */
  77. #define XFS_IFEXTENTS 0x02 /* All extent pointers are read in */
  78. #define XFS_IFBROOT 0x04 /* i_broot points to the bmap b-tree root */
  79. #define XFS_IFEXTIREC 0x08 /* Indirection array of extent blocks */
  80. /*
  81. * Fork handling.
  82. */
  83. #define XFS_IFORK_Q(ip) ((ip)->i_d.di_forkoff != 0)
  84. #define XFS_IFORK_BOFF(ip) ((int)((ip)->i_d.di_forkoff << 3))
  85. #define XFS_IFORK_PTR(ip,w) \
  86. ((w) == XFS_DATA_FORK ? \
  87. &(ip)->i_df : \
  88. ((w) == XFS_ATTR_FORK ? \
  89. (ip)->i_afp : \
  90. (ip)->i_cowfp))
  91. #define XFS_IFORK_DSIZE(ip) \
  92. (XFS_IFORK_Q(ip) ? \
  93. XFS_IFORK_BOFF(ip) : \
  94. XFS_LITINO((ip)->i_mount, (ip)->i_d.di_version))
  95. #define XFS_IFORK_ASIZE(ip) \
  96. (XFS_IFORK_Q(ip) ? \
  97. XFS_LITINO((ip)->i_mount, (ip)->i_d.di_version) - \
  98. XFS_IFORK_BOFF(ip) : \
  99. 0)
  100. #define XFS_IFORK_SIZE(ip,w) \
  101. ((w) == XFS_DATA_FORK ? \
  102. XFS_IFORK_DSIZE(ip) : \
  103. ((w) == XFS_ATTR_FORK ? \
  104. XFS_IFORK_ASIZE(ip) : \
  105. 0))
  106. #define XFS_IFORK_FORMAT(ip,w) \
  107. ((w) == XFS_DATA_FORK ? \
  108. (ip)->i_d.di_format : \
  109. ((w) == XFS_ATTR_FORK ? \
  110. (ip)->i_d.di_aformat : \
  111. (ip)->i_cformat))
  112. #define XFS_IFORK_FMT_SET(ip,w,n) \
  113. ((w) == XFS_DATA_FORK ? \
  114. ((ip)->i_d.di_format = (n)) : \
  115. ((w) == XFS_ATTR_FORK ? \
  116. ((ip)->i_d.di_aformat = (n)) : \
  117. ((ip)->i_cformat = (n))))
  118. #define XFS_IFORK_NEXTENTS(ip,w) \
  119. ((w) == XFS_DATA_FORK ? \
  120. (ip)->i_d.di_nextents : \
  121. ((w) == XFS_ATTR_FORK ? \
  122. (ip)->i_d.di_anextents : \
  123. (ip)->i_cnextents))
  124. #define XFS_IFORK_NEXT_SET(ip,w,n) \
  125. ((w) == XFS_DATA_FORK ? \
  126. ((ip)->i_d.di_nextents = (n)) : \
  127. ((w) == XFS_ATTR_FORK ? \
  128. ((ip)->i_d.di_anextents = (n)) : \
  129. ((ip)->i_cnextents = (n))))
  130. #define XFS_IFORK_MAXEXT(ip, w) \
  131. (XFS_IFORK_SIZE(ip, w) / sizeof(xfs_bmbt_rec_t))
  132. struct xfs_ifork *xfs_iext_state_to_fork(struct xfs_inode *ip, int state);
  133. int xfs_iformat_fork(struct xfs_inode *, struct xfs_dinode *);
  134. void xfs_iflush_fork(struct xfs_inode *, struct xfs_dinode *,
  135. struct xfs_inode_log_item *, int);
  136. void xfs_idestroy_fork(struct xfs_inode *, int);
  137. void xfs_idata_realloc(struct xfs_inode *, int, int);
  138. void xfs_iroot_realloc(struct xfs_inode *, int, int);
  139. int xfs_iread_extents(struct xfs_trans *, struct xfs_inode *, int);
  140. int xfs_iextents_copy(struct xfs_inode *, struct xfs_bmbt_rec *,
  141. int);
  142. void xfs_init_local_fork(struct xfs_inode *, int, const void *, int);
  143. struct xfs_bmbt_rec_host *
  144. xfs_iext_get_ext(struct xfs_ifork *, xfs_extnum_t);
  145. xfs_extnum_t xfs_iext_count(struct xfs_ifork *);
  146. void xfs_iext_insert(struct xfs_inode *, xfs_extnum_t, xfs_extnum_t,
  147. struct xfs_bmbt_irec *, int);
  148. void xfs_iext_add(struct xfs_ifork *, xfs_extnum_t, int);
  149. void xfs_iext_add_indirect_multi(struct xfs_ifork *, int,
  150. xfs_extnum_t, int);
  151. void xfs_iext_remove(struct xfs_inode *, xfs_extnum_t, int, int);
  152. void xfs_iext_remove_inline(struct xfs_ifork *, xfs_extnum_t, int);
  153. void xfs_iext_remove_direct(struct xfs_ifork *, xfs_extnum_t, int);
  154. void xfs_iext_remove_indirect(struct xfs_ifork *, xfs_extnum_t, int);
  155. void xfs_iext_realloc_direct(struct xfs_ifork *, int);
  156. void xfs_iext_direct_to_inline(struct xfs_ifork *, xfs_extnum_t);
  157. void xfs_iext_inline_to_direct(struct xfs_ifork *, int);
  158. void xfs_iext_destroy(struct xfs_ifork *);
  159. struct xfs_bmbt_rec_host *
  160. xfs_iext_bno_to_ext(struct xfs_ifork *, xfs_fileoff_t, int *);
  161. struct xfs_ext_irec *
  162. xfs_iext_bno_to_irec(struct xfs_ifork *, xfs_fileoff_t, int *);
  163. struct xfs_ext_irec *
  164. xfs_iext_idx_to_irec(struct xfs_ifork *, xfs_extnum_t *, int *,
  165. int);
  166. void xfs_iext_irec_init(struct xfs_ifork *);
  167. struct xfs_ext_irec *
  168. xfs_iext_irec_new(struct xfs_ifork *, int);
  169. void xfs_iext_irec_remove(struct xfs_ifork *, int);
  170. void xfs_iext_irec_compact(struct xfs_ifork *);
  171. void xfs_iext_irec_compact_pages(struct xfs_ifork *);
  172. void xfs_iext_irec_compact_full(struct xfs_ifork *);
  173. void xfs_iext_irec_update_extoffs(struct xfs_ifork *, int, int);
  174. bool xfs_iext_lookup_extent(struct xfs_inode *ip,
  175. struct xfs_ifork *ifp, xfs_fileoff_t bno,
  176. xfs_extnum_t *idxp, struct xfs_bmbt_irec *gotp);
  177. bool xfs_iext_get_extent(struct xfs_ifork *ifp, xfs_extnum_t idx,
  178. struct xfs_bmbt_irec *gotp);
  179. extern struct kmem_zone *xfs_ifork_zone;
  180. extern void xfs_ifork_init_cow(struct xfs_inode *ip);
  181. #endif /* __XFS_INODE_FORK_H__ */