xfs_dir2_leaf.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /*
  2. * Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of version 2 of the GNU General Public License as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it would be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. *
  12. * Further, this software is distributed without any warranty that it is
  13. * free of the rightful claim of any third person regarding infringement
  14. * or the like. Any license provided herein, whether implied or
  15. * otherwise, applies only to this software file. Patent licenses, if
  16. * any, provided herein do not apply to combinations of this program with
  17. * other software, or any other product whatsoever.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write the Free Software Foundation, Inc., 59
  21. * Temple Place - Suite 330, Boston MA 02111-1307, USA.
  22. *
  23. * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
  24. * Mountain View, CA 94043, or:
  25. *
  26. * http://www.sgi.com
  27. *
  28. * For further information regarding this notice, see:
  29. *
  30. * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
  31. */
  32. #ifndef __XFS_DIR2_LEAF_H__
  33. #define __XFS_DIR2_LEAF_H__
  34. /*
  35. * Directory version 2, leaf block structures.
  36. */
  37. struct uio;
  38. struct xfs_dabuf;
  39. struct xfs_da_args;
  40. struct xfs_inode;
  41. struct xfs_mount;
  42. struct xfs_trans;
  43. /*
  44. * Offset of the leaf/node space. First block in this space
  45. * is the btree root.
  46. */
  47. #define XFS_DIR2_LEAF_SPACE 1
  48. #define XFS_DIR2_LEAF_OFFSET (XFS_DIR2_LEAF_SPACE * XFS_DIR2_SPACE_SIZE)
  49. #define XFS_DIR2_LEAF_FIRSTDB(mp) \
  50. XFS_DIR2_BYTE_TO_DB(mp, XFS_DIR2_LEAF_OFFSET)
  51. /*
  52. * Offset in data space of a data entry.
  53. */
  54. typedef __uint32_t xfs_dir2_dataptr_t;
  55. #define XFS_DIR2_MAX_DATAPTR ((xfs_dir2_dataptr_t)0xffffffff)
  56. #define XFS_DIR2_NULL_DATAPTR ((xfs_dir2_dataptr_t)0)
  57. /*
  58. * Leaf block header.
  59. */
  60. typedef struct xfs_dir2_leaf_hdr {
  61. xfs_da_blkinfo_t info; /* header for da routines */
  62. __uint16_t count; /* count of entries */
  63. __uint16_t stale; /* count of stale entries */
  64. } xfs_dir2_leaf_hdr_t;
  65. /*
  66. * Leaf block entry.
  67. */
  68. typedef struct xfs_dir2_leaf_entry {
  69. xfs_dahash_t hashval; /* hash value of name */
  70. xfs_dir2_dataptr_t address; /* address of data entry */
  71. } xfs_dir2_leaf_entry_t;
  72. /*
  73. * Leaf block tail.
  74. */
  75. typedef struct xfs_dir2_leaf_tail {
  76. __uint32_t bestcount;
  77. } xfs_dir2_leaf_tail_t;
  78. /*
  79. * Leaf block.
  80. * bests and tail are at the end of the block for single-leaf only
  81. * (magic = XFS_DIR2_LEAF1_MAGIC not XFS_DIR2_LEAFN_MAGIC).
  82. */
  83. typedef struct xfs_dir2_leaf {
  84. xfs_dir2_leaf_hdr_t hdr; /* leaf header */
  85. xfs_dir2_leaf_entry_t ents[1]; /* entries */
  86. /* ... */
  87. xfs_dir2_data_off_t bests[1]; /* best free counts */
  88. xfs_dir2_leaf_tail_t tail; /* leaf tail */
  89. } xfs_dir2_leaf_t;
  90. /*
  91. * DB blocks here are logical directory block numbers, not filesystem blocks.
  92. */
  93. #define XFS_DIR2_MAX_LEAF_ENTS(mp) xfs_dir2_max_leaf_ents(mp)
  94. static inline int xfs_dir2_max_leaf_ents(struct xfs_mount *mp)
  95. {
  96. return (int)(((mp)->m_dirblksize - (uint)sizeof(xfs_dir2_leaf_hdr_t)) /
  97. (uint)sizeof(xfs_dir2_leaf_entry_t));
  98. }
  99. /*
  100. * Get address of the bestcount field in the single-leaf block.
  101. */
  102. #define XFS_DIR2_LEAF_TAIL_P(mp,lp) xfs_dir2_leaf_tail_p(mp, lp)
  103. static inline xfs_dir2_leaf_tail_t *
  104. xfs_dir2_leaf_tail_p(struct xfs_mount *mp, xfs_dir2_leaf_t *lp)
  105. {
  106. return (xfs_dir2_leaf_tail_t *)
  107. ((char *)(lp) + (mp)->m_dirblksize -
  108. (uint)sizeof(xfs_dir2_leaf_tail_t));
  109. }
  110. /*
  111. * Get address of the bests array in the single-leaf block.
  112. */
  113. #define XFS_DIR2_LEAF_BESTS_P(ltp) xfs_dir2_leaf_bests_p(ltp)
  114. static inline xfs_dir2_data_off_t *
  115. xfs_dir2_leaf_bests_p(xfs_dir2_leaf_tail_t *ltp)
  116. {
  117. return (xfs_dir2_data_off_t *)
  118. (ltp) - INT_GET((ltp)->bestcount, ARCH_CONVERT);
  119. }
  120. /*
  121. * Convert dataptr to byte in file space
  122. */
  123. #define XFS_DIR2_DATAPTR_TO_BYTE(mp,dp) xfs_dir2_dataptr_to_byte(mp, dp)
  124. static inline xfs_dir2_off_t
  125. xfs_dir2_dataptr_to_byte(struct xfs_mount *mp, xfs_dir2_dataptr_t dp)
  126. {
  127. return (xfs_dir2_off_t)(dp) << XFS_DIR2_DATA_ALIGN_LOG;
  128. }
  129. /*
  130. * Convert byte in file space to dataptr. It had better be aligned.
  131. */
  132. #define XFS_DIR2_BYTE_TO_DATAPTR(mp,by) xfs_dir2_byte_to_dataptr(mp,by)
  133. static inline xfs_dir2_dataptr_t
  134. xfs_dir2_byte_to_dataptr(struct xfs_mount *mp, xfs_dir2_off_t by)
  135. {
  136. return (xfs_dir2_dataptr_t)((by) >> XFS_DIR2_DATA_ALIGN_LOG);
  137. }
  138. /*
  139. * Convert byte in space to (DB) block
  140. */
  141. #define XFS_DIR2_BYTE_TO_DB(mp,by) xfs_dir2_byte_to_db(mp, by)
  142. static inline xfs_dir2_db_t
  143. xfs_dir2_byte_to_db(struct xfs_mount *mp, xfs_dir2_off_t by)
  144. {
  145. return (xfs_dir2_db_t)((by) >> \
  146. ((mp)->m_sb.sb_blocklog + (mp)->m_sb.sb_dirblklog));
  147. }
  148. /*
  149. * Convert dataptr to a block number
  150. */
  151. #define XFS_DIR2_DATAPTR_TO_DB(mp,dp) xfs_dir2_dataptr_to_db(mp, dp)
  152. static inline xfs_dir2_db_t
  153. xfs_dir2_dataptr_to_db(struct xfs_mount *mp, xfs_dir2_dataptr_t dp)
  154. {
  155. return XFS_DIR2_BYTE_TO_DB(mp, XFS_DIR2_DATAPTR_TO_BYTE(mp, dp));
  156. }
  157. /*
  158. * Convert byte in space to offset in a block
  159. */
  160. #define XFS_DIR2_BYTE_TO_OFF(mp,by) xfs_dir2_byte_to_off(mp, by)
  161. static inline xfs_dir2_data_aoff_t
  162. xfs_dir2_byte_to_off(struct xfs_mount *mp, xfs_dir2_off_t by)
  163. {
  164. return (xfs_dir2_data_aoff_t)((by) & \
  165. ((1 << ((mp)->m_sb.sb_blocklog + (mp)->m_sb.sb_dirblklog)) - 1));
  166. }
  167. /*
  168. * Convert dataptr to a byte offset in a block
  169. */
  170. #define XFS_DIR2_DATAPTR_TO_OFF(mp,dp) xfs_dir2_dataptr_to_off(mp, dp)
  171. static inline xfs_dir2_data_aoff_t
  172. xfs_dir2_dataptr_to_off(struct xfs_mount *mp, xfs_dir2_dataptr_t dp)
  173. {
  174. return XFS_DIR2_BYTE_TO_OFF(mp, XFS_DIR2_DATAPTR_TO_BYTE(mp, dp));
  175. }
  176. /*
  177. * Convert block and offset to byte in space
  178. */
  179. #define XFS_DIR2_DB_OFF_TO_BYTE(mp,db,o) \
  180. xfs_dir2_db_off_to_byte(mp, db, o)
  181. static inline xfs_dir2_off_t
  182. xfs_dir2_db_off_to_byte(struct xfs_mount *mp, xfs_dir2_db_t db,
  183. xfs_dir2_data_aoff_t o)
  184. {
  185. return ((xfs_dir2_off_t)(db) << \
  186. ((mp)->m_sb.sb_blocklog + (mp)->m_sb.sb_dirblklog)) + (o);
  187. }
  188. /*
  189. * Convert block (DB) to block (dablk)
  190. */
  191. #define XFS_DIR2_DB_TO_DA(mp,db) xfs_dir2_db_to_da(mp, db)
  192. static inline xfs_dablk_t
  193. xfs_dir2_db_to_da(struct xfs_mount *mp, xfs_dir2_db_t db)
  194. {
  195. return (xfs_dablk_t)((db) << (mp)->m_sb.sb_dirblklog);
  196. }
  197. /*
  198. * Convert byte in space to (DA) block
  199. */
  200. #define XFS_DIR2_BYTE_TO_DA(mp,by) xfs_dir2_byte_to_da(mp, by)
  201. static inline xfs_dablk_t
  202. xfs_dir2_byte_to_da(struct xfs_mount *mp, xfs_dir2_off_t by)
  203. {
  204. return XFS_DIR2_DB_TO_DA(mp, XFS_DIR2_BYTE_TO_DB(mp, by));
  205. }
  206. /*
  207. * Convert block and offset to dataptr
  208. */
  209. #define XFS_DIR2_DB_OFF_TO_DATAPTR(mp,db,o) \
  210. xfs_dir2_db_off_to_dataptr(mp, db, o)
  211. static inline xfs_dir2_dataptr_t
  212. xfs_dir2_db_off_to_dataptr(struct xfs_mount *mp, xfs_dir2_db_t db,
  213. xfs_dir2_data_aoff_t o)
  214. {
  215. return XFS_DIR2_BYTE_TO_DATAPTR(mp, XFS_DIR2_DB_OFF_TO_BYTE(mp, db, o));
  216. }
  217. /*
  218. * Convert block (dablk) to block (DB)
  219. */
  220. #define XFS_DIR2_DA_TO_DB(mp,da) xfs_dir2_da_to_db(mp, da)
  221. static inline xfs_dir2_db_t
  222. xfs_dir2_da_to_db(struct xfs_mount *mp, xfs_dablk_t da)
  223. {
  224. return (xfs_dir2_db_t)((da) >> (mp)->m_sb.sb_dirblklog);
  225. }
  226. /*
  227. * Convert block (dablk) to byte offset in space
  228. */
  229. #define XFS_DIR2_DA_TO_BYTE(mp,da) xfs_dir2_da_to_byte(mp, da)
  230. static inline xfs_dir2_off_t
  231. xfs_dir2_da_to_byte(struct xfs_mount *mp, xfs_dablk_t da)
  232. {
  233. return XFS_DIR2_DB_OFF_TO_BYTE(mp, XFS_DIR2_DA_TO_DB(mp, da), 0);
  234. }
  235. /*
  236. * Function declarations.
  237. */
  238. extern int xfs_dir2_block_to_leaf(struct xfs_da_args *args,
  239. struct xfs_dabuf *dbp);
  240. extern int xfs_dir2_leaf_addname(struct xfs_da_args *args);
  241. extern void xfs_dir2_leaf_compact(struct xfs_da_args *args,
  242. struct xfs_dabuf *bp);
  243. extern void xfs_dir2_leaf_compact_x1(struct xfs_dabuf *bp, int *indexp,
  244. int *lowstalep, int *highstalep,
  245. int *lowlogp, int *highlogp);
  246. extern int xfs_dir2_leaf_getdents(struct xfs_trans *tp, struct xfs_inode *dp,
  247. struct uio *uio, int *eofp,
  248. struct xfs_dirent *dbp, xfs_dir2_put_t put);
  249. extern int xfs_dir2_leaf_init(struct xfs_da_args *args, xfs_dir2_db_t bno,
  250. struct xfs_dabuf **bpp, int magic);
  251. extern void xfs_dir2_leaf_log_ents(struct xfs_trans *tp, struct xfs_dabuf *bp,
  252. int first, int last);
  253. extern void xfs_dir2_leaf_log_header(struct xfs_trans *tp,
  254. struct xfs_dabuf *bp);
  255. extern int xfs_dir2_leaf_lookup(struct xfs_da_args *args);
  256. extern int xfs_dir2_leaf_removename(struct xfs_da_args *args);
  257. extern int xfs_dir2_leaf_replace(struct xfs_da_args *args);
  258. extern int xfs_dir2_leaf_search_hash(struct xfs_da_args *args,
  259. struct xfs_dabuf *lbp);
  260. extern int xfs_dir2_leaf_trim_data(struct xfs_da_args *args,
  261. struct xfs_dabuf *lbp, xfs_dir2_db_t db);
  262. extern int xfs_dir2_node_to_leaf(struct xfs_da_state *state);
  263. #endif /* __XFS_DIR2_LEAF_H__ */