]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/bnobt.c
Cosmetic configure tweaks to keep xfsprogs in sync with other packages.
[thirdparty/xfsprogs-dev.git] / db / bnobt.c
1 /*
2 * Copyright (c) 2000-2001 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
33 #include <libxfs.h>
34 #include "type.h"
35 #include "faddr.h"
36 #include "fprint.h"
37 #include "field.h"
38 #include "bnobt.h"
39 #include "io.h"
40 #include "print.h"
41 #include "bit.h"
42 #include "init.h"
43
44 static int bnobt_key_count(void *obj, int startoff);
45 static int bnobt_key_offset(void *obj, int startoff, int idx);
46 static int bnobt_ptr_count(void *obj, int startoff);
47 static int bnobt_ptr_offset(void *obj, int startoff, int idx);
48 static int bnobt_rec_count(void *obj, int startoff);
49 static int bnobt_rec_offset(void *obj, int startoff, int idx);
50
51 const field_t bnobt_hfld[] = {
52 { "", FLDT_BNOBT, OI(0), C1, 0, TYP_NONE },
53 { NULL }
54 };
55
56 #define OFF(f) bitize(offsetof(xfs_alloc_block_t, bb_ ## f))
57 const field_t bnobt_flds[] = {
58 { "magic", FLDT_UINT32X, OI(OFF(magic)), C1, 0, TYP_NONE },
59 { "level", FLDT_UINT16D, OI(OFF(level)), C1, 0, TYP_NONE },
60 { "numrecs", FLDT_UINT16D, OI(OFF(numrecs)), C1, 0, TYP_NONE },
61 { "leftsib", FLDT_AGBLOCK, OI(OFF(leftsib)), C1, 0, TYP_BNOBT },
62 { "rightsib", FLDT_AGBLOCK, OI(OFF(rightsib)), C1, 0, TYP_BNOBT },
63 { "recs", FLDT_BNOBTREC, bnobt_rec_offset, bnobt_rec_count,
64 FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE },
65 { "keys", FLDT_BNOBTKEY, bnobt_key_offset, bnobt_key_count,
66 FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE },
67 { "ptrs", FLDT_BNOBTPTR, bnobt_ptr_offset, bnobt_ptr_count,
68 FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_BNOBT },
69 { NULL }
70 };
71
72 #define KOFF(f) bitize(offsetof(xfs_alloc_key_t, ar_ ## f))
73 const field_t bnobt_key_flds[] = {
74 { "startblock", FLDT_AGBLOCK, OI(KOFF(startblock)), C1, 0, TYP_DATA },
75 { "blockcount", FLDT_EXTLEN, OI(KOFF(blockcount)), C1, 0, TYP_NONE },
76 { NULL }
77 };
78
79 #define ROFF(f) bitize(offsetof(xfs_alloc_rec_t, ar_ ## f))
80 const field_t bnobt_rec_flds[] = {
81 { "startblock", FLDT_AGBLOCK, OI(ROFF(startblock)), C1, 0, TYP_DATA },
82 { "blockcount", FLDT_EXTLEN, OI(ROFF(blockcount)), C1, 0, TYP_NONE },
83 { NULL }
84 };
85
86 static int
87 bnobt_key_count(
88 void *obj,
89 int startoff)
90 {
91 xfs_alloc_block_t *block;
92
93 ASSERT(startoff == 0);
94 block = obj;
95 if (INT_GET(block->bb_level, ARCH_CONVERT) == 0)
96 return 0;
97 return INT_GET(block->bb_numrecs, ARCH_CONVERT);
98 }
99
100 static int
101 bnobt_key_offset(
102 void *obj,
103 int startoff,
104 int idx)
105 {
106 xfs_alloc_block_t *block;
107 xfs_alloc_key_t *kp;
108
109 ASSERT(startoff == 0);
110 block = obj;
111 ASSERT(INT_GET(block->bb_level, ARCH_CONVERT) > 0);
112 kp = XFS_BTREE_KEY_ADDR(mp->m_sb.sb_blocksize, xfs_alloc, block, idx,
113 XFS_BTREE_BLOCK_MAXRECS(mp->m_sb.sb_blocksize, xfs_alloc, 0));
114 return bitize((int)((char *)kp - (char *)block));
115 }
116
117 static int
118 bnobt_ptr_count(
119 void *obj,
120 int startoff)
121 {
122 xfs_alloc_block_t *block;
123
124 ASSERT(startoff == 0);
125 block = obj;
126 if (INT_GET(block->bb_level, ARCH_CONVERT) == 0)
127 return 0;
128 return INT_GET(block->bb_numrecs, ARCH_CONVERT);
129 }
130
131 static int
132 bnobt_ptr_offset(
133 void *obj,
134 int startoff,
135 int idx)
136 {
137 xfs_alloc_block_t *block;
138 xfs_alloc_ptr_t *pp;
139
140 ASSERT(startoff == 0);
141 block = obj;
142 ASSERT(INT_GET(block->bb_level, ARCH_CONVERT) > 0);
143 pp = XFS_BTREE_PTR_ADDR(mp->m_sb.sb_blocksize, xfs_alloc, block, idx,
144 XFS_BTREE_BLOCK_MAXRECS(mp->m_sb.sb_blocksize, xfs_alloc, 0));
145 return bitize((int)((char *)pp - (char *)block));
146 }
147
148 static int
149 bnobt_rec_count(
150 void *obj,
151 int startoff)
152 {
153 xfs_alloc_block_t *block;
154
155 ASSERT(startoff == 0);
156 block = obj;
157 if (INT_GET(block->bb_level, ARCH_CONVERT) > 0)
158 return 0;
159 return INT_GET(block->bb_numrecs, ARCH_CONVERT);
160 }
161
162 static int
163 bnobt_rec_offset(
164 void *obj,
165 int startoff,
166 int idx)
167 {
168 xfs_alloc_block_t *block;
169 xfs_alloc_rec_t *rp;
170
171 ASSERT(startoff == 0);
172 block = obj;
173 ASSERT(INT_GET(block->bb_level, ARCH_CONVERT) == 0);
174 rp = XFS_BTREE_REC_ADDR(mp->m_sb.sb_blocksize, xfs_alloc, block, idx,
175 XFS_BTREE_BLOCK_MAXRECS(mp->m_sb.sb_blocksize, xfs_alloc, 1));
176 return bitize((int)((char *)rp - (char *)block));
177 }
178
179 int
180 bnobt_size(
181 void *obj,
182 int startoff,
183 int idx)
184 {
185 return bitize(mp->m_sb.sb_blocksize);
186 }