xfs_dir2_leaf.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /*
  2. * Copyright (c) 2000-2001,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_DIR2_LEAF_H__
  19. #define __XFS_DIR2_LEAF_H__
  20. struct uio;
  21. struct xfs_dabuf;
  22. struct xfs_da_args;
  23. struct xfs_inode;
  24. struct xfs_mount;
  25. struct xfs_trans;
  26. /*
  27. * Offset of the leaf/node space. First block in this space
  28. * is the btree root.
  29. */
  30. #define XFS_DIR2_LEAF_SPACE 1
  31. #define XFS_DIR2_LEAF_OFFSET (XFS_DIR2_LEAF_SPACE * XFS_DIR2_SPACE_SIZE)
  32. #define XFS_DIR2_LEAF_FIRSTDB(mp) \
  33. xfs_dir2_byte_to_db(mp, XFS_DIR2_LEAF_OFFSET)
  34. /*
  35. * Offset in data space of a data entry.
  36. */
  37. typedef __uint32_t xfs_dir2_dataptr_t;
  38. #define XFS_DIR2_MAX_DATAPTR ((xfs_dir2_dataptr_t)0xffffffff)
  39. #define XFS_DIR2_NULL_DATAPTR ((xfs_dir2_dataptr_t)0)
  40. /*
  41. * Leaf block header.
  42. */
  43. typedef struct xfs_dir2_leaf_hdr {
  44. xfs_da_blkinfo_t info; /* header for da routines */
  45. __be16 count; /* count of entries */
  46. __be16 stale; /* count of stale entries */
  47. } xfs_dir2_leaf_hdr_t;
  48. /*
  49. * Leaf block entry.
  50. */
  51. typedef struct xfs_dir2_leaf_entry {
  52. __be32 hashval; /* hash value of name */
  53. __be32 address; /* address of data entry */
  54. } xfs_dir2_leaf_entry_t;
  55. /*
  56. * Leaf block tail.
  57. */
  58. typedef struct xfs_dir2_leaf_tail {
  59. __be32 bestcount;
  60. } xfs_dir2_leaf_tail_t;
  61. /*
  62. * Leaf block.
  63. * bests and tail are at the end of the block for single-leaf only
  64. * (magic = XFS_DIR2_LEAF1_MAGIC not XFS_DIR2_LEAFN_MAGIC).
  65. */
  66. typedef struct xfs_dir2_leaf {
  67. xfs_dir2_leaf_hdr_t hdr; /* leaf header */
  68. xfs_dir2_leaf_entry_t ents[1]; /* entries */
  69. /* ... */
  70. xfs_dir2_data_off_t bests[1]; /* best free counts */
  71. xfs_dir2_leaf_tail_t tail; /* leaf tail */
  72. } xfs_dir2_leaf_t;
  73. /*
  74. * DB blocks here are logical directory block numbers, not filesystem blocks.
  75. */
  76. static inline int xfs_dir2_max_leaf_ents(struct xfs_mount *mp)
  77. {
  78. return (int)(((mp)->m_dirblksize - (uint)sizeof(xfs_dir2_leaf_hdr_t)) /
  79. (uint)sizeof(xfs_dir2_leaf_entry_t));
  80. }
  81. /*
  82. * Get address of the bestcount field in the single-leaf block.
  83. */
  84. static inline xfs_dir2_leaf_tail_t *
  85. xfs_dir2_leaf_tail_p(struct xfs_mount *mp, xfs_dir2_leaf_t *lp)
  86. {
  87. return (xfs_dir2_leaf_tail_t *)
  88. ((char *)(lp) + (mp)->m_dirblksize -
  89. (uint)sizeof(xfs_dir2_leaf_tail_t));
  90. }
  91. /*
  92. * Get address of the bests array in the single-leaf block.
  93. */
  94. static inline __be16 *
  95. xfs_dir2_leaf_bests_p(xfs_dir2_leaf_tail_t *ltp)
  96. {
  97. return (__be16 *)ltp - be32_to_cpu(ltp->bestcount);
  98. }
  99. /*
  100. * Convert dataptr to byte in file space
  101. */
  102. static inline xfs_dir2_off_t
  103. xfs_dir2_dataptr_to_byte(struct xfs_mount *mp, xfs_dir2_dataptr_t dp)
  104. {
  105. return (xfs_dir2_off_t)(dp) << XFS_DIR2_DATA_ALIGN_LOG;
  106. }
  107. /*
  108. * Convert byte in file space to dataptr. It had better be aligned.
  109. */
  110. static inline xfs_dir2_dataptr_t
  111. xfs_dir2_byte_to_dataptr(struct xfs_mount *mp, xfs_dir2_off_t by)
  112. {
  113. return (xfs_dir2_dataptr_t)((by) >> XFS_DIR2_DATA_ALIGN_LOG);
  114. }
  115. /*
  116. * Convert byte in space to (DB) block
  117. */
  118. static inline xfs_dir2_db_t
  119. xfs_dir2_byte_to_db(struct xfs_mount *mp, xfs_dir2_off_t by)
  120. {
  121. return (xfs_dir2_db_t)((by) >> \
  122. ((mp)->m_sb.sb_blocklog + (mp)->m_sb.sb_dirblklog));
  123. }
  124. /*
  125. * Convert dataptr to a block number
  126. */
  127. static inline xfs_dir2_db_t
  128. xfs_dir2_dataptr_to_db(struct xfs_mount *mp, xfs_dir2_dataptr_t dp)
  129. {
  130. return xfs_dir2_byte_to_db(mp, xfs_dir2_dataptr_to_byte(mp, dp));
  131. }
  132. /*
  133. * Convert byte in space to offset in a block
  134. */
  135. static inline xfs_dir2_data_aoff_t
  136. xfs_dir2_byte_to_off(struct xfs_mount *mp, xfs_dir2_off_t by)
  137. {
  138. return (xfs_dir2_data_aoff_t)((by) & \
  139. ((1 << ((mp)->m_sb.sb_blocklog + (mp)->m_sb.sb_dirblklog)) - 1));
  140. }
  141. /*
  142. * Convert dataptr to a byte offset in a block
  143. */
  144. static inline xfs_dir2_data_aoff_t
  145. xfs_dir2_dataptr_to_off(struct xfs_mount *mp, xfs_dir2_dataptr_t dp)
  146. {
  147. return xfs_dir2_byte_to_off(mp, xfs_dir2_dataptr_to_byte(mp, dp));
  148. }
  149. /*
  150. * Convert block and offset to byte in space
  151. */
  152. static inline xfs_dir2_off_t
  153. xfs_dir2_db_off_to_byte(struct xfs_mount *mp, xfs_dir2_db_t db,
  154. xfs_dir2_data_aoff_t o)
  155. {
  156. return ((xfs_dir2_off_t)(db) << \
  157. ((mp)->m_sb.sb_blocklog + (mp)->m_sb.sb_dirblklog)) + (o);
  158. }
  159. /*
  160. * Convert block (DB) to block (dablk)
  161. */
  162. static inline xfs_dablk_t
  163. xfs_dir2_db_to_da(struct xfs_mount *mp, xfs_dir2_db_t db)
  164. {
  165. return (xfs_dablk_t)((db) << (mp)->m_sb.sb_dirblklog);
  166. }
  167. /*
  168. * Convert byte in space to (DA) block
  169. */
  170. static inline xfs_dablk_t
  171. xfs_dir2_byte_to_da(struct xfs_mount *mp, xfs_dir2_off_t by)
  172. {
  173. return xfs_dir2_db_to_da(mp, xfs_dir2_byte_to_db(mp, by));
  174. }
  175. /*
  176. * Convert block and offset to dataptr
  177. */
  178. static inline xfs_dir2_dataptr_t
  179. xfs_dir2_db_off_to_dataptr(struct xfs_mount *mp, xfs_dir2_db_t db,
  180. xfs_dir2_data_aoff_t o)
  181. {
  182. return xfs_dir2_byte_to_dataptr(mp, xfs_dir2_db_off_to_byte(mp, db, o));
  183. }
  184. /*
  185. * Convert block (dablk) to block (DB)
  186. */
  187. static inline xfs_dir2_db_t
  188. xfs_dir2_da_to_db(struct xfs_mount *mp, xfs_dablk_t da)
  189. {
  190. return (xfs_dir2_db_t)((da) >> (mp)->m_sb.sb_dirblklog);
  191. }
  192. /*
  193. * Convert block (dablk) to byte offset in space
  194. */
  195. static inline xfs_dir2_off_t
  196. xfs_dir2_da_to_byte(struct xfs_mount *mp, xfs_dablk_t da)
  197. {
  198. return xfs_dir2_db_off_to_byte(mp, xfs_dir2_da_to_db(mp, da), 0);
  199. }
  200. /*
  201. * Function declarations.
  202. */
  203. extern int xfs_dir2_block_to_leaf(struct xfs_da_args *args,
  204. struct xfs_dabuf *dbp);
  205. extern int xfs_dir2_leaf_addname(struct xfs_da_args *args);
  206. extern void xfs_dir2_leaf_compact(struct xfs_da_args *args,
  207. struct xfs_dabuf *bp);
  208. extern void xfs_dir2_leaf_compact_x1(struct xfs_dabuf *bp, int *indexp,
  209. int *lowstalep, int *highstalep,
  210. int *lowlogp, int *highlogp);
  211. extern int xfs_dir2_leaf_getdents(struct xfs_inode *dp, void *dirent,
  212. size_t bufsize, xfs_off_t *offset,
  213. filldir_t filldir);
  214. extern int xfs_dir2_leaf_init(struct xfs_da_args *args, xfs_dir2_db_t bno,
  215. struct xfs_dabuf **bpp, int magic);
  216. extern void xfs_dir2_leaf_log_ents(struct xfs_trans *tp, struct xfs_dabuf *bp,
  217. int first, int last);
  218. extern void xfs_dir2_leaf_log_header(struct xfs_trans *tp,
  219. struct xfs_dabuf *bp);
  220. extern int xfs_dir2_leaf_lookup(struct xfs_da_args *args);
  221. extern int xfs_dir2_leaf_removename(struct xfs_da_args *args);
  222. extern int xfs_dir2_leaf_replace(struct xfs_da_args *args);
  223. extern int xfs_dir2_leaf_search_hash(struct xfs_da_args *args,
  224. struct xfs_dabuf *lbp);
  225. extern int xfs_dir2_leaf_trim_data(struct xfs_da_args *args,
  226. struct xfs_dabuf *lbp, xfs_dir2_db_t db);
  227. extern int xfs_dir2_node_to_leaf(struct xfs_da_state *state);
  228. #endif /* __XFS_DIR2_LEAF_H__ */