]> err.no Git - linux-2.6/blobdiff - fs/xfs/xfs_dir2_node.c
[XFS] Use do_div() on 64 bit types.
[linux-2.6] / fs / xfs / xfs_dir2_node.c
index 40e4a2e2776551d4484e672e5a237f0ba4a6a03f..d083c38199343e0eacf91007c8e41180e79fcb54 100644 (file)
 #include "xfs_inum.h"
 #include "xfs_trans.h"
 #include "xfs_sb.h"
-#include "xfs_dir.h"
 #include "xfs_dir2.h"
 #include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_da_btree.h"
 #include "xfs_bmap_btree.h"
-#include "xfs_dir_sf.h"
 #include "xfs_dir2_sf.h"
 #include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
@@ -164,7 +162,7 @@ xfs_dir2_leaf_to_node(
                *to = cpu_to_be16(off);
        }
        free->hdr.nused = cpu_to_be32(n);
-       INT_SET(leaf->hdr.info.magic, ARCH_CONVERT, XFS_DIR2_LEAFN_MAGIC);
+       leaf->hdr.info.magic = cpu_to_be16(XFS_DIR2_LEAFN_MAGIC);
        /*
         * Log everything.
         */
@@ -223,9 +221,9 @@ xfs_dir2_leafn_add(
                compact = be16_to_cpu(leaf->hdr.stale) > 1;
        } else
                compact = 0;
-       ASSERT(index == 0 || INT_GET(leaf->ents[index - 1].hashval, ARCH_CONVERT) <= args->hashval);
+       ASSERT(index == 0 || be32_to_cpu(leaf->ents[index - 1].hashval) <= args->hashval);
        ASSERT(index == be16_to_cpu(leaf->hdr.count) ||
-              INT_GET(leaf->ents[index].hashval, ARCH_CONVERT) >= args->hashval);
+              be32_to_cpu(leaf->ents[index].hashval) >= args->hashval);
 
        if (args->justcheck)
                return 0;
