]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/xfs/xfs_dir2_block.c
[NET]: Make socket creation namespace safe.
[linux-2.6-omap-h63xx.git] / fs / xfs / xfs_dir2_block.c
index 972ded595476982dbb960e54245e01bcd86b477a..e4df1aaae2a2083c911d864d102641e6da80644f 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_inode_item.h"
-#include "xfs_dir_leaf.h"
 #include "xfs_dir2_data.h"
 #include "xfs_dir2_leaf.h"
 #include "xfs_dir2_block.h"
@@ -51,6 +48,18 @@ static int xfs_dir2_block_lookup_int(xfs_da_args_t *args, xfs_dabuf_t **bpp,
                                     int *entno);
 static int xfs_dir2_block_sort(const void *a, const void *b);
 
+static xfs_dahash_t xfs_dir_hash_dot, xfs_dir_hash_dotdot;
+
+/*
+ * One-time startup routine called from xfs_init().
+ */
+void
+xfs_dir_startup(void)
+{
+       xfs_dir_hash_dot = xfs_da_hashname(".", 1);
+       xfs_dir_hash_dotdot = xfs_da_hashname("..", 2);
+}
+
 /*
  * Add an entry to a block directory.
  */
@@ -106,13 +115,13 @@ xfs_dir2_block_addname(
                xfs_da_brelse(tp, bp);
                return XFS_ERROR(EFSCORRUPTED);
        }
-       len = XFS_DIR2_DATA_ENTSIZE(args->namelen);
+       len = xfs_dir2_data_entsize(args->namelen);
        /*
         * Set up pointers to parts of the block.
         */
        bf = block->hdr.bestfree;
-       btp = XFS_DIR2_BLOCK_TAIL_P(mp, block);
-       blp = XFS_DIR2_BLOCK_LEAF_P(btp);
+       btp = xfs_dir2_block_tail_p(mp, block);
+       blp = xfs_dir2_block_leaf_p(btp);
        /*
         * No stale entries?  Need space for entry and new leaf.
         */
@@ -273,8 +282,7 @@ xfs_dir2_block_addname(
                 * This needs to happen before the next call to use_free.
                 */
                if (needscan) {
-                       xfs_dir2_data_freescan(mp, (xfs_dir2_data_t *)block,
-                               &needlog, NULL);
+                       xfs_dir2_data_freescan(mp, (xfs_dir2_data_t *)block, &needlog);
                        needscan = 0;
                }
        }
@@ -324,7 +332,7 @@ xfs_dir2_block_addname(
                 */
                if (needscan) {
                        xfs_dir2_data_freescan(mp, (xfs_dir2_data_t *)block,
-                               &needlog, NULL);
+                               &needlog);
                        needscan = 0;
                }
                /*
@@ -388,7 +396,7 @@ xfs_dir2_block_addname(
         * Fill in the leaf entry.
         */
        blp[mid].hashval = cpu_to_be32(args->hashval);
