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

« back to all changes in this revision

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