~ubuntu-branches/ubuntu/utopic/xfsprogs/utopic-proposed

« back to all changes in this revision

Viewing changes to db/bmapbt.c

  • Committer: Bazaar Package Importer
  • Author(s): Nathan Scott
  • Date: 2002-04-13 09:45:06 UTC
  • Revision ID: james.westby@ubuntu.com-20020413094506-t8dhemv41gkeg4kx
Tags: 2.0.3-1
New upstream bugfix release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "bmapbt.h"
 
40
#include "print.h"
 
41
#include "bit.h"
 
42
#include "mount.h"
 
43
 
 
44
static int      bmapbta_key_count(void *obj, int startoff);
 
45
static int      bmapbta_key_offset(void *obj, int startoff, int idx);
 
46
static int      bmapbta_ptr_count(void *obj, int startoff);
 
47
static int      bmapbta_ptr_offset(void *obj, int startoff, int idx);
 
48
static int      bmapbta_rec_count(void *obj, int startoff);
 
49
static int      bmapbta_rec_offset(void *obj, int startoff, int idx);
 
50
static int      bmapbtd_key_count(void *obj, int startoff);
 
51
static int      bmapbtd_key_offset(void *obj, int startoff, int idx);
 
52
static int      bmapbtd_ptr_count(void *obj, int startoff);
 
53
static int      bmapbtd_ptr_offset(void *obj, int startoff, int idx);
 
54
static int      bmapbtd_rec_count(void *obj, int startoff);
 
55
static int      bmapbtd_rec_offset(void *obj, int startoff, int idx);
 
56
 
 
57
const field_t   bmapbta_hfld[] = {
 
58
        { "", FLDT_BMAPBTA, OI(0), C1, 0, TYP_NONE },
 
59
        { NULL }
 
60
};
 
61
const field_t   bmapbtd_hfld[] = {
 
62
        { "", FLDT_BMAPBTD, OI(0), C1, 0, TYP_NONE },
 
63
        { NULL }
 
64
};
 
65
 
 
66
#define OFF(f)  bitize(offsetof(xfs_bmbt_block_t, bb_ ## f))
 
67
const field_t   bmapbta_flds[] = {
 
68
        { "magic", FLDT_UINT32X, OI(OFF(magic)), C1, 0, TYP_NONE },
 
69
        { "level", FLDT_UINT16D, OI(OFF(level)), C1, 0, TYP_NONE },
 
70
        { "numrecs", FLDT_UINT16D, OI(OFF(numrecs)), C1, 0, TYP_NONE },
 
71
        { "leftsib", FLDT_DFSBNO, OI(OFF(leftsib)), C1, 0, TYP_BMAPBTA },
 
72
        { "rightsib", FLDT_DFSBNO, OI(OFF(rightsib)), C1, 0, TYP_BMAPBTA },
 
73
        { "recs", FLDT_BMAPBTAREC, bmapbta_rec_offset, bmapbta_rec_count,
 
74
          FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE },
 
75
        { "keys", FLDT_BMAPBTAKEY, bmapbta_key_offset, bmapbta_key_count,
 
76
          FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE },
 
77
        { "ptrs", FLDT_BMAPBTAPTR, bmapbta_ptr_offset, bmapbta_ptr_count,
 
78
          FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_BMAPBTA },
 
79
        { NULL }
 
80
};
 
