2 * Copyright (c) 2000-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
25 #include "err_protos.h"
30 #include "attr_repair.h"
35 * inode clearing routines
39 clear_dinode_attr(xfs_mount_t *mp, xfs_dinode_t *dino, xfs_ino_t ino_num)
41 ASSERT(dino->di_forkoff != 0);
45 _("clearing inode %" PRIu64 " attributes\n"), ino_num);
48 _("would have cleared inode %" PRIu64 " attributes\n"), ino_num);
50 if (be16_to_cpu(dino->di_anextents) != 0) {
53 dino->di_anextents = cpu_to_be16(0);
56 if (dino->di_aformat != XFS_DINODE_FMT_EXTENTS) {
59 dino->di_aformat = XFS_DINODE_FMT_EXTENTS;
62 /* get rid of the fork by clearing forkoff */
64 /* Originally, when the attr repair code was added, the fork was cleared
65 * by turning it into shortform status. This meant clearing the
66 * hdr.totsize/count fields and also changing aformat to LOCAL
67 * (vs EXTENTS). Over various fixes, the aformat and forkoff have
68 * been updated to not show an attribute fork at all, however.
69 * It could be possible that resetting totsize/count are not needed,
70 * but just to be safe, leave it in for now.
74 xfs_attr_shortform_t *asf = (xfs_attr_shortform_t *)
76 asf->hdr.totsize = cpu_to_be16(sizeof(xfs_attr_sf_hdr_t));
78 dino->di_forkoff = 0; /* got to do this after asf is set */
82 * always returns 1 since the fork gets zapped
88 clear_dinode_core(struct xfs_mount *mp, xfs_dinode_t *dinoc, xfs_ino_t ino_num)
93 #define __dirty_no_modify_ret(dirty) \
94 ({ (dirty) = 1; if (no_modify) return 1; })
96 if (be16_to_cpu(dinoc->di_magic) != XFS_DINODE_MAGIC) {
97 __dirty_no_modify_ret(dirty);
98 dinoc->di_magic = cpu_to_be16(XFS_DINODE_MAGIC);
101 if (!XFS_DINODE_GOOD_VERSION(dinoc->di_version) ||
102 (!fs_inode_nlink && dinoc->di_version > 1)) {
103 __dirty_no_modify_ret(dirty);
104 if (xfs_sb_version_hascrc(&mp->m_sb))
105 dinoc->di_version = 3;
107 dinoc->di_version = (fs_inode_nlink) ? 2 : 1;
110 if (be16_to_cpu(dinoc->di_mode) != 0) {
111 __dirty_no_modify_ret(dirty);
115 if (be16_to_cpu(dinoc->di_flags) != 0) {
116 __dirty_no_modify_ret(dirty);
120 if (be32_to_cpu(dinoc->di_dmevmask) != 0) {
121 __dirty_no_modify_ret(dirty);
122 dinoc->di_dmevmask = 0;
125 if (dinoc->di_forkoff != 0) {
126 __dirty_no_modify_ret(dirty);
127 dinoc->di_forkoff = 0;
130 if (dinoc->di_format != XFS_DINODE_FMT_EXTENTS) {
131 __dirty_no_modify_ret(dirty);
132 dinoc->di_format = XFS_DINODE_FMT_EXTENTS;
135 if (dinoc->di_aformat != XFS_DINODE_FMT_EXTENTS) {
136 __dirty_no_modify_ret(dirty);
137 dinoc->di_aformat = XFS_DINODE_FMT_EXTENTS;
140 if (be64_to_cpu(dinoc->di_size) != 0) {
141 __dirty_no_modify_ret(dirty);
145 if (be64_to_cpu(dinoc->di_nblocks) != 0) {
146 __dirty_no_modify_ret(dirty);
147 dinoc->di_nblocks = 0;
150 if (be16_to_cpu(dinoc->di_onlink) != 0) {
151 __dirty_no_modify_ret(dirty);
152 dinoc->di_onlink = 0;
155 if (be32_to_cpu(dinoc->di_nextents) != 0) {
156 __dirty_no_modify_ret(dirty);
157 dinoc->di_nextents = 0;
160 if (be16_to_cpu(dinoc->di_anextents) != 0) {
161 __dirty_no_modify_ret(dirty);
162 dinoc->di_anextents = 0;
165 if (dinoc->di_version > 1 &&
166 be32_to_cpu(dinoc->di_nlink) != 0) {
167 __dirty_no_modify_ret(dirty);
171 /* we are done for version 1/2 inodes */
172 if (dinoc->di_version < 3)
175 if (be64_to_cpu(dinoc->di_ino) != ino_num) {
176 __dirty_no_modify_ret(dirty);
177 dinoc->di_ino = cpu_to_be64(ino_num);
180 if (platform_uuid_compare(&dinoc->di_uuid, &mp->m_sb.sb_uuid)) {
181 __dirty_no_modify_ret(dirty);
182 platform_uuid_copy(&dinoc->di_uuid, &mp->m_sb.sb_uuid);
185 for (i = 0; i < 16; i++) {
186 if (dinoc->di_pad[i] != 0) {
187 __dirty_no_modify_ret(dirty);
188 memset(dinoc->di_pad, 0, 16);
193 if (be64_to_cpu(dinoc->di_flags2) != 0) {
194 __dirty_no_modify_ret(dirty);
195 dinoc->di_flags2 = 0;
198 if (be64_to_cpu(dinoc->di_lsn) != 0) {
199 __dirty_no_modify_ret(dirty);
203 if (be64_to_cpu(dinoc->di_changecount) != 0) {
204 __dirty_no_modify_ret(dirty);
205 dinoc->di_changecount = 0;
212 clear_dinode_unlinked(xfs_mount_t *mp, xfs_dinode_t *dino)
215 if (be32_to_cpu(dino->di_next_unlinked) != NULLAGINO) {
217 dino->di_next_unlinked = cpu_to_be32(NULLAGINO);
225 * this clears the unlinked list too so it should not be called
226 * until after the agi unlinked lists are walked in phase 3.
227 * returns > zero if the inode has been altered while being cleared
230 clear_dinode(xfs_mount_t *mp, xfs_dinode_t *dino, xfs_ino_t ino_num)
234 dirty = clear_dinode_core(mp, dino, ino_num);
235 dirty += clear_dinode_unlinked(mp, dino);
237 /* and clear the forks */
239 if (dirty && !no_modify)
240 memset(XFS_DFORK_DPTR(dino), 0,
241 XFS_LITINO(mp, dino->di_version));
248 * misc. inode-related utility routines
252 * verify_ag_bno is heavily used. In the common case, it
253 * performs just two number of compares
254 * Returns 1 for bad ag/bno pair or 0 if it's valid.
257 verify_ag_bno(xfs_sb_t *sbp,
261 if (agno < (sbp->sb_agcount - 1))
262 return (agbno >= sbp->sb_agblocks);
263 if (agno == (sbp->sb_agcount - 1))
264 return (agbno >= (sbp->sb_dblocks -
265 ((xfs_drfsbno_t)(sbp->sb_agcount - 1) *
271 * returns 0 if inode number is valid, 1 if bogus
274 verify_inum(xfs_mount_t *mp,
280 xfs_sb_t *sbp = &mp->m_sb;;
282 /* range check ag #, ag block. range-checking offset is pointless */
284 agno = XFS_INO_TO_AGNO(mp, ino);
285 agino = XFS_INO_TO_AGINO(mp, ino);
286 agbno = XFS_AGINO_TO_AGBNO(mp, agino);
290 if (ino == 0 || ino == NULLFSINO)
293 if (ino != XFS_AGINO_TO_INO(mp, agno, agino))
296 return verify_ag_bno(sbp, agno, agbno);
300 * have a separate routine to ensure that we don't accidentally
301 * lose illegally set bits in the agino by turning it into an FSINO
302 * to feed to the above routine
305 verify_aginum(xfs_mount_t *mp,
310 xfs_sb_t *sbp = &mp->m_sb;;
312 /* range check ag #, ag block. range-checking offset is pointless */
314 if (agino == 0 || agino == NULLAGINO)
318 * agino's can't be too close to NULLAGINO because the min blocksize
319 * is 9 bits and at most 1 bit of that gets used for the inode offset
320 * so if the agino gets shifted by the # of offset bits and compared
321 * to the legal agbno values, a bogus agino will be too large. there
322 * will be extra bits set at the top that shouldn't be set.
324 agbno = XFS_AGINO_TO_AGBNO(mp, agino);
328 return verify_ag_bno(sbp, agno, agbno);
332 * return 1 if block number is good, 0 if out of range
335 verify_dfsbno(xfs_mount_t *mp,
340 xfs_sb_t *sbp = &mp->m_sb;;
342 /* range check ag #, ag block. range-checking offset is pointless */
344 agno = XFS_FSB_TO_AGNO(mp, fsbno);
345 agbno = XFS_FSB_TO_AGBNO(mp, fsbno);
347 return verify_ag_bno(sbp, agno, agbno) == 0;
350 #define XR_DFSBNORANGE_VALID 0
351 #define XR_DFSBNORANGE_BADSTART 1
352 #define XR_DFSBNORANGE_BADEND 2
353 #define XR_DFSBNORANGE_OVERFLOW 3
356 verify_dfsbno_range(xfs_mount_t *mp,
358 xfs_dfilblks_t count)
362 xfs_sb_t *sbp = &mp->m_sb;;
364 /* the start and end blocks better be in the same allocation group */
365 agno = XFS_FSB_TO_AGNO(mp, fsbno);
366 if (agno != XFS_FSB_TO_AGNO(mp, fsbno + count - 1)) {
367 return XR_DFSBNORANGE_OVERFLOW;
370 agbno = XFS_FSB_TO_AGBNO(mp, fsbno);
371 if (verify_ag_bno(sbp, agno, agbno)) {
372 return XR_DFSBNORANGE_BADSTART;
375 agbno = XFS_FSB_TO_AGBNO(mp, fsbno + count - 1);
376 if (verify_ag_bno(sbp, agno, agbno)) {
377 return XR_DFSBNORANGE_BADEND;
380 return (XR_DFSBNORANGE_VALID);
384 verify_agbno(xfs_mount_t *mp,
388 xfs_sb_t *sbp = &mp->m_sb;;
390 /* range check ag #, ag block. range-checking offset is pointless */
391 return verify_ag_bno(sbp, agno, agbno) == 0;
397 xfs_bmbt_irec_t *irec,
405 int pwe; /* partially-written extent */
408 * check numeric validity of the extent
410 if (irec->br_startblock >= mp->m_sb.sb_rblocks) {
412 _("inode %" PRIu64 " - bad rt extent start block number %" PRIu64 ", offset %" PRIu64 "\n"),
418 if (irec->br_startblock + irec->br_blockcount - 1 >= mp->m_sb.sb_rblocks) {
420 _("inode %" PRIu64 " - bad rt extent last block number %" PRIu64 ", offset %" PRIu64 "\n"),
422 irec->br_startblock + irec->br_blockcount - 1,
426 if (irec->br_startblock + irec->br_blockcount - 1 < irec->br_startblock) {
428 _("inode %" PRIu64 " - bad rt extent overflows - start %" PRIu64 ", "
429 "end %" PRIu64 ", offset %" PRIu64 "\n"),
432 irec->br_startblock + irec->br_blockcount - 1,
438 * verify that the blocks listed in the record
439 * are multiples of an extent
441 if (xfs_sb_version_hasextflgbit(&mp->m_sb) == 0 &&
442 (irec->br_startblock % mp->m_sb.sb_rextsize != 0 ||
443 irec->br_blockcount % mp->m_sb.sb_rextsize != 0)) {
445 _("malformed rt inode extent [%" PRIu64 " %" PRIu64 "] (fs rtext size = %u)\n"),
448 mp->m_sb.sb_rextsize);
453 * set the appropriate number of extents
454 * this iterates block by block, this can be optimised using extents
456 for (b = irec->br_startblock; b < irec->br_startblock +
457 irec->br_blockcount; b += mp->m_sb.sb_rextsize) {
458 ext = (xfs_drtbno_t) b / mp->m_sb.sb_rextsize;
459 pwe = xfs_sb_version_hasextflgbit(&mp->m_sb) &&
460 irec->br_state == XFS_EXT_UNWRITTEN &&
461 (b % mp->m_sb.sb_rextsize != 0);
463 if (check_dups == 1) {
464 if (search_rt_dup_extent(mp, ext) && !pwe) {
466 _("data fork in rt ino %" PRIu64 " claims dup rt extent,"
467 "off - %" PRIu64 ", start - %" PRIu64 ", count %" PRIu64 "\n"),
471 irec->br_blockcount);
477 state = get_rtbmap(ext);
481 set_rtbmap(ext, XR_E_INUSE);
485 _("bad state in rt block map %" PRIu64 "\n"),
491 _("data fork in rt inode %" PRIu64 " found metadata block %" PRIu64 " in rt bmap\n"),
497 set_rtbmap(ext, XR_E_MULT);
499 _("data fork in rt inode %" PRIu64 " claims used rt block %" PRIu64 "\n"),
505 _("illegal state %d in rt block map %" PRIu64 "\n"),
511 * bump up the block counter
513 *tot += irec->br_blockcount;
519 * return 1 if inode should be cleared, 0 otherwise
520 * if check_dups should be set to 1, that implies that
521 * the primary purpose of this call is to see if the
522 * file overlaps with any duplicate extents (in the
523 * duplicate extent list).
526 process_bmbt_reclist_int(
534 xfs_dfiloff_t *first_key,
535 xfs_dfiloff_t *last_key,
539 xfs_bmbt_irec_t irec;
540 xfs_dfilblks_t cp = 0; /* prev count */
541 xfs_dfsbno_t sp = 0; /* prev start */
542 xfs_dfiloff_t op = 0; /* prev offset */
552 xfs_agnumber_t locked_agno = -1;
555 if (whichfork == XFS_DATA_FORK)
556 forkname = _("data");
558 forkname = _("attr");
560 if (type == XR_INO_RTDATA)
561 ftype = _("real-time");
563 ftype = _("regular");
565 for (i = 0; i < *numrecs; i++) {
566 libxfs_bmbt_disk_get_all(rp + i, &irec);
568 *last_key = *first_key = irec.br_startoff;
570 *last_key = irec.br_startoff;
571 if (i > 0 && op + cp > irec.br_startoff) {
573 _("bmap rec out of order, inode %" PRIu64" entry %d "
574 "[o s c] [%" PRIu64 " %" PRIu64 " %" PRIu64 "], "
575 "%d [%" PRIu64 " %" PRIu64 " %" PRIu64 "]\n"),
576 ino, i, irec.br_startoff, irec.br_startblock,
577 irec.br_blockcount, i - 1, op, sp, cp);
580 op = irec.br_startoff;
581 cp = irec.br_blockcount;
582 sp = irec.br_startblock;
585 * check numeric validity of the extent
587 if (irec.br_blockcount == 0) {
589 _("zero length extent (off = %" PRIu64 ", fsbno = %" PRIu64 ") in ino %" PRIu64 "\n"),
596 if (type == XR_INO_RTDATA && whichfork == XFS_DATA_FORK) {
598 * realtime bitmaps don't use AG locks, so returning
599 * immediately is fine for this code path.
601 if (process_rt_rec(mp, &irec, ino, tot, check_dups))
604 * skip rest of loop processing since that'irec.br_startblock
605 * all for regular file forks and attr forks
611 * regular file data fork or attribute fork
613 switch (verify_dfsbno_range(mp, irec.br_startblock,
614 irec.br_blockcount)) {
615 case XR_DFSBNORANGE_VALID:
618 case XR_DFSBNORANGE_BADSTART:
620 _("inode %" PRIu64 " - bad extent starting block number %" PRIu64 ", offset %" PRIu64 "\n"),
626 case XR_DFSBNORANGE_BADEND:
628 _("inode %" PRIu64 " - bad extent last block number %" PRIu64 ", offset %" PRIu64 "\n"),
630 irec.br_startblock + irec.br_blockcount - 1,
634 case XR_DFSBNORANGE_OVERFLOW:
636 _("inode %" PRIu64 " - bad extent overflows - start %" PRIu64 ", "
637 "end %" PRIu64 ", offset %" PRIu64 "\n"),
640 irec.br_startblock + irec.br_blockcount - 1,
644 if (irec.br_startoff >= fs_max_file_offset) {
646 _("inode %" PRIu64 " - extent offset too large - start %" PRIu64 ", "
647 "count %" PRIu64 ", offset %" PRIu64 "\n"),
648 ino, irec.br_startblock, irec.br_blockcount,
653 if (blkmapp && *blkmapp) {
654 error = blkmap_set_ext(blkmapp, irec.br_startoff,
655 irec.br_startblock, irec.br_blockcount);
658 * we don't want to clear the inode due to an
659 * internal bmap tracking error, but if we've
660 * run out of memory then we simply can't
661 * validate that the filesystem is consistent.
662 * Hence just abort at this point with an ENOMEM
666 _("Fatal error: inode %" PRIu64 " - blkmap_set_ext(): %s\n"
667 "\t%s fork, off - %" PRIu64 ", start - %" PRIu64 ", cnt %" PRIu64 "\n"),
668 ino, strerror(error), forkname,
669 irec.br_startoff, irec.br_startblock,
675 * Profiling shows that the following loop takes the
676 * most time in all of xfs_repair.
678 agno = XFS_FSB_TO_AGNO(mp, irec.br_startblock);
679 agbno = XFS_FSB_TO_AGBNO(mp, irec.br_startblock);
680 ebno = agbno + irec.br_blockcount;
681 if (agno != locked_agno) {
682 if (locked_agno != -1)
683 pthread_mutex_unlock(&ag_locks[locked_agno]);
684 pthread_mutex_lock(&ag_locks[agno]);
690 * if we're just checking the bmap for dups,
691 * return if we find one, otherwise, continue
692 * checking each entry without setting the
695 if (search_dup_extent(agno, agbno, ebno)) {
697 _("%s fork in ino %" PRIu64 " claims dup extent, "
698 "off - %" PRIu64 ", start - %" PRIu64 ", cnt %" PRIu64 "\n"),
699 forkname, ino, irec.br_startoff,
704 *tot += irec.br_blockcount;
708 for (b = irec.br_startblock;
710 b += blen, agbno += blen) {
711 state = get_bmap_ext(agno, agbno, ebno, &blen);
716 _("%s fork in ino %" PRIu64 " claims free block %" PRIu64 "\n"),
717 forkname, ino, (__uint64_t) b);
718 /* fall through ... */
720 set_bmap_ext(agno, agbno, blen, XR_E_INUSE);
724 do_error(_("bad state in block map %" PRIu64 "\n"), b);
730 _("%s fork in inode %" PRIu64 " claims metadata block %" PRIu64 "\n"),
736 set_bmap_ext(agno, agbno, blen, XR_E_MULT);
738 _("%s fork in %s inode %" PRIu64 " claims used block %" PRIu64 "\n"),
739 forkname, ftype, ino, b);
744 _("illegal state %d in block map %" PRIu64 "\n"),
748 *tot += irec.br_blockcount;
752 if (locked_agno != -1)
753 pthread_mutex_unlock(&ag_locks[locked_agno]);
756 ASSERT(i < *numrecs);
757 do_warn(_("correcting nextents for inode %" PRIu64 "\n"), ino);
765 * return 1 if inode should be cleared, 0 otherwise, sets block bitmap
769 process_bmbt_reclist(
777 xfs_dfiloff_t *first_key,
778 xfs_dfiloff_t *last_key,
781 return process_bmbt_reclist_int(mp, rp, numrecs, type, ino, tot,
782 blkmapp, first_key, last_key, 0, whichfork);
786 * return 1 if inode should be cleared, 0 otherwise, does not set
799 xfs_dfiloff_t first_key = 0;
800 xfs_dfiloff_t last_key = 0;
802 return process_bmbt_reclist_int(mp, rp, numrecs, type, ino, tot,
803 NULL, &first_key, &last_key, 1, whichfork);
807 * these two are meant for routines that read and work with inodes
808 * one at a time where the inodes may be in any order (like walking
809 * the unlinked lists to look for inodes). the caller is responsible
810 * for writing/releasing the buffer.
813 get_agino_buf(xfs_mount_t *mp,
818 ino_tree_node_t *irec;
822 if ((irec = find_inode_rec(mp, agno, agino)) == NULL)
825 size = XFS_FSB_TO_BB(mp, MAX(1, XFS_INODES_PER_CHUNK/inodes_per_block));
826 bp = libxfs_readbuf(mp->m_dev, XFS_AGB_TO_DADDR(mp, agno,
827 XFS_AGINO_TO_AGBNO(mp, irec->ino_startnum)), size, 0,
830 do_warn(_("cannot read inode (%u/%u), disk block %" PRIu64 "\n"),
831 agno, irec->ino_startnum,
832 XFS_AGB_TO_DADDR(mp, agno,
833 XFS_AGINO_TO_AGBNO(mp, irec->ino_startnum)));
837 *dipp = xfs_make_iptr(mp, bp, agino -
838 XFS_OFFBNO_TO_AGINO(mp, XFS_AGINO_TO_AGBNO(mp,
846 * these next routines return the filesystem blockno of the
847 * block containing the block "bno" in the file whose bmap
848 * tree (or extent list) is rooted by "rootblock".
850 * the next routines are utility routines for the third
851 * routine, get_bmapi().
853 * NOTE: getfunc_extlist only used by dirv1 checking code
856 getfunc_extlist(xfs_mount_t *mp,
862 xfs_bmbt_irec_t irec;
863 xfs_dfsbno_t final_fsbno = NULLDFSBNO;
864 xfs_bmbt_rec_t *rootblock = (xfs_bmbt_rec_t *)
865 XFS_DFORK_PTR(dip, whichfork);
866 xfs_extnum_t nextents = XFS_DFORK_NEXTENTS(dip, whichfork);
869 for (i = 0; i < nextents; i++) {
870 libxfs_bmbt_disk_get_all(rootblock + i, &irec);
871 if (irec.br_startoff <= bno &&
872 bno < irec.br_startoff + irec.br_blockcount) {
873 final_fsbno = bno - irec.br_startoff + irec.br_startblock;
882 * NOTE: getfunc_btree only used by dirv1 checking code...
885 getfunc_btree(xfs_mount_t *mp,
898 xfs_bmbt_irec_t irec;
901 xfs_bmdr_key_t *rkey;
905 xfs_dfsbno_t final_fsbno = NULLDFSBNO;
906 struct xfs_btree_block *block;
907 xfs_bmdr_block_t *rootblock = (xfs_bmdr_block_t *)
908 XFS_DFORK_PTR(dip, whichfork);
910 ASSERT(rootblock->bb_level != 0);
912 * deal with root block, it's got a slightly different
913 * header structure than interior nodes. We know that
914 * a btree should have at least 2 levels otherwise it
915 * would be an extent list.
917 rkey = XFS_BMDR_KEY_ADDR(rootblock, 1);
918 rp = XFS_BMDR_PTR_ADDR(rootblock, 1,
919 xfs_bmdr_maxrecs(mp, XFS_DFORK_SIZE(dip, mp, whichfork), 1));
921 for (i = 0; i < be16_to_cpu(rootblock->bb_numrecs) - 1; i++) {
922 if (be64_to_cpu(rkey[i].br_startoff) <= bno &&
923 bno < be64_to_cpu(rkey[i + 1].br_startoff)) {
928 if (i == be16_to_cpu(rootblock->bb_numrecs) - 1 &&
929 bno >= be64_to_cpu(rkey[i].br_startoff))
934 fsbno = be64_to_cpu(rp[found]);
936 ASSERT(verify_dfsbno(mp, fsbno));
938 bp = libxfs_readbuf(mp->m_dev, XFS_FSB_TO_DADDR(mp, fsbno),
939 XFS_FSB_TO_BB(mp, 1), 0, NULL);
941 do_error(_("cannot read bmap block %" PRIu64 "\n"), fsbno);
944 block = XFS_BUF_TO_BLOCK(bp);
945 numrecs = be16_to_cpu(block->bb_numrecs);
948 * ok, now traverse any interior btree nodes
951 prev_level = be16_to_cpu(block->bb_level);
954 while (be16_to_cpu(block->bb_level) > 0) {
956 ASSERT(be16_to_cpu(block->bb_level) < prev_level);
958 prev_level = be16_to_cpu(block->bb_level);
960 if (numrecs > mp->m_bmap_dmxr[1]) {
962 _("# of bmap records in inode %" PRIu64 " exceeds max (%u, max - %u)\n"),
968 if (verbose && numrecs < mp->m_bmap_dmnr[1]) {
970 _("- # of bmap records in inode %" PRIu64 " less than minimum (%u, min - %u), proceeding ...\n"),
971 ino, numrecs, mp->m_bmap_dmnr[1]);
973 key = XFS_BMBT_KEY_ADDR(mp, block, 1);
974 pp = XFS_BMBT_PTR_ADDR(mp, block, 1, mp->m_bmap_dmxr[1]);
975 for (found = -1, i = 0; i < numrecs - 1; i++) {
976 if (be64_to_cpu(key[i].br_startoff) <= bno && bno <
977 be64_to_cpu(key[i + 1].br_startoff)) {
982 if (i == numrecs - 1 && bno >= be64_to_cpu(key[i].br_startoff))
986 fsbno = be64_to_cpu(pp[found]);
988 ASSERT(verify_dfsbno(mp, fsbno));
991 * release current btree block and read in the
992 * next btree block to be traversed
995 bp = libxfs_readbuf(mp->m_dev, XFS_FSB_TO_DADDR(mp, fsbno),
996 XFS_FSB_TO_BB(mp, 1), 0, NULL);
998 do_error(_("cannot read bmap block %" PRIu64 "\n"),
1002 block = XFS_BUF_TO_BLOCK(bp);
1003 numrecs = be16_to_cpu(block->bb_numrecs);
1007 * current block must be a leaf block
1009 ASSERT(be16_to_cpu(block->bb_level) == 0);
1010 if (numrecs > mp->m_bmap_dmxr[0]) {
1012 _("# of bmap records in inode %" PRIu64 " greater than maximum (%u, max - %u)\n"),
1013 ino, numrecs, mp->m_bmap_dmxr[0]);
1017 if (verbose && numrecs < mp->m_bmap_dmnr[0])
1019 _("- # of bmap records in inode %" PRIu64 " less than minimum (%u, min - %u), continuing...\n"),
1020 ino, numrecs, mp->m_bmap_dmnr[0]);
1022 rec = XFS_BMBT_REC_ADDR(mp, block, 1);
1023 for (i = 0; i < numrecs; i++) {
1024 libxfs_bmbt_disk_get_all(rec + i, &irec);
1025 if (irec.br_startoff <= bno &&
1026 bno < irec.br_startoff + irec.br_blockcount) {
1027 final_fsbno = bno - irec.br_startoff +
1034 if (final_fsbno == NULLDFSBNO)
1035 do_warn(_("could not map block %" PRIu64 "\n"), bno);
1037 return(final_fsbno);
1041 * this could be smarter. maybe we should have an open inode
1042 * routine that would get the inode buffer and return back
1043 * an inode handle. I'm betting for the moment that this
1044 * is used only by the directory and attribute checking code
1045 * and that the avl tree find and buffer cache search are
1046 * relatively cheap. If they're too expensive, we'll just
1047 * have to fix this and add an inode handle to the da btree
1050 * caller is responsible for checking doubly referenced blocks
1051 * and references to holes
1053 * NOTE: get_bmapi only used by dirv1 checking code
1056 get_bmapi(xfs_mount_t *mp, xfs_dinode_t *dino_p,
1057 xfs_ino_t ino_num, xfs_dfiloff_t bno, int whichfork)
1061 switch (XFS_DFORK_FORMAT(dino_p, whichfork)) {
1062 case XFS_DINODE_FMT_EXTENTS:
1063 fsbno = getfunc_extlist(mp, ino_num, dino_p, bno, whichfork);
1065 case XFS_DINODE_FMT_BTREE:
1066 fsbno = getfunc_btree(mp, ino_num, dino_p, bno, whichfork);
1068 case XFS_DINODE_FMT_LOCAL:
1069 do_error(_("get_bmapi() called for local inode %" PRIu64 "\n"),
1077 do_error(_("bad inode format for inode %" PRIu64 "\n"), ino_num);
1085 * higher level inode processing stuff starts here:
1086 * first, one utility routine for each type of inode
1090 * return 1 if inode should be cleared, 0 otherwise
1095 xfs_agnumber_t agno,
1106 xfs_bmdr_block_t *dib;
1107 xfs_dfiloff_t last_key;
1108 xfs_dfiloff_t first_key = 0;
1111 xfs_bmbt_key_t *pkey;
1116 bmap_cursor_t cursor;
1119 dib = (xfs_bmdr_block_t *)XFS_DFORK_PTR(dip, whichfork);
1120 lino = XFS_AGINO_TO_INO(mp, agno, ino);
1124 if (whichfork == XFS_DATA_FORK)
1125 forkname = _("data");
1127 forkname = _("attr");
1129 magic = xfs_sb_version_hascrc(&mp->m_sb) ? XFS_BMAP_CRC_MAGIC
1132 level = be16_to_cpu(dib->bb_level);
1133 numrecs = be16_to_cpu(dib->bb_numrecs);
1135 if ((level == 0) || (level > XFS_BM_MAXLEVELS(mp, whichfork))) {
1137 * XXX - if we were going to fix up the inode,
1138 * we'd try to treat the fork as an interior
1139 * node and see if we could get an accurate
1140 * level value from one of the blocks pointed
1141 * to by the pointers in the fork. For now
1142 * though, we just bail (and blow out the inode).
1145 _("bad level %d in inode %" PRIu64 " bmap btree root block\n"),
1146 level, XFS_AGINO_TO_INO(mp, agno, ino));
1151 _("bad numrecs 0 in inode %" PRIu64 " bmap btree root block\n"),
1152 XFS_AGINO_TO_INO(mp, agno, ino));
1156 * use bmdr/dfork_dsize since the root block is in the data fork
1158 if (XFS_BMDR_SPACE_CALC(numrecs) > XFS_DFORK_SIZE(dip, mp, whichfork)) {
1160 _("indicated size of %s btree root (%d bytes) greater than space in "
1161 "inode %" PRIu64 " %s fork\n"),
1162 forkname, XFS_BMDR_SPACE_CALC(numrecs), lino, forkname);
1166 init_bm_cursor(&cursor, level + 1);
1168 pp = XFS_BMDR_PTR_ADDR(dib, 1,
1169 xfs_bmdr_maxrecs(mp, XFS_DFORK_SIZE(dip, mp, whichfork), 0));
1170 pkey = XFS_BMDR_KEY_ADDR(dib, 1);
1171 last_key = NULLDFILOFF;
1173 for (i = 0; i < numrecs; i++) {
1175 * XXX - if we were going to do more to fix up the inode
1176 * btree, we'd do it right here. For now, if there's a
1177 * problem, we'll bail out and presumably clear the inode.
1179 if (!verify_dfsbno(mp, be64_to_cpu(pp[i]))) {
1180 do_warn(_("bad bmap btree ptr 0x%llx in ino %" PRIu64 "\n"),
1181 (unsigned long long) be64_to_cpu(pp[i]), lino);
1185 if (scan_lbtree(be64_to_cpu(pp[i]), level, scan_bmapbt, type,
1186 whichfork, lino, tot, nex, blkmapp, &cursor,
1187 1, check_dups, magic, &xfs_bmbt_buf_ops))
1190 * fix key (offset) mismatches between the keys in root
1191 * block records and the first key of each child block.
1192 * fixes cases where entries have been shifted between
1193 * blocks but the parent hasn't been updated
1195 if (!check_dups && cursor.level[level-1].first_key !=
1196 be64_to_cpu(pkey[i].br_startoff)) {
1199 _("correcting key in bmbt root (was %llu, now %" PRIu64") in inode "
1200 "%" PRIu64" %s fork\n"),
1201 (unsigned long long)
1202 be64_to_cpu(pkey[i].br_startoff),
1203 cursor.level[level-1].first_key,
1204 XFS_AGINO_TO_INO(mp, agno, ino),
1207 pkey[i].br_startoff = cpu_to_be64(
1208 cursor.level[level-1].first_key);
1211 _("bad key in bmbt root (is %llu, would reset to %" PRIu64 ") in inode "
1212 "%" PRIu64 " %s fork\n"),
1213 (unsigned long long)
1214 be64_to_cpu(pkey[i].br_startoff),
1215 cursor.level[level-1].first_key,
1216 XFS_AGINO_TO_INO(mp, agno, ino),
1221 * make sure that keys are in ascending order. blow out
1222 * inode if the ordering doesn't hold
1224 if (check_dups == 0) {
1225 if (last_key != NULLDFILOFF && last_key >=
1226 cursor.level[level-1].first_key) {
1228 _("out of order bmbt root key %" PRIu64 " in inode %" PRIu64 " %s fork\n"),
1230 XFS_AGINO_TO_INO(mp, agno, ino),
1234 last_key = cursor.level[level-1].first_key;
1238 * Ideally if all the extents are ok (perhaps after further
1239 * checks below?) we'd just move this back into extents format.
1240 * But for now clear it, as the kernel will choke on this
1242 if (*nex <= XFS_DFORK_SIZE(dip, mp, whichfork) /
1243 sizeof(xfs_bmbt_rec_t)) {
1245 _("extent count for ino %" PRIu64 " %s fork too low (%" PRIu64 ") for file format\n"),
1246 lino, forkname, *nex);
1250 * Check that the last child block's forward sibling pointer
1253 if (check_dups == 0 &&
1254 cursor.level[0].right_fsbno != NULLDFSBNO) {
1256 _("bad fwd (right) sibling pointer (saw %" PRIu64 " should be NULLDFSBNO)\n"),
1257 cursor.level[0].right_fsbno);
1259 _("\tin inode %" PRIu64 " (%s fork) bmap btree block %" PRIu64 "\n"),
1260 XFS_AGINO_TO_INO(mp, agno, ino), forkname,
1261 cursor.level[0].fsbno);
1269 * return 1 if inode should be cleared, 0 otherwise
1274 xfs_agnumber_t agno,
1287 xfs_dfiloff_t first_key;
1288 xfs_dfiloff_t last_key;
1292 lino = XFS_AGINO_TO_INO(mp, agno, ino);
1293 rp = (xfs_bmbt_rec_t *)XFS_DFORK_PTR(dip, whichfork);
1295 numrecs = XFS_DFORK_NEXTENTS(dip, whichfork);
1298 * We've already decided on the maximum number of extents on the inode,
1299 * and numrecs may be corrupt. Hence make sure we only allow numrecs to
1300 * be in the range of valid on-disk numbers, which is:
1301 * 0 < numrecs < 2^31 - 1
1307 * XXX - if we were going to fix up the btree record,
1308 * we'd do it right here. For now, if there's a problem,
1309 * we'll bail out and presumably clear the inode.
1311 if (check_dups == 0)
1312 ret = process_bmbt_reclist(mp, rp, &numrecs, type, lino,
1313 tot, blkmapp, &first_key, &last_key,
1316 ret = scan_bmbt_reclist(mp, rp, &numrecs, type, lino, tot,
1324 * return 1 if inode should be cleared, 0 otherwise
1329 xfs_agnumber_t agno,
1334 xfs_attr_shortform_t *asf;
1337 lino = XFS_AGINO_TO_INO(mp, agno, ino);
1338 if (whichfork == XFS_DATA_FORK && be64_to_cpu(dip->di_size) >
1339 XFS_DFORK_DSIZE(dip, mp)) {
1341 _("local inode %" PRIu64 " data fork is too large (size = %lld, max = %d)\n"),
1342 lino, (unsigned long long) be64_to_cpu(dip->di_size),
1343 XFS_DFORK_DSIZE(dip, mp));
1345 } else if (whichfork == XFS_ATTR_FORK) {
1346 asf = (xfs_attr_shortform_t *)XFS_DFORK_APTR(dip);
1347 if (be16_to_cpu(asf->hdr.totsize) > XFS_DFORK_ASIZE(dip, mp)) {
1349 _("local inode %" PRIu64 " attr fork too large (size %d, max = %d)\n"),
1350 lino, be16_to_cpu(asf->hdr.totsize),
1351 XFS_DFORK_ASIZE(dip, mp));
1354 if (be16_to_cpu(asf->hdr.totsize) < sizeof(xfs_attr_sf_hdr_t)) {
1356 _("local inode %" PRIu64 " attr too small (size = %d, min size = %zd)\n"),
1357 lino, be16_to_cpu(asf->hdr.totsize),
1358 sizeof(xfs_attr_sf_hdr_t));
1367 process_symlink_extlist(xfs_mount_t *mp, xfs_ino_t lino, xfs_dinode_t *dino)
1369 xfs_dfiloff_t expected_offset;
1371 xfs_bmbt_irec_t irec;
1376 if (be64_to_cpu(dino->di_size) <= XFS_DFORK_DSIZE(dino, mp)) {
1377 if (dino->di_format == XFS_DINODE_FMT_LOCAL)
1380 _("mismatch between format (%d) and size (%" PRId64 ") in symlink ino %" PRIu64 "\n"),
1382 (__int64_t)be64_to_cpu(dino->di_size), lino);
1385 if (dino->di_format == XFS_DINODE_FMT_LOCAL) {
1387 _("mismatch between format (%d) and size (%" PRId64 ") in symlink inode %" PRIu64 "\n"),
1389 (__int64_t)be64_to_cpu(dino->di_size), lino);
1393 rp = (xfs_bmbt_rec_t *)XFS_DFORK_DPTR(dino);
1394 numrecs = be32_to_cpu(dino->di_nextents);
1397 * the max # of extents in a symlink inode is equal to the
1398 * number of max # of blocks required to store the symlink
1400 if (numrecs > max_symlink_blocks) {
1402 _("bad number of extents (%d) in symlink %" PRIu64 " data fork\n"),
1407 max_blocks = max_symlink_blocks;
1408 expected_offset = 0;
1410 for (i = 0; i < numrecs; i++) {
1411 libxfs_bmbt_disk_get_all(rp + i, &irec);
1413 if (irec.br_startoff != expected_offset) {
1415 _("bad extent #%d offset (%" PRIu64 ") in symlink %" PRIu64 " data fork\n"),
1416 i, irec.br_startoff, lino);
1419 if (irec.br_blockcount == 0 || irec.br_blockcount > max_blocks) {
1421 _("bad extent #%d count (%" PRIu64 ") in symlink %" PRIu64 " data fork\n"),
1422 i, irec.br_blockcount, lino);
1426 max_blocks -= irec.br_blockcount;
1427 expected_offset += irec.br_blockcount;
1434 * takes a name and length and returns 1 if the name contains
1435 * a \0, returns 0 otherwise
1438 null_check(char *name, int length)
1442 ASSERT(length < MAXPATHLEN);
1444 for (i = 0; i < length; i++, name++) {
1453 process_symlink_remote(
1454 struct xfs_mount *mp,
1456 struct xfs_dinode *dino,
1457 struct blkmap *blkmap,
1468 pathlen = be64_to_cpu(dino->di_size);
1471 while (pathlen > 0) {
1475 fsbno = blkmap_get(blkmap, i);
1476 if (fsbno == NULLDFSBNO) {
1478 _("cannot read inode %" PRIu64 ", file block %d, NULL disk block\n"),
1484 * There's a symlink header for each contiguous extent. If
1485 * there are contiguous blocks, read them in one go.
1487 while (blk_cnt <= max_symlink_blocks) {
1488 if (blkmap_get(blkmap, i + 1) != fsbno + 1)
1494 byte_cnt = XFS_FSB_TO_B(mp, blk_cnt);
1496 bp = libxfs_readbuf(mp->m_dev, XFS_FSB_TO_DADDR(mp, fsbno),
1497 BTOBB(byte_cnt), 0, &xfs_symlink_buf_ops);
1500 _("cannot read inode %" PRIu64 ", file block %d, disk block %" PRIu64 "\n"),
1505 byte_cnt = XFS_SYMLINK_BUF_SPACE(mp, byte_cnt);
1506 byte_cnt = MIN(pathlen, byte_cnt);
1509 if (xfs_sb_version_hascrc(&mp->m_sb)) {
1510 if (!libxfs_symlink_hdr_ok(mp, lino, offset,
1513 _("bad symlink header ino %" PRIu64 ", file block %d, disk block %" PRIu64 "\n"),
1518 src += sizeof(struct xfs_dsymlink_hdr);
1521 memmove(dst + offset, src, byte_cnt);
1523 pathlen -= byte_cnt;
1533 * like usual, returns 0 if everything's ok and 1 if something's
1543 char *symlink, *cptr;
1544 char data[MAXPATHLEN];
1547 * check size against kernel symlink limits. we know
1548 * size is consistent with inode storage format -- e.g.
1549 * the inode is structurally ok so we don't have to check
1552 if (be64_to_cpu(dino->di_size) >= MAXPATHLEN) {
1553 do_warn(_("symlink in inode %" PRIu64 " too long (%llu chars)\n"),
1554 lino, (unsigned long long) be64_to_cpu(dino->di_size));
1559 * have to check symlink component by component.
1560 * get symlink contents into data area
1563 if (be64_to_cpu(dino->di_size) <= XFS_DFORK_DSIZE(dino, mp)) {
1565 * local symlink, just copy the symlink out of the
1566 * inode into the data area
1568 memmove(symlink, XFS_DFORK_DPTR(dino),
1569 be64_to_cpu(dino->di_size));
1573 error = process_symlink_remote(mp, lino, dino, blkmap, symlink);
1578 data[be64_to_cpu(dino->di_size)] = '\0';
1583 if (null_check(symlink, be64_to_cpu(dino->di_size))) {
1585 _("found illegal null character in symlink inode %" PRIu64 "\n"),
1591 * check for any component being too long
1593 if (be64_to_cpu(dino->di_size) >= MAXNAMELEN) {
1594 cptr = strchr(symlink, '/');
1596 while (cptr != NULL) {
1597 if (cptr - symlink >= MAXNAMELEN) {
1599 _("component of symlink in inode %" PRIu64 " too long\n"),
1604 cptr = strchr(symlink, '/');
1607 if (strlen(symlink) >= MAXNAMELEN) {
1609 _("component of symlink in inode %" PRIu64 " too long\n"),
1619 * called to process the set of misc inode special inode types
1620 * that have no associated data storage (fifos, pipes, devices, etc.).
1623 process_misc_ino_types(xfs_mount_t *mp,
1629 * disallow mountpoint inodes until such time as the
1630 * kernel actually allows them to be created (will
1631 * probably require a superblock version rev, sigh).
1633 if (type == XR_INO_MOUNTPOINT) {
1635 _("inode %" PRIu64 " has bad inode type (IFMNT)\n"), lino);
1640 * must also have a zero size
1642 if (be64_to_cpu(dino->di_size) != 0) {
1646 _("size of character device inode %" PRIu64 " != 0 (%" PRId64 " bytes)\n"), lino,
1647 (__int64_t)be64_to_cpu(dino->di_size));
1651 _("size of block device inode %" PRIu64 " != 0 (%" PRId64 " bytes)\n"), lino,
1652 (__int64_t)be64_to_cpu(dino->di_size));
1656 _("size of socket inode %" PRIu64 " != 0 (%" PRId64 " bytes)\n"), lino,
1657 (__int64_t)be64_to_cpu(dino->di_size));
1661 _("size of fifo inode %" PRIu64 " != 0 (%" PRId64 " bytes)\n"), lino,
1662 (__int64_t)be64_to_cpu(dino->di_size));
1665 do_warn(_("Internal error - process_misc_ino_types, "
1666 "illegal type %d\n"), type);
1677 process_misc_ino_types_blocks(xfs_drfsbno_t totblocks, xfs_ino_t lino, int type)
1680 * you can not enforce all misc types have zero data fork blocks
1681 * by checking dino->di_nblocks because atotblocks (attribute
1682 * blocks) are part of nblocks. We must check this later when atotblocks
1683 * has been calculated or by doing a simple check that anExtents == 0.
1684 * We must also guarantee that totblocks is 0. Thus nblocks checking
1685 * will be done later in process_dinode_int for misc types.
1688 if (totblocks != 0) {
1692 _("size of character device inode %" PRIu64 " != 0 (%" PRIu64 " blocks)\n"),
1697 _("size of block device inode %" PRIu64 " != 0 (%" PRIu64 " blocks)\n"),
1702 _("size of socket inode %" PRIu64 " != 0 (%" PRIu64 " blocks)\n"),
1707 _("size of fifo inode %" PRIu64 " != 0 (%" PRIu64 " blocks)\n"),
1722 return be16_to_cpu(dino->di_mode) & S_IFMT;
1730 int mode = be16_to_cpu(dino->di_mode);
1732 ASSERT((new_fmt & ~S_IFMT) == 0);
1736 dino->di_mode = cpu_to_be16(mode);
1740 check_dinode_mode_format(
1741 xfs_dinode_t *dinoc)
1743 if (dinoc->di_format >= XFS_DINODE_FMT_UUID)
1744 return -1; /* FMT_UUID is not used */
1746 switch (dinode_fmt(dinoc)) {
1751 return (dinoc->di_format != XFS_DINODE_FMT_DEV) ? -1 : 0;
1754 return (dinoc->di_format < XFS_DINODE_FMT_LOCAL ||
1755 dinoc->di_format > XFS_DINODE_FMT_BTREE) ? -1 : 0;
1758 return (dinoc->di_format < XFS_DINODE_FMT_EXTENTS ||
1759 dinoc->di_format > XFS_DINODE_FMT_BTREE) ? -1 : 0;
1762 return (dinoc->di_format < XFS_DINODE_FMT_LOCAL ||
1763 dinoc->di_format > XFS_DINODE_FMT_EXTENTS) ? -1 : 0;
1767 return 0; /* invalid modes are checked elsewhere */
1771 * If inode is a superblock inode, does type check to make sure is it valid.
1772 * Returns 0 if it's valid, non-zero if it needs to be cleared.
1776 process_check_sb_inodes(
1778 xfs_dinode_t *dinoc,
1783 if (lino == mp->m_sb.sb_rootino) {
1784 if (*type != XR_INO_DIR) {
1785 do_warn(_("root inode %" PRIu64 " has bad type 0x%x\n"),
1786 lino, dinode_fmt(dinoc));
1789 do_warn(_("resetting to directory\n"));
1790 change_dinode_fmt(dinoc, S_IFDIR);
1793 do_warn(_("would reset to directory\n"));
1797 if (lino == mp->m_sb.sb_uquotino) {
1798 if (*type != XR_INO_DATA) {
1799 do_warn(_("user quota inode %" PRIu64 " has bad type 0x%x\n"),
1800 lino, dinode_fmt(dinoc));
1801 mp->m_sb.sb_uquotino = NULLFSINO;
1806 if (lino == mp->m_sb.sb_gquotino) {
1807 if (*type != XR_INO_DATA) {
1808 do_warn(_("group quota inode %" PRIu64 " has bad type 0x%x\n"),
1809 lino, dinode_fmt(dinoc));
1810 mp->m_sb.sb_gquotino = NULLFSINO;
1815 if (lino == mp->m_sb.sb_rsumino) {
1816 if (*type != XR_INO_RTSUM) {
1818 _("realtime summary inode %" PRIu64 " has bad type 0x%x, "),
1819 lino, dinode_fmt(dinoc));
1821 do_warn(_("resetting to regular file\n"));
1822 change_dinode_fmt(dinoc, S_IFREG);
1825 do_warn(_("would reset to regular file\n"));
1828 if (mp->m_sb.sb_rblocks == 0 && dinoc->di_nextents != 0) {
1830 _("bad # of extents (%u) for realtime summary inode %" PRIu64 "\n"),
1831 be32_to_cpu(dinoc->di_nextents), lino);
1836 if (lino == mp->m_sb.sb_rbmino) {
1837 if (*type != XR_INO_RTBITMAP) {
1839 _("realtime bitmap inode %" PRIu64 " has bad type 0x%x, "),
1840 lino, dinode_fmt(dinoc));
1842 do_warn(_("resetting to regular file\n"));
1843 change_dinode_fmt(dinoc, S_IFREG);
1846 do_warn(_("would reset to regular file\n"));
1849 if (mp->m_sb.sb_rblocks == 0 && dinoc->di_nextents != 0) {
1851 _("bad # of extents (%u) for realtime bitmap inode %" PRIu64 "\n"),
1852 be32_to_cpu(dinoc->di_nextents), lino);
1861 * general size/consistency checks:
1863 * if the size <= size of the data fork, directories must be
1864 * local inodes unlike regular files which would be extent inodes.
1865 * all the other mentioned types have to have a zero size value.
1867 * if the size and format don't match, get out now rather than
1868 * risk trying to process a non-existent extents or btree
1872 process_check_inode_sizes(
1878 xfs_fsize_t size = be64_to_cpu(dino->di_size);
1883 if (size <= XFS_DFORK_DSIZE(dino, mp) &&
1884 dino->di_format != XFS_DINODE_FMT_LOCAL) {
1886 _("mismatch between format (%d) and size (%" PRId64 ") in directory ino %" PRIu64 "\n"),
1887 dino->di_format, size, lino);
1890 if (size > XFS_DIR2_LEAF_OFFSET) {
1892 _("directory inode %" PRIu64 " has bad size %" PRId64 "\n"),
1898 case XR_INO_SYMLINK:
1899 if (process_symlink_extlist(mp, lino, dino)) {
1900 do_warn(_("bad data fork in symlink %" PRIu64 "\n"), lino);
1905 case XR_INO_CHRDEV: /* fall through to FIFO case ... */
1906 case XR_INO_BLKDEV: /* fall through to FIFO case ... */
1907 case XR_INO_SOCK: /* fall through to FIFO case ... */
1908 case XR_INO_MOUNTPOINT: /* fall through to FIFO case ... */
1910 if (process_misc_ino_types(mp, dino, lino, type))
1916 * if we have no realtime blocks, any inode claiming
1917 * to be a real-time file is bogus
1919 if (mp->m_sb.sb_rblocks == 0) {
1921 _("found inode %" PRIu64 " claiming to be a real-time file\n"), lino);
1926 case XR_INO_RTBITMAP:
1927 if (size != (__int64_t)mp->m_sb.sb_rbmblocks *
1928 mp->m_sb.sb_blocksize) {
1930 _("realtime bitmap inode %" PRIu64 " has bad size %" PRId64 " (should be %" PRIu64 ")\n"),
1932 (__int64_t) mp->m_sb.sb_rbmblocks *
1933 mp->m_sb.sb_blocksize);
1939 if (size != mp->m_rsumsize) {
1941 _("realtime summary inode %" PRIu64 " has bad size %" PRId64 " (should be %d)\n"),
1942 lino, size, mp->m_rsumsize);
1954 * check for illegal values of forkoff
1957 process_check_inode_forkoff(
1962 if (dino->di_forkoff == 0)
1965 switch (dino->di_format) {
1966 case XFS_DINODE_FMT_DEV:
1967 if (dino->di_forkoff != (roundup(sizeof(xfs_dev_t), 8) >> 3)) {
1969 _("bad attr fork offset %d in dev inode %" PRIu64 ", should be %d\n"),
1970 dino->di_forkoff, lino,
1971 (int)(roundup(sizeof(xfs_dev_t), 8) >> 3));
1975 case XFS_DINODE_FMT_LOCAL: /* fall through ... */
1976 case XFS_DINODE_FMT_EXTENTS: /* fall through ... */
1977 case XFS_DINODE_FMT_BTREE:
1978 if (dino->di_forkoff >=
1979 (XFS_LITINO(mp, dino->di_version) >> 3)) {
1981 _("bad attr fork offset %d in inode %" PRIu64 ", max=%d\n"),
1982 dino->di_forkoff, lino,
1983 XFS_LITINO(mp, dino->di_version) >> 3);
1988 do_error(_("unexpected inode format %d\n"), dino->di_format);
1995 * Updates the inodes block and extent counts if they are wrong
1998 process_inode_blocks_and_extents(
2000 xfs_drfsbno_t nblocks,
2001 __uint64_t nextents,
2002 __uint64_t anextents,
2006 if (nblocks != be64_to_cpu(dino->di_nblocks)) {
2009 _("correcting nblocks for inode %" PRIu64 ", was %llu - counted %" PRIu64 "\n"), lino,
2010 (unsigned long long) be64_to_cpu(dino->di_nblocks),
2012 dino->di_nblocks = cpu_to_be64(nblocks);
2016 _("bad nblocks %llu for inode %" PRIu64 ", would reset to %" PRIu64 "\n"),
2017 (unsigned long long) be64_to_cpu(dino->di_nblocks),
2022 if (nextents > MAXEXTNUM) {
2024 _("too many data fork extents (%" PRIu64 ") in inode %" PRIu64 "\n"),
2028 if (nextents != be32_to_cpu(dino->di_nextents)) {
2031 _("correcting nextents for inode %" PRIu64 ", was %d - counted %" PRIu64 "\n"),
2033 be32_to_cpu(dino->di_nextents),
2035 dino->di_nextents = cpu_to_be32(nextents);
2039 _("bad nextents %d for inode %" PRIu64 ", would reset to %" PRIu64 "\n"),
2040 be32_to_cpu(dino->di_nextents),
2045 if (anextents > MAXAEXTNUM) {
2047 _("too many attr fork extents (%" PRIu64 ") in inode %" PRIu64 "\n"),
2051 if (anextents != be16_to_cpu(dino->di_anextents)) {
2054 _("correcting anextents for inode %" PRIu64 ", was %d - counted %" PRIu64 "\n"),
2056 be16_to_cpu(dino->di_anextents), anextents);
2057 dino->di_anextents = cpu_to_be16(anextents);
2061 _("bad anextents %d for inode %" PRIu64 ", would reset to %" PRIu64 "\n"),
2062 be16_to_cpu(dino->di_anextents),
2068 * We are comparing different units here, but that's fine given that
2069 * an extent has to have at least a block in it.
2071 if (nblocks < nextents + anextents) {
2073 _("nblocks (%" PRIu64 ") smaller than nextents for inode %" PRIu64 "\n"), nblocks, lino);
2081 * check data fork -- if it's bad, clear the inode
2084 process_inode_data_fork(
2086 xfs_agnumber_t agno,
2091 xfs_drfsbno_t *totblocks,
2092 __uint64_t *nextents,
2096 xfs_ino_t lino = XFS_AGINO_TO_INO(mp, agno, ino);
2101 * extent count on disk is only valid for positive values. The kernel
2102 * uses negative values in memory. hence if we see negative numbers
2105 nex = be32_to_cpu(dino->di_nextents);
2111 if (*nextents > be64_to_cpu(dino->di_nblocks))
2115 if (dino->di_format != XFS_DINODE_FMT_LOCAL && type != XR_INO_RTDATA)
2116 *dblkmap = blkmap_alloc(*nextents, XFS_DATA_FORK);
2119 switch (dino->di_format) {
2120 case XFS_DINODE_FMT_LOCAL:
2121 err = process_lclinode(mp, agno, ino, dino, XFS_DATA_FORK);
2124 case XFS_DINODE_FMT_EXTENTS:
2125 err = process_exinode(mp, agno, ino, dino, type, dirty,
2126 totblocks, nextents, dblkmap, XFS_DATA_FORK,
2129 case XFS_DINODE_FMT_BTREE:
2130 err = process_btinode(mp, agno, ino, dino, type, dirty,
2131 totblocks, nextents, dblkmap, XFS_DATA_FORK,
2134 case XFS_DINODE_FMT_DEV: /* fall through */
2138 do_error(_("unknown format %d, ino %" PRIu64 " (mode = %d)\n"),
2139 dino->di_format, lino, be16_to_cpu(dino->di_mode));
2143 do_warn(_("bad data fork in inode %" PRIu64 "\n"), lino);
2145 *dirty += clear_dinode(mp, dino, lino);
2153 * if check_dups was non-zero, we have to
2154 * re-process data fork to set bitmap since the
2155 * bitmap wasn't set the first time through
2157 switch (dino->di_format) {
2158 case XFS_DINODE_FMT_LOCAL:
2159 err = process_lclinode(mp, agno, ino, dino,
2162 case XFS_DINODE_FMT_EXTENTS:
2163 err = process_exinode(mp, agno, ino, dino, type,
2164 dirty, totblocks, nextents, dblkmap,
2167 case XFS_DINODE_FMT_BTREE:
2168 err = process_btinode(mp, agno, ino, dino, type,
2169 dirty, totblocks, nextents, dblkmap,
2172 case XFS_DINODE_FMT_DEV: /* fall through */
2176 do_error(_("unknown format %d, ino %" PRIu64 " (mode = %d)\n"),
2177 dino->di_format, lino,
2178 be16_to_cpu(dino->di_mode));
2181 if (no_modify && err != 0)
2190 * Process extended attribute fork in inode
2193 process_inode_attr_fork(
2195 xfs_agnumber_t agno,
2200 xfs_drfsbno_t *atotblocks,
2201 __uint64_t *anextents,
2203 int extra_attr_check,
2206 xfs_ino_t lino = XFS_AGINO_TO_INO(mp, agno, ino);
2207 blkmap_t *ablkmap = NULL;
2211 if (!XFS_DFORK_Q(dino)) {
2213 if (dino->di_aformat != XFS_DINODE_FMT_EXTENTS) {
2214 do_warn(_("bad attribute format %d in inode %" PRIu64 ", "),
2215 dino->di_aformat, lino);
2217 do_warn(_("resetting value\n"));
2218 dino->di_aformat = XFS_DINODE_FMT_EXTENTS;
2221 do_warn(_("would reset value\n"));
2226 *anextents = be16_to_cpu(dino->di_anextents);
2227 if (*anextents > be64_to_cpu(dino->di_nblocks))
2230 switch (dino->di_aformat) {
2231 case XFS_DINODE_FMT_LOCAL:
2234 err = process_lclinode(mp, agno, ino, dino, XFS_ATTR_FORK);
2236 case XFS_DINODE_FMT_EXTENTS:
2237 ablkmap = blkmap_alloc(*anextents, XFS_ATTR_FORK);
2239 err = process_exinode(mp, agno, ino, dino, type, dirty,
2240 atotblocks, anextents, &ablkmap,
2241 XFS_ATTR_FORK, check_dups);
2243 case XFS_DINODE_FMT_BTREE:
2244 ablkmap = blkmap_alloc(*anextents, XFS_ATTR_FORK);
2246 err = process_btinode(mp, agno, ino, dino, type, dirty,
2247 atotblocks, anextents, &ablkmap,
2248 XFS_ATTR_FORK, check_dups);
2251 do_warn(_("illegal attribute format %d, ino %" PRIu64 "\n"),
2252 dino->di_aformat, lino);
2259 * clear the attribute fork if necessary. we can't
2260 * clear the inode because we've already put the
2261 * inode space info into the blockmap.
2263 * XXX - put the inode onto the "move it" list and
2264 * log the the attribute scrubbing
2266 do_warn(_("bad attribute fork in inode %" PRIu64), lino);
2269 if (delete_attr_ok) {
2270 do_warn(_(", clearing attr fork\n"));
2271 *dirty += clear_dinode_attr(mp, dino, lino);
2272 dino->di_aformat = XFS_DINODE_FMT_LOCAL;
2275 *dirty += clear_dinode(mp, dino, lino);
2279 do_warn(_(", would clear attr fork\n"));
2284 blkmap_free(ablkmap);
2287 return delete_attr_ok ? 0 : 1;
2291 switch (dino->di_aformat) {
2292 case XFS_DINODE_FMT_LOCAL:
2293 err = process_lclinode(mp, agno, ino, dino,
2296 case XFS_DINODE_FMT_EXTENTS:
2297 err = process_exinode(mp, agno, ino, dino,
2298 type, dirty, atotblocks, anextents,
2299 &ablkmap, XFS_ATTR_FORK, 0);
2301 case XFS_DINODE_FMT_BTREE:
2302 err = process_btinode(mp, agno, ino, dino,
2303 type, dirty, atotblocks, anextents,
2304 &ablkmap, XFS_ATTR_FORK, 0);
2307 do_error(_("illegal attribute fmt %d, ino %" PRIu64 "\n"),
2308 dino->di_aformat, lino);
2311 if (no_modify && err != 0) {
2312 blkmap_free(ablkmap);
2320 * do attribute semantic-based consistency checks now
2323 /* get this only in phase 3, not in both phase 3 and 4 */
2324 if (extra_attr_check &&
2325 process_attributes(mp, lino, dino, ablkmap, &repair)) {
2327 _("problem with attribute contents in inode %" PRIu64 "\n"),
2330 /* clear attributes if not done already */
2332 *dirty += clear_dinode_attr(mp, dino, lino);
2333 dino->di_aformat = XFS_DINODE_FMT_LOCAL;
2335 do_warn(_("would clear attr fork\n"));
2341 *dirty = 1; /* it's been repaired */
2344 blkmap_free(ablkmap);
2349 * check nlinks feature, if it's a version 1 inode,
2350 * just leave nlinks alone. even if it's set wrong,
2351 * it'll be reset when read in.
2355 process_check_inode_nlink_version(
2361 if (dino->di_version > 1 && !fs_inode_nlink) {
2363 * do we have a fs/inode version mismatch with a valid
2364 * version 2 inode here that has to stay version 2 or
2367 if (be32_to_cpu(dino->di_nlink) > XFS_MAXLINK_1) {
2369 * yes. are nlink inodes allowed?
2371 if (fs_inode_nlink_allowed) {
2373 * yes, update status variable which will
2374 * cause sb to be updated later.
2378 (_("version 2 inode %" PRIu64 " claims > %u links, "),
2379 lino, XFS_MAXLINK_1);
2382 _("updating superblock version number\n"));
2385 _("would update superblock version number\n"));
2389 * no, have to convert back to onlinks
2390 * even if we lose some links
2393 _("WARNING: version 2 inode %" PRIu64 " claims > %u links, "),
2394 lino, XFS_MAXLINK_1);
2396 do_warn(_("converting back to version 1,\n"
2397 "this may destroy %d links\n"),
2398 be32_to_cpu(dino->di_nlink) -
2401 dino->di_version = 1;
2402 dino->di_nlink = cpu_to_be32(XFS_MAXLINK_1);
2403 dino->di_onlink = cpu_to_be16(XFS_MAXLINK_1);
2406 do_warn(_("would convert back to version 1,\n"
2407 "\tthis might destroy %d links\n"),
2408 be32_to_cpu(dino->di_nlink) -
2414 * do we have a v2 inode that we could convert back
2415 * to v1 without losing any links? if we do and
2416 * we have a mismatch between superblock bits and the
2417 * version bit, alter the version bit in this case.
2419 * the case where we lost links was handled above.
2421 do_warn(_("found version 2 inode %" PRIu64 ", "), lino);
2423 do_warn(_("converting back to version 1\n"));
2424 dino->di_version = 1;
2425 dino->di_onlink = cpu_to_be16(
2426 be32_to_cpu(dino->di_nlink));
2429 do_warn(_("would convert back to version 1\n"));
2435 * ok, if it's still a version 2 inode, it's going
2436 * to stay a version 2 inode. it should have a zero
2437 * onlink field, so clear it.
2439 if (dino->di_version > 1 &&
2440 dino->di_onlink != 0 && fs_inode_nlink > 0) {
2443 _("clearing obsolete nlink field in version 2 inode %" PRIu64 ", was %d, now 0\n"),
2444 lino, be16_to_cpu(dino->di_onlink));
2445 dino->di_onlink = 0;
2449 _("would clear obsolete nlink field in version 2 inode %" PRIu64 ", currently %d\n"),
2450 lino, be16_to_cpu(dino->di_onlink));
2457 * returns 0 if the inode is ok, 1 if the inode is corrupt
2458 * check_dups can be set to 1 *only* when called by the
2459 * first pass of the duplicate block checking of phase 4.
2460 * *dirty is set > 0 if the dinode has been altered and
2461 * needs to be written out.
2463 * for detailed, info, look at process_dinode() comments.
2466 process_dinode_int(xfs_mount_t *mp,
2468 xfs_agnumber_t agno,
2470 int was_free, /* 1 if inode is currently free */
2471 int *dirty, /* out == > 0 if inode is now dirty */
2472 int *used, /* out == 1 if inode is in use */
2473 int verify_mode, /* 1 == verify but don't modify inode */
2474 int uncertain, /* 1 == inode is uncertain */
2475 int ino_discovery, /* 1 == check dirs for unknown inodes */
2476 int check_dups, /* 1 == check if inode claims
2477 * duplicate blocks */
2478 int extra_attr_check, /* 1 == do attribute format and value checks */
2479 int *isa_dir, /* out == 1 if inode is a directory */
2480 xfs_ino_t *parent) /* out -- parent if ino is a dir */
2482 xfs_drfsbno_t totblocks = 0;
2483 xfs_drfsbno_t atotblocks = 0;
2487 __uint64_t nextents;
2488 __uint64_t anextents;
2490 const int is_free = 0;
2491 const int is_used = 1;
2492 blkmap_t *dblkmap = NULL;
2494 *dirty = *isa_dir = 0;
2496 type = XR_INO_UNKNOWN;
2498 lino = XFS_AGINO_TO_INO(mp, agno, ino);
2499 di_mode = be16_to_cpu(dino->di_mode);
2502 * if in verify mode, don't modify the inode.
2504 * if correcting, reset stuff that has known values
2506 * if in uncertain mode, be silent on errors since we're
2507 * trying to find out if these are inodes as opposed
2508 * to assuming that they are. Just return the appropriate
2509 * return code in that case.
2511 * If uncertain is set, verify_mode MUST be set.
2513 ASSERT(uncertain == 0 || verify_mode != 0);
2515 if (be16_to_cpu(dino->di_magic) != XFS_DINODE_MAGIC) {
2518 do_warn(_("bad magic number 0x%x on inode %" PRIu64 "%c"),
2519 be16_to_cpu(dino->di_magic), lino,
2520 verify_mode ? '\n' : ',');
2523 do_warn(_(" resetting magic number\n"));
2524 dino->di_magic = cpu_to_be16(XFS_DINODE_MAGIC);
2527 do_warn(_(" would reset magic number\n"));
2531 if (!XFS_DINODE_GOOD_VERSION(dino->di_version) ||
2532 (!fs_inode_nlink && dino->di_version > 1) ||
2533 (xfs_sb_version_hascrc(&mp->m_sb) && dino->di_version < 3) ) {
2536 do_warn(_("bad version number 0x%x on inode %" PRIu64 "%c"),
2537 (__s8)dino->di_version, lino,
2538 verify_mode ? '\n' : ',');
2541 do_warn(_(" resetting version number\n"));
2543 xfs_sb_version_hascrc(&mp->m_sb) ? 3 :
2544 (fs_inode_nlink) ? 2 : 1;
2547 do_warn(_(" would reset version number\n"));
2552 * We don't bother checking the CRC here - we cannot guarantee that when
2553 * we are called here that the inode has not already been modified in
2554 * memory and hence invalidated the CRC.
2556 if (xfs_sb_version_hascrc(&mp->m_sb)) {
2557 if (be64_to_cpu(dino->di_ino) != lino) {
2560 _("inode identifier %llu mismatch on inode %" PRIu64 "\n"),
2561 be64_to_cpu(dino->di_ino), lino);
2566 if (platform_uuid_compare(&dino->di_uuid, &mp->m_sb.sb_uuid)) {
2569 _("UUID mismatch on inode %" PRIu64 "\n"), lino);
2577 * blow out of here if the inode size is < 0
2579 if ((xfs_fsize_t)be64_to_cpu(dino->di_size) < 0) {
2582 _("bad (negative) size %" PRId64 " on inode %" PRIu64 "\n"),
2583 (__int64_t)be64_to_cpu(dino->di_size),
2591 * if not in verify mode, check to sii if the inode and imap
2592 * agree that the inode is free
2594 if (!verify_mode && di_mode == 0) {
2596 * was_free value is not meaningful if we're in verify mode
2600 * easy case, inode free -- inode and map agree, clear
2601 * it just in case to ensure that format, etc. are
2605 *dirty += clear_dinode(mp, dino, lino);
2610 * the inode looks free but the map says it's in use.
2611 * clear the inode just to be safe and mark the inode
2615 _("imap claims a free inode %" PRIu64 " is in use, "), lino);
2617 do_warn(_("correcting imap and clearing inode\n"));
2618 *dirty += clear_dinode(mp, dino, lino);
2621 do_warn(_("would correct imap and clear inode\n"));
2627 * because of the lack of any write ordering guarantee, it's
2628 * possible that the core got updated but the forks didn't.
2629 * so rather than be ambitious (and probably incorrect),
2630 * if there's an inconsistency, we get conservative and
2631 * just pitch the file. blow off checking formats of
2632 * free inodes since technically any format is legal
2633 * as we reset the inode when we re-use it.
2635 if (di_mode != 0 && check_dinode_mode_format(dino) != 0) {
2638 _("bad inode format in inode %" PRIu64 "\n"), lino);
2645 * check that we only have valid flags set, and those that are set make
2648 if (dino->di_flags) {
2649 uint16_t flags = be16_to_cpu(dino->di_flags);
2651 if (flags & ~XFS_DIFLAG_ANY) {
2654 _("Bad flags set in inode %" PRIu64 "\n"),
2657 flags &= ~XFS_DIFLAG_ANY;
2660 if (flags & (XFS_DIFLAG_REALTIME | XFS_DIFLAG_RTINHERIT)) {
2661 /* need an rt-dev! */
2665 _("inode %" PRIu64 " has RT flag set but there is no RT device\n"),
2668 flags &= ~(XFS_DIFLAG_REALTIME |
2669 XFS_DIFLAG_RTINHERIT);
2672 if (flags & XFS_DIFLAG_NEWRTBM) {
2673 /* must be a rt bitmap inode */
2674 if (lino != mp->m_sb.sb_rbmino) {
2677 _("inode %" PRIu64 " not rt bitmap\n"),
2680 flags &= ~XFS_DIFLAG_NEWRTBM;
2683 if (flags & (XFS_DIFLAG_RTINHERIT |
2684 XFS_DIFLAG_EXTSZINHERIT |
2685 XFS_DIFLAG_PROJINHERIT |
2686 XFS_DIFLAG_NOSYMLINKS)) {
2687 /* must be a directory */
2688 if (di_mode && !S_ISDIR(di_mode)) {
2691 _("directory flags set on non-directory inode %" PRIu64 "\n" ),
2694 flags &= ~(XFS_DIFLAG_RTINHERIT |
2695 XFS_DIFLAG_EXTSZINHERIT |
2696 XFS_DIFLAG_PROJINHERIT |
2697 XFS_DIFLAG_NOSYMLINKS);
2700 if (flags & (XFS_DIFLAG_REALTIME | XFS_XFLAG_EXTSIZE)) {
2701 /* must be a file */
2702 if (di_mode && !S_ISREG(di_mode)) {
2705 _("file flags set on non-file inode %" PRIu64 "\n"),
2708 flags &= ~(XFS_DIFLAG_REALTIME |
2712 if (!verify_mode && flags != be16_to_cpu(dino->di_flags)) {
2714 do_warn(_(", fixing bad flags.\n"));
2715 dino->di_flags = cpu_to_be16(flags);
2718 do_warn(_(", would fix bad flags.\n"));
2726 * clear the next unlinked field if necessary on a good
2727 * inode only during phase 4 -- when checking for inodes
2728 * referencing duplicate blocks. then it's safe because
2729 * we've done the inode discovery and have found all the inodes
2730 * we're going to find. check_dups is set to 1 only during
2733 if (check_dups && !no_modify)
2734 *dirty += clear_dinode_unlinked(mp, dino);
2736 /* set type and map type info */
2738 switch (di_mode & S_IFMT) {
2744 if (be16_to_cpu(dino->di_flags) & XFS_DIFLAG_REALTIME)
2745 type = XR_INO_RTDATA;
2746 else if (lino == mp->m_sb.sb_rbmino)
2747 type = XR_INO_RTBITMAP;
2748 else if (lino == mp->m_sb.sb_rsumino)
2749 type = XR_INO_RTSUM;
2754 type = XR_INO_SYMLINK;
2757 type = XR_INO_CHRDEV;
2760 type = XR_INO_BLKDEV;
2769 do_warn(_("bad inode type %#o inode %" PRIu64 "\n"),
2770 di_mode & S_IFMT, lino);
2775 * type checks for superblock inodes
2777 if (process_check_sb_inodes(mp, dino, lino, &type, dirty) != 0)
2781 * only regular files with REALTIME or EXTSIZE flags set can have
2782 * extsize set, or directories with EXTSZINHERIT.
2784 if (be32_to_cpu(dino->di_extsize) != 0) {
2785 if ((type == XR_INO_RTDATA) ||
2786 (type == XR_INO_DIR && (be16_to_cpu(dino->di_flags) &
2787 XFS_DIFLAG_EXTSZINHERIT)) ||
2788 (type == XR_INO_DATA && (be16_to_cpu(dino->di_flags) &
2789 XFS_DIFLAG_EXTSIZE))) {
2793 _("bad non-zero extent size %u for non-realtime/extsize inode %" PRIu64 ", "),
2794 be32_to_cpu(dino->di_extsize), lino);
2796 do_warn(_("resetting to zero\n"));
2797 dino->di_extsize = 0;
2800 do_warn(_("would reset to zero\n"));
2805 * general size/consistency checks:
2807 if (process_check_inode_sizes(mp, dino, lino, type) != 0)
2811 * check for illegal values of forkoff
2813 if (process_check_inode_forkoff(mp, dino, lino) != 0)
2817 * check data fork -- if it's bad, clear the inode
2819 if (process_inode_data_fork(mp, agno, ino, dino, type, dirty,
2820 &totblocks, &nextents, &dblkmap, check_dups) != 0)
2824 * check attribute fork if necessary. attributes are
2825 * always stored in the regular filesystem.
2827 if (process_inode_attr_fork(mp, agno, ino, dino, type, dirty,
2828 &atotblocks, &anextents, check_dups, extra_attr_check,
2833 * enforce totblocks is 0 for misc types
2835 if (process_misc_ino_types_blocks(totblocks, lino, type))
2839 * correct space counters if required
2841 if (process_inode_blocks_and_extents(dino, totblocks + atotblocks,
2842 nextents, anextents, lino, dirty) != 0)
2846 * do any semantic type-based checking here
2850 if (process_dir2(mp, lino, dino, ino_discovery,
2851 dirty, "", parent, dblkmap)) {
2853 _("problem with directory contents in inode %" PRIu64 "\n"),
2858 case XR_INO_SYMLINK:
2859 if (process_symlink(mp, lino, dino, dblkmap) != 0) {
2861 _("problem with symbolic link in inode %" PRIu64 "\n"),
2870 blkmap_free(dblkmap);
2873 * check nlinks feature, if it's a version 1 inode,
2874 * just leave nlinks alone. even if it's set wrong,
2875 * it'll be reset when read in.
2877 *dirty += process_check_inode_nlink_version(dino, lino);
2883 *dirty += clear_dinode(mp, dino, lino);
2889 blkmap_free(dblkmap);
2894 * returns 1 if inode is used, 0 if free.
2895 * performs any necessary salvaging actions.
2896 * note that we leave the generation count alone
2897 * because nothing we could set it to would be
2898 * guaranteed to be correct so the best guess for
2899 * the correct value is just to leave it alone.
2901 * The trick is detecting empty files. For those,
2902 * the core and the forks should all be in the "empty"
2903 * or zero-length state -- a zero or possibly minimum length
2904 * (in the case of dirs) extent list -- although inline directories
2905 * and symlinks might be handled differently. So it should be
2906 * possible to sanity check them against each other.
2908 * If the forks are an empty extent list though, then forget it.
2909 * The file is toast anyway since we can't recover its storage.
2913 * mp -- mount structure
2914 * dino -- pointer to on-disk inode structure
2915 * agno/ino -- inode numbers
2916 * free -- whether the map thinks the inode is free (1 == free)
2917 * ino_discovery -- whether we should examine directory
2918 * contents to discover new inodes
2919 * check_dups -- whether we should check to see if the
2920 * inode references duplicate blocks
2921 * if so, we compare the inode's claimed
2922 * blocks against the contents of the
2923 * duplicate extent list but we don't
2924 * set the bitmap. If not, we set the
2925 * bitmap and try and detect multiply
2926 * claimed blocks using the bitmap.
2928 * dirty -- whether we changed the inode (1 == yes)
2929 * used -- 1 if the inode is used, 0 if free. In no modify
2930 * mode, whether the inode should be used or free
2931 * isa_dir -- 1 if the inode is a directory, 0 if not. In
2932 * no modify mode, if the inode would be a dir or not.
2934 * Return value -- 0 if the inode is good, 1 if it is/was corrupt
2941 xfs_agnumber_t agno,
2948 int extra_attr_check,
2952 const int verify_mode = 0;
2953 const int uncertain = 0;
2955 #ifdef XR_INODE_TRACE
2956 fprintf(stderr, _("processing inode %d/%d\n"), agno, ino);
2958 return process_dinode_int(mp, dino, agno, ino, was_free, dirty, used,
2959 verify_mode, uncertain, ino_discovery,
2960 check_dups, extra_attr_check, isa_dir, parent);
2964 * a more cursory check, check inode core, *DON'T* check forks
2965 * this basically just verifies whether the inode is an inode
2966 * and whether or not it has been totally trashed. returns 0
2967 * if the inode passes the cursory sanity check, 1 otherwise.
2973 xfs_agnumber_t agno,
2980 const int verify_mode = 1;
2981 const int check_dups = 0;
2982 const int ino_discovery = 0;
2983 const int uncertain = 0;
2985 return process_dinode_int(mp, dino, agno, ino, 0, &dirty, &used,
2986 verify_mode, uncertain, ino_discovery,
2987 check_dups, 0, &isa_dir, &parent);
2991 * like above only for inode on the uncertain list. it sets
2992 * the uncertain flag which makes process_dinode_int quieter.
2993 * returns 0 if the inode passes the cursory sanity check, 1 otherwise.
2996 verify_uncertain_dinode(
2999 xfs_agnumber_t agno,
3006 const int verify_mode = 1;
3007 const int check_dups = 0;
3008 const int ino_discovery = 0;
3009 const int uncertain = 1;
3011 return process_dinode_int(mp, dino, agno, ino, 0, &dirty, &used,
3012 verify_mode, uncertain, ino_discovery,
3013 check_dups, 0, &isa_dir, &parent);