]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/attr.c
xfs_db: fix crash when field list selector string has trailing slash
[thirdparty/xfsprogs-dev.git] / db / attr.c
1 /*
2 * Copyright (c) 2000-2001,2004-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 "libxfs.h"
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"
27 #include "init.h"
28 #include "output.h"
29
30 static int attr_leaf_entries_count(void *obj, int startoff);
31 static int attr_leaf_hdr_count(void *obj, int startoff);
32 static int attr_leaf_name_local_count(void *obj, int startoff);
33 static int attr_leaf_name_local_name_count(void *obj, int startoff);
34 static int attr_leaf_name_local_value_count(void *obj, int startoff);
35 static int attr_leaf_name_local_value_offset(void *obj, int startoff,
36 int idx);
37 static int attr_leaf_name_remote_count(void *obj, int startoff);
38 static int attr_leaf_name_remote_name_count(void *obj, int startoff);
39 static int attr_leaf_nvlist_count(void *obj, int startoff);
40 static int attr_leaf_nvlist_offset(void *obj, int startoff, int idx);
41 static int attr_node_btree_count(void *obj, int startoff);
42 static int attr_node_hdr_count(void *obj, int startoff);
43
44 static int attr_remote_data_count(void *obj, int startoff);
45 static int attr3_remote_hdr_count(void *obj, int startoff);
46 static int attr3_remote_data_count(void *obj, int startoff);
47
48 const 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))
55 const 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 },
60 { "data", FLDT_CHARNS, OI(0), attr_remote_data_count, FLD_COUNT,
61 TYP_NONE },
62 { "entries", FLDT_ATTR_LEAF_ENTRY, OI(LOFF(entries)),
63 attr_leaf_entries_count, FLD_ARRAY|FLD_COUNT, TYP_NONE },
64 { "btree", FLDT_ATTR_NODE_ENTRY, OI(NOFF(__btree)), attr_node_btree_count,
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))
72 const 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))
81 const 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,
86 OI(LEOFF(flags) + bitsz(uint8_t) - XFS_ATTR_INCOMPLETE_BIT - 1), C1,
87 0, TYP_NONE },
88 { "root", FLDT_UINT1,
89 OI(LEOFF(flags) + bitsz(uint8_t) - XFS_ATTR_ROOT_BIT - 1), C1, 0,
90 TYP_NONE },
91 { "secure", FLDT_UINT1,
92 OI(LEOFF(flags) + bitsz(uint8_t) - XFS_ATTR_SECURE_BIT - 1), C1, 0,
93 TYP_NONE },
94 { "local", FLDT_UINT1,
95 OI(LEOFF(flags) + bitsz(uint8_t) - XFS_ATTR_LOCAL_BIT - 1), C1, 0,
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))
102 const 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))
115 const 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))
123 const 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))
144 const 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))
151 const field_t attr_node_hdr_flds[] = {
152 { "info", FLDT_ATTR_BLKINFO, OI(HOFF(info)), C1, 0, TYP_NONE },
153 { "count", FLDT_UINT16D, OI(HOFF(__count)), C1, 0, TYP_NONE },
154 { "level", FLDT_UINT16D, OI(HOFF(__level)), C1, 0, TYP_NONE },
155 { NULL }
156 };
157
158 static int
159 attr_leaf_entries_count(
160 void *obj,
161 int startoff)
162 {
163 struct xfs_attr_leafblock *leaf = obj;
164
165 ASSERT(startoff == 0);
166 if (be16_to_cpu(leaf->hdr.info.magic) != XFS_ATTR_LEAF_MAGIC)
167 return 0;
168 return be16_to_cpu(leaf->hdr.count);
169 }
170
171 static int
172 attr3_leaf_entries_count(
173 void *obj,
174 int startoff)
175 {
176 struct xfs_attr3_leafblock *leaf = obj;
177
178 ASSERT(startoff == 0);
179 if (be16_to_cpu(leaf->hdr.info.hdr.magic) != XFS_ATTR3_LEAF_MAGIC)
180 return 0;
181 return be16_to_cpu(leaf->hdr.count);
182 }
183
184 static int
185 attr_leaf_hdr_count(
186 void *obj,
187 int startoff)
188 {
189 struct xfs_attr_leafblock *leaf = obj;
190
191 ASSERT(startoff == 0);
192 return be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC;
193 }
194
195 static int
196 attr3_leaf_hdr_count(
197 void *obj,
198 int startoff)
199 {
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
206 static int
207 attr_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
217 static int
218 attr3_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
235 typedef int (*attr_leaf_entry_walk_f)(struct xfs_attr_leafblock *,
236 struct xfs_attr_leaf_entry *, int);
237 static int
238 attr_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;
249
250 ASSERT(bitoffs(startoff) == 0);
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)
253 return 0;
254
255 off = byteize(startoff);
256 xfs_attr3_leaf_hdr_from_disk(mp->m_attr_geo, &leafhdr, leaf);
257 entries = xfs_attr3_leaf_entryp(leaf);
258
259 for (i = 0; i < leafhdr.count; i++) {
260 e = &entries[i];
261 if (be16_to_cpu(e->nameidx) == off)
262 return func(leaf, e, i);
263 }
264 return 0;
265 }
266
267 static 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
276 static int
277 attr_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
285 static 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
300 static int
301 attr_leaf_name_local_name_count(
302 void *obj,
303 int startoff)
304 {
305 return attr_leaf_entry_walk(obj, startoff,
306 __attr_leaf_name_local_name_count);
307 }
308
309 static 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))
318 return 0;
319
320 l = xfs_attr3_leaf_name_local(leaf, i);
321 return be16_to_cpu(l->valuelen);
322 }
323
324 static int
325 attr_leaf_name_local_value_count(
326 void *obj,
327 int startoff)
328 {
329 return attr_leaf_entry_walk(obj, startoff,
330 __attr_leaf_name_local_value_count);
331 }
332
333 static 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);
346 }
347
348 static int
349 attr_leaf_name_local_value_offset(
350 void *obj,
351 int startoff,
352 int idx)
353 {
354 return attr_leaf_entry_walk(obj, startoff,
355 __attr_leaf_name_local_value_offset);
356 }
357
358 static 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;
365 }
366
367 static int
368 attr_leaf_name_remote_count(
369 void *obj,
370 int startoff)
371 {
372 return attr_leaf_entry_walk(obj, startoff,
373 __attr_leaf_name_remote_count);
374 }
375
376 static 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)
385 return 0;
386
387 r = xfs_attr3_leaf_name_remote(leaf, i);
388 return r->namelen;
389 }
390
391 static int
392 attr_leaf_name_remote_name_count(
393 void *obj,
394 int startoff)
395 {
396 return attr_leaf_entry_walk(obj, startoff,
397 __attr_leaf_name_remote_name_count);
398 }
399
400 int
401 attr_leaf_name_size(
402 void *obj,
403 int startoff,
404 int idx)
405 {
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;
410
411 ASSERT(startoff == 0);
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)
414 return 0;
415 e = &xfs_attr3_leaf_entryp(leaf)[idx];
416 if (e->flags & XFS_ATTR_LOCAL) {
417 l = xfs_attr3_leaf_name_local(leaf, idx);
418 return (int)bitize(xfs_attr_leaf_entsize_local(l->namelen,
419 be16_to_cpu(l->valuelen)));
420 } else {
421 r = xfs_attr3_leaf_name_remote(leaf, idx);
422 return (int)bitize(xfs_attr_leaf_entsize_remote(r->namelen));
423 }
424 }
425
426 static int
427 attr_leaf_nvlist_count(
428 void *obj,
429 int startoff)
430 {
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
439 static int
440 attr3_leaf_nvlist_count(
441 void *obj,
442 int startoff)
443 {
444 struct xfs_attr3_leafblock *leaf = obj;
445
446 ASSERT(startoff == 0);
447 if (be16_to_cpu(leaf->hdr.info.hdr.magic) != XFS_ATTR3_LEAF_MAGIC)
448 return 0;
449 return be16_to_cpu(leaf->hdr.count);
450 }
451
452 static int
453 attr_leaf_nvlist_offset(
454 void *obj,
455 int startoff,
456 int idx)
457 {
458 struct xfs_attr_leafblock *leaf = obj;
459 struct xfs_attr_leaf_entry *e;
460
461 ASSERT(startoff == 0);
462 e = &xfs_attr3_leaf_entryp(leaf)[idx];
463 return bitize(be16_to_cpu(e->nameidx));
464 }
465
466 static int
467 attr_node_btree_count(
468 void *obj,
469 int startoff)
470 {
471 struct xfs_da_intnode *node = obj;
472
473 ASSERT(startoff == 0); /* this is a base structure */
474 if (be16_to_cpu(node->hdr.info.magic) != XFS_DA_NODE_MAGIC)
475 return 0;
476 return be16_to_cpu(node->hdr.__count);
477 }
478
479 static int
480 attr3_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
493 static int
494 attr_node_hdr_count(
495 void *obj,
496 int startoff)
497 {
498 struct xfs_da_intnode *node = obj;
499
500 ASSERT(startoff == 0);
501 return be16_to_cpu(node->hdr.info.magic) == XFS_DA_NODE_MAGIC;
502 }
503
504 static int
505 attr3_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;
513 }
514
515 static int
516 attr3_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
526 int
527 attr_size(
528 void *obj,
529 int startoff,
530 int idx)
531 {
532 return bitize(mp->m_sb.sb_blocksize);
533 }
534
535 /*
536 * CRC enabled attribute block field definitions
537 */
538 const 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))
545 const field_t attr3_flds[] = {
546 { "hdr", FLDT_ATTR3_LEAF_HDR, OI(L3OFF(hdr)), attr3_leaf_hdr_count,
547 FLD_COUNT, TYP_NONE },
548 { "hdr", FLDT_ATTR3_NODE_HDR, OI(N3OFF(hdr)), attr3_node_hdr_count,
549 FLD_COUNT, TYP_NONE },
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 },
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))
564 const field_t attr3_leaf_hdr_flds[] = {
565 { "info", FLDT_ATTR3_BLKINFO, OI(LH3OFF(info)), C1, 0, TYP_NONE },
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
576 #define B3OFF(f) bitize(offsetof(struct xfs_da3_blkinfo, f))
577 const 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))
588 const 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 },
592 { "pad", FLDT_UINT32X, OI(H3OFF(__pad32)), C1, FLD_SKIPALL, TYP_NONE },
593 { NULL }
594 };
595
596 #define RM3OFF(f) bitize(offsetof(struct xfs_attr3_rmt_hdr, rm_ ## f))
597 const 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
609 /* Set the CRC. */
610 void
611 xfs_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
641 /*
642 * Special read verifier for attribute buffers. Detect the magic number
643 * appropriately and set the correct verifier and call it.
644 */
645 static void
646 xfs_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"));
672 xfs_buf_ioerror(bp, -EFSCORRUPTED);
673 return;
674 }
675 verify:
676 bp->b_ops->verify_read(bp);
677 }
678
679 static void
680 xfs_attr3_db_write_verify(
681 struct xfs_buf *bp)
682 {
683 dbprintf(_("Writing unknown attribute buffer type!\n"));
684 xfs_buf_ioerror(bp, -EFSCORRUPTED);
685 }
686
687 const struct xfs_buf_ops xfs_attr3_db_buf_ops = {
688 .name = "xfs_attr3",
689 .verify_read = xfs_attr3_db_read_verify,
690 .verify_write = xfs_attr3_db_write_verify,
691 };