xfs_bmap_btree.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright (c) 2000,2002-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_BMAP_BTREE_H__
  19. #define __XFS_BMAP_BTREE_H__
  20. struct xfs_btree_cur;
  21. struct xfs_btree_block;
  22. struct xfs_mount;
  23. struct xfs_inode;
  24. struct xfs_trans;
  25. /*
  26. * Btree block header size depends on a superblock flag.
  27. */
  28. #define XFS_BMBT_BLOCK_LEN(mp) \
  29. (xfs_sb_version_hascrc(&((mp)->m_sb)) ? \
  30. XFS_BTREE_LBLOCK_CRC_LEN : XFS_BTREE_LBLOCK_LEN)
  31. #define XFS_BMBT_REC_ADDR(mp, block, index) \
  32. ((xfs_bmbt_rec_t *) \
  33. ((char *)(block) + \
  34. XFS_BMBT_BLOCK_LEN(mp) + \
  35. ((index) - 1) * sizeof(xfs_bmbt_rec_t)))
  36. #define XFS_BMBT_KEY_ADDR(mp, block, index) \
  37. ((xfs_bmbt_key_t *) \
  38. ((char *)(block) + \
  39. XFS_BMBT_BLOCK_LEN(mp) + \
  40. ((index) - 1) * sizeof(xfs_bmbt_key_t)))
  41. #define XFS_BMBT_PTR_ADDR(mp, block, index, maxrecs) \
  42. ((xfs_bmbt_ptr_t *) \
  43. ((char *)(block) + \
  44. XFS_BMBT_BLOCK_LEN(mp) + \
  45. (maxrecs) * sizeof(xfs_bmbt_key_t) + \
  46. ((index) - 1) * sizeof(xfs_bmbt_ptr_t)))
  47. #define XFS_BMDR_REC_ADDR(block, index) \
  48. ((xfs_bmdr_rec_t *) \
  49. ((char *)(block) + \
  50. sizeof(struct xfs_bmdr_block) + \
  51. ((index) - 1) * sizeof(xfs_bmdr_rec_t)))
  52. #define XFS_BMDR_KEY_ADDR(block, index) \
  53. ((xfs_bmdr_key_t *) \
  54. ((char *)(block) + \
  55. sizeof(struct xfs_bmdr_block) + \
  56. ((index) - 1) * sizeof(xfs_bmdr_key_t)))
  57. #define XFS_BMDR_PTR_ADDR(block, index, maxrecs) \
  58. ((xfs_bmdr_ptr_t *) \
  59. ((char *)(block) + \
  60. sizeof(struct xfs_bmdr_block) + \
  61. (maxrecs) * sizeof(xfs_bmdr_key_t) + \
  62. ((index) - 1) * sizeof(xfs_bmdr_ptr_t)))
  63. /*
  64. * These are to be used when we know the size of the block and
  65. * we don't have a cursor.
  66. */
  67. #define XFS_BMAP_BROOT_PTR_ADDR(mp, bb, i, sz) \
  68. XFS_BMBT_PTR_ADDR(mp, bb, i, xfs_bmbt_maxrecs(mp, sz, 0))
  69. #define XFS_BMAP_BROOT_SPACE_CALC(mp, nrecs) \
  70. (int)(XFS_BMBT_BLOCK_LEN(mp) + \
  71. ((nrecs) * (sizeof(xfs_bmbt_key_t) + sizeof(xfs_bmbt_ptr_t))))
  72. #define XFS_BMAP_BROOT_SPACE(mp, bb) \
  73. (XFS_BMAP_BROOT_SPACE_CALC(mp, be16_to_cpu((bb)->bb_numrecs)))
  74. #define XFS_BMDR_SPACE_CALC(nrecs) \
  75. (int)(sizeof(xfs_bmdr_block_t) + \
  76. ((nrecs) * (sizeof(xfs_bmbt_key_t) + sizeof(xfs_bmbt_ptr_t))))
  77. #define XFS_BMAP_BMDR_SPACE(bb) \
  78. (XFS_BMDR_SPACE_CALC(be16_to_cpu((bb)->bb_numrecs)))
  79. /*
  80. * Maximum number of bmap btree levels.
  81. */
  82. #define XFS_BM_MAXLEVELS(mp,w) ((mp)->m_bm_maxlevels[(w)])
  83. /*
  84. * Prototypes for xfs_bmap.c to call.
  85. */
  86. extern void xfs_bmdr_to_bmbt(struct xfs_inode *, xfs_bmdr_block_t *, int,
  87. struct xfs_btree_block *, int);
  88. void xfs_bmbt_disk_set_all(struct xfs_bmbt_rec *r, struct xfs_bmbt_irec *s);
  89. extern xfs_filblks_t xfs_bmbt_disk_get_blockcount(xfs_bmbt_rec_t *r);
  90. extern xfs_fileoff_t xfs_bmbt_disk_get_startoff(xfs_bmbt_rec_t *r);
  91. extern void xfs_bmbt_disk_get_all(xfs_bmbt_rec_t *r, xfs_bmbt_irec_t *s);
  92. extern void xfs_bmbt_to_bmdr(struct xfs_mount *, struct xfs_btree_block *, int,
  93. xfs_bmdr_block_t *, int);
  94. extern int xfs_bmbt_get_maxrecs(struct xfs_btree_cur *, int level);
  95. extern int xfs_bmdr_maxrecs(int blocklen, int leaf);
  96. extern int xfs_bmbt_maxrecs(struct xfs_mount *, int blocklen, int leaf);
  97. extern int xfs_bmbt_change_owner(struct xfs_trans *tp, struct xfs_inode *ip,
  98. int whichfork, xfs_ino_t new_owner,
  99. struct list_head *buffer_list);
  100. extern struct xfs_btree_cur *xfs_bmbt_init_cursor(struct xfs_mount *,
  101. struct xfs_trans *, struct xfs_inode *, int);
  102. #endif /* __XFS_BMAP_BTREE_H__ */