xfs_dir2_priv.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
  4. * All Rights Reserved.
  5. */
  6. #ifndef __XFS_DIR2_PRIV_H__
  7. #define __XFS_DIR2_PRIV_H__
  8. struct dir_context;
  9. /*
  10. * In-core version of the leaf and free block headers to abstract the
  11. * differences in the v2 and v3 disk format of the headers.
  12. */
  13. struct xfs_dir3_icleaf_hdr {
  14. uint32_t forw;
  15. uint32_t back;
  16. uint16_t magic;
  17. uint16_t count;
  18. uint16_t stale;
  19. /*
  20. * Pointer to the on-disk format entries, which are behind the
  21. * variable size (v4 vs v5) header in the on-disk block.
  22. */
  23. struct xfs_dir2_leaf_entry *ents;
  24. };
  25. struct xfs_dir3_icfree_hdr {
  26. uint32_t magic;
  27. uint32_t firstdb;
  28. uint32_t nvalid;
  29. uint32_t nused;
  30. /*
  31. * Pointer to the on-disk format entries, which are behind the
  32. * variable size (v4 vs v5) header in the on-disk block.
  33. */
  34. __be16 *bests;
  35. };
  36. /* xfs_dir2.c */
  37. xfs_dahash_t xfs_ascii_ci_hashname(const struct xfs_name *name);
  38. enum xfs_dacmp xfs_ascii_ci_compname(struct xfs_da_args *args,
  39. const unsigned char *name, int len);
  40. extern int xfs_dir2_grow_inode(struct xfs_da_args *args, int space,
  41. xfs_dir2_db_t *dbp);
  42. extern int xfs_dir_cilookup_result(struct xfs_da_args *args,
  43. const unsigned char *name, int len);
  44. /* xfs_dir2_block.c */
  45. extern int xfs_dir3_block_read(struct xfs_trans *tp, struct xfs_inode *dp,
  46. struct xfs_buf **bpp);
  47. extern int xfs_dir2_block_addname(struct xfs_da_args *args);
  48. extern int xfs_dir2_block_lookup(struct xfs_da_args *args);
  49. extern int xfs_dir2_block_removename(struct xfs_da_args *args);
  50. extern int xfs_dir2_block_replace(struct xfs_da_args *args);
  51. extern int xfs_dir2_leaf_to_block(struct xfs_da_args *args,
  52. struct xfs_buf *lbp, struct xfs_buf *dbp);
  53. /* xfs_dir2_data.c */
  54. struct xfs_dir2_data_free *xfs_dir2_data_bestfree_p(struct xfs_mount *mp,
  55. struct xfs_dir2_data_hdr *hdr);
  56. __be16 *xfs_dir2_data_entry_tag_p(struct xfs_mount *mp,
  57. struct xfs_dir2_data_entry *dep);
  58. uint8_t xfs_dir2_data_get_ftype(struct xfs_mount *mp,
  59. struct xfs_dir2_data_entry *dep);
  60. void xfs_dir2_data_put_ftype(struct xfs_mount *mp,
  61. struct xfs_dir2_data_entry *dep, uint8_t ftype);
  62. #ifdef DEBUG
  63. extern void xfs_dir3_data_check(struct xfs_inode *dp, struct xfs_buf *bp);
  64. #else
  65. #define xfs_dir3_data_check(dp,bp)
  66. #endif
  67. extern xfs_failaddr_t __xfs_dir3_data_check(struct xfs_inode *dp,
  68. struct xfs_buf *bp);
  69. int xfs_dir3_data_read(struct xfs_trans *tp, struct xfs_inode *dp,
  70. xfs_dablk_t bno, unsigned int flags, struct xfs_buf **bpp);
  71. int xfs_dir3_data_readahead(struct xfs_inode *dp, xfs_dablk_t bno,
  72. unsigned int flags);
  73. extern struct xfs_dir2_data_free *
  74. xfs_dir2_data_freeinsert(struct xfs_dir2_data_hdr *hdr,
  75. struct xfs_dir2_data_free *bf, struct xfs_dir2_data_unused *dup,
  76. int *loghead);
  77. extern int xfs_dir3_data_init(struct xfs_da_args *args, xfs_dir2_db_t blkno,
  78. struct xfs_buf **bpp);
  79. /* xfs_dir2_leaf.c */
  80. void xfs_dir2_leaf_hdr_from_disk(struct xfs_mount *mp,
  81. struct xfs_dir3_icleaf_hdr *to, struct xfs_dir2_leaf *from);
  82. void xfs_dir2_leaf_hdr_to_disk(struct xfs_mount *mp, struct xfs_dir2_leaf *to,
  83. struct xfs_dir3_icleaf_hdr *from);
  84. int xfs_dir3_leaf_read(struct xfs_trans *tp, struct xfs_inode *dp,
  85. xfs_dablk_t fbno, struct xfs_buf **bpp);
  86. int xfs_dir3_leafn_read(struct xfs_trans *tp, struct xfs_inode *dp,
  87. xfs_dablk_t fbno, struct xfs_buf **bpp);
  88. extern int xfs_dir2_block_to_leaf(struct xfs_da_args *args,
  89. struct xfs_buf *dbp);
  90. extern int xfs_dir2_leaf_addname(struct xfs_da_args *args);
  91. extern void xfs_dir3_leaf_compact(struct xfs_da_args *args,
  92. struct xfs_dir3_icleaf_hdr *leafhdr, struct xfs_buf *bp);
  93. extern void xfs_dir3_leaf_compact_x1(struct xfs_dir3_icleaf_hdr *leafhdr,
  94. struct xfs_dir2_leaf_entry *ents, int *indexp,
  95. int *lowstalep, int *highstalep, int *lowlogp, int *highlogp);
  96. extern int xfs_dir3_leaf_get_buf(struct xfs_da_args *args, xfs_dir2_db_t bno,
  97. struct xfs_buf **bpp, uint16_t magic);
  98. extern void xfs_dir3_leaf_log_ents(struct xfs_da_args *args,
  99. struct xfs_dir3_icleaf_hdr *hdr, struct xfs_buf *bp, int first,
  100. int last);
  101. extern void xfs_dir3_leaf_log_header(struct xfs_da_args *args,
  102. struct xfs_buf *bp);
  103. extern int xfs_dir2_leaf_lookup(struct xfs_da_args *args);
  104. extern int xfs_dir2_leaf_removename(struct xfs_da_args *args);
  105. extern int xfs_dir2_leaf_replace(struct xfs_da_args *args);
  106. extern int xfs_dir2_leaf_search_hash(struct xfs_da_args *args,
  107. struct xfs_buf *lbp);
  108. extern int xfs_dir2_leaf_trim_data(struct xfs_da_args *args,
  109. struct xfs_buf *lbp, xfs_dir2_db_t db);
  110. extern struct xfs_dir2_leaf_entry *
  111. xfs_dir3_leaf_find_entry(struct xfs_dir3_icleaf_hdr *leafhdr,
  112. struct xfs_dir2_leaf_entry *ents, int index, int compact,
  113. int lowstale, int highstale, int *lfloglow, int *lfloghigh);
  114. extern int xfs_dir2_node_to_leaf(struct xfs_da_state *state);
  115. extern xfs_failaddr_t xfs_dir3_leaf_check_int(struct xfs_mount *mp,
  116. struct xfs_dir3_icleaf_hdr *hdr, struct xfs_dir2_leaf *leaf,
  117. bool expensive_checks);
  118. /* xfs_dir2_node.c */
  119. void xfs_dir2_free_hdr_from_disk(struct xfs_mount *mp,
  120. struct xfs_dir3_icfree_hdr *to, struct xfs_dir2_free *from);
  121. extern int xfs_dir2_leaf_to_node(struct xfs_da_args *args,
  122. struct xfs_buf *lbp);
  123. extern xfs_dahash_t xfs_dir2_leaf_lasthash(struct xfs_inode *dp,
  124. struct xfs_buf *bp, int *count);
  125. extern int xfs_dir2_leafn_lookup_int(struct xfs_buf *bp,
  126. struct xfs_da_args *args, int *indexp,
  127. struct xfs_da_state *state);
  128. extern int xfs_dir2_leafn_order(struct xfs_inode *dp, struct xfs_buf *leaf1_bp,
  129. struct xfs_buf *leaf2_bp);
  130. extern int xfs_dir2_leafn_split(struct xfs_da_state *state,
  131. struct xfs_da_state_blk *oldblk, struct xfs_da_state_blk *newblk);
  132. extern int xfs_dir2_leafn_toosmall(struct xfs_da_state *state, int *action);
  133. extern void xfs_dir2_leafn_unbalance(struct xfs_da_state *state,
  134. struct xfs_da_state_blk *drop_blk,
  135. struct xfs_da_state_blk *save_blk);
  136. extern int xfs_dir2_node_addname(struct xfs_da_args *args);
  137. extern int xfs_dir2_node_lookup(struct xfs_da_args *args);
  138. extern int xfs_dir2_node_removename(struct xfs_da_args *args);
  139. extern int xfs_dir2_node_replace(struct xfs_da_args *args);
  140. extern int xfs_dir2_node_trim_free(struct xfs_da_args *args, xfs_fileoff_t fo,
  141. int *rvalp);
  142. extern int xfs_dir2_free_read(struct xfs_trans *tp, struct xfs_inode *dp,
  143. xfs_dablk_t fbno, struct xfs_buf **bpp);
  144. /* xfs_dir2_sf.c */
  145. xfs_ino_t xfs_dir2_sf_get_ino(struct xfs_mount *mp, struct xfs_dir2_sf_hdr *hdr,
  146. struct xfs_dir2_sf_entry *sfep);
  147. xfs_ino_t xfs_dir2_sf_get_parent_ino(struct xfs_dir2_sf_hdr *hdr);
  148. void xfs_dir2_sf_put_parent_ino(struct xfs_dir2_sf_hdr *hdr, xfs_ino_t ino);
  149. uint8_t xfs_dir2_sf_get_ftype(struct xfs_mount *mp,
  150. struct xfs_dir2_sf_entry *sfep);
  151. struct xfs_dir2_sf_entry *xfs_dir2_sf_nextentry(struct xfs_mount *mp,
  152. struct xfs_dir2_sf_hdr *hdr, struct xfs_dir2_sf_entry *sfep);
  153. extern int xfs_dir2_block_sfsize(struct xfs_inode *dp,
  154. struct xfs_dir2_data_hdr *block, struct xfs_dir2_sf_hdr *sfhp);
  155. extern int xfs_dir2_block_to_sf(struct xfs_da_args *args, struct xfs_buf *bp,
  156. int size, xfs_dir2_sf_hdr_t *sfhp);
  157. extern int xfs_dir2_sf_addname(struct xfs_da_args *args);
  158. extern int xfs_dir2_sf_create(struct xfs_da_args *args, xfs_ino_t pino);
  159. extern int xfs_dir2_sf_lookup(struct xfs_da_args *args);
  160. extern int xfs_dir2_sf_removename(struct xfs_da_args *args);
  161. extern int xfs_dir2_sf_replace(struct xfs_da_args *args);
  162. extern xfs_failaddr_t xfs_dir2_sf_verify(struct xfs_inode *ip);
  163. int xfs_dir2_sf_entsize(struct xfs_mount *mp,
  164. struct xfs_dir2_sf_hdr *hdr, int len);
  165. void xfs_dir2_sf_put_ino(struct xfs_mount *mp, struct xfs_dir2_sf_hdr *hdr,
  166. struct xfs_dir2_sf_entry *sfep, xfs_ino_t ino);
  167. void xfs_dir2_sf_put_ftype(struct xfs_mount *mp,
  168. struct xfs_dir2_sf_entry *sfep, uint8_t ftype);
  169. /* xfs_dir2_readdir.c */
  170. extern int xfs_readdir(struct xfs_trans *tp, struct xfs_inode *dp,
  171. struct dir_context *ctx, size_t bufsize);
  172. static inline unsigned int
  173. xfs_dir2_data_entsize(
  174. struct xfs_mount *mp,
  175. unsigned int namelen)
  176. {
  177. unsigned int len;
  178. len = offsetof(struct xfs_dir2_data_entry, name[0]) + namelen +
  179. sizeof(xfs_dir2_data_off_t) /* tag */;
  180. if (xfs_has_ftype(mp))
  181. len += sizeof(uint8_t);
  182. return round_up(len, XFS_DIR2_DATA_ALIGN);
  183. }
  184. xfs_dahash_t xfs_dir2_hashname(struct xfs_mount *mp,
  185. const struct xfs_name *name);
  186. enum xfs_dacmp xfs_dir2_compname(struct xfs_da_args *args,
  187. const unsigned char *name, int len);
  188. #endif /* __XFS_DIR2_PRIV_H__ */