81
const field_t   bmapbtd_flds[] = {
 
82
        { "magic", FLDT_UINT32X, OI(OFF(magic)), C1, 0, TYP_NONE },
 
83
        { "level", FLDT_UINT16D, OI(OFF(level)), C1, 0, TYP_NONE },
 
84
        { "numrecs", FLDT_UINT16D, OI(OFF(numrecs)), C1, 0, TYP_NONE },
 
85
        { "leftsib", FLDT_DFSBNO, OI(OFF(leftsib)), C1, 0, TYP_BMAPBTD },
 
86
        { "rightsib", FLDT_DFSBNO, OI(OFF(rightsib)), C1, 0, TYP_BMAPBTD },
 
87
        { "recs", FLDT_BMAPBTDREC, bmapbtd_rec_offset, bmapbtd_rec_count,
 
88
          FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE },
 
89
        { "keys", FLDT_BMAPBTDKEY, bmapbtd_key_offset, bmapbtd_key_count,
 
90
          FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_NONE },
 
91
        { "ptrs", FLDT_BMAPBTDPTR, bmapbtd_ptr_offset, bmapbtd_ptr_count,
 
92
          FLD_ARRAY|FLD_ABASE1|FLD_COUNT|FLD_OFFSET, TYP_BMAPBTD },
 
93
        { NULL }
 
94
};
 
95
 
 
96
#define KOFF(f) bitize(offsetof(xfs_bmbt_key_t, br_ ## f))
 
97
const field_t   bmapbta_key_flds[] = {
 
98
        { "startoff", FLDT_DFILOFFA, OI(KOFF(startoff)), C1, 0, TYP_ATTR },
 
99
        { NULL }
 
100
};
 
101
const field_t   bmapbtd_key_flds[] = {
 
102
        { "startoff", FLDT_DFILOFFD, OI(KOFF(startoff)), C1, 0, TYP_INODATA },
 
103
        { NULL }
 
104
};
 
105
 
 
106
const field_t   bmapbta_rec_flds[] = {
 
107
        { "startoff", FLDT_CFILEOFFA, OI(BMBT_STARTOFF_BITOFF), C1, 0,
 
108
          TYP_ATTR },
 
109
        { "startblock", FLDT_CFSBLOCK, OI(BMBT_STARTBLOCK_BITOFF), C1, 0,
 
110
          TYP_ATTR },
 
111
        { "blockcount", FLDT_CEXTLEN, OI(BMBT_BLOCKCOUNT_BITOFF), C1, 0,
 
112
          TYP_NONE },
 
113
        { "extentflag", FLDT_CEXTFLG, OI(BMBT_EXNTFLAG_BITOFF), C1, 0,
 
114
          TYP_NONE },
 
115
        { NULL }
 
116
};
 
117
const field_t   bmapbtd_rec_flds[] = {
 
118
        { "startoff", FLDT_CFILEOFFD, OI(BMBT_STARTOFF_BITOFF), C1, 0,
 
119
          TYP_INODATA },
 
120
        { "startblock", FLDT_CFSBLOCK, OI(BMBT_STARTBLOCK_BITOFF), C1, 0,
 
121
          TYP_INODATA },
 
122
        { "blockcount", FLDT_CEXTLEN, OI(BMBT_BLOCKCOUNT_BITOFF), C1, 0,
 
123
          TYP_NONE },
 
124
        { "extentflag", FLDT_CEXTFLG, OI(BMBT_EXNTFLAG_BITOFF), C1, 0,
 
125
          TYP_NONE },
 
126
        { NULL }
 
127
};
 
128
 
 
129
static int
 
130
bmapbta_key_count(
 
131
        void                    *obj,
 
132
        int                     startoff)
 
133
{
 
134
        xfs_bmbt_block_t        *block;
 
135
 
 
136
        ASSERT(startoff == 0);
 
137
        block = obj;
 
138
        if (INT_GET(block->bb_level, ARCH_CONVERT) == 0)
 
139
                return 0;
 
140
        return INT_GET(block->bb_numrecs, ARCH_CONVERT);
 
141
}
 
142
 
 
143
static int
 
144
bmapbta_key_offset(
 
145
        void                    *obj,
 
146
        int                     startoff,
 
147
        int                     idx)
 
