xfs_da_btree.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. * Btree searching and modification structure definitions.
  28. *========================================================================*/
  29. /*
  30. * Search comparison results
  31. */
  32. enum xfs_dacmp {
  33. XFS_CMP_DIFFERENT, /* names are completely different */
  34. XFS_CMP_EXACT, /* names are exactly the same */
  35. XFS_CMP_CASE /* names are same but differ in case */
  36. };
  37. /*
  38. * Structure to ease passing around component names.
  39. */
  40. typedef struct xfs_da_args {
  41. const __uint8_t *name; /* string (maybe not NULL terminated) */
  42. int namelen; /* length of string (maybe no NULL) */
  43. __uint8_t filetype; /* filetype of inode for directories */
  44. __uint8_t *value; /* set of bytes (maybe contain NULLs) */
  45. int valuelen; /* length of value */
  46. int flags; /* argument flags (eg: ATTR_NOCREATE) */
  47. xfs_dahash_t hashval; /* hash value of name */
  48. xfs_ino_t inumber; /* input/output inode number */
  49. struct xfs_inode *dp; /* directory inode to manipulate */
  50. xfs_fsblock_t *firstblock; /* ptr to firstblock for bmap calls */
  51. struct xfs_bmap_free *flist; /* ptr to freelist for bmap_finish */
  52. struct xfs_trans *trans; /* current trans (changes over time) */
  53. xfs_extlen_t total; /* total blocks needed, for 1st bmap */
  54. int whichfork; /* data or attribute fork */
  55. xfs_dablk_t blkno; /* blkno of attr leaf of interest */
  56. int index; /* index of attr of interest in blk */
  57. xfs_dablk_t rmtblkno; /* remote attr value starting blkno */
  58. int rmtblkcnt; /* remote attr value block count */
  59. int rmtvaluelen; /* remote attr value length in bytes */
  60. xfs_dablk_t blkno2; /* blkno of 2nd attr leaf of interest */
  61. int index2; /* index of 2nd attr in blk */
  62. xfs_dablk_t rmtblkno2; /* remote attr value starting blkno */
  63. int rmtblkcnt2; /* remote attr value block count */
  64. int rmtvaluelen2; /* remote attr value length in bytes */
  65. int op_flags; /* operation flags */
  66. enum xfs_dacmp cmpresult; /* name compare result for lookups */
  67. } xfs_da_args_t;
  68. /*
  69. * Operation flags:
  70. */
  71. #define XFS_DA_OP_JUSTCHECK 0x0001 /* check for ok with no space */
  72. #define XFS_DA_OP_RENAME 0x0002 /* this is an atomic rename op */
  73. #define XFS_DA_OP_ADDNAME 0x0004 /* this is an add operation */
  74. #define XFS_DA_OP_OKNOENT 0x0008 /* lookup/add op, ENOENT ok, else die */
  75. #define XFS_DA_OP_CILOOKUP 0x0010 /* lookup to return CI name if found */
  76. #define XFS_DA_OP_FLAGS \
  77. { XFS_DA_OP_JUSTCHECK, "JUSTCHECK" }, \
  78. { XFS_DA_OP_RENAME, "RENAME" }, \
  79. { XFS_DA_OP_ADDNAME, "ADDNAME" }, \
  80. { XFS_DA_OP_OKNOENT, "OKNOENT" }, \
  81. { XFS_DA_OP_CILOOKUP, "CILOOKUP" }
  82. /*
  83. * Storage for holding state during Btree searches and split/join ops.
  84. *
  85. * Only need space for 5 intermediate nodes. With a minimum of 62-way
  86. * fanout to the Btree, we can support over 900 million directory blocks,
  87. * which is slightly more than enough.
  88. */
  89. typedef struct xfs_da_state_blk {
  90. struct xfs_buf *bp; /* buffer containing block */
  91. xfs_dablk_t blkno; /* filesystem blkno of buffer */
  92. xfs_daddr_t disk_blkno; /* on-disk blkno (in BBs) of buffer */
  93. int index; /* relevant index into block */
  94. xfs_dahash_t hashval; /* last hash value in block */
  95. int magic; /* blk's magic number, ie: blk type */
  96. } xfs_da_state_blk_t;
  97. typedef struct xfs_da_state_path {
  98. int active; /* number of active levels */
  99. xfs_da_state_blk_t blk[XFS_DA_NODE_MAXDEPTH];
  100. } xfs_da_state_path_t;
  101. typedef struct xfs_da_state {
  102. xfs_da_args_t *args; /* filename arguments */
  103. struct xfs_mount *mp; /* filesystem mount point */
  104. unsigned int blocksize; /* logical block size */
  105. unsigned int node_ents; /* how many entries in danode */
  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. xfs_daddr_t xfs_da_reada_buf(struct xfs_trans *trans, struct xfs_inode *dp,
  172. xfs_dablk_t bno, xfs_daddr_t mapped_bno,
  173. int whichfork, 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__ */