xfs_da_btree.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2000,2002,2005 Silicon Graphics, Inc.
  4. * Copyright (c) 2013 Red Hat, Inc.
  5. * All Rights Reserved.
  6. */
  7. #ifndef __XFS_DA_BTREE_H__
  8. #define __XFS_DA_BTREE_H__
  9. struct xfs_defer_ops;
  10. struct xfs_inode;
  11. struct xfs_trans;
  12. struct zone;
  13. struct xfs_dir_ops;
  14. /*
  15. * Directory/attribute geometry information. There will be one of these for each
  16. * data fork type, and it will be passed around via the xfs_da_args. Global
  17. * structures will be attached to the xfs_mount.
  18. */
  19. struct xfs_da_geometry {
  20. int blksize; /* da block size in bytes */
  21. int fsbcount; /* da block size in filesystem blocks */
  22. uint8_t fsblog; /* log2 of _filesystem_ block size */
  23. uint8_t blklog; /* log2 of da block size */
  24. uint node_ents; /* # of entries in a danode */
  25. int magicpct; /* 37% of block size in bytes */
  26. xfs_dablk_t datablk; /* blockno of dir data v2 */
  27. xfs_dablk_t leafblk; /* blockno of leaf data v2 */
  28. xfs_dablk_t freeblk; /* blockno of free data v2 */
  29. };
  30. /*========================================================================
  31. * Btree searching and modification structure definitions.
  32. *========================================================================*/
  33. /*
  34. * Search comparison results
  35. */
  36. enum xfs_dacmp {
  37. XFS_CMP_DIFFERENT, /* names are completely different */
  38. XFS_CMP_EXACT, /* names are exactly the same */
  39. XFS_CMP_CASE /* names are same but differ in case */
  40. };
  41. /*
  42. * Structure to ease passing around component names.
  43. */
  44. typedef struct xfs_da_args {
  45. struct xfs_da_geometry *geo; /* da block geometry */
  46. const uint8_t *name; /* string (maybe not NULL terminated) */
  47. int namelen; /* length of string (maybe no NULL) */
  48. uint8_t filetype; /* filetype of inode for directories */
  49. uint8_t *value; /* set of bytes (maybe contain NULLs) */
  50. int valuelen; /* length of value */
  51. int flags; /* argument flags (eg: ATTR_NOCREATE) */
  52. xfs_dahash_t hashval; /* hash value of name */
  53. xfs_ino_t inumber; /* input/output inode number */
  54. struct xfs_inode *dp; /* directory inode to manipulate */
  55. xfs_fsblock_t *firstblock; /* ptr to firstblock for bmap calls */
  56. struct xfs_defer_ops *dfops; /* ptr to freelist for bmap_finish */
  57. struct xfs_trans *trans; /* current trans (changes over time) */
  58. xfs_extlen_t total; /* total blocks needed, for 1st bmap */
  59. int whichfork; /* data or attribute fork */
  60. xfs_dablk_t blkno; /* blkno of attr leaf of interest */
  61. int index; /* index of attr of interest in blk */
  62. xfs_dablk_t rmtblkno; /* remote attr value starting blkno */
  63. int rmtblkcnt; /* remote attr value block count */
  64. int rmtvaluelen; /* remote attr value length in bytes */
  65. xfs_dablk_t blkno2; /* blkno of 2nd attr leaf of interest */
  66. int index2; /* index of 2nd attr in blk */
  67. xfs_dablk_t rmtblkno2; /* remote attr value starting blkno */
  68. int rmtblkcnt2; /* remote attr value block count */
  69. int rmtvaluelen2; /* remote attr value length in bytes */
  70. int op_flags; /* operation flags */
  71. enum xfs_dacmp cmpresult; /* name compare result for lookups */
  72. } xfs_da_args_t;
  73. /*
  74. * Operation flags:
  75. */
  76. #define XFS_DA_OP_JUSTCHECK 0x0001 /* check for ok with no space */
  77. #define XFS_DA_OP_RENAME 0x0002 /* this is an atomic rename op */
  78. #define XFS_DA_OP_ADDNAME 0x0004 /* this is an add operation */
  79. #define XFS_DA_OP_OKNOENT 0x0008 /* lookup/add op, ENOENT ok, else die */
  80. #define XFS_DA_OP_CILOOKUP 0x0010 /* lookup to return CI name if found */
  81. #define XFS_DA_OP_FLAGS \
  82. { XFS_DA_OP_JUSTCHECK, "JUSTCHECK" }, \
  83. { XFS_DA_OP_RENAME, "RENAME" }, \
  84. { XFS_DA_OP_ADDNAME, "ADDNAME" }, \
  85. { XFS_DA_OP_OKNOENT, "OKNOENT" }, \
  86. { XFS_DA_OP_CILOOKUP, "CILOOKUP" }
  87. /*
  88. * Storage for holding state during Btree searches and split/join ops.
  89. *
  90. * Only need space for 5 intermediate nodes. With a minimum of 62-way
  91. * fanout to the Btree, we can support over 900 million directory blocks,
  92. * which is slightly more than enough.
  93. */
  94. typedef struct xfs_da_state_blk {
  95. struct xfs_buf *bp; /* buffer containing block */
  96. xfs_dablk_t blkno; /* filesystem blkno of buffer */
  97. xfs_daddr_t disk_blkno; /* on-disk blkno (in BBs) of buffer */
  98. int index; /* relevant index into block */
  99. xfs_dahash_t hashval; /* last hash value in block */
  100. int magic; /* blk's magic number, ie: blk type */
  101. } xfs_da_state_blk_t;
  102. typedef struct xfs_da_state_path {
  103. int active; /* number of active levels */
  104. xfs_da_state_blk_t blk[XFS_DA_NODE_MAXDEPTH];
  105. } xfs_da_state_path_t;
  106. typedef struct xfs_da_state {
  107. xfs_da_args_t *args; /* filename arguments */
  108. struct xfs_mount *mp; /* filesystem mount point */
  109. xfs_da_state_path_t path; /* search/split paths */
  110. xfs_da_state_path_t altpath; /* alternate path for join */
  111. unsigned char inleaf; /* insert into 1->lf, 0->splf */
  112. unsigned char extravalid; /* T/F: extrablk is in use */
  113. unsigned char extraafter; /* T/F: extrablk is after new */
  114. xfs_da_state_blk_t extrablk; /* for double-splits on leaves */
  115. /* for dirv2 extrablk is data */
  116. } xfs_da_state_t;
  117. /*
  118. * Utility macros to aid in logging changed structure fields.
  119. */
  120. #define XFS_DA_LOGOFF(BASE, ADDR) ((char *)(ADDR) - (char *)(BASE))
  121. #define XFS_DA_LOGRANGE(BASE, ADDR, SIZE) \
  122. (uint)(XFS_DA_LOGOFF(BASE, ADDR)), \
  123. (uint)(XFS_DA_LOGOFF(BASE, ADDR)+(SIZE)-1)
  124. /*
  125. * Name ops for directory and/or attr name operations
  126. */
  127. struct xfs_nameops {
  128. xfs_dahash_t (*hashname)(struct xfs_name *);
  129. enum xfs_dacmp (*compname)(struct xfs_da_args *,
  130. const unsigned char *, int);
  131. };
  132. /*========================================================================
  133. * Function prototypes.
  134. *========================================================================*/
  135. /*
  136. * Routines used for growing the Btree.
  137. */
  138. int xfs_da3_node_create(struct xfs_da_args *args, xfs_dablk_t blkno,
  139. int level, struct xfs_buf **bpp, int whichfork);
  140. int xfs_da3_split(xfs_da_state_t *state);
  141. /*
  142. * Routines used for shrinking the Btree.
  143. */
  144. int xfs_da3_join(xfs_da_state_t *state);
  145. void xfs_da3_fixhashpath(struct xfs_da_state *state,
  146. struct xfs_da_state_path *path_to_to_fix);
  147. /*
  148. * Routines used for finding things in the Btree.
  149. */
  150. int xfs_da3_node_lookup_int(xfs_da_state_t *state, int *result);
  151. int xfs_da3_path_shift(xfs_da_state_t *state, xfs_da_state_path_t *path,
  152. int forward, int release, int *result);
  153. /*
  154. * Utility routines.
  155. */
  156. int xfs_da3_blk_link(xfs_da_state_t *state, xfs_da_state_blk_t *old_blk,
  157. xfs_da_state_blk_t *new_blk);
  158. int xfs_da3_node_read(struct xfs_trans *tp, struct xfs_inode *dp,
  159. xfs_dablk_t bno, xfs_daddr_t mappedbno,
  160. struct xfs_buf **bpp, int which_fork);
  161. /*
  162. * Utility routines.
  163. */
  164. int xfs_da_grow_inode(xfs_da_args_t *args, xfs_dablk_t *new_blkno);
  165. int xfs_da_grow_inode_int(struct xfs_da_args *args, xfs_fileoff_t *bno,
  166. int count);
  167. int xfs_da_get_buf(struct xfs_trans *trans, struct xfs_inode *dp,
  168. xfs_dablk_t bno, xfs_daddr_t mappedbno,
  169. struct xfs_buf **bp, int whichfork);
  170. int xfs_da_read_buf(struct xfs_trans *trans, struct xfs_inode *dp,
  171. xfs_dablk_t bno, xfs_daddr_t mappedbno,
  172. struct xfs_buf **bpp, int whichfork,
  173. const struct xfs_buf_ops *ops);
  174. int xfs_da_reada_buf(struct xfs_inode *dp, xfs_dablk_t bno,
  175. xfs_daddr_t mapped_bno, int whichfork,
  176. const struct xfs_buf_ops *ops);
  177. int xfs_da_shrink_inode(xfs_da_args_t *args, xfs_dablk_t dead_blkno,
  178. struct xfs_buf *dead_buf);
  179. uint xfs_da_hashname(const uint8_t *name_string, int name_length);
  180. enum xfs_dacmp xfs_da_compname(struct xfs_da_args *args,
  181. const unsigned char *name, int len);
  182. xfs_da_state_t *xfs_da_state_alloc(void);
  183. void xfs_da_state_free(xfs_da_state_t *state);
  184. extern struct kmem_zone *xfs_da_state_zone;
  185. extern const struct xfs_nameops xfs_default_nameops;
  186. #endif /* __XFS_DA_BTREE_H__ */