]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/dir.c
Update xfsprogs to latest kernel headers and functions
[thirdparty/xfsprogs-dev.git] / db / dir.c
1 /*
2 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include <xfs/libxfs.h>
20 #include "bit.h"
21 #include "type.h"
22 #include "faddr.h"
23 #include "fprint.h"
24 #include "field.h"
25 #include "dir.h"
26 #include "io.h"
27 #include "init.h"
28
29 static int dir_leaf_entries_count(void *obj, int startoff);
30 static int dir_leaf_hdr_count(void *obj, int startoff);
31 static int dir_leaf_name_count(void *obj, int startoff);
32 static int dir_leaf_namelist_count(void *obj, int startoff);
33 static int dir_leaf_namelist_offset(void *obj, int startoff, int idx);
34 static int dir_node_btree_count(void *obj, int startoff);
35 static int dir_node_hdr_count(void *obj, int startoff);
36
37 const field_t dir_hfld[] = {
38 { "", FLDT_DIR, OI(0), C1, 0, TYP_NONE },
39 { NULL }
40 };
41
42 #define LOFF(f) bitize(offsetof(xfs_dir_leafblock_t, f))
43 #define NOFF(f) bitize(offsetof(xfs_da_intnode_t, f))
44 const field_t dir_flds[] = {
45 { "lhdr", FLDT_DIR_LEAF_HDR, OI(LOFF(hdr)), dir_leaf_hdr_count,
46 FLD_COUNT, TYP_NONE },
47 { "nhdr", FLDT_DIR_NODE_HDR, OI(NOFF(hdr)), dir_node_hdr_count,
48 FLD_COUNT, TYP_NONE },
49 { "entries", FLDT_DIR_LEAF_ENTRY, OI(LOFF(entries)),
50 dir_leaf_entries_count, FLD_ARRAY|FLD_COUNT, TYP_NONE },
51 { "btree", FLDT_DIR_NODE_ENTRY, OI(NOFF(btree)),
52 dir_node_btree_count, FLD_ARRAY|FLD_COUNT, TYP_NONE },
53 { "namelist", FLDT_DIR_LEAF_NAME, dir_leaf_namelist_offset,
54 dir_leaf_namelist_count, FLD_ARRAY|FLD_OFFSET|FLD_COUNT, TYP_NONE },
55 { NULL }
56 };
57
58 #define BOFF(f) bitize(offsetof(xfs_da_blkinfo_t, f))
59 const field_t dir_blkinfo_flds[] = {
60 { "forw", FLDT_DIRBLOCK, OI(BOFF(forw)), C1, 0, TYP_INODATA },
61 { "back", FLDT_DIRBLOCK, OI(BOFF(back)), C1, 0, TYP_INODATA },
62 { "magic", FLDT_UINT16X, OI(BOFF(magic)), C1, 0, TYP_NONE },
63 { "pad", FLDT_UINT16X, OI(BOFF(pad)), C1, FLD_SKIPALL, TYP_NONE },
64 { NULL }
65 };
66
67 #define LEOFF(f) bitize(offsetof(xfs_dir_leaf_entry_t, f))
68 const field_t dir_leaf_entry_flds[] = {
69 { "hashval", FLDT_UINT32X, OI(LEOFF(hashval)), C1, 0, TYP_NONE },
70 { "nameidx", FLDT_UINT16D, OI(LEOFF(nameidx)), C1, 0, TYP_NONE },
71 { "namelen", FLDT_UINT8D, OI(LEOFF(namelen)), C1, 0, TYP_NONE },
72 { "pad2", FLDT_UINT8X, OI(LEOFF(pad2)), C1, FLD_SKIPALL, TYP_NONE },
73 { NULL }
74 };
75
76 #define LHOFF(f) bitize(offsetof(xfs_dir_leaf_hdr_t, f))
77 const field_t dir_leaf_hdr_flds[] = {
78 { "info", FLDT_DIR_BLKINFO, OI(LHOFF(info)), C1, 0, TYP_NONE },
79 { "count", FLDT_UINT16D, OI(LHOFF(count)), C1, 0, TYP_NONE },
80 { "namebytes", FLDT_UINT16D, OI(LHOFF(namebytes)), C1, 0, TYP_NONE },
81 { "firstused", FLDT_UINT16D, OI(LHOFF(firstused)), C1, 0, TYP_NONE },
82 { "holes", FLDT_UINT8D, OI(LHOFF(holes)), C1, 0, TYP_NONE },
83 { "pad1", FLDT_UINT8X, OI(LHOFF(pad1)), C1, FLD_SKIPALL, TYP_NONE },
84 { "freemap", FLDT_DIR_LEAF_MAP, OI(LHOFF(freemap)),
85 CI(XFS_DIR_LEAF_MAPSIZE), FLD_ARRAY, TYP_NONE },
86 { NULL }
87 };
88
89 #define LMOFF(f) bitize(offsetof(xfs_dir_leaf_map_t, f))
90 const field_t dir_leaf_map_flds[] = {
91 { "base", FLDT_UINT16D, OI(LMOFF(base)), C1, 0, TYP_NONE },
92 { "size", FLDT_UINT16D, OI(LMOFF(size)), C1, 0, TYP_NONE },
93 { NULL }
94 };
95
96 #define LNOFF(f) bitize(offsetof(xfs_dir_leaf_name_t, f))
97 const field_t dir_leaf_name_flds[] = {
98 { "inumber", FLDT_DIR_INO, OI(LNOFF(inumber)), C1, 0, TYP_INODE },
99 { "name", FLDT_CHARNS, OI(LNOFF(name)), dir_leaf_name_count, FLD_COUNT,
100 TYP_NONE },
101 { NULL }
102 };
103
104 #define EOFF(f) bitize(offsetof(xfs_da_node_entry_t, f))
105 const field_t dir_node_entry_flds[] = {
106 { "hashval", FLDT_UINT32X, OI(EOFF(hashval)), C1, 0, TYP_NONE },
107 { "before", FLDT_DIRBLOCK, OI(EOFF(before)), C1, 0, TYP_INODATA },
108 { NULL }
109 };
110
111 #define HOFF(f) bitize(offsetof(xfs_da_node_hdr_t, f))
112 const field_t dir_node_hdr_flds[] = {
113 { "info", FLDT_DIR_BLKINFO, OI(HOFF(info)), C1, 0, TYP_NONE },
114 { "count", FLDT_UINT16D, OI(HOFF(count)), C1, 0, TYP_NONE },
115 { "level", FLDT_UINT16D, OI(HOFF(level)), C1, 0, TYP_NONE },
116 { NULL }
117 };
118
119 /*ARGSUSED*/
120 static int
121 dir_leaf_entries_count(
122 void *obj,
123 int startoff)
124 {
125 xfs_dir_leafblock_t *block;
126
127 ASSERT(startoff == 0);
128 block = obj;
129 if (be16_to_cpu(block->hdr.info.magic) != XFS_DIR_LEAF_MAGIC)
130 return 0;
131 return be16_to_cpu(block->hdr.count);
132 }
133
134 /*ARGSUSED*/
135 static int
136 dir_leaf_hdr_count(
137 void *obj,
138 int startoff)
139 {
140 xfs_dir_leafblock_t *block;
141
142 ASSERT(startoff == 0);
143 block = obj;
144 return be16_to_cpu(block->hdr.info.magic) == XFS_DIR_LEAF_MAGIC;
145 }
146
147 static int
148 dir_leaf_name_count(
149 void *obj,
150 int startoff)
151 {
152 xfs_dir_leafblock_t *block;
153 xfs_dir_leaf_entry_t *e;
154 int i;
155 int off;
156
157 ASSERT(bitoffs(startoff) == 0);
158 off = byteize(startoff);
159 block = obj;
160 if (be16_to_cpu(block->hdr.info.magic) != XFS_DIR_LEAF_MAGIC)
161 return 0;
162 for (i = 0; i < be16_to_cpu(block->hdr.count); i++) {
163 e = &block->entries[i];
164 if (be16_to_cpu(e->nameidx) == off)
165 return e->namelen;
166 }
167 return 0;
168 }
169
170 /*ARGSUSED*/
171 int
172 dir_leaf_name_size(
173 void *obj,
174 int startoff,
175 int idx)
176 {
177 xfs_dir_leafblock_t *block;
178 xfs_dir_leaf_entry_t *e;
179
180 ASSERT(startoff == 0);
181 block = obj;
182 if (be16_to_cpu(block->hdr.info.magic) != XFS_DIR_LEAF_MAGIC)
183 return 0;
184 e = &block->entries[idx];
185 return bitize((int)xfs_dir_leaf_entsize_byentry(e));
186 }
187
188 /*ARGSUSED*/
189 static int
190 dir_leaf_namelist_count(
191 void *obj,
192 int startoff)
193 {
194 xfs_dir_leafblock_t *block;
195
196 ASSERT(startoff == 0);
197 block = obj;
198 if (be16_to_cpu(block->hdr.info.magic) != XFS_DIR_LEAF_MAGIC)
199 return 0;
200 return be16_to_cpu(block->hdr.count);
201 }
202
203 /*ARGSUSED*/
204 static int
205 dir_leaf_namelist_offset(
206 void *obj,
207 int startoff,
208 int idx)
209 {
210 xfs_dir_leafblock_t *block;
211 xfs_dir_leaf_entry_t *e;
212
213 ASSERT(startoff == 0);
214 block = obj;
215 e = &block->entries[idx];
216 return bitize(be16_to_cpu(e->nameidx));
217 }
218
219 /*ARGSUSED*/
220 static int
221 dir_node_btree_count(
222 void *obj,
223 int startoff)
224 {
225 xfs_da_intnode_t *block;
226
227 ASSERT(startoff == 0); /* this is a base structure */
228 block = obj;
229 if (be16_to_cpu(block->hdr.info.magic) != XFS_DA_NODE_MAGIC)
230 return 0;
231 return be16_to_cpu(block->hdr.count);
232 }
233
234 /*ARGSUSED*/
235 static int
236 dir_node_hdr_count(
237 void *obj,
238 int startoff)
239 {
240 xfs_da_intnode_t *block;
241
242 ASSERT(startoff == 0);
243 block = obj;
244 return be16_to_cpu(block->hdr.info.magic) == XFS_DA_NODE_MAGIC;
245 }
246
247 /*ARGSUSED*/
248 int
249 dir_size(
250 void *obj,
251 int startoff,
252 int idx)
253 {
254 return bitize(mp->m_sb.sb_blocksize);
255 }