linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / fs / xfs / xfs_dir2_leaf.c
index c75d54f..d342b6b 100644 (file)
@@ -1,49 +1,26 @@
 /*
- * Copyright (c) 2000-2003 Silicon Graphics, Inc.  All Rights Reserved.
+ * Copyright (c) 2000-2003,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_leaf.c
- * XFS directory version 2 implementation - single leaf form
- * see xfs_dir2_leaf.h for data structures.
- * These directories have multiple XFS_DIR2_DATA blocks and one
- * XFS_DIR2_LEAF1 block containing the hash table and freespace map.
- */
-
 #include "xfs.h"
-
-#include "xfs_macros.h"
+#include "xfs_fs.h"
 #include "xfs_types.h"
-#include "xfs_inum.h"
+#include "xfs_bit.h"
 #include "xfs_log.h"
+#include "xfs_inum.h"
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
@@ -51,6 +28,7 @@
 #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_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_bmap.h"
-#include "xfs_da_btree.h"
 #include "xfs_dir2_data.h"
 #include "xfs_dir2_leaf.h"
 #include "xfs_dir2_block.h"
 #include "xfs_dir2_node.h"
 #include "xfs_dir2_trace.h"
 #include "xfs_error.h"
-#include "xfs_bit.h"
 
 /*
  * Local function declarations.
@@ -77,6 +53,10 @@ static void xfs_dir2_leaf_check(xfs_inode_t *dp, xfs_dabuf_t *bp);
 #endif
 static int xfs_dir2_leaf_lookup_int(xfs_da_args_t *args, xfs_dabuf_t **lbpp,
                                    int *indexp, xfs_dabuf_t **dbpp);
+static void xfs_dir2_leaf_log_bests(struct xfs_trans *tp, struct xfs_dabuf *bp,
+                                   int first, int last);
+static void xfs_dir2_leaf_log_tail(struct xfs_trans *tp, struct xfs_dabuf *bp);
+
 
 /*
  * Convert a block form directory to a leaf form directory.
@@ -127,7 +107,7 @@ xfs_dir2_block_to_leaf(
        block = dbp->data;
        xfs_dir2_data_check(dp, dbp);
        btp = XFS_DIR2_BLOCK_TAIL_P(mp, block);
-       blp = XFS_DIR2_BLOCK_LEAF_P_ARCH(btp, ARCH_CONVERT);
+       blp = XFS_DIR2_BLOCK_LEAF_P(btp);
        /*
         * Set the counts in the leaf header.
         */
