xfs: kill some warnings on i386 builds
[safe/jmp/linux-2.6] / fs / xfs / xfs_dir2_leaf.c
index e7c12fa..29f484c 100644 (file)
@@ -38,8 +38,8 @@
 #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_trace.h"
 
 /*
  * Local function declarations.
@@ -80,7 +80,8 @@ xfs_dir2_block_to_leaf(
        int                     needscan;       /* need to rescan bestfree */
        xfs_trans_t             *tp;            /* transaction pointer */
 
-       xfs_dir2_trace_args_b("block_to_leaf", args, dbp);
+       trace_xfs_dir2_block_to_leaf(args);
+
        dp = args->dp;
        mp = dp->i_mount;
        tp = args->trans;
@@ -188,7 +189,8 @@ xfs_dir2_leaf_addname(
        xfs_trans_t             *tp;            /* transaction pointer */
        xfs_dir2_db_t           use_block;      /* data block number */
 
-       xfs_dir2_trace_args("leaf_addname", args);
+       trace_xfs_dir2_leaf_addname(args);
+
        dp = args->dp;
        tp = args->trans;
        mp = dp->i_mount;
@@ -263,20 +265,21 @@ xfs_dir2_leaf_addname(
         * If we don't have enough free bytes but we can make enough
         * by compacting out stale entries, we'll do that.
         */
-       if ((char *)bestsp - (char *)&leaf->ents[be16_to_cpu(leaf->hdr.count)] < needbytes &&
-           be16_to_cpu(leaf->hdr.stale) > 1) {
+       if ((char *)bestsp - (char *)&leaf->ents[be16_to_cpu(leaf->hdr.count)] <
+                               needbytes && be16_to_cpu(leaf->hdr.stale) > 1) {
                compact = 1;
        }
        /*
         * Otherwise if we don't have enough free bytes we need to
         * convert to node form.
         */
-       else if ((char *)bestsp - (char *)&leaf->ents[be16_to_cpu(leaf->hdr.count)] <
-                needbytes) {
+       else if ((char *)bestsp - (char *)&leaf->ents[be16_to_cpu(
+                                               leaf->hdr.count)] < needbytes) {
                /*
                 * Just checking or no space reservation, give up.
                 */
-               if (args->justcheck || args->total == 0) {
+               if ((args->op_flags & XFS_DA_OP_JUSTCHECK) ||
+                                                       args->total == 0) {
                        xfs_da_brelse(tp, lbp);
                        return XFS_ERROR(ENOSPC);
                }
@@ -301,7 +304,7 @@ xfs_dir2_leaf_addname(
         * If just checking, then it will fit unless we needed to allocate
         * a new data block.
         */
-       if (args->justcheck) {
+       if (args->op_flags & XFS_DA_OP_JUSTCHECK) {
                xfs_da_brelse(tp, lbp);
                return use_block == -1 ? XFS_ERROR(ENOSPC) : 0;
        }
@@ -359,7 +362,7 @@ xfs_dir2_leaf_addname(
                        bestsp--;
                        memmove(&bestsp[0], &bestsp[1],
                                be32_to_cpu(ltp->bestcount) * sizeof(bestsp[0]));
-                       be32_add(&ltp->bestcount, 1);
+                       be32_add_cpu(&ltp->bestcount, 1);
                        xfs_dir2_leaf_log_tail(tp, lbp);
                        xfs_dir2_leaf_log_bests(tp, lbp, 0, be32_to_cpu(ltp->bestcount) - 1);
                }
@@ -445,7 +448,7 @@ xfs_dir2_leaf_addname(
                 */
                lfloglow = index;
                lfloghigh = be16_to_cpu(leaf->hdr.count);
-               be16_add(&leaf->hdr.count, 1);
+               be16_add_cpu(&leaf->hdr.count, 1);
        }
        /*
         * There are stale entries.
@@ -523,7 +526,7 @@ xfs_dir2_leaf_addname(
                        lfloglow = MIN(index, lfloglow);
                        lfloghigh = MAX(highstale, lfloghigh);
                }
-               be16_add(&leaf->hdr.stale, -1);
+               be16_add_cpu(&leaf->hdr.stale, -1);
        }
        /*
         * Fill in the new leaf entry.
@@ -548,7 +551,7 @@ xfs_dir2_leaf_addname(
  * Check the internal consistency of a leaf1 block.
  * Pop an assert if something is wrong.
  */
-void
+STATIC void
 xfs_dir2_leaf_check(
        xfs_inode_t             *dp,            /* incore directory inode */
        xfs_dabuf_t             *bp)            /* leaf's buffer */
@@ -626,7 +629,7 @@ xfs_dir2_leaf_compact(
         * Update and log the header, log the leaf entries.
         */
        ASSERT(be16_to_cpu(leaf->hdr.stale) == from - to);
-       be16_add(&leaf->hdr.count, -(be16_to_cpu(leaf->hdr.stale)));
+       be16_add_cpu(&leaf->hdr.count, -(be16_to_cpu(leaf->hdr.stale)));
        leaf->hdr.stale = 0;
        xfs_dir2_leaf_log_header(args->trans, bp);
        if (loglow != -1)
@@ -728,7 +731,7 @@ xfs_dir2_leaf_compact_x1(
        /*
         * Adjust the leaf header values.
         */
-       be16_add(&leaf->hdr.count, -(from - to));
+       be16_add_cpu(&leaf->hdr.count, -(from - to));
        leaf->hdr.stale = cpu_to_be16(1);
        /*
         * Remember the low/high stale value only in the "right"
@@ -779,7 +782,6 @@ xfs_dir2_leaf_getdents(
        int                     ra_index;       /* *map index for read-ahead */
        int                     ra_offset;      /* map entry offset for ra */
        int                     ra_want;        /* readahead count wanted */
-       xfs_ino_t               ino;
 
        /*
         * If the offset is at or past the largest allowed value,
@@ -854,6 +856,7 @@ xfs_dir2_leaf_getdents(
                         */
                        ra_want = howmany(bufsize + mp->m_dirblksize,
                                          mp->m_sb.sb_blocksize) - 1;
+                       ASSERT(ra_want >= 0);
 
                        /*
                         * If we don't have as many as we want, and we haven't
@@ -1075,24 +1078,12 @@ xfs_dir2_leaf_getdents(
                        continue;
                }
 
-               /*
-                * Copy the entry into the putargs, and try formatting it.
-                */
                dep = (xfs_dir2_data_entry_t *)ptr;
-
                length = xfs_dir2_data_entsize(dep->namelen);
 
-               ino = be64_to_cpu(dep->inumber);
-#if XFS_BIG_INUMS
-               ino += mp->m_inoadd;
-#endif
-
-               /*
-                * Won't fit.  Return to caller.
-                */
                if (filldir(dirent, dep->name, dep->namelen,
-                           xfs_dir2_byte_to_dataptr(mp, curoff + length),
-                           ino, DT_UNKNOWN))
+                           xfs_dir2_byte_to_dataptr(mp, curoff) & 0x7fffffff,
+                           be64_to_cpu(dep->inumber), DT_UNKNOWN))
                        break;
 
                /*
@@ -1100,17 +1091,18 @@ xfs_dir2_leaf_getdents(
                 */
                ptr += length;
                curoff += length;
-               bufsize -= length;
+               /* bufsize may have just been a guess; don't go negative */
+               bufsize = bufsize > length ? bufsize - length : 0;
        }
 
        /*
         * All done.  Set output offset value to current offset.
         */
        if (curoff > xfs_dir2_dataptr_to_byte(mp, XFS_DIR2_MAX_DATAPTR))
-               *offset = XFS_DIR2_MAX_DATAPTR;
+               *offset = XFS_DIR2_MAX_DATAPTR & 0x7fffffff;
        else
-               *offset = xfs_dir2_byte_to_dataptr(mp, curoff);
-       kmem_free(map, map_size * sizeof(*map));
+               *offset = xfs_dir2_byte_to_dataptr(mp, curoff) & 0x7fffffff;
+       kmem_free(map);
        if (bp)
                xfs_da_brelse(NULL, bp);
        return error;
@@ -1276,7 +1268,8 @@ xfs_dir2_leaf_lookup(
        xfs_dir2_leaf_entry_t   *lep;           /* leaf entry */
        xfs_trans_t             *tp;            /* transaction pointer */
 
-       xfs_dir2_trace_args("leaf_lookup", args);
+       trace_xfs_dir2_leaf_lookup(args);
+
        /*
         * Look up name in the leaf block, returning both buffers and index.
         */
@@ -1298,12 +1291,13 @@ xfs_dir2_leaf_lookup(
              ((char *)dbp->data +
               xfs_dir2_dataptr_to_off(dp->i_mount, be32_to_cpu(lep->address)));
        /*
-        * Return the found inode number.
+        * Return the found inode number & CI name if appropriate
         */
        args->inumber = be64_to_cpu(dep->inumber);
+       error = xfs_dir_cilookup_result(args, dep->name, dep->namelen);
        xfs_da_brelse(tp, dbp);
        xfs_da_brelse(tp, lbp);
-       return XFS_ERROR(EEXIST);
+       return XFS_ERROR(error);
 }
 
 /*
@@ -1319,8 +1313,8 @@ xfs_dir2_leaf_lookup_int(
        int                     *indexp,        /* out: index in leaf block */
        xfs_dabuf_t             **dbpp)         /* out: data buffer */
 {
-       xfs_dir2_db_t           curdb;          /* current data block number */
-       xfs_dabuf_t             *dbp;           /* data buffer */
+       xfs_dir2_db_t           curdb = -1;     /* current data block number */
+       xfs_dabuf_t             *dbp = NULL;    /* data buffer */
        xfs_dir2_data_entry_t   *dep;           /* data entry */
        xfs_inode_t             *dp;            /* incore directory inode */
        int                     error;          /* error return code */
@@ -1331,6 +1325,8 @@ xfs_dir2_leaf_lookup_int(
        xfs_mount_t             *mp;            /* filesystem mount point */
        xfs_dir2_db_t           newdb;          /* new data block number */
        xfs_trans_t             *tp;            /* transaction pointer */
+       xfs_dir2_db_t           cidb = -1;      /* case match data block no. */
+       enum xfs_dacmp          cmp;            /* name compare result */
 
        dp = args->dp;
        tp = args->trans;
@@ -1338,11 +1334,10 @@ xfs_dir2_leaf_lookup_int(
        /*
         * Read the leaf block into the buffer.
         */
-       if ((error =
-           xfs_da_read_buf(tp, dp, mp->m_dirleafblk, -1, &lbp,
-                   XFS_DATA_FORK))) {
+       error = xfs_da_read_buf(tp, dp, mp->m_dirleafblk, -1, &lbp,
+                                                       XFS_DATA_FORK);
+       if (error)
                return error;
-       }
        *lbpp = lbp;
        leaf = lbp->data;
        xfs_dir2_leaf_check(dp, lbp);
@@ -1354,9 +1349,9 @@ xfs_dir2_leaf_lookup_int(
         * Loop over all the entries with the right hash value
         * looking to match the name.
         */
-       for (lep = &leaf->ents[index], dbp = NULL, curdb = -1;
-            index < be16_to_cpu(leaf->hdr.count) && be32_to_cpu(lep->hashval) == args->hashval;
-            lep++, index++) {
+       for (lep = &leaf->ents[index]; index < be16_to_cpu(leaf->hdr.count) &&
+                               be32_to_cpu(lep->hashval) == args->hashval;
+                               lep++, index++) {
                /*
                 * Skip over stale leaf entries.
                 */
@@ -1373,10 +1368,10 @@ xfs_dir2_leaf_lookup_int(
                if (newdb != curdb) {
                        if (dbp)
                                xfs_da_brelse(tp, dbp);
-                       if ((error =
-                           xfs_da_read_buf(tp, dp,
-                                   xfs_dir2_db_to_da(mp, newdb), -1, &dbp,
-                                   XFS_DATA_FORK))) {
+                       error = xfs_da_read_buf(tp, dp,
+                                               xfs_dir2_db_to_da(mp, newdb),
+                                               -1, &dbp, XFS_DATA_FORK);
+                       if (error) {
                                xfs_da_brelse(tp, lbp);
                                return error;
                        }
@@ -1386,24 +1381,50 @@ xfs_dir2_leaf_lookup_int(
                /*
                 * Point to the data entry.
                 */
-               dep = (xfs_dir2_data_entry_t *)
-                     ((char *)dbp->data +
-                      xfs_dir2_dataptr_to_off(mp, be32_to_cpu(lep->address)));
+               dep = (xfs_dir2_data_entry_t *)((char *)dbp->data +
+                       xfs_dir2_dataptr_to_off(mp, be32_to_cpu(lep->address)));
                /*
-                * If it matches then return it.
+                * Compare name and if it's an exact match, return the index
+                * and buffer. If it's the first case-insensitive match, store
+                * the index and buffer and continue looking for an exact match.
                 */
-               if (dep->namelen == args->namelen &&
-                   dep->name[0] == args->name[0] &&
-                   memcmp(dep->name, args->name, args->namelen) == 0) {
-                       *dbpp = dbp;
+               cmp = mp->m_dirnameops->compname(args, dep->name, dep->namelen);
+               if (cmp != XFS_CMP_DIFFERENT && cmp != args->cmpresult) {
+                       args->cmpresult = cmp;
                        *indexp = index;
-                       return 0;
+                       /* case exact match: return the current buffer. */
+                       if (cmp == XFS_CMP_EXACT) {
+                               *dbpp = dbp;
+                               return 0;
+                       }
+                       cidb = curdb;
                }
        }
+       ASSERT(args->op_flags & XFS_DA_OP_OKNOENT);
+       /*
+        * Here, we can only be doing a lookup (not a rename or remove).
+        * If a case-insensitive match was found earlier, re-read the
+        * appropriate data block if required and return it.
+        */
+       if (args->cmpresult == XFS_CMP_CASE) {
+               ASSERT(cidb != -1);
+               if (cidb != curdb) {
+                       xfs_da_brelse(tp, dbp);
+                       error = xfs_da_read_buf(tp, dp,
+                                               xfs_dir2_db_to_da(mp, cidb),
+                                               -1, &dbp, XFS_DATA_FORK);
+                       if (error) {
+                               xfs_da_brelse(tp, lbp);
+                               return error;
+                       }
+               }
+               *dbpp = dbp;
+               return 0;
+       }
        /*
         * No match found, return ENOENT.
         */
-       ASSERT(args->oknoent);
+       ASSERT(cidb == -1);
        if (dbp)
                xfs_da_brelse(tp, dbp);
        xfs_da_brelse(tp, lbp);
@@ -1436,7 +1457,8 @@ xfs_dir2_leaf_removename(
        xfs_dir2_data_off_t     oldbest;        /* old value of best free */
        xfs_trans_t             *tp;            /* transaction pointer */
 
-       xfs_dir2_trace_args("leaf_removename", args);
+       trace_xfs_dir2_leaf_removename(args);
+
        /*
         * Lookup the leaf entry, get the leaf and data blocks read in.
         */
@@ -1470,7 +1492,7 @@ xfs_dir2_leaf_removename(
        /*
         * We just mark the leaf entry stale by putting a null in it.
         */
-       be16_add(&leaf->hdr.stale, 1);
+       be16_add_cpu(&leaf->hdr.stale, 1);
        xfs_dir2_leaf_log_header(tp, lbp);
        lep->address = cpu_to_be32(XFS_DIR2_NULL_DATAPTR);
        xfs_dir2_leaf_log_ents(tp, lbp, index, index);
@@ -1531,7 +1553,7 @@ xfs_dir2_leaf_removename(
                         */
                        memmove(&bestsp[db - i], bestsp,
                                (be32_to_cpu(ltp->bestcount) - (db - i)) * sizeof(*bestsp));
-                       be32_add(&ltp->bestcount, -(db - i));
+                       be32_add_cpu(&ltp->bestcount, -(db - i));
                        xfs_dir2_leaf_log_tail(tp, lbp);
                        xfs_dir2_leaf_log_bests(tp, lbp, 0, be32_to_cpu(ltp->bestcount) - 1);
                } else
@@ -1568,7 +1590,8 @@ xfs_dir2_leaf_replace(
        xfs_dir2_leaf_entry_t   *lep;           /* leaf entry */
        xfs_trans_t             *tp;            /* transaction pointer */
 
-       xfs_dir2_trace_args("leaf_replace", args);
+       trace_xfs_dir2_leaf_replace(args);
+
        /*
         * Look up the entry.
         */
@@ -1712,7 +1735,7 @@ xfs_dir2_leaf_trim_data(
         * Eliminate the last bests entry from the table.
         */
        bestsp = xfs_dir2_leaf_bests_p(ltp);
-       be32_add(&ltp->bestcount, -1);
+       be32_add_cpu(&ltp->bestcount, -1);
        memmove(&bestsp[1], &bestsp[0], be32_to_cpu(ltp->bestcount) * sizeof(*bestsp));
        xfs_dir2_leaf_log_tail(tp, lbp);
        xfs_dir2_leaf_log_bests(tp, lbp, 0, be32_to_cpu(ltp->bestcount) - 1);
@@ -1748,7 +1771,9 @@ xfs_dir2_node_to_leaf(
        if (state->path.active > 1)
                return 0;
        args = state->args;
-       xfs_dir2_trace_args("node_to_leaf", args);
+
+       trace_xfs_dir2_node_to_leaf(args);
+
        mp = state->mp;
        dp = args->dp;
        tp = args->trans;