Pull video into test branch
[sfrench/cifs-2.6.git] / fs / xfs / xfs_dir2_data.c
index fd6b7c03018a68595672af069f626057b77129e1..f7c799217072066518a560965c907cc8f428ef35 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"
 #include "xfs_inode.h"
-#include "xfs_dir_leaf.h"
 #include "xfs_dir2_data.h"
 #include "xfs_dir2_leaf.h"
 #include "xfs_dir2_block.h"
@@ -108,9 +105,9 @@ xfs_dir2_data_check(
                 * If we find it, account for that, else make sure it
                 * doesn't need to be there.
                 */
-               if (INT_GET(dup->freetag, ARCH_CONVERT) == XFS_DIR2_DATA_FREE_TAG) {
+               if (be16_to_cpu(dup->freetag) == XFS_DIR2_DATA_FREE_TAG) {
                        ASSERT(lastfree == 0);
-                       ASSERT(INT_GET(*XFS_DIR2_DATA_UNUSED_TAG_P(dup), ARCH_CONVERT) ==
+                       ASSERT(be16_to_cpu(*XFS_DIR2_DATA_UNUSED_TAG_P(dup)) ==
                               (char *)dup - (char *)d);
                        dfp = xfs_dir2_data_freefind(d, dup);
                        if (dfp) {
@@ -118,10 +115,10 @@ xfs_dir2_data_check(
                                ASSERT((freeseen & (1 << i)) == 0);
                                freeseen |= 1 << i;
                        } else {
-                               ASSERT(INT_GET(dup->length, ARCH_CONVERT) <=
+                               ASSERT(be16_to_cpu(dup->length) <=
                                       be16_to_cpu(bf[2].length));
                        }
-                       p += INT_GET(dup->length, ARCH_CONVERT);
+                       p += be16_to_cpu(dup->length);
                        lastfree = 1;
                        continue;
                }
@@ -133,8 +130,8 @@ xfs_dir2_data_check(
                 */
                dep = (xfs_dir2_data_entry_t *)p;
                ASSERT(dep->namelen != 0);
-               ASSERT(xfs_dir_ino_validate(mp, INT_GET(dep->inumber, ARCH_CONVERT)) == 0);
-               ASSERT(INT_GET(*XFS_DIR2_DATA_ENTRY_TAG_P(dep), ARCH_CONVERT) ==
+               ASSERT(xfs_dir_ino_validate(mp, be64_to_cpu(dep->inumber)) == 0);
+               ASSERT(be16_to_cpu(*XFS_DIR2_DATA_ENTRY_TAG_P(dep)) ==
                       (char *)dep - (char *)d);
                count++;
                lastfree = 0;
@@ -143,12 +140,12 @@ xfs_dir2_data_check(
                                (xfs_dir2_data_aoff_t)
                                ((char *)dep - (char *)d));
                        hash = xfs_da_hashname((char *)dep->name, dep->namelen);
-                       for (i = 0; i < INT_GET(btp->count, ARCH_CONVERT); i++) {
-                               if (INT_GET(lep[i].address, ARCH_CONVERT) == addr &&
-                                   INT_GET(lep[i].hashval, ARCH_CONVERT) == hash)
+                       for (i = 0; i < be32_to_cpu(btp->count); i++) {
+                               if (be32_to_cpu(lep[i].address) == addr &&
+                                   be32_to_cpu(lep[i].hashval) == hash)
                                        break;
                        }
-                       ASSERT(i < INT_GET(btp->count, ARCH_CONVERT));
+                       ASSERT(i < be32_to_cpu(btp->count));
                }
                p += XFS_DIR2_DATA_ENTSIZE(dep->namelen);
        }
@@ -157,14 +154,14 @@ xfs_dir2_data_check(
         */
        ASSERT(freeseen == 7);
        if (be32_to_cpu(d->hdr.magic) == XFS_DIR2_BLOCK_MAGIC) {
-               for (i = stale = 0; i < INT_GET(btp->count, ARCH_CONVERT); i++) {
-                       if (INT_GET(lep[i].address, ARCH_CONVERT) == XFS_DIR2_NULL_DATAPTR)
+               for (i = stale = 0; i < be32_to_cpu(btp->count); i++) {
+                       if (be32_to_cpu(lep[i].address) == XFS_DIR2_NULL_DATAPTR)
                                stale++;
                        if (i > 0)
-                               ASSERT(INT_GET(lep[i].hashval, ARCH_CONVERT) >= INT_GET(lep[i - 1].hashval, ARCH_CONVERT));
+                               ASSERT(be32_to_cpu(lep[i].hashval) >= be32_to_cpu(lep[i - 1].hashval));
                }
-               ASSERT(count == INT_GET(btp->count, ARCH_CONVERT) - INT_GET(btp->stale, ARCH_CONVERT));
-               ASSERT(stale == INT_GET(btp->stale, ARCH_CONVERT));
+               ASSERT(count == be32_to_cpu(btp->count) - be32_to_cpu(btp->stale));
+               ASSERT(stale == be32_to_cpu(btp->stale));
        }
 }
 #endif
@@ -205,12 +202,12 @@ xfs_dir2_data_freefind(
                ASSERT(seenzero == 0);
                if (be16_to_cpu(dfp->offset) == off) {
                        matched = 1;
-                       ASSERT(be16_to_cpu(dfp->length) == INT_GET(dup->length, ARCH_CONVERT));
+                       ASSERT(dfp->length == dup->length);
                } else if (off < be16_to_cpu(dfp->offset))
-                       ASSERT(off + INT_GET(dup->length, ARCH_CONVERT) <= be16_to_cpu(dfp->offset));
+                       ASSERT(off + be16_to_cpu(dup->length) <= be16_to_cpu(dfp->offset));
                else
                        ASSERT(be16_to_cpu(dfp->offset) + be16_to_cpu(dfp->length) <= off);
-               ASSERT(matched || be16_to_cpu(dfp->length) >= INT_GET(dup->length, ARCH_CONVERT));
+               ASSERT(matched || be16_to_cpu(dfp->length) >= be16_to_cpu(dup->length));
                if (dfp > &d->hdr.bestfree[0])
                        ASSERT(be16_to_cpu(dfp[-1].length) >= be16_to_cpu(dfp[0].length));
        }
@@ -219,7 +216,7 @@ xfs_dir2_data_freefind(
         * If this is smaller than the smallest bestfree entry,
         * it can't be there since they're sorted.
         */
-       if (INT_GET(dup->length, ARCH_CONVERT) <
+       if (be16_to_cpu(dup->length) <
            be16_to_cpu(d->hdr.bestfree[XFS_DIR2_DATA_FD_COUNT - 1].length))
                return NULL;
        /*
@@ -364,11 +361,11 @@ xfs_dir2_data_freescan(
                /*
                 * If it's a free entry, insert it.
                 */
-               if (INT_GET(dup->freetag, ARCH_CONVERT) == XFS_DIR2_DATA_FREE_TAG) {
+               if (be16_to_cpu(dup->freetag) == XFS_DIR2_DATA_FREE_TAG) {
                        ASSERT((char *)dup - (char *)d ==
-                              INT_GET(*XFS_DIR2_DATA_UNUSED_TAG_P(dup), ARCH_CONVERT));
+                              be16_to_cpu(*XFS_DIR2_DATA_UNUSED_TAG_P(dup)));
                        xfs_dir2_data_freeinsert(d, dup, loghead);
-                       p += INT_GET(dup->length, ARCH_CONVERT);
+                       p += be16_to_cpu(dup->length);
                }
                /*
                 * For active entries, check their tags and skip them.
@@ -376,7 +373,7 @@ xfs_dir2_data_freescan(
                else {
                        dep = (xfs_dir2_data_entry_t *)p;
                        ASSERT((char *)dep - (char *)d ==
-                              INT_GET(*XFS_DIR2_DATA_ENTRY_TAG_P(dep), ARCH_CONVERT));
+                              be16_to_cpu(*XFS_DIR2_DATA_ENTRY_TAG_P(dep)));
                        p += XFS_DIR2_DATA_ENTSIZE(dep->namelen);
                }
        }
@@ -428,13 +425,12 @@ xfs_dir2_data_init(
         * Set up an unused entry for the block's body.
         */
        dup = &d->u[0].unused;
-       INT_SET(dup->freetag, ARCH_CONVERT, XFS_DIR2_DATA_FREE_TAG);
+       dup->freetag = cpu_to_be16(XFS_DIR2_DATA_FREE_TAG);
 
        t=mp->m_dirblksize - (uint)sizeof(d->hdr);
        d->hdr.bestfree[0].length = cpu_to_be16(t);
-       INT_SET(dup->length, ARCH_CONVERT, t);
-       INT_SET(*XFS_DIR2_DATA_UNUSED_TAG_P(dup), ARCH_CONVERT,
-               (xfs_dir2_data_off_t)((char *)dup - (char *)d));
+       dup->length = cpu_to_be16(t);
+       *XFS_DIR2_DATA_UNUSED_TAG_P(dup) = cpu_to_be16((char *)dup - (char *)d);
        /*
         * Log it and return it.
         */
@@ -550,11 +546,11 @@ xfs_dir2_data_make_free(
         * the previous entry and see if it's free.
         */
        if (offset > sizeof(d->hdr)) {
-               xfs_dir2_data_off_t     *tagp;  /* tag just before us */
+               __be16                  *tagp;  /* tag just before us */
 
-               tagp = (xfs_dir2_data_off_t *)((char *)d + offset) - 1;
-               prevdup = (xfs_dir2_data_unused_t *)((char *)d + INT_GET(*tagp, ARCH_CONVERT));
-               if (INT_GET(prevdup->freetag, ARCH_CONVERT) != XFS_DIR2_DATA_FREE_TAG)
+               tagp = (__be16 *)((char *)d + offset) - 1;
+               prevdup = (xfs_dir2_data_unused_t *)((char *)d + be16_to_cpu(*tagp));
+               if (be16_to_cpu(prevdup->freetag) != XFS_DIR2_DATA_FREE_TAG)
                        prevdup = NULL;
        } else
                prevdup = NULL;
@@ -565,7 +561,7 @@ xfs_dir2_data_make_free(
        if ((char *)d + offset + len < endptr) {
                postdup =
                        (xfs_dir2_data_unused_t *)((char *)d + offset + len);
-               if (INT_GET(postdup->freetag, ARCH_CONVERT) != XFS_DIR2_DATA_FREE_TAG)
+               if (be16_to_cpu(postdup->freetag) != XFS_DIR2_DATA_FREE_TAG)
                        postdup = NULL;
        } else
                postdup = NULL;
@@ -593,9 +589,9 @@ xfs_dir2_data_make_free(
                /*
                 * Fix up the new big freespace.
                 */
-               INT_MOD(prevdup->length, ARCH_CONVERT, len + INT_GET(postdup->length, ARCH_CONVERT));
-               INT_SET(*XFS_DIR2_DATA_UNUSED_TAG_P(prevdup), ARCH_CONVERT,
-                       (xfs_dir2_data_off_t)((char *)prevdup - (char *)d));
+               be16_add(&prevdup->length, len + be16_to_cpu(postdup->length));
+               *XFS_DIR2_DATA_UNUSED_TAG_P(prevdup) =
+                       cpu_to_be16((char *)prevdup - (char *)d);
                xfs_dir2_data_log_unused(tp, bp, prevdup);
                if (!needscan) {
                        /*
@@ -617,7 +613,7 @@ xfs_dir2_data_make_free(
                         */
                        dfp = xfs_dir2_data_freeinsert(d, prevdup, needlogp);
                        ASSERT(dfp == &d->hdr.bestfree[0]);
-                       ASSERT(be16_to_cpu(dfp->length) == INT_GET(prevdup->length, ARCH_CONVERT));
+                       ASSERT(dfp->length == prevdup->length);
                        ASSERT(!dfp[1].length);
                        ASSERT(!dfp[2].length);
                }
@@ -627,9 +623,9 @@ xfs_dir2_data_make_free(
         */
        else if (prevdup) {
                dfp = xfs_dir2_data_freefind(d, prevdup);
-               INT_MOD(prevdup->length, ARCH_CONVERT, len);
-               INT_SET(*XFS_DIR2_DATA_UNUSED_TAG_P(prevdup), ARCH_CONVERT,
-                       (xfs_dir2_data_off_t)((char *)prevdup - (char *)d));
+               be16_add(&prevdup->length, len);
+               *XFS_DIR2_DATA_UNUSED_TAG_P(prevdup) =
+                       cpu_to_be16((char *)prevdup - (char *)d);
                xfs_dir2_data_log_unused(tp, bp, prevdup);
                /*
                 * If the previous entry was in the table, the new entry
@@ -644,7 +640,7 @@ xfs_dir2_data_make_free(
                 * Otherwise we need a scan if the new entry is big enough.
                 */
                else {
-                       needscan = INT_GET(prevdup->length, ARCH_CONVERT) >
+                       needscan = be16_to_cpu(prevdup->length) >
                                   be16_to_cpu(d->hdr.bestfree[2].length);
                }
        }
@@ -654,10 +650,10 @@ xfs_dir2_data_make_free(
        else if (postdup) {
                dfp = xfs_dir2_data_freefind(d, postdup);
                newdup = (xfs_dir2_data_unused_t *)((char *)d + offset);
-               INT_SET(newdup->freetag, ARCH_CONVERT, XFS_DIR2_DATA_FREE_TAG);
-               INT_SET(newdup->length, ARCH_CONVERT, len + INT_GET(postdup->length, ARCH_CONVERT));
-               INT_SET(*XFS_DIR2_DATA_UNUSED_TAG_P(newdup), ARCH_CONVERT,
-                       (xfs_dir2_data_off_t)((char *)newdup - (char *)d));
+               newdup->freetag = cpu_to_be16(XFS_DIR2_DATA_FREE_TAG);
+               newdup->length = cpu_to_be16(len + be16_to_cpu(postdup->length));
+               *XFS_DIR2_DATA_UNUSED_TAG_P(newdup) =
+                       cpu_to_be16((char *)newdup - (char *)d);
                xfs_dir2_data_log_unused(tp, bp, newdup);
                /*
                 * If the following entry was in the table, the new entry
@@ -672,7 +668,7 @@ xfs_dir2_data_make_free(
                 * Otherwise we need a scan if the new entry is big enough.
                 */
                else {
-                       needscan = INT_GET(newdup->length, ARCH_CONVERT) >
+                       needscan = be16_to_cpu(newdup->length) >
                                   be16_to_cpu(d->hdr.bestfree[2].length);
                }
        }
@@ -681,10 +677,10 @@ xfs_dir2_data_make_free(
         */
        else {
                newdup = (xfs_dir2_data_unused_t *)((char *)d + offset);
-               INT_SET(newdup->freetag, ARCH_CONVERT, XFS_DIR2_DATA_FREE_TAG);
-               INT_SET(newdup->length, ARCH_CONVERT, len);
-               INT_SET(*XFS_DIR2_DATA_UNUSED_TAG_P(newdup), ARCH_CONVERT,
-                       (xfs_dir2_data_off_t)((char *)newdup - (char *)d));
+               newdup->freetag = cpu_to_be16(XFS_DIR2_DATA_FREE_TAG);
+               newdup->length = cpu_to_be16(len);
+               *XFS_DIR2_DATA_UNUSED_TAG_P(newdup) =
+                       cpu_to_be16((char *)newdup - (char *)d);
                xfs_dir2_data_log_unused(tp, bp, newdup);
                (void)xfs_dir2_data_freeinsert(d, newdup, needlogp);
        }
@@ -716,15 +712,15 @@ xfs_dir2_data_use_free(
        d = bp->data;
        ASSERT(be32_to_cpu(d->hdr.magic) == XFS_DIR2_DATA_MAGIC ||
               be32_to_cpu(d->hdr.magic) == XFS_DIR2_BLOCK_MAGIC);
-       ASSERT(INT_GET(dup->freetag, ARCH_CONVERT) == XFS_DIR2_DATA_FREE_TAG);
+       ASSERT(be16_to_cpu(dup->freetag) == XFS_DIR2_DATA_FREE_TAG);
        ASSERT(offset >= (char *)dup - (char *)d);
-       ASSERT(offset + len <= (char *)dup + INT_GET(dup->length, ARCH_CONVERT) - (char *)d);
-       ASSERT((char *)dup - (char *)d == INT_GET(*XFS_DIR2_DATA_UNUSED_TAG_P(dup), ARCH_CONVERT));
+       ASSERT(offset + len <= (char *)dup + be16_to_cpu(dup->length) - (char *)d);
+       ASSERT((char *)dup - (char *)d == be16_to_cpu(*XFS_DIR2_DATA_UNUSED_TAG_P(dup)));
        /*
         * Look up the entry in the bestfree table.
         */
        dfp = xfs_dir2_data_freefind(d, dup);
-       oldlen = INT_GET(dup->length, ARCH_CONVERT);
+       oldlen = be16_to_cpu(dup->length);
        ASSERT(dfp || oldlen <= be16_to_cpu(d->hdr.bestfree[2].length));
        /*
         * Check for alignment with front and back of the entry.
@@ -750,10 +746,10 @@ xfs_dir2_data_use_free(
         */
        else if (matchfront) {
                newdup = (xfs_dir2_data_unused_t *)((char *)d + offset + len);
-               INT_SET(newdup->freetag, ARCH_CONVERT, XFS_DIR2_DATA_FREE_TAG);
-               INT_SET(newdup->length, ARCH_CONVERT, oldlen - len);
-               INT_SET(*XFS_DIR2_DATA_UNUSED_TAG_P(newdup), ARCH_CONVERT,
-                       (xfs_dir2_data_off_t)((char *)newdup - (char *)d));
+               newdup->freetag = cpu_to_be16(XFS_DIR2_DATA_FREE_TAG);
+               newdup->length = cpu_to_be16(oldlen - len);
+               *XFS_DIR2_DATA_UNUSED_TAG_P(newdup) =
+                       cpu_to_be16((char *)newdup - (char *)d);
                xfs_dir2_data_log_unused(tp, bp, newdup);
                /*
                 * If it was in the table, remove it and add the new one.
@@ -762,7 +758,7 @@ xfs_dir2_data_use_free(
                        xfs_dir2_data_freeremove(d, dfp, needlogp);
                        dfp = xfs_dir2_data_freeinsert(d, newdup, needlogp);
                        ASSERT(dfp != NULL);
-                       ASSERT(be16_to_cpu(dfp->length) == INT_GET(newdup->length, ARCH_CONVERT));
+                       ASSERT(dfp->length == newdup->length);
                        ASSERT(be16_to_cpu(dfp->offset) == (char *)newdup - (char *)d);
                        /*
                         * If we got inserted at the last slot,
@@ -778,10 +774,9 @@ xfs_dir2_data_use_free(
         */
        else if (matchback) {
                newdup = dup;
-               INT_SET(newdup->length, ARCH_CONVERT, (xfs_dir2_data_off_t)
-                       (((char *)d + offset) - (char *)newdup));
-               INT_SET(*XFS_DIR2_DATA_UNUSED_TAG_P(newdup), ARCH_CONVERT,
-                       (xfs_dir2_data_off_t)((char *)newdup - (char *)d));
+               newdup->length = cpu_to_be16(((char *)d + offset) - (char *)newdup);
+               *XFS_DIR2_DATA_UNUSED_TAG_P(newdup) =
+                       cpu_to_be16((char *)newdup - (char *)d);
                xfs_dir2_data_log_unused(tp, bp, newdup);
                /*
                 * If it was in the table, remove it and add the new one.
@@ -790,7 +785,7 @@ xfs_dir2_data_use_free(
                        xfs_dir2_data_freeremove(d, dfp, needlogp);
                        dfp = xfs_dir2_data_freeinsert(d, newdup, needlogp);
                        ASSERT(dfp != NULL);
-                       ASSERT(be16_to_cpu(dfp->length) == INT_GET(newdup->length, ARCH_CONVERT));
+                       ASSERT(dfp->length == newdup->length);
                        ASSERT(be16_to_cpu(dfp->offset) == (char *)newdup - (char *)d);
                        /*
                         * If we got inserted at the last slot,
@@ -806,16 +801,15 @@ xfs_dir2_data_use_free(
         */
        else {
                newdup = dup;
-               INT_SET(newdup->length, ARCH_CONVERT, (xfs_dir2_data_off_t)
-                       (((char *)d + offset) - (char *)newdup));
-               INT_SET(*XFS_DIR2_DATA_UNUSED_TAG_P(newdup), ARCH_CONVERT,
-                       (xfs_dir2_data_off_t)((char *)newdup - (char *)d));
+               newdup->length = cpu_to_be16(((char *)d + offset) - (char *)newdup);
+               *XFS_DIR2_DATA_UNUSED_TAG_P(newdup) =
+                       cpu_to_be16((char *)newdup - (char *)d);
                xfs_dir2_data_log_unused(tp, bp, newdup);
                newdup2 = (xfs_dir2_data_unused_t *)((char *)d + offset + len);
-               INT_SET(newdup2->freetag, ARCH_CONVERT, XFS_DIR2_DATA_FREE_TAG);
-               INT_SET(newdup2->length, ARCH_CONVERT, oldlen - len - INT_GET(newdup->length, ARCH_CONVERT));
-               INT_SET(*XFS_DIR2_DATA_UNUSED_TAG_P(newdup2), ARCH_CONVERT,
-                       (xfs_dir2_data_off_t)((char *)newdup2 - (char *)d));
+               newdup2->freetag = cpu_to_be16(XFS_DIR2_DATA_FREE_TAG);
+               newdup2->length = cpu_to_be16(oldlen - len - be16_to_cpu(newdup->length));
+               *XFS_DIR2_DATA_UNUSED_TAG_P(newdup2) =
+                       cpu_to_be16((char *)newdup2 - (char *)d);
                xfs_dir2_data_log_unused(tp, bp, newdup2);
                /*
                 * If the old entry was in the table, we need to scan