xfs_dir2_priv.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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_PRIV_H__
  19. #define __XFS_DIR2_PRIV_H__
  20. struct dir_context;
  21. /*
  22. * Directory offset/block conversion functions.
  23. *
  24. * DB blocks here are logical directory block numbers, not filesystem blocks.
  25. */
  26. /*
  27. * Convert dataptr to byte in file space
  28. */
  29. static inline xfs_dir2_off_t
  30. xfs_dir2_dataptr_to_byte(xfs_dir2_dataptr_t dp)
  31. {
  32. return (xfs_dir2_off_t)dp << XFS_DIR2_DATA_ALIGN_LOG;
  33. }
  34. /*
  35. * Convert byte in file space to dataptr. It had better be aligned.
  36. */
  37. static inline xfs_dir2_dataptr_t
  38. xfs_dir2_byte_to_dataptr(xfs_dir2_off_t by)
  39. {
  40. return (xfs_dir2_dataptr_t)(by >> XFS_DIR2_DATA_ALIGN_LOG);
  41. }
  42. /*
  43. * Convert byte in space to (DB) block
  44. */
  45. static inline xfs_dir2_db_t
  46. xfs_dir2_byte_to_db(struct xfs_da_geometry *geo, xfs_dir2_off_t by)
  47. {
  48. return (xfs_dir2_db_t)(by >> geo->blklog);
  49. }
  50. /*
  51. * Convert dataptr to a block number
  52. */
  53. static inline xfs_dir2_db_t
  54. xfs_dir2_dataptr_to_db(struct xfs_da_geometry *geo, xfs_dir2_dataptr_t dp)
  55. {
  56. return xfs_dir2_byte_to_db(geo, xfs_dir2_dataptr_to_byte(dp));
  57. }
  58. /*
  59. * Convert byte in space to offset in a block
  60. */
  61. static inline xfs_dir2_data_aoff_t
  62. xfs_dir2_byte_to_off(struct xfs_da_geometry *geo, xfs_dir2_off_t by)
  63. {
  64. return (xfs_dir2_data_aoff_t)(by & (geo->blksize - 1));
  65. }
  66. /*
  67. * Convert dataptr to a byte offset in a block
  68. */
  69. static inline xfs_dir2_data_aoff_t
  70. xfs_dir2_dataptr_to_off(struct xfs_da_geometry *geo, xfs_dir2_dataptr_t dp)
  71. {
  72. return xfs_dir2_byte_to_off(geo, xfs_dir2_dataptr_to_byte(dp));
  73. }
  74. /*
  75. * Convert block and offset to byte in space
  76. */
  77. static inline xfs_dir2_off_t
  78. xfs_dir2_db_off_to_byte(struct xfs_da_geometry *geo, xfs_dir2_db_t db,
  79. xfs_dir2_data_aoff_t o)
  80. {
  81. return ((xfs_dir2_off_t)db << geo->blklog) + o;
  82. }
  83. /*
  84. * Convert block (DB) to block (dablk)
  85. */
  86. static inline xfs_dablk_t
  87. xfs_dir2_db_to_da(struct xfs_da_geometry *geo, xfs_dir2_db_t db)
  88. {
  89. return (xfs_dablk_t)(db << (geo->blklog - geo->fsblog));
  90. }
  91. /*
  92. * Convert byte in space to (DA) block
  93. */
  94. static inline xfs_dablk_t
  95. xfs_dir2_byte_to_da(struct xfs_da_geometry *geo, xfs_dir2_off_t by)
  96. {
  97. return xfs_dir2_db_to_da(geo, xfs_dir2_byte_to_db(geo, by));
  98. }
  99. /*
  100. * Convert block and offset to dataptr
  101. */
  102. static inline xfs_dir2_dataptr_t
  103. xfs_dir2_db_off_to_dataptr(struct xfs_da_geometry *geo, xfs_dir2_db_t db,
  104. xfs_dir2_data_aoff_t o)
  105. {
  106. return xfs_dir2_byte_to_dataptr(xfs_dir2_db_off_to_byte(geo, db, o));
  107. }
  108. /*
  109. * Convert block (dablk) to block (DB)
  110. */
  111. static inline xfs_dir2_db_t
  112. xfs_dir2_da_to_db(struct xfs_da_geometry *geo, xfs_dablk_t da)
  113. {
  114. return (xfs_dir2_db_t)(da >> (geo->blklog - geo->fsblog));
  115. }
  116. /*
  117. * Convert block (dablk) to byte offset in space
  118. */
  119. static inline xfs_dir2_off_t
  120. xfs_dir2_da_to_byte(struct xfs_da_geometry *geo, xfs_dablk_t da)
  121. {
  122. return xfs_dir2_db_off_to_byte(geo, xfs_dir2_da_to_db(geo, da), 0);
  123. }
  124. /*
  125. * Directory tail pointer accessor functions. Based on block geometry.
  126. */
  127. static inline struct xfs_dir2_block_tail *
  128. xfs_dir2_block_tail_p(struct xfs_da_geometry *geo, struct xfs_dir2_data_hdr *hdr)
  129. {
  130. return ((struct xfs_dir2_block_tail *)
  131. ((char *)hdr + geo->blksize)) - 1;
  132. }
  133. static inline struct xfs_dir2_leaf_tail *
  134. xfs_dir2_leaf_tail_p(struct xfs_da_geometry *geo, struct xfs_dir2_leaf *lp)
  135. {
  136. return (struct xfs_dir2_leaf_tail *)
  137. ((char *)lp + geo->blksize -
  138. sizeof(struct xfs_dir2_leaf_tail));
  139. }
  140. /* xfs_dir2.c */
  141. extern int xfs_dir_ino_validate(struct xfs_mount *mp, xfs_ino_t ino);
  142. extern int xfs_dir2_grow_inode(struct xfs_da_args *args, int space,
  143. xfs_dir2_db_t *dbp);
  144. extern int xfs_dir_cilookup_result(struct xfs_da_args *args,
  145. const unsigned char *name, int len);
  146. #define S_SHIFT 12
  147. extern const unsigned char xfs_mode_to_ftype[];
  148. extern unsigned char xfs_dir3_get_dtype(struct xfs_mount *mp,
  149. __uint8_t filetype);
  150. /* xfs_dir2_block.c */
  151. extern int xfs_dir3_block_read(struct xfs_trans *tp, struct xfs_inode *dp,
  152. struct xfs_buf **bpp);
  153. extern int xfs_dir2_block_addname(struct xfs_da_args *args);
  154. extern int xfs_dir2_block_lookup(struct xfs_da_args *args);
  155. extern int xfs_dir2_block_removename(struct xfs_da_args *args);
  156. extern int xfs_dir2_block_replace(struct xfs_da_args *args);
  157. extern int xfs_dir2_leaf_to_block(struct xfs_da_args *args,
  158. struct xfs_buf *lbp, struct xfs_buf *dbp);
  159. /* xfs_dir2_data.c */
  160. #ifdef DEBUG
  161. #define xfs_dir3_data_check(dp,bp) __xfs_dir3_data_check(dp, bp);
  162. #else
  163. #define xfs_dir3_data_check(dp,bp)
  164. #endif
  165. extern int __xfs_dir3_data_check(struct xfs_inode *dp, struct xfs_buf *bp);
  166. extern int xfs_dir3_data_read(struct xfs_trans *tp, struct xfs_inode *dp,
  167. xfs_dablk_t bno, xfs_daddr_t mapped_bno, struct xfs_buf **bpp);
  168. extern int xfs_dir3_data_readahead(struct xfs_inode *dp, xfs_dablk_t bno,
  169. xfs_daddr_t mapped_bno);
  170. extern struct xfs_dir2_data_free *
  171. xfs_dir2_data_freeinsert(struct xfs_dir2_data_hdr *hdr,
  172. struct xfs_dir2_data_free *bf, struct xfs_dir2_data_unused *dup,
  173. int *loghead);
  174. extern int xfs_dir3_data_init(struct xfs_da_args *args, xfs_dir2_db_t blkno,
  175. struct xfs_buf **bpp);
  176. /* xfs_dir2_leaf.c */
  177. extern int xfs_dir3_leafn_read(struct xfs_trans *tp, struct xfs_inode *dp,
  178. xfs_dablk_t fbno, xfs_daddr_t mappedbno, struct xfs_buf **bpp);
  179. extern int xfs_dir2_block_to_leaf(struct xfs_da_args *args,
  180. struct xfs_buf *dbp);
  181. extern int xfs_dir2_leaf_addname(struct xfs_da_args *args);
  182. extern void xfs_dir3_leaf_compact(struct xfs_da_args *args,
  183. struct xfs_dir3_icleaf_hdr *leafhdr, struct xfs_buf *bp);
  184. extern void xfs_dir3_leaf_compact_x1(struct xfs_dir3_icleaf_hdr *leafhdr,
  185. struct xfs_dir2_leaf_entry *ents, int *indexp,
  186. int *lowstalep, int *highstalep, int *lowlogp, int *highlogp);
  187. extern int xfs_dir3_leaf_get_buf(struct xfs_da_args *args, xfs_dir2_db_t bno,
  188. struct xfs_buf **bpp, __uint16_t magic);
  189. extern void xfs_dir3_leaf_log_ents(struct xfs_da_args *args,
  190. struct xfs_buf *bp, int first, int last);
  191. extern void xfs_dir3_leaf_log_header(struct xfs_da_args *args,
  192. struct xfs_buf *bp);
  193. extern int xfs_dir2_leaf_lookup(struct xfs_da_args *args);
  194. extern int xfs_dir2_leaf_removename(struct xfs_da_args *args);
  195. extern int xfs_dir2_leaf_replace(struct xfs_da_args *args);
  196. extern int xfs_dir2_leaf_search_hash(struct xfs_da_args *args,
  197. struct xfs_buf *lbp);
  198. extern int xfs_dir2_leaf_trim_data(struct xfs_da_args *args,
  199. struct xfs_buf *lbp, xfs_dir2_db_t db);
  200. extern struct xfs_dir2_leaf_entry *
  201. xfs_dir3_leaf_find_entry(struct xfs_dir3_icleaf_hdr *leafhdr,
  202. struct xfs_dir2_leaf_entry *ents, int index, int compact,
  203. int lowstale, int highstale, int *lfloglow, int *lfloghigh);
  204. extern int xfs_dir2_node_to_leaf(struct xfs_da_state *state);
  205. extern bool xfs_dir3_leaf_check_int(struct xfs_mount *mp, struct xfs_inode *dp,
  206. struct xfs_dir3_icleaf_hdr *hdr, struct xfs_dir2_leaf *leaf);
  207. /* xfs_dir2_node.c */
  208. extern int xfs_dir2_leaf_to_node(struct xfs_da_args *args,
  209. struct xfs_buf *lbp);
  210. extern xfs_dahash_t xfs_dir2_leafn_lasthash(struct xfs_inode *dp,
  211. struct xfs_buf *bp, int *count);
  212. extern int xfs_dir2_leafn_lookup_int(struct xfs_buf *bp,
  213. struct xfs_da_args *args, int *indexp,
  214. struct xfs_da_state *state);
  215. extern int xfs_dir2_leafn_order(struct xfs_inode *dp, struct xfs_buf *leaf1_bp,
  216. struct xfs_buf *leaf2_bp);
  217. extern int xfs_dir2_leafn_split(struct xfs_da_state *state,
  218. struct xfs_da_state_blk *oldblk, struct xfs_da_state_blk *newblk);
  219. extern int xfs_dir2_leafn_toosmall(struct xfs_da_state *state, int *action);
  220. extern void xfs_dir2_leafn_unbalance(struct xfs_da_state *state,
  221. struct xfs_da_state_blk *drop_blk,
  222. struct xfs_da_state_blk *save_blk);
  223. extern int xfs_dir2_node_addname(struct xfs_da_args *args);
  224. extern int xfs_dir2_node_lookup(struct xfs_da_args *args);
  225. extern int xfs_dir2_node_removename(struct xfs_da_args *args);
  226. extern int xfs_dir2_node_replace(struct xfs_da_args *args);
  227. extern int xfs_dir2_node_trim_free(struct xfs_da_args *args, xfs_fileoff_t fo,
  228. int *rvalp);
  229. extern int xfs_dir2_free_read(struct xfs_trans *tp, struct xfs_inode *dp,
  230. xfs_dablk_t fbno, struct xfs_buf **bpp);
  231. /* xfs_dir2_sf.c */
  232. extern int xfs_dir2_block_sfsize(struct xfs_inode *dp,
  233. struct xfs_dir2_data_hdr *block, struct xfs_dir2_sf_hdr *sfhp);
  234. extern int xfs_dir2_block_to_sf(struct xfs_da_args *args, struct xfs_buf *bp,
  235. int size, xfs_dir2_sf_hdr_t *sfhp);
  236. extern int xfs_dir2_sf_addname(struct xfs_da_args *args);
  237. extern int xfs_dir2_sf_create(struct xfs_da_args *args, xfs_ino_t pino);
  238. extern int xfs_dir2_sf_lookup(struct xfs_da_args *args);
  239. extern int xfs_dir2_sf_removename(struct xfs_da_args *args);
  240. extern int xfs_dir2_sf_replace(struct xfs_da_args *args);
  241. /* xfs_dir2_readdir.c */
  242. extern int xfs_readdir(struct xfs_inode *dp, struct dir_context *ctx,
  243. size_t bufsize);
  244. #endif /* __XFS_DIR2_PRIV_H__ */