2 * Copyright (c) 2000-2002,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
23 #include "err_protos.h"
31 * Tag bad directory entries with this.
32 * We can't tag them with -1 since that will look like a
33 * data_unused_t instead of a data_entry_t.
35 #define BADFSINO ((xfs_ino_t)0xfeffffffffffffffULL)
38 * Known bad inode list. These are seen when the leaf and node
39 * block linkages are incorrect.
41 typedef struct dir2_bad
{
43 struct dir2_bad
*next
;
46 static dir2_bad_t
*dir2_bad_list
;
54 if ((l
= malloc(sizeof(dir2_bad_t
))) == NULL
) {
56 _("malloc failed (%zu bytes) dir2_add_badlist:ino %" PRIu64
"\n"),
57 sizeof(dir2_bad_t
), ino
);
60 l
->next
= dir2_bad_list
;
71 for (l
= dir2_bad_list
; l
; l
= l
->next
)
78 * takes a name and length (name need not be null-terminated)
79 * and returns 1 if the name contains a '/' or a \0, returns 0
83 namecheck(char *name
, int length
)
88 ASSERT(length
< MAXNAMELEN
);
90 for (c
= name
, i
= 0; i
< length
; i
++, c
++) {
91 if (*c
== '/' || *c
== '\0')
99 * Multibuffer handling.
100 * V2 directory blocks can be noncontiguous, needing multiple buffers.
102 static struct xfs_buf
*
108 #define MAP_ARRAY_SZ 4
109 struct xfs_buf_map map_array
[MAP_ARRAY_SZ
];
110 struct xfs_buf_map
*map
;
114 if (nex
> MAP_ARRAY_SZ
) {
115 map
= calloc(nex
, sizeof(*map
));
117 do_error(_("couldn't malloc dir2 buffer list\n"));
121 /* common case avoids calloc/free */
124 for (i
= 0; i
< nex
; i
++) {
125 map
[i
].bm_bn
= XFS_FSB_TO_DADDR(mp
, bmp
[i
].startblock
);
126 map
[i
].bm_len
= XFS_FSB_TO_BB(mp
, bmp
[i
].blockcount
);
128 bp
= libxfs_readbuf_map(mp
->m_dev
, map
, nex
, 0);
129 if (map
!= map_array
)
135 * walk tree from root to the left-most leaf block reading in
136 * blocks and setting up cursor. passes back file block number of the
137 * left-most leaf block if successful (bno). returns 1 if successful,
141 traverse_int_dir2block(xfs_mount_t
*mp
,
142 dir2_bt_cursor_t
*da_cursor
,
150 xfs_da_blkinfo_t
*info
;
151 xfs_da_intnode_t
*node
;
155 * traverse down left-side of tree until we hit the
156 * left-most leaf block setting up the btree cursor along
159 bno
= mp
->m_dirleafblk
;
162 da_cursor
->active
= 0;
166 * read in each block along the way and set up cursor
168 nex
= blkmap_getn(da_cursor
->blkmap
, bno
, mp
->m_dirblkfsbs
,
174 bp
= da_read_buf(mp
, nex
, bmp
);
179 _("can't read block %u for directory inode %" PRIu64
"\n"),
180 bno
, da_cursor
->ino
);
186 if (be16_to_cpu(info
->magic
) == XFS_DIR2_LEAFN_MAGIC
) {
189 _("found non-root LEAFN node in inode %" PRIu64
" bno = %u\n"),
190 da_cursor
->ino
, bno
);
195 } else if (be16_to_cpu(info
->magic
) != XFS_DA_NODE_MAGIC
) {
198 _("bad dir magic number 0x%x in inode %" PRIu64
" bno = %u\n"),
199 be16_to_cpu(info
->magic
),
200 da_cursor
->ino
, bno
);
203 node
= (xfs_da_intnode_t
*)info
;
204 if (be16_to_cpu(node
->hdr
.count
) > mp
->m_dir_node_ents
) {
207 _("bad record count in inode %" PRIu64
", count = %d, max = %d\n"), da_cursor
->ino
,
208 be16_to_cpu(node
->hdr
.count
),
209 mp
->m_dir_node_ents
);
213 * maintain level counter
216 i
= da_cursor
->active
= be16_to_cpu(node
->hdr
.level
);
217 if (i
>= XFS_DA_NODE_MAXDEPTH
) {
219 _("bad header depth for directory inode %" PRIu64
"\n"),
226 if (be16_to_cpu(node
->hdr
.level
) == i
- 1) {
230 _("bad directory btree for directory inode %" PRIu64
"\n"),
237 da_cursor
->level
[i
].hashval
=
238 be32_to_cpu(node
->btree
[0].hashval
);
239 da_cursor
->level
[i
].bp
= bp
;
240 da_cursor
->level
[i
].bno
= bno
;
241 da_cursor
->level
[i
].index
= 0;
244 * set up new bno for next level down
246 bno
= be32_to_cpu(node
->btree
[0].before
);
247 } while (info
!= NULL
&& i
> 1);
250 * now return block number and get out
252 *rbno
= da_cursor
->level
[0].bno
= bno
;
256 while (i
> 1 && i
<= da_cursor
->active
) {
257 libxfs_putbuf(da_cursor
->level
[i
].bp
);
265 * blow out buffer for this level and all the rest above as well
266 * if error == 0, we are not expecting to encounter any unreleased
267 * buffers (e.g. if we do, it's a mistake). if error == 1, we're
268 * in an error-handling case so unreleased buffers may exist.
271 release_dir2_cursor_int(xfs_mount_t
*mp
,
272 dir2_bt_cursor_t
*cursor
,
276 int level
= prev_level
+ 1;
278 if (cursor
->level
[level
].bp
!= NULL
) {
280 do_warn(_("release_dir2_cursor_int got unexpected "
281 "non-null bp, dabno = %u\n"),
282 cursor
->level
[level
].bno
);
286 libxfs_putbuf(cursor
->level
[level
].bp
);
287 cursor
->level
[level
].bp
= NULL
;
290 if (level
< cursor
->active
)
291 release_dir2_cursor_int(mp
, cursor
, level
, error
);
297 release_dir2_cursor(xfs_mount_t
*mp
,
298 dir2_bt_cursor_t
*cursor
,
301 release_dir2_cursor_int(mp
, cursor
, prev_level
, 0);
305 err_release_dir2_cursor(xfs_mount_t
*mp
,
306 dir2_bt_cursor_t
*cursor
,
309 release_dir2_cursor_int(mp
, cursor
, prev_level
, 1);
313 * make sure that all entries in all blocks along the right side of
314 * of the tree are used and hashval's are consistent. level is the
315 * level of the descendent block. returns 0 if good (even if it had
316 * to be fixed up), and 1 if bad. The right edge of the tree is
317 * technically a block boundary. This routine should be used then
318 * instead of verify_dir2_path().
321 verify_final_dir2_path(xfs_mount_t
*mp
,
322 dir2_bt_cursor_t
*cursor
,
325 xfs_da_intnode_t
*node
;
328 int this_level
= p_level
+ 1;
331 * the index should point to the next "unprocessed" entry
332 * in the block which should be the final (rightmost) entry
334 entry
= cursor
->level
[this_level
].index
;
335 node
= (xfs_da_intnode_t
*)(cursor
->level
[this_level
].bp
->b_addr
);
337 * check internal block consistency on this level -- ensure
338 * that all entries are used, encountered and expected hashvals
341 if (entry
!= be16_to_cpu(node
->hdr
.count
) - 1) {
343 _("directory block used/count inconsistency - %d / %hu\n"),
344 entry
, be16_to_cpu(node
->hdr
.count
));
348 * hash values monotonically increasing ???
350 if (cursor
->level
[this_level
].hashval
>=
351 be32_to_cpu(node
->btree
[entry
].hashval
)) {
352 do_warn(_("directory/attribute block hashvalue inconsistency, "
353 "expected > %u / saw %u\n"),
354 cursor
->level
[this_level
].hashval
,
355 be32_to_cpu(node
->btree
[entry
].hashval
));
358 if (be32_to_cpu(node
->hdr
.info
.forw
) != 0) {
359 do_warn(_("bad directory/attribute forward block pointer, "
360 "expected 0, saw %u\n"),
361 be32_to_cpu(node
->hdr
.info
.forw
));
365 do_warn(_("bad directory block in inode %" PRIu64
"\n"), cursor
->ino
);
369 * keep track of greatest block # -- that gets
370 * us the length of the directory
372 if (cursor
->level
[this_level
].bno
> cursor
->greatest_bno
)
373 cursor
->greatest_bno
= cursor
->level
[this_level
].bno
;
376 * ok, now check descendant block number against this level
378 if (cursor
->level
[p_level
].bno
!=
379 be32_to_cpu(node
->btree
[entry
].before
))
382 if (cursor
->level
[p_level
].hashval
!=
383 be32_to_cpu(node
->btree
[entry
].hashval
)) {
386 _("correcting bad hashval in non-leaf dir block\n"
387 "\tin (level %d) in inode %" PRIu64
".\n"),
388 this_level
, cursor
->ino
);
389 node
->btree
[entry
].hashval
= cpu_to_be32(
390 cursor
->level
[p_level
].hashval
);
391 cursor
->level
[this_level
].dirty
++;
394 _("would correct bad hashval in non-leaf dir block\n"
395 "\tin (level %d) in inode %" PRIu64
".\n"),
396 this_level
, cursor
->ino
);
401 * release/write buffer
403 ASSERT(cursor
->level
[this_level
].dirty
== 0 ||
404 (cursor
->level
[this_level
].dirty
&& !no_modify
));
406 if (cursor
->level
[this_level
].dirty
&& !no_modify
)
407 libxfs_writebuf(cursor
->level
[this_level
].bp
, 0);
409 libxfs_putbuf(cursor
->level
[this_level
].bp
);
411 cursor
->level
[this_level
].bp
= NULL
;
414 * bail out if this is the root block (top of tree)
416 if (this_level
>= cursor
->active
)
419 * set hashvalue to correctl reflect the now-validated
420 * last entry in this block and continue upwards validation
422 cursor
->level
[this_level
].hashval
=
423 be32_to_cpu(node
->btree
[entry
].hashval
);
425 return(verify_final_dir2_path(mp
, cursor
, this_level
));
429 * Verifies the path from a descendant block up to the root.
430 * Should be called when the descendant level traversal hits
431 * a block boundary before crossing the boundary (reading in a new
434 * the directory/attr btrees work differently to the other fs btrees.
435 * each interior block contains records that are <hashval, bno>
436 * pairs. The bno is a file bno, not a filesystem bno. The last
437 * hashvalue in the block <bno> will be <hashval>. BUT unlike
438 * the freespace btrees, the *last* value in each block gets
439 * propagated up the tree instead of the first value in each block.
440 * that is, the interior records point to child blocks and the *greatest*
441 * hash value contained by the child block is the one the block above
442 * uses as the key for the child block.
444 * level is the level of the descendent block. returns 0 if good,
445 * and 1 if bad. The descendant block may be a leaf block.
447 * the invariant here is that the values in the cursor for the
448 * levels beneath this level (this_level) and the cursor index
449 * for this level *must* be valid.
451 * that is, the hashval/bno info is accurate for all
452 * DESCENDANTS and match what the node[index] information
453 * for the current index in the cursor for this level.
455 * the index values in the cursor for the descendant level
456 * are allowed to be off by one as they will reflect the
457 * next entry at those levels to be processed.
459 * the hashvalue for the current level can't be set until
460 * we hit the last entry in the block so, it's garbage
461 * until set by this routine.
463 * bno and bp for the current block/level are always valid
464 * since they have to be set so we can get a buffer for the
468 verify_dir2_path(xfs_mount_t
*mp
,
469 dir2_bt_cursor_t
*cursor
,
472 xfs_da_intnode_t
*node
;
473 xfs_da_intnode_t
*newnode
;
478 int this_level
= p_level
+ 1;
484 * index is currently set to point to the entry that
485 * should be processed now in this level.
487 entry
= cursor
->level
[this_level
].index
;
488 node
= cursor
->level
[this_level
].bp
->b_addr
;
491 * if this block is out of entries, validate this
492 * block and move on to the next block.
493 * and update cursor value for said level
495 if (entry
>= be16_to_cpu(node
->hdr
.count
)) {
497 * update the hash value for this level before
498 * validating it. bno value should be ok since
499 * it was set when the block was first read in.
501 cursor
->level
[this_level
].hashval
=
502 be32_to_cpu(node
->btree
[entry
- 1].hashval
);
505 * keep track of greatest block # -- that gets
506 * us the length of the directory
508 if (cursor
->level
[this_level
].bno
> cursor
->greatest_bno
)
509 cursor
->greatest_bno
= cursor
->level
[this_level
].bno
;
512 * validate the path for the current used-up block
515 if (verify_dir2_path(mp
, cursor
, this_level
))
518 * ok, now get the next buffer and check sibling pointers
520 dabno
= be32_to_cpu(node
->hdr
.info
.forw
);
522 nex
= blkmap_getn(cursor
->blkmap
, dabno
, mp
->m_dirblkfsbs
,
526 _("can't get map info for block %u of directory inode %" PRIu64
"\n"),
531 bp
= da_read_buf(mp
, nex
, bmp
);
537 _("can't read block %u for directory inode %" PRIu64
"\n"),
542 newnode
= bp
->b_addr
;
544 * verify magic number and back pointer, sanity-check
545 * entry count, verify level
548 if (XFS_DA_NODE_MAGIC
!= be16_to_cpu(newnode
->hdr
.info
.magic
)) {
550 _("bad magic number %x in block %u for directory inode %" PRIu64
"\n"),
551 be16_to_cpu(newnode
->hdr
.info
.magic
),
555 if (be32_to_cpu(newnode
->hdr
.info
.back
) !=
556 cursor
->level
[this_level
].bno
) {
558 _("bad back pointer in block %u for directory inode %" PRIu64
"\n"),
562 if (be16_to_cpu(newnode
->hdr
.count
) > mp
->m_dir_node_ents
) {
564 _("entry count %d too large in block %u for directory inode %" PRIu64
"\n"),
565 be16_to_cpu(newnode
->hdr
.count
),
569 if (be16_to_cpu(newnode
->hdr
.level
) != this_level
) {
571 _("bad level %d in block %u for directory inode %" PRIu64
"\n"),
572 be16_to_cpu(newnode
->hdr
.level
),
581 * update cursor, write out the *current* level if
582 * required. don't write out the descendant level
584 ASSERT(cursor
->level
[this_level
].dirty
== 0 ||
585 (cursor
->level
[this_level
].dirty
&& !no_modify
));
587 if (cursor
->level
[this_level
].dirty
&& !no_modify
)
588 libxfs_writebuf(cursor
->level
[this_level
].bp
, 0);
590 libxfs_putbuf(cursor
->level
[this_level
].bp
);
591 cursor
->level
[this_level
].bp
= bp
;
592 cursor
->level
[this_level
].dirty
= 0;
593 cursor
->level
[this_level
].bno
= dabno
;
594 cursor
->level
[this_level
].hashval
=
595 be32_to_cpu(newnode
->btree
[0].hashval
);
598 entry
= cursor
->level
[this_level
].index
= 0;
601 * ditto for block numbers
603 if (cursor
->level
[p_level
].bno
!=
604 be32_to_cpu(node
->btree
[entry
].before
))
607 * ok, now validate last hashvalue in the descendant
608 * block against the hashval in the current entry
610 if (cursor
->level
[p_level
].hashval
!=
611 be32_to_cpu(node
->btree
[entry
].hashval
)) {
614 _("correcting bad hashval in interior dir block\n"
615 "\tin (level %d) in inode %" PRIu64
".\n"),
616 this_level
, cursor
->ino
);
617 node
->btree
[entry
].hashval
= cpu_to_be32(
618 cursor
->level
[p_level
].hashval
);
619 cursor
->level
[this_level
].dirty
++;
622 _("would correct bad hashval in interior dir block\n"
623 "\tin (level %d) in inode %" PRIu64
".\n"),
624 this_level
, cursor
->ino
);
628 * increment index for this level to point to next entry
629 * (which should point to the next descendant block)
631 cursor
->level
[this_level
].index
++;
636 * Fix up a shortform directory which was in long form (i8count set)
637 * and is now in short form (i8count clear).
638 * Return pointer to the end of the data when done.
641 process_sf_dir2_fixi8(
643 xfs_dir2_sf_entry_t
**next_sfep
)
646 xfs_dir2_sf_t
*newsfp
;
647 xfs_dir2_sf_entry_t
*newsfep
;
648 xfs_dir2_sf_t
*oldsfp
;
649 xfs_dir2_sf_entry_t
*oldsfep
;
653 oldsize
= (__psint_t
)*next_sfep
- (__psint_t
)sfp
;
654 oldsfp
= malloc(oldsize
);
655 if (oldsfp
== NULL
) {
656 do_error(_("couldn't malloc dir2 shortform copy\n"));
659 memmove(oldsfp
, newsfp
, oldsize
);
660 newsfp
->hdr
.count
= oldsfp
->hdr
.count
;
661 newsfp
->hdr
.i8count
= 0;
662 ino
= xfs_dir2_sf_get_parent_ino(&sfp
->hdr
);
663 xfs_dir2_sf_put_parent_ino(&newsfp
->hdr
, ino
);
664 oldsfep
= xfs_dir2_sf_firstentry(&oldsfp
->hdr
);
665 newsfep
= xfs_dir2_sf_firstentry(&newsfp
->hdr
);
666 while ((int)((char *)oldsfep
- (char *)oldsfp
) < oldsize
) {
667 newsfep
->namelen
= oldsfep
->namelen
;
668 xfs_dir2_sf_put_offset(newsfep
,
669 xfs_dir2_sf_get_offset(oldsfep
));
670 memmove(newsfep
->name
, oldsfep
->name
, newsfep
->namelen
);
671 ino
= xfs_dir2_sfe_get_ino(&oldsfp
->hdr
, oldsfep
);
672 xfs_dir2_sfe_put_ino(&newsfp
->hdr
, newsfep
, ino
);
673 oldsfep
= xfs_dir2_sf_nextentry(&oldsfp
->hdr
, oldsfep
);
674 newsfep
= xfs_dir2_sf_nextentry(&newsfp
->hdr
, newsfep
);
676 *next_sfep
= newsfep
;
681 * Regenerate legal (minimal) offsets for the shortform directory.
684 process_sf_dir2_fixoff(
689 xfs_dir2_sf_entry_t
*sfep
;
692 sfp
= (xfs_dir2_sf_t
*)XFS_DFORK_DPTR(dip
);
693 sfep
= xfs_dir2_sf_firstentry(&sfp
->hdr
);
694 offset
= XFS_DIR2_DATA_FIRST_OFFSET
;
696 for (i
= 0; i
< sfp
->hdr
.count
; i
++) {
697 xfs_dir2_sf_put_offset(sfep
, offset
);
698 offset
+= xfs_dir2_data_entsize(sfep
->namelen
);
699 sfep
= xfs_dir2_sf_nextentry(&sfp
->hdr
, sfep
);
704 * this routine performs inode discovery and tries to fix things
705 * in place. available redundancy -- inode data size should match
706 * used directory space in inode.
707 * a non-zero return value means the directory is bogus and should be blasted.
716 int *dino_dirty
, /* out - 1 if dinode buffer dirty */
717 char *dirname
, /* directory pathname */
718 xfs_ino_t
*parent
, /* out - NULLFSINO if entry not exist */
719 int *repair
) /* out - 1 if dir was fixed up */
725 __int64_t ino_dir_size
;
727 ino_tree_node_t
*irec_p
;
729 char *junkreason
= NULL
;
732 char name
[MAXNAMELEN
+ 1];
734 xfs_dir2_sf_entry_t
*next_sfep
;
738 xfs_dir2_sf_entry_t
*sfep
;
741 xfs_dir2_sf_entry_t
*tmp_sfep
;
744 sfp
= (xfs_dir2_sf_t
*)XFS_DFORK_DPTR(dip
);
745 max_size
= XFS_DFORK_DSIZE(dip
, mp
);
746 num_entries
= sfp
->hdr
.count
;
747 ino_dir_size
= be64_to_cpu(dip
->di_size
);
748 offset
= XFS_DIR2_DATA_FIRST_OFFSET
;
749 bad_offset
= *repair
= 0;
751 ASSERT(ino_dir_size
<= max_size
);
754 * Initialize i8 based on size of parent inode number.
756 i8
= (xfs_dir2_sf_get_parent_ino(&sfp
->hdr
) > XFS_DIR2_MAX_SHORT_INUM
);
759 * check for bad entry count
761 if (num_entries
* xfs_dir2_sf_entsize(&sfp
->hdr
, 1) +
762 xfs_dir2_sf_hdr_size(0) > max_size
|| num_entries
== 0)
766 * run through entries, stop at first bad entry, don't need
767 * to check for .. since that's encoded in its own field
769 sfep
= next_sfep
= xfs_dir2_sf_firstentry(&sfp
->hdr
);
771 i
< num_entries
&& ino_dir_size
> (char *)next_sfep
- (char *)sfp
;
777 lino
= xfs_dir2_sfe_get_ino(&sfp
->hdr
, sfep
);
779 * if entry points to self, junk it since only '.' or '..'
780 * should do that and shortform dirs don't contain either
781 * entry. if inode number is invalid, trash entry.
782 * if entry points to special inodes, trash it.
783 * if inode is unknown but number is valid,
784 * add it to the list of uncertain inodes. don't
785 * have to worry about an entry pointing to a
786 * deleted lost+found inode because the entry was
787 * deleted at the same time that the inode was cleared.
791 junkreason
= _("current");
792 } else if (verify_inum(mp
, lino
)) {
794 junkreason
= _("invalid");
795 } else if (lino
== mp
->m_sb
.sb_rbmino
) {
797 junkreason
= _("realtime bitmap");
798 } else if (lino
== mp
->m_sb
.sb_rsumino
) {
800 junkreason
= _("realtime summary");
801 } else if (lino
== mp
->m_sb
.sb_uquotino
) {
803 junkreason
= _("user quota");
804 } else if (lino
== mp
->m_sb
.sb_gquotino
) {
806 junkreason
= _("group quota");
807 } else if ((irec_p
= find_inode_rec(mp
,
808 XFS_INO_TO_AGNO(mp
, lino
),
809 XFS_INO_TO_AGINO(mp
, lino
))) != NULL
) {
811 * if inode is marked free and we're in inode
812 * discovery mode, leave the entry alone for now.
813 * if the inode turns out to be used, we'll figure
814 * that out when we scan it. If the inode really
815 * is free, we'll hit this code again in phase 4
816 * after we've finished inode discovery and blow
817 * out the entry then.
819 ino_off
= XFS_INO_TO_AGINO(mp
, lino
) -
820 irec_p
->ino_startnum
;
821 ASSERT(is_inode_confirmed(irec_p
, ino_off
));
822 if (is_inode_free(irec_p
, ino_off
) && !ino_discovery
) {
824 junkreason
= _("free");
826 } else if (ino_discovery
) {
828 * put the inode on the uncertain list. we'll
829 * pull the inode off the list and check it later.
830 * if the inode turns out be bogus, we'll delete
831 * this entry in phase 6.
833 add_inode_uncertain(mp
, lino
, 0);
836 * blow the entry out. we know about all
837 * undiscovered entries now (past inode discovery
838 * phase) so this is clearly a bogus entry.
841 junkreason
= _("non-existent");
843 namelen
= sfep
->namelen
;
846 _("entry \"%*.*s\" in shortform directory %" PRIu64
" references %s inode %" PRIu64
"\n"),
847 namelen
, namelen
, sfep
->name
, ino
, junkreason
,
851 * if we're really lucky, this is
852 * the last entry in which case we
853 * can use the dir size to set the
854 * namelen value. otherwise, forget
855 * it because we're not going to be
856 * able to find the next entry.
860 if (i
== num_entries
- 1) {
861 namelen
= ino_dir_size
-
862 ((__psint_t
) &sfep
->name
[0] -
866 _("zero length entry in shortform dir %" PRIu64
", resetting to %d\n"),
868 sfep
->namelen
= namelen
;
871 _("zero length entry in shortform dir %" PRIu64
", would set to %d\n"),
876 _("zero length entry in shortform dir %" PRIu64
""),
879 do_warn(_(", junking %d entries\n"),
882 do_warn(_(", would junk %d entries\n"),
885 * don't process the rest of the directory,
886 * break out of processing looop
890 } else if ((__psint_t
) sfep
- (__psint_t
) sfp
+
891 xfs_dir2_sf_entsize(&sfp
->hdr
, sfep
->namelen
)
895 if (i
== num_entries
- 1) {
896 namelen
= ino_dir_size
-
897 ((__psint_t
) &sfep
->name
[0] -
900 _("size of last entry overflows space left in in shortform dir %" PRIu64
", "),
903 do_warn(_("resetting to %d\n"),
905 sfep
->namelen
= namelen
;
908 do_warn(_("would reset to %d\n"),
913 _("size of entry #%d overflows space left in in shortform dir %" PRIu64
"\n"),
916 if (i
== num_entries
- 1)
918 _("junking entry #%d\n"),
922 _("junking %d entries\n"),
925 if (i
== num_entries
- 1)
927 _("would junk entry #%d\n"),
931 _("would junk %d entries\n"),
940 * check for illegal chars in name.
941 * no need to check for bad length because
942 * the length value is stored in a byte
943 * so it can't be too big, it can only wrap
945 if (namecheck((char *)&sfep
->name
[0], namelen
)) {
950 _("entry contains illegal character in shortform dir %" PRIu64
"\n"),
955 if (xfs_dir2_sf_get_offset(sfep
) < offset
) {
957 _("entry contains offset out of order in shortform dir %" PRIu64
"\n"),
961 offset
= xfs_dir2_sf_get_offset(sfep
) +
962 xfs_dir2_data_entsize(namelen
);
965 * junk the entry by copying up the rest of the
966 * fork over the current entry and decrementing
967 * the entry count. if we're in no_modify mode,
968 * just issue the warning instead. then continue
969 * the loop with the next_sfep pointer set to the
970 * correct place in the fork and other counters
971 * properly set to reflect the deletion if it
975 memmove(name
, sfep
->name
, namelen
);
976 name
[namelen
] = '\0';
979 tmp_elen
= xfs_dir2_sf_entsize(&sfp
->hdr
,
981 be64_add_cpu(&dip
->di_size
, -tmp_elen
);
982 ino_dir_size
-= tmp_elen
;
984 tmp_sfep
= (xfs_dir2_sf_entry_t
*)
985 ((__psint_t
) sfep
+ tmp_elen
);
986 tmp_len
= max_size
- ((__psint_t
) tmp_sfep
989 memmove(sfep
, tmp_sfep
, tmp_len
);
993 memset((void *) ((__psint_t
) sfep
+ tmp_len
), 0,
997 * reset the tmp value to the current
998 * pointer so we'll process the entry
1004 * WARNING: drop the index i by one
1005 * so it matches the decremented count
1006 * for accurate comparisons later
1014 _("junking entry \"%s\" in directory inode %" PRIu64
"\n"),
1018 _("would have junked entry \"%s\" in directory inode %" PRIu64
"\n"),
1021 } else if (lino
> XFS_DIR2_MAX_SHORT_INUM
)
1024 * go onto next entry unless we've just junked an
1025 * entry in which the current entry pointer points
1026 * to an unprocessed entry. have to take into zero-len
1027 * entries into account in no modify mode since we
1028 * calculate size based on next_sfep.
1030 next_sfep
= (tmp_sfep
== NULL
)
1031 ? (xfs_dir2_sf_entry_t
*) ((__psint_t
) sfep
1033 ? xfs_dir2_sf_entsize(&sfp
->hdr
, sfep
->namelen
)
1034 : xfs_dir2_sf_entsize(&sfp
->hdr
, namelen
)))
1038 /* sync up sizes and entry counts */
1040 if (sfp
->hdr
.count
!= i
) {
1043 _("would have corrected entry count in directory %" PRIu64
" from %d to %d\n"),
1044 ino
, sfp
->hdr
.count
, i
);
1047 _("corrected entry count in directory %" PRIu64
", was %d, now %d\n"),
1048 ino
, sfp
->hdr
.count
, i
);
1055 if (sfp
->hdr
.i8count
!= i8
) {
1058 _("would have corrected i8 count in directory %" PRIu64
" from %d to %d\n"),
1059 ino
, sfp
->hdr
.i8count
, i8
);
1062 _("corrected i8 count in directory %" PRIu64
", was %d, now %d\n"),
1063 ino
, sfp
->hdr
.i8count
, i8
);
1065 process_sf_dir2_fixi8(sfp
, &next_sfep
);
1067 sfp
->hdr
.i8count
= i8
;
1073 if ((intptr_t)next_sfep
- (intptr_t)sfp
!= ino_dir_size
) {
1076 _("would have corrected directory %" PRIu64
" size from %" PRId64
" to %" PRIdPTR
"\n"),
1078 (intptr_t)next_sfep
- (intptr_t)sfp
);
1081 _("corrected directory %" PRIu64
" size, was %" PRId64
", now %" PRIdPTR
"\n"),
1083 (intptr_t)next_sfep
- (intptr_t)sfp
);
1085 dip
->di_size
= cpu_to_be64(
1086 (__psint_t
)next_sfep
- (__psint_t
)sfp
);
1091 if (offset
+ (sfp
->hdr
.count
+ 2) * sizeof(xfs_dir2_leaf_entry_t
) +
1092 sizeof(xfs_dir2_block_tail_t
) > mp
->m_dirblksize
) {
1093 do_warn(_("directory %" PRIu64
" offsets too high\n"), ino
);
1099 _("would have corrected entry offsets in directory %" PRIu64
"\n"),
1103 _("corrected entry offsets in directory %" PRIu64
"\n"),
1105 process_sf_dir2_fixoff(dip
);
1112 * check parent (..) entry
1114 *parent
= xfs_dir2_sf_get_parent_ino(&sfp
->hdr
);
1117 * if parent entry is bogus, null it out. we'll fix it later .
1119 if (verify_inum(mp
, *parent
)) {
1122 _("bogus .. inode number (%" PRIu64
") in directory inode %" PRIu64
", "),
1124 *parent
= NULLFSINO
;
1126 do_warn(_("clearing inode number\n"));
1128 xfs_dir2_sf_put_parent_ino(&sfp
->hdr
, zero
);
1132 do_warn(_("would clear inode number\n"));
1134 } else if (ino
== mp
->m_sb
.sb_rootino
&& ino
!= *parent
) {
1136 * root directories must have .. == .
1140 _("corrected root directory %" PRIu64
" .. entry, was %" PRIu64
", now %" PRIu64
"\n"),
1143 xfs_dir2_sf_put_parent_ino(&sfp
->hdr
, ino
);
1148 _("would have corrected root directory %" PRIu64
" .. entry from %" PRIu64
" to %" PRIu64
"\n"),
1151 } else if (ino
== *parent
&& ino
!= mp
->m_sb
.sb_rootino
) {
1153 * likewise, non-root directories can't have .. pointing
1156 *parent
= NULLFSINO
;
1158 _("bad .. entry in directory inode %" PRIu64
", points to self, "),
1161 do_warn(_("clearing inode number\n"));
1163 xfs_dir2_sf_put_parent_ino(&sfp
->hdr
, zero
);
1167 do_warn(_("would clear inode number\n"));
1175 * Process one directory data block.
1184 char *dirname
, /* directory pathname */
1185 xfs_ino_t
*parent
, /* out - NULLFSINO if entry not exist */
1187 int *dot
, /* out - 1 if there is a dot, else 0 */
1188 int *dotdot
, /* out - 1 if there's a dotdot, else 0 */
1194 xfs_dir2_data_free_t
*bf
;
1196 char *clearreason
= NULL
;
1198 xfs_dir2_data_entry_t
*dep
;
1199 xfs_dir2_data_free_t
*dfp
;
1200 xfs_dir2_data_unused_t
*dup
;
1204 ino_tree_node_t
*irec_p
;
1212 bf
= d
->hdr
.bestfree
;
1214 badbest
= lastfree
= freeseen
= 0;
1215 if (be16_to_cpu(bf
[0].length
) == 0) {
1216 badbest
|= be16_to_cpu(bf
[0].offset
) != 0;
1219 if (be16_to_cpu(bf
[1].length
) == 0) {
1220 badbest
|= be16_to_cpu(bf
[1].offset
) != 0;
1223 if (be16_to_cpu(bf
[2].length
) == 0) {
1224 badbest
|= be16_to_cpu(bf
[2].offset
) != 0;
1227 badbest
|= be16_to_cpu(bf
[0].length
) < be16_to_cpu(bf
[1].length
);
1228 badbest
|= be16_to_cpu(bf
[1].length
) < be16_to_cpu(bf
[2].length
);
1229 while (ptr
< endptr
) {
1230 dup
= (xfs_dir2_data_unused_t
*)ptr
;
1232 * If it's unused, look for the space in the bestfree table.
1233 * If we find it, account for that, else make sure it doesn't
1236 if (be16_to_cpu(dup
->freetag
) == XFS_DIR2_DATA_FREE_TAG
) {
1237 if (ptr
+ be16_to_cpu(dup
->length
) > endptr
||
1238 be16_to_cpu(dup
->length
) == 0 ||
1239 (be16_to_cpu(dup
->length
) & (XFS_DIR2_DATA_ALIGN
- 1)))
1241 if (be16_to_cpu(*xfs_dir2_data_unused_tag_p(dup
)) !=
1242 (char *)dup
- (char *)d
)
1244 badbest
|= lastfree
!= 0;
1245 dfp
= xfs_dir2_data_freefind(&d
->hdr
, dup
);
1248 badbest
|= (freeseen
& (1 << i
)) != 0;
1251 badbest
|= be16_to_cpu(dup
->length
) >
1252 be16_to_cpu(bf
[2].length
);
1253 ptr
+= be16_to_cpu(dup
->length
);
1257 dep
= (xfs_dir2_data_entry_t
*)ptr
;
1258 if (ptr
+ xfs_dir2_data_entsize(dep
->namelen
) > endptr
)
1260 if (be16_to_cpu(*xfs_dir2_data_entry_tag_p(dep
)) !=
1261 (char *)dep
- (char *)d
)
1263 ptr
+= xfs_dir2_data_entsize(dep
->namelen
);
1267 * Dropped out before we processed everything, give up.
1268 * Phase 6 will kill this block if we don't kill the inode.
1270 if (ptr
!= endptr
) {
1271 do_warn(_("corrupt block %u in directory inode %" PRIu64
"\n"),
1274 do_warn(_("\twill junk block\n"));
1276 do_warn(_("\twould junk block\n"));
1281 * Process the entries now.
1283 while (ptr
< endptr
) {
1284 dup
= (xfs_dir2_data_unused_t
*)ptr
;
1285 if (be16_to_cpu(dup
->freetag
) == XFS_DIR2_DATA_FREE_TAG
) {
1286 ptr
+= be16_to_cpu(dup
->length
);
1289 dep
= (xfs_dir2_data_entry_t
*)ptr
;
1290 ent_ino
= be64_to_cpu(dep
->inumber
);
1294 * We may have to blow out an entry because of bad inode
1295 * numbers. Do NOT touch the name until after we've computed
1296 * the hashvalue and done a namecheck() on the name.
1298 * Conditions must either set clearino to zero or set
1299 * clearreason why it's being cleared.
1301 if (!ino_discovery
&& ent_ino
== BADFSINO
) {
1303 * Don't do a damned thing. We already found this
1304 * (or did it ourselves) during phase 3.
1307 } else if (verify_inum(mp
, ent_ino
)) {
1309 * Bad inode number. Clear the inode number and the
1310 * entry will get removed later. We don't trash the
1311 * directory since it's still structurally intact.
1313 clearreason
= _("invalid");
1314 } else if (ent_ino
== mp
->m_sb
.sb_rbmino
) {
1315 clearreason
= _("realtime bitmap");
1316 } else if (ent_ino
== mp
->m_sb
.sb_rsumino
) {
1317 clearreason
= _("realtime summary");
1318 } else if (ent_ino
== mp
->m_sb
.sb_uquotino
) {
1319 clearreason
= _("user quota");
1320 } else if (ent_ino
== mp
->m_sb
.sb_gquotino
) {
1321 clearreason
= _("group quota");
1323 irec_p
= find_inode_rec(mp
,
1324 XFS_INO_TO_AGNO(mp
, ent_ino
),
1325 XFS_INO_TO_AGINO(mp
, ent_ino
));
1326 if (irec_p
== NULL
) {
1327 if (ino_discovery
) {
1328 add_inode_uncertain(mp
, ent_ino
, 0);
1331 clearreason
= _("non-existent");
1334 * Inode recs should have only confirmed
1337 ino_off
= XFS_INO_TO_AGINO(mp
, ent_ino
)
1338 - irec_p
->ino_startnum
;
1339 ASSERT(is_inode_confirmed(irec_p
, ino_off
));
1341 * If inode is marked free and we're in inode
1342 * discovery mode, leave the entry alone for
1343 * now. If the inode turns out to be used,
1344 * we'll figure that out when we scan it.
1345 * If the inode really is free, we'll hit this
1346 * code again in phase 4 after we've finished
1347 * inode discovery and blow out the entry then.
1349 if (!ino_discovery
&& is_inode_free(irec_p
,
1351 clearreason
= _("free");
1356 ASSERT((clearino
== 0 && clearreason
== NULL
) ||
1357 (clearino
!= 0 && clearreason
!= NULL
));
1360 _("entry \"%*.*s\" at block %d offset %" PRIdPTR
" in directory inode %" PRIu64
1361 " references %s inode %" PRIu64
"\n"),
1362 dep
->namelen
, dep
->namelen
, dep
->name
,
1363 da_bno
, (intptr_t)ptr
- (intptr_t)d
, ino
,
1364 clearreason
, ent_ino
);
1366 * If the name length is 0 (illegal) make it 1 and blast
1369 if (dep
->namelen
== 0) {
1371 _("entry at block %u offset %" PRIdPTR
" in directory inode %" PRIu64
1372 "has 0 namelength\n"),
1373 da_bno
, (intptr_t)ptr
- (intptr_t)d
, ino
);
1379 * If needed to clear the inode number, do it now.
1384 _("\tclearing inode number in entry at offset %" PRIdPTR
"...\n"),
1385 (intptr_t)ptr
- (intptr_t)d
);
1386 dep
->inumber
= cpu_to_be64(BADFSINO
);
1391 _("\twould clear inode number in entry at offset %" PRIdPTR
"...\n"),
1392 (intptr_t)ptr
- (intptr_t)d
);
1396 * Only complain about illegal names in phase 3 (when inode
1397 * discovery is turned on). Otherwise, we'd complain a lot
1400 junkit
= ent_ino
== BADFSINO
;
1401 nm_illegal
= namecheck((char *)dep
->name
, dep
->namelen
);
1402 if (ino_discovery
&& nm_illegal
) {
1404 _("entry at block %u offset %" PRIdPTR
" in directory inode %" PRIu64
" has illegal name \"%*.*s\": "),
1405 da_bno
, (intptr_t)ptr
- (intptr_t)d
, ino
,
1406 dep
->namelen
, dep
->namelen
, dep
->name
);
1410 * Now we can mark entries with BADFSINO's bad.
1412 if (!no_modify
&& ent_ino
== BADFSINO
) {
1418 * Special .. entry processing.
1420 if (dep
->namelen
== 2 &&
1421 dep
->name
[0] == '.' && dep
->name
[1] == '.') {
1426 * What if .. == .? Legal only in the root
1427 * inode. Blow out entry and set parent to
1428 * NULLFSINO otherwise.
1430 if (ino
== ent_ino
&&
1431 ino
!= mp
->m_sb
.sb_rootino
) {
1432 *parent
= NULLFSINO
;
1434 _("bad .. entry in directory inode %" PRIu64
", points to self: "),
1439 * We have to make sure that . == .. in the
1442 else if (ino
!= ent_ino
&&
1443 ino
== mp
->m_sb
.sb_rootino
) {
1445 _("bad .. entry in root directory inode %" PRIu64
", was %" PRIu64
": "),
1448 do_warn(_("correcting\n"));
1449 dep
->inumber
= cpu_to_be64(ino
);
1452 do_warn(_("would correct\n"));
1457 * Can't fix the directory unless we know which ..
1458 * entry is the right one. Both have valid inode
1459 * numbers or we wouldn't be here. So since both
1460 * seem equally valid, trash this one.
1464 _("multiple .. entries in directory inode %" PRIu64
": "),
1470 * Special . entry processing.
1472 else if (dep
->namelen
== 1 && dep
->name
[0] == '.') {
1475 if (ent_ino
!= ino
) {
1477 _("bad . entry in directory inode %" PRIu64
", was %" PRIu64
": "),
1480 do_warn(_("correcting\n"));
1481 dep
->inumber
= cpu_to_be64(ino
);
1484 do_warn(_("would correct\n"));
1489 _("multiple . entries in directory inode %" PRIu64
": "),
1495 * All other entries -- make sure only . references self.
1497 else if (ent_ino
== ino
) {
1499 _("entry \"%*.*s\" in directory inode %" PRIu64
" points to self: "),
1500 dep
->namelen
, dep
->namelen
, dep
->name
, ino
);
1504 * Clear junked entries.
1510 do_warn(_("clearing entry\n"));
1512 do_warn(_("would clear entry\n"));
1516 * Advance to the next entry.
1518 ptr
+= xfs_dir2_data_entsize(dep
->namelen
);
1521 * Check the bestfree table.
1523 if (freeseen
!= 7 || badbest
) {
1525 _("bad bestfree table in block %u in directory inode %" PRIu64
": "),
1528 do_warn(_("repairing table\n"));
1529 libxfs_dir2_data_freescan(mp
, &d
->hdr
, &i
);
1532 do_warn(_("would repair table\n"));
1539 * Process a block-format directory.
1548 int *dino_dirty
, /* out - 1 if dinode buffer dirty */
1549 char *dirname
, /* directory pathname */
1550 xfs_ino_t
*parent
, /* out - NULLFSINO if entry not exist */
1552 int *dot
, /* out - 1 if there is a dot, else 0 */
1553 int *dotdot
, /* out - 1 if there's a dotdot, else 0 */
1554 int *repair
) /* out - 1 if something was fixed */
1556 xfs_dir2_block_t
*block
;
1557 xfs_dir2_leaf_entry_t
*blp
;
1560 xfs_dir2_block_tail_t
*btp
;
1566 *repair
= *dot
= *dotdot
= 0;
1567 *parent
= NULLFSINO
;
1568 nex
= blkmap_getn(blkmap
, mp
->m_dirdatablk
, mp
->m_dirblkfsbs
, &bmp
, &lbmp
);
1571 _("block %u for directory inode %" PRIu64
" is missing\n"),
1572 mp
->m_dirdatablk
, ino
);
1575 bp
= da_read_buf(mp
, nex
, bmp
);
1580 _("can't read block %u for directory inode %" PRIu64
"\n"),
1581 mp
->m_dirdatablk
, ino
);
1588 if (be32_to_cpu(block
->hdr
.magic
) != XFS_DIR2_BLOCK_MAGIC
)
1590 _("bad directory block magic # %#x in block %u for directory inode %" PRIu64
"\n"),
1591 be32_to_cpu(block
->hdr
.magic
), mp
->m_dirdatablk
, ino
);
1593 * process the data area
1594 * this also checks & fixes the bestfree
1596 btp
= xfs_dir2_block_tail_p(mp
, &block
->hdr
);
1597 blp
= xfs_dir2_block_leaf_p(btp
);
1599 * Don't let this go past the end of the block.
1601 if ((char *)blp
> (char *)btp
)
1602 blp
= (xfs_dir2_leaf_entry_t
*)btp
;
1603 rval
= process_dir2_data(mp
, ino
, dip
, ino_discovery
, dirname
, parent
,
1604 bp
, dot
, dotdot
, mp
->m_dirdatablk
, (char *)blp
, &dirty
);
1605 if (dirty
&& !no_modify
) {
1607 libxfs_writebuf(bp
, 0);
1614 * Validates leaf contents, node format directories only.
1615 * magic number and sibling pointers checked by caller.
1616 * Returns 0 if block is ok, 1 if the block is bad.
1617 * Looking for: out of order hash values, bad stale counts.
1620 process_leaf_block_dir2(
1622 xfs_dir2_leaf_t
*leaf
,
1625 xfs_dahash_t last_hashval
,
1626 xfs_dahash_t
*next_hashval
)
1630 struct xfs_dir2_leaf_entry
*ents
;
1632 ents
= xfs_dir3_leaf_ents_p(leaf
);
1634 for (i
= stale
= 0; i
< be16_to_cpu(leaf
->hdr
.count
); i
++) {
1635 if ((char *)&ents
[i
] >= (char *)leaf
+ mp
->m_dirblksize
) {
1637 _("bad entry count in block %u of directory inode %" PRIu64
"\n"),
1641 if (be32_to_cpu(ents
[i
].address
) == XFS_DIR2_NULL_DATAPTR
)
1643 else if (be32_to_cpu(ents
[i
].hashval
) < last_hashval
) {
1645 _("bad hash ordering in block %u of directory inode %" PRIu64
"\n"),
1649 *next_hashval
= last_hashval
= be32_to_cpu(ents
[i
].hashval
);
1651 if (stale
!= be16_to_cpu(leaf
->hdr
.stale
)) {
1653 _("bad stale count in block %u of directory inode %" PRIu64
"\n"),
1661 * Returns 0 if the directory is ok, 1 if it has to be rebuilt.
1664 process_leaf_level_dir2(
1666 dir2_bt_cursor_t
*da_cursor
,
1672 xfs_dahash_t current_hashval
;
1674 xfs_dahash_t greatest_hashval
;
1676 xfs_dir2_leaf_t
*leaf
;
1678 xfs_dablk_t prev_bno
;
1681 da_bno
= da_cursor
->level
[0].bno
;
1682 ino
= da_cursor
->ino
;
1685 current_hashval
= 0;
1686 greatest_hashval
= 0;
1690 nex
= blkmap_getn(da_cursor
->blkmap
, da_bno
, mp
->m_dirblkfsbs
,
1693 * Directory code uses 0 as the NULL block pointer since 0
1694 * is the root block and no directory block pointer can point
1695 * to the root block of the btree.
1697 ASSERT(da_bno
!= 0);
1701 _("can't map block %u for directory inode %" PRIu64
"\n"),
1705 bp
= da_read_buf(mp
, nex
, bmp
);
1711 _("can't read file block %u for directory inode %" PRIu64
"\n"),
1717 * Check magic number for leaf directory btree block.
1719 if (be16_to_cpu(leaf
->hdr
.info
.magic
) !=
1720 XFS_DIR2_LEAFN_MAGIC
) {
1722 _("bad directory leaf magic # %#x for directory inode %" PRIu64
" block %u\n"),
1723 be16_to_cpu(leaf
->hdr
.info
.magic
),
1730 * For each block, process the block, verify its path,
1731 * then get next block. Update cursor values along the way.
1733 if (process_leaf_block_dir2(mp
, leaf
, da_bno
, ino
,
1734 current_hashval
, &greatest_hashval
)) {
1739 * Index can be set to hdr.count so match the indices of the
1740 * interior blocks -- which at the end of the block will point
1741 * to 1 after the final real entry in the block.
1743 da_cursor
->level
[0].hashval
= greatest_hashval
;
1744 da_cursor
->level
[0].bp
= bp
;
1745 da_cursor
->level
[0].bno
= da_bno
;
1746 da_cursor
->level
[0].index
=
1747 be16_to_cpu(leaf
->hdr
.count
);
1748 da_cursor
->level
[0].dirty
= buf_dirty
;
1750 if (be32_to_cpu(leaf
->hdr
.info
.back
) != prev_bno
) {
1752 _("bad sibling back pointer for block %u in directory inode %" PRIu64
"\n"),
1758 da_bno
= be32_to_cpu(leaf
->hdr
.info
.forw
);
1760 if (verify_dir2_path(mp
, da_cursor
, 0)) {
1765 current_hashval
= greatest_hashval
;
1766 ASSERT(buf_dirty
== 0 || (buf_dirty
&& !no_modify
));
1767 if (buf_dirty
&& !no_modify
) {
1769 libxfs_writebuf(bp
, 0);
1772 } while (da_bno
!= 0);
1773 if (verify_final_dir2_path(mp
, da_cursor
, 0)) {
1775 * Verify the final path up (right-hand-side) if still ok.
1777 do_warn(_("bad hash path in directory %" PRIu64
"\n"), ino
);
1781 * Redundant but just for testing.
1783 release_dir2_cursor(mp
, da_cursor
, 0);
1788 * Release all buffers holding interior btree blocks.
1790 err_release_dir2_cursor(mp
, da_cursor
, 0);
1791 if (bmp
&& (bmp
!= &lbmp
))
1797 * Return 1 if the directory's leaf/node space is corrupted and
1798 * needs to be rebuilt, 0 if it's ok.
1809 dir2_bt_cursor_t da_cursor
;
1812 * Try again -- traverse down left-side of tree until we hit the
1813 * left-most leaf block setting up the btree cursor along the way.
1814 * Then walk the leaf blocks left-to-right, calling a parent
1815 * verification routine each time we traverse a block.
1817 memset(&da_cursor
, 0, sizeof(da_cursor
));
1818 da_cursor
.ino
= ino
;
1819 da_cursor
.dip
= dip
;
1820 da_cursor
.blkmap
= blkmap
;
1823 * Now process interior node.
1825 if (traverse_int_dir2block(mp
, &da_cursor
, &bno
) == 0)
1829 * Skip directories with a root marked XFS_DIR2_LEAFN_MAGIC
1832 release_dir2_cursor(mp
, &da_cursor
, 0);
1836 * Now pass cursor and bno into leaf-block processing routine.
1837 * The leaf dir level routine checks the interior paths up to
1838 * the root including the final right-most path.
1840 return process_leaf_level_dir2(mp
, &da_cursor
, repair
);
1845 * Process leaf and node directories.
1846 * Process the data blocks then, if it's a node directory, check
1847 * the consistency of those blocks.
1850 process_leaf_node_dir2(
1855 char *dirname
, /* directory pathname */
1856 xfs_ino_t
*parent
, /* out - NULLFSINO if entry not exist */
1858 int *dot
, /* out - 1 if there is a dot, else 0 */
1859 int *dotdot
, /* out - 1 if there's a dotdot, else 0 */
1860 int *repair
, /* out - 1 if something was fixed */
1861 int isnode
) /* node directory not leaf */
1865 xfs_dir2_data_t
*data
;
1869 xfs_dfiloff_t ndbno
;
1875 *repair
= *dot
= *dotdot
= good
= 0;
1876 *parent
= NULLFSINO
;
1877 ndbno
= NULLDFILOFF
;
1878 while ((dbno
= blkmap_next_off(blkmap
, ndbno
, &t
)) < mp
->m_dirleafblk
) {
1879 nex
= blkmap_getn(blkmap
, dbno
, mp
->m_dirblkfsbs
, &bmp
, &lbmp
);
1880 /* Advance through map to last dfs block in this dir block */
1882 while (ndbno
< dbno
+ mp
->m_dirblkfsbs
- 1) {
1883 ndbno
= blkmap_next_off(blkmap
, ndbno
, &t
);
1887 _("block %" PRIu64
" for directory inode %" PRIu64
" is missing\n"),
1891 bp
= da_read_buf(mp
, nex
, bmp
);
1896 _("can't read block %" PRIu64
" for directory inode %" PRIu64
"\n"),
1901 if (be32_to_cpu(data
->hdr
.magic
) != XFS_DIR2_DATA_MAGIC
)
1903 _("bad directory block magic # %#x in block %" PRIu64
" for directory inode %" PRIu64
"\n"),
1904 be32_to_cpu(data
->hdr
.magic
), dbno
, ino
);
1905 i
= process_dir2_data(mp
, ino
, dip
, ino_discovery
, dirname
,
1906 parent
, bp
, dot
, dotdot
, (xfs_dablk_t
)dbno
,
1907 (char *)data
+ mp
->m_dirblksize
, &dirty
);
1910 if (dirty
&& !no_modify
) {
1912 libxfs_writebuf(bp
, 0);
1920 if (dir2_is_badino(ino
))
1923 if (process_node_dir2(mp
, ino
, dip
, blkmap
, repair
))
1924 dir2_add_badlist(ino
);
1930 * Returns 1 if things are bad (directory needs to be junked)
1931 * and 0 if things are ok. If ino_discovery is 1, add unknown
1932 * inodes to uncertain inode list.
1951 *parent
= NULLFSINO
;
1956 * branch off depending on the type of inode. This routine
1957 * is only called ONCE so all the subordinate routines will
1958 * fix '.' and junk '..' if they're bogus.
1961 last
= blkmap_last_off(blkmap
);
1962 if (be64_to_cpu(dip
->di_size
) <= XFS_DFORK_DSIZE(dip
, mp
) &&
1963 dip
->di_format
== XFS_DINODE_FMT_LOCAL
) {
1965 res
= process_sf_dir2(mp
, ino
, dip
, ino_discovery
, dino_dirty
,
1966 dirname
, parent
, &repair
);
1967 } else if (last
== mp
->m_dirblkfsbs
&&
1968 (dip
->di_format
== XFS_DINODE_FMT_EXTENTS
||
1969 dip
->di_format
== XFS_DINODE_FMT_BTREE
)) {
1970 res
= process_block_dir2(mp
, ino
, dip
, ino_discovery
,
1971 dino_dirty
, dirname
, parent
, blkmap
, &dot
, &dotdot
,
1973 } else if (last
>= mp
->m_dirleafblk
+ mp
->m_dirblkfsbs
&&
1974 (dip
->di_format
== XFS_DINODE_FMT_EXTENTS
||
1975 dip
->di_format
== XFS_DINODE_FMT_BTREE
)) {
1976 res
= process_leaf_node_dir2(mp
, ino
, dip
, ino_discovery
,
1977 dirname
, parent
, blkmap
, &dot
, &dotdot
, &repair
,
1978 last
> mp
->m_dirleafblk
+ mp
->m_dirblkfsbs
);
1980 do_warn(_("bad size/format for directory %" PRIu64
"\n"), ino
);
1984 * bad . entries in all directories will be fixed up in phase 6
1987 do_warn(_("no . entry for directory %" PRIu64
"\n"), ino
);
1991 * shortform dirs always have a .. entry. .. for all longform
1992 * directories will get fixed in phase 6. .. for other shortform
1993 * dirs also get fixed there. .. for a shortform root was
1994 * fixed in place since we know what it should be
1996 if (dotdot
== 0 && ino
!= mp
->m_sb
.sb_rootino
) {
1997 do_warn(_("no .. entry for directory %" PRIu64
"\n"), ino
);
1998 } else if (dotdot
== 0 && ino
== mp
->m_sb
.sb_rootino
) {
1999 do_warn(_("no .. entry for root directory %" PRIu64
"\n"), ino
);
2000 need_root_dotdot
= 1;
2003 ASSERT((ino
!= mp
->m_sb
.sb_rootino
&& ino
!= *parent
) ||
2004 (ino
== mp
->m_sb
.sb_rootino
&&
2005 (ino
== *parent
|| need_root_dotdot
== 1)));