]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/inobt.c
Merge whitespace changes over
[thirdparty/xfsprogs-dev.git] / db / inobt.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 "inobt.h"
39 #include "print.h"
40 #include "bit.h"
41 #include "init.h"
42
43 static int inobt_key_count(void *obj, int startoff);
44 static int inobt_key_offset(void *obj, int startoff, int idx);
45 static int inobt_ptr_count(void *obj, int startoff);
46 static int inobt_ptr_offset(void *obj, int startoff, int idx);
47 static int inobt_rec_count(void *obj, int startoff);
48 static int inobt_rec_offset(void *obj, int startoff, int idx);
49
50 const field_t inobt_hfld[] = {
51 { "", FLDT_INOBT, OI(0), C1, 0, TYP_NONE },
52 { NULL }
53 };
54
55 #define OFF(f) bitize(offsetof(xfs_inobt_block_t, bb_ ## f))
56 const field_t inobt_flds[] = {
57 { "magic", FLDT_UINT32X, OI(OFF(magic)), C1, 0, TYP_NONE },
58 { "level", FLDT_UINT16D, OI(OFF(level)), C1, 0, TYP_NONE },
59 { "numrecs", FLDT_UINT16D, OI(OFF(numrecs)), C1, 0, TYP_NONE },
60 { "leftsib", FLDT_AGBLOCK, OI(OFF(leftsib)), C1, 0, TYP_INOBT },
61 { "rightsib", FLDT_AGBLOCK, OI(OFF(rightsib)), C1, 0, TYP_INOBT },
62 { "recs", FLDT_INOBTREC, inobt_rec_offset, inobt_rec_count,
63 FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE },
64 { "keys", FLDT_INOBTKEY, inobt_key_offset, inobt_key_count,
65 FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE },
66 { "ptrs", FLDT_INOBTPTR, inobt_ptr_offset, inobt_ptr_count,
67 FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_INOBT },
68 { NULL }
69 };
70
71 #define KOFF(f) bitize(offsetof(xfs_inobt_key_t, ir_ ## f))
72 const field_t inobt_key_flds[] = {
73 { "startino", FLDT_AGINO, OI(KOFF(startino)), C1, 0, TYP_INODE },
74 { NULL }
75 };
76
77 #define ROFF(f) bitize(offsetof(xfs_inobt_rec_t, ir_ ## f))
78 const field_t inobt_rec_flds[] = {
79 { "startino", FLDT_AGINO, OI(ROFF(startino)), C1, 0, TYP_INODE },
80 { "freecount", FLDT_INT32D, OI(ROFF(freecount)), C1, 0, TYP_NONE },
81 { "free", FLDT_INOFREE, OI(ROFF(free)), C1, 0, TYP_NONE },
82 { NULL }
83 };
84
85 /*ARGSUSED*/
86 static int
87 inobt_key_count(
88 void *obj,
89 int startoff)
90 {
91 xfs_inobt_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 /*ARGSUSED*/
101 static int
102 inobt_key_offset(
103 void *obj,
104 int startoff,
105 int idx)
106 {
107 xfs_inobt_block_t *block;
108 xfs_inobt_key_t *kp;
109
110 ASSERT(startoff == 0);
111 block = obj;
112 ASSERT(INT_GET(block->bb_level, ARCH_CONVERT) > 0);
113 kp = XFS_BTREE_KEY_ADDR(mp->m_sb.sb_blocksize, xfs_inobt, block, idx,
114 XFS_BTREE_BLOCK_MAXRECS(mp->m_sb.sb_blocksize, xfs_inobt, 0));
115 return bitize((int)((char *)kp - (char *)block));
116 }
117
118 /*ARGSUSED*/
119 static int
120 inobt_ptr_count(
121 void *obj,
122 int startoff)
123 {
124 xfs_inobt_block_t *block;
125
126 ASSERT(startoff == 0);
127 block = obj;
128 if (INT_GET(block->bb_level, ARCH_CONVERT) == 0)
129 return 0;
130 return INT_GET(block->bb_numrecs, ARCH_CONVERT);
131 }
132
133 /*ARGSUSED*/
134 static int
135 inobt_ptr_offset(
136 void *obj,
137 int startoff,
138 int idx)
139 {
140 xfs_inobt_block_t *block;
141 xfs_inobt_ptr_t *pp;
142
143 ASSERT(startoff == 0);
144 block = obj;
145 ASSERT(INT_GET(block->bb_level, ARCH_CONVERT) > 0);
146 pp = XFS_BTREE_PTR_ADDR(mp->m_sb.sb_blocksize, xfs_inobt, block, idx,
147 XFS_BTREE_BLOCK_MAXRECS(mp->m_sb.sb_blocksize, xfs_inobt, 0));
148 return bitize((int)((char *)pp - (char *)block));
149 }
150
151 /*ARGSUSED*/
152 static int
153 inobt_rec_count(
154 void *obj,
155 int startoff)
156 {
157 xfs_inobt_block_t *block;
158
159 ASSERT(startoff == 0);
160 block = obj;
161 if (INT_GET(block->bb_level, ARCH_CONVERT) > 0)
162 return 0;
163 return INT_GET(block->bb_numrecs, ARCH_CONVERT);
164 }
165
166 /*ARGSUSED*/
167 static int
168 inobt_rec_offset(
169 void *obj,
170 int startoff,
171 int idx)
172 {
173 xfs_inobt_block_t *block;
174 xfs_inobt_rec_t *rp;
175
176 ASSERT(startoff == 0);
177 block = obj;
178 ASSERT(INT_GET(block->bb_level, ARCH_CONVERT) == 0);
179 rp = XFS_BTREE_REC_ADDR(mp->m_sb.sb_blocksize, xfs_inobt, block, idx,
180 XFS_BTREE_BLOCK_MAXRECS(mp->m_sb.sb_blocksize, xfs_inobt, 1));
181 return bitize((int)((char *)rp - (char *)block));
182 }
183
184 /*ARGSUSED*/
185 int
186 inobt_size(
187 void *obj,
188 int startoff,
189 int idx)
190 {
191 return bitize(mp->m_sb.sb_blocksize);
192 }