1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2002,2004-2005 Silicon Graphics, Inc.
9 #include "err_protos.h"
10 #include "attr_repair.h"
17 static int xfs_acl_valid(struct xfs_mount
*mp
, struct xfs_acl
*daclp
);
18 static int xfs_mac_valid(xfs_mac_label_t
*lp
);
21 * da node check/verify functions that the attribute tree relies on are first in
22 * the file before the actual attribute code. This used to be shared with the
23 * dir v1 code, but that format is no longer supported yb the userspace
24 * utilities and hence is now specific to the attribute tree implementation.
27 typedef unsigned char da_freemap_t
;
30 * Allocate a freespace map for directory or attr leaf blocks (1 bit per byte)
31 * 1 == used, 0 == free.
34 alloc_da_freemap(struct xfs_mount
*mp
)
36 return calloc(1, mp
->m_sb
.sb_blocksize
/ NBBY
);
40 * Set the he range [start, stop) in the directory freemap.
42 * Returns 1 if there is a conflict or 0 if everything's good.
44 * Within a char, the lowest bit of the char represents the byte with
45 * the smallest address
48 set_da_freemap(xfs_mount_t
*mp
, da_freemap_t
*map
, int start
, int stop
)
50 const da_freemap_t mask
= 0x1;
55 * allow == relation since [x, x) claims 1 byte
57 do_warn(_("bad range claimed [%d, %d) in da block\n"),
62 if (stop
> mp
->m_sb
.sb_blocksize
) {
64 _("byte range end [%d %d) in da block larger than blocksize %d\n"),
65 start
, stop
, mp
->m_sb
.sb_blocksize
);
69 for (i
= start
; i
< stop
; i
++) {
70 if (map
[i
/ NBBY
] & (mask
<< i
% NBBY
)) {
71 do_warn(_("multiply claimed byte %d in da block\n"), i
);
74 map
[i
/ NBBY
] |= (mask
<< i
% NBBY
);
81 * For attribute repair, there are 3 formats to worry about. First, is
82 * shortform attributes which reside in the inode. Second is the leaf
83 * form, and lastly the btree. Much of this models after the directory
84 * structure so code resembles the directory repair cases.
85 * For shortform case, if an attribute looks corrupt, it is removed.
86 * If that leaves the shortform down to 0 attributes, it's okay and
87 * will appear to just have a null attribute fork. Some checks are done
88 * for validity of the value field based on what the security needs are.
89 * Calls will be made to xfs_mac_valid or xfs_acl_valid routines if the
90 * security attributes exist. They will be cleared if invalid.
91 * No other values will be checked. The DMF folks do not have current
92 * requirements, but may in the future.
94 * For leaf block attributes, it requires more processing. One sticky
95 * point is that the attributes can be local (within the leaf) or
96 * remote (outside the leaf in other blocks). Thinking of local only
97 * if you get a bad attribute, and want to delete just one, it's a-okay
98 * if it remains large enough to still be a leaf block attribute. Otherwise,
99 * it may have to be converted to shortform. How to convert this and when
100 * is an issue. This call is happening in Phase3. Phase5 will capture empty
101 * blocks, but Phase6 allows you to use the libxfs library which knows
102 * how to handle attributes in the kernel for converting formats. What we
103 * could do is mark an attribute to be cleared now, but in phase6 somehow
104 * have it cleared for real and then the format changed to shortform if
105 * applicable. Since this requires more work than I anticipate can be
106 * accomplished for the next release, we will instead just say any bad
107 * attribute in the leaf block will make the entire attribute fork be
108 * cleared. The simplest way to do that is to ignore the leaf format, and
109 * call clear_dinode_attr to just make a shortform attribute fork with
112 * Another issue with handling repair on leaf attributes is the remote
113 * blocks. To make sure that they look good and are not used multiple times
114 * by the attribute fork, some mechanism to keep track of all them is necessary.
115 * Do this in the future, time permitting. For now, note that there is no
116 * check for remote blocks and their allocations.
118 * For btree formatted attributes, the model can follow directories. That
119 * would mean go down the tree to the leftmost leaf. From there moving down
120 * the links and processing each. They would call back up the tree, to verify
121 * that the tree structure is okay. Any problems will result in the attribute
122 * fork being emptied and put in shortform format.
130 return namecheck((char *)name
, length
, false);
134 * This routine just checks what security needs are for attribute values
135 * only called when root flag is set, otherwise these names could exist in
136 * in user attribute land without a conflict.
137 * If value is non-zero, then a remote attribute is being passed in
141 struct xfs_mount
*mp
,
147 /* for proper alignment issues, get the structs and memmove the values */
148 xfs_mac_label_t macl
;
152 if ((namelen
== SGI_ACL_FILE_SIZE
&&
153 strncmp(namevalue
, SGI_ACL_FILE
, SGI_ACL_FILE_SIZE
) == 0) ||
154 (namelen
== SGI_ACL_DEFAULT_SIZE
&&
155 strncmp(namevalue
, SGI_ACL_DEFAULT
, SGI_ACL_DEFAULT_SIZE
) == 0)) {
157 valuep
= malloc(valuelen
);
159 do_error(_("No memory for ACL check!\n"));
160 memcpy(valuep
, namevalue
+ namelen
, valuelen
);
164 if (xfs_acl_valid(mp
, valuep
) != 0) {
167 _("entry contains illegal value in attribute named SGI_ACL_FILE "
168 "or SGI_ACL_DEFAULT\n"));
174 } else if (strncmp(namevalue
, SGI_MAC_FILE
, SGI_MAC_FILE_SIZE
) == 0) {
176 memset(&macl
, 0, sizeof(xfs_mac_label_t
));
177 memmove(&macl
, namevalue
+namelen
, valuelen
);
182 if (xfs_mac_valid((xfs_mac_label_t
*)valuep
) != 1) { /* 1 is valid */
184 * if sysconf says MAC enabled,
185 * temp = mac_from_text("msenhigh/mintlow", NULL)
186 * copy it to value, update valuelen, totsize
187 * This causes pushing up or down of all following
188 * attributes, forcing a attribute format change!!
193 _("entry contains illegal value in attribute named SGI_MAC_LABEL\n"));
195 } else if (strncmp(namevalue
, SGI_CAP_FILE
, SGI_CAP_FILE_SIZE
) == 0) {
196 if ( valuelen
!= sizeof(xfs_cap_set_t
)) {
199 _("entry contains illegal value in attribute named SGI_CAP_FILE\n"));
208 * this routine validates the attributes in shortform format.
209 * a non-zero return repair value means certain attributes are bogus
210 * and were cleared if possible. Warnings do not generate error conditions
211 * if you cannot modify the structures. repair is set to 1, if anything
215 process_shortform_attr(
216 struct xfs_mount
*mp
,
221 xfs_attr_shortform_t
*asf
;
222 xfs_attr_sf_entry_t
*currententry
, *nextentry
, *tempentry
;
224 int currentsize
, remainingspace
;
228 asf
= (xfs_attr_shortform_t
*) XFS_DFORK_APTR(dip
);
230 /* Assumption: hdr.totsize is less than a leaf block and was checked
231 * by lclinode for valid sizes. Check the count though.
233 if (asf
->hdr
.count
== 0)
234 /* then the total size should just be the header length */
235 if (be16_to_cpu(asf
->hdr
.totsize
) != sizeof(xfs_attr_sf_hdr_t
)) {
236 /* whoops there's a discrepancy. Clear the hdr */
239 _("there are no attributes in the fork for inode %" PRIu64
"\n"),
242 cpu_to_be16(sizeof(xfs_attr_sf_hdr_t
));
247 _("would junk the attribute fork since count is 0 for inode %" PRIu64
"\n"),
253 currentsize
= sizeof(xfs_attr_sf_hdr_t
);
254 remainingspace
= be16_to_cpu(asf
->hdr
.totsize
) - currentsize
;
255 nextentry
= &asf
->list
[0];
256 for (i
= 0; i
< asf
->hdr
.count
; i
++) {
257 currententry
= nextentry
;
260 /* don't go off the end if the hdr.count was off */
261 if ((currentsize
+ (sizeof(xfs_attr_sf_entry_t
) - 1)) >
262 be16_to_cpu(asf
->hdr
.totsize
))
263 break; /* get out and reset count and totSize */
265 /* if the namelen is 0, can't get to the rest of the entries */
266 if (currententry
->namelen
== 0) {
267 do_warn(_("zero length name entry in attribute fork,"));
270 _(" truncating attributes for inode %" PRIu64
" to %d\n"), ino
, i
);
272 break; /* and then update hdr fields */
275 _(" would truncate attributes for inode %" PRIu64
" to %d\n"), ino
, i
);
279 /* It's okay to have a 0 length valuelen, but do a
280 * rough check to make sure we haven't gone outside of
283 if (remainingspace
< currententry
->namelen
||
284 ((remainingspace
- currententry
->
285 namelen
) < currententry
->valuelen
)) {
287 _("name or value attribute lengths are too large,\n"));
290 _(" truncating attributes for inode %" PRIu64
" to %d\n"),
293 break; /* and then update hdr fields */
296 _(" would truncate attributes for inode %" PRIu64
" to %d\n"),
303 /* namecheck checks for null chars in attr names. */
304 if (attr_namecheck(currententry
->nameval
,
305 currententry
->namelen
)) {
307 _("entry contains illegal character in shortform attribute name\n"));
311 if (currententry
->flags
& XFS_ATTR_INCOMPLETE
) {
313 _("entry has INCOMPLETE flag on in shortform attribute\n"));
317 /* Only check values for root security attributes */
318 if (currententry
->flags
& XFS_ATTR_ROOT
)
319 junkit
|= valuecheck(mp
,
320 (char *)¤tentry
->nameval
[0],
321 NULL
, currententry
->namelen
,
322 currententry
->valuelen
);
324 remainingspace
= remainingspace
-
325 XFS_ATTR_SF_ENTSIZE(currententry
);
329 /* get rid of only this entry */
331 _("removing attribute entry %d for inode %" PRIu64
"\n"),
333 tempentry
= (xfs_attr_sf_entry_t
*)
334 ((intptr_t) currententry
+
335 XFS_ATTR_SF_ENTSIZE(currententry
));
336 memmove(currententry
,tempentry
,remainingspace
);
338 i
--; /* no worries, it will wrap back to 0 */
340 continue; /* go back up now */
343 _("would remove attribute entry %d for inode %" PRIu64
"\n"),
348 /* Let's get ready for the next entry... */
349 nextentry
= (xfs_attr_sf_entry_t
*)((intptr_t) nextentry
+
350 XFS_ATTR_SF_ENTSIZE(currententry
));
351 currentsize
= currentsize
+ XFS_ATTR_SF_ENTSIZE(currententry
);
355 if (asf
->hdr
.count
!= i
) {
358 _("would have corrected attribute entry count in inode %" PRIu64
" from %d to %d\n"),
359 ino
, asf
->hdr
.count
, i
);
362 _("corrected attribute entry count in inode %" PRIu64
", was %d, now %d\n"),
363 ino
, asf
->hdr
.count
, i
);
369 /* ASSUMPTION: currentsize <= totsize */
370 if (be16_to_cpu(asf
->hdr
.totsize
) != currentsize
) {
373 _("would have corrected attribute totsize in inode %" PRIu64
" from %d to %d\n"),
374 ino
, be16_to_cpu(asf
->hdr
.totsize
),
378 _("corrected attribute entry totsize in inode %" PRIu64
", was %d, now %d\n"),
379 ino
, be16_to_cpu(asf
->hdr
.totsize
),
381 asf
->hdr
.totsize
= cpu_to_be16(currentsize
);
389 /* This routine brings in blocks from disk one by one and assembles them
390 * in the value buffer. If get_bmapi gets smarter later to return an extent
391 * or list of extents, that would be great. For now, we don't expect too
392 * many blocks per remote value, so one by one is sufficient.
395 rmtval_get(xfs_mount_t
*mp
, xfs_ino_t ino
, blkmap_t
*blkmap
,
396 xfs_dablk_t blocknum
, int valuelen
, char* value
)
400 int clearit
= 0, i
= 0, length
= 0, amountdone
= 0;
403 if (xfs_sb_version_hascrc(&mp
->m_sb
))
404 hdrsize
= sizeof(struct xfs_attr3_rmt_hdr
);
406 /* ASSUMPTION: valuelen is a valid number, so use it for looping */
407 /* Note that valuelen is not a multiple of blocksize */
408 while (amountdone
< valuelen
) {
409 bno
= blkmap_get(blkmap
, blocknum
+ i
);
410 if (bno
== NULLFSBLOCK
) {
412 _("remote block for attributes of inode %" PRIu64
" is missing\n"), ino
);
416 bp
= libxfs_readbuf(mp
->m_dev
, XFS_FSB_TO_DADDR(mp
, bno
),
417 XFS_FSB_TO_BB(mp
, 1), 0,
418 &xfs_attr3_rmt_buf_ops
);
421 _("can't read remote block for attributes of inode %" PRIu64
"\n"), ino
);
426 if (bp
->b_error
== -EFSBADCRC
|| bp
->b_error
== -EFSCORRUPTED
) {
428 _("Corrupt remote block for attributes of inode %" PRIu64
"\n"), ino
);
434 ASSERT(mp
->m_sb
.sb_blocksize
== bp
->b_bcount
);
436 length
= min(bp
->b_bcount
- hdrsize
, valuelen
- amountdone
);
437 memmove(value
, bp
->b_addr
+ hdrsize
, length
);
438 amountdone
+= length
;
446 /* The block is read in. The magic number and forward / backward
447 * links are checked by the caller process_leaf_attr.
448 * If any problems occur the routine returns with non-zero. In
449 * this case the next step is to clear the attribute fork, by
450 * changing it to shortform and zeroing it out. Forkoff need not
455 process_leaf_attr_local(
456 struct xfs_mount
*mp
,
457 xfs_attr_leafblock_t
*leaf
,
459 xfs_attr_leaf_entry_t
*entry
,
460 xfs_dahash_t last_hashval
,
464 xfs_attr_leaf_name_local_t
*local
;
466 local
= xfs_attr3_leaf_name_local(leaf
, i
);
467 if (local
->namelen
== 0 || attr_namecheck(local
->nameval
,
470 _("attribute entry %d in attr block %u, inode %" PRIu64
" has bad name (namelen = %d)\n"),
471 i
, da_bno
, ino
, local
->namelen
);
475 /* Check on the hash value. Checking order of values
476 * is not necessary, since one wrong clears the whole
477 * fork. If the ordering's wrong, it's caught here or
478 * the kernel code has a bug with transaction logging
479 * or attributes itself. Being paranoid, let's check
480 * ordering anyway in case both the name value and the
481 * hashvalue were wrong but matched. Unlikely, however.
483 if (be32_to_cpu(entry
->hashval
) != libxfs_da_hashname(
484 &local
->nameval
[0], local
->namelen
) ||
485 be32_to_cpu(entry
->hashval
) < last_hashval
) {
487 _("bad hashvalue for attribute entry %d in attr block %u, inode %" PRIu64
"\n"),
492 /* Only check values for root security attributes */
493 if (entry
->flags
& XFS_ATTR_ROOT
) {
494 if (valuecheck(mp
, (char *)&local
->nameval
[0], NULL
,
495 local
->namelen
, be16_to_cpu(local
->valuelen
))) {
497 _("bad security value for attribute entry %d in attr block %u, inode %" PRIu64
"\n"),
502 return xfs_attr_leaf_entsize_local(local
->namelen
,
503 be16_to_cpu(local
->valuelen
));
507 process_leaf_attr_remote(
508 xfs_attr_leafblock_t
*leaf
,
510 xfs_attr_leaf_entry_t
*entry
,
511 xfs_dahash_t last_hashval
,
517 xfs_attr_leaf_name_remote_t
*remotep
;
520 remotep
= xfs_attr3_leaf_name_remote(leaf
, i
);
522 if (remotep
->namelen
== 0 || attr_namecheck(remotep
->name
,
524 be32_to_cpu(entry
->hashval
) !=
525 libxfs_da_hashname((unsigned char *)&remotep
->name
[0],
527 be32_to_cpu(entry
->hashval
) < last_hashval
||
528 be32_to_cpu(remotep
->valueblk
) == 0) {
530 _("inconsistent remote attribute entry %d in attr block %u, ino %" PRIu64
"\n"), i
, da_bno
, ino
);
534 value
= malloc(be32_to_cpu(remotep
->valuelen
));
537 _("cannot malloc enough for remotevalue attribute for inode %" PRIu64
"\n"),
539 do_warn(_("SKIPPING this remote attribute\n"));
542 if (rmtval_get(mp
, ino
, blkmap
, be32_to_cpu(remotep
->valueblk
),
543 be32_to_cpu(remotep
->valuelen
), value
)) {
545 _("remote attribute get failed for entry %d, inode %" PRIu64
"\n"),
549 if ((entry
->flags
& XFS_ATTR_ROOT
) &&
550 valuecheck(mp
, (char *)&remotep
->name
[0], value
, remotep
->namelen
,
551 be32_to_cpu(remotep
->valuelen
))) {
553 _("remote attribute value check failed for entry %d, inode %" PRIu64
"\n"),
559 return xfs_attr_leaf_entsize_remote(remotep
->namelen
);
567 process_leaf_attr_block(
569 xfs_attr_leafblock_t
*leaf
,
573 xfs_dahash_t last_hashval
,
574 xfs_dahash_t
*current_hashval
,
577 xfs_attr_leaf_entry_t
*entry
;
578 int i
, start
, stop
, clearit
, usedbs
, firstb
, thissize
;
579 da_freemap_t
*attr_freemap
;
580 struct xfs_attr3_icleaf_hdr leafhdr
;
582 xfs_attr3_leaf_hdr_from_disk(mp
->m_attr_geo
, &leafhdr
, leaf
);
583 clearit
= usedbs
= 0;
584 firstb
= mp
->m_sb
.sb_blocksize
;
585 stop
= xfs_attr3_leaf_hdr_size(leaf
);
587 /* does the count look sorta valid? */
588 if (!leafhdr
.count
||
589 leafhdr
.count
* sizeof(xfs_attr_leaf_entry_t
) + stop
>
590 mp
->m_sb
.sb_blocksize
) {
592 _("bad attribute count %d in attr block %u, inode %" PRIu64
"\n"),
593 leafhdr
.count
, da_bno
, ino
);
597 attr_freemap
= alloc_da_freemap(mp
);
598 (void) set_da_freemap(mp
, attr_freemap
, 0, stop
);
600 /* go thru each entry checking for problems */
601 for (i
= 0, entry
= xfs_attr3_leaf_entryp(leaf
);
602 i
< leafhdr
.count
; i
++, entry
++) {
604 /* check if index is within some boundary. */
605 if (be16_to_cpu(entry
->nameidx
) > mp
->m_sb
.sb_blocksize
) {
607 _("bad attribute nameidx %d in attr block %u, inode %" PRIu64
"\n"),
608 be16_to_cpu(entry
->nameidx
), da_bno
, ino
);
613 if (entry
->flags
& XFS_ATTR_INCOMPLETE
) {
614 /* we are inconsistent state. get rid of us */
616 _("attribute entry #%d in attr block %u, inode %" PRIu64
" is INCOMPLETE\n"),
622 /* mark the entry used */
623 start
= (intptr_t)entry
- (intptr_t)leaf
;
624 stop
= start
+ sizeof(xfs_attr_leaf_entry_t
);
625 if (set_da_freemap(mp
, attr_freemap
, start
, stop
)) {
627 _("attribute entry %d in attr block %u, inode %" PRIu64
" claims already used space\n"),
630 break; /* got an overlap */
633 if (entry
->flags
& XFS_ATTR_LOCAL
)
634 thissize
= process_leaf_attr_local(mp
, leaf
, i
, entry
,
635 last_hashval
, da_bno
, ino
);
637 thissize
= process_leaf_attr_remote(leaf
, i
, entry
,
638 last_hashval
, da_bno
, ino
,
645 *current_hashval
= last_hashval
= be32_to_cpu(entry
->hashval
);
647 if (set_da_freemap(mp
, attr_freemap
, be16_to_cpu(entry
->nameidx
),
648 be16_to_cpu(entry
->nameidx
) + thissize
)) {
650 _("attribute entry %d in attr block %u, inode %" PRIu64
" claims used space\n"),
653 break; /* got an overlap */
656 if (be16_to_cpu(entry
->nameidx
) < firstb
)
657 firstb
= be16_to_cpu(entry
->nameidx
);
662 /* verify the header information is correct */
664 /* if the holes flag is set, don't reset first_used unless it's
665 * pointing to used bytes. we're being conservative here
666 * since the block will get compacted anyhow by the kernel.
669 if ((leafhdr
.holes
== 0 &&
670 firstb
!= leafhdr
.firstused
) ||
671 leafhdr
.firstused
> firstb
) {
674 _("- resetting first used heap value from %d to %d in "
675 "block %u of attribute fork of inode %" PRIu64
"\n"),
677 firstb
, da_bno
, ino
);
678 leafhdr
.firstused
= firstb
;
682 _("- would reset first used value from %d to %d in "
683 "block %u of attribute fork of inode %" PRIu64
"\n"),
685 firstb
, da_bno
, ino
);
689 if (usedbs
!= leafhdr
.usedbytes
) {
692 _("- resetting usedbytes cnt from %d to %d in "
693 "block %u of attribute fork of inode %" PRIu64
"\n"),
695 usedbs
, da_bno
, ino
);
696 leafhdr
.usedbytes
= usedbs
;
700 _("- would reset usedbytes cnt from %d to %d in "
701 "block %u of attribute fork of %" PRIu64
"\n"),
703 usedbs
, da_bno
, ino
);
707 /* there's a lot of work in process_leaf_dir_block to go thru
708 * checking for holes and compacting if appropiate. I don't think
709 * attributes need all that, so let's just leave the holes. If
710 * we discover later that this is a good place to do compaction
711 * we can add it then.
715 * If we're just going to zap the block, don't pretend like we
716 * repaired it, because repairing the block stops the clear
722 xfs_attr3_leaf_hdr_to_disk(mp
->m_attr_geo
, leaf
, &leafhdr
);
725 return (clearit
); /* and repair */
730 * returns 0 if the attribute fork is ok, 1 if it has to be junked.
733 process_leaf_attr_level(xfs_mount_t
*mp
,
734 da_bt_cursor_t
*da_cursor
)
737 xfs_attr_leafblock_t
*leaf
;
740 xfs_fsblock_t dev_bno
;
742 xfs_dablk_t prev_bno
;
743 xfs_dahash_t current_hashval
= 0;
744 xfs_dahash_t greatest_hashval
;
745 struct xfs_attr3_icleaf_hdr leafhdr
;
747 da_bno
= da_cursor
->level
[0].bno
;
748 ino
= da_cursor
->ino
;
750 * 0 is the root block and no block
751 * pointer can point to the root block of the btree
755 _("btree cycle detected in attribute fork for inode %" PRIu64
"\n"),
764 dev_bno
= blkmap_get(da_cursor
->blkmap
, da_bno
);
765 if (dev_bno
== NULLFSBLOCK
) {
767 _("can't map block %u for attribute fork for inode %" PRIu64
"\n"),
772 bp
= libxfs_readbuf(mp
->m_dev
, XFS_FSB_TO_DADDR(mp
, dev_bno
),
773 XFS_FSB_TO_BB(mp
, 1), 0,
774 &xfs_attr3_leaf_buf_ops
);
777 _("can't read file block %u (fsbno %" PRIu64
") for attribute fork of inode %" PRIu64
"\n"),
778 da_bno
, dev_bno
, ino
);
783 xfs_attr3_leaf_hdr_from_disk(mp
->m_attr_geo
, &leafhdr
, leaf
);
785 /* check magic number for leaf directory btree block */
786 if (!(leafhdr
.magic
== XFS_ATTR_LEAF_MAGIC
||
787 leafhdr
.magic
== XFS_ATTR3_LEAF_MAGIC
)) {
789 _("bad attribute leaf magic %#x for inode %" PRIu64
"\n"),
796 * for each block, process the block, verify its path,
797 * then get next block. update cursor values along the way
799 if (process_leaf_attr_block(mp
, leaf
, da_bno
, ino
,
800 da_cursor
->blkmap
, current_hashval
,
801 &greatest_hashval
, &repair
)) {
807 * index can be set to hdr.count so match the
808 * indexes of the interior blocks -- which at the
809 * end of the block will point to 1 after the final
810 * real entry in the block
812 da_cursor
->level
[0].hashval
= greatest_hashval
;
813 da_cursor
->level
[0].bp
= bp
;
814 da_cursor
->level
[0].bno
= da_bno
;
815 da_cursor
->level
[0].index
= leafhdr
.count
;
816 da_cursor
->level
[0].dirty
= repair
;
818 if (leafhdr
.back
!= prev_bno
) {
820 _("bad sibling back pointer for block %u in attribute fork for inode %" PRIu64
"\n"),
827 da_bno
= leafhdr
.forw
;
830 if (verify_da_path(mp
, da_cursor
, 0, XFS_ATTR_FORK
)) {
836 current_hashval
= greatest_hashval
;
838 * If block looks ok but CRC didn't match, make sure to
841 if (!no_modify
&& bp
->b_error
== -EFSBADCRC
)
844 if (repair
&& !no_modify
)
845 libxfs_writebuf(bp
, 0);
848 } while (da_bno
!= 0);
850 if (verify_final_da_path(mp
, da_cursor
, 0, XFS_ATTR_FORK
)) {
852 * verify the final path up (right-hand-side) if still ok
855 _("bad hash path in attribute fork for inode %" PRIu64
"\n"),
860 /* releases all buffers holding interior btree blocks */
861 release_da_cursor(mp
, da_cursor
, 0);
865 /* release all buffers holding interior btree blocks */
866 err_release_da_cursor(mp
, da_cursor
, 0);
872 * a node directory is a true btree -- where the attribute fork
873 * has gotten big enough that it is represented as a non-trivial (e.g.
874 * has more than just a block) btree.
876 * Note that if we run into any problems, we will trash the attribute fork.
878 * returns 0 if things are ok, 1 if bad
879 * Note this code has been based off process_node_dir.
890 da_bt_cursor_t da_cursor
;
893 * try again -- traverse down left-side of tree until we hit
894 * the left-most leaf block setting up the btree cursor along
895 * the way. Then walk the leaf blocks left-to-right, calling
896 * a parent-verification routine each time we traverse a block.
898 memset(&da_cursor
, 0, sizeof(da_bt_cursor_t
));
899 da_cursor
.active
= 0;
902 da_cursor
.greatest_bno
= 0;
903 da_cursor
.blkmap
= blkmap
;
906 * now process interior node. don't have any buffers held in this path.
908 error
= traverse_int_dablock(mp
, &da_cursor
, &bno
, XFS_ATTR_FORK
);
910 return(1); /* 0 means unsuccessful */
913 * now pass cursor and bno into leaf-block processing routine
914 * the leaf dir level routine checks the interior paths
915 * up to the root including the final right-most path.
918 return (process_leaf_attr_level(mp
, &da_cursor
));
921 /* check v5 metadata */
924 struct xfs_mount
*mp
,
928 struct xfs_da3_blkinfo
*info
= bp
->b_addr
;
930 if (info
->hdr
.magic
!= cpu_to_be16(XFS_ATTR3_LEAF_MAGIC
) &&
931 info
->hdr
.magic
!= cpu_to_be16(XFS_DA3_NODE_MAGIC
))
935 if (be64_to_cpu(info
->owner
) != ino
) {
937 _("expected owner inode %" PRIu64
", got %llu, attr block %" PRIu64
"\n"),
938 ino
, (unsigned long long)be64_to_cpu(info
->owner
),
942 /* verify block number */
943 if (be64_to_cpu(info
->blkno
) != bp
->b_bn
) {
945 _("expected block %" PRIu64
", got %llu, inode %" PRIu64
"attr block\n"),
946 bp
->b_bn
, (unsigned long long)be64_to_cpu(info
->blkno
),
951 if (platform_uuid_compare(&info
->uuid
, &mp
->m_sb
.sb_meta_uuid
) != 0) {
953 _("wrong FS UUID, inode %" PRIu64
" attr block %" PRIu64
"\n"),
962 * Start processing for a leaf or fuller btree.
963 * A leaf directory is one where the attribute fork is too big for
964 * the inode but is small enough to fit into one btree block
965 * outside the inode. This code is modelled after process_leaf_dir_block.
967 * returns 0 if things are ok, 1 if bad (attributes needs to be junked)
968 * repair is set, if anything was changed, but attributes can live thru it
971 process_longform_attr(
976 int *repair
) /* out - 1 if something was fixed */
978 xfs_attr_leafblock_t
*leaf
;
981 xfs_dahash_t next_hashval
;
983 struct xfs_attr3_icleaf_hdr leafhdr
;
988 bno
= blkmap_get(blkmap
, 0);
990 if ( bno
== NULLFSBLOCK
) {
991 if (dip
->di_aformat
== XFS_DINODE_FMT_EXTENTS
&&
992 be16_to_cpu(dip
->di_anextents
) == 0)
993 return(0); /* the kernel can handle this state */
995 _("block 0 of inode %" PRIu64
" attribute fork is missing\n"),
999 /* FIX FOR bug 653709 -- EKN */
1000 if (mp
->m_sb
.sb_agcount
< XFS_FSB_TO_AGNO(mp
, bno
)) {
1002 _("agno of attribute fork of inode %" PRIu64
" out of regular partition\n"), ino
);
1006 bp
= libxfs_readbuf(mp
->m_dev
, XFS_FSB_TO_DADDR(mp
, bno
),
1007 XFS_FSB_TO_BB(mp
, 1), 0, &xfs_da3_node_buf_ops
);
1010 _("can't read block 0 of inode %" PRIu64
" attribute fork\n"),
1014 if (bp
->b_error
== -EFSBADCRC
)
1017 /* is this block sane? */
1018 if (__check_attr_header(mp
, bp
, ino
)) {
1024 /* verify leaf block */
1026 xfs_attr3_leaf_hdr_from_disk(mp
->m_attr_geo
, &leafhdr
, leaf
);
1028 /* check sibling pointers in leaf block or root block 0 before
1029 * we have to release the btree block
1031 if (leafhdr
.forw
!= 0 || leafhdr
.back
!= 0) {
1034 _("clearing forw/back pointers in block 0 for attributes in inode %" PRIu64
"\n"),
1039 xfs_attr3_leaf_hdr_to_disk(mp
->m_attr_geo
,
1043 _("would clear forw/back pointers in block 0 for attributes in inode %" PRIu64
"\n"), ino
);
1048 * use magic number to tell us what type of attribute this is.
1049 * it's possible to have a node or leaf attribute in either an
1050 * extent format or btree format attribute fork.
1052 switch (leafhdr
.magic
) {
1053 case XFS_ATTR_LEAF_MAGIC
: /* leaf-form attribute */
1054 case XFS_ATTR3_LEAF_MAGIC
:
1055 if (process_leaf_attr_block(mp
, leaf
, 0, ino
, blkmap
,
1056 0, &next_hashval
, repair
)) {
1058 /* the block is bad. lose the attribute fork. */
1062 *repair
= *repair
|| repairlinks
;
1065 case XFS_DA_NODE_MAGIC
: /* btree-form attribute */
1066 case XFS_DA3_NODE_MAGIC
:
1067 /* must do this now, to release block 0 before the traversal */
1068 if ((*repair
|| repairlinks
) && !no_modify
) {
1070 libxfs_writebuf(bp
, 0);
1073 error
= process_node_attr(mp
, ino
, dip
, blkmap
); /* + repair */
1079 _("bad attribute leaf magic # %#x for dir ino %" PRIu64
"\n"),
1080 be16_to_cpu(leaf
->hdr
.info
.magic
), ino
);
1086 if (*repair
&& !no_modify
)
1087 libxfs_writebuf(bp
, 0);
1091 return(0); /* repair may be set */
1097 struct xfs_mount
*mp
,
1098 struct xfs_icacl
**aclp
,
1099 struct xfs_acl
*dacl
)
1101 struct xfs_icacl
*acl
;
1102 struct xfs_icacl_entry
*ace
;
1103 struct xfs_acl_entry
*dace
;
1107 count
= be32_to_cpu(dacl
->acl_cnt
);
1108 if (count
> XFS_ACL_MAX_ENTRIES(mp
)) {
1109 do_warn(_("Too many ACL entries, count %d\n"), count
);
1115 acl
= malloc(sizeof(struct xfs_icacl
) +
1116 count
* sizeof(struct xfs_icacl_entry
));
1118 do_warn(_("cannot malloc enough for ACL attribute\n"));
1119 do_warn(_("SKIPPING this ACL\n"));
1124 acl
->acl_cnt
= count
;
1125 for (i
= 0; i
< count
; i
++) {
1126 ace
= &acl
->acl_entry
[i
];
1127 dace
= &dacl
->acl_entry
[i
];
1129 ace
->ae_tag
= be32_to_cpu(dace
->ae_tag
);
1130 ace
->ae_id
= be32_to_cpu(dace
->ae_id
);
1131 ace
->ae_perm
= be16_to_cpu(dace
->ae_perm
);
1139 * returns 1 if attributes got cleared
1140 * and 0 if things are ok.
1148 int *repair
) /* returned if we did repair */
1151 __u8 aformat
= dip
->di_aformat
;
1153 xfs_attr_shortform_t
*asf
;
1155 asf
= (xfs_attr_shortform_t
*) XFS_DFORK_APTR(dip
);
1158 if (aformat
== XFS_DINODE_FMT_LOCAL
) {
1159 ASSERT(be16_to_cpu(asf
->hdr
.totsize
) <=
1160 XFS_DFORK_ASIZE(dip
, mp
));
1161 err
= process_shortform_attr(mp
, ino
, dip
, repair
);
1162 } else if (aformat
== XFS_DINODE_FMT_EXTENTS
||
1163 aformat
== XFS_DINODE_FMT_BTREE
) {
1164 err
= process_longform_attr(mp
, ino
, dip
, blkmap
,
1166 /* if err, convert this to shortform and clear it */
1167 /* if repair and no error, it's taken care of */
1169 do_warn(_("illegal attribute format %d, ino %" PRIu64
"\n"),
1173 return (err
); /* and repair */
1181 struct xfs_mount
*mp
,
1182 struct xfs_acl
*daclp
)
1184 struct xfs_icacl
*aclp
= NULL
;
1185 struct xfs_icacl_entry
*entry
, *e
;
1186 int user
= 0, group
= 0, other
= 0, mask
= 0, mask_required
= 0;
1192 switch (xfs_acl_from_disk(mp
, &aclp
, daclp
)) {
1201 for (i
= 0; i
< aclp
->acl_cnt
; i
++) {
1202 entry
= &aclp
->acl_entry
[i
];
1203 if (entry
->ae_perm
& ~(ACL_READ
|ACL_WRITE
|ACL_EXECUTE
))
1205 switch (entry
->ae_tag
) {
1220 for (j
= i
+ 1; j
< aclp
->acl_cnt
; j
++) {
1221 e
= &aclp
->acl_entry
[j
];
1222 if (e
->ae_id
== entry
->ae_id
&&
1223 e
->ae_tag
== entry
->ae_tag
)
1236 if (!user
|| !group
|| !other
|| (mask_required
&& !mask
))
1247 * Check a category or division set to ensure that all values are in
1248 * ascending order and each division or category appears only once.
1251 __check_setvalue(const unsigned short *list
, unsigned short count
)
1255 for (i
= 1; i
< count
; i
++)
1256 if (list
[i
] <= list
[i
-1])
1263 * Check the validity of a MAC label.
1266 xfs_mac_valid(xfs_mac_label_t
*lp
)
1272 * if the total category set and division set is greater than 250
1275 if ((lp
->ml_catcount
+ lp
->ml_divcount
) > XFS_MAC_MAX_SETS
)
1279 * check whether the msentype value is valid, and do they have
1280 * appropriate level, category association.
1282 switch (lp
->ml_msen_type
) {
1283 case XFS_MSEN_ADMIN_LABEL
:
1284 case XFS_MSEN_EQUAL_LABEL
:
1285 case XFS_MSEN_HIGH_LABEL
:
1286 case XFS_MSEN_MLD_HIGH_LABEL
:
1287 case XFS_MSEN_LOW_LABEL
:
1288 case XFS_MSEN_MLD_LOW_LABEL
:
1289 if (lp
->ml_level
!= 0 || lp
->ml_catcount
> 0 )
1292 case XFS_MSEN_TCSEC_LABEL
:
1293 case XFS_MSEN_MLD_LABEL
:
1294 if (lp
->ml_catcount
> 0 &&
1295 __check_setvalue(lp
->ml_list
,
1296 lp
->ml_catcount
) == -1)
1299 case XFS_MSEN_UNKNOWN_LABEL
:
1305 * check whether the minttype value is valid, and do they have
1306 * appropriate grade, division association.
1308 switch (lp
->ml_mint_type
) {
1309 case XFS_MINT_BIBA_LABEL
:
1310 if (lp
->ml_divcount
> 0 &&
1311 __check_setvalue(lp
->ml_list
+ lp
->ml_catcount
,
1312 lp
->ml_divcount
) == -1)
1315 case XFS_MINT_EQUAL_LABEL
:
1316 case XFS_MINT_HIGH_LABEL
:
1317 case XFS_MINT_LOW_LABEL
:
1318 if (lp
->ml_grade
!= 0 || lp
->ml_divcount
> 0 )