xfs_alloc_btree.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of version 2 of the GNU General Public License as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it would be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. *
  12. * Further, this software is distributed without any warranty that it is
  13. * free of the rightful claim of any third person regarding infringement
  14. * or the like. Any license provided herein, whether implied or
  15. * otherwise, applies only to this software file. Patent licenses, if
  16. * any, provided herein do not apply to combinations of this program with
  17. * other software, or any other product whatsoever.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write the Free Software Foundation, Inc., 59
  21. * Temple Place - Suite 330, Boston MA 02111-1307, USA.
  22. *
  23. * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
  24. * Mountain View, CA 94043, or:
  25. *
  26. * http://www.sgi.com
  27. *
  28. * For further information regarding this notice, see:
  29. *
  30. * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
  31. */
  32. #ifndef __XFS_ALLOC_BTREE_H__
  33. #define __XFS_ALLOC_BTREE_H__
  34. /*
  35. * Freespace on-disk structures
  36. */
  37. struct xfs_buf;
  38. struct xfs_btree_cur;
  39. struct xfs_btree_sblock;
  40. struct xfs_mount;
  41. /*
  42. * There are two on-disk btrees, one sorted by blockno and one sorted
  43. * by blockcount and blockno. All blocks look the same to make the code
  44. * simpler; if we have time later, we'll make the optimizations.
  45. */
  46. #define XFS_ABTB_MAGIC 0x41425442 /* 'ABTB' for bno tree */
  47. #define XFS_ABTC_MAGIC 0x41425443 /* 'ABTC' for cnt tree */
  48. /*
  49. * Data record/key structure
  50. */
  51. typedef struct xfs_alloc_rec
  52. {
  53. xfs_agblock_t ar_startblock; /* starting block number */
  54. xfs_extlen_t ar_blockcount; /* count of free blocks */
  55. } xfs_alloc_rec_t, xfs_alloc_key_t;
  56. typedef xfs_agblock_t xfs_alloc_ptr_t; /* btree pointer type */
  57. /* btree block header type */
  58. typedef struct xfs_btree_sblock xfs_alloc_block_t;
  59. #define XFS_BUF_TO_ALLOC_BLOCK(bp) ((xfs_alloc_block_t *)XFS_BUF_PTR(bp))
  60. /*
  61. * Real block structures have a size equal to the disk block size.
  62. */
  63. #define XFS_ALLOC_BLOCK_SIZE(lev,cur) (1 << (cur)->bc_blocklog)
  64. #define XFS_ALLOC_BLOCK_MAXRECS(lev,cur) ((cur)->bc_mp->m_alloc_mxr[lev != 0])
  65. #define XFS_ALLOC_BLOCK_MINRECS(lev,cur) ((cur)->bc_mp->m_alloc_mnr[lev != 0])
  66. /*
  67. * Minimum and maximum blocksize and sectorsize.
  68. * The blocksize upper limit is pretty much arbitrary.
  69. * The sectorsize upper limit is due to sizeof(sb_sectsize).
  70. */
  71. #define XFS_MIN_BLOCKSIZE_LOG 9 /* i.e. 512 bytes */
  72. #define XFS_MAX_BLOCKSIZE_LOG 16 /* i.e. 65536 bytes */
  73. #define XFS_MIN_BLOCKSIZE (1 << XFS_MIN_BLOCKSIZE_LOG)
  74. #define XFS_MAX_BLOCKSIZE (1 << XFS_MAX_BLOCKSIZE_LOG)
  75. #define XFS_MIN_SECTORSIZE_LOG 9 /* i.e. 512 bytes */
  76. #define XFS_MAX_SECTORSIZE_LOG 15 /* i.e. 32768 bytes */
  77. #define XFS_MIN_SECTORSIZE (1 << XFS_MIN_SECTORSIZE_LOG)
  78. #define XFS_MAX_SECTORSIZE (1 << XFS_MAX_SECTORSIZE_LOG)
  79. /*
  80. * Block numbers in the AG:
  81. * SB is sector 0, AGF is sector 1, AGI is sector 2, AGFL is sector 3.
  82. */
  83. #define XFS_BNO_BLOCK(mp) ((xfs_agblock_t)(XFS_AGFL_BLOCK(mp) + 1))
  84. #define XFS_CNT_BLOCK(mp) ((xfs_agblock_t)(XFS_BNO_BLOCK(mp) + 1))
  85. /*
  86. * Record, key, and pointer address macros for btree blocks.
  87. */
  88. #define XFS_ALLOC_REC_ADDR(bb,i,cur) \
  89. XFS_BTREE_REC_ADDR(XFS_ALLOC_BLOCK_SIZE(0,cur), xfs_alloc, \
  90. bb, i, XFS_ALLOC_BLOCK_MAXRECS(0, cur))
  91. #define XFS_ALLOC_KEY_ADDR(bb,i,cur) \
  92. XFS_BTREE_KEY_ADDR(XFS_ALLOC_BLOCK_SIZE(1,cur), xfs_alloc, \
  93. bb, i, XFS_ALLOC_BLOCK_MAXRECS(1, cur))
  94. #define XFS_ALLOC_PTR_ADDR(bb,i,cur) \
  95. XFS_BTREE_PTR_ADDR(XFS_ALLOC_BLOCK_SIZE(1,cur), xfs_alloc, \
  96. bb, i, XFS_ALLOC_BLOCK_MAXRECS(1, cur))
  97. /*
  98. * Decrement cursor by one record at the level.
  99. * For nonzero levels the leaf-ward information is untouched.
  100. */
  101. extern int xfs_alloc_decrement(struct xfs_btree_cur *cur, int level, int *stat);
  102. /*
  103. * Delete the record pointed to by cur.
  104. * The cursor refers to the place where the record was (could be inserted)
  105. * when the operation returns.
  106. */
  107. extern int xfs_alloc_delete(struct xfs_btree_cur *cur, int *stat);
  108. /*
  109. * Get the data from the pointed-to record.
  110. */
  111. extern int xfs_alloc_get_rec(struct xfs_btree_cur *cur, xfs_agblock_t *bno,
  112. xfs_extlen_t *len, int *stat);
  113. /*
  114. * Increment cursor by one record at the level.
  115. * For nonzero levels the leaf-ward information is untouched.
  116. */
  117. extern int xfs_alloc_increment(struct xfs_btree_cur *cur, int level, int *stat);
  118. /*
  119. * Insert the current record at the point referenced by cur.
  120. * The cursor may be inconsistent on return if splits have been done.
  121. */
  122. extern int xfs_alloc_insert(struct xfs_btree_cur *cur, int *stat);
  123. /*
  124. * Lookup the record equal to [bno, len] in the btree given by cur.
  125. */
  126. extern int xfs_alloc_lookup_eq(struct xfs_btree_cur *cur, xfs_agblock_t bno,
  127. xfs_extlen_t len, int *stat);
  128. /*
  129. * Lookup the first record greater than or equal to [bno, len]
  130. * in the btree given by cur.
  131. */
  132. extern int xfs_alloc_lookup_ge(struct xfs_btree_cur *cur, xfs_agblock_t bno,
  133. xfs_extlen_t len, int *stat);
  134. /*
  135. * Lookup the first record less than or equal to [bno, len]
  136. * in the btree given by cur.
  137. */
  138. extern int xfs_alloc_lookup_le(struct xfs_btree_cur *cur, xfs_agblock_t bno,
  139. xfs_extlen_t len, int *stat);
  140. /*
  141. * Update the record referred to by cur, to the value given by [bno, len].
  142. * This either works (return 0) or gets an EFSCORRUPTED error.
  143. */
  144. extern int xfs_alloc_update(struct xfs_btree_cur *cur, xfs_agblock_t bno,
  145. xfs_extlen_t len);
  146. #endif /* __XFS_ALLOC_BTREE_H__ */