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