@@ -271,7 +269,7 @@ xfs_dir2_leafn_add(
                         */
                        for (lowstale = index - 1;
                             lowstale >= 0 &&
-                               INT_GET(leaf->ents[lowstale].address, ARCH_CONVERT) !=
+                               be32_to_cpu(leaf->ents[lowstale].address) !=
                                XFS_DIR2_NULL_DATAPTR;
                             lowstale--)
                                continue;
@@ -282,7 +280,7 @@ xfs_dir2_leafn_add(
                         */
                        for (highstale = index;
                             highstale < be16_to_cpu(leaf->hdr.count) &&
-                               INT_GET(leaf->ents[highstale].address, ARCH_CONVERT) !=
+                               be32_to_cpu(leaf->ents[highstale].address) !=
                                XFS_DIR2_NULL_DATAPTR &&
                                (lowstale < 0 ||
                                 index - lowstale - 1 >= highstale - index);
@@ -296,7 +294,7 @@ xfs_dir2_leafn_add(
                if (lowstale >= 0 &&
                    (highstale == be16_to_cpu(leaf->hdr.count) ||
                     index - lowstale - 1 < highstale - index)) {
-                       ASSERT(INT_GET(leaf->ents[lowstale].address, ARCH_CONVERT) ==
+                       ASSERT(be32_to_cpu(leaf->ents[lowstale].address) ==
                               XFS_DIR2_NULL_DATAPTR);
                        ASSERT(index - lowstale - 1 >= 0);
                        if (index - lowstale - 1 > 0)
@@ -312,7 +310,7 @@ xfs_dir2_leafn_add(
                 * Shift entries down toward the stale slot.
                 */
                else {
-                       ASSERT(INT_GET(leaf->ents[highstale].address, ARCH_CONVERT) ==
+                       ASSERT(be32_to_cpu(leaf->ents[highstale].address) ==
                               XFS_DIR2_NULL_DATAPTR);
                        ASSERT(highstale - index >= 0);
                        if (highstale - index > 0)
@@ -328,8 +326,9 @@ xfs_dir2_leafn_add(
        /*
         * Insert the new entry, log everything.
         */
-       INT_SET(lep->hashval, ARCH_CONVERT, args->hashval);
-       INT_SET(lep->address, ARCH_CONVERT, XFS_DIR2_DB_OFF_TO_DATAPTR(mp, args->blkno, args->index));
+       lep->hashval = cpu_to_be32(args->hashval);
+       lep->address = cpu_to_be32(XFS_DIR2_DB_OFF_TO_DATAPTR(mp,
+                               args->blkno, args->index));
        xfs_dir2_leaf_log_header(tp, bp);
        xfs_dir2_leaf_log_ents(tp, bp, lfloglow, lfloghigh);
        xfs_dir2_leafn_check(dp, bp);
@@ -352,14 +351,14 @@ xfs_dir2_leafn_check(
 
        leaf = bp->data;
        mp = dp->i_mount;
-       ASSERT(INT_GET(leaf->hdr.info.magic, ARCH_CONVERT) == XFS_DIR2_LEAFN_MAGIC);
+       ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_DIR2_LEAFN_MAGIC);
        ASSERT(be16_to_cpu(leaf->hdr.count) <= XFS_DIR2_MAX_LEAF_ENTS(mp));
        for (i = stale = 0; i < be16_to_cpu(leaf->hdr.count); i++) {
                if (i + 1 < be16_to_cpu(leaf->hdr.count)) {
-                       ASSERT(INT_GET(leaf->ents[i].hashval, ARCH_CONVERT) <=
-                              INT_GET(leaf->ents[i + 1].hashval, ARCH_CONVERT));
+                       ASSERT(be32_to_cpu(leaf->ents[i].hashval) <=
+                              be32_to_cpu(leaf->ents[i + 1].hashval));
                }
-               if (INT_GET(leaf->ents[i].address, ARCH_CONVERT) == XFS_DIR2_NULL_DATAPTR)
+               if (be32_to_cpu(leaf->ents[i].address) == XFS_DIR2_NULL_DATAPTR)
                        stale++;
        }
        ASSERT(be16_to_cpu(leaf->hdr.stale) == stale);
@@ -378,12 +377,12 @@ xfs_dir2_leafn_lasthash(
        xfs_dir2_leaf_t *leaf;                  /* leaf structure */
 
        leaf = bp->data;
-       ASSERT(INT_GET(leaf->hdr.info.magic, ARCH_CONVERT) == XFS_DIR2_LEAFN_MAGIC);
+       ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_DIR2_LEAFN_MAGIC);
        if (count)
                *count = be16_to_cpu(leaf->hdr.count);
        if (!leaf->hdr.count)
                return 0;
-       return INT_GET(leaf->ents[be16_to_cpu(leaf->hdr.count) - 1].hashval, ARCH_CONVERT);
+       return be32_to_cpu(leaf->ents[be16_to_cpu(leaf->hdr.count) - 1].hashval);
 }
 
 /*
@@ -419,7 +418,7 @@ xfs_dir2_leafn_lookup_int(
        tp = args->trans;
        mp = dp->i_mount;
        leaf = bp->data;
-       ASSERT(INT_GET(leaf->hdr.info.magic, ARCH_CONVERT) == XFS_DIR2_LEAFN_MAGIC);
+       ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_DIR2_LEAFN_MAGIC);
 #ifdef __KERNEL__
        ASSERT(be16_to_cpu(leaf->hdr.count) > 0);
 #endif
@@ -456,17 +455,17 @@ xfs_dir2_leafn_lookup_int(
         * Loop over leaf entries with the right hash value.
         */
        for (lep = &leaf->ents[index];
-            index < be16_to_cpu(leaf->hdr.count) && INT_GET(lep->hashval, ARCH_CONVERT) == args->hashval;
+            index < be16_to_cpu(leaf->hdr.count) && be32_to_cpu(lep->hashval) == args->hashval;
             lep++, index++) {
                /*
                 * Skip stale leaf entries.
                 */
-               if (INT_GET(lep->address, ARCH_CONVERT) == XFS_DIR2_NULL_DATAPTR)
+               if (be32_to_cpu(lep->address) == XFS_DIR2_NULL_DATAPTR)
                        continue;
                /*
                 * Pull the data block number from the entry.
                 */
-               newdb = XFS_DIR2_DATAPTR_TO_DB(mp, INT_GET(lep->address, ARCH_CONVERT));
+               newdb = XFS_DIR2_DATAPTR_TO_DB(mp, be32_to_cpu(lep->address));
                /*
                 * For addname, we're looking for a place to put the new entry.
                 * We want to use a data block with an entry of equal
@@ -504,7 +503,6 @@ xfs_dir2_leafn_lookup_int(
                                                        XFS_DATA_FORK))) {
                                                return error;
                                        }
-                                       curfdb = newfdb;
                                        free = curbp->data;
                                        ASSERT(be32_to_cpu(free->hdr.magic) ==
                                               XFS_DIR2_FREE_MAGIC);
@@ -526,8 +524,11 @@ xfs_dir2_leafn_lookup_int(
                                if (unlikely(be16_to_cpu(free->bests[fi]) == NULLDATAOFF)) {
                                        XFS_ERROR_REPORT("xfs_dir2_leafn_lookup_int",
                                                         XFS_ERRLEVEL_LOW, mp);
+                                       if (curfdb != newfdb)
+                                               xfs_da_brelse(tp, curbp);
                                        return XFS_ERROR(EFSCORRUPTED);
                                }
+                               curfdb = newfdb;
                                if (be16_to_cpu(free->bests[fi]) >= length) {
                                        *indexp = index;
                                        state->extravalid = 1;
@@ -572,14 +573,14 @@ xfs_dir2_leafn_lookup_int(
                         */
                        dep = (xfs_dir2_data_entry_t *)
                              ((char *)curbp->data +
-                              XFS_DIR2_DATAPTR_TO_OFF(mp, INT_GET(lep->address, ARCH_CONVERT)));
+                              XFS_DIR2_DATAPTR_TO_OFF(mp, be32_to_cpu(lep->address)));
                        /*
                         * Compare the entry, return it if it matches.
                         */
                        if (dep->namelen == args->namelen &&
                            dep->name[0] == args->name[0] &&
                            memcmp(dep->name, args->name, args->namelen) == 0) {
-                               args->inumber = INT_GET(dep->inumber, ARCH_CONVERT);
+                               args->inumber = be64_to_cpu(dep->inumber);
                                *indexp = index;
                                state->extravalid = 1;
                                state->extrablk.bp = curbp;
@@ -672,7 +673,7 @@ xfs_dir2_leafn_moveents(
                int     i;                      /* temp leaf index */
 
                for (i = start_s, stale = 0; i < start_s + count; i++) {
-                       if (INT_GET(leaf_s->ents[i].address, ARCH_CONVERT) == XFS_DIR2_NULL_DATAPTR)
+                       if (be32_to_cpu(leaf_s->ents[i].address) == XFS_DIR2_NULL_DATAPTR)
                                stale++;
                }
        } else
@@ -719,13 +720,13 @@ xfs_dir2_leafn_order(
 
        leaf1 = leaf1_bp->data;
        leaf2 = leaf2_bp->data;
-       ASSERT(INT_GET(leaf1->hdr.info.magic, ARCH_CONVERT) == XFS_DIR2_LEAFN_MAGIC);
-       ASSERT(INT_GET(leaf2->hdr.info.magic, ARCH_CONVERT) == XFS_DIR2_LEAFN_MAGIC);
+       ASSERT(be16_to_cpu(leaf1->hdr.info.magic) == XFS_DIR2_LEAFN_MAGIC);
+       ASSERT(be16_to_cpu(leaf2->hdr.info.magic) == XFS_DIR2_LEAFN_MAGIC);
        if (be16_to_cpu(leaf1->hdr.count) > 0 &&
            be16_to_cpu(leaf2->hdr.count) > 0 &&
-           (INT_GET(leaf2->ents[0].hashval, ARCH_CONVERT) < INT_GET(leaf1->ents[0].hashval, ARCH_CONVERT) ||
-            INT_GET(leaf2->ents[be16_to_cpu(leaf2->hdr.count) - 1].hashval, ARCH_CONVERT) <
-            INT_GET(leaf1->ents[be16_to_cpu(leaf1->hdr.count) - 1].hashval, ARCH_CONVERT)))
+           (be32_to_cpu(leaf2->ents[0].hashval) < be32_to_cpu(leaf1->ents[0].hashval) ||
+            be32_to_cpu(leaf2->ents[be16_to_cpu(leaf2->hdr.count) - 1].hashval) <
+            be32_to_cpu(leaf1->ents[be16_to_cpu(leaf1->hdr.count) - 1].hashval)))
                return 1;
        return 0;
 }
@@ -781,9 +782,9 @@ xfs_dir2_leafn_rebalance(
                xfs_dahash_t    midhash;        /* middle entry hash value */
 
                if (mid >= be16_to_cpu(leaf1->hdr.count))
-                       midhash = INT_GET(leaf2->ents[mid - be16_to_cpu(leaf1->hdr.count)].hashval, ARCH_CONVERT);
+                       midhash = be32_to_cpu(leaf2->ents[mid - be16_to_cpu(leaf1->hdr.count)].hashval);
                else
-                       midhash = INT_GET(leaf1->ents[mid].hashval, ARCH_CONVERT);
+                       midhash = be32_to_cpu(leaf1->ents[mid].hashval);
                isleft = args->hashval <= midhash;
        }
        /*
@@ -829,7 +830,7 @@ xfs_dir2_leafn_rebalance(
                state->inleaf = 1;
                blk2->index = 0;
                cmn_err(CE_ALERT,
-                       "xfs_dir2_leafn_rebalance: picked the wrong leaf? reverting orignal leaf: "
+                       "xfs_dir2_leafn_rebalance: picked the wrong leaf? reverting original leaf: "
                        "blk1->index %d\n",
                        blk1->index);
        }
@@ -867,7 +868,7 @@ xfs_dir2_leafn_remove(
        tp = args->trans;
        mp = dp->i_mount;
        leaf = bp->data;
-       ASSERT(INT_GET(leaf->hdr.info.magic, ARCH_CONVERT) == XFS_DIR2_LEAFN_MAGIC);
+       ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_DIR2_LEAFN_MAGIC);
        /*
         * Point to the entry we're removing.
         */
@@ -875,9 +876,9 @@ xfs_dir2_leafn_remove(
        /*
         * Extract the data block and offset from the entry.
         */
-       db = XFS_DIR2_DATAPTR_TO_DB(mp, INT_GET(lep->address, ARCH_CONVERT));
+       db = XFS_DIR2_DATAPTR_TO_DB(mp, be32_to_cpu(lep->address));
        ASSERT(dblk->blkno == db);
-       off = XFS_DIR2_DATAPTR_TO_OFF(mp, INT_GET(lep->address, ARCH_CONVERT));
+       off = XFS_DIR2_DATAPTR_TO_OFF(mp, be32_to_cpu(lep->address));
        ASSERT(dblk->index == off);
        /*
         * Kill the leaf entry by marking it stale.
@@ -885,7 +886,7 @@ xfs_dir2_leafn_remove(
         */
        be16_add(&leaf->hdr.stale, 1);
        xfs_dir2_leaf_log_header(tp, bp);
-       INT_SET(lep->address, ARCH_CONVERT, XFS_DIR2_NULL_DATAPTR);
+       lep->address = cpu_to_be32(XFS_DIR2_NULL_DATAPTR);
        xfs_dir2_leaf_log_ents(tp, bp, index, index);
        /*
         * Make the data entry free.  Keep track of the longest freespace
@@ -903,7 +904,7 @@ xfs_dir2_leafn_remove(
         * Log the data block header if needed.
         */
        if (needscan)
-               xfs_dir2_data_freescan(mp, data, &needlog, NULL);
+               xfs_dir2_data_freescan(mp, data, &needlog);
        if (needlog)
                xfs_dir2_data_log_header(tp, dbp);
        xfs_dir2_data_check(dp, dbp);
@@ -969,7 +970,7 @@ xfs_dir2_leafn_remove(
                        /*
                         * One less used entry in the free table.
                         */
-                       free->hdr.nused = cpu_to_be32(-1);
+                       be32_add(&free->hdr.nused, -1);
                        xfs_dir2_free_log_header(tp, fbp);
                        /*
                         * If this was the last entry in the table, we can
@@ -1138,7 +1139,7 @@ xfs_dir2_leafn_toosmall(
         */
        blk = &state->path.blk[state->path.active - 1];
        info = blk->bp->data;
-       ASSERT(INT_GET(info->magic, ARCH_CONVERT) == XFS_DIR2_LEAFN_MAGIC);
+       ASSERT(be16_to_cpu(info->magic) == XFS_DIR2_LEAFN_MAGIC);
        leaf = (xfs_dir2_leaf_t *)info;
        count = be16_to_cpu(leaf->hdr.count) - be16_to_cpu(leaf->hdr.stale);
        bytes = (uint)sizeof(leaf->hdr) + count * (uint)sizeof(leaf->ents[0]);
@@ -1160,7 +1161,7 @@ xfs_dir2_leafn_toosmall(
                 * Make altpath point to the block we want to keep and
                 * path point to the block we want to drop (this one).
                 */
-               forward = info->forw;
+               forward = (info->forw != 0);
                memcpy(&state->altpath, &state->path, sizeof(state->path));
                error = xfs_da_path_shift(state, &state->altpath, forward, 0,
                        &rval);
@@ -1176,9 +1177,9 @@ xfs_dir2_leafn_toosmall(
         * We prefer coalescing with the lower numbered sibling so as
         * to shrink a directory over time.
         */
-       forward = INT_GET(info->forw, ARCH_CONVERT) < INT_GET(info->back, ARCH_CONVERT);
+       forward = be32_to_cpu(info->forw) < be32_to_cpu(info->back);
        for (i = 0, bp = NULL; i < 2; forward = !forward, i++) {
-               blkno = forward ?INT_GET( info->forw, ARCH_CONVERT) : INT_GET(info->back, ARCH_CONVERT);
+               blkno = forward ? be32_to_cpu(info->forw) : be32_to_cpu(info->back);
                if (blkno == 0)
                        continue;
                /*
@@ -1197,7 +1198,7 @@ xfs_dir2_leafn_toosmall(
                count = be16_to_cpu(leaf->hdr.count) - be16_to_cpu(leaf->hdr.stale);
                bytes = state->blocksize - (state->blocksize >> 2);
                leaf = bp->data;
-               ASSERT(INT_GET(leaf->hdr.info.magic, ARCH_CONVERT) == XFS_DIR2_LEAFN_MAGIC);
+               ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_DIR2_LEAFN_MAGIC);
                count += be16_to_cpu(leaf->hdr.count) - be16_to_cpu(leaf->hdr.stale);
                bytes -= count * (uint)sizeof(leaf->ents[0]);
                /*
@@ -1256,8 +1257,8 @@ xfs_dir2_leafn_unbalance(
        ASSERT(save_blk->magic == XFS_DIR2_LEAFN_MAGIC);
        drop_leaf = drop_blk->bp->data;
        save_leaf = save_blk->bp->data;
-       ASSERT(INT_GET(drop_leaf->hdr.info.magic, ARCH_CONVERT) == XFS_DIR2_LEAFN_MAGIC);
-       ASSERT(INT_GET(save_leaf->hdr.info.magic, ARCH_CONVERT) == XFS_DIR2_LEAFN_MAGIC);
+       ASSERT(be16_to_cpu(drop_leaf->hdr.info.magic) == XFS_DIR2_LEAFN_MAGIC);
+       ASSERT(be16_to_cpu(save_leaf->hdr.info.magic) == XFS_DIR2_LEAFN_MAGIC);
        /*
         * If there are any stale leaf entries, take this opportunity
         * to purge them.
@@ -1269,14 +1270,14 @@ xfs_dir2_leafn_unbalance(
        /*
         * Move the entries from drop to the appropriate end of save.
         */
-       drop_blk->hashval = INT_GET(drop_leaf->ents[be16_to_cpu(drop_leaf->hdr.count) - 1].hashval, ARCH_CONVERT);
+       drop_blk->hashval = be32_to_cpu(drop_leaf->ents[be16_to_cpu(drop_leaf->hdr.count) - 1].hashval);
        if (xfs_dir2_leafn_order(save_blk->bp, drop_blk->bp))
                xfs_dir2_leafn_moveents(args, drop_blk->bp, 0, save_blk->bp, 0,
                        be16_to_cpu(drop_leaf->hdr.count));
        else
                xfs_dir2_leafn_moveents(args, drop_blk->bp, 0, save_blk->bp,
                        be16_to_cpu(save_leaf->hdr.count), be16_to_cpu(drop_leaf->hdr.count));
-       save_blk->hashval = INT_GET(save_leaf->ents[be16_to_cpu(save_leaf->hdr.count) - 1].hashval, ARCH_CONVERT);
+       save_blk->hashval = be32_to_cpu(save_leaf->ents[be16_to_cpu(save_leaf->hdr.count) - 1].hashval);
        xfs_dir2_leafn_check(args->dp, save_blk->bp);
 }
 
@@ -1378,7 +1379,7 @@ xfs_dir2_node_addname_int(
        xfs_mount_t             *mp;            /* filesystem mount point */
        int                     needlog;        /* need to log data header */
        int                     needscan;       /* need to rescan data frees */
-       xfs_dir2_data_off_t     *tagp;          /* data entry tag pointer */
+       __be16                  *tagp;          /* data entry tag pointer */
        xfs_trans_t             *tp;            /* transaction pointer */
 
        dp = args->dp;
@@ -1694,17 +1695,17 @@ xfs_dir2_node_addname_int(
         * Fill in the new entry and log it.
         */
        dep = (xfs_dir2_data_entry_t *)dup;
-       INT_SET(dep->inumber, ARCH_CONVERT, args->inumber);
+       dep->inumber = cpu_to_be64(args->inumber);
        dep->namelen = args->namelen;
        memcpy(dep->name, args->name, dep->namelen);
        tagp = XFS_DIR2_DATA_ENTRY_TAG_P(dep);
-       INT_SET(*tagp, ARCH_CONVERT, (xfs_dir2_data_off_t)((char *)dep - (char *)data));
+       *tagp = cpu_to_be16((char *)dep - (char *)data);
        xfs_dir2_data_log_entry(tp, dbp, dep);
        /*
         * Rescan the block for bestfree if needed.
         */
        if (needscan)
-               xfs_dir2_data_freescan(mp, data, &needlog, NULL);
+               xfs_dir2_data_freescan(mp, data, &needlog);
        /*
         * Log the data block header if needed.
         */
@@ -1731,7 +1732,7 @@ xfs_dir2_node_addname_int(
         * Return the data block and offset in args, then drop the data block.
         */
        args->blkno = (xfs_dablk_t)dbno;
-       args->index = INT_GET(*tagp, ARCH_CONVERT);
+       args->index = be16_to_cpu(*tagp);
        xfs_da_buf_done(dbp);
        return 0;
 }
@@ -1903,12 +1904,12 @@ xfs_dir2_node_replace(
                ASSERT(be32_to_cpu(data->hdr.magic) == XFS_DIR2_DATA_MAGIC);
                dep = (xfs_dir2_data_entry_t *)
                      ((char *)data +
-                      XFS_DIR2_DATAPTR_TO_OFF(state->mp, INT_GET(lep->address, ARCH_CONVERT)));
-               ASSERT(inum != INT_GET(dep->inumber, ARCH_CONVERT));
+                      XFS_DIR2_DATAPTR_TO_OFF(state->mp, be32_to_cpu(lep->address)));
+               ASSERT(inum != be64_to_cpu(dep->inumber));
                /*
                 * Fill in the new inode number and log the entry.
                 */
-               INT_SET(dep->inumber, ARCH_CONVERT, inum);
+               dep->inumber = cpu_to_be64(inum);
                xfs_dir2_data_log_entry(args->trans, state->extrablk.bp, dep);
                rval = 0;
        }