@@ -162,7 +142,7 @@ xfs_dir2_block_to_leaf(
         */
        ltp = XFS_DIR2_LEAF_TAIL_P(mp, leaf);
        INT_SET(ltp->bestcount, ARCH_CONVERT, 1);
-       bestsp = XFS_DIR2_LEAF_BESTS_P_ARCH(ltp, ARCH_CONVERT);
+       bestsp = XFS_DIR2_LEAF_BESTS_P(ltp);
        INT_COPY(bestsp[0], block->hdr.bestfree[0].length, ARCH_CONVERT);
        /*
         * Log the data header and leaf bests table.
@@ -233,7 +213,7 @@ xfs_dir2_leaf_addname(
        index = xfs_dir2_leaf_search_hash(args, lbp);
        leaf = lbp->data;
        ltp = XFS_DIR2_LEAF_TAIL_P(mp, leaf);
-       bestsp = XFS_DIR2_LEAF_BESTS_P_ARCH(ltp, ARCH_CONVERT);
+       bestsp = XFS_DIR2_LEAF_BESTS_P(ltp);
        length = XFS_DIR2_DATA_ENTSIZE(args->namelen);
        /*
         * See if there are any entries with the same hash value
@@ -274,7 +254,7 @@ xfs_dir2_leaf_addname(
         * How many bytes do we need in the leaf block?
         */
        needbytes =
-               (!INT_ISZERO(leaf->hdr.stale, ARCH_CONVERT) ? 0 : (uint)sizeof(leaf->ents[0])) +
+               (leaf->hdr.stale ? 0 : (uint)sizeof(leaf->ents[0])) +
                (use_block != -1 ? 0 : (uint)sizeof(leaf->bests[0]));
        /*
         * Now kill use_block if it refers to a missing block, so we
@@ -456,7 +436,7 @@ xfs_dir2_leaf_addname(
         * Now we need to make room to insert the leaf entry.
         * If there are no stale entries, we just insert a hole at index.
         */
-       if (INT_ISZERO(leaf->hdr.stale, ARCH_CONVERT)) {
+       if (!leaf->hdr.stale) {
                /*
                 * lep is still good as the index leaf entry.
                 */
@@ -595,7 +575,7 @@ xfs_dir2_leaf_check(
         * Leaves and bests don't overlap.
         */
        ASSERT((char *)&leaf->ents[INT_GET(leaf->hdr.count, ARCH_CONVERT)] <=
-              (char *)XFS_DIR2_LEAF_BESTS_P_ARCH(ltp, ARCH_CONVERT));
+              (char *)XFS_DIR2_LEAF_BESTS_P(ltp));
        /*
         * Check hash value order, count stale entries.
         */
@@ -625,7 +605,7 @@ xfs_dir2_leaf_compact(
        int             to;             /* target leaf index */
 
        leaf = bp->data;
-       if (INT_ISZERO(leaf->hdr.stale, ARCH_CONVERT)) {
+       if (!leaf->hdr.stale) {
                return;
        }
        /*
@@ -649,7 +629,7 @@ xfs_dir2_leaf_compact(
         */
        ASSERT(INT_GET(leaf->hdr.stale, ARCH_CONVERT) == from - to);
        INT_MOD(leaf->hdr.count, ARCH_CONVERT, -(INT_GET(leaf->hdr.stale, ARCH_CONVERT)));
-       INT_ZERO(leaf->hdr.stale, ARCH_CONVERT);
+       leaf->hdr.stale = 0;
        xfs_dir2_leaf_log_header(args->trans, bp);
        if (loglow != -1)
                xfs_dir2_leaf_log_ents(args->trans, bp, loglow, to - 1);
@@ -1192,10 +1172,10 @@ xfs_dir2_leaf_init(
         * Initialize the header.
         */
        INT_SET(leaf->hdr.info.magic, ARCH_CONVERT, magic);
-       INT_ZERO(leaf->hdr.info.forw, ARCH_CONVERT);
-       INT_ZERO(leaf->hdr.info.back, ARCH_CONVERT);
-       INT_ZERO(leaf->hdr.count, ARCH_CONVERT);
-       INT_ZERO(leaf->hdr.stale, ARCH_CONVERT);
+       leaf->hdr.info.forw = 0;
+       leaf->hdr.info.back = 0;
+       leaf->hdr.count = 0;
+       leaf->hdr.stale = 0;
        xfs_dir2_leaf_log_header(tp, bp);
        /*
         * If it's a leaf-format directory initialize the tail.
@@ -1204,7 +1184,7 @@ xfs_dir2_leaf_init(
         */
        if (magic == XFS_DIR2_LEAF1_MAGIC) {
                ltp = XFS_DIR2_LEAF_TAIL_P(mp, leaf);
-               INT_ZERO(ltp->bestcount, ARCH_CONVERT);
+               ltp->bestcount = 0;
                xfs_dir2_leaf_log_tail(tp, bp);
        }
        *bpp = bp;
@@ -1214,7 +1194,7 @@ xfs_dir2_leaf_init(
 /*
  * Log the bests entries indicated from a leaf1 block.
  */
-void
+static void
 xfs_dir2_leaf_log_bests(
        xfs_trans_t             *tp,            /* transaction pointer */
        xfs_dabuf_t             *bp,            /* leaf buffer */
@@ -1229,8 +1209,8 @@ xfs_dir2_leaf_log_bests(
        leaf = bp->data;
        ASSERT(INT_GET(leaf->hdr.info.magic, ARCH_CONVERT) == XFS_DIR2_LEAF1_MAGIC);
        ltp = XFS_DIR2_LEAF_TAIL_P(tp->t_mountp, leaf);
-       firstb = XFS_DIR2_LEAF_BESTS_P_ARCH(ltp, ARCH_CONVERT) + first;
-       lastb = XFS_DIR2_LEAF_BESTS_P_ARCH(ltp, ARCH_CONVERT) + last;
+       firstb = XFS_DIR2_LEAF_BESTS_P(ltp) + first;
+       lastb = XFS_DIR2_LEAF_BESTS_P(ltp) + last;
        xfs_da_log_buf(tp, bp, (uint)((char *)firstb - (char *)leaf),
                (uint)((char *)lastb - (char *)leaf + sizeof(*lastb) - 1));
 }
@@ -1278,7 +1258,7 @@ xfs_dir2_leaf_log_header(
 /*
  * Log the tail of the leaf1 block.
  */
-void
+STATIC void
 xfs_dir2_leaf_log_tail(
        xfs_trans_t             *tp,            /* transaction pointer */
        xfs_dabuf_t             *bp)            /* leaf buffer */
@@ -1497,7 +1477,7 @@ xfs_dir2_leaf_removename(
        needscan = needlog = 0;
        oldbest = INT_GET(data->hdr.bestfree[0].length, ARCH_CONVERT);
        ltp = XFS_DIR2_LEAF_TAIL_P(mp, leaf);
-       bestsp = XFS_DIR2_LEAF_BESTS_P_ARCH(ltp, ARCH_CONVERT);
+       bestsp = XFS_DIR2_LEAF_BESTS_P(ltp);
        ASSERT(INT_GET(bestsp[db], ARCH_CONVERT) == oldbest);
        /*
         * Mark the former data entry unused.
@@ -1658,7 +1638,7 @@ xfs_dir2_leaf_search_hash(
 
        leaf = lbp->data;
 #ifndef __KERNEL__
-       if (INT_ISZERO(leaf->hdr.count, ARCH_CONVERT))
+       if (!leaf->hdr.count)
                return 0;
 #endif
        /*
@@ -1749,7 +1729,7 @@ xfs_dir2_leaf_trim_data(
        /*
         * Eliminate the last bests entry from the table.
         */
-       bestsp = XFS_DIR2_LEAF_BESTS_P_ARCH(ltp, ARCH_CONVERT);
+       bestsp = XFS_DIR2_LEAF_BESTS_P(ltp);
        INT_MOD(ltp->bestcount, ARCH_CONVERT, -1);
        memmove(&bestsp[1], &bestsp[0], INT_GET(ltp->bestcount, ARCH_CONVERT) * sizeof(*bestsp));
        xfs_dir2_leaf_log_tail(tp, lbp);
@@ -1835,7 +1815,7 @@ xfs_dir2_node_to_leaf(
        }
        free = fbp->data;
        ASSERT(INT_GET(free->hdr.magic, ARCH_CONVERT) == XFS_DIR2_FREE_MAGIC);
-       ASSERT(INT_ISZERO(free->hdr.firstdb, ARCH_CONVERT));
+       ASSERT(!free->hdr.firstdb);
        /*
         * Now see if the leafn and free data will fit in a leaf1.
         * If not, release the buffer and give up.
@@ -1865,7 +1845,7 @@ xfs_dir2_node_to_leaf(
        /*
         * Set up the leaf bests table.
         */
-       memcpy(XFS_DIR2_LEAF_BESTS_P_ARCH(ltp, ARCH_CONVERT), free->bests,
+       memcpy(XFS_DIR2_LEAF_BESTS_P(ltp), free->bests,
                INT_GET(ltp->bestcount, ARCH_CONVERT) * sizeof(leaf->bests[0]));
        xfs_dir2_leaf_log_bests(tp, lbp, 0, INT_GET(ltp->bestcount, ARCH_CONVERT) - 1);
        xfs_dir2_leaf_log_tail(tp, lbp);