]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - db/cntbt.c
Update copyright/license notices to match SGI legal prefered boilerplate.
[thirdparty/xfsprogs-dev.git] / db / cntbt.c
CommitLineData
2bd0ea18 1/*
da23017d
NS
2 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
dfc130f3 4 *
da23017d
NS
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
2bd0ea18 7 * published by the Free Software Foundation.
dfc130f3 8 *
da23017d
NS
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.
dfc130f3 13 *
da23017d
NS
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
2bd0ea18
NS
17 */
18
1d7e80ee 19#include <xfs/libxfs.h>
2bd0ea18
NS
20#include "type.h"
21#include "faddr.h"
22#include "fprint.h"
23#include "field.h"
24#include "cntbt.h"
25#include "print.h"
26#include "bit.h"
4ca431fc 27#include "init.h"
2bd0ea18
NS
28
29static int cntbt_key_count(void *obj, int startoff);
30static int cntbt_key_offset(void *obj, int startoff, int idx);
31static int cntbt_ptr_count(void *obj, int startoff);
32static int cntbt_ptr_offset(void *obj, int startoff, int idx);
33static int cntbt_rec_count(void *obj, int startoff);
34static int cntbt_rec_offset(void *obj, int startoff, int idx);
35
36const field_t cntbt_hfld[] = {
37 { "", FLDT_CNTBT, OI(0), C1, 0, TYP_NONE },
38 { NULL }
39};
40
41#define OFF(f) bitize(offsetof(xfs_alloc_block_t, bb_ ## f))
42const field_t cntbt_flds[] = {
43 { "magic", FLDT_UINT32X, OI(OFF(magic)), C1, 0, TYP_NONE },
44 { "level", FLDT_UINT16D, OI(OFF(level)), C1, 0, TYP_NONE },
45 { "numrecs", FLDT_UINT16D, OI(OFF(numrecs)), C1, 0, TYP_NONE },
46 { "leftsib", FLDT_AGBLOCK, OI(OFF(leftsib)), C1, 0, TYP_CNTBT },
47 { "rightsib", FLDT_AGBLOCK, OI(OFF(rightsib)), C1, 0, TYP_CNTBT },
48 { "recs", FLDT_CNTBTREC, cntbt_rec_offset, cntbt_rec_count,
49 FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE },
50 { "keys", FLDT_CNTBTKEY, cntbt_key_offset, cntbt_key_count,
51 FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE },
52 { "ptrs", FLDT_CNTBTPTR, cntbt_ptr_offset, cntbt_ptr_count,
53 FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_CNTBT },
54 { NULL }
55};
56
57#define KOFF(f) bitize(offsetof(xfs_alloc_key_t, ar_ ## f))
58const field_t cntbt_key_flds[] = {
59 { "blockcount", FLDT_EXTLEN, OI(KOFF(blockcount)), C1, 0, TYP_NONE },
60 { "startblock", FLDT_AGBLOCK, OI(KOFF(startblock)), C1, 0, TYP_DATA },
61 { NULL }
62};
63
64#define ROFF(f) bitize(offsetof(xfs_alloc_rec_t, ar_ ## f))
65const field_t cntbt_rec_flds[] = {
66 { "startblock", FLDT_AGBLOCK, OI(ROFF(startblock)), C1, 0, TYP_DATA },
67 { "blockcount", FLDT_EXTLEN, OI(ROFF(blockcount)), C1, 0, TYP_NONE },
68 { NULL }
69};
70
71/*ARGSUSED*/
72static int
73cntbt_key_count(
74 void *obj,
75 int startoff)
76{
77 xfs_alloc_block_t *block;
78
79 ASSERT(startoff == 0);
80 block = obj;
81 if (INT_GET(block->bb_level, ARCH_CONVERT) == 0)
82 return 0;
83 return INT_GET(block->bb_numrecs, ARCH_CONVERT);
84}
85
86/*ARGSUSED*/
87static int
88cntbt_key_offset(
89 void *obj,
90 int startoff,
91 int idx)
92{
93 xfs_alloc_block_t *block;
94 xfs_alloc_key_t *kp;
95
96 ASSERT(startoff == 0);
97 block = obj;
98 ASSERT(INT_GET(block->bb_level, ARCH_CONVERT) > 0);
99 kp = XFS_BTREE_KEY_ADDR(mp->m_sb.sb_blocksize, xfs_alloc, block, idx,
100 XFS_BTREE_BLOCK_MAXRECS(mp->m_sb.sb_blocksize, xfs_alloc, 0));
101 return bitize((int)((char *)kp - (char *)block));
102}
103
104/*ARGSUSED*/
105static int
106cntbt_ptr_count(
107 void *obj,
108 int startoff)
109{
110 xfs_alloc_block_t *block;
111
112 ASSERT(startoff == 0);
113 block = obj;
114 if (INT_GET(block->bb_level, ARCH_CONVERT) == 0)
115 return 0;
116 return INT_GET(block->bb_numrecs, ARCH_CONVERT);
117}
118
119/*ARGSUSED*/
120static int
121cntbt_ptr_offset(
122 void *obj,
123 int startoff,
124 int idx)
125{
126 xfs_alloc_block_t *block;
127 xfs_alloc_ptr_t *pp;
128
129 ASSERT(startoff == 0);
130 block = obj;
131 ASSERT(INT_GET(block->bb_level, ARCH_CONVERT) > 0);
132 pp = XFS_BTREE_PTR_ADDR(mp->m_sb.sb_blocksize, xfs_alloc, block, idx,
133 XFS_BTREE_BLOCK_MAXRECS(mp->m_sb.sb_blocksize, xfs_alloc, 0));
134 return bitize((int)((char *)pp - (char *)block));
135}
136
137/*ARGSUSED*/
138static int
139cntbt_rec_count(
140 void *obj,
141 int startoff)
142{
143 xfs_alloc_block_t *block;
144
145 ASSERT(startoff == 0);
146 block = obj;
147 if (INT_GET(block->bb_level, ARCH_CONVERT) > 0)
148 return 0;
149 return INT_GET(block->bb_numrecs, ARCH_CONVERT);
150}
151
152/*ARGSUSED*/
153static int
154cntbt_rec_offset(
155 void *obj,
156 int startoff,
157 int idx)
158{
159 xfs_alloc_block_t *block;
160 xfs_alloc_rec_t *rp;
161
162 ASSERT(startoff == 0);
163 block = obj;
164 ASSERT(INT_GET(block->bb_level, ARCH_CONVERT) == 0);
165 rp = XFS_BTREE_REC_ADDR(mp->m_sb.sb_blocksize, xfs_alloc, block, idx,
166 XFS_BTREE_BLOCK_MAXRECS(mp->m_sb.sb_blocksize, xfs_alloc, 1));
167 return bitize((int)((char *)rp - (char *)block));
168}
169
170/*ARGSUSED*/
171int
172cntbt_size(
173 void *obj,
174 int startoff,
175 int idx)
176{
177 return bitize(mp->m_sb.sb_blocksize);
178}