]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - db/attr.c
xfs_db: print structure padding fields consistently
[thirdparty/xfsprogs-dev.git] / db / attr.c
CommitLineData
2bd0ea18 1/*
da23017d
NS
2 * Copyright (c) 2000-2001,2004-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
dfc130f3 4 *
da23017d
NS
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
2bd0ea18 7 * published by the Free Software Foundation.
dfc130f3 8 *
da23017d
NS
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.
dfc130f3 13 *
da23017d
NS
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
2bd0ea18
NS
17 */
18
6b803e5a 19#include "libxfs.h"
2bd0ea18
NS
20#include "bit.h"
21#include "type.h"
22#include "faddr.h"
23#include "fprint.h"
24#include "field.h"
25#include "attr.h"
26#include "io.h"
4ca431fc 27#include "init.h"
2847273f 28#include "output.h"
2bd0ea18
NS
29
30static int attr_leaf_entries_count(void *obj, int startoff);
31static int attr_leaf_hdr_count(void *obj, int startoff);
32static int attr_leaf_name_local_count(void *obj, int startoff);
33static int attr_leaf_name_local_name_count(void *obj, int startoff);
34static int attr_leaf_name_local_value_count(void *obj, int startoff);
35static int attr_leaf_name_local_value_offset(void *obj, int startoff,
36 int idx);
37static int attr_leaf_name_remote_count(void *obj, int startoff);
38static int attr_leaf_name_remote_name_count(void *obj, int startoff);
39static int attr_leaf_nvlist_count(void *obj, int startoff);
40static int attr_leaf_nvlist_offset(void *obj, int startoff, int idx);
41static int attr_node_btree_count(void *obj, int startoff);
42static int attr_node_hdr_count(void *obj, int startoff);
43
29b90b5b
DW
44static int attr_remote_data_count(void *obj, int startoff);
45static int attr3_remote_hdr_count(void *obj, int startoff);
46static int attr3_remote_data_count(void *obj, int startoff);
47
2bd0ea18
NS
48const field_t attr_hfld[] = {
49 { "", FLDT_ATTR, OI(0), C1, 0, TYP_NONE },
50 { NULL }
51};
52
53#define LOFF(f) bitize(offsetof(xfs_attr_leafblock_t, f))
54#define NOFF(f) bitize(offsetof(xfs_da_intnode_t, f))
55const field_t attr_flds[] = {
56 { "hdr", FLDT_ATTR_LEAF_HDR, OI(LOFF(hdr)), attr_leaf_hdr_count,
57 FLD_COUNT, TYP_NONE },
58 { "hdr", FLDT_ATTR_NODE_HDR, OI(NOFF(hdr)), attr_node_hdr_count,
59 FLD_COUNT, TYP_NONE },
29b90b5b
DW
60 { "data", FLDT_CHARNS, OI(0), attr_remote_data_count, FLD_COUNT,
61 TYP_NONE },
2bd0ea18
NS
62 { "entries", FLDT_ATTR_LEAF_ENTRY, OI(LOFF(entries)),
63 attr_leaf_entries_count, FLD_ARRAY|FLD_COUNT, TYP_NONE },
88b32f06 64 { "btree", FLDT_ATTR_NODE_ENTRY, OI(NOFF(__btree)), attr_node_btree_count,
2bd0ea18
NS
65 FLD_ARRAY|FLD_COUNT, TYP_NONE },
66 { "nvlist", FLDT_ATTR_LEAF_NAME, attr_leaf_nvlist_offset,
67 attr_leaf_nvlist_count, FLD_ARRAY|FLD_OFFSET|FLD_COUNT, TYP_NONE },
68 { NULL }
69};
70
71#define BOFF(f) bitize(offsetof(xfs_da_blkinfo_t, f))
72const field_t attr_blkinfo_flds[] = {
73 { "forw", FLDT_ATTRBLOCK, OI(BOFF(forw)), C1, 0, TYP_ATTR },
74 { "back", FLDT_ATTRBLOCK, OI(BOFF(back)), C1, 0, TYP_ATTR },
75 { "magic", FLDT_UINT16X, OI(BOFF(magic)), C1, 0, TYP_NONE },
76 { "pad", FLDT_UINT16X, OI(BOFF(pad)), C1, FLD_SKIPALL, TYP_NONE },
77 { NULL }
78};
79
80#define LEOFF(f) bitize(offsetof(xfs_attr_leaf_entry_t, f))
81const field_t attr_leaf_entry_flds[] = {
82 { "hashval", FLDT_UINT32X, OI(LEOFF(hashval)), C1, 0, TYP_NONE },
83 { "nameidx", FLDT_UINT16D, OI(LEOFF(nameidx)), C1, 0, TYP_NONE },
84 { "flags", FLDT_UINT8X, OI(LEOFF(flags)), C1, FLD_SKIPALL, TYP_NONE },
85 { "incomplete", FLDT_UINT1,
14f8b681 86 OI(LEOFF(flags) + bitsz(uint8_t) - XFS_ATTR_INCOMPLETE_BIT - 1), C1,
2bd0ea18
NS
87 0, TYP_NONE },
88 { "root", FLDT_UINT1,
14f8b681 89 OI(LEOFF(flags) + bitsz(uint8_t) - XFS_ATTR_ROOT_BIT - 1), C1, 0,
2bd0ea18 90 TYP_NONE },
4b0c5771 91 { "secure", FLDT_UINT1,
14f8b681 92 OI(LEOFF(flags) + bitsz(uint8_t) - XFS_ATTR_SECURE_BIT - 1), C1, 0,
4b0c5771 93 TYP_NONE },
2bd0ea18 94 { "local", FLDT_UINT1,
14f8b681 95 OI(LEOFF(flags) + bitsz(uint8_t) - XFS_ATTR_LOCAL_BIT - 1), C1, 0,
2bd0ea18
NS
96 TYP_NONE },
97 { "pad2", FLDT_UINT8X, OI(LEOFF(pad2)), C1, FLD_SKIPALL, TYP_NONE },
98 { NULL }
99};
100
101#define LHOFF(f) bitize(offsetof(xfs_attr_leaf_hdr_t, f))
102const field_t attr_leaf_hdr_flds[] = {
103 { "info", FLDT_ATTR_BLKINFO, OI(LHOFF(info)), C1, 0, TYP_NONE },
104 { "count", FLDT_UINT16D, OI(LHOFF(count)), C1, 0, TYP_NONE },
105 { "usedbytes", FLDT_UINT16D, OI(LHOFF(usedbytes)), C1, 0, TYP_NONE },
106 { "firstused", FLDT_UINT16D, OI(LHOFF(firstused)), C1, 0, TYP_NONE },
107 { "holes", FLDT_UINT8D, OI(LHOFF(holes)), C1, 0, TYP_NONE },
108 { "pad1", FLDT_UINT8X, OI(LHOFF(pad1)), C1, FLD_SKIPALL, TYP_NONE },
109 { "freemap", FLDT_ATTR_LEAF_MAP, OI(LHOFF(freemap)),
110 CI(XFS_ATTR_LEAF_MAPSIZE), FLD_ARRAY, TYP_NONE },
111 { NULL }
112};
113
114#define LMOFF(f) bitize(offsetof(xfs_attr_leaf_map_t, f))
115const field_t attr_leaf_map_flds[] = {
116 { "base", FLDT_UINT16D, OI(LMOFF(base)), C1, 0, TYP_NONE },
117 { "size", FLDT_UINT16D, OI(LMOFF(size)), C1, 0, TYP_NONE },
118 { NULL }
119};
120
121#define LNOFF(f) bitize(offsetof(xfs_attr_leaf_name_local_t, f))
122#define LVOFF(f) bitize(offsetof(xfs_attr_leaf_name_remote_t, f))
123const field_t attr_leaf_name_flds[] = {
124 { "valuelen", FLDT_UINT16D, OI(LNOFF(valuelen)),
125 attr_leaf_name_local_count, FLD_COUNT, TYP_NONE },
126 { "namelen", FLDT_UINT8D, OI(LNOFF(namelen)),
127 attr_leaf_name_local_count, FLD_COUNT, TYP_NONE },
128 { "name", FLDT_CHARNS, OI(LNOFF(nameval)),
129 attr_leaf_name_local_name_count, FLD_COUNT, TYP_NONE },
130 { "value", FLDT_CHARNS, attr_leaf_name_local_value_offset,
131 attr_leaf_name_local_value_count, FLD_COUNT|FLD_OFFSET, TYP_NONE },
132 { "valueblk", FLDT_UINT32X, OI(LVOFF(valueblk)),
133 attr_leaf_name_remote_count, FLD_COUNT, TYP_NONE },
134 { "valuelen", FLDT_UINT32D, OI(LVOFF(valuelen)),
135 attr_leaf_name_remote_count, FLD_COUNT, TYP_NONE },
136 { "namelen", FLDT_UINT8D, OI(LVOFF(namelen)),
137 attr_leaf_name_remote_count, FLD_COUNT, TYP_NONE },
138 { "name", FLDT_CHARNS, OI(LVOFF(name)),
139 attr_leaf_name_remote_name_count, FLD_COUNT, TYP_NONE },
140 { NULL }
141};
142
143#define EOFF(f) bitize(offsetof(xfs_da_node_entry_t, f))
144const field_t attr_node_entry_flds[] = {
145 { "hashval", FLDT_UINT32X, OI(EOFF(hashval)), C1, 0, TYP_NONE },
146 { "before", FLDT_ATTRBLOCK, OI(EOFF(before)), C1, 0, TYP_ATTR },
147 { NULL }
148};
149
150#define HOFF(f) bitize(offsetof(xfs_da_node_hdr_t, f))
151const field_t attr_node_hdr_flds[] = {
152 { "info", FLDT_ATTR_BLKINFO, OI(HOFF(info)), C1, 0, TYP_NONE },
a24374f4 153 { "count", FLDT_UINT16D, OI(HOFF(__count)), C1, 0, TYP_NONE },
88b32f06 154 { "level", FLDT_UINT16D, OI(HOFF(__level)), C1, 0, TYP_NONE },
2bd0ea18
NS
155 { NULL }
156};
157
2bd0ea18
NS
158static int
159attr_leaf_entries_count(
160 void *obj,
161 int startoff)
162{
ad04ef4a 163 struct xfs_attr_leafblock *leaf = obj;
dfc130f3 164
2bd0ea18 165 ASSERT(startoff == 0);
ad04ef4a 166 if (be16_to_cpu(leaf->hdr.info.magic) != XFS_ATTR_LEAF_MAGIC)
2bd0ea18 167 return 0;
ad04ef4a
DC
168 return be16_to_cpu(leaf->hdr.count);
169}
170
171static int
172attr3_leaf_entries_count(
173 void *obj,
174 int startoff)
175{
176 struct xfs_attr3_leafblock *leaf = obj;
177
178 ASSERT(startoff == 0);
e13d0f78 179 if (be16_to_cpu(leaf->hdr.info.hdr.magic) != XFS_ATTR3_LEAF_MAGIC)
ad04ef4a
DC
180 return 0;
181 return be16_to_cpu(leaf->hdr.count);
2bd0ea18
NS
182}
183
2bd0ea18
NS
184static int
185attr_leaf_hdr_count(
186 void *obj,
187 int startoff)
188{
ad04ef4a 189 struct xfs_attr_leafblock *leaf = obj;
dfc130f3 190
2bd0ea18 191 ASSERT(startoff == 0);
ad04ef4a 192 return be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC;
2bd0ea18
NS
193}
194
195static int
ad04ef4a 196attr3_leaf_hdr_count(
2bd0ea18
NS
197 void *obj,
198 int startoff)
199{
ad04ef4a
DC
200 struct xfs_attr3_leafblock *leaf = obj;
201
202 ASSERT(startoff == 0);
203 return be16_to_cpu(leaf->hdr.info.hdr.magic) == XFS_ATTR3_LEAF_MAGIC;
204}
205
29b90b5b
DW
206static int
207attr_remote_data_count(
208 void *obj,
209 int startoff)
210{
211 if (attr_leaf_hdr_count(obj, startoff) == 0 &&
212 attr_node_hdr_count(obj, startoff) == 0)
213 return mp->m_sb.sb_blocksize;
214 return 0;
215}
216
217static int
218attr3_remote_data_count(
219 void *obj,
220 int startoff)
221{
222 struct xfs_attr3_rmt_hdr *hdr = obj;
223 size_t buf_space;
224
225 ASSERT(startoff == 0);
226
227 if (hdr->rm_magic != cpu_to_be32(XFS_ATTR3_RMT_MAGIC))
228 return 0;
229 buf_space = XFS_ATTR3_RMT_BUF_SPACE(mp, mp->m_sb.sb_blocksize);
230 if (be32_to_cpu(hdr->rm_bytes) > buf_space)
231 return buf_space;
232 return be32_to_cpu(hdr->rm_bytes);
233}
234
ad04ef4a
DC
235typedef int (*attr_leaf_entry_walk_f)(struct xfs_attr_leafblock *,
236 struct xfs_attr_leaf_entry *, int);
237static int
238attr_leaf_entry_walk(
239 void *obj,
240 int startoff,
241 attr_leaf_entry_walk_f func)
242{
243 struct xfs_attr_leafblock *leaf = obj;
244 struct xfs_attr3_icleaf_hdr leafhdr;
245 struct xfs_attr_leaf_entry *entries;
246 struct xfs_attr_leaf_entry *e;
247 int i;
248 int off;
2bd0ea18
NS
249
250 ASSERT(bitoffs(startoff) == 0);
ad04ef4a
DC
251 if (be16_to_cpu(leaf->hdr.info.magic) != XFS_ATTR_LEAF_MAGIC &&
252 be16_to_cpu(leaf->hdr.info.magic) != XFS_ATTR3_LEAF_MAGIC)
2bd0ea18 253 return 0;
ad04ef4a
DC
254
255 off = byteize(startoff);
19ebedcf 256 xfs_attr3_leaf_hdr_from_disk(mp->m_attr_geo, &leafhdr, leaf);
ad04ef4a
DC
257 entries = xfs_attr3_leaf_entryp(leaf);
258
259 for (i = 0; i < leafhdr.count; i++) {
260 e = &entries[i];
5e656dbb 261 if (be16_to_cpu(e->nameidx) == off)
ad04ef4a 262 return func(leaf, e, i);
2bd0ea18
NS
263 }
264 return 0;
265}
266
ad04ef4a
DC
267static int
268__attr_leaf_name_local_count(
269 struct xfs_attr_leafblock *leaf,
270 struct xfs_attr_leaf_entry *e,
271 int i)
272{
273 return (e->flags & XFS_ATTR_LOCAL) != 0;
274}
275
276static int
277attr_leaf_name_local_count(
278 void *obj,
279 int startoff)
280{
281 return attr_leaf_entry_walk(obj, startoff,
282 __attr_leaf_name_local_count);
283}
284
285static int
286__attr_leaf_name_local_name_count(
287 struct xfs_attr_leafblock *leaf,
288 struct xfs_attr_leaf_entry *e,
289 int i)
290{
291 struct xfs_attr_leaf_name_local *l;
292
293 if (!(e->flags & XFS_ATTR_LOCAL))
294 return 0;
295
296 l = xfs_attr3_leaf_name_local(leaf, i);
297 return l->namelen;
298}
299
2bd0ea18
NS
300static int
301attr_leaf_name_local_name_count(
302 void *obj,
303 int startoff)
304{
ad04ef4a
DC
305 return attr_leaf_entry_walk(obj, startoff,
306 __attr_leaf_name_local_name_count);
307}
2bd0ea18 308
ad04ef4a
DC
309static int
310__attr_leaf_name_local_value_count(
311 struct xfs_attr_leafblock *leaf,
312 struct xfs_attr_leaf_entry *e,
313 int i)
314{
315 struct xfs_attr_leaf_name_local *l;
316
317 if (!(e->flags & XFS_ATTR_LOCAL))
2bd0ea18 318 return 0;
ad04ef4a
DC
319
320 l = xfs_attr3_leaf_name_local(leaf, i);
321 return be16_to_cpu(l->valuelen);
2bd0ea18
NS
322}
323
324static int
325attr_leaf_name_local_value_count(
326 void *obj,
327 int startoff)
328{
ad04ef4a
DC
329 return attr_leaf_entry_walk(obj, startoff,
330 __attr_leaf_name_local_value_count);
331}
2bd0ea18 332
ad04ef4a
DC
333static int
334__attr_leaf_name_local_value_offset(
335 struct xfs_attr_leafblock *leaf,
336 struct xfs_attr_leaf_entry *e,
337 int i)
338{
339 struct xfs_attr_leaf_name_local *l;
340 char *vp;
341
342 l = xfs_attr3_leaf_name_local(leaf, i);
343 vp = (char *)&l->nameval[l->namelen];
344
345 return (int)bitize(vp - (char *)l);
2bd0ea18
NS
346}
347
2bd0ea18
NS
348static int
349attr_leaf_name_local_value_offset(
350 void *obj,
351 int startoff,
352 int idx)
353{
ad04ef4a
DC
354 return attr_leaf_entry_walk(obj, startoff,
355 __attr_leaf_name_local_value_offset);
356}
dfc130f3 357
ad04ef4a
DC
358static int
359__attr_leaf_name_remote_count(
360 struct xfs_attr_leafblock *leaf,
361 struct xfs_attr_leaf_entry *e,
362 int i)
363{
364 return (e->flags & XFS_ATTR_LOCAL) == 0;
2bd0ea18
NS
365}
366
367static int
368attr_leaf_name_remote_count(
ad04ef4a
DC
369 void *obj,
370 int startoff)
2bd0ea18 371{
ad04ef4a
DC
372 return attr_leaf_entry_walk(obj, startoff,
373 __attr_leaf_name_remote_count);
374}
2bd0ea18 375
ad04ef4a
DC
376static int
377__attr_leaf_name_remote_name_count(
378 struct xfs_attr_leafblock *leaf,
379 struct xfs_attr_leaf_entry *e,
380 int i)
381{
382 struct xfs_attr_leaf_name_remote *r;
383
384 if (e->flags & XFS_ATTR_LOCAL)
2bd0ea18 385 return 0;
ad04ef4a
DC
386
387 r = xfs_attr3_leaf_name_remote(leaf, i);
388 return r->namelen;
2bd0ea18
NS
389}
390
391static int
392attr_leaf_name_remote_name_count(
393 void *obj,
394 int startoff)
395{
ad04ef4a
DC
396 return attr_leaf_entry_walk(obj, startoff,
397 __attr_leaf_name_remote_name_count);
2bd0ea18
NS
398}
399
2bd0ea18
NS
400int
401attr_leaf_name_size(
402 void *obj,
403 int startoff,
404 int idx)
405{
ad04ef4a
DC
406 struct xfs_attr_leafblock *leaf = obj;
407 struct xfs_attr_leaf_entry *e;
408 struct xfs_attr_leaf_name_local *l;
409 struct xfs_attr_leaf_name_remote *r;
2bd0ea18
NS
410
411 ASSERT(startoff == 0);
ad04ef4a
DC
412 if (be16_to_cpu(leaf->hdr.info.magic) != XFS_ATTR_LEAF_MAGIC &&
413 be16_to_cpu(leaf->hdr.info.magic) != XFS_ATTR3_LEAF_MAGIC)
2bd0ea18 414 return 0;
ad04ef4a 415 e = &xfs_attr3_leaf_entryp(leaf)[idx];
5e656dbb 416 if (e->flags & XFS_ATTR_LOCAL) {
ad04ef4a 417 l = xfs_attr3_leaf_name_local(leaf, idx);
56b2de80 418 return (int)bitize(xfs_attr_leaf_entsize_local(l->namelen,
5e656dbb 419 be16_to_cpu(l->valuelen)));
2bd0ea18 420 } else {
ad04ef4a 421 r = xfs_attr3_leaf_name_remote(leaf, idx);
56b2de80 422 return (int)bitize(xfs_attr_leaf_entsize_remote(r->namelen));
2bd0ea18
NS
423 }
424}
425
2bd0ea18
NS
426static int
427attr_leaf_nvlist_count(
428 void *obj,
429 int startoff)
430{
ad04ef4a
DC
431 struct xfs_attr_leafblock *leaf = obj;
432
433 ASSERT(startoff == 0);
434 if (be16_to_cpu(leaf->hdr.info.magic) != XFS_ATTR_LEAF_MAGIC)
435 return 0;
436 return be16_to_cpu(leaf->hdr.count);
437}
438
439static int
440attr3_leaf_nvlist_count(
441 void *obj,
442 int startoff)
443{
444 struct xfs_attr3_leafblock *leaf = obj;
2bd0ea18
NS
445
446 ASSERT(startoff == 0);
ad04ef4a 447 if (be16_to_cpu(leaf->hdr.info.hdr.magic) != XFS_ATTR3_LEAF_MAGIC)
2bd0ea18 448 return 0;
ad04ef4a 449 return be16_to_cpu(leaf->hdr.count);
2bd0ea18
NS
450}
451
2bd0ea18
NS
452static int
453attr_leaf_nvlist_offset(
454 void *obj,
455 int startoff,
456 int idx)
457{
ad04ef4a
DC
458 struct xfs_attr_leafblock *leaf = obj;
459 struct xfs_attr_leaf_entry *e;
2bd0ea18
NS
460
461 ASSERT(startoff == 0);
ad04ef4a 462 e = &xfs_attr3_leaf_entryp(leaf)[idx];
5e656dbb 463 return bitize(be16_to_cpu(e->nameidx));
2bd0ea18
NS
464}
465
2bd0ea18
NS
466static int
467attr_node_btree_count(
468 void *obj,
469 int startoff)
470{
ad04ef4a 471 struct xfs_da_intnode *node = obj;
2bd0ea18
NS
472
473 ASSERT(startoff == 0); /* this is a base structure */
ad04ef4a 474 if (be16_to_cpu(node->hdr.info.magic) != XFS_DA_NODE_MAGIC)
2bd0ea18 475 return 0;
ad04ef4a 476 return be16_to_cpu(node->hdr.__count);
2bd0ea18
NS
477}
478
ad04ef4a
DC
479static int
480attr3_node_btree_count(
481 void *obj,
482 int startoff)
483{
484 struct xfs_da3_intnode *node = obj;
485
486 ASSERT(startoff == 0);
487 if (be16_to_cpu(node->hdr.info.hdr.magic) != XFS_DA3_NODE_MAGIC)
488 return 0;
489 return be16_to_cpu(node->hdr.__count);
490}
491
492
2bd0ea18
NS
493static int
494attr_node_hdr_count(
495 void *obj,
496 int startoff)
497{
ad04ef4a 498 struct xfs_da_intnode *node = obj;
dfc130f3 499
2bd0ea18 500 ASSERT(startoff == 0);
ad04ef4a
DC
501 return be16_to_cpu(node->hdr.info.magic) == XFS_DA_NODE_MAGIC;
502}
503
504static int
505attr3_node_hdr_count(
506 void *obj,
507 int startoff)
508{
509 struct xfs_da3_intnode *node = obj;
510
511 ASSERT(startoff == 0);
512 return be16_to_cpu(node->hdr.info.hdr.magic) == XFS_DA3_NODE_MAGIC;
2bd0ea18
NS
513}
514
29b90b5b
DW
515static int
516attr3_remote_hdr_count(
517 void *obj,
518 int startoff)
519{
520 struct xfs_attr3_rmt_hdr *node = obj;
521
522 ASSERT(startoff == 0);
523 return be32_to_cpu(node->rm_magic) == XFS_ATTR3_RMT_MAGIC;
524}
525
2bd0ea18
NS
526int
527attr_size(
528 void *obj,
529 int startoff,
530 int idx)
531{
532 return bitize(mp->m_sb.sb_blocksize);
533}
ad04ef4a
DC
534
535/*
536 * CRC enabled attribute block field definitions
537 */
538const field_t attr3_hfld[] = {
539 { "", FLDT_ATTR3, OI(0), C1, 0, TYP_NONE },
540 { NULL }
541};
542
543#define L3OFF(f) bitize(offsetof(struct xfs_attr3_leafblock, f))
544#define N3OFF(f) bitize(offsetof(struct xfs_da3_intnode, f))
545const field_t attr3_flds[] = {
546 { "hdr", FLDT_ATTR3_LEAF_HDR, OI(L3OFF(hdr)), attr3_leaf_hdr_count,
547 FLD_COUNT, TYP_NONE },
73a423b1 548 { "hdr", FLDT_ATTR3_NODE_HDR, OI(N3OFF(hdr)), attr3_node_hdr_count,
ad04ef4a 549 FLD_COUNT, TYP_NONE },
29b90b5b
DW
550 { "hdr", FLDT_ATTR3_REMOTE_HDR, OI(0), attr3_remote_hdr_count,
551 FLD_COUNT, TYP_NONE },
552 { "data", FLDT_CHARNS, OI(bitize(sizeof(struct xfs_attr3_rmt_hdr))),
553 attr3_remote_data_count, FLD_COUNT, TYP_NONE },
ad04ef4a
DC
554 { "entries", FLDT_ATTR_LEAF_ENTRY, OI(L3OFF(entries)),
555 attr3_leaf_entries_count, FLD_ARRAY|FLD_COUNT, TYP_NONE },
556 { "btree", FLDT_ATTR_NODE_ENTRY, OI(N3OFF(__btree)),
557 attr3_node_btree_count, FLD_ARRAY|FLD_COUNT, TYP_NONE },
558 { "nvlist", FLDT_ATTR_LEAF_NAME, attr_leaf_nvlist_offset,
559 attr3_leaf_nvlist_count, FLD_ARRAY|FLD_OFFSET|FLD_COUNT, TYP_NONE },
560 { NULL }
561};
562
563#define LH3OFF(f) bitize(offsetof(struct xfs_attr3_leaf_hdr, f))
564const field_t attr3_leaf_hdr_flds[] = {
73a423b1 565 { "info", FLDT_ATTR3_BLKINFO, OI(LH3OFF(info)), C1, 0, TYP_NONE },
ad04ef4a
DC
566 { "count", FLDT_UINT16D, OI(LH3OFF(count)), C1, 0, TYP_NONE },
567 { "usedbytes", FLDT_UINT16D, OI(LH3OFF(usedbytes)), C1, 0, TYP_NONE },
568 { "firstused", FLDT_UINT16D, OI(LH3OFF(firstused)), C1, 0, TYP_NONE },
569 { "holes", FLDT_UINT8D, OI(LH3OFF(holes)), C1, 0, TYP_NONE },
570 { "pad1", FLDT_UINT8X, OI(LH3OFF(pad1)), C1, FLD_SKIPALL, TYP_NONE },
571 { "freemap", FLDT_ATTR_LEAF_MAP, OI(LH3OFF(freemap)),
572 CI(XFS_ATTR_LEAF_MAPSIZE), FLD_ARRAY, TYP_NONE },
573 { NULL }
574};
575
73a423b1
DW
576#define B3OFF(f) bitize(offsetof(struct xfs_da3_blkinfo, f))
577const field_t attr3_blkinfo_flds[] = {
578 { "hdr", FLDT_ATTR_BLKINFO, OI(B3OFF(hdr)), C1, 0, TYP_NONE },
579 { "crc", FLDT_CRC, OI(B3OFF(crc)), C1, 0, TYP_NONE },
580 { "bno", FLDT_DFSBNO, OI(B3OFF(blkno)), C1, 0, TYP_BMAPBTD },
581 { "lsn", FLDT_UINT64X, OI(B3OFF(lsn)), C1, 0, TYP_NONE },
582 { "uuid", FLDT_UUID, OI(B3OFF(uuid)), C1, 0, TYP_NONE },
583 { "owner", FLDT_INO, OI(B3OFF(owner)), C1, 0, TYP_NONE },
584 { NULL }
585};
586
587#define H3OFF(f) bitize(offsetof(struct xfs_da3_node_hdr, f))
588const field_t attr3_node_hdr_flds[] = {
589 { "info", FLDT_ATTR3_BLKINFO, OI(H3OFF(info)), C1, 0, TYP_NONE },
590 { "count", FLDT_UINT16D, OI(H3OFF(__count)), C1, 0, TYP_NONE },
591 { "level", FLDT_UINT16D, OI(H3OFF(__level)), C1, 0, TYP_NONE },
31df6ad1 592 { "pad", FLDT_UINT32X, OI(H3OFF(__pad32)), C1, FLD_SKIPALL, TYP_NONE },
73a423b1
DW
593 { NULL }
594};
595
29b90b5b
DW
596#define RM3OFF(f) bitize(offsetof(struct xfs_attr3_rmt_hdr, rm_ ## f))
597const struct field attr3_remote_crc_flds[] = {
598 { "magic", FLDT_UINT32X, OI(RM3OFF(magic)), C1, 0, TYP_NONE },
599 { "offset", FLDT_UINT32D, OI(RM3OFF(offset)), C1, 0, TYP_NONE },
600 { "bytes", FLDT_UINT32D, OI(RM3OFF(bytes)), C1, 0, TYP_NONE },
601 { "crc", FLDT_CRC, OI(RM3OFF(crc)), C1, 0, TYP_NONE },
602 { "uuid", FLDT_UUID, OI(RM3OFF(uuid)), C1, 0, TYP_NONE },
603 { "owner", FLDT_INO, OI(RM3OFF(owner)), C1, 0, TYP_NONE },
604 { "bno", FLDT_DFSBNO, OI(RM3OFF(blkno)), C1, 0, TYP_BMAPBTD },
605 { "lsn", FLDT_UINT64X, OI(RM3OFF(lsn)), C1, 0, TYP_NONE },
606 { NULL }
607};
608
89baf918
DW
609/* Set the CRC. */
610void
611xfs_attr3_set_crc(
612 struct xfs_buf *bp)
613{
614 __be32 magic32;
615 __be16 magic16;
616
617 magic32 = *(__be32 *)bp->b_addr;
618 magic16 = ((struct xfs_da_blkinfo *)bp->b_addr)->magic;
619
620 switch (magic16) {
621 case cpu_to_be16(XFS_ATTR3_LEAF_MAGIC):
622 xfs_buf_update_cksum(bp, XFS_ATTR3_LEAF_CRC_OFF);
623 return;
624 case cpu_to_be16(XFS_DA3_NODE_MAGIC):
625 xfs_buf_update_cksum(bp, XFS_DA3_NODE_CRC_OFF);
626 return;
627 default:
628 break;
629 }
630
631 switch (magic32) {
632 case cpu_to_be32(XFS_ATTR3_RMT_MAGIC):
633 xfs_buf_update_cksum(bp, XFS_ATTR3_RMT_CRC_OFF);
634 return;
635 default:
636 dbprintf(_("Unknown attribute buffer type!\n"));
637 break;
638 }
639}
640
2847273f
DC
641/*
642 * Special read verifier for attribute buffers. Detect the magic number
643 * appropriately and set the correct verifier and call it.
644 */
645static void
646xfs_attr3_db_read_verify(
647 struct xfs_buf *bp)
648{
649 __be32 magic32;
650 __be16 magic16;
651
652 magic32 = *(__be32 *)bp->b_addr;
653 magic16 = ((struct xfs_da_blkinfo *)bp->b_addr)->magic;
654
655 switch (magic16) {
656 case cpu_to_be16(XFS_ATTR3_LEAF_MAGIC):
657 bp->b_ops = &xfs_attr3_leaf_buf_ops;
658 goto verify;
659 case cpu_to_be16(XFS_DA3_NODE_MAGIC):
660 bp->b_ops = &xfs_da3_node_buf_ops;
661 goto verify;
662 default:
663 break;
664 }
665
666 switch (magic32) {
667 case cpu_to_be32(XFS_ATTR3_RMT_MAGIC):
668 bp->b_ops = &xfs_attr3_rmt_buf_ops;
669 break;
670 default:
671 dbprintf(_("Unknown attribute buffer type!\n"));
66fc04e0 672 xfs_buf_ioerror(bp, -EFSCORRUPTED);
2847273f
DC
673 return;
674 }
675verify:
676 bp->b_ops->verify_read(bp);
677}
678
679static void
680xfs_attr3_db_write_verify(
681 struct xfs_buf *bp)
682{
683 dbprintf(_("Writing unknown attribute buffer type!\n"));
66fc04e0 684 xfs_buf_ioerror(bp, -EFSCORRUPTED);
2847273f
DC
685}
686
687const struct xfs_buf_ops xfs_attr3_db_buf_ops = {
a3fac935 688 .name = "xfs_attr3",
2847273f
DC
689 .verify_read = xfs_attr3_db_read_verify,
690 .verify_write = xfs_attr3_db_write_verify,
691};