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

« back to all changes in this revision

Viewing changes to repair/dir.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:
104
104
        fprintf(stderr, "process_shortform_dir - inode %llu\n", ino);
105
105
#endif
106
106
 
107
 
        sf = &dip->di_u.di_dirsf;
108
 
 
 
107
        sf = (xfs_dir_shortform_t *)XFS_DFORK_DPTR(dip);
109
108
        max_size = XFS_DFORK_DSIZE(dip, mp);
110
 
        num_entries = INT_GET(sf->hdr.count, ARCH_CONVERT);
111
 
        ino_dir_size = INT_GET(dip->di_core.di_size, ARCH_CONVERT);
 
109
        num_entries = sf->hdr.count;
 
110
        ino_dir_size = be64_to_cpu(dip->di_core.di_size);
112
111
        *repair = 0;
113
112
 
114
113
        ASSERT(ino_dir_size <= max_size);
131
130
                sf_entry = next_sfe;
132
131
                junkit = 0;
133
132
                bad_sfnamelen = 0;
134
 
                XFS_DIR_SF_GET_DIRINO(&sf_entry->inumber, &lino);
 
133
                xfs_dir_sf_get_dirino(&sf_entry->inumber, &lino);
135
134
 
136
135
                /*
137
136
                 * if entry points to self, junk it since only '.' or '..'
259
258
                                break;
260
259
                        }
261
260
                } else if ((__psint_t) sf_entry - (__psint_t) sf +
262
 
                                + XFS_DIR_SF_ENTSIZE_BYENTRY(sf_entry)
 
261
                                + xfs_dir_sf_entsize_byentry(sf_entry)
263
262
                                > ino_dir_size)  {
264
263
                        bad_sfnamelen = 1;
265
264
 
338
337
                        name[namelen] = '\0';
339
338
 
340
339
                        if (!no_modify)  {
341
 
                                tmp_elen = XFS_DIR_SF_ENTSIZE_BYENTRY(sf_entry);
342
 
                                INT_MOD(dip->di_core.di_size,
343
 
                                        ARCH_CONVERT, -(tmp_elen));
 
340
                                tmp_elen = xfs_dir_sf_entsize_byentry(sf_entry);
 
341
                                be64_add_cpu(&dip->di_core.di_size, -tmp_elen);
344
342
                                ino_dir_size -= tmp_elen;
345
343
 
346
344
                                tmp_sfe = (xfs_dir_sf_entry_t *)
350
348
 
351
349
                                memmove(sf_entry, tmp_sfe, tmp_len);
352
350
 
353
 
                                INT_MOD(sf->hdr.count, ARCH_CONVERT, -1);
 
351
                                sf->hdr.count -= 1;
354
352
                                num_entries--;
355
 
                                memset((void *) ((__psint_t) sf_entry + tmp_len), 0,
356
 
                                        tmp_elen);
 
353
                                memset((void *)((__psint_t)sf_entry + tmp_len), 
 
354
                                                                0, tmp_elen);
357
355
 
358
356
                                /*
359
357
                                 * reset the tmp value to the current
392
390
                next_sfe = (tmp_sfe == NULL)
393
391
                        ? (xfs_dir_sf_entry_t *) ((__psint_t) sf_entry
394
392
                                + ((!bad_sfnamelen)
395
 
                                        ? XFS_DIR_SF_ENTSIZE_BYENTRY(sf_entry)
 
393
                                        ? xfs_dir_sf_entsize_byentry(sf_entry)
396
394
                                        : sizeof(xfs_dir_sf_entry_t) - 1
397
395
                                                + namelen))
398
396
                        : tmp_sfe;
400
398
 
401
399
        /* sync up sizes and entry counts */
402
400
 
403
 
        if (INT_GET(sf->hdr.count, ARCH_CONVERT) != i)  {
 
401
        if (sf->hdr.count != i)  {
404
402
                if (no_modify)  {
405
403
                        do_warn(
406
404
        _("would have corrected entry count in directory %llu from %d to %d\n"),
407
 
                        ino, INT_GET(sf->hdr.count, ARCH_CONVERT), i);
 
405
                        ino, sf->hdr.count, i);
408
406
                } else  {
409
407
                        do_warn(
410
408
        _("corrected entry count in directory %llu, was %d, now %d\n"),
411
 
                        ino, INT_GET(sf->hdr.count, ARCH_CONVERT), i);
412
 
                        INT_SET(sf->hdr.count, ARCH_CONVERT, i);
 
409
                        ino, sf->hdr.count, i);
 
410
                        sf->hdr.count = i;
413
411
                        *dino_dirty = 1;
414
412
                        *repair = 1;
415
413
                }
427
425
                                ino, (__int64_t) ino_dir_size,
428
426
                        (__int64_t)((__psint_t) next_sfe - (__psint_t) sf));
429
427
 
430
 
                        INT_SET(dip->di_core.di_size,
431
 
                                ARCH_CONVERT, (xfs_fsize_t)
432
 
                                ((__psint_t) next_sfe - (__psint_t) sf));
 
428
                        dip->di_core.di_size = cpu_to_be64((__psint_t)next_sfe 
 
429
                                                        - (__psint_t)sf);
433
430
                        *dino_dirty = 1;
434
431
                        *repair = 1;
435
432
                }
437
434
        /*
438
435
         * check parent (..) entry
439
436
         */
440
 
        XFS_DIR_SF_GET_DIRINO(&sf->hdr.parent, parent);
 
437
        xfs_dir_sf_get_dirino(&sf->hdr.parent, parent);
441
438
 
442
439
        /*
443
440
         * if parent entry is bogus, null it out.  we'll fix it later .
451
448
                if (!no_modify)  {
452
449
                        do_warn(_("clearing inode number\n"));
453
450
 
454
 
                        XFS_DIR_SF_PUT_DIRINO(parent, &sf->hdr.parent);
 
451
                        xfs_dir_sf_put_dirino(parent, &sf->hdr.parent);
455
452
                        *dino_dirty = 1;
456
453
                        *repair = 1;
457
454
                } else  {
466
463
        _("corrected root directory %llu .. entry, was %llu, now %llu\n"),
467
464
                                ino, *parent, ino);
468
465
                        *parent = ino;
469
 
                        XFS_DIR_SF_PUT_DIRINO(parent, &sf->hdr.parent);
 
466
                        xfs_dir_sf_put_dirino(parent, &sf->hdr.parent);
470
467
                        *dino_dirty = 1;
471
468
                        *repair = 1;
472
469
                } else  {
485
482
                if (!no_modify)  {
486
483
                        do_warn(_("clearing inode number\n"));
487
484
 
488
 
                        XFS_DIR_SF_PUT_DIRINO(parent, &sf->hdr.parent);
 
485
                        xfs_dir_sf_put_dirino(parent, &sf->hdr.parent);
489
486
                        *dino_dirty = 1;
490
487
                        *repair = 1;
491
488
                } else  {
805
802
 
806
803
                node = (xfs_da_intnode_t *)XFS_BUF_PTR(bp);
807
804
 
808
 
                if (INT_GET(node->hdr.info.magic, ARCH_CONVERT) != XFS_DA_NODE_MAGIC)  {
 
805
                if (be16_to_cpu(node->hdr.info.magic) != XFS_DA_NODE_MAGIC)  {
809
806
                        do_warn(_("bad dir/attr magic number in inode %llu, "
810
807
                                  "file bno = %u, fsbno = %llu\n"),
811
808
                                da_cursor->ino, bno, fsbno);
812
809
                        libxfs_putbuf(bp);
813
810
                        goto error_out;
814
811
                }
815
 
                if (INT_GET(node->hdr.count, ARCH_CONVERT) >
 
812
                if (be16_to_cpu(node->hdr.count) >
816
813
                                                mp->m_dir_node_ents)  {
817
814
                        do_warn(_("bad record count in inode %llu, "
818
815
                                  "count = %d, max = %d\n"),
819
816
                                da_cursor->ino,
820
 
                                INT_GET(node->hdr.count, ARCH_CONVERT),
 
817
                                be16_to_cpu(node->hdr.count),
821
818
                                mp->m_dir_node_ents);
822
819
                        libxfs_putbuf(bp);
823
820
                        goto error_out;
827
824
                 * maintain level counter
828
825
                 */
829
826
                if (i == -1)
830
 
                        i = da_cursor->active = INT_GET(node->hdr.level, ARCH_CONVERT);
 
827
                        i = da_cursor->active = be16_to_cpu(node->hdr.level);
