]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blobdiff - repair/phase6.c
Merge back recent changes from xfs kernel headers.
[thirdparty/xfsprogs-dev.git] / repair / phase6.c
index d0c988ed21a2fd67c9a0a1d6d53765f5aa294fe5..aa3d61c4b0039d3b048729c33245a40c89b2dbe7 100644 (file)
@@ -1,32 +1,32 @@
 /*
- * Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
- * 
+ * Copyright (c) 2000-2004 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
  * 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://www.sgi.com
+ *
+ * For further information regarding this notice, see:
+ *
  * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
  */
 
@@ -347,7 +347,7 @@ mk_rbmino(xfs_mount_t *mp)
        if ((i = libxfs_trans_reserve(tp, 10, 0, 0, 0, 0)))
                res_failed(i);
 
-       error = libxfs_trans_iget(mp, tp, mp->m_sb.sb_rbmino, 0, &ip);
+       error = libxfs_trans_iget(mp, tp, mp->m_sb.sb_rbmino, 0, 0, &ip);
        if (error) {
                do_error(
                _("couldn't iget realtime bitmap inode -- error - %d\n"),
@@ -357,7 +357,7 @@ mk_rbmino(xfs_mount_t *mp)
        bzero(&ip->i_d, sizeof(xfs_dinode_core_t));
 
        ip->i_d.di_magic = XFS_DINODE_MAGIC;
-       ip->i_d.di_mode = IFREG;
+       ip->i_d.di_mode = S_IFREG;
        ip->i_d.di_version = XFS_DINODE_VERSION_1;
        ip->i_d.di_format = XFS_DINODE_FMT_EXTENTS;
        ip->i_d.di_aformat = XFS_DINODE_FMT_EXTENTS;
@@ -440,7 +440,7 @@ fill_rbmino(xfs_mount_t *mp)
        if ((error = libxfs_trans_reserve(tp, 10, 0, 0, 0, 0)))
                res_failed(error);
 
-       error = libxfs_trans_iget(mp, tp, mp->m_sb.sb_rbmino, 0, &ip);
+       error = libxfs_trans_iget(mp, tp, mp->m_sb.sb_rbmino, 0, 0, &ip);
        if (error) {
                do_error(
                _("couldn't iget realtime bitmap inode -- error - %d\n"),
@@ -464,7 +464,7 @@ fill_rbmino(xfs_mount_t *mp)
 
                error = libxfs_trans_read_buf(
                                mp, tp, mp->m_dev,
-                               XFS_FSB_TO_DADDR(mp, map.br_startblock), 
+                               XFS_FSB_TO_DADDR(mp, map.br_startblock),
                                XFS_FSB_TO_BB(mp, 1), 1, &bp);
 
                if (error) {
@@ -510,7 +510,7 @@ fill_rsumino(xfs_mount_t *mp)
        if ((error = libxfs_trans_reserve(tp, 10, 0, 0, 0, 0)))
                res_failed(error);
 
-       error = libxfs_trans_iget(mp, tp, mp->m_sb.sb_rsumino, 0, &ip);
+       error = libxfs_trans_iget(mp, tp, mp->m_sb.sb_rsumino, 0, 0, &ip);
        if (error) {
                do_error(
                _("couldn't iget realtime summary inode -- error - %d\n"),
@@ -534,7 +534,7 @@ fill_rsumino(xfs_mount_t *mp)
 
                error = libxfs_trans_read_buf(
                                mp, tp, mp->m_dev,
-                               XFS_FSB_TO_DADDR(mp, map.br_startblock), 
+                               XFS_FSB_TO_DADDR(mp, map.br_startblock),
                                XFS_FSB_TO_BB(mp, 1), 1, &bp);
 
                if (error) {
@@ -582,7 +582,7 @@ mk_rsumino(xfs_mount_t *mp)
                                XFS_TRANS_PERM_LOG_RES, XFS_MKDIR_LOG_COUNT)))
                res_failed(i);
 
-       error = libxfs_trans_iget(mp, tp, mp->m_sb.sb_rsumino, 0, &ip);
+       error = libxfs_trans_iget(mp, tp, mp->m_sb.sb_rsumino, 0, 0, &ip);
        if (error) {
                do_error(
                _("couldn't iget realtime summary inode -- error - %d\n"),
@@ -592,7 +592,7 @@ mk_rsumino(xfs_mount_t *mp)
        bzero(&ip->i_d, sizeof(xfs_dinode_core_t));
 
        ip->i_d.di_magic = XFS_DINODE_MAGIC;
-       ip->i_d.di_mode = IFREG;
+       ip->i_d.di_mode = S_IFREG;
        ip->i_d.di_version = XFS_DINODE_VERSION_1;
        ip->i_d.di_format = XFS_DINODE_FMT_EXTENTS;
        ip->i_d.di_aformat = XFS_DINODE_FMT_EXTENTS;
@@ -648,7 +648,6 @@ mk_rsumino(xfs_mount_t *mp)
                        libxfs_device_zero(mp->m_dev,
                                      XFS_FSB_TO_DADDR(mp, ep->br_startblock),
                                      XFS_FSB_TO_BB(mp, ep->br_blockcount));
-                               do_error(_("dev_zero of rtbitmap failed\n"));
                        bno += ep->br_blockcount;
                }
        }
@@ -680,7 +679,7 @@ mk_root_dir(xfs_mount_t *mp)
                                XFS_TRANS_PERM_LOG_RES, XFS_MKDIR_LOG_COUNT)))
                res_failed(i);
 
-       error = libxfs_trans_iget(mp, tp, mp->m_sb.sb_rootino, 0, &ip);
+       error = libxfs_trans_iget(mp, tp, mp->m_sb.sb_rootino, 0, 0, &ip);
        if (error) {
                do_error(_("could not iget root inode -- error - %d\n"), error);
        }
@@ -691,7 +690,7 @@ mk_root_dir(xfs_mount_t *mp)
        bzero(&ip->i_d, sizeof(xfs_dinode_core_t));
 
        ip->i_d.di_magic = XFS_DINODE_MAGIC;
-       ip->i_d.di_mode = (__uint16_t) mode|IFDIR;
+       ip->i_d.di_mode = (__uint16_t) mode|S_IFDIR;
        ip->i_d.di_version = XFS_DINODE_VERSION_1;
        ip->i_d.di_format = XFS_DINODE_FMT_EXTENTS;
        ip->i_d.di_aformat = XFS_DINODE_FMT_EXTENTS;
@@ -753,8 +752,8 @@ mk_orphanage(xfs_mount_t *mp)
                do_error(_("%d - couldn't iget root inode to make %s\n"),
                        i, ORPHANAGE);
 
-       error = libxfs_inode_alloc(&tp, pip, mode|IFDIR,
-                                       1, mp->m_dev, &zerocr, &ip);
+       error = libxfs_inode_alloc(&tp, pip, mode|S_IFDIR,
+                                       1, 0, &zerocr, &ip);
 
        if (error) {
                do_error(_("%s inode allocation failed %d\n"),
@@ -783,7 +782,7 @@ mk_orphanage(xfs_mount_t *mp)
        } else
                orphanage_entered = 1;
 
-       /* 
+       /*
         * bump up the link count in the root directory to account
         * for .. in the new directory
         */
@@ -1042,7 +1041,7 @@ _("can't map block %d in %s inode %llu, xfs_bmapi returns %d, nmap = %d\n"),
                 * walk down left side of btree, release buffers as you
                 * go.  if the root block is a leaf (single-level btree),
                 * just return it.
-                * 
+                *
                 */
 
                bp = libxfs_readbuf(mp->m_dev, XFS_FSB_TO_DADDR(mp, fsbno),
@@ -1354,7 +1353,7 @@ lf_block_dir_entry_check(xfs_mount_t              *mp,
 
                junkit = 0;
 
-               XFS_DIR_SF_GET_DIRINO_ARCH(&namest->inumber, &lino, ARCH_CONVERT);
+               XFS_DIR_SF_GET_DIRINO(&namest->inumber, &lino);
                bcopy(namest->name, fname, entry->namelen);
                fname[entry->namelen] = '\0';
 
@@ -1410,7 +1409,7 @@ lf_block_dir_entry_check(xfs_mount_t              *mp,
                 */
                irec = find_inode_rec(XFS_INO_TO_AGNO(mp, lino),
                                        XFS_INO_TO_AGINO(mp, lino));
-               
+
                if (irec == NULL)  {
                        nbad++;
                        do_warn(
@@ -1745,8 +1744,8 @@ longform_dir2_entry_check_data(
        junkit = 0;
        freetab = *freetabp;
        if (isblock) {
-               btp = XFS_DIR2_BLOCK_TAIL_P(mp, d);
-               blp = XFS_DIR2_BLOCK_LEAF_P_ARCH(btp, ARCH_CONVERT);
+               btp = XFS_DIR2_BLOCK_TAIL_P(mp, (xfs_dir2_block_t *)d);
+               blp = XFS_DIR2_BLOCK_LEAF_P(btp);
                endptr = (char *)blp;
                if (endptr > (char *)btp)
                        endptr = (char *)btp;
@@ -1790,9 +1789,8 @@ longform_dir2_entry_check_data(
                                break;
 
                        /* check for invalid tag */
-                       if (INT_GET(*XFS_DIR2_DATA_UNUSED_TAG_P_ARCH(
-                                   dup, ARCH_CONVERT), ARCH_CONVERT) != 
-                           (char *)dup - (char *)d)
+                       if (INT_GET(*XFS_DIR2_DATA_UNUSED_TAG_P(dup),
+                                   ARCH_CONVERT) != (char *)dup - (char *)d)
                                break;
 
                        /* check for block with no data entries */
@@ -2118,7 +2116,7 @@ longform_dir2_check_leaf(
        }
        leaf = bp->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);
        if (INT_GET(leaf->hdr.info.magic, ARCH_CONVERT) !=
                        XFS_DIR2_LEAF1_MAGIC ||
            INT_GET(leaf->hdr.info.forw, ARCH_CONVERT) ||
@@ -2353,7 +2351,7 @@ longform_dir2_rebuild_setup(
                /* construct freelist */
                block = (xfs_dir2_block_t *)data;
                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);
                needlog = needscan = 0;
                libxfs_dir2_data_make_free(tp, dbp, (char *)blp - (char *)block,
                        (char *)block + mp->m_dirblksize - (char *)blp,
@@ -2491,7 +2489,7 @@ longform_dir2_rebuild_data(
        ptr = (char *)data->u;
        if (INT_GET(data->hdr.magic, ARCH_CONVERT) == XFS_DIR2_BLOCK_MAGIC) {
                btp = XFS_DIR2_BLOCK_TAIL_P(mp, (xfs_dir2_block_t *)data);
-               endptr = (char *)XFS_DIR2_BLOCK_LEAF_P_ARCH(btp, ARCH_CONVERT);
+               endptr = (char *)XFS_DIR2_BLOCK_LEAF_P(btp);
        } else
                endptr = (char *)data + mp->m_dirblksize;
        fblock = fbp->data;
@@ -2558,7 +2556,7 @@ longform_dir2_rebuild_data(
 
 /*
  * Finish the rebuild of a directory.
- * Stuff / in and then remove it, this forces the directory to end 
+ * Stuff / in and then remove it, this forces the directory to end
  * up in the right format.
  */
 void
@@ -2719,13 +2717,16 @@ longform_dir2_entry_check(xfs_mount_t   *mp,
                next_da_bno = da_bno + mp->m_dirblkfsbs - 1;
                if (libxfs_bmap_next_offset(NULL, ip, &next_da_bno, XFS_DATA_FORK))
                        break;
-               if (libxfs_da_read_bufr(NULL, ip, da_bno, -1, &bp,
-                               XFS_DATA_FORK)) {
+               if (libxfs_da_read_bufr(NULL, ip, da_bno,
+                               da_bno == 0 ? -2 : -1, &bp, XFS_DATA_FORK)) {
                        do_error(_("can't read block %u for directory inode "
                                   "%llu\n"),
                                da_bno, ino);
                        /* NOTREACHED */
                }
+               /* is there a hole at the start? */
+               if (da_bno == 0 && bp == NULL)
+                       continue;
                longform_dir2_entry_check_data(mp, ip, num_illegal, need_dot,
                        stack, irec, ino_offset, &bp, hashtab, &freetab, da_bno,
                        isblock);
@@ -2738,7 +2739,7 @@ longform_dir2_entry_check(xfs_mount_t     *mp,
                ASSERT(bp);
                block = bp->data;
                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);
                seeval = dir_hash_see_all(hashtab, blp, INT_GET(btp->count, ARCH_CONVERT), INT_GET(btp->stale, ARCH_CONVERT));
                if (dir_hash_check(hashtab, ip, seeval))
                        fixit |= 1;
@@ -2807,7 +2808,7 @@ shortform_dir_entry_check(xfs_mount_t     *mp,
         * no need to worry about '.' since it doesn't exist.
         */
        sf_entry = next_sfe = &sf->list[0];
-       if (sf == NULL) { 
+       if (sf == NULL) {
                junkit = 1;
                do_warn(_("shortform dir inode %llu has null data entries \n"),
                        ino);
@@ -2821,7 +2822,7 @@ shortform_dir_entry_check(xfs_mount_t     *mp,
                bad_sfnamelen = 0;
                tmp_sfe = NULL;
 
-               XFS_DIR_SF_GET_DIRINO_ARCH(&sf_entry->inumber, &lino, ARCH_CONVERT);
+               XFS_DIR_SF_GET_DIRINO(&sf_entry->inumber, &lino);
 
                namelen = sf_entry->namelen;
 
@@ -3080,7 +3081,7 @@ prune_sf_dir_entry(xfs_mount_t *mp, xfs_ino_t ino, xfs_inode_t *ip)
                        sf_entry = next_sfe, i++)  {
                tmp_sfe = NULL;
 
-               XFS_DIR_SF_GET_DIRINO_ARCH(&sf_entry->inumber, &lino, ARCH_CONVERT);
+               XFS_DIR_SF_GET_DIRINO(&sf_entry->inumber, &lino);
 
                bcopy(sf_entry->name, fname, sf_entry->namelen);
                fname[sf_entry->namelen] = '\0';
@@ -3191,7 +3192,7 @@ shortform_dir2_entry_check(xfs_mount_t    *mp,
        /*
         * Initialise i8 counter -- the parent inode number counts as well.
         */
-       i8 = (XFS_DIR2_SF_GET_INUMBER_ARCH(sfp, &sfp->hdr.parent, ARCH_CONVERT) > XFS_DIR2_MAX_SHORT_INUM);
+       i8 = (XFS_DIR2_SF_GET_INUMBER(sfp, &sfp->hdr.parent) > XFS_DIR2_MAX_SHORT_INUM);
 
        /*
         * now run through entries, stop at first bad entry, don't need
@@ -3207,7 +3208,7 @@ shortform_dir2_entry_check(xfs_mount_t    *mp,
                bad_sfnamelen = 0;
                tmp_sfep = NULL;
 
-               lino = XFS_DIR2_SF_GET_INUMBER_ARCH(sfp, XFS_DIR2_SF_INUMBERP(sfep), ARCH_CONVERT);
+               lino = XFS_DIR2_SF_GET_INUMBER(sfp, XFS_DIR2_SF_INUMBERP(sfep));
 
                namelen = sfep->namelen;
 
@@ -3852,7 +3853,7 @@ mark_standalone_inodes(xfs_mount_t *mp)
        irec = find_inode_rec(XFS_INO_TO_AGNO(mp, mp->m_sb.sb_rsumino),
                        XFS_INO_TO_AGINO(mp, mp->m_sb.sb_rsumino));
 
-       offset = XFS_INO_TO_AGINO(mp, mp->m_sb.sb_rsumino) - 
+       offset = XFS_INO_TO_AGINO(mp, mp->m_sb.sb_rsumino) -
                        irec->ino_startnum;
 
        ASSERT(irec != NULL);