~ubuntu-branches/ubuntu/utopic/xfsprogs/utopic-proposed

« back to all changes in this revision

Viewing changes to repair/dir2.c

  • Committer: Bazaar Package Importer
  • Author(s): Nathan Scott
  • Date: 2009-05-06 11:29:18 UTC
  • mfrom: (8.1.1 jaunty)
  • Revision ID: james.westby@ubuntu.com-20090506112918-uzoyzcp90rtr8td7
Tags: 3.0.2
New bugfix release

Show diffs side-by-side

added added

removed removed

Lines of Context:
249
249
        da_buf_done(dabuf);
250
250
        for (i = 0; i < nbuf; i++) {
251
251
#ifdef XR_PF_TRACE
252
 
                pftrace("putbuf %p (%llu)", bplist[i], (long long)XFS_BUF_ADDR(bplist[i]));
 
252
                pftrace("putbuf %p (%llu)", bplist[i],
 
253
                                        (long long)XFS_BUF_ADDR(bplist[i]));
253
254
#endif
254
255
                libxfs_putbuf(bplist[i]);
255
256
        }
309
310
 
310
311
                info = bp->data;
311
312
 
312
 
                if (INT_GET(info->magic, ARCH_CONVERT) ==
313
 
                                        XFS_DIR2_LEAFN_MAGIC)  {
 
313
                if (be16_to_cpu(info->magic) == XFS_DIR2_LEAFN_MAGIC)  {
314
314
                        if ( i != -1 ) {
315
315
                                do_warn(_("found non-root LEAFN node in inode "
316
316
                                          "%llu bno = %u\n"),
319
319
                        *rbno = 0;
320
320
                        da_brelse(bp);
321
321
                        return(1);
322
 
                } else if (INT_GET(info->magic, ARCH_CONVERT) !=
323
 
                                        XFS_DA_NODE_MAGIC)  {
 
322
                } else if (be16_to_cpu(info->magic) != XFS_DA_NODE_MAGIC)  {
324
323
                        da_brelse(bp);
325
324
                        do_warn(_("bad dir magic number 0x%x in inode %llu "
326
325
                                  "bno = %u\n"),
327
 
                                INT_GET(info->magic, ARCH_CONVERT),
 
326
                                be16_to_cpu(info->magic),
328
327
                                        da_cursor->ino, bno);
329
328
                        goto error_out;
330
329
                }
331
330
                node = (xfs_da_intnode_t*)info;
332
 
                if (INT_GET(node->hdr.count, ARCH_CONVERT) >
333
 
                                                mp->m_dir_node_ents)  {
 
331
                if (be16_to_cpu(node->hdr.count) > mp->m_dir_node_ents)  {
334
332
                        da_brelse(bp);
335
333
                        do_warn(_("bad record count in inode %llu, count = %d, "
336
334
                                  "max = %d\n"), da_cursor->ino,
337
 
                                INT_GET(node->hdr.count, ARCH_CONVERT),
 
335
                                be16_to_cpu(node->hdr.count),
338
336
                                mp->m_dir_node_ents);
339
337
                        goto error_out;
340
338
                }
342
340
                 * maintain level counter
343
341
                 */
344
342
                if (i == -1)
345
 
                        i = da_cursor->active =
346
 
                                INT_GET(node->hdr.level, ARCH_CONVERT);
 
343
                        i = da_cursor->active = be16_to_cpu(node->hdr.level);
347
344
                else  {
348
 
                        if (INT_GET(node->hdr.level, ARCH_CONVERT) == i - 1)  {
 
345
                        if (be16_to_cpu(node->hdr.level) == i - 1)  {
349
346
                                i--;
350
347
                        } else  {
351
348
                                do_warn(_("bad directory btree for directory "
357
354
                }
358
355
 
359
356
                da_cursor->level[i].hashval =
360
 
                        INT_GET(node->btree[0].hashval, ARCH_CONVERT);
 
357
                                        be32_to_cpu(node->btree[0].hashval);
361
358
                da_cursor->level[i].bp = bp;
362
359
                da_cursor->level[i].bno = bno;
363
360
                da_cursor->level[i].index = 0;
365
362
                /*
366
363
                 * set up new bno for next level down
367
364
                 */
368
 
                bno = INT_GET(node->btree[0].before, ARCH_CONVERT);
 
365
                bno = be32_to_cpu(node->btree[0].before);
369
366
        } while (info != NULL && i > 1);
370
367
 
371
368
        /*
460
457
         * that all entries are used, encountered and expected hashvals
461
458
         * match, etc.
462
459
         */
463
 
        if (entry != INT_GET(node->hdr.count, ARCH_CONVERT) - 1)  {
 
460
        if (entry != be16_to_cpu(node->hdr.count) - 1)  {
464
461
                do_warn(
465
462
                _("directory block used/count inconsistency - %d / %hu\n"),
466
 
                        entry, INT_GET(node->hdr.count, ARCH_CONVERT));
 
463
                        entry, be16_to_cpu(node->hdr.count));
467
464
                bad++;
468
465
        }
469
466
        /*
470
467
         * hash values monotonically increasing ???
471
468
         */
472
469
        if (cursor->level[this_level].hashval >=
473
 
            INT_GET(node->btree[entry].hashval, ARCH_CONVERT))  {
 
470
                                be32_to_cpu(node->btree[entry].hashval))  {
474
471
                do_warn(_("directory/attribute block hashvalue inconsistency, "
475
472
                          "expected > %u / saw %u\n"),
476
473
                        cursor->level[this_level].hashval,
477
 
                        INT_GET(node->btree[entry].hashval, ARCH_CONVERT));
 
474
                        be32_to_cpu(node->btree[entry].hashval));
478
475
                bad++;
479
476
        }
480
 
        if (INT_GET(node->hdr.info.forw, ARCH_CONVERT) != 0)  {
 
477
        if (be32_to_cpu(node->hdr.info.forw) != 0)  {
481
478
                do_warn(_("bad directory/attribute forward block pointer, "
482
479
                          "expected 0, saw %u\n"),
483
 
                        INT_GET(node->hdr.info.forw, ARCH_CONVERT));
 
480
                        be32_to_cpu(node->hdr.info.forw));
484
481
                bad++;
485
482
        }
486
483
        if (bad)  {
498
495
         * ok, now check descendant block number against this level
499
496
         */
500
497
        if (cursor->level[p_level].bno !=
501
 
            INT_GET(node->btree[entry].before, ARCH_CONVERT))  {
 
498
                                be32_to_cpu(node->btree[entry].before))
502
499
                return(1);
503
 
        }
504
500
 
505
501
        if (cursor->level[p_level].hashval !=
506
 
            INT_GET(node->btree[entry].hashval, ARCH_CONVERT))  {
 
502
                                be32_to_cpu(node->btree[entry].hashval))  {
507
503
                if (!no_modify)  {
508
504
                        do_warn(_("correcting bad hashval in non-leaf dir "
509
505
                                  "block\n\tin (level %d) in inode %llu.\n"),
510
506
                                this_level, cursor->ino);
511
 
                        INT_SET(node->btree[entry].hashval, ARCH_CONVERT,
512
 
                                cursor->level[p_level].hashval);
 
507
                        node->btree[entry].hashval = cpu_to_be32(
 
508
                                                cursor->level[p_level].hashval);
513
509
                        cursor->level[this_level].dirty++;
514
510
                } else  {
515
511
                        do_warn(_("would correct bad hashval in non-leaf dir "
534
530
        /*
535
531
         * bail out if this is the root block (top of tree)
536
532
         */
537
 
        if (this_level >= cursor->active)  {
 
533
        if (this_level >= cursor->active)  
538
534
                return(0);
539
 
        }
540
535
        /*
541
536
         * set hashvalue to correctl reflect the now-validated
542
537
         * last entry in this block and continue upwards validation
543
538
         */
544
539
        cursor->level[this_level].hashval =
545
 
                INT_GET(node->btree[entry].hashval, ARCH_CONVERT);
 
540
                be32_to_cpu(node->btree[entry].hashval);
546
541
 
547
542
        return(verify_final_dir2_path(mp, cursor, this_level));
548
543
}
614
609
         * block and move on to the next block.
615
610
         * and update cursor value for said level
616
611
         */
617
 
        if (entry >= INT_GET(node->hdr.count, ARCH_CONVERT))  {
 
612
        if (entry >= be16_to_cpu(node->hdr.count))  {
618
613
                /*
619
614
                 * update the hash value for this level before
620
615
                 * validating it.  bno value should be ok since
621
616
                 * it was set when the block was first read in.
622
617
                 */
623
618
                cursor->level[this_level].hashval =
624
 
                        INT_GET(node->btree[entry - 1].hashval, ARCH_CONVERT);
 
619
                        be32_to_cpu(node->btree[entry - 1].hashval);
625
620
 
626
621
                /*
627
622
                 * keep track of greatest block # -- that gets
639
634
                /*
640
635
                 * ok, now get the next buffer and check sibling pointers
641
636
                 */
642
 
                dabno = INT_GET(node->hdr.info.forw, ARCH_CONVERT);
 
637
                dabno = be32_to_cpu(node->hdr.info.forw);
643
638
                ASSERT(dabno != 0);
644
639
                nex = blkmap_getn(cursor->blkmap, dabno, mp->m_dirblkfsbs,
645
640
                        &bmp, &lbmp);
667
662
                 * entry count, verify level
668
663
                 */
669
664
                bad = 0;
670
 
                if (XFS_DA_NODE_MAGIC !=
671
 
                    INT_GET(newnode->hdr.info.magic, ARCH_CONVERT))  {
 
665
                if (XFS_DA_NODE_MAGIC != be16_to_cpu(newnode->hdr.info.magic)) {
672
666
                        do_warn(_("bad magic number %x in block %u for "
673
667
                                  "directory inode %llu\n"),
674
 
                                INT_GET(newnode->hdr.info.magic, ARCH_CONVERT),
 
668
                                be16_to_cpu(newnode->hdr.info.magic),
675
669
                                dabno, cursor->ino);
676
670
                        bad++;
677
671
                }
678
 
                if (INT_GET(newnode->hdr.info.back, ARCH_CONVERT) !=
679
 
                    cursor->level[this_level].bno)  {
 
672
                if (be32_to_cpu(newnode->hdr.info.back) !=
 
673
                                        cursor->level[this_level].bno)  {
680
674
                        do_warn(_("bad back pointer in block %u for directory "
681
675
                                  "inode %llu\n"),
682
676
                                dabno, cursor->ino);
683
677
                        bad++;
684
678
                }
685
 
                if (INT_GET(newnode->hdr.count, ARCH_CONVERT) >
686
 
                                                mp->m_dir_node_ents)  {
 
679
                if (be16_to_cpu(newnode->hdr.count) > mp->m_dir_node_ents)  {
687
680
                        do_warn(_("entry count %d too large in block %u for "
688
681
                                  "directory inode %llu\n"),
689
 
                                INT_GET(newnode->hdr.count, ARCH_CONVERT),
 
682
                                be16_to_cpu(newnode->hdr.count),
690
683
                                dabno, cursor->ino);
691
684
                        bad++;
692
685
                }
693
 
                if (INT_GET(newnode->hdr.level, ARCH_CONVERT) != this_level)  {
 
686
                if (be16_to_cpu(newnode->hdr.level) != this_level)  {
694
687
                        do_warn(_("bad level %d in block %u for directory "
695
688
                                  "inode %llu\n"),
696
 
                                INT_GET(newnode->hdr.level, ARCH_CONVERT),
 
689
                                be16_to_cpu(newnode->hdr.level),
697
690
                                dabno, cursor->ino);
698
691
                        bad++;
699
692
                }
716
709
                cursor->level[this_level].dirty = 0;
717
710
                cursor->level[this_level].bno = dabno;
718
711
                cursor->level[this_level].hashval =
719
 
                        INT_GET(newnode->btree[0].hashval, ARCH_CONVERT);
 
712
                        be32_to_cpu(newnode->btree[0].hashval);
720
713
                node = newnode;
721
714
 
722
715
                entry = cursor->level[this_level].index = 0;
725
718
         * ditto for block numbers
726
719
         */
727
720
        if (cursor->level[p_level].bno !=
728
 
            INT_GET(node->btree[entry].before, ARCH_CONVERT))  {
 
721
                                be32_to_cpu(node->btree[entry].before))
729
722
                return(1);
730
 
        }
731
723
        /*
732
724
         * ok, now validate last hashvalue in the descendant
733
725
         * block against the hashval in the current entry
734
726
         */
735
727
        if (cursor->level[p_level].hashval !=
736
 
            INT_GET(node->btree[entry].hashval, ARCH_CONVERT))  {
 
728
                                be32_to_cpu(node->btree[entry].hashval))  {
737
729
                if (!no_modify)  {
738
730
                        do_warn(_("correcting bad hashval in interior dir "
739
731
                                  "block\n\tin (level %d) in inode %llu.\n"),
740
732
                                this_level, cursor->ino);
741
 
                        INT_SET(node->btree[entry].hashval, ARCH_CONVERT,
742
 
                                cursor->level[p_level].hashval);
 
733
                        node->btree[entry].hashval = cpu_to_be32(
 
734
                                        cursor->level[p_level].hashval);
743
735
                        cursor->level[this_level].dirty++;
744
736
                } else  {
745
737
                        do_warn(_("would correct bad hashval in interior dir "
780
772
                exit(1);
781
773
        }
782
774
        memmove(oldsfp, newsfp, oldsize);
783
 
        INT_SET(newsfp->hdr.count, ARCH_CONVERT,
784
 
                        INT_GET(oldsfp->hdr.count, ARCH_CONVERT));
 
775
        newsfp->hdr.count = oldsfp->hdr.count;
785
776
        newsfp->hdr.i8count = 0;
786
 
        ino = XFS_DIR2_SF_GET_INUMBER(oldsfp, &oldsfp->hdr.parent);
787
 
        XFS_DIR2_SF_PUT_INUMBER(newsfp, &ino, &newsfp->hdr.parent);
788
 
        oldsfep = XFS_DIR2_SF_FIRSTENTRY(oldsfp);
789
 
        newsfep = XFS_DIR2_SF_FIRSTENTRY(newsfp);
 
777
        ino = xfs_dir2_sf_get_inumber(oldsfp, &oldsfp->hdr.parent);
 
778
        xfs_dir2_sf_put_inumber(newsfp, &ino, &newsfp->hdr.parent);
 
779
        oldsfep = xfs_dir2_sf_firstentry(oldsfp);
 
780
        newsfep = xfs_dir2_sf_firstentry(newsfp);
790
781
        while ((int)((char *)oldsfep - (char *)oldsfp) < oldsize) {
791
782
                newsfep->namelen = oldsfep->namelen;
792
 
                XFS_DIR2_SF_PUT_OFFSET(newsfep,
793
 
                        XFS_DIR2_SF_GET_OFFSET(oldsfep));
 
783
                xfs_dir2_sf_put_offset(newsfep,
 
784
                        xfs_dir2_sf_get_offset(oldsfep));
794
785
                memmove(newsfep->name, oldsfep->name, newsfep->namelen);
795
 
                ino = XFS_DIR2_SF_GET_INUMBER(oldsfp,
796
 
                        XFS_DIR2_SF_INUMBERP(oldsfep));
797
 
                XFS_DIR2_SF_PUT_INUMBER(newsfp, &ino,
798
 
                        XFS_DIR2_SF_INUMBERP(newsfep));
799
 
                oldsfep = XFS_DIR2_SF_NEXTENTRY(oldsfp, oldsfep);
800
 
                newsfep = XFS_DIR2_SF_NEXTENTRY(newsfp, newsfep);
 
786
                ino = xfs_dir2_sf_get_inumber(oldsfp,
 
787
                        xfs_dir2_sf_inumberp(oldsfep));
 
788
                xfs_dir2_sf_put_inumber(newsfp, &ino,
 
789
                        xfs_dir2_sf_inumberp(newsfep));
 
790
                oldsfep = xfs_dir2_sf_nextentry(oldsfp, oldsfep);
 
791
                newsfep = xfs_dir2_sf_nextentry(newsfp, newsfep);
801
792
        }
802
793
        *next_sfep = newsfep;
803
794
        free(oldsfp);
815
806
        xfs_dir2_sf_entry_t     *sfep;
816
807
        xfs_dir2_sf_t           *sfp;
817
808
 
818
 
        for (i = 0, sfp = &dip->di_u.di_dir2sf,
819
 
                sfep = XFS_DIR2_SF_FIRSTENTRY(sfp),
820
 
                offset = XFS_DIR2_DATA_FIRST_OFFSET;
821
 
             i < INT_GET(sfp->hdr.count, ARCH_CONVERT);
822
 
             i++, sfep = XFS_DIR2_SF_NEXTENTRY(sfp, sfep)) {
823
 
                XFS_DIR2_SF_PUT_OFFSET(sfep, offset);
824
 
                offset += XFS_DIR2_DATA_ENTSIZE(sfep->namelen);
 
809
        sfp = &dip->di_u.di_dir2sf;
 
810
        sfep = xfs_dir2_sf_firstentry(sfp);
 
811
        offset = XFS_DIR2_DATA_FIRST_OFFSET;
 
812
 
 
813
        for (i = 0; i < sfp->hdr.count; i++) {
 
814
                xfs_dir2_sf_put_offset(sfep, offset);
 
815
                offset += xfs_dir2_data_entsize(sfep->namelen);
 
816
                sfep = xfs_dir2_sf_nextentry(sfp, sfep);
825
817
        }
826
818
}
827
819
 
869
861
        sfp = &dip->di_u.di_dir2sf;
870
862
        max_size = XFS_DFORK_DSIZE(dip, mp);
871
863
        num_entries = sfp->hdr.count;
872
 
        ino_dir_size = INT_GET(dip->di_core.di_size, ARCH_CONVERT);
 
864
        ino_dir_size = be64_to_cpu(dip->di_core.di_size);
873
865
        offset = XFS_DIR2_DATA_FIRST_OFFSET;
874
866
        bad_offset = *repair = 0;
875
867
 
878
870
        /*
879
871
         * Initialize i8 based on size of parent inode number.
880
872
         */
881
 
        i8 = (XFS_DIR2_SF_GET_INUMBER(sfp, &sfp->hdr.parent)
 
873
        i8 = (xfs_dir2_sf_get_inumber(sfp, &sfp->hdr.parent)
882
874
                > XFS_DIR2_MAX_SHORT_INUM);
883
875
 
884
876
        /*
885
877
         * check for bad entry count
886
878
         */
887
 
        if (num_entries * XFS_DIR2_SF_ENTSIZE_BYNAME(sfp, 1) +
888
 
                    XFS_DIR2_SF_HDR_SIZE(0) > max_size ||
889
 
            num_entries == 0)
 
879
        if (num_entries * xfs_dir2_sf_entsize_byname(sfp, 1) +
 
880
                    xfs_dir2_sf_hdr_size(0) > max_size || num_entries == 0)
890
881
                num_entries = 0xFF;
891
882
 
892
883
        /*
893
884
         * run through entries, stop at first bad entry, don't need
894
885
         * to check for .. since that's encoded in its own field
895
886
         */
896
 
        sfep = next_sfep = XFS_DIR2_SF_FIRSTENTRY(sfp);
 
887
        sfep = next_sfep = xfs_dir2_sf_firstentry(sfp);
897
888
        for (i = 0;
898
889
             i < num_entries && ino_dir_size > (char *)next_sfep - (char *)sfp;
899
890
             i++) {
901
892
                sfep = next_sfep;
902
893
                junkit = 0;
903
894
                bad_sfnamelen = 0;
904
 
                lino = XFS_DIR2_SF_GET_INUMBER(sfp,
905
 
                                XFS_DIR2_SF_INUMBERP(sfep));
 
895
                lino = xfs_dir2_sf_get_inumber(sfp, xfs_dir2_sf_inumberp(sfep));
906
896
                /*
907
897
                 * if entry points to self, junk it since only '.' or '..'
908
898
                 * should do that and shortform dirs don't contain either
1017
1007
                                break;
1018
1008
                        }
1019
1009
                } else if ((__psint_t) sfep - (__psint_t) sfp +
1020
 
                                + XFS_DIR2_SF_ENTSIZE_BYENTRY(sfp, sfep)
1021
 
                                > ino_dir_size)  {
 
1010
                                xfs_dir2_sf_entsize_byentry(sfp, sfep)
 
1011
                                                        > ino_dir_size)  {
1022
1012
                        bad_sfnamelen = 1;
1023
1013
 
1024
1014
                        if (i == num_entries - 1)  {
1081
1071
                        junkit = 1;
1082
1072
                }
1083
1073
 
1084
 
                if (XFS_DIR2_SF_GET_OFFSET(sfep) < offset) {
 
1074
                if (xfs_dir2_sf_get_offset(sfep) < offset) {
1085
1075
                        do_warn(_("entry contains offset out of order in "
1086
1076
                                  "shortform dir %llu\n"),
1087
1077
                                ino);
1088
1078
                        bad_offset = 1;
1089
1079
                }
1090
 
                offset = XFS_DIR2_SF_GET_OFFSET(sfep) +
1091
 
                         XFS_DIR2_DATA_ENTSIZE(namelen);
 
1080
                offset = xfs_dir2_sf_get_offset(sfep) +
 
1081
                                                xfs_dir2_data_entsize(namelen);
1092
1082
 
1093
1083
                /*
1094
1084
                 * junk the entry by copying up the rest of the
1106
1096
 
1107
1097
                        if (!no_modify)  {
1108
1098
                                tmp_elen =
1109
 
                                        XFS_DIR2_SF_ENTSIZE_BYENTRY(sfp, sfep);
1110
 
                                INT_MOD(dip->di_core.di_size, ARCH_CONVERT,
1111
 
                                        -(tmp_elen));
 
1099
                                        xfs_dir2_sf_entsize_byentry(sfp, sfep);
 
1100
                                be64_add_cpu(&dip->di_core.di_size, -tmp_elen);
1112
1101
                                ino_dir_size -= tmp_elen;
1113
1102
 
1114
1103
                                tmp_sfep = (xfs_dir2_sf_entry_t *)
1118
1107
 
1119
1108
                                memmove(sfep, tmp_sfep, tmp_len);
1120
1109
 
1121
 
                                INT_MOD(sfp->hdr.count, ARCH_CONVERT, -1);
 
1110
                                sfp->hdr.count -= 1;
1122
1111
                                num_entries--;
1123
1112
                                memset((void *) ((__psint_t) sfep + tmp_len), 0,
1124
1113
                                        tmp_elen);
1160
1149
                next_sfep = (tmp_sfep == NULL)
1161
1150
                        ? (xfs_dir2_sf_entry_t *) ((__psint_t) sfep
1162
1151
                                + ((!bad_sfnamelen)
1163
 
                                        ? XFS_DIR2_SF_ENTSIZE_BYENTRY(sfp,
 
1152
                                        ? xfs_dir2_sf_entsize_byentry(sfp,
1164
1153
                                                sfep)
1165
 
                                        : XFS_DIR2_SF_ENTSIZE_BYNAME(sfp,
 
1154
                                        : xfs_dir2_sf_entsize_byname(sfp,
1166
1155
                                                namelen)))
1167
1156
                        : tmp_sfep;
1168
1157
        }
1169
1158
 
1170
1159
        /* sync up sizes and entry counts */
1171
1160
 
1172
 
        if (INT_GET(sfp->hdr.count, ARCH_CONVERT) != i) {
 
1161
        if (sfp->hdr.count != i) {
1173
1162
                if (no_modify) {
1174
1163
                        do_warn(_("would have corrected entry count "
1175
1164
                                  "in directory %llu from %d to %d\n"),
1176
 
                                ino, INT_GET(sfp->hdr.count, ARCH_CONVERT), i);
 
1165
                                ino, sfp->hdr.count, i);
1177
1166
                } else {
1178
1167
                        do_warn(_("corrected entry count in directory %llu, "
1179
1168
                                  "was %d, now %d\n"),
1180
 
                                ino, INT_GET(sfp->hdr.count, ARCH_CONVERT), i);
1181
 
                        INT_SET(sfp->hdr.count, ARCH_CONVERT, i);
 
1169
                                ino, sfp->hdr.count, i);
 
1170
                        sfp->hdr.count = i;
1182
1171
                        *dino_dirty = 1;
1183
1172
                        *repair = 1;
1184
1173
                }
1216
1205
                                (__int64_t)((__psint_t)next_sfep -
1217
1206
                                            (__psint_t)sfp));
1218
1207
 
1219
 
                        INT_SET(dip->di_core.di_size, ARCH_CONVERT,
1220
 
                                (xfs_fsize_t)((__psint_t)next_sfep -
1221
 
                                              (__psint_t)sfp));
 
1208
                        dip->di_core.di_size = cpu_to_be64(
 
1209
                                        (__psint_t)next_sfep - (__psint_t)sfp);
1222
1210
                        *dino_dirty = 1;
1223
1211
                        *repair = 1;
1224
1212
                }
1225
1213
        }
1226
 
        if (offset +
1227
 
                (INT_GET(sfp->hdr.count, ARCH_CONVERT) + 2) *
1228
 
                        sizeof(xfs_dir2_leaf_entry_t) +
1229
 
            sizeof(xfs_dir2_block_tail_t) > mp->m_dirblksize) {
 
1214
        if (offset + (sfp->hdr.count + 2) * sizeof(xfs_dir2_leaf_entry_t) +
 
1215
                        sizeof(xfs_dir2_block_tail_t) > mp->m_dirblksize) {
1230
1216
                do_warn(_("directory %llu offsets too high\n"), ino);
1231
1217
                bad_offset = 1;
1232
1218
        }
1248
1234
        /*
1249
1235
         * check parent (..) entry
1250
1236
         */
1251
 
        *parent = XFS_DIR2_SF_GET_INUMBER(sfp, &sfp->hdr.parent);
 
1237
        *parent = xfs_dir2_sf_get_inumber(sfp, &sfp->hdr.parent);
1252
1238
 
1253
1239
        /*
1254
1240
         * if parent entry is bogus, null it out.  we'll fix it later .
1262
1248
                if (!no_modify)  {
1263
1249
                        do_warn(_("clearing inode number\n"));
1264
1250
 
1265
 
                        XFS_DIR2_SF_PUT_INUMBER(sfp, &zero, &sfp->hdr.parent);
 
1251
                        xfs_dir2_sf_put_inumber(sfp, &zero, &sfp->hdr.parent);
1266
1252
                        *dino_dirty = 1;
1267
1253
                        *repair = 1;
1268
1254
                } else  {
1277
1263
                                  "was %llu, now %llu\n"),
1278
1264
                                ino, *parent, ino);
1279
1265
                        *parent = ino;
1280
 
                        XFS_DIR2_SF_PUT_INUMBER(sfp, parent, &sfp->hdr.parent);
 
1266
                        xfs_dir2_sf_put_inumber(sfp, parent, &sfp->hdr.parent);
1281
1267
                        *dino_dirty = 1;
1282
1268
                        *repair = 1;
1283
1269
                } else  {
1297
1283
                if (!no_modify)  {
1298
1284
                        do_warn(_("clearing inode number\n"));
1299
1285
 
1300
 
                        XFS_DIR2_SF_PUT_INUMBER(sfp, &zero, &sfp->hdr.parent);
 
1286
                        xfs_dir2_sf_put_inumber(sfp, &zero, &sfp->hdr.parent);
1301
1287
                        *dino_dirty = 1;
1302
1288
                        *repair = 1;
1303
1289
                } else  {
1342
1328
        int                     lastfree;
1343
1329
        int                     nm_illegal;
1344
1330
        char                    *ptr;
 
1331
        xfs_ino_t               ent_ino;
1345
1332
 
1346
1333
        d = bp->data;
1347
1334
        bf = d->hdr.bestfree;
1348
1335
        ptr = (char *)d->u;
1349
1336
        badbest = lastfree = freeseen = 0;
1350
 
        if (INT_GET(bf[0].length, ARCH_CONVERT) == 0) {
1351
 
                badbest |= INT_GET(bf[0].offset, ARCH_CONVERT) != 0;
 
1337
        if (be16_to_cpu(bf[0].length) == 0) {
 
1338
                badbest |= be16_to_cpu(bf[0].offset) != 0;
1352
1339
                freeseen |= 1 << 0;
1353
1340
        }
1354
 
        if (INT_GET(bf[1].length, ARCH_CONVERT) == 0) {
1355
 
                badbest |= INT_GET(bf[1].offset, ARCH_CONVERT) != 0;
 
1341
        if (be16_to_cpu(bf[1].length) == 0) {
 
1342
                badbest |= be16_to_cpu(bf[1].offset) != 0;
1356
1343
                freeseen |= 1 << 1;
1357
1344
        }
1358
 
        if (INT_GET(bf[2].length, ARCH_CONVERT) == 0) {
1359
 
                badbest |= INT_GET(bf[2].offset, ARCH_CONVERT) != 0;
 
1345
        if (be16_to_cpu(bf[2].length) == 0) {
 
1346
                badbest |= be16_to_cpu(bf[2].offset) != 0;
1360
1347
                freeseen |= 1 << 2;
1361
1348
        }
1362
 
        badbest |= INT_GET(bf[0].length, ARCH_CONVERT) < INT_GET(bf[1].length, ARCH_CONVERT);
1363
 
        badbest |= INT_GET(bf[1].length, ARCH_CONVERT) < INT_GET(bf[2].length, ARCH_CONVERT);
 
1349
        badbest |= be16_to_cpu(bf[0].length) < be16_to_cpu(bf[1].length);
 
1350
        badbest |= be16_to_cpu(bf[1].length) < be16_to_cpu(bf[2].length);
1364
1351
        while (ptr < endptr) {
1365
1352
                dup = (xfs_dir2_data_unused_t *)ptr;
1366
1353
                /*
1368
1355
                 * If we find it, account for that, else make sure it doesn't
1369
1356
                 * need to be there.
1370
1357
                 */
1371
 
                if (INT_GET(dup->freetag, ARCH_CONVERT) == XFS_DIR2_DATA_FREE_TAG) {
1372
 
                        if (ptr + INT_GET(dup->length, ARCH_CONVERT) > endptr ||
1373
 
                            INT_GET(dup->length, ARCH_CONVERT) == 0 ||
1374
 
                            (INT_GET(dup->length, ARCH_CONVERT) & (XFS_DIR2_DATA_ALIGN - 1)))
 
1358
                if (be16_to_cpu(dup->freetag) == XFS_DIR2_DATA_FREE_TAG) {
 
1359
                        if (ptr + be16_to_cpu(dup->length) > endptr ||
 
1360
                            be16_to_cpu(dup->length) == 0 ||
 
1361
                            (be16_to_cpu(dup->length) & (XFS_DIR2_DATA_ALIGN - 1)))
1375
1362
                                break;
1376
 
                        if (INT_GET(*XFS_DIR2_DATA_UNUSED_TAG_P(dup),
1377
 
                                    ARCH_CONVERT) != (char *)dup - (char *)d)
 
1363
                        if (be16_to_cpu(*xfs_dir2_data_unused_tag_p(dup)) !=
 
1364
                                                        (char *)dup - (char *)d)
1378
1365
                                break;
1379
1366
                        badbest |= lastfree != 0;
1380
1367
                        dfp = xfs_dir2_data_freefind(d, dup);
1383
1370
                                badbest |= (freeseen & (1 << i)) != 0;
1384
1371
                                freeseen |= 1 << i;
1385
1372
                        } else
1386
 
                                badbest |= INT_GET(dup->length, ARCH_CONVERT) >
1387
 
                                        INT_GET(bf[2].length, ARCH_CONVERT);
1388
 
                        ptr += INT_GET(dup->length, ARCH_CONVERT);
 
1373
                                badbest |= be16_to_cpu(dup->length) >
 
1374
                                        be16_to_cpu(bf[2].length);
 
1375
                        ptr += be16_to_cpu(dup->length);
1389
1376
                        lastfree = 1;
1390
1377
                        continue;
1391
1378
                }
1392
1379
                dep = (xfs_dir2_data_entry_t *)ptr;
1393
 
                if (ptr + XFS_DIR2_DATA_ENTSIZE(dep->namelen) > endptr)
1394
 
                        break;
1395
 
                if (INT_GET(*XFS_DIR2_DATA_ENTRY_TAG_P(dep), ARCH_CONVERT) !=
1396
 
                    (char *)dep - (char *)d)
1397
 
                        break;
1398
 
                ptr += XFS_DIR2_DATA_ENTSIZE(dep->namelen);
 
1380
                if (ptr + xfs_dir2_data_entsize(dep->namelen) > endptr)
 
1381
                        break;
 
1382
                if (be16_to_cpu(*xfs_dir2_data_entry_tag_p(dep)) !=
 
1383
                                                (char *)dep - (char *)d)
 
1384
                        break;
 
1385
                ptr += xfs_dir2_data_entsize(dep->namelen);
1399
1386
                lastfree = 0;
1400
1387
        }
1401
1388
        /*
1417
1404
         */
1418
1405
        while (ptr < endptr) {
1419
1406
                dup = (xfs_dir2_data_unused_t *)ptr;
1420
 
                if (INT_GET(dup->freetag, ARCH_CONVERT) ==
1421
 
                    XFS_DIR2_DATA_FREE_TAG) {
1422
 
                        ptr += INT_GET(dup->length, ARCH_CONVERT);
 
1407
                if (be16_to_cpu(dup->freetag) == XFS_DIR2_DATA_FREE_TAG) {
 
1408
                        ptr += be16_to_cpu(dup->length);
1423
1409
                        continue;
1424
1410
                }
1425
1411
                dep = (xfs_dir2_data_entry_t *)ptr;
 
1412
                ent_ino = be64_to_cpu(dep->inumber);
 
1413
                clearino = 1;
 
1414
                clearreason = NULL;
1426
1415
                /*
1427
1416
                 * We may have to blow out an entry because of bad inode
1428
1417
                 * numbers.  Do NOT touch the name until after we've computed
1429
1418
                 * the hashvalue and done a namecheck() on the name.
 
1419
                 *
 
1420
                 * Conditions must either set clearino to zero or set 
 
1421
                 * clearreason why it's being cleared.
1430
1422
                 */
1431
 
                if (!ino_discovery &&
1432
 
                    INT_GET(dep->inumber, ARCH_CONVERT) == BADFSINO) {
 
1423
                if (!ino_discovery && ent_ino == BADFSINO) {
1433
1424
                        /*
1434
1425
                         * Don't do a damned thing.  We already found this
1435
1426
                         * (or did it ourselves) during phase 3.
1436
1427
                         */
1437
1428
                        clearino = 0;
1438
 
                } else if (verify_inum(mp, INT_GET(dep->inumber, ARCH_CONVERT))) {
 
1429
                } else if (verify_inum(mp, ent_ino)) {
1439
1430
                        /*
1440
1431
                         * Bad inode number.  Clear the inode number and the
1441
1432
                         * entry will get removed later.  We don't trash the
1442
1433
                         * directory since it's still structurally intact.
1443
1434
                         */
1444
 
                        clearino = 1;
1445
1435
                        clearreason = _("invalid");
1446
 
                } else if (INT_GET(dep->inumber, ARCH_CONVERT) == mp->m_sb.sb_rbmino) {
1447
 
                        clearino = 1;
 
1436
                } else if (ent_ino == mp->m_sb.sb_rbmino) {
1448
1437
                        clearreason = _("realtime bitmap");
1449
 
                } else if (INT_GET(dep->inumber, ARCH_CONVERT) == mp->m_sb.sb_rsumino) {
1450
 
                        clearino = 1;
 
1438
                } else if (ent_ino == mp->m_sb.sb_rsumino) {
1451
1439
                        clearreason = _("realtime summary");
1452
 
                } else if (INT_GET(dep->inumber, ARCH_CONVERT) == mp->m_sb.sb_uquotino) {
1453
 
                        clearino = 1;
 
1440
                } else if (ent_ino == mp->m_sb.sb_uquotino) {
1454
1441
                        clearreason = _("user quota");
1455
 
                } else if (INT_GET(dep->inumber, ARCH_CONVERT) == mp->m_sb.sb_gquotino) {
1456
 
                        clearino = 1;
 
1442
                } else if (ent_ino == mp->m_sb.sb_gquotino) {
1457
1443
                        clearreason = _("group quota");
1458
 
                } else if ((irec_p = find_inode_rec(
1459
 
                                XFS_INO_TO_AGNO(mp, INT_GET(dep->inumber,
1460
 
                                        ARCH_CONVERT)),
1461
 
                                XFS_INO_TO_AGINO(mp, INT_GET(dep->inumber,
1462
 
                                        ARCH_CONVERT)))) != NULL) {
1463
 
                        /*
1464
 
                         * Inode recs should have only confirmed inodes in them.
1465
 
                         */
1466
 
                        ino_off = XFS_INO_TO_AGINO(mp, INT_GET(dep->inumber,
1467
 
                                        ARCH_CONVERT)) - irec_p->ino_startnum;
1468
 
                        ASSERT(is_inode_confirmed(irec_p, ino_off));
1469
 
                        /*
1470
 
                         * If inode is marked free and we're in inode discovery
1471
 
                         * mode, leave the entry alone for now.  If the inode
1472
 
                         * turns out to be used, we'll figure that out when we
1473
 
                         * scan it.  If the inode really is free, we'll hit this
1474
 
                         * code again in phase 4 after we've finished inode
1475
 
                         * discovery and blow out the entry then.
1476
 
                         */
1477
 
                        if (!ino_discovery && is_inode_free(irec_p, ino_off)) {
1478
 
                                clearino = 1;
1479
 
                                clearreason = _("free");
1480
 
                        } else
1481
 
                                clearino = 0;
1482
 
                } else if (ino_discovery) {
1483
 
                        add_inode_uncertain(mp, INT_GET(dep->inumber, ARCH_CONVERT), 0);
1484
 
                        clearino = 0;
1485
1444
                } else {
1486
 
                        clearino = 1;
1487
 
                        clearreason = _("non-existent");
 
1445
                        irec_p = find_inode_rec(XFS_INO_TO_AGNO(mp, ent_ino),
 
1446
                                                XFS_INO_TO_AGINO(mp, ent_ino));
 
1447
                        if (irec_p == NULL) {
 
1448
                                if (ino_discovery) {
 
1449
                                        add_inode_uncertain(mp, ent_ino, 0);
 
1450
                                        clearino = 0;
 
1451
                                } else 
 
1452
                                        clearreason = _("non-existent");
 
1453
                        } else {
 
1454
                                /*
 
1455
                                 * Inode recs should have only confirmed
 
1456
                                 * inodes in them.
 
1457
                                 */
 
1458
                                ino_off = XFS_INO_TO_AGINO(mp, ent_ino)
 
1459
                                                        - irec_p->ino_startnum;
 
1460
                                ASSERT(is_inode_confirmed(irec_p, ino_off));
 
1461
                                /*
 
1462
                                 * If inode is marked free and we're in inode
 
1463
                                 * discovery mode, leave the entry alone for
 
1464
                                 * now.  If the inode turns out to be used,
 
1465
                                 * we'll figure that out when we scan it.
 
1466
                                 * If the inode really is free, we'll hit this
 
1467
                                 * code again in phase 4 after we've finished
 
1468
                                 * inode discovery and blow out the entry then.
 
1469
                                 */
 
1470
                                if (!ino_discovery && is_inode_free(irec_p,
 
1471
                                                                ino_off))
 
1472
                                        clearreason = _("free");
 
1473
                                else
 
1474
                                        clearino = 0;
 
1475
                        }
1488
1476
                }
 
1477
                ASSERT((clearino == 0 && clearreason == NULL) ||
 
1478
                        (clearino != 0 && clearreason != NULL));
1489
1479
                if (clearino)
1490
1480
                        do_warn(_("entry \"%*.*s\" at block %u offset %d in "
1491
1481
                                  "directory inode %llu references %s inode "
1492
1482
                                  "%llu\n"),
1493
1483
                                dep->namelen, dep->namelen, dep->name,
1494
1484
                                da_bno, (char *)ptr - (char *)d, ino,
1495
 
                                clearreason,
1496
 
                                INT_GET(dep->inumber, ARCH_CONVERT));
 
1485
                                clearreason, ent_ino);
1497
1486
                /*
1498
1487
                 * If the name length is 0 (illegal) make it 1 and blast
1499
1488
                 * the entry.
1514
1503
                                do_warn(_("\tclearing inode number in entry at "
1515
1504
                                          "offset %d...\n"),
1516
1505
                                        (char *)ptr - (char *)d);
1517
 
                                INT_SET(dep->inumber, ARCH_CONVERT, BADFSINO);
 
1506
                                dep->inumber = cpu_to_be64(BADFSINO);
 
1507
                                ent_ino = BADFSINO;
1518
1508
                                bp->dirty = 1;
1519
1509
                        } else {
1520
1510
                                do_warn(_("\twould clear inode number in entry "
1527
1517
                 * discovery is turned on).  Otherwise, we'd complain a lot
1528
1518
                 * during phase 4.
1529
1519
                 */
1530
 
                junkit = INT_GET(dep->inumber, ARCH_CONVERT) == BADFSINO;
 
1520
                junkit = ent_ino == BADFSINO;
1531
1521
                nm_illegal = namecheck((char *)dep->name, dep->namelen);
1532
1522
                if (ino_discovery && nm_illegal) {
1533
1523
                        do_warn(_("entry at block %u offset %d in directory "
1539
1529
                /*
1540
1530
                 * Now we can mark entries with BADFSINO's bad.
1541
1531
                 */
1542
 
                if (!no_modify &&
1543
 
                    INT_GET(dep->inumber, ARCH_CONVERT) == BADFSINO) {
 
1532
                if (!no_modify && ent_ino == BADFSINO) {
1544
1533
                        dep->name[0] = '/';
1545
1534
                        bp->dirty = 1;
1546
1535
                        junkit = 0;
1552
1541
                    dep->name[0] == '.' && dep->name[1] == '.') {
1553
1542
                        if (!*dotdot) {
1554
1543
                                (*dotdot)++;
1555
 
                                *parent = INT_GET(dep->inumber, ARCH_CONVERT);
 
1544
                                *parent = ent_ino;
1556
1545
                                /*
1557
1546
                                 * What if .. == .?  Legal only in the root
1558
1547
                                 * inode.  Blow out entry and set parent to
1559
1548
                                 * NULLFSINO otherwise.
1560
1549
                                 */
1561
 
                                if (ino == INT_GET(dep->inumber, ARCH_CONVERT) &&
1562
 
                                    ino != mp->m_sb.sb_rootino) {
 
1550
                                if (ino == ent_ino &&
 
1551
                                                ino != mp->m_sb.sb_rootino) {
1563
1552
                                        *parent = NULLFSINO;
1564
1553
                                        do_warn(_("bad .. entry in directory "
1565
1554
                                                  "inode %llu, points to self: "),
1570
1559
                                 * We have to make sure that . == .. in the
1571
1560
                                 * root inode.
1572
1561
                                 */
1573
 
                                else if (ino != INT_GET(dep->inumber, ARCH_CONVERT) &&
1574
 
                                           ino == mp->m_sb.sb_rootino) {
 
1562
                                else if (ino != ent_ino &&
 
1563
                                                ino == mp->m_sb.sb_rootino) {
1575
1564
                                        do_warn(_("bad .. entry in root "
1576
1565
                                                  "directory inode %llu, was "
1577
1566
                                                  "%llu: "),
1578
 
                                                ino, INT_GET(dep->inumber, ARCH_CONVERT));
 
1567
                                                ino, ent_ino);
1579
1568
                                        if (!no_modify) {
1580
1569
                                                do_warn(_("correcting\n"));
1581
 
                                                INT_SET(dep->inumber, ARCH_CONVERT, ino);
 
1570
                                                dep->inumber = cpu_to_be64(ino);
1582
1571
                                                bp->dirty = 1;
1583
1572
                                        } else {
1584
1573
                                                do_warn(_("would correct\n"));
1604
1593
                else if (dep->namelen == 1 && dep->name[0] == '.') {
1605
1594
                        if (!*dot) {
1606
1595
                                (*dot)++;
1607
 
                                if (INT_GET(dep->inumber, ARCH_CONVERT) != ino) {
 
1596
                                if (ent_ino != ino) {
1608
1597
                                        do_warn(_("bad . entry in directory "
1609
1598
                                                  "inode %llu, was %llu: "),
1610
 
                                                ino, INT_GET(dep->inumber, ARCH_CONVERT));
 
1599
                                                ino, ent_ino);
1611
1600
                                        if (!no_modify) {
1612
1601
                                                do_warn(_("correcting\n"));
1613
 
                                                INT_SET(dep->inumber, ARCH_CONVERT, ino);
 
1602
                                                dep->inumber = cpu_to_be64(ino);
1614
1603
                                                bp->dirty = 1;
1615
1604
                                        } else {
1616
1605
                                                do_warn(_("would correct\n"));
1626
1615
                /*
1627
1616
                 * All other entries -- make sure only . references self.
1628
1617
                 */
1629
 
                else if (INT_GET(dep->inumber, ARCH_CONVERT) == ino) {
 
1618
                else if (ent_ino == ino) {
1630
1619
                        do_warn(_("entry \"%*.*s\" in directory inode %llu "
1631
1620
                                  "points to self: "),
1632
1621
                                dep->namelen, dep->namelen, dep->name, ino);
1647
1636
                /*
1648
1637
                 * Advance to the next entry.
1649
1638
                 */
1650
 
                ptr += XFS_DIR2_DATA_ENTSIZE(dep->namelen);
 
1639
                ptr += xfs_dir2_data_entsize(dep->namelen);
1651
1640
        }
1652
1641
        /*
1653
1642
         * Check the bestfree table.
1654
1643
         */
1655
1644
        if (freeseen != 7 || badbest) {
1656
1645
                do_warn(_("bad bestfree table in block %u in directory inode "
1657
 
                          "%llu: "),
1658
 
                        da_bno, ino);
 
1646
                          "%llu: "), da_bno, ino);
1659
1647
                if (!no_modify) {
1660
1648
                        do_warn(_("repairing table\n"));
1661
 
                        libxfs_dir2_data_freescan(mp, d, &i, endptr);
 
1649
                        libxfs_dir2_data_freescan(mp, d, &i);
1662
1650
                        bp->dirty = 1;
1663
1651
                } else {
1664
1652
                        do_warn(_("would repair table\n"));
1714
1702
         * Verify the block
1715
1703
         */
1716
1704
        block = bp->data;
1717
 
        if (INT_GET(block->hdr.magic, ARCH_CONVERT) != XFS_DIR2_BLOCK_MAGIC)
 
1705
        if (be32_to_cpu(block->hdr.magic) != XFS_DIR2_BLOCK_MAGIC)
1718
1706
                do_warn(_("bad directory block magic # %#x in block %u for "
1719
1707
                          "directory inode %llu\n"),
1720
 
                        INT_GET(block->hdr.magic, ARCH_CONVERT),
1721
 
                        mp->m_dirdatablk, ino);
 
1708
                        be32_to_cpu(block->hdr.magic), mp->m_dirdatablk, ino);
1722
1709
        /*
1723
1710
         * process the data area
1724
1711
         * this also checks & fixes the bestfree
1725
1712
         */
1726
 
        btp = XFS_DIR2_BLOCK_TAIL_P(mp, block);
1727
 
        blp = XFS_DIR2_BLOCK_LEAF_P(btp);
 
1713
        btp = xfs_dir2_block_tail_p(mp, block);
 
1714
        blp = xfs_dir2_block_leaf_p(btp);
1728
1715
        /*
1729
1716
         * Don't let this go past the end of the block.
1730
1717
         */
1758
1745
        int                     i;
1759
1746
        int                     stale;
1760
1747
 
1761
 
        for (i = stale = 0; i < INT_GET(leaf->hdr.count, ARCH_CONVERT); i++) {
 
1748
        for (i = stale = 0; i < be16_to_cpu(leaf->hdr.count); i++) {
1762
1749
                if ((char *)&leaf->ents[i] >= (char *)leaf + mp->m_dirblksize) {
1763
1750
                        do_warn(_("bad entry count in block %u of directory "
1764
1751
                                  "inode %llu\n"),
1765
1752
                                da_bno, ino);
1766
1753
                        return 1;
1767
1754
                }
1768
 
                if (INT_GET(leaf->ents[i].address, ARCH_CONVERT) ==
1769
 
                    XFS_DIR2_NULL_DATAPTR)
 
1755
                if (be32_to_cpu(leaf->ents[i].address) == XFS_DIR2_NULL_DATAPTR)
1770
1756
                        stale++;
1771
 
                else if (INT_GET(leaf->ents[i].hashval, ARCH_CONVERT) <
1772
 
                         last_hashval) {
 
1757
                else if (be32_to_cpu(leaf->ents[i].hashval) < last_hashval) {
1773
1758
                        do_warn(_("bad hash ordering in block %u of directory "
1774
1759
                                  "inode %llu\n"),
1775
1760
                                da_bno, ino);
1776
1761
                        return 1;
1777
1762
                }
1778
1763
                *next_hashval = last_hashval =
1779
 
                        INT_GET(leaf->ents[i].hashval, ARCH_CONVERT);
 
1764
                                        be32_to_cpu(leaf->ents[i].hashval);
1780
1765
        }
1781
 
        if (stale != INT_GET(leaf->hdr.stale, ARCH_CONVERT)) {
 
1766
        if (stale != be16_to_cpu(leaf->hdr.stale)) {
1782
1767
                do_warn(_("bad stale count in block %u of directory "
1783
1768
                          "inode %llu\n"),
1784
1769
                        da_bno, ino);
1846
1831
                /*
1847
1832
                 * Check magic number for leaf directory btree block.
1848
1833
                 */
1849
 
                if (INT_GET(leaf->hdr.info.magic, ARCH_CONVERT) !=
 
1834
                if (be16_to_cpu(leaf->hdr.info.magic) !=
1850
1835
                   XFS_DIR2_LEAFN_MAGIC) {
1851
1836
                        do_warn(_("bad directory leaf magic # %#x for "
1852
1837
                                  "directory inode %llu block %u\n"),
1853
 
                                INT_GET(leaf->hdr.info.magic, ARCH_CONVERT),
 
1838
                                be16_to_cpu(leaf->hdr.info.magic),
1854
1839
                                ino, da_bno);
1855
1840
                        da_brelse(bp);
1856
1841
                        goto error_out;
1874
1859
                da_cursor->level[0].bp = bp;
1875
1860
                da_cursor->level[0].bno = da_bno;
1876
1861
                da_cursor->level[0].index =
1877
 
                        INT_GET(leaf->hdr.count, ARCH_CONVERT);
 
1862
                        be16_to_cpu(leaf->hdr.count);
1878
1863
                da_cursor->level[0].dirty = buf_dirty;
1879
1864
 
1880
 
                if (INT_GET(leaf->hdr.info.back, ARCH_CONVERT) != prev_bno) {
 
1865
                if (be32_to_cpu(leaf->hdr.info.back) != prev_bno) {
1881
1866
                        do_warn(_("bad sibling back pointer for block %u in "
1882
1867
                                  "directory inode %llu\n"),
1883
1868
                                da_bno, ino);
1885
1870
                        goto error_out;
1886
1871
                }
1887
1872
                prev_bno = da_bno;
1888
 
                da_bno = INT_GET(leaf->hdr.info.forw, ARCH_CONVERT);
 
1873
                da_bno = be32_to_cpu(leaf->hdr.info.forw);
1889
1874
                if (da_bno != 0) {
1890
1875
                        if (verify_dir2_path(mp, da_cursor, 0)) {
1891
1876
                                da_brelse(bp);
2023
2008
                        continue;
2024
2009
                }
2025
2010
                data = bp->data;
2026
 
                if (INT_GET(data->hdr.magic, ARCH_CONVERT) !=
2027
 
                    XFS_DIR2_DATA_MAGIC)
 
2011
                if (be32_to_cpu(data->hdr.magic) != XFS_DIR2_DATA_MAGIC)
2028
2012
                        do_warn(_("bad directory block magic # %#x in block "
2029
2013
                                "%llu for directory inode %llu\n"),
2030
 
                                INT_GET(data->hdr.magic, ARCH_CONVERT),
2031
 
                                dbno, ino);
 
2014
                                be32_to_cpu(data->hdr.magic), dbno, ino);
2032
2015
                i = process_dir2_data(mp, ino, dip, ino_discovery, dirname,
2033
2016
                        parent, bp, dot, dotdot, (xfs_dablk_t)dbno,
2034
2017
                        (char *)data + mp->m_dirblksize);
2086
2069
         */
2087
2070
        if (blkmap)
2088
2071
                last = blkmap_last_off(blkmap);
2089
 
        if (INT_GET(dip->di_core.di_size, ARCH_CONVERT) <=
2090
 
                XFS_DFORK_DSIZE(dip, mp) &&
2091
 
            dip->di_core.di_format == XFS_DINODE_FMT_LOCAL) {
 
2072
        if (be64_to_cpu(dip->di_core.di_size) <= XFS_DFORK_DSIZE(dip, mp) &&
 
2073
                        dip->di_core.di_format == XFS_DINODE_FMT_LOCAL) {
2092
2074
                dot = dotdot = 1;
2093
2075
                res = process_sf_dir2(mp, ino, dip, ino_discovery, dino_dirty,
2094
2076
                        dirname, parent, &repair);
2095
2077
        } else if (last == mp->m_dirblkfsbs &&
2096
 
                 (dip->di_core.di_format == XFS_DINODE_FMT_EXTENTS ||
2097
 
                  dip->di_core.di_format == XFS_DINODE_FMT_BTREE)) {
 
2078
                        (dip->di_core.di_format == XFS_DINODE_FMT_EXTENTS ||
 
2079
                        dip->di_core.di_format == XFS_DINODE_FMT_BTREE)) {
2098
2080
                res = process_block_dir2(mp, ino, dip, ino_discovery,
2099
2081
                        dino_dirty, dirname, parent, blkmap, &dot, &dotdot,
2100
2082
                        &repair);
2101
2083
        } else if (last >= mp->m_dirleafblk + mp->m_dirblkfsbs &&
2102
 
                 (dip->di_core.di_format == XFS_DINODE_FMT_EXTENTS ||
2103
 
                  dip->di_core.di_format == XFS_DINODE_FMT_BTREE)) {
 
2084
                        (dip->di_core.di_format == XFS_DINODE_FMT_EXTENTS ||
 
2085
                        dip->di_core.di_format == XFS_DINODE_FMT_BTREE)) {
2104
2086
                res = process_leaf_node_dir2(mp, ino, dip, ino_discovery,
2105
2087
                        dirname, parent, blkmap, &dot, &dotdot, &repair,
2106
2088
                        last > mp->m_dirleafblk + mp->m_dirblkfsbs);