831
828
                else  {
832
 
                        if (INT_GET(node->hdr.level, ARCH_CONVERT) == i - 1)  {
 
829
                        if (be16_to_cpu(node->hdr.level) == i - 1)  {
833
830
                                i--;
834
831
                        } else  {
835
832
                                if (whichfork == XFS_DATA_FORK)
845
842
                        }
846
843
                }
847
844
 
848
 
                da_cursor->level[i].hashval =
849
 
                                INT_GET(node->btree[0].hashval, ARCH_CONVERT);
 
845
                da_cursor->level[i].hashval = be32_to_cpu(
 
846
                                                        node->btree[0].hashval);
850
847
                da_cursor->level[i].bp = bp;
851
848
                da_cursor->level[i].bno = bno;
852
849
                da_cursor->level[i].index = 0;
857
854
                /*
858
855
                 * set up new bno for next level down
859
856
                 */
860
 
                bno = INT_GET(node->btree[0].before, ARCH_CONVERT);
861
 
        } while(node != NULL && i > 1);
 
857
                bno = be32_to_cpu(node->btree[0].before);
 
858
        } while (node != NULL && i > 1);
862
859
 
863
860
        /*
864
861
         * now return block number and get out
957
954
                return(fsbno);
958
955
        }
959
956
 
960
 
        if (INT_GET(dino->di_core.di_size, ARCH_CONVERT) <= XFS_LBSIZE(mp))
 
957
        if (be64_to_cpu(dino->di_core.di_size) <= XFS_LBSIZE(mp))
961
958
                return(fsbno);
962
959
 
963
960
        do {
980
977
                node = (xfs_da_intnode_t *)XFS_BUF_PTR(bp);
981
978
 
982
979
                if (XFS_DA_NODE_MAGIC !=
983
 
                    INT_GET(node->hdr.info.magic, ARCH_CONVERT))  {
 
980
                    be16_to_cpu(node->hdr.info.magic))  {
984
981
                        do_warn(_("bad dir/attr magic number in inode %llu, "
985
982
                                  "file bno = %u, fsbno = %llu\n"),
986
983
                                ino, bno, fsbno);
989
986
                }
990
987
 
991
988
                if (i == -1)
992
 
                        i = INT_GET(node->hdr.level, ARCH_CONVERT);
993
 
                bno = INT_GET(node->btree[0].before, ARCH_CONVERT);
 
989
                        i = be16_to_cpu(node->hdr.level);
 
990
                bno = be32_to_cpu(node->btree[0].before);
994
991
 
995
992
                libxfs_putbuf(bp);
996
993
 
1042
1039
         * that all entries are used, encountered and expected hashvals
1043
1040
         * match, etc.
1044
1041
         */
1045
 
        if (entry != INT_GET(node->hdr.count, ARCH_CONVERT) - 1)  {
 
1042
        if (entry != be16_to_cpu(node->hdr.count) - 1)  {
1046
1043
                do_warn(_("directory/attribute block used/count "
1047
1044
                          "inconsistency - %d/%hu\n"),
1048
 
                        entry, INT_GET(node->hdr.count, ARCH_CONVERT));
 
1045
                        entry, be16_to_cpu(node->hdr.count));
1049
1046
                bad++;
1050
1047
        }
1051
1048
        /*
1052
1049
         * hash values monotonically increasing ???
1053
1050
         */
1054
 
        if (cursor->level[this_level].hashval >=
1055
 
            INT_GET(node->btree[entry].hashval, ARCH_CONVERT)) {
 
1051
        if (cursor->level[this_level].hashval >= 
 
1052
                                be32_to_cpu(node->btree[entry].hashval)) {
1056
1053
                do_warn(_("directory/attribute block hashvalue inconsistency, "
1057
1054
                          "expected > %u / saw %u\n"),
1058
1055
                        cursor->level[this_level].hashval,
1059
 
                        INT_GET(node->btree[entry].hashval, ARCH_CONVERT));
 
1056
                        be32_to_cpu(node->btree[entry].hashval));
1060
1057
                bad++;
1061
1058
        }
1062
 
        if (INT_GET(node->hdr.info.forw, ARCH_CONVERT) != 0)  {
 
1059
        if (be32_to_cpu(node->hdr.info.forw) != 0)  {
1063
1060
                do_warn(_("bad directory/attribute forward block pointer, "
1064
1061
                          "expected 0, saw %u\n"),
1065
 
                        INT_GET(node->hdr.info.forw, ARCH_CONVERT));
 
1062
                        be32_to_cpu(node->hdr.info.forw));
1066
1063
                bad++;
1067
1064
        }
