]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blobdiff - libxfs/xfs_dir2_data.c
Update copyright/license notices to match SGI legal prefered boilerplate.
[thirdparty/xfsprogs-dev.git] / libxfs / xfs_dir2_data.c
index d921a21cc0cee3cd8f2aa0a2ce3f6484f9c98fe8..1f2488241b5375d82c6aa88d6b623effe3c6686c 100644 (file)
@@ -1,33 +1,19 @@
 /*
- * Copyright (c) 2000 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
+ * 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 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.
- * 
- * 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/
+ *
+ * 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.
+ *
+ * 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
  */
 
 /*
  * Core data block handling routines for XFS V2 directories.
  * See xfs_dir2_data.h for data structures.
  */
+
 #include <xfs.h>
 
+
 #ifdef DEBUG
 /*
  * Check the consistency of the data block.
@@ -50,7 +38,7 @@ xfs_dir2_data_check(
 {
        xfs_dir2_dataptr_t      addr;           /* addr for leaf lookup */
        xfs_dir2_data_free_t    *bf;            /* bestfree table */
-       xfs_dir2_block_tail_t   *btp;           /* block tail */
+       xfs_dir2_block_tail_t   *btp=NULL;      /* block tail */
        int                     count;          /* count of entries found */
        xfs_dir2_data_t         *d;             /* data block pointer */
        xfs_dir2_data_entry_t   *dep;           /* data entry */
