xfs_da_btree.h 7.5 KB

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