1068
1065
        if (bad) {
1080
1077
        /*
1081
1078
         * ok, now check descendant block number against this level
1082
1079
         */
1083
 
        if (cursor->level[p_level].bno !=
1084
 
            INT_GET(node->btree[entry].before, ARCH_CONVERT))  {
 
1080
        if (cursor->level[p_level].bno != be32_to_cpu(
 
1081
                                                node->btree[entry].before)) {
1085
1082
#ifdef XR_DIR_TRACE
1086
1083
                fprintf(stderr, "bad directory btree pointer, child bno should "
1087
1084
                                "be %d, block bno is %d, hashval is %u\n",
1088
 
                        INT_GET(node->btree[entry].before, ARCH_CONVERT),
 
1085
                        be16_to_cpu(node->btree[entry].before),
1089
1086
                        cursor->level[p_level].bno,
1090
1087
                        cursor->level[p_level].hashval);
1091
1088
                fprintf(stderr, "verify_final_da_path returns 1 (bad) #1a\n");
1093
1090
                return(1);
1094
1091
        }
1095
1092
 
1096
 
        if (cursor->level[p_level].hashval !=
1097
 
            INT_GET(node->btree[entry].hashval, ARCH_CONVERT)) {
 
1093
        if (cursor->level[p_level].hashval != be32_to_cpu(
 
1094
                                                node->btree[entry].hashval)) {
1098
1095
                if (!no_modify)  {
1099
1096
                        do_warn(_("correcting bad hashval in non-leaf "
1100
1097
                                  "dir/attr block\n\tin (level %d) in "
1101
1098
                                  "inode %llu.\n"),
1102
1099
                                this_level, cursor->ino);
1103
 
                        INT_SET(node->btree[entry].hashval, ARCH_CONVERT,
1104
 
                                cursor->level[p_level].hashval);
 
1100
                        node->btree[entry].hashval = cpu_to_be32(
 
1101
                                                cursor->level[p_level].hashval);
1105
1102
                        cursor->level[this_level].dirty++;
1106
1103
                } else  {
1107
1104
                        do_warn(_("would correct bad hashval in non-leaf "
1115
1112
         * Note: squirrel hashval away _before_ releasing the
1116
1113
         * buffer, preventing a use-after-free problem.
1117
1114
         */
1118
 
        hashval = INT_GET(node->btree[entry].hashval, ARCH_CONVERT);
 
1115
        hashval = be32_to_cpu(node->btree[entry].hashval);
1119
1116
 
1120
1117
        /*
1121
1118
         * release/write buffer
1212
1209
         * block and move on to the next block.
1213
1210
         * and update cursor value for said level
1214
1211
         */
1215
 
        if (entry >= INT_GET(node->hdr.count, ARCH_CONVERT))  {
 
1212
        if (entry >= be16_to_cpu(node->hdr.count))  {
1216
1213
                /*
1217
1214
                 * update the hash value for this level before
1218
1215
                 * validating it.  bno value should be ok since
1219
1216
                 * it was set when the block was first read in.
1220
1217
                 */
1221
1218
                cursor->level[this_level].hashval =
1222
 
                                INT_GET(node->btree[entry - 1].hashval, ARCH_CONVERT);
 
1219
                                be32_to_cpu(node->btree[entry - 1].hashval);
1223
1220
 
1224
1221
                /*
1225
1222
                 * keep track of greatest block # -- that gets
1237
1234
                /*
1238
1235
                 * ok, now get the next buffer and check sibling pointers
1239
1236
                 */
1240
 
                dabno = INT_GET(node->hdr.info.forw, ARCH_CONVERT);
 
1237
                dabno = be32_to_cpu(node->hdr.info.forw);
1241
1238
                ASSERT(dabno != 0);
1242
1239
                fsbno = blkmap_get(cursor->blkmap, dabno);
1243
1240
 
1263
1260
                 * entry count, verify level
1264
1261
                 */
1265
1262
                bad = 0;
1266
 
                if (XFS_DA_NODE_MAGIC !=
1267
 
                    INT_GET(newnode->hdr.info.magic, ARCH_CONVERT))  {
 
1263
                if (XFS_DA_NODE_MAGIC != be16_to_cpu(newnode->hdr.info.magic)) {
1268
1264
                        do_warn(_("bad magic number %x in block %u (%llu) "
1269
1265
                                  "for directory inode %llu\n"),
1270
 
                                INT_GET(newnode->hdr.info.magic, ARCH_CONVERT),
 
1266
                                be16_to_cpu(newnode->hdr.info.magic),
1271
1267
                                dabno, fsbno, cursor->ino);
1272
1268
                        bad++;
1273
1269
                }
1274
 
                if (INT_GET(newnode->hdr.info.back, ARCH_CONVERT) !=
1275
 
                    cursor->level[this_level].bno)  {
 
1270
                if (be32_to_cpu(newnode->hdr.info.back) != 
 
1271
                                                cursor->level[this_level].bno) {
1276
1272
                        do_warn(_("bad back pointer in block %u (%llu) "
1277
1273
                                  "for directory inode %llu\n"),
1278
1274
                                dabno, fsbno, cursor->ino);
1279
1275
                        bad++;
1280
1276
                }
1281
 
                if (INT_GET(newnode->hdr.count, ARCH_CONVERT) >
1282
 
                    mp->m_dir_node_ents)  {
 
1277
                if (be16_to_cpu(newnode->hdr.count) > mp->m_dir_node_ents) {
1283
1278
                        do_warn(_("entry count %d too large in block %u (%llu) "
1284
1279
                                  "for directory inode %llu\n"),
1285
 
                                INT_GET(newnode->hdr.count, ARCH_CONVERT),
 
1280
                                be16_to_cpu(newnode->hdr.count),
1286
1281
                                dabno, fsbno, cursor->ino);
1287
1282
                        bad++;
1288
1283
                }
1289
 
                if (INT_GET(newnode->hdr.level, ARCH_CONVERT) != this_level)  {
 
1284
                if (be16_to_cpu(newnode->hdr.level) != this_level) {
1290
1285
                        do_warn(_("bad level %d in block %u (%llu) "
1291
1286
                                  "for directory inode %llu\n"),
1292
 
                                INT_GET(newnode->hdr.level, ARCH_CONVERT),
 
1287
                                be16_to_cpu(newnode->hdr.level),
1293
1288
                                dabno, fsbno, cursor->ino);
1294
1289
                        bad++;
1295
1290
                }
1315
1310
                cursor->level[this_level].dirty = 0;
1316
1311
                cursor->level[this_level].bno = dabno;
1317
1312
                cursor->level[this_level].hashval =
1318
 
                        INT_GET(newnode->btree[0].hashval, ARCH_CONVERT);
 
1313
                                        be32_to_cpu(newnode->btree[0].hashval);
1319
1314
#ifdef XR_DIR_TRACE
1320
1315
                cursor->level[this_level].n = newnode;
1321
1316
#endif
1327
1322
         * ditto for block numbers
1328
1323
         */
1329
1324
        if (cursor->level[p_level].bno !=
1330
 
                        INT_GET(node->btree[entry].before, ARCH_CONVERT))  {
 
1325
                                be32_to_cpu(node->btree[entry].before))  {
1331
1326
#ifdef XR_DIR_TRACE
1332
1327
                fprintf(stderr, "bad directory btree pointer, child bno "
1333
1328
                        "should be %d, block bno is %d, hashval is %u\n",
1334
 
                        INT_GET(node->btree[entry].before, ARCH_CONVERT),
 
1329
                        be32_to_cpu(node->btree[entry].before),
1335
1330
                        cursor->level[p_level].bno,
1336
1331
                        cursor->level[p_level].hashval);
1337
1332
                fprintf(stderr, "verify_da_path returns 1 (bad) #1a\n");
1343
1338
         * block against the hashval in the current entry
1344
1339
         */
1345
1340
        if (cursor->level[p_level].hashval !=
1346
 
                        INT_GET(node->btree[entry].hashval, ARCH_CONVERT))  {
 
1341
                                be32_to_cpu(node->btree[entry].hashval))  {
1347
1342
                if (!no_modify)  {
1348
1343
                        do_warn(_("correcting bad hashval in interior "
1349
1344
                                  "dir/attr block\n\tin (level %d) in "
1350
1345
                                  "inode %llu.\n"),
1351
1346
                                this_level, cursor->ino);
1352
 
                        INT_SET(node->btree[entry].hashval, ARCH_CONVERT,
1353
 
                                cursor->level[p_level].hashval);
 
1347
                        node->btree[entry].hashval = cpu_to_be32(
 
1348
                                                cursor->level[p_level].hashval);
1354
1349
                        cursor->level[this_level].dirty++;
1355
1350
                } else  {
1356
1351
                        do_warn(_("would correct bad hashval in interior "
1370
1365
        return(0);
1371
1366
}
1372
1367
 
1373
 
#if 0
1374
 
/*
1375
 
 * handles junking directory leaf block entries that have zero lengths
1376
 
 * buf_dirty is an in/out, set to 1 if the leaf was modified.
1377
 
 * we do NOT initialize it to zero if nothing happened because it
1378
 
 * may be already set by the caller.  Assumes that the block
1379
 
 * has been compacted before calling this routine.
1380
 
 */
1381
 
void
1382
 
junk_zerolen_dir_leaf_entries(
1383
 
        xfs_mount_t             *mp,
1384
 
        xfs_dir_leafblock_t     *leaf,
1385
 
        xfs_ino_t               ino,
1386
 
        int                     *buf_dirty)
1387
 
{
1388
 
        xfs_dir_leaf_entry_t    *entry;
1389
 
        xfs_dir_leaf_name_t     *namest;
1390
 
        xfs_dir_leaf_hdr_t      *hdr;
1391
 
        xfs_dir_leaf_map_t      *map;
1392
 
        xfs_ino_t               tmp_ino;
1393
 
        int                     bytes;
1394
 
        int                     tmp_bytes;
1395
 
        int                     current_hole = 0;
1396
 
        int                     i;
1397
 
        int                     j;
1398
 
        int                     tmp;
1399
 
        int                     start;
1400
 
        int                     before;
1401
 
        int                     after;
1402
 
        int                     smallest;
1403
 
        int                     tablesize;
1404
 
 
1405
 
        entry = &leaf->entries[0];
1406
 
        hdr = &leaf->hdr;
1407
 
 
1408
 
        /*
1409
 
         * we can convert the entries to one character entries
1410
 
         * as long as we have space.  Once we run out, then
1411
 
         * we have to delete really delete (copy over) an entry.
1412
 
         * however, that frees up some space that we could use ...
1413
 
         *
1414
 
         * so the idea is, we'll use up space from all the holes,
1415
 
         * potentially leaving each hole too small to do any good.
1416
 
         * then if need to, we'll delete entries and use that space
1417
 
         * up from the top-most byte down.  that may leave a 4th hole
1418
 
         * but we can represent that by correctly setting the value
1419
 
         * of firstused.  that leaves any hole between the end of
1420
 
         * the entry list and firstused so it doesn't have to be
1421
 
         * recorded in the hole map.
1422
 
         */
1423
 
 
1424
 
        for (bytes = i = 0; i < INT_GET(hdr->count, ARCH_CONVERT); entry++, i++) {
1425
 
                /*
1426
 
                 * skip over entries that are good or already converted
1427
 
                 */
1428
 
                if (entry->namelen != 0)
1429
 
                        continue;
1430
 
 
1431
 
                *buf_dirty = 1;
1432
 
#if 0
1433
 
                /*
1434
 
                 * try and use up existing holes first until they get
1435
 
                 * too small, then set bytes to the # of bytes between
1436
 
                 * the current heap beginning and the last used byte
1437
 
                 * in the entry table.
1438
 
                 */
1439
 
                if (bytes < sizeof(xfs_dir_leaf_name_t) &&
1440
 
                                current_hole < XFS_DIR_LEAF_MAPSIZE)  {
1441
 
                        /*
1442
 
                         * skip over holes that are too small
1443
 
                         */
1444
 
                        while (current_hole < XFS_DIR_LEAF_MAPSIZE &&
1445
 
                                INT_GET(hdr->freemap[current_hole].size, ARCH_CONVERT) <
1446
 
                                        sizeof(xfs_dir_leaf_name_t))  {
1447
 
                                current_hole++;
1448
 
                        }
1449
 
 
1450
 
                        if (current_hole < XFS_DIR_LEAF_MAPSIZE)
1451
 
                                bytes = INT_GET(hdr->freemap[current_hole].size, ARCH_CONVERT);
1452
 
                        else
1453
 
                                bytes = (int) INT_GET(hdr->firstused, ARCH_CONVERT) -
1454
 
                                 ((__psint_t) &leaf->entries[INT_GET(hdr->count, ARCH_CONVERT)] -
1455
 
                                  (__psint_t) leaf);
1456
 
                }
1457
 
#endif
1458
 
                current_hole = 0;
1459
 
 
1460
 
                for (map = &hdr->freemap[0];
1461
 
                                current_hole < XFS_DIR_LEAF_MAPSIZE &&
1462
 
                                        INT_GET(map->size, ARCH_CONVERT) < sizeof(xfs_dir_leaf_name_t);
1463
 
                                map++)  {
1464
 
                        current_hole++;
1465
 
                }
1466
 
 
1467
 
                /*
1468
 
                 * if we can use an existing hole, do it.  otherwise,
1469
 
                 * delete entries until the deletions create a big enough
1470
 
                 * hole to convert another entry.  then use up those bytes
1471
 
                 * bytes until you run low.  then delete entries again ...
1472
 
                 */
1473
 
                if (current_hole < XFS_DIR_LEAF_MAPSIZE)  {
1474
 
                        ASSERT(sizeof(xfs_dir_leaf_name_t) <= bytes);
1475
 
 
1476
 
                        do_warn(_("marking bad entry in directory inode %llu\n"),
1477
 
                                ino);
1478
 
 
1479
 
                        entry->namelen = 1;
1480
 
                        INT_SET(entry->nameidx, ARCH_CONVERT, INT_GET(hdr->freemap[current_hole].base, ARCH_CONVERT) +
1481
 
                                        bytes - sizeof(xfs_dir_leaf_name_t));
1482
 
 
1483
 
                        namest = XFS_DIR_LEAF_NAMESTRUCT(leaf, INT_GET(entry->nameidx, ARCH_CONVERT));
1484
 
                        tmp_ino = NULLFSINO;
1485
 
                        XFS_DIR_SF_PUT_DIRINO(&tmp_ino, &namest->inumber);
1486
 
                        namest->name[0] = '/';
1487
 
 
1488
 
                        if (INT_GET(entry->nameidx, ARCH_CONVERT) < INT_GET(hdr->firstused, ARCH_CONVERT))
1489
 
                                INT_SET(hdr->firstused, ARCH_CONVERT, INT_GET(entry->nameidx, ARCH_CONVERT));
1490
 
                        INT_MOD(hdr->freemap[current_hole].size, ARCH_CONVERT, -(sizeof(xfs_dir_leaf_name_t)));
1491
 
                        INT_MOD(hdr->namebytes, ARCH_CONVERT, +1);
1492
 
                } else  {
1493
 
                        /*
1494
 
                         * delete the table entry and try and account for the
1495
 
                         * space in the holemap.  don't have to update namebytes
1496
 
                         * or firstused since we're not actually deleting any
1497
 
                         * bytes from the heap.  following code swiped from
1498
 
                         * xfs_dir_leaf_remove() in xfs_dir_leaf.c
1499
 
                         */
1500
 
                        INT_MOD(hdr->count, ARCH_CONVERT, -1);
1501
 
                        do_warn(
1502
 
                _("deleting zero length entry in directory inode %llu\n"),
1503
 
                                ino);
1504
 
                        /*
1505
 
                         * overwrite the bad entry unless it's the
1506
 
                         * last entry in the list (highly unlikely).
1507
 
                         * zero out the free'd bytes.
1508
 
                         */
1509
 
                        if (INT_GET(hdr->count, ARCH_CONVERT) - i > 0)  {
1510
 
                                memmove(entry, entry + 1, (INT_GET(hdr->count, ARCH_CONVERT) - i) *
1511
 
                                        sizeof(xfs_dir_leaf_entry_t));
1512
 
                        }
1513
 
                        memset((void *) ((__psint_t) entry +
1514
 
                                (INT_GET(leaf->hdr.count, ARCH_CONVERT) - i - 1) *
1515
 
                                sizeof(xfs_dir_leaf_entry_t)), 0,
1516
 
                                sizeof(xfs_dir_leaf_entry_t));
1517
 
 
1518
 
                        start = (__psint_t) &leaf->entries[INT_GET(hdr->count, ARCH_CONVERT)] -
1519
 
                                (__psint_t) &leaf;
1520
 
                        tablesize = sizeof(xfs_dir_leaf_entry_t) *
1521
 
                                (INT_GET(hdr->count, ARCH_CONVERT) + 1) + sizeof(xfs_dir_leaf_hdr_t);
1522
 
                        map = &hdr->freemap[0];
1523
 
                        tmp = INT_GET(map->size, ARCH_CONVERT);
1524
 
                        before = after = -1;
1525
 
                        smallest = XFS_DIR_LEAF_MAPSIZE - 1;
1526
 
                        for (j = 0; j < XFS_DIR_LEAF_MAPSIZE; map++, j++) {
1527
 
                                ASSERT(INT_GET(map->base, ARCH_CONVERT) < XFS_LBSIZE(mp));
1528
 
                                ASSERT(INT_GET(map->size, ARCH_CONVERT) < XFS_LBSIZE(mp));
1529
 
                                if (INT_GET(map->base, ARCH_CONVERT) == tablesize) {
1530
 
                                        INT_MOD(map->base, ARCH_CONVERT, -(sizeof(xfs_dir_leaf_entry_t)));
1531
 
                                        INT_MOD(map->size, ARCH_CONVERT, sizeof(xfs_dir_leaf_entry_t));
1532
 
                                }
1533
 
 
1534
 
                                if ((INT_GET(map->base, ARCH_CONVERT) + INT_GET(map->size, ARCH_CONVERT)) == start) {
1535
 
                                        before = j;
1536
 
                                } else if (INT_GET(map->base, ARCH_CONVERT) == start +
1537
 
                                                sizeof(xfs_dir_leaf_entry_t))  {
1538
 
                                        after = j;
1539
 
                                } else if (INT_GET(map->size, ARCH_CONVERT) < tmp) {
1540
 
                                        tmp = INT_GET(map->size, ARCH_CONVERT);
1541
 
                                        smallest = j;
1542
 
                                }
1543
 
                        }
1544
 
 
1545
 
                        /*
1546
 
                         * Coalesce adjacent freemap regions,
1547
 
                         * or replace the smallest region.
1548
 
                         */
1549
 
                        if ((before >= 0) || (after >= 0)) {
1550
 
                                if ((before >= 0) && (after >= 0))  {
1551
 
                                        map = &hdr->freemap[before];
1552
 
                                        INT_MOD(map->size, ARCH_CONVERT, sizeof(xfs_dir_leaf_entry_t));
1553
 
                                        INT_MOD(map->size, ARCH_CONVERT, INT_GET(hdr->freemap[after].size, ARCH_CONVERT));
1554
 
                                        hdr->freemap[after].base = 0;
1555
 
                                        hdr->freemap[after].size = 0;
1556
 
                                } else if (before >= 0) {
1557
 
                                        map = &hdr->freemap[before];
1558
 
                                        INT_MOD(map->size, ARCH_CONVERT, sizeof(xfs_dir_leaf_entry_t));
1559
 
                                } else {
1560
 
                                        map = &hdr->freemap[after];
1561
 
                                        INT_SET(map->base, ARCH_CONVERT, start);
1562
 
                                        INT_MOD(map->size, ARCH_CONVERT, sizeof(xfs_dir_leaf_entry_t));
1563
 
                                }
1564
 
                        } else  {
1565
 
                                /*
1566
 
                                 * Replace smallest region
1567
 
                                 * (if it is smaller than free'd entry)
1568
 
                                 */
1569
 
                                map = &hdr->freemap[smallest];
1570
 
                                if (INT_GET(map->size, ARCH_CONVERT) < sizeof(xfs_dir_leaf_entry_t))  {
1571
 
                                        INT_SET(map->base, ARCH_CONVERT, start);
1572
 
                                        INT_SET(map->size, ARCH_CONVERT, sizeof(xfs_dir_leaf_entry_t));
1573
 
                                }
1574
 
                                /*
1575
 
                                 * mark as needing compaction
1576
 
                                 */
1577
 
                                hdr->holes = 1;
1578
 
                        }
1579
 
#if 0
1580
 
                        /*
1581
 
                         * do we have to delete stuff or is there
1582
 
                         * room for deletions?
1583
 
                         */
1584
 
                        ASSERT(current_hole == XFS_DIR_LEAF_MAPSIZE);
1585
 
 
1586
 
                        /*
1587
 
                         * here, bytes == number of unused bytes from
1588
 
                         * end of list to top (beginning) of heap
1589
 
                         * (firstused).  It's ok to leave extra
1590
 
                         * unused bytes in that region because they
1591
 
                         * wind up before firstused (which we reset
1592
 
                         * appropriately
1593
 
                         */
1594
 
                        if (bytes < sizeof(xfs_dir_leaf_name_t))  {
1595
 
                                /*
1596
 
                                 * have to delete an entry because
1597
 
                                 * we have no room to convert it to
1598
 
                                 * a bad entry
1599
 
                                 */
1600
 
                                do_warn(
1601
 
                                _("deleting entry in directory inode %llu\n"),
1602
 
                                        ino);
1603
 
                                /*
1604
 
                                 * overwrite the bad entry unless it's the
1605
 
                                 * last entry in the list (highly unlikely).
1606
 
                                 */
1607
 
                                if (INT_GET(leaf->hdr.count, ARCH_CONVERT) - i - 1> 0)  {
1608
 
                                        memmove(entry, entry + 1,
1609
 
                                                (INT_GET(leaf->hdr.count, ARCH_CONVERT) - i - 1) *
1610
 
                                                sizeof(xfs_dir_leaf_entry_t));
1611
 
                                }
1612
 
                                memset((void *) ((__psint_t) entry +
1613
 
                                        (INT_GET(leaf->hdr.count, ARCH_CONVERT) - i - 1) *
1614
 
                                        sizeof(xfs_dir_leaf_entry_t)), 0,
1615
 
                                        sizeof(xfs_dir_leaf_entry_t));
1616
 
 
1617
 
                                /*
1618
 
                                 * bump up free byte count, drop other
1619
 
                                 * index vars since the table just
1620
 
                                 * shrank by one entry and we don't
1621
 
                                 * want to miss any as we walk the table
1622
 
                                 */
1623
 
                                bytes += sizeof(xfs_dir_leaf_entry_t);
1624
 
                                INT_MOD(leaf->hdr.count, ARCH_CONVERT, -1);
1625
 
                                entry--;
1626
 
                                i--;
1627
 
                        } else  {
1628
 
                                /*
1629
 
                                 * convert entry using the bytes in between
1630
 
                                 * the end of the entry table and the heap
1631
 
                                 */
1632
 
                                entry->namelen = 1;
1633
 
                                INT_MOD(leaf->hdr.firstused, ARCH_CONVERT, -(sizeof(xfs_dir_leaf_name_t)));
1634
 
                                INT_SET(entry->nameidx, ARCH_CONVERT, INT_GET(leaf->hdr.firstused, ARCH_CONVERT));
1635
 
 
1636
 
                                namest = XFS_DIR_LEAF_NAMESTRUCT(leaf,
1637
 
                                                        INT_GET(entry->nameidx, ARCH_CONVERT));
1638
 
                                tmp_ino = NULLFSINO;
1639
 
                                XFS_DIR_SF_PUT_DIRINO(&tmp_ino,
1640
 
                                                        &namest->inumber);
1641
 
                                namest->name[0] = '/';
1642
 
 
1643
 
                                bytes -= sizeof(xfs_dir_leaf_entry_t);
1644
 
                        }
1645
 
#endif
1646
 
                }
1647
 
        }
1648
 
 
1649
 
        return;
1650
 
}
1651
 
#endif
1652
 
 
1653
1368
size_t ts_dirbuf_size = 64*1024;
1654
1369
 
1655
1370
/*
1759
1474
         * inodes on a later pass.
1760
1475
         */
1761
1476
        for (i = 0, entry = &leaf->entries[0];
1762
 
                        i < INT_GET(leaf->hdr.count, ARCH_CONVERT);
 
1477
                        i < be16_to_cpu(leaf->hdr.count);
1763
1478
                        i++, entry++)  {
1764
1479
                /*
1765
1480
                 * check that the name index isn't out of bounds
1766
1481
                 * if it is, delete the entry since we can't
1767
1482
                 * grab the inode #.
1768
1483
                 */
1769
 
                if (INT_GET(entry->nameidx, ARCH_CONVERT) >=
 
1484
                if (be16_to_cpu(entry->nameidx) >=
1770
1485
                    mp->m_sb.sb_blocksize)  {
1771
1486
                        if (!no_modify)  {
1772
1487
                                *buf_dirty = 1;
1773
1488
 
1774
 
                                if (INT_GET(leaf->hdr.count, ARCH_CONVERT) > 1)  {
 
1489
                                if (be16_to_cpu(leaf->hdr.count) > 1)  {
1775
1490
                                        do_warn(
1776
1491
_("nameidx %d for entry #%d, bno %d, ino %llu > fs blocksize, deleting entry\n"),
1777
 
                                                INT_GET(entry->nameidx,
1778
 
                                                        ARCH_CONVERT),
 
1492
                                                be16_to_cpu(entry->nameidx),
1779
1493
                                                i, da_bno, ino);
1780
 
                                        ASSERT(INT_GET(leaf->hdr.count,
1781
 
                                                        ARCH_CONVERT) > i);
 
1494
                                        ASSERT(be16_to_cpu(leaf->hdr.count) > i);
1782
1495
 
1783
 
                                        bytes = (INT_GET(leaf->hdr.count,
1784
 
                                                        ARCH_CONVERT) - i) *
 
1496
                                        bytes = (be16_to_cpu(leaf->hdr.count) - i) *
1785
1497
                                                sizeof(xfs_dir_leaf_entry_t);
1786
1498
 
1787
1499
                                        /*
1808
1520
                                         * map since we haven't set it for
1809
1521
                                         * this entry yet.
1810
1522
                                         */
1811
 
                                        INT_MOD(leaf->hdr.count, ARCH_CONVERT, -1);
 
1523
                                        be16_add_cpu(&leaf->hdr.count, -1);
1812
1524
                                        i--;
1813
1525
                                        entry--;
1814
1526
                                } else  {
1815
1527
                                        do_warn(
1816
1528
_("nameidx %d, entry #%d, bno %d, ino %llu > fs blocksize, marking entry bad\n"),
1817
 
                                                INT_GET(entry->nameidx,
1818
 
                                                        ARCH_CONVERT),
 
1529
                                                be16_to_cpu(entry->nameidx),
1819
1530
                                                i, da_bno, ino);
1820
 
                                        INT_SET(entry->nameidx, ARCH_CONVERT,
 
1531
                                        entry->nameidx = cpu_to_be16(
1821
1532
                                                mp->m_sb.sb_blocksize -
1822
1533
                                                sizeof(xfs_dir_leaf_name_t));
1823
 
                                        namest = XFS_DIR_LEAF_NAMESTRUCT(leaf,
1824
 
                                                        INT_GET(entry->nameidx,
1825
 
                                                                ARCH_CONVERT));
 
1534
                                        namest = xfs_dir_leaf_namestruct(leaf,
 
1535
                                                be16_to_cpu(entry->nameidx));
1826
1536
                                        lino = NULLFSINO;
1827
 
                                        XFS_DIR_SF_PUT_DIRINO(&lino,
 
1537
                                        xfs_dir_sf_put_dirino(&lino,
1828
1538
                                                        &namest->inumber);
1829
1539
                                        namest->name[0] = '/';
1830
1540
                                }
1831
1541
                        } else  {
1832
1542
                                do_warn(
1833
1543
_("nameidx %d, entry #%d, bno %d, ino %llu > fs blocksize, would delete entry\n"),
1834
 
                                        INT_GET(entry->nameidx, ARCH_CONVERT),
 
1544
                                        be16_to_cpu(entry->nameidx),
1835
1545
                                        i, da_bno, ino);
1836
1546
                        }
1837
1547
                        continue;
1843
1553
                 * we can still try for the inode as long as nameidx
1844
1554
                 * is ok.
1845
1555
                 */
1846
 
                namest = XFS_DIR_LEAF_NAMESTRUCT(leaf,
1847
 
                                INT_GET(entry->nameidx, ARCH_CONVERT));
1848
 
                XFS_DIR_SF_GET_DIRINO(&namest->inumber, &lino);
 
1556
                namest = xfs_dir_leaf_namestruct(leaf, 
 
1557
                                                be16_to_cpu(entry->nameidx));
 
1558
                xfs_dir_sf_get_dirino(&namest->inumber, &lino);
1849
1559
 
1850
1560
                /*
1851
1561
                 * we may have to blow out an entry because of bad
1874
1584
                                _("\tclearing ino number in entry %d...\n"),
1875
1585
                                        i);
1876
1586
                                lino = NULLFSINO;
1877
 
                                XFS_DIR_SF_PUT_DIRINO(&lino, &namest->inumber);
 
1587
                                xfs_dir_sf_put_dirino(&lino, &namest->inumber);
1878
1588
                                *buf_dirty = 1;
1879
1589
                        } else  {
1880
1590
                                do_warn(
1891
1601
                                        i);
1892
1602
 
1893
1603
                                lino = NULLFSINO;
1894
 
                                XFS_DIR_SF_PUT_DIRINO(&lino, &namest->inumber);
 
1604
                                xfs_dir_sf_put_dirino(&lino, &namest->inumber);
1895
1605
                                *buf_dirty = 1;
1896
1606
                        } else  {
1897
1607
                                do_warn(
1907
1617
                                _("\tclearing ino number in entry %d...\n"), i);
1908
1618
 
1909
1619
                                lino = NULLFSINO;
1910
 
                                XFS_DIR_SF_PUT_DIRINO(&lino, &namest->inumber);
 
1620
                                xfs_dir_sf_put_dirino(&lino, &namest->inumber);
1911
1621
                                *buf_dirty = 1;
1912
1622
                        } else  {
1913
1623
                                do_warn(
1924
1634
                                        i);
1925
1635
 
1926
1636
                                lino = NULLFSINO;
1927
 
                                XFS_DIR_SF_PUT_DIRINO(&lino, &namest->inumber);
 
1637
                                xfs_dir_sf_put_dirino(&lino, &namest->inumber);
1928
1638
                                *buf_dirty = 1;
1929
1639
                        } else  {
1930
1640
                                do_warn(
1941
1651
                                        i);
1942
1652
 
1943
1653
                                lino = NULLFSINO;
1944
 
                                XFS_DIR_SF_PUT_DIRINO(&lino, &namest->inumber);
 
1654
                                xfs_dir_sf_put_dirino(&lino, &namest->inumber);
1945
1655
                                *buf_dirty = 1;
1946
1656
                        } else  {
1947
1657
                                do_warn(
1973
1683
_("entry references free inode %llu in directory %llu, will clear entry\n"),
1974
1684
                                                lino, ino);
1975
1685
                                        lino = NULLFSINO;
1976
 
                                        XFS_DIR_SF_PUT_DIRINO(&lino,
 
1686
                                        xfs_dir_sf_put_dirino(&lino,
1977
1687
                                                        &namest->inumber);
1978
1688
                                        *buf_dirty = 1;
1979
1689
                                } else  {
1991
1701
                        if (!no_modify)  {
1992
1702
                                do_warn(_("clearing inode number...\n"));
1993
1703
                                lino = NULLFSINO;
1994
 
                                XFS_DIR_SF_PUT_DIRINO(&lino, &namest->inumber);
 
1704
                                xfs_dir_sf_put_dirino(&lino, &namest->inumber);
1995
1705
                                *buf_dirty = 1;
1996
1706
                        } else  {
1997
1707
                                do_warn(_("would clear inode number...\n"));
2012
1722
                if (entry->namelen == 0)  {
2013
1723
                        *buf_dirty = 1;
2014
1724
 
2015
 
                        if (INT_GET(leaf->hdr.count, ARCH_CONVERT) > 1)  {
 
1725
                        if (be16_to_cpu(leaf->hdr.count) > 1)  {
2016
1726
                                do_warn(
2017
1727
        _("entry #%d, dir inode %llu, has zero-len name, deleting entry\n"),
2018
1728
                                        i, ino);
2019
 
                                ASSERT(INT_GET(leaf->hdr.count, ARCH_CONVERT) > i);
 
1729
                                ASSERT(be16_to_cpu(leaf->hdr.count) > i);
2020
1730
 
2021
 
                                bytes = (INT_GET(leaf->hdr.count,
2022
 
                                                ARCH_CONVERT) - i) *
2023
 
                                        sizeof(xfs_dir_leaf_entry_t);
 
1731
                                bytes = (be16_to_cpu(leaf->hdr.count) - i) *
 
1732
                                                sizeof(xfs_dir_leaf_entry_t);
2024
1733
 
2025
1734
                                /*
2026
1735
                                 * compress table unless we're
2030
1739
                                 */
2031
1740
                                if (bytes > sizeof(xfs_dir_leaf_entry_t))  {
2032
1741
                                        memmove(entry, entry + 1, bytes);
2033
 
                                        memset((void *)
2034
 
                                                ((__psint_t) entry + bytes), 0,
 
1742
                                        memset((void *)((__psint_t) entry + 
 
1743
                                                        bytes), 0,
2035
1744
                                                sizeof(xfs_dir_leaf_entry_t));
2036
1745
                                } else  {
2037
1746
                                        memset(entry, 0,
2044
1753
                                 * map since we haven't set it for
2045
1754
                                 * this entry yet.
2046
1755
                                 */
2047
 
                                INT_MOD(leaf->hdr.count, ARCH_CONVERT, -1);
 
1756
                                be16_add_cpu(&leaf->hdr.count, -1);
2048
1757
                                i--;
2049
1758
                                entry--;
2050
1759
                        } else  {
2055
1764
                                do_warn(
2056
1765
        _("entry #%d, dir inode %llu, has zero-len name, marking entry bad\n"),
2057
1766
                                        i, ino);
2058
 
                                INT_SET(entry->nameidx, ARCH_CONVERT,
2059
 
                                        mp->m_sb.sb_blocksize -
 
1767
                                entry->nameidx = cpu_to_be16(
 
1768
                                                mp->m_sb.sb_blocksize -
2060
1769
                                                sizeof(xfs_dir_leaf_name_t));
2061
 
                                namest = XFS_DIR_LEAF_NAMESTRUCT(leaf,
2062
 
                                                INT_GET(entry->nameidx,
2063
 
                                                        ARCH_CONVERT));
2064
 
                                XFS_DIR_SF_PUT_DIRINO(&lino, &namest->inumber);
 
1770
                                namest = xfs_dir_leaf_namestruct(leaf,
 
1771
                                                be16_to_cpu(entry->nameidx));
 
1772
                                xfs_dir_sf_put_dirino(&lino, &namest->inumber);
2065
1773
                                namest->name[0] = '/';
2066
1774
                        }
2067
 
                } else if (INT_GET(entry->nameidx, ARCH_CONVERT) +
2068
 
                                        entry->namelen > XFS_LBSIZE(mp))  {
 
1775
                } else if (be16_to_cpu(entry->nameidx) + entry->namelen > 
 
1776
                                                        XFS_LBSIZE(mp))  {
2069
1777
                        do_warn(
2070
1778
_("bad size, entry #%d in dir inode %llu, block %u -- entry overflows block\n"),
2071
1779
                                i, ino, da_bno);
2127
1835
                                        fname, ino);
2128
1836
                        }
2129
1837
                } else if (!nm_illegal &&
2130
 
                           INT_GET(entry->hashval, ARCH_CONVERT) != hashval)  {
 
1838
                                be32_to_cpu(entry->hashval) != hashval) {
2131
1839
                        /*
2132
1840
                         * try resetting the hashvalue to the correct
2133
1841
                         * value for the string, if the string has been
2139
1847
                                do_warn(
2140
1848
                _("\t\tin directory inode %llu.  resetting hash value.\n"),
2141
1849
                                        ino);
2142
 
                                INT_SET(entry->hashval, ARCH_CONVERT, hashval);
 
1850
                                entry->hashval = cpu_to_be32(hashval);
2143
1851
                                *buf_dirty = 1;
2144
1852
                        } else  {
2145
1853
                                do_warn(
2161
1869
                 * marked for deletion, the hash value ordering must
2162
1870
                 * be maintained.
2163
1871
                 */
2164
 
                if (INT_GET(entry->hashval, ARCH_CONVERT) < last_hashval)  {
 
1872
                if (be32_to_cpu(entry->hashval) < last_hashval)  {
2165
1873
                        /*
2166
1874
                         * blow out the entry -- set hashval to sane value
2167
1875
                         * and set the first character in the string to
2179
1887
                                do_warn(
2180
1888
                        _("\t\tin directory inode %llu.  will clear entry\n"),
2181
1889
                                        ino);
2182
 
                                INT_SET(entry->hashval, ARCH_CONVERT,
2183
 
                                        last_hashval);
 
1890
                                entry->hashval = cpu_to_be32(last_hashval);
2184
1891
                                namest->name[0] = '/';
2185
1892
                                *buf_dirty = 1;
2186
1893
                        } else  {
2190
1897
                        }
2191
1898
                }
2192
1899
 
2193
 
                *next_hashval = last_hashval = INT_GET(entry->hashval, ARCH_CONVERT);
 
1900
                *next_hashval = last_hashval = be32_to_cpu(entry->hashval);
2194
1901
 
2195
1902
                /*
2196
1903
                 * if heap data conflicts with something,
2197
1904
                 * blow it out and skip the rest of the loop
2198
1905
                 */
2199
 
                if (set_da_freemap(mp, dir_freemap,
2200
 
                                INT_GET(entry->nameidx, ARCH_CONVERT),
2201
 
                                INT_GET(entry->nameidx, ARCH_CONVERT)
2202
 
                                + sizeof(xfs_dir_leaf_name_t)
2203
 
                                + entry->namelen - 1))  {
 
1906
                if (set_da_freemap(mp, dir_freemap, be16_to_cpu(entry->nameidx),
 
1907
                                be16_to_cpu(entry->nameidx)
 
1908
                                        + sizeof(xfs_dir_leaf_name_t)
 
1909
                                        + entry->namelen - 1))  {
2204
1910
                        do_warn(
2205
1911
_("name \"%s\" (block %u, slot %d) conflicts with used space in dir inode %llu\n"),
2206
1912
                                fname, da_bno, i, ino);
2222
1928
                /*
2223
1929
                 * keep track of heap stats (first byte used, total bytes used)
2224
1930
                 */
2225
 
                if (INT_GET(entry->nameidx, ARCH_CONVERT) < first_used)
2226
 
                        first_used = INT_GET(entry->nameidx, ARCH_CONVERT);
 
1931
                if (be16_to_cpu(entry->nameidx) < first_used)
 
1932
                        first_used = be16_to_cpu(entry->nameidx);
2227
1933
                bytes_used += entry->namelen;
2228
1934
 
2229
1935
                /*
2270
1976
                                                do_warn(
2271
1977
                _("correcting .. entry in root inode %llu, was %llu\n"),
2272
1978
                                                        ino, *parent);
2273
 
                                                XFS_DIR_SF_PUT_DIRINO(
 
1979
                                                xfs_dir_sf_put_dirino(
2274
1980
                                                        &ino, &namest->inumber);
2275
1981
                                                *buf_dirty = 1;
2276
1982
                                        } else  {
2313
2019
                                                do_warn(
2314
2020
_(". in directory inode %llu has wrong value (%llu), fixing entry...\n"),
2315
2021
                                                        ino, lino);
2316
 
                                                XFS_DIR_SF_PUT_DIRINO(&ino,
 
2022
                                                xfs_dir_sf_put_dirino(&ino,
2317
2023
                                                        &namest->inumber);
2318
2024
                                                *buf_dirty = 1;
2319
2025
                                        } else  {
2366
2072
         * pointing to used bytes.  we're being conservative here
2367
2073
         * since the block will get compacted anyhow by the kernel.
2368
2074
         */
2369
 
        if ((leaf->hdr.holes == 0 &&
2370
 
             first_used != INT_GET(leaf->hdr.firstused, ARCH_CONVERT)) ||
2371
 
            INT_GET(leaf->hdr.firstused, ARCH_CONVERT) > first_used)  {
 
2075
        if ((leaf->hdr.holes == 0 && 
 
2076
                        first_used != be16_to_cpu(leaf->hdr.firstused)) ||
 
2077
                        be16_to_cpu(leaf->hdr.firstused) > first_used)  {
2372
2078
                if (!no_modify)  {
2373
2079
                        if (verbose)
2374
2080
                                do_warn(
2375
2081
_("- resetting first used heap value from %d to %d in block %u of dir ino %llu\n"),
2376
 
                                        (int) INT_GET(leaf->hdr.firstused,
2377
 
                                                ARCH_CONVERT),
 
2082
                                        be16_to_cpu(leaf->hdr.firstused),
2378
2083
                                        first_used, da_bno, ino);
2379
 
                        INT_SET(leaf->hdr.firstused, ARCH_CONVERT, first_used);
 
2084
                        leaf->hdr.firstused = cpu_to_be16(first_used);
2380
2085
                        *buf_dirty = 1;
2381
2086
                } else  {
2382
2087
                        if (verbose)
2383
2088
                                do_warn(
2384
2089
_("- would reset first used value from %d to %d in block %u of dir ino %llu\n"),
2385
 
                                        (int) INT_GET(leaf->hdr.firstused,
2386
 
                                                ARCH_CONVERT),
 
2090
                                        be16_to_cpu(leaf->hdr.firstused),
2387
2091
                                        first_used, da_bno, ino);
2388
2092
                }
2389
2093
        }
2390
2094
 
2391
 
        if (bytes_used != INT_GET(leaf->hdr.namebytes, ARCH_CONVERT))  {
 
2095
        if (bytes_used != be16_to_cpu(leaf->hdr.namebytes))  {
2392
2096
                if (!no_modify)  {
2393
2097
                        if (verbose)
2394
2098
                                do_warn(
2395
2099
_("- resetting namebytes cnt from %d to %d in block %u of dir inode %llu\n"),
2396
 
                                        (int) INT_GET(leaf->hdr.namebytes,
2397
 
                                                ARCH_CONVERT),
 
2100
                                        be16_to_cpu(leaf->hdr.namebytes),
2398
2101
                                        bytes_used, da_bno, ino);
2399
 
                        INT_SET(leaf->hdr.namebytes, ARCH_CONVERT, bytes_used);
 
2102
                        leaf->hdr.namebytes = cpu_to_be16(bytes_used);
2400
2103
                        *buf_dirty = 1;
2401
2104
                } else  {
2402
2105
                        if (verbose)
2403
2106
                                do_warn(
2404
2107
_("- would reset namebytes cnt from %d to %d in block %u of dir inode %llu\n"),
2405
 
                                        (int) INT_GET(leaf->hdr.namebytes,
2406
 
                                                ARCH_CONVERT),
 
2108
                                        be16_to_cpu(leaf->hdr.namebytes),
2407
2109
                                        bytes_used, da_bno, ino);
2408
2110
                }
2409
2111
        }
2419
2121
 
2420
2122
        bholemap.lost_holes = leaf->hdr.holes;
2421
2123
        for (i = 0; i < XFS_DIR_LEAF_MAPSIZE; i++)  {
2422
 
                bholemap.hentries[i].base = INT_GET(leaf->hdr.freemap[i].base, ARCH_CONVERT);
2423
 
                bholemap.hentries[i].size = INT_GET(leaf->hdr.freemap[i].size, ARCH_CONVERT);
 
2124
                bholemap.hentries[i].base = be16_to_cpu(leaf->hdr.freemap[i].base);
 
2125
                bholemap.hentries[i].size = be16_to_cpu(leaf->hdr.freemap[i].size);
2424
2126
        }
2425
2127
 
2426
2128
        /*
2503
2205
                         */
2504
2206
                        for (i = 0, s_entry = &leaf->entries[0],
2505
2207
                                        d_entry = &new_leaf->entries[0];
2506
 
                                        i < INT_GET(leaf->hdr.count, ARCH_CONVERT);
 
2208
                                        i < be16_to_cpu(leaf->hdr.count);
2507
2209
                                        i++, s_entry++)  {
2508
2210
                                /*
2509
2211
                                 * skip zero-length entries
2526
2228
                                first_used -= bytes;
2527
2229
                                first_byte -= bytes;
2528
2230
 
2529
 
                                INT_SET(d_entry->nameidx, ARCH_CONVERT, first_used);
2530
 
                                INT_SET(d_entry->hashval, ARCH_CONVERT, INT_GET(s_entry->hashval, ARCH_CONVERT));
 
2231
                                d_entry->nameidx = cpu_to_be16(first_used);
 
2232
                                d_entry->hashval = s_entry->hashval;
2531
2233
                                d_entry->namelen = s_entry->namelen;
2532
2234
                                d_entry->pad2 = 0;
2533
2235
 
2534
 
                                memmove(first_byte, (char *) leaf + INT_GET(s_entry->nameidx, ARCH_CONVERT),
2535
 
                                        bytes);
 
2236
                                memmove(first_byte, (char *)leaf + 
 
2237
                                        be16_to_cpu(s_entry->nameidx), bytes);
2536
2238
 
2537
2239
                                num_entries++;
2538
2240
                                d_entry++;
2550
2252
                        /*
2551
2253
                         * reset header info
2552
2254
                         */
2553
 
                        if (num_entries != INT_GET(new_leaf->hdr.count, ARCH_CONVERT))
2554
 
                                INT_SET(new_leaf->hdr.count, ARCH_CONVERT, num_entries);
 
2255
                        if (num_entries != be16_to_cpu(new_leaf->hdr.count))
 
2256
                                new_leaf->hdr.count = cpu_to_be16(num_entries);
2555
2257
 
2556
 
                        INT_SET(new_leaf->hdr.firstused, ARCH_CONVERT, first_used);
 
2258
                        new_leaf->hdr.firstused = cpu_to_be16(first_used);
2557
2259
                        new_leaf->hdr.holes = 0;
2558
2260
                        new_leaf->hdr.pad1 = 0;
2559
2261
 
2560
 
                        INT_SET(new_leaf->hdr.freemap[0].base, ARCH_CONVERT, (__psint_t) d_entry
2561
 
                                                        - (__psint_t) new_leaf);
2562
 
                        INT_SET(new_leaf->hdr.freemap[0].size, ARCH_CONVERT, (__psint_t) first_byte
2563
 
                                                        - (__psint_t) d_entry);
 
2262
                        new_leaf->hdr.freemap[0].base = cpu_to_be16(
 
2263
                                (__psint_t) d_entry - (__psint_t) new_leaf);
 
2264
                        new_leaf->hdr.freemap[0].size = cpu_to_be16(
 
2265
                                (__psint_t) first_byte - (__psint_t) d_entry);
2564
2266
 
2565
 
                        ASSERT(INT_GET(new_leaf->hdr.freemap[0].base, ARCH_CONVERT) < first_used);
2566
 
                        ASSERT(INT_GET(new_leaf->hdr.freemap[0].base, ARCH_CONVERT) ==
 
2267
                        ASSERT(be16_to_cpu(new_leaf->hdr.freemap[0].base) < first_used);
 
2268
                        ASSERT(be16_to_cpu(new_leaf->hdr.freemap[0].base) ==
2567
2269
                                        (__psint_t) (&new_leaf->entries[0])
2568
2270
                                        - (__psint_t) new_leaf
2569
2271
                                        + i * sizeof(xfs_dir_leaf_entry_t));
2570
 
                        ASSERT(INT_GET(new_leaf->hdr.freemap[0].base, ARCH_CONVERT) < XFS_LBSIZE(mp));
2571
 
                        ASSERT(INT_GET(new_leaf->hdr.freemap[0].size, ARCH_CONVERT) < XFS_LBSIZE(mp));
2572
 
                        ASSERT(INT_GET(new_leaf->hdr.freemap[0].base, ARCH_CONVERT) +
2573
 
                                INT_GET(new_leaf->hdr.freemap[0].size, ARCH_CONVERT) == first_used);
 
2272
                        ASSERT(be16_to_cpu(new_leaf->hdr.freemap[0].base) < XFS_LBSIZE(mp));
 
2273
                        ASSERT(be16_to_cpu(new_leaf->hdr.freemap[0].size) < XFS_LBSIZE(mp));
 
2274
                        ASSERT(be16_to_cpu(new_leaf->hdr.freemap[0].base) +
 
2275
                                be16_to_cpu(new_leaf->hdr.freemap[0].size) == first_used);
2574
2276
 
2575
2277
                        new_leaf->hdr.freemap[1].base = 0;
2576
2278
                        new_leaf->hdr.freemap[1].size = 0;
2671
2373
                 * check magic number for leaf directory btree block
2672
2374
                 */
2673
2375
                if (XFS_DIR_LEAF_MAGIC !=
2674
 
                    INT_GET(leaf->hdr.info.magic, ARCH_CONVERT)) {
 
2376
                    be16_to_cpu(leaf->hdr.info.magic)) {
2675
2377
                        do_warn(
2676
2378
                        _("bad directory leaf magic # %#x for dir ino %llu\n"),
2677
 
                                INT_GET(leaf->hdr.info.magic, ARCH_CONVERT),
 
2379
                                be16_to_cpu(leaf->hdr.info.magic),
2678
2380
                                ino);
2679
2381
                        libxfs_putbuf(bp);
2680
2382
                        goto error_out;
2688
2390
 
2689
2391
                buf_dirty = 0;
2690
2392
                /*
2691
 
                 * for each block, process the block, verify it's path,
 
2393
                 * for each block, process the block, verify its path,
2692
2394
                 * then get next block.  update cursor values along the way
2693
2395
                 */
2694
2396
                if (process_leaf_dir_block(mp, leaf, da_bno, ino,
2708
2410
                da_cursor->level[0].hashval = greatest_hashval;
2709
2411
                da_cursor->level[0].bp = bp;
2710
2412
                da_cursor->level[0].bno = da_bno;
2711
 
                da_cursor->level[0].index = INT_GET(leaf->hdr.count, ARCH_CONVERT);
 
2413
                da_cursor->level[0].index = be16_to_cpu(leaf->hdr.count);
2712
2414
                da_cursor->level[0].dirty = buf_dirty;
2713
2415
 
2714
 
                if (INT_GET(leaf->hdr.info.back, ARCH_CONVERT) != prev_bno)  {
 
2416
                if (be32_to_cpu(leaf->hdr.info.back) != prev_bno)  {
2715
2417
                        do_warn(_("bad sibling back pointer for directory "
2716
2418
                                  "block %u in directory inode %llu\n"),
2717
2419
                                da_bno, ino);
2720
2422
                }
2721
2423
 
2722
2424
                prev_bno = da_bno;
2723
 
                da_bno = INT_GET(leaf->hdr.info.forw, ARCH_CONVERT);
 
2425
                da_bno = be32_to_cpu(leaf->hdr.info.forw);
2724
2426
 
2725
2427
                if (da_bno != 0)
2726
2428
                        if (verify_da_path(mp, da_cursor, 0))  {
2849
2551
        /*
2850
2552
         * sanity check inode size
2851
2553
         */
2852
 
        if (INT_GET(dip->di_core.di_size, ARCH_CONVERT) <
 
2554
        if (be64_to_cpu(dip->di_core.di_size) <
2853
2555
                        (da_cursor.greatest_bno + 1) * mp->m_sb.sb_blocksize)  {
2854
2556
                if ((xfs_fsize_t) da_cursor.greatest_bno
2855
2557
                                * mp->m_sb.sb_blocksize > UINT_MAX)  {
2861
2563
 
2862
2564
                do_warn(
2863
2565
_("setting directory inode (%llu) size to %llu bytes, was %lld bytes\n"),
2864
 
                        ino,
2865
 
                        (xfs_dfiloff_t) (da_cursor.greatest_bno + 1)
 
2566
                        ino, (xfs_dfiloff_t) (da_cursor.greatest_bno + 1)
2866
2567
                                * mp->m_sb.sb_blocksize,
2867
 
                        INT_GET(dip->di_core.di_size, ARCH_CONVERT));
 
2568
                        be64_to_cpu(dip->di_core.di_size));
2868
2569
 
2869
 
                INT_SET(dip->di_core.di_size, ARCH_CONVERT, (xfs_fsize_t)
2870
 
                        (da_cursor.greatest_bno + 1) * mp->m_sb.sb_blocksize);
 
2570
                dip->di_core.di_size = cpu_to_be64((da_cursor.greatest_bno + 1) 
 
2571
                                                * mp->m_sb.sb_blocksize);
2871
2572
        }
2872
2573
        return(0);
2873
2574
}
2934
2635
        /*
2935
2636
         * check magic number for leaf directory btree block
2936
2637
         */
2937
 
        if (INT_GET(leaf->hdr.info.magic, ARCH_CONVERT) != XFS_DIR_LEAF_MAGIC) {
 
2638
        if (be16_to_cpu(leaf->hdr.info.magic) != XFS_DIR_LEAF_MAGIC) {
2938
2639
                do_warn(_("bad directory leaf magic # %#x for dir ino %llu\n"),
2939
 
                        INT_GET(leaf->hdr.info.magic, ARCH_CONVERT), ino);
 
2640
                        be16_to_cpu(leaf->hdr.info.magic), ino);
2940
2641
                libxfs_putbuf(bp);
2941
2642
                return(1);
2942
2643
        }
2956
2657
        /*
2957
2658
         * check sibling pointers in leaf block (above doesn't do it)
2958
2659
         */
2959
 
        if (INT_GET(leaf->hdr.info.forw, ARCH_CONVERT) != 0 ||
2960
 
            INT_GET(leaf->hdr.info.back, ARCH_CONVERT) != 0)  {
 
2660
        if (leaf->hdr.info.forw || leaf->hdr.info.back)  {
2961
2661
                if (!no_modify)  {
2962
2662
                        do_warn(_("clearing forw/back pointers for "
2963
2663
                                  "directory inode %llu\n"), ino);
3009
2709
         * is only called ONCE so all the subordinate routines will
3010
2710
         * fix '.' and junk '..' if they're bogus.
3011
2711
         */
3012
 
        if (INT_GET(dip->di_core.di_size, ARCH_CONVERT) <=
3013
 
            XFS_DFORK_DSIZE(dip, mp))  {
 
2712
        if (be64_to_cpu(dip->di_core.di_size) <= XFS_DFORK_DSIZE(dip, mp))  {
3014
2713
                dot = 1;
3015
2714
                dotdot = 1;
3016
2715
                if (process_shortform_dir(mp, ino, dip, ino_discovery,
3017
 
                                dino_dirty, parent, dirname, &repair))  {
 
2716
                                dino_dirty, parent, dirname, &repair))
3018
2717
                        res = 1;
3019
 
                }
3020
 
        } else if (INT_GET(dip->di_core.di_size, ARCH_CONVERT) <=
3021
 
                   XFS_LBSIZE(mp))  {
 
2718
        } else if (be64_to_cpu(dip->di_core.di_size) <= XFS_LBSIZE(mp))  {
3022
2719
                if (process_leaf_dir(mp, ino, dip, ino_discovery,
3023
2720
                                dino_dirty, blkmap, &dot, &dotdot,
3024
 
                                parent, dirname, &repair))  {
 
2721
                                parent, dirname, &repair))
3025
2722
                        res = 1;
3026
 
                }
3027
2723
        } else  {
3028
2724
                if (process_node_dir(mp, ino, dip, ino_discovery,
3029
2725
                                blkmap, &dot, &dotdot,
3030
 
                                parent, dirname, &repair))  {
 
2726
                                parent, dirname, &repair))
3031
2727
                        res = 1;
3032
 
                }
3033
2728
        }
3034
2729
        /*
3035
2730
         * bad . entries in all directories will be fixed up in phase 6
3036
2731
         */
3037
 
        if (dot == 0) {
 
2732
        if (dot == 0) 
3038
2733
                do_warn(_("no . entry for directory %llu\n"), ino);
3039
 
        }
3040
2734
 
3041
2735
        /*
3042
2736
         * shortform dirs always have a .. entry.  .. for all longform