linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / fs / xfs / xfs_dir2_data.c
index c1b8ea0..5b7c47e 100644 (file)
@@ -1,60 +1,38 @@
 /*
- * Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
+ * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
+ * All Rights Reserved.
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
  * published by the Free Software Foundation.
  *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc., 59
- * Temple Place - Suite 330, Boston MA 02111-1307, USA.
- *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA  94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
-
-/*
- * xfs_dir2_data.c
- * Core data block handling routines for XFS V2 directories.
- * See xfs_dir2_data.h for data structures.
- */
-
 #include "xfs.h"
-
-#include "xfs_macros.h"
+#include "xfs_fs.h"
 #include "xfs_types.h"
-#include "xfs_inum.h"
 #include "xfs_log.h"
+#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_attr_sf.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_da_btree.h"
 #include "xfs_dir_leaf.h"
 #include "xfs_dir2_data.h"
 #include "xfs_dir2_leaf.h"
@@ -98,7 +76,7 @@ xfs_dir2_data_check(
        p = (char *)d->u;
        if (INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_BLOCK_MAGIC) {
                btp = XFS_DIR2_BLOCK_TAIL_P(mp, (xfs_dir2_block_t *)d);
-               lep = XFS_DIR2_BLOCK_LEAF_P_ARCH(btp, ARCH_CONVERT);
+               lep = XFS_DIR2_BLOCK_LEAF_P(btp);
                endp = (char *)lep;
        } else
                endp = (char *)d + mp->m_dirblksize;
@@ -106,16 +84,16 @@ xfs_dir2_data_check(
        /*
         * Account for zero bestfree entries.
         */
-       if (INT_ISZERO(bf[0].length, ARCH_CONVERT)) {
-               ASSERT(INT_ISZERO(bf[0].offset, ARCH_CONVERT));
+       if (!bf[0].length) {
+               ASSERT(!bf[0].offset);
                freeseen |= 1 << 0;
        }
-       if (INT_ISZERO(bf[1].length, ARCH_CONVERT)) {
-               ASSERT(INT_ISZERO(bf[1].offset, ARCH_CONVERT));
+       if (!bf[1].length) {
+               ASSERT(!bf[1].offset);
                freeseen |= 1 << 1;
        }
-       if (INT_ISZERO(bf[2].length, ARCH_CONVERT)) {
-               ASSERT(INT_ISZERO(bf[2].offset, ARCH_CONVERT));
+       if (!bf[2].length) {
+               ASSERT(!bf[2].offset);
                freeseen |= 1 << 2;
        }
        ASSERT(INT_GET(bf[0].length, ARCH_CONVERT) >= INT_GET(bf[1].length, ARCH_CONVERT));
@@ -132,7 +110,7 @@ xfs_dir2_data_check(
                 */
                if (INT_GET(dup->freetag, ARCH_CONVERT) == XFS_DIR2_DATA_FREE_TAG) {
                        ASSERT(lastfree == 0);
-                       ASSERT(INT_GET(*XFS_DIR2_DATA_UNUSED_TAG_P_ARCH(dup, ARCH_CONVERT), ARCH_CONVERT) ==
+                       ASSERT(INT_GET(*XFS_DIR2_DATA_UNUSED_TAG_P(dup), ARCH_CONVERT) ==
                               (char *)dup - (char *)d);
                        dfp = xfs_dir2_data_freefind(d, dup);
                        if (dfp) {
@@ -217,8 +195,8 @@ xfs_dir2_data_freefind(
        for (dfp = &d->hdr.bestfree[0], seenzero = matched = 0;
             dfp < &d->hdr.bestfree[XFS_DIR2_DATA_FD_COUNT];
             dfp++) {
-               if (INT_ISZERO(dfp->offset, ARCH_CONVERT)) {
-                       ASSERT(INT_ISZERO(dfp->length, ARCH_CONVERT));
+               if (!dfp->offset) {
+                       ASSERT(!dfp->length);
                        seenzero = 1;
                        continue;
                }
@@ -247,7 +225,7 @@ xfs_dir2_data_freefind(
        for (dfp = &d->hdr.bestfree[0];
             dfp < &d->hdr.bestfree[XFS_DIR2_DATA_FD_COUNT];
             dfp++) {
-               if (INT_ISZERO(dfp->offset, ARCH_CONVERT))
+               if (!dfp->offset)
                        return NULL;
                if (INT_GET(dfp->offset, ARCH_CONVERT) == off)
                        return dfp;
@@ -304,7 +282,7 @@ xfs_dir2_data_freeinsert(
 /*
  * Remove a bestfree entry from the table.
  */
-void
+STATIC void
 xfs_dir2_data_freeremove(
        xfs_dir2_data_t         *d,             /* data block pointer */
        xfs_dir2_data_free_t    *dfp,           /* bestfree entry pointer */
@@ -334,8 +312,8 @@ xfs_dir2_data_freeremove(
        /*
         * Clear the 3rd entry, must be zero now.
         */
-       INT_ZERO(d->hdr.bestfree[2].length, ARCH_CONVERT);
-       INT_ZERO(d->hdr.bestfree[2].offset, ARCH_CONVERT);
+       d->hdr.bestfree[2].length = 0;
+       d->hdr.bestfree[2].offset = 0;
        *loghead = 1;
 }
 
@@ -372,7 +350,7 @@ xfs_dir2_data_freescan(
                endp = aendp;
        else if (INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_BLOCK_MAGIC) {
                btp = XFS_DIR2_BLOCK_TAIL_P(mp, (xfs_dir2_block_t *)d);
-               endp = (char *)XFS_DIR2_BLOCK_LEAF_P_ARCH(btp, ARCH_CONVERT);
+               endp = (char *)XFS_DIR2_BLOCK_LEAF_P(btp);
        } else
                endp = (char *)d + mp->m_dirblksize;
        /*
@@ -385,7 +363,7 @@ xfs_dir2_data_freescan(
                 */
                if (INT_GET(dup->freetag, ARCH_CONVERT) == XFS_DIR2_DATA_FREE_TAG) {
                        ASSERT((char *)dup - (char *)d ==
-                              INT_GET(*XFS_DIR2_DATA_UNUSED_TAG_P_ARCH(dup, ARCH_CONVERT), ARCH_CONVERT));
+                              INT_GET(*XFS_DIR2_DATA_UNUSED_TAG_P(dup), ARCH_CONVERT));
                        xfs_dir2_data_freeinsert(d, dup, loghead);
                        p += INT_GET(dup->length, ARCH_CONVERT);
                }
@@ -440,8 +418,8 @@ xfs_dir2_data_init(
        INT_SET(d->hdr.magic, ARCH_CONVERT, XFS_DIR2_DATA_MAGIC);
        INT_SET(d->hdr.bestfree[0].offset, ARCH_CONVERT, (xfs_dir2_data_off_t)sizeof(d->hdr));
        for (i = 1; i < XFS_DIR2_DATA_FD_COUNT; i++) {
-               INT_ZERO(d->hdr.bestfree[i].length, ARCH_CONVERT);
-               INT_ZERO(d->hdr.bestfree[i].offset, ARCH_CONVERT);
+               d->hdr.bestfree[i].length = 0;
+               d->hdr.bestfree[i].offset = 0;
        }
        /*
         * Set up an unused entry for the block's body.
@@ -452,7 +430,7 @@ xfs_dir2_data_init(
        t=mp->m_dirblksize - (uint)sizeof(d->hdr);
        INT_SET(d->hdr.bestfree[0].length, ARCH_CONVERT, t);
        INT_SET(dup->length, ARCH_CONVERT, t);
-       INT_SET(*XFS_DIR2_DATA_UNUSED_TAG_P_ARCH(dup, ARCH_CONVERT), ARCH_CONVERT,
+       INT_SET(*XFS_DIR2_DATA_UNUSED_TAG_P(dup), ARCH_CONVERT,
                (xfs_dir2_data_off_t)((char *)dup - (char *)d));
        /*
         * Log it and return it.
@@ -523,8 +501,8 @@ xfs_dir2_data_log_unused(
         * Log the end (tag) of the unused entry.
         */
        xfs_da_log_buf(tp, bp,
-               (uint)((char *)XFS_DIR2_DATA_UNUSED_TAG_P_ARCH(dup, ARCH_CONVERT) - (char *)d),
-               (uint)((char *)XFS_DIR2_DATA_UNUSED_TAG_P_ARCH(dup, ARCH_CONVERT) - (char *)d +
+               (uint)((char *)XFS_DIR2_DATA_UNUSED_TAG_P(dup) - (char *)d),
+               (uint)((char *)XFS_DIR2_DATA_UNUSED_TAG_P(dup) - (char *)d +
                       sizeof(xfs_dir2_data_off_t) - 1));
 }
 
@@ -562,7 +540,7 @@ xfs_dir2_data_make_free(
 
                ASSERT(INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_BLOCK_MAGIC);
                btp = XFS_DIR2_BLOCK_TAIL_P(mp, (xfs_dir2_block_t *)d);
-               endptr = (char *)XFS_DIR2_BLOCK_LEAF_P_ARCH(btp, ARCH_CONVERT);
+               endptr = (char *)XFS_DIR2_BLOCK_LEAF_P(btp);
        }
        /*
         * If this isn't the start of the block, then back up to
@@ -608,12 +586,12 @@ xfs_dir2_data_make_free(
                 * since the third bestfree is there, there might be more
                 * entries.
                 */
-               needscan = !INT_ISZERO(d->hdr.bestfree[2].length, ARCH_CONVERT);
+               needscan = d->hdr.bestfree[2].length;
                /*
                 * 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_ARCH(prevdup, ARCH_CONVERT), ARCH_CONVERT,
+               INT_SET(*XFS_DIR2_DATA_UNUSED_TAG_P(prevdup), ARCH_CONVERT,
                        (xfs_dir2_data_off_t)((char *)prevdup - (char *)d));
                xfs_dir2_data_log_unused(tp, bp, prevdup);
                if (!needscan) {
@@ -637,8 +615,8 @@ xfs_dir2_data_make_free(
                        dfp = xfs_dir2_data_freeinsert(d, prevdup, needlogp);
                        ASSERT(dfp == &d->hdr.bestfree[0]);
                        ASSERT(INT_GET(dfp->length, ARCH_CONVERT) == INT_GET(prevdup->length, ARCH_CONVERT));
-                       ASSERT(INT_ISZERO(dfp[1].length, ARCH_CONVERT));
-                       ASSERT(INT_ISZERO(dfp[2].length, ARCH_CONVERT));
+                       ASSERT(!dfp[1].length);
+                       ASSERT(!dfp[2].length);
                }
        }
        /*
@@ -647,7 +625,7 @@ 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_ARCH(prevdup, ARCH_CONVERT), ARCH_CONVERT,
+               INT_SET(*XFS_DIR2_DATA_UNUSED_TAG_P(prevdup), ARCH_CONVERT,
                        (xfs_dir2_data_off_t)((char *)prevdup - (char *)d));
                xfs_dir2_data_log_unused(tp, bp, prevdup);
                /*
@@ -673,7 +651,7 @@ xfs_dir2_data_make_free(
                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_ARCH(newdup, ARCH_CONVERT), ARCH_CONVERT,
+               INT_SET(*XFS_DIR2_DATA_UNUSED_TAG_P(newdup), ARCH_CONVERT,
                        (xfs_dir2_data_off_t)((char *)newdup - (char *)d));
                xfs_dir2_data_log_unused(tp, bp, newdup);
                /*
@@ -698,7 +676,7 @@ xfs_dir2_data_make_free(
                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_ARCH(newdup, ARCH_CONVERT), ARCH_CONVERT,
+               INT_SET(*XFS_DIR2_DATA_UNUSED_TAG_P(newdup), ARCH_CONVERT,
                        (xfs_dir2_data_off_t)((char *)newdup - (char *)d));
                xfs_dir2_data_log_unused(tp, bp, newdup);
                (void)xfs_dir2_data_freeinsert(d, newdup, needlogp);
@@ -734,7 +712,7 @@ xfs_dir2_data_use_free(
        ASSERT(INT_GET(dup->freetag, ARCH_CONVERT) == 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_ARCH(dup, ARCH_CONVERT), ARCH_CONVERT));
+       ASSERT((char *)dup - (char *)d == INT_GET(*XFS_DIR2_DATA_UNUSED_TAG_P(dup), ARCH_CONVERT));
        /*
         * Look up the entry in the bestfree table.
         */
@@ -754,7 +732,7 @@ xfs_dir2_data_use_free(
         */
        if (matchfront && matchback) {
                if (dfp) {
-                       needscan = !INT_ISZERO(d->hdr.bestfree[2].offset, ARCH_CONVERT);
+                       needscan = d->hdr.bestfree[2].offset;
                        if (!needscan)
                                xfs_dir2_data_freeremove(d, dfp, needlogp);
                }
@@ -767,7 +745,7 @@ xfs_dir2_data_use_free(
                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_ARCH(newdup, ARCH_CONVERT), ARCH_CONVERT,
+               INT_SET(*XFS_DIR2_DATA_UNUSED_TAG_P(newdup), ARCH_CONVERT,
                        (xfs_dir2_data_off_t)((char *)newdup - (char *)d));
                xfs_dir2_data_log_unused(tp, bp, newdup);
                /*
@@ -795,7 +773,7 @@ xfs_dir2_data_use_free(
                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_ARCH(newdup, ARCH_CONVERT), ARCH_CONVERT,
+               INT_SET(*XFS_DIR2_DATA_UNUSED_TAG_P(newdup), ARCH_CONVERT,
                        (xfs_dir2_data_off_t)((char *)newdup - (char *)d));
                xfs_dir2_data_log_unused(tp, bp, newdup);
                /*
@@ -823,13 +801,13 @@ xfs_dir2_data_use_free(
                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_ARCH(newdup, ARCH_CONVERT), ARCH_CONVERT,
+               INT_SET(*XFS_DIR2_DATA_UNUSED_TAG_P(newdup), ARCH_CONVERT,
                        (xfs_dir2_data_off_t)((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_ARCH(newdup2, ARCH_CONVERT), ARCH_CONVERT,
+               INT_SET(*XFS_DIR2_DATA_UNUSED_TAG_P(newdup2), ARCH_CONVERT,
                        (xfs_dir2_data_off_t)((char *)newdup2 - (char *)d));
                xfs_dir2_data_log_unused(tp, bp, newdup2);
                /*
@@ -841,7 +819,7 @@ xfs_dir2_data_use_free(
                 * the 2 new will work.
                 */
                if (dfp) {
-                       needscan = !INT_ISZERO(d->hdr.bestfree[2].length, ARCH_CONVERT);
+                       needscan = d->hdr.bestfree[2].length;
                        if (!needscan) {
                                xfs_dir2_data_freeremove(d, dfp, needlogp);
                                (void)xfs_dir2_data_freeinsert(d, newdup,