xfs_dir2_leaf.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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. * Constants.
  45. */
  46. /*
  47. * Offset of the leaf/node space. First block in this space
  48. * is the btree root.
  49. */
  50. #define XFS_DIR2_LEAF_SPACE 1
  51. #define XFS_DIR2_LEAF_OFFSET (XFS_DIR2_LEAF_SPACE * XFS_DIR2_SPACE_SIZE)
  52. #define XFS_DIR2_LEAF_FIRSTDB(mp) \
  53. XFS_DIR2_BYTE_TO_DB(mp, XFS_DIR2_LEAF_OFFSET)
  54. /*
  55. * Types.
  56. */
  57. /*
  58. * Offset in data space of a data entry.
  59. */
  60. typedef __uint32_t xfs_dir2_dataptr_t;
  61. #define XFS_DIR2_MAX_DATAPTR ((xfs_dir2_dataptr_t)0xffffffff)
  62. #define XFS_DIR2_NULL_DATAPTR ((xfs_dir2_dataptr_t)0)
  63. /*
  64. * Structures.
  65. */
  66. /*
  67. * Leaf block header.
  68. */
  69. typedef struct xfs_dir2_leaf_hdr {
  70. xfs_da_blkinfo_t info; /* header for da routines */
  71. __uint16_t count; /* count of entries */
  72. __uint16_t stale; /* count of stale entries */
  73. } xfs_dir2_leaf_hdr_t;
  74. /*
  75. * Leaf block entry.
  76. */
  77. typedef struct xfs_dir2_leaf_entry {
  78. xfs_dahash_t hashval; /* hash value of name */
  79. xfs_dir2_dataptr_t address; /* address of data entry */
  80. } xfs_dir2_leaf_entry_t;
  81. /*
  82. * Leaf block tail.
  83. */
  84. typedef struct xfs_dir2_leaf_tail {
  85. __uint32_t bestcount;
  86. } xfs_dir2_leaf_tail_t;
  87. /*
  88. * Leaf block.
  89. * bests and tail are at the end of the block for single-leaf only
  90. * (magic = XFS_DIR2_LEAF1_MAGIC not XFS_DIR2_LEAFN_MAGIC).
  91. */
  92. typedef struct xfs_dir2_leaf {
  93. xfs_dir2_leaf_hdr_t hdr; /* leaf header */
  94. xfs_dir2_leaf_entry_t ents[1]; /* entries */
  95. /* ... */
  96. xfs_dir2_data_off_t bests[1]; /* best free counts */
  97. xfs_dir2_leaf_tail_t tail; /* leaf tail */
  98. } xfs_dir2_leaf_t;
  99. /*
  100. * Macros.
  101. * The DB blocks are logical directory block numbers, not filesystem blocks.
  102. */
  103. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_MAX_LEAF_ENTS)
  104. int
  105. xfs_dir2_max_leaf_ents(struct xfs_mount *mp);
  106. #define XFS_DIR2_MAX_LEAF_ENTS(mp) \
  107. xfs_dir2_max_leaf_ents(mp)
  108. #else
  109. #define XFS_DIR2_MAX_LEAF_ENTS(mp) \
  110. ((int)(((mp)->m_dirblksize - (uint)sizeof(xfs_dir2_leaf_hdr_t)) / \
  111. (uint)sizeof(xfs_dir2_leaf_entry_t)))
  112. #endif
  113. /*
  114. * Get address of the bestcount field in the single-leaf block.
  115. */
  116. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_LEAF_TAIL_P)
  117. xfs_dir2_leaf_tail_t *
  118. xfs_dir2_leaf_tail_p(struct xfs_mount *mp, xfs_dir2_leaf_t *lp);
  119. #define XFS_DIR2_LEAF_TAIL_P(mp,lp) \
  120. xfs_dir2_leaf_tail_p(mp, lp)
  121. #else
  122. #define XFS_DIR2_LEAF_TAIL_P(mp,lp) \
  123. ((xfs_dir2_leaf_tail_t *)\
  124. ((char *)(lp) + (mp)->m_dirblksize - \
  125. (uint)sizeof(xfs_dir2_leaf_tail_t)))
  126. #endif
  127. /*
  128. * Get address of the bests array in the single-leaf block.
  129. */
  130. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_LEAF_BESTS_P)
  131. xfs_dir2_data_off_t *
  132. xfs_dir2_leaf_bests_p(xfs_dir2_leaf_tail_t *ltp);
  133. #define XFS_DIR2_LEAF_BESTS_P(ltp) xfs_dir2_leaf_bests_p(ltp)
  134. #else
  135. #define XFS_DIR2_LEAF_BESTS_P(ltp) \
  136. ((xfs_dir2_data_off_t *)(ltp) - INT_GET((ltp)->bestcount, ARCH_CONVERT))
  137. #endif
  138. /*
  139. * Convert dataptr to byte in file space
  140. */
  141. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_DATAPTR_TO_BYTE)
  142. xfs_dir2_off_t
  143. xfs_dir2_dataptr_to_byte(struct xfs_mount *mp, xfs_dir2_dataptr_t dp);
  144. #define XFS_DIR2_DATAPTR_TO_BYTE(mp,dp) xfs_dir2_dataptr_to_byte(mp, dp)
  145. #else
  146. #define XFS_DIR2_DATAPTR_TO_BYTE(mp,dp) \
  147. ((xfs_dir2_off_t)(dp) << XFS_DIR2_DATA_ALIGN_LOG)
  148. #endif
  149. /*
  150. * Convert byte in file space to dataptr. It had better be aligned.
  151. */
  152. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_BYTE_TO_DATAPTR)
  153. xfs_dir2_dataptr_t
  154. xfs_dir2_byte_to_dataptr(struct xfs_mount *mp, xfs_dir2_off_t by);
  155. #define XFS_DIR2_BYTE_TO_DATAPTR(mp,by) xfs_dir2_byte_to_dataptr(mp,by)
  156. #else
  157. #define XFS_DIR2_BYTE_TO_DATAPTR(mp,by) \
  158. ((xfs_dir2_dataptr_t)((by) >> XFS_DIR2_DATA_ALIGN_LOG))
  159. #endif
  160. /*
  161. * Convert dataptr to a block number
  162. */
  163. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_DATAPTR_TO_DB)
  164. xfs_dir2_db_t
  165. xfs_dir2_dataptr_to_db(struct xfs_mount *mp, xfs_dir2_dataptr_t dp);
  166. #define XFS_DIR2_DATAPTR_TO_DB(mp,dp) xfs_dir2_dataptr_to_db(mp, dp)
  167. #else
  168. #define XFS_DIR2_DATAPTR_TO_DB(mp,dp) \
  169. XFS_DIR2_BYTE_TO_DB(mp, XFS_DIR2_DATAPTR_TO_BYTE(mp, dp))
  170. #endif
  171. /*
  172. * Convert dataptr to a byte offset in a block
  173. */
  174. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_DATAPTR_TO_OFF)
  175. xfs_dir2_data_aoff_t
  176. xfs_dir2_dataptr_to_off(struct xfs_mount *mp, xfs_dir2_dataptr_t dp);
  177. #define XFS_DIR2_DATAPTR_TO_OFF(mp,dp) xfs_dir2_dataptr_to_off(mp, dp)
  178. #else
  179. #define XFS_DIR2_DATAPTR_TO_OFF(mp,dp) \
  180. XFS_DIR2_BYTE_TO_OFF(mp, XFS_DIR2_DATAPTR_TO_BYTE(mp, dp))
  181. #endif
  182. /*
  183. * Convert block and offset to byte in space
  184. */
  185. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_DB_OFF_TO_BYTE)
  186. xfs_dir2_off_t
  187. xfs_dir2_db_off_to_byte(struct xfs_mount *mp, xfs_dir2_db_t db,
  188. xfs_dir2_data_aoff_t o);
  189. #define XFS_DIR2_DB_OFF_TO_BYTE(mp,db,o) \
  190. xfs_dir2_db_off_to_byte(mp, db, o)
  191. #else
  192. #define XFS_DIR2_DB_OFF_TO_BYTE(mp,db,o) \
  193. (((xfs_dir2_off_t)(db) << \
  194. ((mp)->m_sb.sb_blocklog + (mp)->m_sb.sb_dirblklog)) + (o))
  195. #endif
  196. /*
  197. * Convert byte in space to (DB) block
  198. */
  199. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_BYTE_TO_DB)
  200. xfs_dir2_db_t xfs_dir2_byte_to_db(struct xfs_mount *mp, xfs_dir2_off_t by);
  201. #define XFS_DIR2_BYTE_TO_DB(mp,by) xfs_dir2_byte_to_db(mp, by)
  202. #else
  203. #define XFS_DIR2_BYTE_TO_DB(mp,by) \
  204. ((xfs_dir2_db_t)((by) >> \
  205. ((mp)->m_sb.sb_blocklog + (mp)->m_sb.sb_dirblklog)))
  206. #endif
  207. /*
  208. * Convert byte in space to (DA) block
  209. */
  210. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_BYTE_TO_DA)
  211. xfs_dablk_t xfs_dir2_byte_to_da(struct xfs_mount *mp, xfs_dir2_off_t by);
  212. #define XFS_DIR2_BYTE_TO_DA(mp,by) xfs_dir2_byte_to_da(mp, by)
  213. #else
  214. #define XFS_DIR2_BYTE_TO_DA(mp,by) \
  215. XFS_DIR2_DB_TO_DA(mp, XFS_DIR2_BYTE_TO_DB(mp, by))
  216. #endif
  217. /*
  218. * Convert byte in space to offset in a block
  219. */
  220. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_BYTE_TO_OFF)
  221. xfs_dir2_data_aoff_t
  222. xfs_dir2_byte_to_off(struct xfs_mount *mp, xfs_dir2_off_t by);
  223. #define XFS_DIR2_BYTE_TO_OFF(mp,by) xfs_dir2_byte_to_off(mp, by)
  224. #else
  225. #define XFS_DIR2_BYTE_TO_OFF(mp,by) \
  226. ((xfs_dir2_data_aoff_t)((by) & \
  227. ((1 << ((mp)->m_sb.sb_blocklog + \
  228. (mp)->m_sb.sb_dirblklog)) - 1)))
  229. #endif
  230. /*
  231. * Convert block and offset to dataptr
  232. */
  233. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_DB_OFF_TO_DATAPTR)
  234. xfs_dir2_dataptr_t
  235. xfs_dir2_db_off_to_dataptr(struct xfs_mount *mp, xfs_dir2_db_t db,
  236. xfs_dir2_data_aoff_t o);
  237. #define XFS_DIR2_DB_OFF_TO_DATAPTR(mp,db,o) \
  238. xfs_dir2_db_off_to_dataptr(mp, db, o)
  239. #else
  240. #define XFS_DIR2_DB_OFF_TO_DATAPTR(mp,db,o) \
  241. XFS_DIR2_BYTE_TO_DATAPTR(mp, XFS_DIR2_DB_OFF_TO_BYTE(mp, db, o))
  242. #endif
  243. /*
  244. * Convert block (DB) to block (dablk)
  245. */
  246. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_DB_TO_DA)
  247. xfs_dablk_t xfs_dir2_db_to_da(struct xfs_mount *mp, xfs_dir2_db_t db);
  248. #define XFS_DIR2_DB_TO_DA(mp,db) xfs_dir2_db_to_da(mp, db)
  249. #else
  250. #define XFS_DIR2_DB_TO_DA(mp,db) \
  251. ((xfs_dablk_t)((db) << (mp)->m_sb.sb_dirblklog))
  252. #endif
  253. /*
  254. * Convert block (dablk) to block (DB)
  255. */
  256. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_DA_TO_DB)
  257. xfs_dir2_db_t xfs_dir2_da_to_db(struct xfs_mount *mp, xfs_dablk_t da);
  258. #define XFS_DIR2_DA_TO_DB(mp,da) xfs_dir2_da_to_db(mp, da)
  259. #else
  260. #define XFS_DIR2_DA_TO_DB(mp,da) \
  261. ((xfs_dir2_db_t)((da) >> (mp)->m_sb.sb_dirblklog))
  262. #endif
  263. /*
  264. * Convert block (dablk) to byte offset in space
  265. */
  266. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_DA_TO_BYTE)
  267. xfs_dir2_off_t xfs_dir2_da_to_byte(struct xfs_mount *mp, xfs_dablk_t da);
  268. #define XFS_DIR2_DA_TO_BYTE(mp,da) xfs_dir2_da_to_byte(mp, da)
  269. #else
  270. #define XFS_DIR2_DA_TO_BYTE(mp,da) \
  271. XFS_DIR2_DB_OFF_TO_BYTE(mp, XFS_DIR2_DA_TO_DB(mp, da), 0)
  272. #endif
  273. /*
  274. * Function declarations.
  275. */
  276. extern int
  277. xfs_dir2_block_to_leaf(struct xfs_da_args *args, struct xfs_dabuf *dbp);
  278. extern int
  279. xfs_dir2_leaf_addname(struct xfs_da_args *args);
  280. extern void
  281. xfs_dir2_leaf_compact(struct xfs_da_args *args, struct xfs_dabuf *bp);
  282. extern void
  283. xfs_dir2_leaf_compact_x1(struct xfs_dabuf *bp, int *indexp,
  284. int *lowstalep, int *highstalep, int *lowlogp,
  285. int *highlogp);
  286. extern int
  287. xfs_dir2_leaf_getdents(struct xfs_trans *tp, struct xfs_inode *dp,
  288. struct uio *uio, int *eofp, struct xfs_dirent *dbp,
  289. xfs_dir2_put_t put);
  290. extern int
  291. xfs_dir2_leaf_init(struct xfs_da_args *args, xfs_dir2_db_t bno,
  292. struct xfs_dabuf **bpp, int magic);
  293. extern void
  294. xfs_dir2_leaf_log_ents(struct xfs_trans *tp, struct xfs_dabuf *bp,
  295. int first, int last);
  296. extern void
  297. xfs_dir2_leaf_log_header(struct xfs_trans *tp, struct xfs_dabuf *bp);
  298. extern int
  299. xfs_dir2_leaf_lookup(struct xfs_da_args *args);
  300. extern int
  301. xfs_dir2_leaf_removename(struct xfs_da_args *args);
  302. extern int
  303. xfs_dir2_leaf_replace(struct xfs_da_args *args);
  304. extern int
  305. xfs_dir2_leaf_search_hash(struct xfs_da_args *args,
  306. struct xfs_dabuf *lbp);
  307. extern int
  308. xfs_dir2_leaf_trim_data(struct xfs_da_args *args, struct xfs_dabuf *lbp, xfs_dir2_db_t db);
  309. extern int
  310. xfs_dir2_node_to_leaf(struct xfs_da_state *state);
  311. #endif /* __XFS_DIR2_LEAF_H__ */