xfs_da_btree.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. xfs_dablk_t blkno2; /* blkno of 2nd attr leaf of interest */
  60. int index2; /* index of 2nd attr in blk */
  61. xfs_dablk_t rmtblkno2; /* remote attr value starting blkno */
  62. int rmtblkcnt2; /* remote attr value block count */
  63. int op_flags; /* operation flags */
  64. enum xfs_dacmp cmpresult; /* name compare result for lookups */
  65. } xfs_da_args_t;
  66. /*
  67. * Operation flags:
  68. */
  69. #define XFS_DA_OP_JUSTCHECK 0x0001 /* check for ok with no space */
  70. #define XFS_DA_OP_RENAME 0x0002 /* this is an atomic rename op */
  71. #define XFS_DA_OP_ADDNAME 0x0004 /* this is an add operation */
  72. #define XFS_DA_OP_OKNOENT 0x0008 /* lookup/add op, ENOENT ok, else die */
  73. #define XFS_DA_OP_CILOOKUP 0x0010 /* lookup to return CI name if found */
  74. #define XFS_DA_OP_FLAGS \
  75. { XFS_DA_OP_JUSTCHECK, "JUSTCHECK" }, \
  76. { XFS_DA_OP_RENAME, "RENAME" }, \
  77. { XFS_DA_OP_ADDNAME, "ADDNAME" }, \
  78. { XFS_DA_OP_OKNOENT, "OKNOENT" }, \
  79. { XFS_DA_OP_CILOOKUP, "CILOOKUP" }
  80. /*
  81. * Storage for holding state during Btree searches and split/join ops.
  82. *
  83. * Only need space for 5 intermediate nodes. With a minimum of 62-way
  84. * fanout to the Btree, we can support over 900 million directory blocks,
  85. * which is slightly more than enough.
  86. */
  87. typedef struct xfs_da_state_blk {
  88. struct xfs_buf *bp; /* buffer containing block */
  89. xfs_dablk_t blkno; /* filesystem blkno of buffer */
  90. xfs_daddr_t disk_blkno; /* on-disk blkno (in BBs) of buffer */
  91. int index; /* relevant index into block */
  92. xfs_dahash_t hashval; /* last hash value in block */
  93. int magic; /* blk's magic number, ie: blk type */
  94. } xfs_da_state_blk_t;
  95. typedef struct xfs_da_state_path {
  96. int active; /* number of active levels */
  97. xfs_da_state_blk_t blk[XFS_DA_NODE_MAXDEPTH];
  98. } xfs_da_state_path_t;
  99. typedef struct xfs_da_state {
  100. xfs_da_args_t *args; /* filename arguments */
  101. struct xfs_mount *mp; /* filesystem mount point */
  102. unsigned int blocksize; /* logical block size */
  103. unsigned int node_ents; /* how many entries in danode */
  104. xfs_da_state_path_t path; /* search/split paths */
  105. xfs_da_state_path_t altpath; /* alternate path for join */
  106. unsigned char inleaf; /* insert into 1->lf, 0->splf */
  107. unsigned char extravalid; /* T/F: extrablk is in use */
  108. unsigned char extraafter; /* T/F: extrablk is after new */
  109. xfs_da_state_blk_t extrablk; /* for double-splits on leaves */
  110. /* for dirv2 extrablk is data */
  111. } xfs_da_state_t;
  112. /*
  113. * Utility macros to aid in logging changed structure fields.
  114. */
  115. #define XFS_DA_LOGOFF(BASE, ADDR) ((char *)(ADDR) - (char *)(BASE))
  116. #define XFS_DA_LOGRANGE(BASE, ADDR, SIZE) \
  117. (uint)(XFS_DA_LOGOFF(BASE, ADDR)), \
  118. (uint)(XFS_DA_LOGOFF(BASE, ADDR)+(SIZE)-1)
  119. /*
  120. * Name ops for directory and/or attr name operations
  121. */
  122. struct xfs_nameops {
  123. xfs_dahash_t (*hashname)(struct xfs_name *);
  124. enum xfs_dacmp (*compname)(struct xfs_da_args *,
  125. const unsigned char *, int);
  126. };
  127. /*========================================================================
  128. * Function prototypes.
  129. *========================================================================*/
  130. /*
  131. * Routines used for growing the Btree.
  132. */
  133. int xfs_da3_node_create(struct xfs_da_args *args, xfs_dablk_t blkno,
  134. int level, struct xfs_buf **bpp, int whichfork);
  135. int xfs_da3_split(xfs_da_state_t *state);
  136. /*
  137. * Routines used for shrinking the Btree.
  138. */
  139. int xfs_da3_join(xfs_da_state_t *state);
  140. void xfs_da3_fixhashpath(struct xfs_da_state *state,
  141. struct xfs_da_state_path *path_to_to_fix);
  142. /*
  143. * Routines used for finding things in the Btree.
  144. */
  145. int xfs_da3_node_lookup_int(xfs_da_state_t *state, int *result);
  146. int xfs_da3_path_shift(xfs_da_state_t *state, xfs_da_state_path_t *path,
  147. int forward, int release, int *result);
  148. /*
  149. * Utility routines.
  150. */
  151. int xfs_da3_blk_link(xfs_da_state_t *state, xfs_da_state_blk_t *old_blk,
  152. xfs_da_state_blk_t *new_blk);
  153. int xfs_da3_node_read(struct xfs_trans *tp, struct xfs_inode *dp,
  154. xfs_dablk_t bno, xfs_daddr_t mappedbno,
  155. struct xfs_buf **bpp, int which_fork);
  156. /*
  157. * Utility routines.
  158. */
  159. int xfs_da_grow_inode(xfs_da_args_t *args, xfs_dablk_t *new_blkno);
  160. int xfs_da_grow_inode_int(struct xfs_da_args *args, xfs_fileoff_t *bno,
  161. int count);
  162. int xfs_da_get_buf(struct xfs_trans *trans, struct xfs_inode *dp,
  163. xfs_dablk_t bno, xfs_daddr_t mappedbno,
  164. struct xfs_buf **bp, int whichfork);
  165. int xfs_da_read_buf(struct xfs_trans *trans, struct xfs_inode *dp,
  166. xfs_dablk_t bno, xfs_daddr_t mappedbno,
  167. struct xfs_buf **bpp, int whichfork,
  168. const struct xfs_buf_ops *ops);
  169. xfs_daddr_t xfs_da_reada_buf(struct xfs_trans *trans, struct xfs_inode *dp,
  170. xfs_dablk_t bno, xfs_daddr_t mapped_bno,
  171. int whichfork, const struct xfs_buf_ops *ops);
  172. int xfs_da_shrink_inode(xfs_da_args_t *args, xfs_dablk_t dead_blkno,
  173. struct xfs_buf *dead_buf);
  174. uint xfs_da_hashname(const __uint8_t *name_string, int name_length);
  175. enum xfs_dacmp xfs_da_compname(struct xfs_da_args *args,
  176. const unsigned char *name, int len);
  177. xfs_da_state_t *xfs_da_state_alloc(void);
  178. void xfs_da_state_free(xfs_da_state_t *state);
  179. extern struct kmem_zone *xfs_da_state_zone;
  180. extern const struct xfs_nameops xfs_default_nameops;
  181. #endif /* __XFS_DA_BTREE_H__ */