-       blp[mid].address = cpu_to_be32(XFS_DIR2_BYTE_TO_DATAPTR(mp,
+       blp[mid].address = cpu_to_be32(xfs_dir2_byte_to_dataptr(mp,
                                (char *)dep - (char *)block));
        xfs_dir2_block_log_leaf(tp, bp, lfloglow, lfloghigh);
        /*
@@ -400,17 +408,16 @@ xfs_dir2_block_addname(
        /*
         * Create the new data entry.
         */
-       INT_SET(dep->inumber, ARCH_CONVERT, args->inumber);
+       dep->inumber = cpu_to_be64(args->inumber);
        dep->namelen = args->namelen;
        memcpy(dep->name, args->name, args->namelen);
-       tagp = XFS_DIR2_DATA_ENTRY_TAG_P(dep);
+       tagp = xfs_dir2_data_entry_tag_p(dep);
        *tagp = cpu_to_be16((char *)dep - (char *)block);
        /*
         * Clean up the bestfree array and log the header, tail, and entry.
         */
        if (needscan)
-               xfs_dir2_data_freescan(mp, (xfs_dir2_data_t *)block, &needlog,
-                       NULL);
+               xfs_dir2_data_freescan(mp, (xfs_dir2_data_t *)block, &needlog);
        if (needlog)
                xfs_dir2_data_log_header(tp, bp);
        xfs_dir2_block_log_tail(tp, bp);
@@ -448,7 +455,7 @@ xfs_dir2_block_getdents(
        /*
         * If the block number in the offset is out of range, we're done.
         */
-       if (XFS_DIR2_DATAPTR_TO_DB(mp, uio->uio_offset) > mp->m_dirdatablk) {
+       if (xfs_dir2_dataptr_to_db(mp, uio->uio_offset) > mp->m_dirdatablk) {
                *eofp = 1;
                return 0;
        }
@@ -464,15 +471,15 @@ xfs_dir2_block_getdents(
         * Extract the byte offset we start at from the seek pointer.
         * We'll skip entries before this.
         */
-       wantoff = XFS_DIR2_DATAPTR_TO_OFF(mp, uio->uio_offset);
+       wantoff = xfs_dir2_dataptr_to_off(mp, uio->uio_offset);
        block = bp->data;
        xfs_dir2_data_check(dp, bp);
        /*
         * Set up values for the loop.
         */
-       btp = XFS_DIR2_BLOCK_TAIL_P(mp, block);
+       btp = xfs_dir2_block_tail_p(mp, block);
        ptr = (char *)block->u;
-       endptr = (char *)XFS_DIR2_BLOCK_LEAF_P(btp);
+       endptr = (char *)xfs_dir2_block_leaf_p(btp);
        p.dbp = dbp;
        p.put = put;
        p.uio = uio;
@@ -495,7 +502,7 @@ xfs_dir2_block_getdents(
                /*
                 * Bump pointer for the next iteration.
                 */
-               ptr += XFS_DIR2_DATA_ENTSIZE(dep->namelen);
+               ptr += xfs_dir2_data_entsize(dep->namelen);
                /*
                 * The entry is before the desired starting point, skip it.
                 */
@@ -506,9 +513,9 @@ xfs_dir2_block_getdents(
                 */
                p.namelen = dep->namelen;
 
-               p.cook = XFS_DIR2_DB_OFF_TO_DATAPTR(mp, mp->m_dirdatablk,
+               p.cook = xfs_dir2_db_off_to_dataptr(mp, mp->m_dirdatablk,
                                                    ptr - (char *)block);
-               p.ino = INT_GET(dep->inumber, ARCH_CONVERT);
+               p.ino = be64_to_cpu(dep->inumber);
 #if XFS_BIG_INUMS
                p.ino += mp->m_inoadd;
 #endif
@@ -524,7 +531,7 @@ xfs_dir2_block_getdents(
                 */
                if (!p.done) {
                        uio->uio_offset =
-                               XFS_DIR2_DB_OFF_TO_DATAPTR(mp, mp->m_dirdatablk,
+                               xfs_dir2_db_off_to_dataptr(mp, mp->m_dirdatablk,
                                        (char *)dep - (char *)block);
                        xfs_da_brelse(tp, bp);
                        return error;
@@ -538,7 +545,7 @@ xfs_dir2_block_getdents(
        *eofp = 1;
 
        uio->uio_offset =
-               XFS_DIR2_DB_OFF_TO_DATAPTR(mp, mp->m_dirdatablk + 1, 0);
+               xfs_dir2_db_off_to_dataptr(mp, mp->m_dirdatablk + 1, 0);
 
        xfs_da_brelse(tp, bp);
 
@@ -562,8 +569,8 @@ xfs_dir2_block_log_leaf(
 
        mp = tp->t_mountp;
        block = bp->data;
-       btp = XFS_DIR2_BLOCK_TAIL_P(mp, block);
-       blp = XFS_DIR2_BLOCK_LEAF_P(btp);
+       btp = xfs_dir2_block_tail_p(mp, block);
+       blp = xfs_dir2_block_leaf_p(btp);
        xfs_da_log_buf(tp, bp, (uint)((char *)&blp[first] - (char *)block),
                (uint)((char *)&blp[last + 1] - (char *)block - 1));
 }
@@ -582,7 +589,7 @@ xfs_dir2_block_log_tail(
 
        mp = tp->t_mountp;
        block = bp->data;
-       btp = XFS_DIR2_BLOCK_TAIL_P(mp, block);
+       btp = xfs_dir2_block_tail_p(mp, block);
        xfs_da_log_buf(tp, bp, (uint)((char *)btp - (char *)block),
                (uint)((char *)(btp + 1) - (char *)block - 1));
 }
@@ -616,17 +623,17 @@ xfs_dir2_block_lookup(
        mp = dp->i_mount;
        block = bp->data;
        xfs_dir2_data_check(dp, bp);
-       btp = XFS_DIR2_BLOCK_TAIL_P(mp, block);
-       blp = XFS_DIR2_BLOCK_LEAF_P(btp);
+       btp = xfs_dir2_block_tail_p(mp, block);
+       blp = xfs_dir2_block_leaf_p(btp);
        /*
         * Get the offset from the leaf entry, to point to the data.
         */
        dep = (xfs_dir2_data_entry_t *)
-             ((char *)block + XFS_DIR2_DATAPTR_TO_OFF(mp, be32_to_cpu(blp[ent].address)));
+             ((char *)block + xfs_dir2_dataptr_to_off(mp, be32_to_cpu(blp[ent].address)));
        /*
         * Fill in inode number, release the block.
         */
-       args->inumber = INT_GET(dep->inumber, ARCH_CONVERT);
+       args->inumber = be64_to_cpu(dep->inumber);
        xfs_da_brelse(args->trans, bp);
        return XFS_ERROR(EEXIST);
 }
@@ -668,8 +675,8 @@ xfs_dir2_block_lookup_int(
        ASSERT(bp != NULL);
        block = bp->data;
        xfs_dir2_data_check(dp, bp);
-       btp = XFS_DIR2_BLOCK_TAIL_P(mp, block);
-       blp = XFS_DIR2_BLOCK_LEAF_P(btp);
+       btp = xfs_dir2_block_tail_p(mp, block);
+       blp = xfs_dir2_block_leaf_p(btp);
        /*
         * Loop doing a binary search for our hash value.
         * Find our entry, ENOENT if it's not there.
@@ -706,7 +713,7 @@ xfs_dir2_block_lookup_int(
                 * Get pointer to the entry from the leaf.
                 */
                dep = (xfs_dir2_data_entry_t *)
-                       ((char *)block + XFS_DIR2_DATAPTR_TO_OFF(mp, addr));
+                       ((char *)block + xfs_dir2_dataptr_to_off(mp, addr));
                /*
                 * Compare, if it's right give back buffer & entry number.
                 */
@@ -761,20 +768,20 @@ xfs_dir2_block_removename(
        tp = args->trans;
        mp = dp->i_mount;
        block = bp->data;
-       btp = XFS_DIR2_BLOCK_TAIL_P(mp, block);
-       blp = XFS_DIR2_BLOCK_LEAF_P(btp);
+       btp = xfs_dir2_block_tail_p(mp, block);
+       blp = xfs_dir2_block_leaf_p(btp);
        /*
         * Point to the data entry using the leaf entry.
         */
        dep = (xfs_dir2_data_entry_t *)
-             ((char *)block + XFS_DIR2_DATAPTR_TO_OFF(mp, be32_to_cpu(blp[ent].address)));
+             ((char *)block + xfs_dir2_dataptr_to_off(mp, be32_to_cpu(blp[ent].address)));
        /*
         * Mark the data entry's space free.
         */
        needlog = needscan = 0;
        xfs_dir2_data_make_free(tp, bp,
                (xfs_dir2_data_aoff_t)((char *)dep - (char *)block),
-               XFS_DIR2_DATA_ENTSIZE(dep->namelen), &needlog, &needscan);
+               xfs_dir2_data_entsize(dep->namelen), &needlog, &needscan);
        /*
         * Fix up the block tail.
         */
@@ -789,8 +796,7 @@ xfs_dir2_block_removename(
         * Fix up bestfree, log the header if necessary.
         */
        if (needscan)
-               xfs_dir2_data_freescan(mp, (xfs_dir2_data_t *)block, &needlog,
-                       NULL);
+               xfs_dir2_data_freescan(mp, (xfs_dir2_data_t *)block, &needlog);
        if (needlog)
                xfs_dir2_data_log_header(tp, bp);
        xfs_dir2_data_check(dp, bp);
@@ -837,18 +843,18 @@ xfs_dir2_block_replace(
        dp = args->dp;
        mp = dp->i_mount;
        block = bp->data;
-       btp = XFS_DIR2_BLOCK_TAIL_P(mp, block);
-       blp = XFS_DIR2_BLOCK_LEAF_P(btp);
+       btp = xfs_dir2_block_tail_p(mp, block);
+       blp = xfs_dir2_block_leaf_p(btp);
        /*
         * Point to the data entry we need to change.
         */
        dep = (xfs_dir2_data_entry_t *)
-             ((char *)block + XFS_DIR2_DATAPTR_TO_OFF(mp, be32_to_cpu(blp[ent].address)));
-       ASSERT(INT_GET(dep->inumber, ARCH_CONVERT) != args->inumber);
+             ((char *)block + xfs_dir2_dataptr_to_off(mp, be32_to_cpu(blp[ent].address)));
+       ASSERT(be64_to_cpu(dep->inumber) != args->inumber);
        /*
         * Change the inode number to the new value.
         */
-       INT_SET(dep->inumber, ARCH_CONVERT, args->inumber);
+       dep->inumber = cpu_to_be64(args->inumber);
        xfs_dir2_data_log_entry(args->trans, bp, dep);
        xfs_dir2_data_check(dp, bp);
        xfs_da_buf_done(bp);
@@ -906,7 +912,7 @@ xfs_dir2_leaf_to_block(
        mp = dp->i_mount;
        leaf = lbp->data;
        ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_DIR2_LEAF1_MAGIC);
-       ltp = XFS_DIR2_LEAF_TAIL_P(mp, leaf);
+       ltp = xfs_dir2_leaf_tail_p(mp, leaf);
        /*
         * If there are data blocks other than the first one, take this
         * opportunity to remove trailing empty data blocks that may have
@@ -914,7 +920,7 @@ xfs_dir2_leaf_to_block(
         * These will show up in the leaf bests table.
         */
        while (dp->i_d.di_size > mp->m_dirblksize) {
-               bestsp = XFS_DIR2_LEAF_BESTS_P(ltp);
+               bestsp = xfs_dir2_leaf_bests_p(ltp);
                if (be16_to_cpu(bestsp[be32_to_cpu(ltp->bestcount) - 1]) ==
                    mp->m_dirblksize - (uint)sizeof(block->hdr)) {
                        if ((error =
@@ -968,14 +974,14 @@ xfs_dir2_leaf_to_block(
        /*
         * Initialize the block tail.
         */
-       btp = XFS_DIR2_BLOCK_TAIL_P(mp, block);
+       btp = xfs_dir2_block_tail_p(mp, block);
        btp->count = cpu_to_be32(be16_to_cpu(leaf->hdr.count) - be16_to_cpu(leaf->hdr.stale));
        btp->stale = 0;
        xfs_dir2_block_log_tail(tp, dbp);
        /*
         * Initialize the block leaf area.  We compact out stale entries.
         */
-       lep = XFS_DIR2_BLOCK_LEAF_P(btp);
+       lep = xfs_dir2_block_leaf_p(btp);
        for (from = to = 0; from < be16_to_cpu(leaf->hdr.count); from++) {
                if (be32_to_cpu(leaf->ents[from].address) == XFS_DIR2_NULL_DATAPTR)
                        continue;
@@ -987,8 +993,7 @@ xfs_dir2_leaf_to_block(
         * Scan the bestfree if we need it and log the data block header.
         */
        if (needscan)
-               xfs_dir2_data_freescan(mp, (xfs_dir2_data_t *)block, &needlog,
-                       NULL);
+               xfs_dir2_data_freescan(mp, (xfs_dir2_data_t *)block, &needlog);
        if (needlog)
                xfs_dir2_data_log_header(tp, dbp);
        /*
@@ -1062,7 +1067,7 @@ xfs_dir2_sf_to_block(
        ASSERT(dp->i_df.if_bytes == dp->i_d.di_size);
        ASSERT(dp->i_df.if_u1.if_data != NULL);
        sfp = (xfs_dir2_sf_t *)dp->i_df.if_u1.if_data;
-       ASSERT(dp->i_d.di_size >= XFS_DIR2_SF_HDR_SIZE(sfp->hdr.i8count));
+       ASSERT(dp->i_d.di_size >= xfs_dir2_sf_hdr_size(sfp->hdr.i8count));
        /*
         * Copy the directory into the stack buffer.
         * Then pitch the incore inode data so we can make extents.
@@ -1114,10 +1119,10 @@ xfs_dir2_sf_to_block(
        /*
         * Fill in the tail.
         */
-       btp = XFS_DIR2_BLOCK_TAIL_P(mp, block);
+       btp = xfs_dir2_block_tail_p(mp, block);
        btp->count = cpu_to_be32(sfp->hdr.count + 2);   /* ., .. */
        btp->stale = 0;
-       blp = XFS_DIR2_BLOCK_LEAF_P(btp);
+       blp = xfs_dir2_block_leaf_p(btp);
        endoffset = (uint)((char *)blp - (char *)block);
        /*
         * Remove the freespace, we'll manage it.
@@ -1130,28 +1135,28 @@ xfs_dir2_sf_to_block(
         */
        dep = (xfs_dir2_data_entry_t *)
              ((char *)block + XFS_DIR2_DATA_DOT_OFFSET);
-       INT_SET(dep->inumber, ARCH_CONVERT, dp->i_ino);
+       dep->inumber = cpu_to_be64(dp->i_ino);
        dep->namelen = 1;
        dep->name[0] = '.';
-       tagp = XFS_DIR2_DATA_ENTRY_TAG_P(dep);
+       tagp = xfs_dir2_data_entry_tag_p(dep);
        *tagp = cpu_to_be16((char *)dep - (char *)block);
        xfs_dir2_data_log_entry(tp, bp, dep);
        blp[0].hashval = cpu_to_be32(xfs_dir_hash_dot);
-       blp[0].address = cpu_to_be32(XFS_DIR2_BYTE_TO_DATAPTR(mp,
+       blp[0].address = cpu_to_be32(xfs_dir2_byte_to_dataptr(mp,
                                (char *)dep - (char *)block));
        /*
         * Create entry for ..
         */
        dep = (xfs_dir2_data_entry_t *)
                ((char *)block + XFS_DIR2_DATA_DOTDOT_OFFSET);
-       INT_SET(dep->inumber, ARCH_CONVERT, XFS_DIR2_SF_GET_INUMBER(sfp, &sfp->hdr.parent));
+       dep->inumber = cpu_to_be64(xfs_dir2_sf_get_inumber(sfp, &sfp->hdr.parent));
        dep->namelen = 2;
        dep->name[0] = dep->name[1] = '.';
-       tagp = XFS_DIR2_DATA_ENTRY_TAG_P(dep);
+       tagp = xfs_dir2_data_entry_tag_p(dep);
        *tagp = cpu_to_be16((char *)dep - (char *)block);
        xfs_dir2_data_log_entry(tp, bp, dep);
        blp[1].hashval = cpu_to_be32(xfs_dir_hash_dotdot);
-       blp[1].address = cpu_to_be32(XFS_DIR2_BYTE_TO_DATAPTR(mp,
+       blp[1].address = cpu_to_be32(xfs_dir2_byte_to_dataptr(mp,
                                (char *)dep - (char *)block));
        offset = XFS_DIR2_DATA_FIRST_OFFSET;
        /*
@@ -1160,7 +1165,7 @@ xfs_dir2_sf_to_block(
        if ((i = 0) == sfp->hdr.count)
                sfep = NULL;
        else
-               sfep = XFS_DIR2_SF_FIRSTENTRY(sfp);
+               sfep = xfs_dir2_sf_firstentry(sfp);
        /*
         * Need to preserve the existing offset values in the sf directory.
         * Insert holes (unused entries) where necessary.
@@ -1172,7 +1177,7 @@ xfs_dir2_sf_to_block(
                if (sfep == NULL)
                        newoffset = endoffset;
                else
-                       newoffset = XFS_DIR2_SF_GET_OFFSET(sfep);
+                       newoffset = xfs_dir2_sf_get_offset(sfep);
                /*
                 * There should be a hole here, make one.
                 */
@@ -1181,7 +1186,7 @@ xfs_dir2_sf_to_block(
                              ((char *)block + offset);
                        dup->freetag = cpu_to_be16(XFS_DIR2_DATA_FREE_TAG);
                        dup->length = cpu_to_be16(newoffset - offset);
-                       *XFS_DIR2_DATA_UNUSED_TAG_P(dup) = cpu_to_be16(
+                       *xfs_dir2_data_unused_tag_p(dup) = cpu_to_be16(
                                ((char *)dup - (char *)block));
                        xfs_dir2_data_log_unused(tp, bp, dup);
                        (void)xfs_dir2_data_freeinsert((xfs_dir2_data_t *)block,
@@ -1193,22 +1198,22 @@ xfs_dir2_sf_to_block(
                 * Copy a real entry.
                 */
                dep = (xfs_dir2_data_entry_t *)((char *)block + newoffset);
-               INT_SET(dep->inumber, ARCH_CONVERT, XFS_DIR2_SF_GET_INUMBER(sfp,
-                               XFS_DIR2_SF_INUMBERP(sfep)));
+               dep->inumber = cpu_to_be64(xfs_dir2_sf_get_inumber(sfp,
+                               xfs_dir2_sf_inumberp(sfep)));
                dep->namelen = sfep->namelen;
                memcpy(dep->name, sfep->name, dep->namelen);
-               tagp = XFS_DIR2_DATA_ENTRY_TAG_P(dep);
+               tagp = xfs_dir2_data_entry_tag_p(dep);
                *tagp = cpu_to_be16((char *)dep - (char *)block);
                xfs_dir2_data_log_entry(tp, bp, dep);
                blp[2 + i].hashval = cpu_to_be32(xfs_da_hashname(
                                        (char *)sfep->name, sfep->namelen));
-               blp[2 + i].address = cpu_to_be32(XFS_DIR2_BYTE_TO_DATAPTR(mp,
+               blp[2 + i].address = cpu_to_be32(xfs_dir2_byte_to_dataptr(mp,
                                                 (char *)dep - (char *)block));
                offset = (int)((char *)(tagp + 1) - (char *)block);
                if (++i == sfp->hdr.count)
                        sfep = NULL;
                else
-                       sfep = XFS_DIR2_SF_NEXTENTRY(sfp, sfep);
+                       sfep = xfs_dir2_sf_nextentry(sfp, sfep);
        }
        /* Done with the temporary buffer */
        kmem_free(buf, buf_len);