]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blobdiff - db/check.c
Merge whitespace changes over
[thirdparty/xfsprogs-dev.git] / db / check.c
index 0eaf9caa2acffeab98b0622e0b1f36bb878ef413..fd4186331fbdfdc0d7e7372dcb33b262342ddc9b 100644 (file)
@@ -1,47 +1,45 @@
 /*
- * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
- * 
+ * Copyright (c) 2000-2002 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/
  */
 
 #include <libxfs.h>
 #include <math.h>
-#include <getopt.h>
 #include <sys/time.h>
 #include "bmap.h"
 #include "check.h"
 #include "command.h"
-#include "data.h"
 #include "io.h"
 #include "output.h"
 #include "type.h"
-#include "mount.h"
+#include "init.h"
 #include "malloc.h"
 
 typedef enum {
@@ -282,7 +280,7 @@ static xfs_ino_t    process_data_dir_v2(int *dot, int *dotdot,
                                            freetab_t **freetabp);
 static xfs_dir2_data_free_t
                        *process_data_dir_v2_freefind(xfs_dir2_data_t *data,
-                                                  xfs_dir2_data_unused_t *dup);
+                                                  xfs_dir2_data_unused_t *dup);
 static void            process_dir(xfs_dinode_t *dip, blkmap_t *blkmap,
                                    inodata_t *id);
 static int             process_dir_v1(xfs_dinode_t *dip, blkmap_t *blkmap,
@@ -370,24 +368,24 @@ static void               set_rinomap(xfs_drfsbno_t bno, xfs_extlen_t len,
 static void            setlink_inode(inodata_t *id, nlink_t nlink, int isdir,
                                       int security);
 
-static const cmdinfo_t blockfree_cmd = 
+static const cmdinfo_t blockfree_cmd =
        { "blockfree", NULL, blockfree_f, 0, 0, 0,
          NULL, "free block usage information", NULL };
-static const cmdinfo_t blockget_cmd = 
+static const cmdinfo_t blockget_cmd =
        { "blockget", "check", blockget_f, 0, -1, 0,
          "[-s|-v] [-n] [-b bno]... [-i ino] ...",
          "get block usage and check consistency", NULL };
 #ifdef DEBUG
-static const cmdinfo_t blocktrash_cmd = 
+static const cmdinfo_t blocktrash_cmd =
        { "blocktrash", NULL, blocktrash_f, 0, -1, 0,
          "[-n count] [-x minlen] [-y maxlen] [-s seed] [-0123] [-t type] ...",
          "trash randomly selected block(s)", NULL };
 #endif
-static const cmdinfo_t blockuse_cmd = 
+static const cmdinfo_t blockuse_cmd =
        { "blockuse", NULL, blockuse_f, 0, 3, 0,
          "[-n] [-c blockcount]",
          "print usage for current block(s)", NULL };
-static const cmdinfo_t ncheck_cmd = 
+static const cmdinfo_t ncheck_cmd =
        { "ncheck", NULL, ncheck_f, 0, -1, 0,
          "[-s] [-i ino] ...",
          "print inode-name pairs", NULL };
@@ -439,7 +437,7 @@ addname_inode(
        id->name[namelen] = '\0';
 }
 
-static void 
+static void
 addparent_inode(
        inodata_t       *id,
        xfs_ino_t       parent)
@@ -829,7 +827,7 @@ blockget_f(
        for (agno = 0; agno < mp->m_sb.sb_agcount; agno++) {
                /*
                 * Check that there are no blocks either
-                * a) unaccounted for or 
+                * a) unaccounted for or
                 * b) bno-free but not cnt-free
                 */
                checknot_dbmap(agno, 0, mp->m_sb.sb_agblocks,
@@ -1337,7 +1335,7 @@ check_linkcounts(
                        ep = ep->next;
                }
        }
-               
+
 }
 
 static int
@@ -1748,11 +1746,11 @@ init(
        while ((c = getopt(argc, argv, "b:i:npsv")) != EOF) {
                switch (c) {
                case 'b':
-                       bno = atoll(optarg);
+                       bno = strtoll(optarg, NULL, 10);
                        add_blist(bno);
                        break;
                case 'i':
-                       ino = atoll(optarg);
+                       ino = strtoll(optarg, NULL, 10);
                        add_ilist(ino);
                        break;
                case 'n':
@@ -1839,7 +1837,7 @@ ncheck_f(
        while ((c = getopt(argc, argv, "i:s")) != EOF) {
                switch (c) {
                case 'i':
-                       ino = atoll(optarg);
+                       ino = strtoll(optarg, NULL, 10);
                        ilist = xrealloc(ilist, (ilist_size + 1) *
                                sizeof(*ilist));
                        ilist[ilist_size++] = ino;
@@ -1898,7 +1896,7 @@ prepend_path(
 
        len = (int)(strlen(oldpath) + strlen(parent) + 2);
        path = xmalloc(len);
-       sprintf(path, "%s/%s", parent, oldpath);
+       snprintf(path, len, "%s/%s", parent, oldpath);
        return path;
 }
 
@@ -2085,7 +2083,7 @@ process_btinode(
                if (!sflag || id->ilist)
                        dbprintf("numrecs for ino %lld %s fork bmap root too "
                                 "large (%u)\n",
-                               id->ino, 
+                               id->ino,
                                whichfork == XFS_DATA_FORK ? "data" : "attr",
                                INT_GET(dib->bb_numrecs, ARCH_CONVERT));
                error++;
@@ -2595,7 +2593,7 @@ process_inode(
                "dev", "local", "extents", "btree", "uuid"
        };
 
-        /* convert the core, then copy it back into the inode */
+       /* convert the core, then copy it back into the inode */
        libxfs_xlate_dinode_core((xfs_caddr_t)&dip->di_core, &tdic, 1,
                                 ARCH_CONVERT);
        memcpy(&dip->di_core, &tdic, sizeof(xfs_dinode_core_t));
@@ -2676,8 +2674,8 @@ process_inode(
                dbprintf("inode %lld mode %#o fmt %s "
                         "afmt %s "
                         "nex %d anex %d nblk %lld sz %lld%s%s\n",
-                       id->ino, dic->di_mode, fmtnames[dic->di_format],
-                       fmtnames[dic->di_aformat],
+                       id->ino, dic->di_mode, fmtnames[(int)dic->di_format],
+                       fmtnames[(int)dic->di_aformat],
                        dic->di_nextents,
                        dic->di_anextents,
                        dic->di_nblocks, dic->di_size,
@@ -2778,6 +2776,7 @@ process_inode(
                        ic = 1;
                        break;
                default:
+                       break;
                }
                if (ic)
                        quota_add(dic->di_gid, dic->di_uid, 0, bc, ic, rc);
@@ -2930,7 +2929,7 @@ process_leaf_dir_v1_int(
        entry = &leaf->entries[0];
        for (i = 0; i < INT_GET(leaf->hdr.count, ARCH_CONVERT); entry++, i++) {
                namest = XFS_DIR_LEAF_NAMESTRUCT(leaf, INT_GET(entry->nameidx, ARCH_CONVERT));
-                lino=DIRINO_GET_ARCH(&namest->inumber, ARCH_CONVERT);
+               lino=DIRINO_GET_ARCH(&namest->inumber, ARCH_CONVERT);
                cid = find_inode(lino, 1);
                if (v)
                        dbprintf("dir %lld entry %*.*s %lld\n", id->ino,
@@ -3200,7 +3199,7 @@ process_leaf_node_dir_v2_int(
                }
                break;
        case XFS_DIR2_LEAFN_MAGIC:
-               /* if it's at the root location then we can check the 
+               /* if it's at the root location then we can check the
                 * pointers are null XXX */
                break;
        case XFS_DA_NODE_MAGIC:
@@ -3350,7 +3349,7 @@ process_quota(
                if ((dqb = iocur_top->data) == NULL) {
                        pop_cur();
                        if (scicb)
-                               dbprintf("can't read block %lld for %s quota "  
+                               dbprintf("can't read block %lld for %s quota "
                                         "inode (fsblock %lld)\n",
                                        (xfs_dfiloff_t)qbno, s,
                                        (xfs_dfsbno_t)bno);
@@ -3367,7 +3366,7 @@ process_quota(
                                        INT_GET(dqb->dd_diskdq.d_rtbcount, ARCH_CONVERT));
                        if (INT_GET(dqb->dd_diskdq.d_magic, ARCH_CONVERT) != XFS_DQUOT_MAGIC) {
                                if (scicb)
-                                       dbprintf("bad magic number %#x for %s " 
+                                       dbprintf("bad magic number %#x for %s "
                                                 "dqblk %lld entry %d id %d\n",
                                                INT_GET(dqb->dd_diskdq.d_magic, ARCH_CONVERT), s,
                                                (xfs_dfiloff_t)qbno, i, dqid);
@@ -3657,7 +3656,7 @@ process_shortform_dir_v1(
        (*dot)++;
        sfe = &sf->list[0];
        for (i = INT_GET(sf->hdr.count, ARCH_CONVERT) - 1; i >= 0; i--) {
-                lino = DIRINO_GET_ARCH(&sfe->inumber, ARCH_CONVERT);
+               lino = DIRINO_GET_ARCH(&sfe->inumber, ARCH_CONVERT);
                cid = find_inode(lino, 1);
                if (cid == NULL) {
                        if (!sflag)
@@ -3681,7 +3680,7 @@ process_shortform_dir_v1(
                dbprintf("dir %llu size is %lld, should be %d\n",
                        id->ino, dip->di_core.di_size,
                        (int)((char *)sfe - (char *)sf));
-        lino=DIRINO_GET_ARCH(&sf->hdr.parent, ARCH_CONVERT);
+       lino=DIRINO_GET_ARCH(&sf->hdr.parent, ARCH_CONVERT);
        cid = find_inode(lino, 1);
        if (cid)
                addlink_inode(cid);
@@ -3821,18 +3820,19 @@ scan_ag(
        agffreeblks = agflongest = 0;
        agicount = agifreecount = 0;
        push_cur();
-       set_cur(&typtab[TYP_SB], XFS_AG_DADDR(mp, agno, XFS_SB_DADDR), 1,
-               DB_RING_IGN, NULL);
-        
+       set_cur(&typtab[TYP_SB],
+               XFS_AG_DADDR(mp, agno, XFS_SB_DADDR),
+               XFS_FSS_TO_BB(mp, 1), DB_RING_IGN, NULL);
+
        if (!iocur_top->data) {
                dbprintf("can't read superblock for ag %u\n", agno);
                pop_cur();
                serious_error++;
                return;
        }
+
        libxfs_xlate_sb(iocur_top->data, sb, 1, ARCH_CONVERT, XFS_SB_ALL_BITS);
+
        if (sb->sb_magicnum != XFS_SB_MAGIC) {
                if (!sflag)
                        dbprintf("bad sb magic # %#x in ag %u\n",
@@ -3856,8 +3856,9 @@ scan_ag(
                set_dbmap(agno, XFS_FSB_TO_AGBNO(mp, sb->sb_logstart),
                        sb->sb_logblocks, DBM_LOG, agno, XFS_SB_BLOCK(mp));
        push_cur();
-       set_cur(&typtab[TYP_AGF], XFS_AG_DADDR(mp, agno, XFS_AGF_DADDR), 1,
-               DB_RING_IGN, NULL);
+       set_cur(&typtab[TYP_AGF],
+               XFS_AG_DADDR(mp, agno, XFS_AGF_DADDR(mp)),
+               XFS_FSS_TO_BB(mp, 1), DB_RING_IGN, NULL);
        if ((agf = iocur_top->data) == NULL) {
                dbprintf("can't read agf block for ag %u\n", agno);
                pop_cur();
@@ -3885,8 +3886,9 @@ scan_ag(
                        sb->sb_agblocks - INT_GET(agf->agf_length, ARCH_CONVERT),
                        DBM_MISSING, agno, XFS_SB_BLOCK(mp));
        push_cur();
-       set_cur(&typtab[TYP_AGI], XFS_AG_DADDR(mp, agno, XFS_AGI_DADDR), 1,
-               DB_RING_IGN, NULL);
+       set_cur(&typtab[TYP_AGI],
+               XFS_AG_DADDR(mp, agno, XFS_AGI_DADDR(mp)),
+               XFS_FSS_TO_BB(mp, 1), DB_RING_IGN, NULL);
        if ((agi = iocur_top->data) == NULL) {
                dbprintf("can't read agi block for ag %u\n", agno);
                serious_error++;
@@ -3957,11 +3959,11 @@ scan_ag(
        for (i = 0; i < XFS_AGI_UNLINKED_BUCKETS; i++) {
                if (INT_GET(agi->agi_unlinked[i], ARCH_CONVERT) != NULLAGINO) {
                        if (!sflag) {
-                                xfs_agino_t agino=INT_GET(agi->agi_unlinked[i], ARCH_CONVERT);
+                               xfs_agino_t agino=INT_GET(agi->agi_unlinked[i], ARCH_CONVERT);
                                dbprintf("agi unlinked bucket %d is %u in ag "
                                         "%u (inode=%lld)\n", i, agino, agno,
-                                        XFS_AGINO_TO_INO(mp, agno, agino));
-                        }
+                                       XFS_AGINO_TO_INO(mp, agno, agino));
+                       }
                        error++;
                }
        }
@@ -3989,7 +3991,8 @@ scan_freelist(
                return;
        push_cur();
        set_cur(&typtab[TYP_AGFL],
-               XFS_AG_DADDR(mp, seqno, XFS_AGFL_DADDR), 1, DB_RING_IGN, NULL);
+               XFS_AG_DADDR(mp, seqno, XFS_AGFL_DADDR(mp)),
+               XFS_FSS_TO_BB(mp, 1), DB_RING_IGN, NULL);
        if ((agfl = iocur_top->data) == NULL) {
                dbprintf("can't read agfl block for ag %u\n", seqno);
                serious_error++;
@@ -4004,7 +4007,7 @@ scan_freelist(
                count++;
                if (i == INT_GET(agf->agf_fllast, ARCH_CONVERT))
                        break;
-               if (++i == XFS_AGFL_SIZE)
+               if (++i == XFS_AGFL_SIZE(mp))
                        i = 0;
        }
        if (count != INT_GET(agf->agf_flcount, ARCH_CONVERT)) {