]>
Commit | Line | Data |
---|---|---|
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 | |
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 | const field_t attr_hfld[] = { | |
45 | { "", FLDT_ATTR, OI(0), C1, 0, TYP_NONE }, | |
46 | { NULL } | |
47 | }; | |
48 | ||
49 | #define LOFF(f) bitize(offsetof(xfs_attr_leafblock_t, f)) | |
50 | #define NOFF(f) bitize(offsetof(xfs_da_intnode_t, f)) | |
51 | const field_t attr_flds[] = { | |
52 | { "hdr", FLDT_ATTR_LEAF_HDR, OI(LOFF(hdr)), attr_leaf_hdr_count, | |
53 | FLD_COUNT, TYP_NONE }, | |
54 | { "hdr", FLDT_ATTR_NODE_HDR, OI(NOFF(hdr)), attr_node_hdr_count, | |
55 | FLD_COUNT, TYP_NONE }, | |
56 | { "entries", FLDT_ATTR_LEAF_ENTRY, OI(LOFF(entries)), | |
57 | attr_leaf_entries_count, FLD_ARRAY|FLD_COUNT, TYP_NONE }, | |
88b32f06 | 58 | { "btree", FLDT_ATTR_NODE_ENTRY, OI(NOFF(__btree)), attr_node_btree_count, |
2bd0ea18 NS |
59 | FLD_ARRAY|FLD_COUNT, TYP_NONE }, |
60 | { "nvlist", FLDT_ATTR_LEAF_NAME, attr_leaf_nvlist_offset, | |
61 | attr_leaf_nvlist_count, FLD_ARRAY|FLD_OFFSET|FLD_COUNT, TYP_NONE }, | |
62 | { NULL } | |
63 | }; | |
64 | ||
65 | #define BOFF(f) bitize(offsetof(xfs_da_blkinfo_t, f)) | |
66 | const field_t attr_blkinfo_flds[] = { | |
67 | { "forw", FLDT_ATTRBLOCK, OI(BOFF(forw)), C1, 0, TYP_ATTR }, | |
68 | { "back", FLDT_ATTRBLOCK, OI(BOFF(back)), C1, 0, TYP_ATTR }, | |
69 | { "magic", FLDT_UINT16X, OI(BOFF(magic)), C1, 0, TYP_NONE }, | |
70 | { "pad", FLDT_UINT16X, OI(BOFF(pad)), C1, FLD_SKIPALL, TYP_NONE }, | |
71 | { NULL } | |
72 | }; | |
73 | ||
74 | #define LEOFF(f) bitize(offsetof(xfs_attr_leaf_entry_t, f)) | |
75 | const field_t attr_leaf_entry_flds[] = { | |
76 | { "hashval", FLDT_UINT32X, OI(LEOFF(hashval)), C1, 0, TYP_NONE }, | |
77 | { "nameidx", FLDT_UINT16D, OI(LEOFF(nameidx)), C1, 0, TYP_NONE }, | |
78 | { "flags", FLDT_UINT8X, OI(LEOFF(flags)), C1, FLD_SKIPALL, TYP_NONE }, | |
79 | { "incomplete", FLDT_UINT1, | |
80 | OI(LEOFF(flags) + bitsz(__uint8_t) - XFS_ATTR_INCOMPLETE_BIT - 1), C1, | |
81 | 0, TYP_NONE }, | |
82 | { "root", FLDT_UINT1, | |
83 | OI(LEOFF(flags) + bitsz(__uint8_t) - XFS_ATTR_ROOT_BIT - 1), C1, 0, | |
84 | TYP_NONE }, | |
4b0c5771 NS |
85 | { "secure", FLDT_UINT1, |
86 | OI(LEOFF(flags) + bitsz(__uint8_t) - XFS_ATTR_SECURE_BIT - 1), C1, 0, | |
87 | TYP_NONE }, | |
2bd0ea18 NS |
88 | { "local", FLDT_UINT1, |
89 | OI(LEOFF(flags) + bitsz(__uint8_t) - XFS_ATTR_LOCAL_BIT - 1), C1, 0, | |
90 | TYP_NONE }, | |
91 | { "pad2", FLDT_UINT8X, OI(LEOFF(pad2)), C1, FLD_SKIPALL, TYP_NONE }, | |
92 | { NULL } | |
93 | }; | |
94 | ||
95 | #define LHOFF(f) bitize(offsetof(xfs_attr_leaf_hdr_t, f)) | |
96 | const field_t attr_leaf_hdr_flds[] = { | |
97 | { "info", FLDT_ATTR_BLKINFO, OI(LHOFF(info)), C1, 0, TYP_NONE }, | |
98 | { "count", FLDT_UINT16D, OI(LHOFF(count)), C1, 0, TYP_NONE }, | |
99 | { "usedbytes", FLDT_UINT16D, OI(LHOFF(usedbytes)), C1, 0, TYP_NONE }, | |
100 | { "firstused", FLDT_UINT16D, OI(LHOFF(firstused)), C1, 0, TYP_NONE }, | |
101 | { "holes", FLDT_UINT8D, OI(LHOFF(holes)), C1, 0, TYP_NONE }, | |
102 | { "pad1", FLDT_UINT8X, OI(LHOFF(pad1)), C1, FLD_SKIPALL, TYP_NONE }, | |
103 | { "freemap", FLDT_ATTR_LEAF_MAP, OI(LHOFF(freemap)), | |
104 | CI(XFS_ATTR_LEAF_MAPSIZE), FLD_ARRAY, TYP_NONE }, | |
105 | { NULL } | |
106 | }; | |
107 | ||
108 | #define LMOFF(f) bitize(offsetof(xfs_attr_leaf_map_t, f)) | |
109 | const field_t attr_leaf_map_flds[] = { | |
110 | { "base", FLDT_UINT16D, OI(LMOFF(base)), C1, 0, TYP_NONE }, | |
111 | { "size", FLDT_UINT16D, OI(LMOFF(size)), C1, 0, TYP_NONE }, | |
112 | { NULL } | |
113 | }; | |
114 | ||
115 | #define LNOFF(f) bitize(offsetof(xfs_attr_leaf_name_local_t, f)) | |
116 | #define LVOFF(f) bitize(offsetof(xfs_attr_leaf_name_remote_t, f)) | |
117 | const field_t attr_leaf_name_flds[] = { | |
118 | { "valuelen", FLDT_UINT16D, OI(LNOFF(valuelen)), | |
119 | attr_leaf_name_local_count, FLD_COUNT, TYP_NONE }, | |
120 | { "namelen", FLDT_UINT8D, OI(LNOFF(namelen)), | |
121 | attr_leaf_name_local_count, FLD_COUNT, TYP_NONE }, | |
122 | { "name", FLDT_CHARNS, OI(LNOFF(nameval)), | |
123 | attr_leaf_name_local_name_count, FLD_COUNT, TYP_NONE }, | |
124 | { "value", FLDT_CHARNS, attr_leaf_name_local_value_offset, | |
125 | attr_leaf_name_local_value_count, FLD_COUNT|FLD_OFFSET, TYP_NONE }, | |
126 | { "valueblk", FLDT_UINT32X, OI(LVOFF(valueblk)), | |
127 | attr_leaf_name_remote_count, FLD_COUNT, TYP_NONE }, | |
128 | { "valuelen", FLDT_UINT32D, OI(LVOFF(valuelen)), | |
129 | attr_leaf_name_remote_count, FLD_COUNT, TYP_NONE }, | |
130 | { "namelen", FLDT_UINT8D, OI(LVOFF(namelen)), | |
131 | attr_leaf_name_remote_count, FLD_COUNT, TYP_NONE }, | |
132 | { "name", FLDT_CHARNS, OI(LVOFF(name)), | |
133 | attr_leaf_name_remote_name_count, FLD_COUNT, TYP_NONE }, | |
134 | { NULL } | |
135 | }; | |
136 | ||
137 | #define EOFF(f) bitize(offsetof(xfs_da_node_entry_t, f)) | |
138 | const field_t attr_node_entry_flds[] = { | |
139 | { "hashval", FLDT_UINT32X, OI(EOFF(hashval)), C1, 0, TYP_NONE }, | |
140 | { "before", FLDT_ATTRBLOCK, OI(EOFF(before)), C1, 0, TYP_ATTR }, | |
141 | { NULL } | |
142 | }; | |
143 | ||
144 | #define HOFF(f) bitize(offsetof(xfs_da_node_hdr_t, f)) | |
145 | const field_t attr_node_hdr_flds[] = { | |
146 | { "info", FLDT_ATTR_BLKINFO, OI(HOFF(info)), C1, 0, TYP_NONE }, | |
a24374f4 | 147 | { "count", FLDT_UINT16D, OI(HOFF(__count)), C1, 0, TYP_NONE }, |
88b32f06 | 148 | { "level", FLDT_UINT16D, OI(HOFF(__level)), C1, 0, TYP_NONE }, |
2bd0ea18 NS |
149 | { NULL } |
150 | }; | |
151 | ||
2bd0ea18 NS |
152 | static int |
153 | attr_leaf_entries_count( | |
154 | void *obj, | |
155 | int startoff) | |
156 | { | |
ad04ef4a | 157 | struct xfs_attr_leafblock *leaf = obj; |
dfc130f3 | 158 | |
2bd0ea18 | 159 | ASSERT(startoff == 0); |
ad04ef4a | 160 | if (be16_to_cpu(leaf->hdr.info.magic) != XFS_ATTR_LEAF_MAGIC) |
2bd0ea18 | 161 | return 0; |
ad04ef4a DC |
162 | return be16_to_cpu(leaf->hdr.count); |
163 | } | |
164 | ||
165 | static int | |
166 | attr3_leaf_entries_count( | |
167 | void *obj, | |
168 | int startoff) | |
169 | { | |
170 | struct xfs_attr3_leafblock *leaf = obj; | |
171 | ||
172 | ASSERT(startoff == 0); | |
e13d0f78 | 173 | if (be16_to_cpu(leaf->hdr.info.hdr.magic) != XFS_ATTR3_LEAF_MAGIC) |
ad04ef4a DC |
174 | return 0; |
175 | return be16_to_cpu(leaf->hdr.count); | |
2bd0ea18 NS |
176 | } |
177 | ||
2bd0ea18 NS |
178 | static int |
179 | attr_leaf_hdr_count( | |
180 | void *obj, | |
181 | int startoff) | |
182 | { | |
ad04ef4a | 183 | struct xfs_attr_leafblock *leaf = obj; |
dfc130f3 | 184 | |
2bd0ea18 | 185 | ASSERT(startoff == 0); |
ad04ef4a | 186 | return be16_to_cpu(leaf->hdr.info.magic) == XFS_ATTR_LEAF_MAGIC; |
2bd0ea18 NS |
187 | } |
188 | ||
189 | static int | |
ad04ef4a | 190 | attr3_leaf_hdr_count( |
2bd0ea18 NS |
191 | void *obj, |
192 | int startoff) | |
193 | { | |
ad04ef4a DC |
194 | struct xfs_attr3_leafblock *leaf = obj; |
195 | ||
196 | ASSERT(startoff == 0); | |
197 | return be16_to_cpu(leaf->hdr.info.hdr.magic) == XFS_ATTR3_LEAF_MAGIC; | |
198 | } | |
199 | ||
200 | typedef int (*attr_leaf_entry_walk_f)(struct xfs_attr_leafblock *, | |
201 | struct xfs_attr_leaf_entry *, int); | |
202 | static int | |
203 | attr_leaf_entry_walk( | |
204 | void *obj, | |
205 | int startoff, | |
206 | attr_leaf_entry_walk_f func) | |
207 | { | |
208 | struct xfs_attr_leafblock *leaf = obj; | |
209 | struct xfs_attr3_icleaf_hdr leafhdr; | |
210 | struct xfs_attr_leaf_entry *entries; | |
211 | struct xfs_attr_leaf_entry *e; | |
212 | int i; | |
213 | int off; | |
2bd0ea18 NS |
214 | |
215 | ASSERT(bitoffs(startoff) == 0); | |
ad04ef4a DC |
216 | if (be16_to_cpu(leaf->hdr.info.magic) != XFS_ATTR_LEAF_MAGIC && |
217 | be16_to_cpu(leaf->hdr.info.magic) != XFS_ATTR3_LEAF_MAGIC) | |
2bd0ea18 | 218 | return 0; |
ad04ef4a DC |
219 | |
220 | off = byteize(startoff); | |
19ebedcf | 221 | xfs_attr3_leaf_hdr_from_disk(mp->m_attr_geo, &leafhdr, leaf); |
ad04ef4a DC |
222 | entries = xfs_attr3_leaf_entryp(leaf); |
223 | ||
224 | for (i = 0; i < leafhdr.count; i++) { | |
225 | e = &entries[i]; | |
5e656dbb | 226 | if (be16_to_cpu(e->nameidx) == off) |
ad04ef4a | 227 | return func(leaf, e, i); |
2bd0ea18 NS |
228 | } |
229 | return 0; | |
230 | } | |
231 | ||
ad04ef4a DC |
232 | static int |
233 | __attr_leaf_name_local_count( | |
234 | struct xfs_attr_leafblock *leaf, | |
235 | struct xfs_attr_leaf_entry *e, | |
236 | int i) | |
237 | { | |
238 | return (e->flags & XFS_ATTR_LOCAL) != 0; | |
239 | } | |
240 | ||
241 | static int | |
242 | attr_leaf_name_local_count( | |
243 | void *obj, | |
244 | int startoff) | |
245 | { | |
246 | return attr_leaf_entry_walk(obj, startoff, | |
247 | __attr_leaf_name_local_count); | |
248 | } | |
249 | ||
250 | static int | |
251 | __attr_leaf_name_local_name_count( | |
252 | struct xfs_attr_leafblock *leaf, | |
253 | struct xfs_attr_leaf_entry *e, | |
254 | int i) | |
255 | { | |
256 | struct xfs_attr_leaf_name_local *l; | |
257 | ||
258 | if (!(e->flags & XFS_ATTR_LOCAL)) | |
259 | return 0; | |
260 | ||
261 | l = xfs_attr3_leaf_name_local(leaf, i); | |
262 | return l->namelen; | |
263 | } | |
264 | ||
2bd0ea18 NS |
265 | static int |
266 | attr_leaf_name_local_name_count( | |
267 | void *obj, | |
268 | int startoff) | |
269 | { | |
ad04ef4a DC |
270 | return attr_leaf_entry_walk(obj, startoff, |
271 | __attr_leaf_name_local_name_count); | |
272 | } | |
2bd0ea18 | 273 | |
ad04ef4a DC |
274 | static int |
275 | __attr_leaf_name_local_value_count( | |
276 | struct xfs_attr_leafblock *leaf, | |
277 | struct xfs_attr_leaf_entry *e, | |
278 | int i) | |
279 | { | |
280 | struct xfs_attr_leaf_name_local *l; | |
281 | ||
282 | if (!(e->flags & XFS_ATTR_LOCAL)) | |
2bd0ea18 | 283 | return 0; |
ad04ef4a DC |
284 | |
285 | l = xfs_attr3_leaf_name_local(leaf, i); | |
286 | return be16_to_cpu(l->valuelen); | |
2bd0ea18 NS |
287 | } |
288 | ||
289 | static int | |
290 | attr_leaf_name_local_value_count( | |
291 | void *obj, | |
292 | int startoff) | |
293 | { | |
ad04ef4a DC |
294 | return attr_leaf_entry_walk(obj, startoff, |
295 | __attr_leaf_name_local_value_count); | |
296 | } | |
2bd0ea18 | 297 | |
ad04ef4a DC |
298 | static int |
299 | __attr_leaf_name_local_value_offset( | |
300 | struct xfs_attr_leafblock *leaf, | |
301 | struct xfs_attr_leaf_entry *e, | |
302 | int i) | |
303 | { | |
304 | struct xfs_attr_leaf_name_local *l; | |
305 | char *vp; | |
306 | ||
307 | l = xfs_attr3_leaf_name_local(leaf, i); | |
308 | vp = (char *)&l->nameval[l->namelen]; | |
309 | ||
310 | return (int)bitize(vp - (char *)l); | |
2bd0ea18 NS |
311 | } |
312 | ||
2bd0ea18 NS |
313 | static int |
314 | attr_leaf_name_local_value_offset( | |
315 | void *obj, | |
316 | int startoff, | |
317 | int idx) | |
318 | { | |
ad04ef4a DC |
319 | return attr_leaf_entry_walk(obj, startoff, |
320 | __attr_leaf_name_local_value_offset); | |
321 | } | |
dfc130f3 | 322 | |
ad04ef4a DC |
323 | static int |
324 | __attr_leaf_name_remote_count( | |
325 | struct xfs_attr_leafblock *leaf, | |
326 | struct xfs_attr_leaf_entry *e, | |
327 | int i) | |
328 | { | |
329 | return (e->flags & XFS_ATTR_LOCAL) == 0; | |
2bd0ea18 NS |
330 | } |
331 | ||
332 | static int | |
333 | attr_leaf_name_remote_count( | |
ad04ef4a DC |
334 | void *obj, |
335 | int startoff) | |
2bd0ea18 | 336 | { |
ad04ef4a DC |
337 | return attr_leaf_entry_walk(obj, startoff, |
338 | __attr_leaf_name_remote_count); | |
339 | } | |
2bd0ea18 | 340 | |
ad04ef4a DC |
341 | static int |
342 | __attr_leaf_name_remote_name_count( | |
343 | struct xfs_attr_leafblock *leaf, | |
344 | struct xfs_attr_leaf_entry *e, | |
345 | int i) | |
346 | { | |
347 | struct xfs_attr_leaf_name_remote *r; | |
348 | ||
349 | if (e->flags & XFS_ATTR_LOCAL) | |
2bd0ea18 | 350 | return 0; |
ad04ef4a DC |
351 | |
352 | r = xfs_attr3_leaf_name_remote(leaf, i); | |
353 | return r->namelen; | |
2bd0ea18 NS |
354 | } |
355 | ||
356 | static int | |
357 | attr_leaf_name_remote_name_count( | |
358 | void *obj, | |
359 | int startoff) | |
360 | { | |
ad04ef4a DC |
361 | return attr_leaf_entry_walk(obj, startoff, |
362 | __attr_leaf_name_remote_name_count); | |
2bd0ea18 NS |
363 | } |
364 | ||
2bd0ea18 NS |
365 | int |
366 | attr_leaf_name_size( | |
367 | void *obj, | |
368 | int startoff, | |
369 | int idx) | |
370 | { | |
ad04ef4a DC |
371 | struct xfs_attr_leafblock *leaf = obj; |
372 | struct xfs_attr_leaf_entry *e; | |
373 | struct xfs_attr_leaf_name_local *l; | |
374 | struct xfs_attr_leaf_name_remote *r; | |
2bd0ea18 NS |
375 | |
376 | ASSERT(startoff == 0); | |
ad04ef4a DC |
377 | if (be16_to_cpu(leaf->hdr.info.magic) != XFS_ATTR_LEAF_MAGIC && |
378 | be16_to_cpu(leaf->hdr.info.magic) != XFS_ATTR3_LEAF_MAGIC) | |
2bd0ea18 | 379 | return 0; |
ad04ef4a | 380 | e = &xfs_attr3_leaf_entryp(leaf)[idx]; |
5e656dbb | 381 | if (e->flags & XFS_ATTR_LOCAL) { |
ad04ef4a | 382 | l = xfs_attr3_leaf_name_local(leaf, idx); |
56b2de80 | 383 | return (int)bitize(xfs_attr_leaf_entsize_local(l->namelen, |
5e656dbb | 384 | be16_to_cpu(l->valuelen))); |
2bd0ea18 | 385 | } else { |
ad04ef4a | 386 | r = xfs_attr3_leaf_name_remote(leaf, idx); |
56b2de80 | 387 | return (int)bitize(xfs_attr_leaf_entsize_remote(r->namelen)); |
2bd0ea18 NS |
388 | } |
389 | } | |
390 | ||
2bd0ea18 NS |
391 | static int |
392 | attr_leaf_nvlist_count( | |
393 | void *obj, | |
394 | int startoff) | |
395 | { | |
ad04ef4a DC |
396 | struct xfs_attr_leafblock *leaf = obj; |
397 | ||
398 | ASSERT(startoff == 0); | |
399 | if (be16_to_cpu(leaf->hdr.info.magic) != XFS_ATTR_LEAF_MAGIC) | |
400 | return 0; | |
401 | return be16_to_cpu(leaf->hdr.count); | |
402 | } | |
403 | ||
404 | static int | |
405 | attr3_leaf_nvlist_count( | |
406 | void *obj, | |
407 | int startoff) | |
408 | { | |
409 | struct xfs_attr3_leafblock *leaf = obj; | |
2bd0ea18 NS |
410 | |
411 | ASSERT(startoff == 0); | |
ad04ef4a | 412 | if (be16_to_cpu(leaf->hdr.info.hdr.magic) != XFS_ATTR3_LEAF_MAGIC) |
2bd0ea18 | 413 | return 0; |
ad04ef4a | 414 | return be16_to_cpu(leaf->hdr.count); |
2bd0ea18 NS |
415 | } |
416 | ||
2bd0ea18 NS |
417 | static int |
418 | attr_leaf_nvlist_offset( | |
419 | void *obj, | |
420 | int startoff, | |
421 | int idx) | |
422 | { | |
ad04ef4a DC |
423 | struct xfs_attr_leafblock *leaf = obj; |
424 | struct xfs_attr_leaf_entry *e; | |
2bd0ea18 NS |
425 | |
426 | ASSERT(startoff == 0); | |
ad04ef4a | 427 | e = &xfs_attr3_leaf_entryp(leaf)[idx]; |
5e656dbb | 428 | return bitize(be16_to_cpu(e->nameidx)); |
2bd0ea18 NS |
429 | } |
430 | ||
2bd0ea18 NS |
431 | static int |
432 | attr_node_btree_count( | |
433 | void *obj, | |
434 | int startoff) | |
435 | { | |
ad04ef4a | 436 | struct xfs_da_intnode *node = obj; |
2bd0ea18 NS |
437 | |
438 | ASSERT(startoff == 0); /* this is a base structure */ | |
ad04ef4a | 439 | if (be16_to_cpu(node->hdr.info.magic) != XFS_DA_NODE_MAGIC) |
2bd0ea18 | 440 | return 0; |
ad04ef4a | 441 | return be16_to_cpu(node->hdr.__count); |
2bd0ea18 NS |
442 | } |
443 | ||
ad04ef4a DC |
444 | static int |
445 | attr3_node_btree_count( | |
446 | void *obj, | |
447 | int startoff) | |
448 | { | |
449 | struct xfs_da3_intnode *node = obj; | |
450 | ||
451 | ASSERT(startoff == 0); | |
452 | if (be16_to_cpu(node->hdr.info.hdr.magic) != XFS_DA3_NODE_MAGIC) | |
453 | return 0; | |
454 | return be16_to_cpu(node->hdr.__count); | |
455 | } | |
456 | ||
457 | ||
2bd0ea18 NS |
458 | static int |
459 | attr_node_hdr_count( | |
460 | void *obj, | |
461 | int startoff) | |
462 | { | |
ad04ef4a | 463 | struct xfs_da_intnode *node = obj; |
dfc130f3 | 464 | |
2bd0ea18 | 465 | ASSERT(startoff == 0); |
ad04ef4a DC |
466 | return be16_to_cpu(node->hdr.info.magic) == XFS_DA_NODE_MAGIC; |
467 | } | |
468 | ||
469 | static int | |
470 | attr3_node_hdr_count( | |
471 | void *obj, | |
472 | int startoff) | |
473 | { | |
474 | struct xfs_da3_intnode *node = obj; | |
475 | ||
476 | ASSERT(startoff == 0); | |
477 | return be16_to_cpu(node->hdr.info.hdr.magic) == XFS_DA3_NODE_MAGIC; | |
2bd0ea18 NS |
478 | } |
479 | ||
2bd0ea18 NS |
480 | int |
481 | attr_size( | |
482 | void *obj, | |
483 | int startoff, | |
484 | int idx) | |
485 | { | |
486 | return bitize(mp->m_sb.sb_blocksize); | |
487 | } | |
ad04ef4a DC |
488 | |
489 | /* | |
490 | * CRC enabled attribute block field definitions | |
491 | */ | |
492 | const field_t attr3_hfld[] = { | |
493 | { "", FLDT_ATTR3, OI(0), C1, 0, TYP_NONE }, | |
494 | { NULL } | |
495 | }; | |
496 | ||
497 | #define L3OFF(f) bitize(offsetof(struct xfs_attr3_leafblock, f)) | |
498 | #define N3OFF(f) bitize(offsetof(struct xfs_da3_intnode, f)) | |
499 | const field_t attr3_flds[] = { | |
500 | { "hdr", FLDT_ATTR3_LEAF_HDR, OI(L3OFF(hdr)), attr3_leaf_hdr_count, | |
501 | FLD_COUNT, TYP_NONE }, | |
502 | { "hdr", FLDT_DA3_NODE_HDR, OI(N3OFF(hdr)), attr3_node_hdr_count, | |
503 | FLD_COUNT, TYP_NONE }, | |
504 | { "entries", FLDT_ATTR_LEAF_ENTRY, OI(L3OFF(entries)), | |
505 | attr3_leaf_entries_count, FLD_ARRAY|FLD_COUNT, TYP_NONE }, | |
506 | { "btree", FLDT_ATTR_NODE_ENTRY, OI(N3OFF(__btree)), | |
507 | attr3_node_btree_count, FLD_ARRAY|FLD_COUNT, TYP_NONE }, | |
508 | { "nvlist", FLDT_ATTR_LEAF_NAME, attr_leaf_nvlist_offset, | |
509 | attr3_leaf_nvlist_count, FLD_ARRAY|FLD_OFFSET|FLD_COUNT, TYP_NONE }, | |
510 | { NULL } | |
511 | }; | |
512 | ||
513 | #define LH3OFF(f) bitize(offsetof(struct xfs_attr3_leaf_hdr, f)) | |
514 | const field_t attr3_leaf_hdr_flds[] = { | |
515 | { "info", FLDT_DA3_BLKINFO, OI(LH3OFF(info)), C1, 0, TYP_NONE }, | |
516 | { "count", FLDT_UINT16D, OI(LH3OFF(count)), C1, 0, TYP_NONE }, | |
517 | { "usedbytes", FLDT_UINT16D, OI(LH3OFF(usedbytes)), C1, 0, TYP_NONE }, | |
518 | { "firstused", FLDT_UINT16D, OI(LH3OFF(firstused)), C1, 0, TYP_NONE }, | |
519 | { "holes", FLDT_UINT8D, OI(LH3OFF(holes)), C1, 0, TYP_NONE }, | |
520 | { "pad1", FLDT_UINT8X, OI(LH3OFF(pad1)), C1, FLD_SKIPALL, TYP_NONE }, | |
521 | { "freemap", FLDT_ATTR_LEAF_MAP, OI(LH3OFF(freemap)), | |
522 | CI(XFS_ATTR_LEAF_MAPSIZE), FLD_ARRAY, TYP_NONE }, | |
523 | { NULL } | |
524 | }; | |
525 | ||
2847273f DC |
526 | /* |
527 | * Special read verifier for attribute buffers. Detect the magic number | |
528 | * appropriately and set the correct verifier and call it. | |
529 | */ | |
530 | static void | |
531 | xfs_attr3_db_read_verify( | |
532 | struct xfs_buf *bp) | |
533 | { | |
534 | __be32 magic32; | |
535 | __be16 magic16; | |
536 | ||
537 | magic32 = *(__be32 *)bp->b_addr; | |
538 | magic16 = ((struct xfs_da_blkinfo *)bp->b_addr)->magic; | |
539 | ||
540 | switch (magic16) { | |
541 | case cpu_to_be16(XFS_ATTR3_LEAF_MAGIC): | |
542 | bp->b_ops = &xfs_attr3_leaf_buf_ops; | |
543 | goto verify; | |
544 | case cpu_to_be16(XFS_DA3_NODE_MAGIC): | |
545 | bp->b_ops = &xfs_da3_node_buf_ops; | |
546 | goto verify; | |
547 | default: | |
548 | break; | |
549 | } | |
550 | ||
551 | switch (magic32) { | |
552 | case cpu_to_be32(XFS_ATTR3_RMT_MAGIC): | |
553 | bp->b_ops = &xfs_attr3_rmt_buf_ops; | |
554 | break; | |
555 | default: | |
556 | dbprintf(_("Unknown attribute buffer type!\n")); | |
66fc04e0 | 557 | xfs_buf_ioerror(bp, -EFSCORRUPTED); |
2847273f DC |
558 | return; |
559 | } | |
560 | verify: | |
561 | bp->b_ops->verify_read(bp); | |
562 | } | |
563 | ||
564 | static void | |
565 | xfs_attr3_db_write_verify( | |
566 | struct xfs_buf *bp) | |
567 | { | |
568 | dbprintf(_("Writing unknown attribute buffer type!\n")); | |
66fc04e0 | 569 | xfs_buf_ioerror(bp, -EFSCORRUPTED); |
2847273f DC |
570 | } |
571 | ||
572 | const struct xfs_buf_ops xfs_attr3_db_buf_ops = { | |
a3fac935 | 573 | .name = "xfs_attr3", |
2847273f DC |
574 | .verify_read = xfs_attr3_db_read_verify, |
575 | .verify_write = xfs_attr3_db_write_verify, | |
576 | }; |