2 * Copyright (c) 2000-2002,2004-2005 Silicon Graphics, Inc.
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.
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.
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
21 #include "err_protos.h"
22 #include "attr_repair.h"
28 static int xfs_acl_valid(xfs_acl_disk_t
*daclp
);
29 static int xfs_mac_valid(xfs_mac_label_t
*lp
);
32 * da node check/verify functions that the attribute tree relies on are first in
33 * the file before the actual attribute code. This used to be shared with the
34 * dir v1 code, but that format is no longer supported yb the userspace
35 * utilities and hence is now specific to the attribute tree implementation.
37 #define XR_DA_LEAF_MAPSIZE XFS_ATTR_LEAF_MAPSIZE
39 typedef unsigned char da_freemap_t
;
42 * the cursor gets passed up and down the da btree processing
43 * routines. The interior block processing routines use the
44 * cursor to determine if the pointers to and from the preceding
45 * and succeeding sibling blocks are ok and whether the values in
46 * the current block are consistent with the entries in the parent
47 * nodes. When a block is traversed, a parent-verification routine
48 * is called to verify if the next logical entry in the next level up
49 * is consistent with the greatest hashval in the next block of the
50 * current level. The verification routine is itself recursive and
51 * calls itself if it has to traverse an interior block to get
52 * the next logical entry. The routine recurses upwards through
53 * the tree until it finds a block where it can simply step to
54 * the next entry. The hashval in that entry should be equal to
55 * the hashval being passed to it (the greatest hashval in the block
56 * that the entry points to). If that isn't true, then the tree
57 * is blown and we need to trash it, salvage and trash it, or fix it.
58 * Currently, we just trash it.
60 typedef struct da_level_state
{
61 xfs_buf_t
*bp
; /* block bp */
63 xfs_da_intnode_t
*n
; /* bp data */
65 xfs_dablk_t bno
; /* file block number */
66 xfs_dahash_t hashval
; /* last verified hashval */
67 int index
; /* current index in block */
68 int dirty
; /* is buffer dirty ? (1 == yes) */
71 typedef struct da_bt_cursor
{
72 int active
; /* highest level in tree (# levels-1) */
73 int type
; /* 0 if dir, 1 if attr */
75 xfs_dablk_t greatest_bno
;
77 da_level_state_t level
[XFS_DA_NODE_MAXDEPTH
];
78 struct blkmap
*blkmap
;
83 * Allocate a freespace map for directory or attr leaf blocks (1 bit per byte)
84 * 1 == used, 0 == free.
87 alloc_da_freemap(struct xfs_mount
*mp
)
89 return calloc(1, mp
->m_sb
.sb_blocksize
/ NBBY
);
93 * Set the he range [start, stop) in the directory freemap.
95 * Returns 1 if there is a conflict or 0 if everything's good.
97 * Within a char, the lowest bit of the char represents the byte with
98 * the smallest address
101 set_da_freemap(xfs_mount_t
*mp
, da_freemap_t
*map
, int start
, int stop
)
103 const da_freemap_t mask
= 0x1;
108 * allow == relation since [x, x) claims 1 byte
110 do_warn(_("bad range claimed [%d, %d) in da block\n"),
115 if (stop
> mp
->m_sb
.sb_blocksize
) {
117 _("byte range end [%d %d) in da block larger than blocksize %d\n"),
118 start
, stop
, mp
->m_sb
.sb_blocksize
);
122 for (i
= start
; i
< stop
; i
++) {
123 if (map
[i
/ NBBY
] & (mask
<< i
% NBBY
)) {
124 do_warn(_("multiply claimed byte %d in da block\n"), i
);
127 map
[i
/ NBBY
] |= (mask
<< i
% NBBY
);
134 * walk tree from root to the left-most leaf block reading in
135 * blocks and setting up cursor. passes back file block number of the
136 * left-most leaf block if successful (bno). returns 1 if successful,
140 traverse_int_dablock(xfs_mount_t
*mp
,
141 da_bt_cursor_t
*da_cursor
,
147 xfs_da_intnode_t
*node
;
150 struct xfs_da_node_entry
*btree
;
151 struct xfs_da3_icnode_hdr nodehdr
;
154 * traverse down left-side of tree until we hit the
155 * left-most leaf block setting up the btree cursor along
161 da_cursor
->active
= 0;
165 * read in each block along the way and set up cursor
167 fsbno
= blkmap_get(da_cursor
->blkmap
, bno
);
169 if (fsbno
== NULLDFSBNO
)
172 bp
= libxfs_readbuf(mp
->m_dev
, XFS_FSB_TO_DADDR(mp
, fsbno
),
173 XFS_FSB_TO_BB(mp
, 1), 0, &xfs_da3_node_buf_ops
);
175 if (whichfork
== XFS_DATA_FORK
)
177 _("can't read block %u (fsbno %" PRIu64
") for directory inode %" PRIu64
"\n"),
178 bno
, fsbno
, da_cursor
->ino
);
181 _("can't read block %u (fsbno %" PRIu64
") for attrbute fork of inode %" PRIu64
"\n"),
182 bno
, fsbno
, da_cursor
->ino
);
186 node
= (xfs_da_intnode_t
*)XFS_BUF_PTR(bp
);
187 btree
= xfs_da3_node_tree_p(node
);
188 xfs_da3_node_hdr_from_disk(&nodehdr
, node
);
190 if (nodehdr
.magic
!= XFS_DA_NODE_MAGIC
&&
191 nodehdr
.magic
!= XFS_DA3_NODE_MAGIC
) {
192 do_warn(_("bad dir/attr magic number in inode %" PRIu64
", "
193 "file bno = %u, fsbno = %" PRIu64
"\n"),
194 da_cursor
->ino
, bno
, fsbno
);
199 if (nodehdr
.count
> mp
->m_dir_node_ents
) {
200 do_warn(_("bad record count in inode %" PRIu64
", "
201 "count = %d, max = %d\n"),
204 mp
->m_dir_node_ents
);
210 * maintain level counter
213 i
= da_cursor
->active
= nodehdr
.level
;
215 if (nodehdr
.level
== i
- 1) {
218 if (whichfork
== XFS_DATA_FORK
)
219 do_warn(_("bad directory btree for "
220 "directory inode %" PRIu64
"\n"),
223 do_warn(_("bad attribute fork btree "
224 "for inode %" PRIu64
"\n"),
231 da_cursor
->level
[i
].hashval
= be32_to_cpu(btree
[0].hashval
);
232 da_cursor
->level
[i
].bp
= bp
;
233 da_cursor
->level
[i
].bno
= bno
;
234 da_cursor
->level
[i
].index
= 0;
236 da_cursor
->level
[i
].n
= XFS_BUF_TO_DA_INTNODE(bp
);
240 * set up new bno for next level down
242 bno
= be32_to_cpu(btree
[0].before
);
243 } while (node
!= NULL
&& i
> 1);
246 * now return block number and get out
248 *rbno
= da_cursor
->level
[0].bno
= bno
;
252 while (i
> 1 && i
<= da_cursor
->active
) {
253 libxfs_putbuf(da_cursor
->level
[i
].bp
);
261 * blow out buffer for this level and all the rest above as well
262 * if error == 0, we are not expecting to encounter any unreleased
263 * buffers (e.g. if we do, it's a mistake). if error == 1, we're
264 * in an error-handling case so unreleased buffers may exist.
267 release_da_cursor_int(xfs_mount_t
*mp
,
268 da_bt_cursor_t
*cursor
,
272 int level
= prev_level
+ 1;
274 if (cursor
->level
[level
].bp
!= NULL
) {
276 do_warn(_("release_da_cursor_int got unexpected "
277 "non-null bp, dabno = %u\n"),
278 cursor
->level
[level
].bno
);
282 libxfs_putbuf(cursor
->level
[level
].bp
);
283 cursor
->level
[level
].bp
= NULL
;
286 if (level
< cursor
->active
)
287 release_da_cursor_int(mp
, cursor
, level
, error
);
293 release_da_cursor(xfs_mount_t
*mp
,
294 da_bt_cursor_t
*cursor
,
297 release_da_cursor_int(mp
, cursor
, prev_level
, 0);
301 err_release_da_cursor(xfs_mount_t
*mp
,
302 da_bt_cursor_t
*cursor
,
305 release_da_cursor_int(mp
, cursor
, prev_level
, 1);
309 * make sure that all entries in all blocks along the right side of
310 * of the tree are used and hashval's are consistent. level is the
311 * level of the descendent block. returns 0 if good (even if it had
312 * to be fixed up), and 1 if bad. The right edge of the tree is
313 * technically a block boundary. this routine should be used then
314 * instead of verify_da_path().
317 verify_final_da_path(xfs_mount_t
*mp
,
318 da_bt_cursor_t
*cursor
,
321 xfs_da_intnode_t
*node
;
322 xfs_dahash_t hashval
;
325 int this_level
= p_level
+ 1;
326 struct xfs_da_node_entry
*btree
;
327 struct xfs_da3_icnode_hdr nodehdr
;
330 fprintf(stderr
, "in verify_final_da_path, this_level = %d\n",
334 * the index should point to the next "unprocessed" entry
335 * in the block which should be the final (rightmost) entry
337 entry
= cursor
->level
[this_level
].index
;
338 node
= (xfs_da_intnode_t
*)XFS_BUF_PTR(cursor
->level
[this_level
].bp
);
339 btree
= xfs_da3_node_tree_p(node
);
340 xfs_da3_node_hdr_from_disk(&nodehdr
, node
);
343 * check internal block consistency on this level -- ensure
344 * that all entries are used, encountered and expected hashvals
347 if (entry
!= nodehdr
.count
- 1) {
348 do_warn(_("directory/attribute block used/count "
349 "inconsistency - %d/%hu\n"),
350 entry
, nodehdr
.count
);
354 * hash values monotonically increasing ???
356 if (cursor
->level
[this_level
].hashval
>=
357 be32_to_cpu(btree
[entry
].hashval
)) {
358 do_warn(_("directory/attribute block hashvalue inconsistency, "
359 "expected > %u / saw %u\n"),
360 cursor
->level
[this_level
].hashval
,
361 be32_to_cpu(btree
[entry
].hashval
));
364 if (nodehdr
.forw
!= 0) {
365 do_warn(_("bad directory/attribute forward block pointer, "
366 "expected 0, saw %u\n"),
371 do_warn(_("bad directory block in dir ino %" PRIu64
"\n"),
376 * keep track of greatest block # -- that gets
377 * us the length of the directory
379 if (cursor
->level
[this_level
].bno
> cursor
->greatest_bno
)
380 cursor
->greatest_bno
= cursor
->level
[this_level
].bno
;
383 * ok, now check descendant block number against this level
385 if (cursor
->level
[p_level
].bno
!= be32_to_cpu(btree
[entry
].before
)) {
387 fprintf(stderr
, "bad directory btree pointer, child bno should "
388 "be %d, block bno is %d, hashval is %u\n",
389 be16_to_cpu(btree
[entry
].before
),
390 cursor
->level
[p_level
].bno
,
391 cursor
->level
[p_level
].hashval
);
392 fprintf(stderr
, "verify_final_da_path returns 1 (bad) #1a\n");
397 if (cursor
->level
[p_level
].hashval
!= be32_to_cpu(btree
[entry
].hashval
)) {
399 do_warn(_("correcting bad hashval in non-leaf "
400 "dir/attr block\n\tin (level %d) in "
401 "inode %" PRIu64
".\n"),
402 this_level
, cursor
->ino
);
403 btree
[entry
].hashval
= cpu_to_be32(
404 cursor
->level
[p_level
].hashval
);
405 cursor
->level
[this_level
].dirty
++;
407 do_warn(_("would correct bad hashval in non-leaf "
408 "dir/attr block\n\tin (level %d) in "
409 "inode %" PRIu64
".\n"),
410 this_level
, cursor
->ino
);
415 * Note: squirrel hashval away _before_ releasing the
416 * buffer, preventing a use-after-free problem.
418 hashval
= be32_to_cpu(btree
[entry
].hashval
);
421 * release/write buffer
423 ASSERT(cursor
->level
[this_level
].dirty
== 0 ||
424 (cursor
->level
[this_level
].dirty
&& !no_modify
));
426 if (cursor
->level
[this_level
].dirty
&& !no_modify
)
427 libxfs_writebuf(cursor
->level
[this_level
].bp
, 0);
429 libxfs_putbuf(cursor
->level
[this_level
].bp
);
431 cursor
->level
[this_level
].bp
= NULL
;
434 * bail out if this is the root block (top of tree)
436 if (this_level
>= cursor
->active
) {
438 fprintf(stderr
, "verify_final_da_path returns 0 (ok)\n");
443 * set hashvalue to correctly reflect the now-validated
444 * last entry in this block and continue upwards validation
446 cursor
->level
[this_level
].hashval
= hashval
;
447 return(verify_final_da_path(mp
, cursor
, this_level
));
451 * Verifies the path from a descendant block up to the root.
452 * Should be called when the descendant level traversal hits
453 * a block boundary before crossing the boundary (reading in a new
456 * the directory/attr btrees work differently to the other fs btrees.
457 * each interior block contains records that are <hashval, bno>
458 * pairs. The bno is a file bno, not a filesystem bno. The last
459 * hashvalue in the block <bno> will be <hashval>. BUT unlike
460 * the freespace btrees, the *last* value in each block gets
461 * propagated up the tree instead of the first value in each block.
462 * that is, the interior records point to child blocks and the *greatest*
463 * hash value contained by the child block is the one the block above
464 * uses as the key for the child block.
466 * level is the level of the descendent block. returns 0 if good,
467 * and 1 if bad. The descendant block may be a leaf block.
469 * the invariant here is that the values in the cursor for the
470 * levels beneath this level (this_level) and the cursor index
471 * for this level *must* be valid.
473 * that is, the hashval/bno info is accurate for all
474 * DESCENDANTS and match what the node[index] information
475 * for the current index in the cursor for this level.
477 * the index values in the cursor for the descendant level
478 * are allowed to be off by one as they will reflect the
479 * next entry at those levels to be processed.
481 * the hashvalue for the current level can't be set until
482 * we hit the last entry in the block so, it's garbage
483 * until set by this routine.
485 * bno and bp for the current block/level are always valid
486 * since they have to be set so we can get a buffer for the
490 verify_da_path(xfs_mount_t
*mp
,
491 da_bt_cursor_t
*cursor
,
494 xfs_da_intnode_t
*node
;
495 xfs_da_intnode_t
*newnode
;
501 int this_level
= p_level
+ 1;
502 struct xfs_da_node_entry
*btree
;
503 struct xfs_da3_icnode_hdr nodehdr
;
506 * index is currently set to point to the entry that
507 * should be processed now in this level.
509 entry
= cursor
->level
[this_level
].index
;
510 node
= (xfs_da_intnode_t
*)XFS_BUF_PTR(cursor
->level
[this_level
].bp
);
511 btree
= xfs_da3_node_tree_p(node
);
512 xfs_da3_node_hdr_from_disk(&nodehdr
, node
);
515 * if this block is out of entries, validate this
516 * block and move on to the next block.
517 * and update cursor value for said level
519 if (entry
>= nodehdr
.count
) {
521 * update the hash value for this level before
522 * validating it. bno value should be ok since
523 * it was set when the block was first read in.
525 cursor
->level
[this_level
].hashval
=
526 be32_to_cpu(btree
[entry
- 1].hashval
);
529 * keep track of greatest block # -- that gets
530 * us the length of the directory
532 if (cursor
->level
[this_level
].bno
> cursor
->greatest_bno
)
533 cursor
->greatest_bno
= cursor
->level
[this_level
].bno
;
536 * validate the path for the current used-up block
539 if (verify_da_path(mp
, cursor
, this_level
))
542 * ok, now get the next buffer and check sibling pointers
544 dabno
= nodehdr
.forw
;
546 fsbno
= blkmap_get(cursor
->blkmap
, dabno
);
548 if (fsbno
== NULLDFSBNO
) {
549 do_warn(_("can't get map info for block %u "
550 "of directory inode %" PRIu64
"\n"),
555 bp
= libxfs_readbuf(mp
->m_dev
, XFS_FSB_TO_DADDR(mp
, fsbno
),
556 XFS_FSB_TO_BB(mp
, 1), 0, &xfs_da3_node_buf_ops
);
559 _("can't read block %u (%" PRIu64
") for directory inode %" PRIu64
"\n"),
560 dabno
, fsbno
, cursor
->ino
);
564 newnode
= (xfs_da_intnode_t
*)XFS_BUF_PTR(bp
);
565 btree
= xfs_da3_node_tree_p(node
);
566 xfs_da3_node_hdr_from_disk(&nodehdr
, newnode
);
568 * verify magic number and back pointer, sanity-check
569 * entry count, verify level
572 if (nodehdr
.magic
!= XFS_DA_NODE_MAGIC
||
573 nodehdr
.magic
!= XFS_DA3_NODE_MAGIC
) {
575 _("bad magic number %x in block %u (%" PRIu64
") for directory inode %" PRIu64
"\n"),
577 dabno
, fsbno
, cursor
->ino
);
580 if (nodehdr
.back
!= cursor
->level
[this_level
].bno
) {
582 _("bad back pointer in block %u (%"PRIu64
") for directory inode %" PRIu64
"\n"),
583 dabno
, fsbno
, cursor
->ino
);
586 if (nodehdr
.count
> mp
->m_dir_node_ents
) {
588 _("entry count %d too large in block %u (%" PRIu64
") for directory inode %" PRIu64
"\n"),
590 dabno
, fsbno
, cursor
->ino
);
593 if (nodehdr
.level
!= this_level
) {
595 _("bad level %d in block %u (%" PRIu64
") for directory inode %" PRIu64
"\n"),
597 dabno
, fsbno
, cursor
->ino
);
602 fprintf(stderr
, "verify_da_path returns 1 (bad) #4\n");
608 * update cursor, write out the *current* level if
609 * required. don't write out the descendant level
611 ASSERT(cursor
->level
[this_level
].dirty
== 0 ||
612 (cursor
->level
[this_level
].dirty
&& !no_modify
));
614 if (cursor
->level
[this_level
].dirty
&& !no_modify
)
615 libxfs_writebuf(cursor
->level
[this_level
].bp
, 0);
617 libxfs_putbuf(cursor
->level
[this_level
].bp
);
618 cursor
->level
[this_level
].bp
= bp
;
619 cursor
->level
[this_level
].dirty
= 0;
620 cursor
->level
[this_level
].bno
= dabno
;
621 cursor
->level
[this_level
].hashval
=
622 be32_to_cpu(btree
[0].hashval
);
624 cursor
->level
[this_level
].n
= newnode
;
626 entry
= cursor
->level
[this_level
].index
= 0;
629 * ditto for block numbers
631 if (cursor
->level
[p_level
].bno
!= be32_to_cpu(btree
[entry
].before
)) {
633 fprintf(stderr
, "bad directory btree pointer, child bno "
634 "should be %d, block bno is %d, hashval is %u\n",
635 be32_to_cpu(btree
[entry
].before
),
636 cursor
->level
[p_level
].bno
,
637 cursor
->level
[p_level
].hashval
);
638 fprintf(stderr
, "verify_da_path returns 1 (bad) #1a\n");
643 * ok, now validate last hashvalue in the descendant
644 * block against the hashval in the current entry
646 if (cursor
->level
[p_level
].hashval
!=
647 be32_to_cpu(btree
[entry
].hashval
)) {
649 do_warn(_("correcting bad hashval in interior "
650 "dir/attr block\n\tin (level %d) in "
651 "inode %" PRIu64
".\n"),
652 this_level
, cursor
->ino
);
653 btree
[entry
].hashval
= cpu_to_be32(
654 cursor
->level
[p_level
].hashval
);
655 cursor
->level
[this_level
].dirty
++;
657 do_warn(_("would correct bad hashval in interior "
658 "dir/attr block\n\tin (level %d) in "
659 "inode %" PRIu64
".\n"),
660 this_level
, cursor
->ino
);
664 * increment index for this level to point to next entry
665 * (which should point to the next descendant block)
667 cursor
->level
[this_level
].index
++;
669 fprintf(stderr
, "verify_da_path returns 0 (ok)\n");
675 * For attribute repair, there are 3 formats to worry about. First, is
676 * shortform attributes which reside in the inode. Second is the leaf
677 * form, and lastly the btree. Much of this models after the directory
678 * structure so code resembles the directory repair cases.
679 * For shortform case, if an attribute looks corrupt, it is removed.
680 * If that leaves the shortform down to 0 attributes, it's okay and
681 * will appear to just have a null attribute fork. Some checks are done
682 * for validity of the value field based on what the security needs are.
683 * Calls will be made to xfs_mac_valid or xfs_acl_valid routines if the
684 * security attributes exist. They will be cleared if invalid.
685 * No other values will be checked. The DMF folks do not have current
686 * requirements, but may in the future.
688 * For leaf block attributes, it requires more processing. One sticky
689 * point is that the attributes can be local (within the leaf) or
690 * remote (outside the leaf in other blocks). Thinking of local only
691 * if you get a bad attribute, and want to delete just one, it's a-okay
692 * if it remains large enough to still be a leaf block attribute. Otherwise,
693 * it may have to be converted to shortform. How to convert this and when
694 * is an issue. This call is happening in Phase3. Phase5 will capture empty
695 * blocks, but Phase6 allows you to use the libxfs library which knows
696 * how to handle attributes in the kernel for converting formats. What we
697 * could do is mark an attribute to be cleared now, but in phase6 somehow
698 * have it cleared for real and then the format changed to shortform if
699 * applicable. Since this requires more work than I anticipate can be
700 * accomplished for the next release, we will instead just say any bad
701 * attribute in the leaf block will make the entire attribute fork be
702 * cleared. The simplest way to do that is to ignore the leaf format, and
703 * call clear_dinode_attr to just make a shortform attribute fork with
706 * Another issue with handling repair on leaf attributes is the remote
707 * blocks. To make sure that they look good and are not used multiple times
708 * by the attribute fork, some mechanism to keep track of all them is necessary.
709 * Do this in the future, time permitting. For now, note that there is no
710 * check for remote blocks and their allocations.
712 * For btree formatted attributes, the model can follow directories. That
713 * would mean go down the tree to the leftmost leaf. From there moving down
714 * the links and processing each. They would call back up the tree, to verify
715 * that the tree structure is okay. Any problems will result in the attribute
716 * fork being emptied and put in shortform format.
720 * This routine just checks what security needs are for attribute values
721 * only called when root flag is set, otherwise these names could exist in
722 * in user attribute land without a conflict.
723 * If value is non-zero, then a remote attribute is being passed in
726 valuecheck(char *namevalue
, char *value
, int namelen
, int valuelen
)
728 /* for proper alignment issues, get the structs and memmove the values */
729 xfs_mac_label_t macl
;
734 if ((strncmp(namevalue
, SGI_ACL_FILE
, SGI_ACL_FILE_SIZE
) == 0) ||
735 (strncmp(namevalue
, SGI_ACL_DEFAULT
,
736 SGI_ACL_DEFAULT_SIZE
) == 0)) {
738 memset(&thisacl
, 0, sizeof(xfs_acl_t
));
739 memmove(&thisacl
, namevalue
+namelen
, valuelen
);
744 if (xfs_acl_valid((xfs_acl_disk_t
*)valuep
) != 0) {
747 _("entry contains illegal value in attribute named SGI_ACL_FILE "
748 "or SGI_ACL_DEFAULT\n"));
750 } else if (strncmp(namevalue
, SGI_MAC_FILE
, SGI_MAC_FILE_SIZE
) == 0) {
752 memset(&macl
, 0, sizeof(xfs_mac_label_t
));
753 memmove(&macl
, namevalue
+namelen
, valuelen
);
758 if (xfs_mac_valid((xfs_mac_label_t
*)valuep
) != 1) { /* 1 is valid */
760 * if sysconf says MAC enabled,
761 * temp = mac_from_text("msenhigh/mintlow", NULL)
762 * copy it to value, update valuelen, totsize
763 * This causes pushing up or down of all following
764 * attributes, forcing a attribute format change!!
769 _("entry contains illegal value in attribute named SGI_MAC_LABEL\n"));
771 } else if (strncmp(namevalue
, SGI_CAP_FILE
, SGI_CAP_FILE_SIZE
) == 0) {
772 if ( valuelen
!= sizeof(xfs_cap_set_t
)) {
775 _("entry contains illegal value in attribute named SGI_CAP_FILE\n"));
784 * this routine validates the attributes in shortform format.
785 * a non-zero return repair value means certain attributes are bogus
786 * and were cleared if possible. Warnings do not generate error conditions
787 * if you cannot modify the structures. repair is set to 1, if anything
791 process_shortform_attr(
796 xfs_attr_shortform_t
*asf
;
797 xfs_attr_sf_entry_t
*currententry
, *nextentry
, *tempentry
;
799 int currentsize
, remainingspace
;
803 asf
= (xfs_attr_shortform_t
*) XFS_DFORK_APTR(dip
);
805 /* Assumption: hdr.totsize is less than a leaf block and was checked
806 * by lclinode for valid sizes. Check the count though.
808 if (asf
->hdr
.count
== 0)
809 /* then the total size should just be the header length */
810 if (be16_to_cpu(asf
->hdr
.totsize
) != sizeof(xfs_attr_sf_hdr_t
)) {
811 /* whoops there's a discrepancy. Clear the hdr */
814 _("there are no attributes in the fork for inode %" PRIu64
"\n"),
817 cpu_to_be16(sizeof(xfs_attr_sf_hdr_t
));
822 _("would junk the attribute fork since count is 0 for inode %" PRIu64
"\n"),
828 currentsize
= sizeof(xfs_attr_sf_hdr_t
);
829 remainingspace
= be16_to_cpu(asf
->hdr
.totsize
) - currentsize
;
830 nextentry
= &asf
->list
[0];
831 for (i
= 0; i
< asf
->hdr
.count
; i
++) {
832 currententry
= nextentry
;
835 /* don't go off the end if the hdr.count was off */
836 if ((currentsize
+ (sizeof(xfs_attr_sf_entry_t
) - 1)) >
837 be16_to_cpu(asf
->hdr
.totsize
))
838 break; /* get out and reset count and totSize */
840 /* if the namelen is 0, can't get to the rest of the entries */
841 if (currententry
->namelen
== 0) {
842 do_warn(_("zero length name entry in attribute fork,"));
845 _(" truncating attributes for inode %" PRIu64
" to %d\n"), ino
, i
);
847 break; /* and then update hdr fields */
850 _(" would truncate attributes for inode %" PRIu64
" to %d\n"), ino
, i
);
854 /* It's okay to have a 0 length valuelen, but do a
855 * rough check to make sure we haven't gone outside of
858 if (remainingspace
< currententry
->namelen
||
859 ((remainingspace
- currententry
->
860 namelen
) < currententry
->valuelen
)) {
862 _("name or value attribute lengths are too large,\n"));
865 _(" truncating attributes for inode %" PRIu64
" to %d\n"),
868 break; /* and then update hdr fields */
871 _(" would truncate attributes for inode %" PRIu64
" to %d\n"),
878 /* namecheck checks for / and null terminated for file names.
879 * attributes names currently follow the same rules.
881 if (namecheck((char *)¤tentry
->nameval
[0],
882 currententry
->namelen
)) {
884 _("entry contains illegal character in shortform attribute name\n"));
888 if (currententry
->flags
& XFS_ATTR_INCOMPLETE
) {
890 _("entry has INCOMPLETE flag on in shortform attribute\n"));
894 /* Only check values for root security attributes */
895 if (currententry
->flags
& XFS_ATTR_ROOT
)
896 junkit
= valuecheck((char *)¤tentry
->nameval
[0],
897 NULL
, currententry
->namelen
,
898 currententry
->valuelen
);
900 remainingspace
= remainingspace
-
901 XFS_ATTR_SF_ENTSIZE(currententry
);
905 /* get rid of only this entry */
907 _("removing attribute entry %d for inode %" PRIu64
"\n"),
909 tempentry
= (xfs_attr_sf_entry_t
*)
910 ((__psint_t
) currententry
+
911 XFS_ATTR_SF_ENTSIZE(currententry
));
912 memmove(currententry
,tempentry
,remainingspace
);
914 i
--; /* no worries, it will wrap back to 0 */
916 continue; /* go back up now */
919 _("would remove attribute entry %d for inode %" PRIu64
"\n"),
924 /* Let's get ready for the next entry... */
925 nextentry
= (xfs_attr_sf_entry_t
*)((__psint_t
) nextentry
+
926 XFS_ATTR_SF_ENTSIZE(currententry
));
927 currentsize
= currentsize
+ XFS_ATTR_SF_ENTSIZE(currententry
);
931 if (asf
->hdr
.count
!= i
) {
934 _("would have corrected attribute entry count in inode %" PRIu64
" from %d to %d\n"),
935 ino
, asf
->hdr
.count
, i
);
938 _("corrected attribute entry count in inode %" PRIu64
", was %d, now %d\n"),
939 ino
, asf
->hdr
.count
, i
);
945 /* ASSUMPTION: currentsize <= totsize */
946 if (be16_to_cpu(asf
->hdr
.totsize
) != currentsize
) {
949 _("would have corrected attribute totsize in inode %" PRIu64
" from %d to %d\n"),
950 ino
, be16_to_cpu(asf
->hdr
.totsize
),
954 _("corrected attribute entry totsize in inode %" PRIu64
", was %d, now %d\n"),
955 ino
, be16_to_cpu(asf
->hdr
.totsize
),
957 asf
->hdr
.totsize
= cpu_to_be16(currentsize
);
965 /* This routine brings in blocks from disk one by one and assembles them
966 * in the value buffer. If get_bmapi gets smarter later to return an extent
967 * or list of extents, that would be great. For now, we don't expect too
968 * many blocks per remote value, so one by one is sufficient.
971 rmtval_get(xfs_mount_t
*mp
, xfs_ino_t ino
, blkmap_t
*blkmap
,
972 xfs_dablk_t blocknum
, int valuelen
, char* value
)
976 int clearit
= 0, i
= 0, length
= 0, amountdone
= 0;
978 /* ASSUMPTION: valuelen is a valid number, so use it for looping */
979 /* Note that valuelen is not a multiple of blocksize */
980 while (amountdone
< valuelen
) {
981 bno
= blkmap_get(blkmap
, blocknum
+ i
);
982 if (bno
== NULLDFSBNO
) {
984 _("remote block for attributes of inode %" PRIu64
" is missing\n"), ino
);
988 bp
= libxfs_readbuf(mp
->m_dev
, XFS_FSB_TO_DADDR(mp
, bno
),
989 XFS_FSB_TO_BB(mp
, 1), 0, NULL
);
992 _("can't read remote block for attributes of inode %" PRIu64
"\n"), ino
);
996 ASSERT(mp
->m_sb
.sb_blocksize
== XFS_BUF_COUNT(bp
));
997 length
= MIN(XFS_BUF_COUNT(bp
), valuelen
- amountdone
);
998 memmove(value
, XFS_BUF_PTR(bp
), length
);
999 amountdone
+= length
;
1007 /* The block is read in. The magic number and forward / backward
1008 * links are checked by the caller process_leaf_attr.
1009 * If any problems occur the routine returns with non-zero. In
1010 * this case the next step is to clear the attribute fork, by
1011 * changing it to shortform and zeroing it out. Forkoff need not
1016 process_leaf_attr_local(
1017 xfs_attr_leafblock_t
*leaf
,
1019 xfs_attr_leaf_entry_t
*entry
,
1020 xfs_dahash_t last_hashval
,
1024 xfs_attr_leaf_name_local_t
*local
;
1026 local
= xfs_attr3_leaf_name_local(leaf
, i
);
1027 if (local
->namelen
== 0 || namecheck((char *)&local
->nameval
[0],
1030 _("attribute entry %d in attr block %u, inode %" PRIu64
" has bad name (namelen = %d)\n"),
1031 i
, da_bno
, ino
, local
->namelen
);
1035 /* Check on the hash value. Checking order of values
1036 * is not necessary, since one wrong clears the whole
1037 * fork. If the ordering's wrong, it's caught here or
1038 * the kernel code has a bug with transaction logging
1039 * or attributes itself. Being paranoid, let's check
1040 * ordering anyway in case both the name value and the
1041 * hashvalue were wrong but matched. Unlikely, however.
1043 if (be32_to_cpu(entry
->hashval
) != libxfs_da_hashname(
1044 &local
->nameval
[0], local
->namelen
) ||
1045 be32_to_cpu(entry
->hashval
) < last_hashval
) {
1047 _("bad hashvalue for attribute entry %d in attr block %u, inode %" PRIu64
"\n"),
1052 /* Only check values for root security attributes */
1053 if (entry
->flags
& XFS_ATTR_ROOT
) {
1054 if (valuecheck((char *)&local
->nameval
[0], NULL
,
1055 local
->namelen
, be16_to_cpu(local
->valuelen
))) {
1057 _("bad security value for attribute entry %d in attr block %u, inode %" PRIu64
"\n"),
1062 return xfs_attr_leaf_entsize_local(local
->namelen
,
1063 be16_to_cpu(local
->valuelen
));
1067 process_leaf_attr_remote(
1068 xfs_attr_leafblock_t
*leaf
,
1070 xfs_attr_leaf_entry_t
*entry
,
1071 xfs_dahash_t last_hashval
,
1077 xfs_attr_leaf_name_remote_t
*remotep
;
1080 remotep
= xfs_attr3_leaf_name_remote(leaf
, i
);
1082 if (remotep
->namelen
== 0 || namecheck((char *)&remotep
->name
[0],
1083 remotep
->namelen
) ||
1084 be32_to_cpu(entry
->hashval
) !=
1085 libxfs_da_hashname((uchar_t
*)&remotep
->name
[0],
1086 remotep
->namelen
) ||
1087 be32_to_cpu(entry
->hashval
) < last_hashval
||
1088 be32_to_cpu(remotep
->valueblk
) == 0) {
1090 _("inconsistent remote attribute entry %d in attr block %u, ino %" PRIu64
"\n"), i
, da_bno
, ino
);
1094 if (!(entry
->flags
& XFS_ATTR_ROOT
))
1097 value
= malloc(be32_to_cpu(remotep
->valuelen
));
1098 if (value
== NULL
) {
1100 _("cannot malloc enough for remotevalue attribute for inode %" PRIu64
"\n"),
1102 do_warn(_("SKIPPING this remote attribute\n"));
1105 if (rmtval_get(mp
, ino
, blkmap
, be32_to_cpu(remotep
->valueblk
),
1106 be32_to_cpu(remotep
->valuelen
), value
)) {
1108 _("remote attribute get failed for entry %d, inode %" PRIu64
"\n"),
1112 if (valuecheck((char *)&remotep
->name
[0], value
, remotep
->namelen
,
1113 be32_to_cpu(remotep
->valuelen
))) {
1115 _("remote attribute value check failed for entry %d, inode %" PRIu64
"\n"),
1121 return xfs_attr_leaf_entsize_remote(remotep
->namelen
);
1129 process_leaf_attr_block(
1131 xfs_attr_leafblock_t
*leaf
,
1135 xfs_dahash_t last_hashval
,
1136 xfs_dahash_t
*current_hashval
,
1139 xfs_attr_leaf_entry_t
*entry
;
1140 int i
, start
, stop
, clearit
, usedbs
, firstb
, thissize
;
1141 da_freemap_t
*attr_freemap
;
1142 struct xfs_attr3_icleaf_hdr leafhdr
;
1144 xfs_attr3_leaf_hdr_from_disk(&leafhdr
, leaf
);
1145 clearit
= usedbs
= 0;
1147 firstb
= mp
->m_sb
.sb_blocksize
;
1148 stop
= xfs_attr3_leaf_hdr_size(leaf
);
1150 /* does the count look sorta valid? */
1151 if (leafhdr
.count
* sizeof(xfs_attr_leaf_entry_t
) + stop
>
1154 _("bad attribute count %d in attr block %u, inode %" PRIu64
"\n"),
1155 leafhdr
.count
, da_bno
, ino
);
1159 attr_freemap
= alloc_da_freemap(mp
);
1160 (void) set_da_freemap(mp
, attr_freemap
, 0, stop
);
1162 /* go thru each entry checking for problems */
1163 for (i
= 0, entry
= xfs_attr3_leaf_entryp(leaf
);
1164 i
< leafhdr
.count
; i
++, entry
++) {
1166 /* check if index is within some boundary. */
1167 if (be16_to_cpu(entry
->nameidx
) > XFS_LBSIZE(mp
)) {
1169 _("bad attribute nameidx %d in attr block %u, inode %" PRIu64
"\n"),
1170 be16_to_cpu(entry
->nameidx
), da_bno
, ino
);
1175 if (entry
->flags
& XFS_ATTR_INCOMPLETE
) {
1176 /* we are inconsistent state. get rid of us */
1178 _("attribute entry #%d in attr block %u, inode %" PRIu64
" is INCOMPLETE\n"),
1184 /* mark the entry used */
1185 start
= (__psint_t
)entry
- (__psint_t
)leaf
;
1186 stop
= start
+ sizeof(xfs_attr_leaf_entry_t
);
1187 if (set_da_freemap(mp
, attr_freemap
, start
, stop
)) {
1189 _("attribute entry %d in attr block %u, inode %" PRIu64
" claims already used space\n"),
1192 break; /* got an overlap */
1195 if (entry
->flags
& XFS_ATTR_LOCAL
)
1196 thissize
= process_leaf_attr_local(leaf
, i
, entry
,
1197 last_hashval
, da_bno
, ino
);
1199 thissize
= process_leaf_attr_remote(leaf
, i
, entry
,
1200 last_hashval
, da_bno
, ino
,
1207 *current_hashval
= last_hashval
= be32_to_cpu(entry
->hashval
);
1209 if (set_da_freemap(mp
, attr_freemap
, be16_to_cpu(entry
->nameidx
),
1210 be16_to_cpu(entry
->nameidx
) + thissize
)) {
1212 _("attribute entry %d in attr block %u, inode %" PRIu64
" claims used space\n"),
1215 break; /* got an overlap */
1218 if (be16_to_cpu(entry
->nameidx
) < firstb
)
1219 firstb
= be16_to_cpu(entry
->nameidx
);
1221 } /* end the loop */
1224 /* verify the header information is correct */
1226 /* if the holes flag is set, don't reset first_used unless it's
1227 * pointing to used bytes. we're being conservative here
1228 * since the block will get compacted anyhow by the kernel.
1231 if ((leafhdr
.holes
== 0 &&
1232 firstb
!= leafhdr
.firstused
) ||
1233 leafhdr
.firstused
> firstb
) {
1236 _("- resetting first used heap value from %d to %d in "
1237 "block %u of attribute fork of inode %" PRIu64
"\n"),
1239 firstb
, da_bno
, ino
);
1240 leafhdr
.firstused
= firstb
;
1244 _("- would reset first used value from %d to %d in "
1245 "block %u of attribute fork of inode %" PRIu64
"\n"),
1247 firstb
, da_bno
, ino
);
1251 if (usedbs
!= leafhdr
.usedbytes
) {
1254 _("- resetting usedbytes cnt from %d to %d in "
1255 "block %u of attribute fork of inode %" PRIu64
"\n"),
1257 usedbs
, da_bno
, ino
);
1258 leafhdr
.usedbytes
= usedbs
;
1262 _("- would reset usedbytes cnt from %d to %d in "
1263 "block %u of attribute fork of %" PRIu64
"\n"),
1265 usedbs
, da_bno
, ino
);
1269 /* there's a lot of work in process_leaf_dir_block to go thru
1270 * checking for holes and compacting if appropiate. I don't think
1271 * attributes need all that, so let's just leave the holes. If
1272 * we discover later that this is a good place to do compaction
1273 * we can add it then.
1277 xfs_attr3_leaf_hdr_to_disk(leaf
, &leafhdr
);
1280 return (clearit
); /* and repair */
1285 * returns 0 if the attribute fork is ok, 1 if it has to be junked.
1288 process_leaf_attr_level(xfs_mount_t
*mp
,
1289 da_bt_cursor_t
*da_cursor
)
1292 xfs_attr_leafblock_t
*leaf
;
1295 xfs_dfsbno_t dev_bno
;
1297 xfs_dablk_t prev_bno
;
1298 xfs_dahash_t current_hashval
= 0;
1299 xfs_dahash_t greatest_hashval
;
1300 struct xfs_attr3_icleaf_hdr leafhdr
;
1302 da_bno
= da_cursor
->level
[0].bno
;
1303 ino
= da_cursor
->ino
;
1308 dev_bno
= blkmap_get(da_cursor
->blkmap
, da_bno
);
1310 * 0 is the root block and no block
1311 * pointer can point to the root block of the btree
1313 ASSERT(da_bno
!= 0);
1315 if (dev_bno
== NULLDFSBNO
) {
1317 _("can't map block %u for attribute fork for inode %" PRIu64
"\n"),
1322 bp
= libxfs_readbuf(mp
->m_dev
, XFS_FSB_TO_DADDR(mp
, dev_bno
),
1323 XFS_FSB_TO_BB(mp
, 1), 0, NULL
);
1326 _("can't read file block %u (fsbno %" PRIu64
") for attribute fork of inode %" PRIu64
"\n"),
1327 da_bno
, dev_bno
, ino
);
1332 xfs_attr3_leaf_hdr_from_disk(&leafhdr
, leaf
);
1334 /* check magic number for leaf directory btree block */
1335 if (!(leafhdr
.magic
== XFS_ATTR_LEAF_MAGIC
||
1336 leafhdr
.magic
== XFS_ATTR3_LEAF_MAGIC
)) {
1338 _("bad attribute leaf magic %#x for inode %" PRIu64
"\n"),
1339 leafhdr
.magic
, ino
);
1345 * for each block, process the block, verify its path,
1346 * then get next block. update cursor values along the way
1348 if (process_leaf_attr_block(mp
, leaf
, da_bno
, ino
,
1349 da_cursor
->blkmap
, current_hashval
,
1350 &greatest_hashval
, &repair
)) {
1356 * index can be set to hdr.count so match the
1357 * indexes of the interior blocks -- which at the
1358 * end of the block will point to 1 after the final
1359 * real entry in the block
1361 da_cursor
->level
[0].hashval
= greatest_hashval
;
1362 da_cursor
->level
[0].bp
= bp
;
1363 da_cursor
->level
[0].bno
= da_bno
;
1364 da_cursor
->level
[0].index
= leafhdr
.count
;
1365 da_cursor
->level
[0].dirty
= repair
;
1367 if (leafhdr
.back
!= prev_bno
) {
1369 _("bad sibling back pointer for block %u in attribute fork for inode %" PRIu64
"\n"),
1376 da_bno
= leafhdr
.forw
;
1378 if (da_bno
!= 0 && verify_da_path(mp
, da_cursor
, 0)) {
1383 current_hashval
= greatest_hashval
;
1385 if (repair
&& !no_modify
)
1386 libxfs_writebuf(bp
, 0);
1389 } while (da_bno
!= 0);
1391 if (verify_final_da_path(mp
, da_cursor
, 0)) {
1393 * verify the final path up (right-hand-side) if still ok
1396 _("bad hash path in attribute fork for inode %" PRIu64
"\n"),
1401 /* releases all buffers holding interior btree blocks */
1402 release_da_cursor(mp
, da_cursor
, 0);
1406 /* release all buffers holding interior btree blocks */
1407 err_release_da_cursor(mp
, da_cursor
, 0);
1413 * a node directory is a true btree -- where the attribute fork
1414 * has gotten big enough that it is represented as a non-trivial (e.g.
1415 * has more than just a block) btree.
1417 * Note that if we run into any problems, we will trash the attribute fork.
1419 * returns 0 if things are ok, 1 if bad
1420 * Note this code has been based off process_node_dir.
1431 da_bt_cursor_t da_cursor
;
1434 * try again -- traverse down left-side of tree until we hit
1435 * the left-most leaf block setting up the btree cursor along
1436 * the way. Then walk the leaf blocks left-to-right, calling
1437 * a parent-verification routine each time we traverse a block.
1439 memset(&da_cursor
, 0, sizeof(da_bt_cursor_t
));
1440 da_cursor
.active
= 0;
1442 da_cursor
.ino
= ino
;
1443 da_cursor
.dip
= dip
;
1444 da_cursor
.greatest_bno
= 0;
1445 da_cursor
.blkmap
= blkmap
;
1448 * now process interior node. don't have any buffers held in this path.
1450 error
= traverse_int_dablock(mp
, &da_cursor
, &bno
, XFS_ATTR_FORK
);
1452 return(1); /* 0 means unsuccessful */
1455 * now pass cursor and bno into leaf-block processing routine
1456 * the leaf dir level routine checks the interior paths
1457 * up to the root including the final right-most path.
1460 return (process_leaf_attr_level(mp
, &da_cursor
));
1464 * Start processing for a leaf or fuller btree.
1465 * A leaf directory is one where the attribute fork is too big for
1466 * the inode but is small enough to fit into one btree block
1467 * outside the inode. This code is modelled after process_leaf_dir_block.
1469 * returns 0 if things are ok, 1 if bad (attributes needs to be junked)
1470 * repair is set, if anything was changed, but attributes can live thru it
1473 process_longform_attr(
1478 int *repair
) /* out - 1 if something was fixed */
1480 xfs_attr_leafblock_t
*leaf
;
1483 xfs_dahash_t next_hashval
;
1484 int repairlinks
= 0;
1485 struct xfs_attr3_icleaf_hdr leafhdr
;
1489 bno
= blkmap_get(blkmap
, 0);
1491 if ( bno
== NULLDFSBNO
) {
1492 if (dip
->di_aformat
== XFS_DINODE_FMT_EXTENTS
&&
1493 be16_to_cpu(dip
->di_anextents
) == 0)
1494 return(0); /* the kernel can handle this state */
1496 _("block 0 of inode %" PRIu64
" attribute fork is missing\n"),
1500 /* FIX FOR bug 653709 -- EKN */
1501 if (mp
->m_sb
.sb_agcount
< XFS_FSB_TO_AGNO(mp
, bno
)) {
1503 _("agno of attribute fork of inode %" PRIu64
" out of regular partition\n"), ino
);
1507 bp
= libxfs_readbuf(mp
->m_dev
, XFS_FSB_TO_DADDR(mp
, bno
),
1508 XFS_FSB_TO_BB(mp
, 1), 0, &xfs_da3_node_buf_ops
);
1511 _("can't read block 0 of inode %" PRIu64
" attribute fork\n"),
1516 /* verify leaf block */
1517 leaf
= (xfs_attr_leafblock_t
*)XFS_BUF_PTR(bp
);
1518 xfs_attr3_leaf_hdr_from_disk(&leafhdr
, leaf
);
1520 /* check sibling pointers in leaf block or root block 0 before
1521 * we have to release the btree block
1523 if (leafhdr
.forw
!= 0 || leafhdr
.back
!= 0) {
1526 _("clearing forw/back pointers in block 0 for attributes in inode %" PRIu64
"\n"),
1531 xfs_attr3_leaf_hdr_to_disk(leaf
, &leafhdr
);
1534 _("would clear forw/back pointers in block 0 for attributes in inode %" PRIu64
"\n"), ino
);
1539 * use magic number to tell us what type of attribute this is.
1540 * it's possible to have a node or leaf attribute in either an
1541 * extent format or btree format attribute fork.
1543 switch (leafhdr
.magic
) {
1544 case XFS_ATTR_LEAF_MAGIC
: /* leaf-form attribute */
1545 case XFS_ATTR3_LEAF_MAGIC
:
1546 if (process_leaf_attr_block(mp
, leaf
, 0, ino
, blkmap
,
1547 0, &next_hashval
, repair
)) {
1548 /* the block is bad. lose the attribute fork. */
1552 *repair
= *repair
|| repairlinks
;
1555 case XFS_DA_NODE_MAGIC
: /* btree-form attribute */
1556 case XFS_DA3_NODE_MAGIC
:
1557 /* must do this now, to release block 0 before the traversal */
1560 libxfs_writebuf(bp
, 0);
1563 return (process_node_attr(mp
, ino
, dip
, blkmap
)); /* + repair */
1566 _("bad attribute leaf magic # %#x for dir ino %" PRIu64
"\n"),
1567 be16_to_cpu(leaf
->hdr
.info
.magic
), ino
);
1572 if (*repair
&& !no_modify
)
1573 libxfs_writebuf(bp
, 0);
1577 return(0); /* repair may be set */
1582 xfs_acl_from_disk(struct xfs_acl
**aclp
, struct xfs_acl_disk
*dacl
)
1586 xfs_acl_entry_t
*ace
;
1587 xfs_acl_entry_disk_t
*dace
, *end
;
1589 count
= be32_to_cpu(dacl
->acl_cnt
);
1590 if (count
> XFS_ACL_MAX_ENTRIES
) {
1591 do_warn(_("Too many ACL entries, count %d\n"), count
);
1597 end
= &dacl
->acl_entry
[0] + count
;
1598 acl
= malloc((int)((char *)end
- (char *)dacl
));
1600 do_warn(_("cannot malloc enough for ACL attribute\n"));
1601 do_warn(_("SKIPPING this ACL\n"));
1606 acl
->acl_cnt
= count
;
1607 ace
= &acl
->acl_entry
[0];
1608 for (dace
= &dacl
->acl_entry
[0]; dace
< end
; ace
++, dace
++) {
1609 ace
->ae_tag
= be32_to_cpu(dace
->ae_tag
);
1610 ace
->ae_id
= be32_to_cpu(dace
->ae_id
);
1611 ace
->ae_perm
= be16_to_cpu(dace
->ae_perm
);
1619 * returns 1 if attributes got cleared
1620 * and 0 if things are ok.
1628 int *repair
) /* returned if we did repair */
1631 __u8 aformat
= dip
->di_aformat
;
1633 xfs_attr_shortform_t
*asf
;
1635 asf
= (xfs_attr_shortform_t
*) XFS_DFORK_APTR(dip
);
1638 if (aformat
== XFS_DINODE_FMT_LOCAL
) {
1639 ASSERT(be16_to_cpu(asf
->hdr
.totsize
) <=
1640 XFS_DFORK_ASIZE(dip
, mp
));
1641 err
= process_shortform_attr(ino
, dip
, repair
);
1642 } else if (aformat
== XFS_DINODE_FMT_EXTENTS
||
1643 aformat
== XFS_DINODE_FMT_BTREE
) {
1644 err
= process_longform_attr(mp
, ino
, dip
, blkmap
,
1646 /* if err, convert this to shortform and clear it */
1647 /* if repair and no error, it's taken care of */
1649 do_warn(_("illegal attribute format %d, ino %" PRIu64
"\n"),
1653 return (err
); /* and repair */
1660 xfs_acl_valid(xfs_acl_disk_t
*daclp
)
1662 xfs_acl_t
*aclp
= NULL
;
1663 xfs_acl_entry_t
*entry
, *e
;
1664 int user
= 0, group
= 0, other
= 0, mask
= 0, mask_required
= 0;
1670 switch (xfs_acl_from_disk(&aclp
, daclp
)) {
1679 for (i
= 0; i
< aclp
->acl_cnt
; i
++) {
1680 entry
= &aclp
->acl_entry
[i
];
1681 if (entry
->ae_perm
& ~(ACL_READ
|ACL_WRITE
|ACL_EXECUTE
))
1683 switch (entry
->ae_tag
) {
1698 for (j
= i
+ 1; j
< aclp
->acl_cnt
; j
++) {
1699 e
= &aclp
->acl_entry
[j
];
1700 if (e
->ae_id
== entry
->ae_id
&&
1701 e
->ae_tag
== entry
->ae_tag
)
1714 if (!user
|| !group
|| !other
|| (mask_required
&& !mask
))
1725 * Check a category or division set to ensure that all values are in
1726 * ascending order and each division or category appears only once.
1729 __check_setvalue(const unsigned short *list
, unsigned short count
)
1733 for (i
= 1; i
< count
; i
++)
1734 if (list
[i
] <= list
[i
-1])
1741 * Check the validity of a MAC label.
1744 xfs_mac_valid(xfs_mac_label_t
*lp
)
1750 * if the total category set and division set is greater than 250
1753 if ((lp
->ml_catcount
+ lp
->ml_divcount
) > XFS_MAC_MAX_SETS
)
1757 * check whether the msentype value is valid, and do they have
1758 * appropriate level, category association.
1760 switch (lp
->ml_msen_type
) {
1761 case XFS_MSEN_ADMIN_LABEL
:
1762 case XFS_MSEN_EQUAL_LABEL
:
1763 case XFS_MSEN_HIGH_LABEL
:
1764 case XFS_MSEN_MLD_HIGH_LABEL
:
1765 case XFS_MSEN_LOW_LABEL
:
1766 case XFS_MSEN_MLD_LOW_LABEL
:
1767 if (lp
->ml_level
!= 0 || lp
->ml_catcount
> 0 )
1770 case XFS_MSEN_TCSEC_LABEL
:
1771 case XFS_MSEN_MLD_LABEL
:
1772 if (lp
->ml_catcount
> 0 &&
1773 __check_setvalue(lp
->ml_list
,
1774 lp
->ml_catcount
) == -1)
1777 case XFS_MSEN_UNKNOWN_LABEL
:
1783 * check whether the minttype value is valid, and do they have
1784 * appropriate grade, division association.
1786 switch (lp
->ml_mint_type
) {
1787 case XFS_MINT_BIBA_LABEL
:
1788 if (lp
->ml_divcount
> 0 &&
1789 __check_setvalue(lp
->ml_list
+ lp
->ml_catcount
,
1790 lp
->ml_divcount
) == -1)
1793 case XFS_MINT_EQUAL_LABEL
:
1794 case XFS_MINT_HIGH_LABEL
:
1795 case XFS_MINT_LOW_LABEL
:
1796 if (lp
->ml_grade
!= 0 || lp
->ml_divcount
> 0 )