xfs_dir2_node.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright (c) 2000,2005 Silicon Graphics, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it would be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write the Free Software Foundation,
  16. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef __XFS_DIR2_NODE_H__
  19. #define __XFS_DIR2_NODE_H__
  20. /*
  21. * Directory version 2, btree node format structures
  22. */
  23. struct uio;
  24. struct xfs_dabuf;
  25. struct xfs_da_args;
  26. struct xfs_da_state;
  27. struct xfs_da_state_blk;
  28. struct xfs_inode;
  29. struct xfs_trans;
  30. /*
  31. * Offset of the freespace index.
  32. */
  33. #define XFS_DIR2_FREE_SPACE 2
  34. #define XFS_DIR2_FREE_OFFSET (XFS_DIR2_FREE_SPACE * XFS_DIR2_SPACE_SIZE)
  35. #define XFS_DIR2_FREE_FIRSTDB(mp) \
  36. XFS_DIR2_BYTE_TO_DB(mp, XFS_DIR2_FREE_OFFSET)
  37. #define XFS_DIR2_FREE_MAGIC 0x58443246 /* XD2F */
  38. typedef struct xfs_dir2_free_hdr {
  39. __be32 magic; /* XFS_DIR2_FREE_MAGIC */
  40. __be32 firstdb; /* db of first entry */
  41. __be32 nvalid; /* count of valid entries */
  42. __be32 nused; /* count of used entries */
  43. } xfs_dir2_free_hdr_t;
  44. typedef struct xfs_dir2_free {
  45. xfs_dir2_free_hdr_t hdr; /* block header */
  46. __be16 bests[1]; /* best free counts */
  47. /* unused entries are -1 */
  48. } xfs_dir2_free_t;
  49. #define XFS_DIR2_MAX_FREE_BESTS(mp) \
  50. (((mp)->m_dirblksize - (uint)sizeof(xfs_dir2_free_hdr_t)) / \
  51. (uint)sizeof(xfs_dir2_data_off_t))
  52. /*
  53. * Convert data space db to the corresponding free db.
  54. */
  55. #define XFS_DIR2_DB_TO_FDB(mp,db) xfs_dir2_db_to_fdb(mp, db)
  56. static inline xfs_dir2_db_t
  57. xfs_dir2_db_to_fdb(struct xfs_mount *mp, xfs_dir2_db_t db)
  58. {
  59. return (XFS_DIR2_FREE_FIRSTDB(mp) + (db) / XFS_DIR2_MAX_FREE_BESTS(mp));
  60. }
  61. /*
  62. * Convert data space db to the corresponding index in a free db.
  63. */
  64. #define XFS_DIR2_DB_TO_FDINDEX(mp,db) xfs_dir2_db_to_fdindex(mp, db)
  65. static inline int
  66. xfs_dir2_db_to_fdindex(struct xfs_mount *mp, xfs_dir2_db_t db)
  67. {
  68. return ((db) % XFS_DIR2_MAX_FREE_BESTS(mp));
  69. }
  70. extern void xfs_dir2_free_log_bests(struct xfs_trans *tp, struct xfs_dabuf *bp,
  71. int first, int last);
  72. extern int xfs_dir2_leaf_to_node(struct xfs_da_args *args,
  73. struct xfs_dabuf *lbp);
  74. extern xfs_dahash_t xfs_dir2_leafn_lasthash(struct xfs_dabuf *bp, int *count);
  75. extern int xfs_dir2_leafn_lookup_int(struct xfs_dabuf *bp,
  76. struct xfs_da_args *args, int *indexp,
  77. struct xfs_da_state *state);
  78. extern int xfs_dir2_leafn_order(struct xfs_dabuf *leaf1_bp,
  79. struct xfs_dabuf *leaf2_bp);
  80. extern int xfs_dir2_leafn_split(struct xfs_da_state *state,
  81. struct xfs_da_state_blk *oldblk,
  82. struct xfs_da_state_blk *newblk);
  83. extern int xfs_dir2_leafn_toosmall(struct xfs_da_state *state, int *action);
  84. extern void xfs_dir2_leafn_unbalance(struct xfs_da_state *state,
  85. struct xfs_da_state_blk *drop_blk,
  86. struct xfs_da_state_blk *save_blk);
  87. extern int xfs_dir2_node_addname(struct xfs_da_args *args);
  88. extern int xfs_dir2_node_lookup(struct xfs_da_args *args);
  89. extern int xfs_dir2_node_removename(struct xfs_da_args *args);
  90. extern int xfs_dir2_node_replace(struct xfs_da_args *args);
  91. extern int xfs_dir2_node_trim_free(struct xfs_da_args *args, xfs_fileoff_t fo,
  92. int *rvalp);
  93. #endif /* __XFS_DIR2_NODE_H__ */