xfs_da_btree.h 8.2 KB

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