148
{
 
149
        xfs_bmbt_block_t        *block;
 
150
        xfs_bmbt_key_t          *kp;
 
151
 
 
152
        ASSERT(startoff == 0);
 
153
        block = obj;
 
154
        ASSERT(INT_GET(block->bb_level, ARCH_CONVERT) > 0);
 
155
        kp = XFS_BTREE_KEY_ADDR(mp->m_sb.sb_blocksize, xfs_bmbt, block, idx,
 
156
                XFS_BTREE_BLOCK_MAXRECS(mp->m_sb.sb_blocksize, xfs_bmbt, 0));
 
157
        return bitize((int)((char *)kp - (char *)block));
 
158
}
 
159
 
 
160
static int
 
161
bmapbta_ptr_count(
 
162
        void                    *obj,
 
163
        int                     startoff)
 
164
{
 
165
        xfs_bmbt_block_t        *block;
 
166
 
 
167
        ASSERT(startoff == 0);
 
168
        block = obj;
 
169
        if (INT_GET(block->bb_level, ARCH_CONVERT) == 0)
 
170
                return 0;
 
171
        return INT_GET(block->bb_numrecs, ARCH_CONVERT);
 
172
}
 
173
 
 
174
static int
 
175
bmapbta_ptr_offset(
 
176
        void                    *obj,
 
177
        int                     startoff,
 
178
        int                     idx)
 
179
{
 
180
        xfs_bmbt_block_t        *block;
 
181
        xfs_bmbt_ptr_t          *pp;
 
182
 
 
183
        ASSERT(startoff == 0);
 
184
        block = obj;
 
185
        ASSERT(INT_GET(block->bb_level, ARCH_CONVERT) > 0);
 
186
        pp = XFS_BTREE_PTR_ADDR(mp->m_sb.sb_blocksize, xfs_bmbt, block, idx,
 
187
                XFS_BTREE_BLOCK_MAXRECS(mp->m_sb.sb_blocksize, xfs_bmbt, 0));
 
188
        return bitize((int)((char *)pp - (char *)block));
 
189
}
 
190
 
 
191
static int
 
192
bmapbta_rec_count(
 
193
        void                    *obj,
 
194
        int                     startoff)
 
195
{
 
196
        xfs_bmbt_block_t        *block;
 
197
 
 
198
        ASSERT(startoff == 0);
 
199
        block = obj;
 
200
        if (INT_GET(block->bb_level, ARCH_CONVERT) > 0)
 
201
                return 0;
 
202
        return INT_GET(block->bb_numrecs, ARCH_CONVERT);
 
203
}
 
204
 
 
205
static int
 
206
bmapbta_rec_offset(
 
207
        void                    *obj,
 
208
        int                     startoff,
 
209
        int                     idx)
 
210
{
 
211
        xfs_bmbt_block_t        *block;
 
212
        xfs_bmbt_rec_t          *rp;
 
213
 
 
214
        ASSERT(startoff == 0);
 
215
        block = obj;
 
216
        ASSERT(INT_GET(block->bb_level, ARCH_CONVERT) == 0);
 
217
        rp = XFS_BTREE_REC_ADDR(mp->m_sb.sb_blocksize, xfs_bmbt, block, idx,
 
218
                XFS_BTREE_BLOCK_MAXRECS(mp->m_sb.sb_blocksize, xfs_bmbt, 1));
 
219
        return bitize((int)((char *)rp - (char *)block));
 
220
}
 
221
 
 
222
int
 
223
bmapbta_size(
 
224
        void    *obj,
 
225
        int     startoff,
 
226
        int     idx)
 
227
{
 
228
        return bitize(mp->m_sb.sb_blocksize);
 
229
}
 
230
 
 
231
static int
 
232
bmapbtd_key_count(
 
233
        void                    *obj,
 
234
        int                     startoff)
 
235
{
 
236
        xfs_bmbt_block_t        *block;
 
237
 
 
238
        ASSERT(startoff == 0);
 
239
        block = obj;
 
240
        if (INT_GET(block->bb_level, ARCH_CONVERT) == 0)
 
241
                return 0;
 
242
        return INT_GET(block->bb_numrecs, ARCH_CONVERT);
 
243
}
 