@@ -61,7 +49,7 @@ xfs_dir2_data_check(
        xfs_dahash_t            hash;           /* hash of current name */
        int                     i;              /* leaf index */
        int                     lastfree;       /* last entry was unused */
-       xfs_dir2_leaf_entry_t   *lep;           /* block leaf entries */
+       xfs_dir2_leaf_entry_t   *lep=NULL;      /* block leaf entries */
        xfs_mount_t             *mp;            /* filesystem mount point */
        char                    *p;             /* current data position */
        int                     stale;          /* count of stale leaves */
@@ -74,7 +62,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;
@@ -82,16 +70,16 @@ xfs_dir2_data_check(
        /*
         * Account for zero bestfree entries.
         */
-       if (INT_GET(bf[0].length, ARCH_CONVERT) == 0) {
-               ASSERT(INT_GET(bf[0].offset, ARCH_CONVERT) == 0);
+       if (!bf[0].length) {
+               ASSERT(!bf[0].offset);
                freeseen |= 1 << 0;
        }
-       if (INT_GET(bf[1].length, ARCH_CONVERT) == 0) {
-               ASSERT(INT_GET(bf[1].offset, ARCH_CONVERT) == 0);
+       if (!bf[1].length) {
+               ASSERT(!bf[1].offset);
                freeseen |= 1 << 1;
        }
-       if (INT_GET(bf[2].length, ARCH_CONVERT) == 0) {
-               ASSERT(INT_GET(bf[2].offset, ARCH_CONVERT) == 0);
+       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));
@@ -103,12 +91,12 @@ xfs_dir2_data_check(
                dup = (xfs_dir2_data_unused_t *)p;
                /*
                 * If it's unused, look for the space in the bestfree table.
-                * If we find it, account for that, else make sure it 
+                * If we find it, account for that, else make sure it
                 * doesn't need to be there.
                 */
                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) {
@@ -123,7 +111,7 @@ xfs_dir2_data_check(
                }
                /*
                 * It's a real entry.  Validate the fields.
-                * If this is a block directory then make sure it's 
+                * If this is a block directory then make sure it's
                 * in the leaf section of the block.
                 * The linear search is crude but this is DEBUG code.
                 */
@@ -193,8 +181,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_GET(dfp->offset, ARCH_CONVERT) == 0) {
-                       ASSERT(INT_GET(dfp->length, ARCH_CONVERT) == 0);
+               if (!dfp->offset) {
+                       ASSERT(!dfp->length);
                        seenzero = 1;
                        continue;
                }
@@ -223,7 +211,7 @@ xfs_dir2_data_freefind(
        for (dfp = &d->hdr.bestfree[0];
             dfp < &d->hdr.bestfree[XFS_DIR2_DATA_FD_COUNT];
             dfp++) {
-               if (INT_GET(dfp->offset, ARCH_CONVERT) == 0)
+               if (!dfp->offset)
                        return NULL;
                if (INT_GET(dfp->offset, ARCH_CONVERT) == off)
                        return dfp;
@@ -251,7 +239,7 @@ xfs_dir2_data_freeinsert(
               INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_BLOCK_MAGIC);
 #endif
        dfp = d->hdr.bestfree;
-       INT_COPY(new.length, dup->length, ARCH_CONVERT); 
+       INT_COPY(new.length, dup->length, ARCH_CONVERT);
        INT_SET(new.offset, ARCH_CONVERT, (xfs_dir2_data_off_t)((char *)dup - (char *)d));
        /*
         * Insert at position 0, 1, or 2; or not at all.
@@ -310,8 +298,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;
 }
 
@@ -338,7 +326,7 @@ xfs_dir2_data_freescan(
        /*
         * Start by clearing the table.
         */
-       bzero(d->hdr.bestfree, sizeof(d->hdr.bestfree));
+       memset(d->hdr.bestfree, 0, sizeof(d->hdr.bestfree));
        *loghead = 1;
        /*
         * Set up pointers.
@@ -348,7 +336,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;
        /*
@@ -361,7 +349,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);
                }
@@ -395,7 +383,7 @@ xfs_dir2_data_init(
        int                     i;              /* bestfree index */
        xfs_mount_t             *mp;            /* filesystem mount point */
        xfs_trans_t             *tp;            /* transaction pointer */
-        int                     t;              /* temp */
+       int                     t;              /* temp */
 
        dp = args->dp;
        mp = dp->i_mount;
@@ -406,7 +394,6 @@ xfs_dir2_data_init(
        error = xfs_da_get_buf(tp, dp, XFS_DIR2_DB_TO_DA(mp, blkno), -1, &bp,
                XFS_DATA_FORK);
        if (error) {
-#pragma mips_frequency_hint NEVER
                return error;
        }
        ASSERT(bp != NULL);
@@ -417,19 +404,19 @@ 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.
         */
        dup = &d->u[0].unused;
        INT_SET(dup->freetag, ARCH_CONVERT, XFS_DIR2_DATA_FREE_TAG);
-        
-        t=mp->m_dirblksize - (uint)sizeof(d->hdr);
-        INT_SET(d->hdr.bestfree[0].length, ARCH_CONVERT, t);
+
+       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.
@@ -472,7 +459,7 @@ xfs_dir2_data_log_header(
        d = bp->data;
        ASSERT(INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_DATA_MAGIC ||
               INT_GET(d->hdr.magic, ARCH_CONVERT) == XFS_DIR2_BLOCK_MAGIC);
-       xfs_da_log_buf(tp, bp, (uint)((char *)&d->hdr - (char *)d), 
+       xfs_da_log_buf(tp, bp, (uint)((char *)&d->hdr - (char *)d),
                (uint)(sizeof(d->hdr) - 1));
 }
 
@@ -500,8 +487,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));
 }
 
@@ -539,10 +526,10 @@ 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 
+        * If this isn't the start of the block, then back up to
         * the previous entry and see if it's free.
         */
        if (offset > sizeof(d->hdr)) {
@@ -568,7 +555,7 @@ xfs_dir2_data_make_free(
        ASSERT(*needscanp == 0);
        needscan = 0;
        /*
-        * Previous and following entries are both free, 
+        * Previous and following entries are both free,
         * merge everything into a single free entry.
         */
        if (prevdup && postdup) {
@@ -585,17 +572,17 @@ xfs_dir2_data_make_free(
                 * since the third bestfree is there, there might be more
                 * entries.
                 */
-               needscan = INT_GET(d->hdr.bestfree[2].length, ARCH_CONVERT) != 0;
+               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) {
                        /*
-                        * Has to be the case that entries 0 and 1 are 
+                        * Has to be the case that entries 0 and 1 are
                         * dfp and dfp2 (don't know which is which), and
                         * entry 2 is empty.
                         * Remove entry 1 first then entry 0.
@@ -614,8 +601,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_GET(dfp[1].length, ARCH_CONVERT) == 0);
-                       ASSERT(INT_GET(dfp[2].length, ARCH_CONVERT) == 0);
+                       ASSERT(!dfp[1].length);
+                       ASSERT(!dfp[2].length);
                }
        }
        /*
@@ -624,7 +611,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);
                /*
@@ -650,7 +637,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);
                /*
@@ -675,7 +662,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);
@@ -711,7 +698,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.
         */
@@ -731,7 +718,7 @@ xfs_dir2_data_use_free(
         */
        if (matchfront && matchback) {
                if (dfp) {
-                       needscan = INT_GET(d->hdr.bestfree[2].offset, ARCH_CONVERT) != 0;
+                       needscan = d->hdr.bestfree[2].offset;
                        if (!needscan)
                                xfs_dir2_data_freeremove(d, dfp, needlogp);
                }
@@ -744,7 +731,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);
                /*
@@ -772,7 +759,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);
                /*
@@ -800,13 +787,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);
                /*
@@ -818,7 +805,7 @@ xfs_dir2_data_use_free(
                 * the 2 new will work.
                 */
                if (dfp) {
-                       needscan = INT_GET(d->hdr.bestfree[2].length, ARCH_CONVERT) != 0;
+                       needscan = d->hdr.bestfree[2].length;
                        if (!needscan) {
                                xfs_dir2_data_freeremove(d, dfp, needlogp);
                                (void)xfs_dir2_data_freeinsert(d, newdup,