]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blobdiff - libxfs/xfs_dir2_block.c
Undoes mod: xfs-cmds:slinx:120772a
[thirdparty/xfsprogs-dev.git] / libxfs / xfs_dir2_block.c
index 9cf677314f91b3e6d61b4acacf2073d0dc569c70..a60d276c880769dbcba5ef2ffa72bb8485b6afd5 100644 (file)
@@ -55,16 +55,16 @@ xfs_dir2_block_addname(
        xfs_inode_t             *dp;            /* directory inode */
        xfs_dir2_data_unused_t  *dup;           /* block unused entry */
        int                     error;          /* error return value */
-       xfs_dir2_data_unused_t  *enddup;        /* unused at end of data */
+       xfs_dir2_data_unused_t  *enddup=NULL;   /* unused at end of data */
        xfs_dahash_t            hash;           /* hash value of found entry */
        int                     high;           /* high index for binary srch */
        int                     highstale;      /* high stale index */
-       int                     lfloghigh;      /* last final leaf to log */
-       int                     lfloglow;       /* first final leaf to log */
+       int                     lfloghigh=0;    /* last final leaf to log */
+       int                     lfloglow=0;     /* first final leaf to log */
        int                     len;            /* length of the new entry */
        int                     low;            /* low index for binary srch */
        int                     lowstale;       /* low stale index */
-       int                     mid;            /* midpoint for binary srch */
+       int                     mid=0;          /* midpoint for binary srch */
        xfs_mount_t             *mp;            /* filesystem mount point */
        int                     needlog;        /* need to log header */
        int                     needscan;       /* need to rescan freespace */
@@ -78,9 +78,8 @@ xfs_dir2_block_addname(
        /*
         * Read the (one and only) directory block into dabuf bp.
         */
-       if (error =
-           xfs_da_read_buf(tp, dp, mp->m_dirdatablk, -1, &bp, XFS_DATA_FORK)) {
-#pragma mips_frequency_hint NEVER
+       if ((error =
+           xfs_da_read_buf(tp, dp, mp->m_dirdatablk, -1, &bp, XFS_DATA_FORK))) {
                return error;
        }
        ASSERT(bp != NULL);
@@ -89,7 +88,6 @@ xfs_dir2_block_addname(
         * Check the magic number, corrupted if wrong.
         */
        if (INT_GET(block->hdr.magic, ARCH_CONVERT) != XFS_DIR2_BLOCK_MAGIC) {
-#pragma mips_frequency_hint NEVER
                xfs_da_brelse(tp, bp);
                return XFS_ERROR(EFSCORRUPTED);
        }
@@ -103,7 +101,7 @@ xfs_dir2_block_addname(
        /*
         * No stale entries?  Need space for entry and new leaf.
         */
-       if (INT_GET(btp->stale, ARCH_CONVERT) == 0) {
+       if (INT_ISZERO(btp->stale, ARCH_CONVERT)) {
                /*
                 * Tag just before the first leaf entry.
                 */
@@ -131,7 +129,6 @@ xfs_dir2_block_addname(
                                 * to hold the new leaf too?
                                 */
                                if (INT_GET(dup->length, ARCH_CONVERT) < len + (uint)sizeof(*blp)) {
-#pragma mips_frequency_hint NEVER
                                        /*
                                         * Yes, we use the second-largest
                                         * entry instead if it works.
@@ -149,7 +146,6 @@ xfs_dir2_block_addname(
                                 * just check its length.
                                 */
                                if (INT_GET(dup->length, ARCH_CONVERT) < len) {
-#pragma mips_frequency_hint NEVER
                                        dup = NULL;
                                }
                        }
@@ -169,7 +165,6 @@ xfs_dir2_block_addname(
         * Will need to compact to make this work.
         */
        else {
-#pragma mips_frequency_hint NEVER
                /*
                 * Tag just before the first leaf entry.
                 */
@@ -201,7 +196,6 @@ xfs_dir2_block_addname(
         * If we don't have space for the new entry & leaf ...
         */
        if (!dup) {
-#pragma mips_frequency_hint NEVER
                /*
                 * Not trying to actually do anything, or don't have
                 * a space reservation: return no-space.
@@ -230,7 +224,6 @@ xfs_dir2_block_addname(
         * XXX should be the one closest to mid but mid is not yet computed.
         */
        if (compact) {
-#pragma mips_frequency_hint NEVER
                int     fromidx;                /* source leaf index */
                int     toidx;                  /* target leaf index */
 
@@ -291,13 +284,12 @@ xfs_dir2_block_addname(
                        high = mid - 1;
        }
        while (mid >= 0 && INT_GET(blp[mid].hashval, ARCH_CONVERT) >= args->hashval) {
-#pragma mips_frequency_hint NEVER
                mid--;
        }
        /*
         * No stale entries, will use enddup space to hold new leaf.
         */
-       if (INT_GET(btp->stale, ARCH_CONVERT) == 0) {
+       if (INT_ISZERO(btp->stale, ARCH_CONVERT)) {
                /*
                 * Mark the space needed for the new leaf entry, now in use.
                 */
@@ -477,7 +469,7 @@ xfs_dir2_block_lookup(
         * Get the buffer, look up the entry.
         * If not found (ENOENT) then return, have no buffer.
         */
-       if (error = xfs_dir2_block_lookup_int(args, &bp, &ent))
+       if ((error = xfs_dir2_block_lookup_int(args, &bp, &ent)))
                return error;
        dp = args->dp;
        mp = dp->i_mount;
@@ -528,9 +520,8 @@ xfs_dir2_block_lookup_int(
        /*
         * Read the buffer, return error if we can't get it.
         */
-       if (error =
-           xfs_da_read_buf(tp, dp, mp->m_dirdatablk, -1, &bp, XFS_DATA_FORK)) {
-#pragma mips_frequency_hint NEVER
+       if ((error =
+           xfs_da_read_buf(tp, dp, mp->m_dirdatablk, -1, &bp, XFS_DATA_FORK))) {
                return error;
        }
        ASSERT(bp != NULL);
@@ -561,7 +552,6 @@ xfs_dir2_block_lookup_int(
         * Back up to the first one with the right hash value.
         */
        while (mid > 0 && INT_GET(blp[mid - 1].hashval, ARCH_CONVERT) == args->hashval) {
-#pragma mips_frequency_hint NEVER
                mid--;
        }
        /*
@@ -623,8 +613,7 @@ xfs_dir2_block_removename(
         * Look up the entry in the block.  Gets the buffer and entry index.
         * It will always be there, the vnodeops level does a lookup first.
         */
-       if (error = xfs_dir2_block_lookup_int(args, &bp, &ent)) {
-#pragma mips_frequency_hint NEVER
+       if ((error = xfs_dir2_block_lookup_int(args, &bp, &ent))) {
                return error;
        }
        dp = args->dp;
@@ -701,8 +690,7 @@ xfs_dir2_block_replace(
         * Lookup the entry in the directory.  Get buffer and entry index.
         * This will always succeed since the caller has already done a lookup.
         */
-       if (error = xfs_dir2_block_lookup_int(args, &bp, &ent)) {
-#pragma mips_frequency_hint NEVER
+       if ((error = xfs_dir2_block_lookup_int(args, &bp, &ent))) {
                return error;
        }
        dp = args->dp;
@@ -788,10 +776,9 @@ xfs_dir2_leaf_to_block(
                bestsp = XFS_DIR2_LEAF_BESTS_P_ARCH(ltp, ARCH_CONVERT);
                if (INT_GET(bestsp[INT_GET(ltp->bestcount, ARCH_CONVERT) - 1], ARCH_CONVERT) ==
                    mp->m_dirblksize - (uint)sizeof(block->hdr)) {
-#pragma mips_frequency_hint NEVER
-                       if (error =
+                       if ((error =
                            xfs_dir2_leaf_trim_data(args, lbp,
-                                   (xfs_dir2_db_t)(INT_GET(ltp->bestcount, ARCH_CONVERT) - 1)))
+                                   (xfs_dir2_db_t)(INT_GET(ltp->bestcount, ARCH_CONVERT) - 1))))
                                goto out;
                } else {
                        error = 0;
@@ -804,7 +791,6 @@ xfs_dir2_leaf_to_block(
        if (dbp == NULL &&
            (error = xfs_da_read_buf(tp, dp, mp->m_dirdatablk, -1, &dbp,
                    XFS_DATA_FORK))) {
-#pragma mips_frequency_hint NEVER
                goto out;
        }
        block = dbp->data;
@@ -842,7 +828,7 @@ xfs_dir2_leaf_to_block(
         */
        btp = XFS_DIR2_BLOCK_TAIL_P(mp, block);
        INT_SET(btp->count, ARCH_CONVERT, INT_GET(leaf->hdr.count, ARCH_CONVERT) - INT_GET(leaf->hdr.stale, ARCH_CONVERT));
-       INT_SET(btp->stale, ARCH_CONVERT, 0);
+       INT_ZERO(btp->stale, ARCH_CONVERT);
        xfs_dir2_block_log_tail(tp, dbp);
        /*
         * Initialize the block leaf area.  We compact out stale entries.
@@ -869,7 +855,6 @@ xfs_dir2_leaf_to_block(
        error = xfs_da_shrink_inode(args, mp->m_dirleafblk, lbp);
        lbp = NULL;
        if (error) {
-#pragma mips_frequency_hint NEVER
                goto out;
        }
        /*
@@ -901,7 +886,8 @@ xfs_dir2_sf_to_block(
        xfs_dir2_leaf_entry_t   *blp;           /* block leaf entries */
        xfs_dabuf_t             *bp;            /* block buffer */
        xfs_dir2_block_tail_t   *btp;           /* block tail pointer */
-       char                    buf[XFS_DIR2_SF_MAX_SIZE];      /* sf buffer */
+       char                    *buf;           /* sf buffer */
+       int                     buf_len;
        xfs_dir2_data_entry_t   *dep;           /* data entry pointer */
        xfs_inode_t             *dp;            /* incore directory inode */
        int                     dummy;          /* trash */
@@ -928,7 +914,6 @@ xfs_dir2_sf_to_block(
         * Bomb out if the shortform directory is way too short.
         */
        if (dp->i_d.di_size < offsetof(xfs_dir2_sf_hdr_t, parent)) {
-#pragma mips_frequency_hint NEVER
                ASSERT(XFS_FORCED_SHUTDOWN(mp));
                return XFS_ERROR(EIO);
        }
@@ -940,6 +925,10 @@ xfs_dir2_sf_to_block(
         * Copy the directory into the stack buffer.
         * Then pitch the incore inode data so we can make extents.
         */
+
+       buf_len = dp->i_df.if_bytes;
+       buf = kmem_alloc(dp->i_df.if_bytes, KM_SLEEP);
+
        bcopy(sfp, buf, dp->i_df.if_bytes);
        xfs_idata_realloc(dp, -dp->i_df.if_bytes, XFS_DATA_FORK);
        dp->i_d.di_size = 0;
@@ -953,7 +942,7 @@ xfs_dir2_sf_to_block(
         */
        error = xfs_dir2_grow_inode(args, XFS_DIR2_DATA_SPACE, &blkno);
        if (error) {
-#pragma mips_frequency_hint NEVER
+               kmem_free(buf, buf_len);
                return error;
        }
        /*
@@ -961,7 +950,7 @@ xfs_dir2_sf_to_block(
         */
        error = xfs_dir2_data_init(args, blkno, &bp);
        if (error) {
-#pragma mips_frequency_hint NEVER
+               kmem_free(buf, buf_len);
                return error;
        }
        block = bp->data;
@@ -1077,6 +1066,8 @@ xfs_dir2_sf_to_block(
                else
                        sfep = XFS_DIR2_SF_NEXTENTRY(sfp, sfep);
        }
+       /* Done with the temporary buffer */
+       kmem_free(buf, buf_len);
        /*
         * Sort the leaf entries by hash value.
         */