244
 
 
245
static int
 
246
bmapbtd_key_offset(
 
247
        void                    *obj,
 
248
        int                     startoff,
 
249
        int                     idx)
 
250
{
 
251
        xfs_bmbt_block_t        *block;
 
252
        xfs_bmbt_key_t          *kp;
 
253
 
 
254
        ASSERT(startoff == 0);
 
255
        block = obj;
 
256
        ASSERT(INT_GET(block->bb_level, ARCH_CONVERT) > 0);
 
257
        kp = XFS_BTREE_KEY_ADDR(mp->m_sb.sb_blocksize, xfs_bmbt, block, idx,
 
258
                XFS_BTREE_BLOCK_MAXRECS(mp->m_sb.sb_blocksize, xfs_bmbt, 0));
 
259
        return bitize((int)((char *)kp - (char *)block));
 
260
}
 
261
 
 
262
static int
 
263
bmapbtd_ptr_count(
 
264
        void                    *obj,
 
265
        int                     startoff)
 
266
{
 
267
        xfs_bmbt_block_t        *block;
 
268
 
 
269
        ASSERT(startoff == 0);
 
270
        block = obj;
 
271
        if (INT_GET(block->bb_level, ARCH_CONVERT) == 0)
 
272
                return 0;
 
273
        return INT_GET(block->bb_numrecs, ARCH_CONVERT);
 
274
}
 
275
 
 
276
static int
 
277
bmapbtd_ptr_offset(
 
278
        void                    *obj,
 
279
        int                     startoff,
 
280
        int                     idx)
 
281
{
 
282
        xfs_bmbt_block_t        *block;
 
283
        xfs_bmbt_ptr_t          *pp;
 
284
 
 
285
        ASSERT(startoff == 0);
 
286
        block = obj;
 
287
        ASSERT(INT_GET(block->bb_level, ARCH_CONVERT) > 0);
 
288
        pp = XFS_BTREE_PTR_ADDR(mp->m_sb.sb_blocksize, xfs_bmbt, block, idx,
 
289
                XFS_BTREE_BLOCK_MAXRECS(mp->m_sb.sb_blocksize, xfs_bmbt, 0));
 
290
        return bitize((int)((char *)pp - (char *)block));
 
291
}
 
292
 
 
293
static int
 
294
bmapbtd_rec_count(
 
295
        void                    *obj,
 
296
        int                     startoff)
 
297
{
 
298
        xfs_bmbt_block_t        *block;
 
299
 
 
300
        ASSERT(startoff == 0);
 
301
        block = obj;
 
302
        if (INT_GET(block->bb_level, ARCH_CONVERT) > 0)
 
303
                return 0;
 
304
        return INT_GET(block->bb_numrecs, ARCH_CONVERT);
 
305
}
 
306
 
 
307
static int
 
308
bmapbtd_rec_offset(
 
309
        void                    *obj,
 
310
        int                     startoff,
 
311
        int                     idx)
 
312
{
 
313
        xfs_bmbt_block_t        *block;
 
314
        xfs_bmbt_rec_t          *rp;
 
315
 
 
316
        ASSERT(startoff == 0);
 
317
        block = obj;
 
318
        ASSERT(INT_GET(block->bb_level, ARCH_CONVERT) == 0);
 
319
        rp = XFS_BTREE_REC_ADDR(mp->m_sb.sb_blocksize, xfs_bmbt, block, idx,
 
320
                XFS_BTREE_BLOCK_MAXRECS(mp->m_sb.sb_blocksize, xfs_bmbt, 1));
 
321
        return bitize((int)((char *)rp - (char *)block));
 
322
}
 
323
 
 
324
int
 
325
bmapbtd_size(
 
326
        void    *obj,
 
327
        int     startoff,
 
328
        int     idx)
 
329
{
 
330
        return bitize(mp->m_sb.sb_blocksize);
 
331
}