Fix strict aliasing problems or add -fno-strict-aliasing
[openafs.git] / src / budb / ol_verify.c
index 69c01c2..0ca22a5 100644 (file)
@@ -12,8 +12,6 @@
 #include <afsconfig.h>
 #include <afs/param.h>
 
-RCSID
-    ("$Header$");
 
 #include <stdio.h>
 #ifdef AFS_NT40_ENV
@@ -22,13 +20,7 @@ RCSID
 #include <netinet/in.h>
 #include <netdb.h>
 #endif
-#ifdef HAVE_STRING_H
 #include <string.h>
-#else
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-#endif
 #include <afs/stds.h>
 #include <sys/types.h>
 #include <lock.h>
@@ -36,6 +28,7 @@ RCSID
 #include "database.h"
 #include "error_macros.h"
 #include "budb_errs.h"
+#include "budb_internal.h"
 #include <afs/cellconfig.h>
 #include "afs/audit.h"
 
@@ -174,10 +167,10 @@ int hashBlockType[HT_MAX_FUNCTION + 1] = {
 struct mapCompatability {
     short trigger;             /* these bits trigger this element */
 } mapC[] = {
-MAP_FREE, MAP_HTBLOCK, MAP_DUMPHASH | MAP_IDHASH,
-       MAP_TAPEHASH | MAP_TAPEONDUMP, MAP_VOLINFOONNAME,
-       MAP_VOLINFONAMEHEAD | MAP_VOLHASH,
-       MAP_VOLFRAGONTAPE | MAP_VOLFRAGONVOL, MAP_TEXTBLOCK};
+       {MAP_FREE}, {MAP_HTBLOCK}, {MAP_DUMPHASH | MAP_IDHASH},
+       {MAP_TAPEHASH | MAP_TAPEONDUMP}, {MAP_VOLINFOONNAME},
+       {MAP_VOLINFONAMEHEAD | MAP_VOLHASH},
+       {MAP_VOLFRAGONTAPE | MAP_VOLFRAGONVOL}, {MAP_TEXTBLOCK}};
 
 /* no. of entries in the mapC array */
 int NMAPCs = (sizeof(mapC) / sizeof(mapC[0]));
@@ -193,6 +186,11 @@ char *textName[TB_NUM] = {
 extern int sizeFunctions[];
 extern int nHTBuckets;
 
+afs_int32 DbVerify(struct rx_call *call, afs_int32 *status, 
+                  afs_int32 *orphans, afs_int32 *host);
+afs_int32 verifyTextChain(struct ubik_trans *ut, struct textBlock *tbPtr);
+       
+
 #define DBBAD BUDB_DATABASEINCONSISTENT
 
 /* ------------------------------------
@@ -208,7 +206,7 @@ extern int nHTBuckets;
  */
 
 afs_int32
-BumpErrors()
+BumpErrors(void)
 {
     if (++miscData.errors >= miscData.maxErrors)
        return (1);
@@ -227,11 +225,8 @@ BumpErrors()
  */
 
 afs_int32
-checkDiskAddress(address, type, blockIndexPtr, entryIndexPtr)
-     unsigned long address;
-     int type;
-     int *blockIndexPtr;
-     int *entryIndexPtr;
+checkDiskAddress(unsigned long address, int type, int *blockIndexPtr, 
+                int *entryIndexPtr)
 {
     int index, offset;
 
@@ -275,10 +270,7 @@ checkDiskAddress(address, type, blockIndexPtr, entryIndexPtr)
  */
 
 afs_int32
-ConvertDiskAddress(address, blockIndexPtr, entryIndexPtr)
-     afs_uint32 address;
-     int *blockIndexPtr;
-     int *entryIndexPtr;
+ConvertDiskAddress(afs_uint32 address, int *blockIndexPtr, int *entryIndexPtr)
 {
     int index, type;
     afs_int32 code;
@@ -291,21 +283,21 @@ ConvertDiskAddress(address, blockIndexPtr, entryIndexPtr)
 }
 
 char *
-TypeName(index)
-     int index;
+TypeName(int index)
 {
-    static char error[16];
+    static char error[36];
 
     if ((index < 0) || (index >= NBLOCKTYPES)) {
-       sprintf(error, "UNKNOWN_TYPE", index);
+       sprintf(error, "UNKNOWN_TYPE %d", index);
        return (error);
     }
     return (typeName[index]);
 }
 
-getDumpID(ut, tapePtr, dumpID)
-     struct tape *tapePtr;
-     afs_int32 *dumpID;
+int
+getDumpID(struct ubik_trans *ut,
+    struct tape *tapePtr,
+    afs_int32 *dumpID)
 {
     struct dump d;
     afs_int32 code;
@@ -314,6 +306,7 @@ getDumpID(ut, tapePtr, dumpID)
     code = dbread(ut, ntohl(tapePtr->dump), &d, sizeof(d));
     if (!code)
        *dumpID = ntohl(d.id);
+    return code;
 }
 
 /* ------------------------------------
@@ -326,12 +319,11 @@ getDumpID(ut, tapePtr, dumpID)
  *      to the dump.
  */
 afs_int32
-verifyDumpEntry(ut, dumpAddr, ai, ao, dumpPtr)
-     struct ubik_trans *ut;
-     afs_int32 dumpAddr;
-     int ai, ao;
-     struct dump *dumpPtr;
+verifyDumpEntry(struct ubik_trans *ut, afs_int32 dumpAddr, int ai, int ao,
+               void *param)
 {
+    struct dump *dumpPtr = (struct dump *)param;
+    
     struct tape tape;
     afs_int32 tapeAddr, tapeCount = 0, volCount = 0, appDumpCount = 0;
     afs_int32 appDumpAddr, appDumpIndex, appDumpOffset;
@@ -460,12 +452,10 @@ verifyDumpEntry(ut, dumpAddr, ai, ao, dumpPtr)
  *      they belong to the tape.
  */
 afs_int32
-verifyTapeEntry(ut, tapeAddr, ai, ao, tapePtr)
-     struct ubik_trans *ut;
-     afs_int32 tapeAddr;
-     int ai, ao;
-     struct tape *tapePtr;
+verifyTapeEntry(struct ubik_trans *ut, afs_int32 tapeAddr, int ai, int ao,
+               void *param)
 {
+    struct tape *tapePtr = (struct tape *) param;
     int volCount = 0, ccheck = 1;
     afs_int32 volFragAddr;
     int blockIndex, entryIndex;
@@ -539,12 +529,10 @@ verifyTapeEntry(ut, tapeAddr, ai, ao, tapePtr)
  *      So no check is done agaist it.
  */
 afs_int32
-verifyVolFragEntry(ut, va, ai, ao, v)
-     struct ubik_trans *ut;
-     afs_int32 va;
-     int ai, ao;
-     struct volFragment *v;
+verifyVolFragEntry(struct ubik_trans *ut, afs_int32 va, int ai, int ao,
+                  void *param)
 {
+    /* struct volFragment *v = (struct volFragment *)param; */
     misc->nVolFrag++;
     return 0;
 }
@@ -556,12 +544,11 @@ verifyVolFragEntry(ut, va, ai, ao, v)
  *      also verify all entries are also on the chain.
  */
 afs_int32
-verifyVolInfoEntry(ut, volInfoAddr, ai, ao, volInfo)
-     struct ubik_trans *ut;
-     afs_int32 volInfoAddr;
-     int ai, ao;
-     struct volInfo *volInfo;
+verifyVolInfoEntry(struct ubik_trans *ut, afs_int32 volInfoAddr, int ai, 
+                  int ao, void *param)
 {
+    struct volInfo *volInfo = (struct volInfo *) param;
+    
     int volCount = 0, ccheck = 1;
     afs_int32 volFragAddr;
     int blockIndex, entryIndex;
@@ -687,8 +674,7 @@ verifyVolInfoEntry(ut, volInfoAddr, ai, ao, volInfo)
  *     blockMap array. Also check that the type of block is good.
  */
 afs_int32
-verifyBlocks(ut)
-     struct ubik_trans *ut;
+verifyBlocks(struct ubik_trans *ut)
 {
     struct block block;
     int blocktype;
@@ -744,14 +730,13 @@ int minvols, maxvols, ttlvols;
  *      entry and is not threaded on multiple lists.
  */
 afs_int32
-verifyHashTableBlock(ut, mhtPtr, htBlockPtr, old, length, index, mapBit)
-     struct ubik_trans *ut;
-     struct memoryHashTable *mhtPtr;
-     struct htBlock *htBlockPtr;
-     int old;
-     afs_int32 length;         /* size of whole hash table */
-     int index;                        /* base index of this block */
-     int mapBit;
+verifyHashTableBlock(struct ubik_trans *ut,
+                    struct memoryHashTable *mhtPtr,
+                    struct htBlock *htBlockPtr,
+                    int old,
+                    afs_int32 length,  /* size of whole hash table */
+                    int index,         /* base index of this block */
+                    int mapBit)
 {
     int type;                  /* hash table type */
     int entrySize;             /* hashed entry size */
@@ -847,10 +832,8 @@ verifyHashTableBlock(ut, mhtPtr, htBlockPtr, old, length, index, mapBit)
  *      the hash table.
  */
 afs_int32
-verifyHashTable(ut, mhtPtr, mapBit)
-     struct ubik_trans *ut;
-     struct memoryHashTable *mhtPtr;
-     int mapBit;
+verifyHashTable(struct ubik_trans *ut, struct memoryHashTable *mhtPtr, 
+               int mapBit)
 {
     struct hashTable *htPtr = mhtPtr->ht;
 
@@ -948,19 +931,21 @@ verifyHashTable(ut, mhtPtr, mapBit)
  *     the integrity of each allocated structure.
  */
 afs_int32
-verifyEntryChains(ut)
-     struct ubik_trans *ut;
+verifyEntryChains(struct ubik_trans *ut)
 {
     afs_int32 code;
     afs_int32 offset;
+    afs_int32 start;
     int blockIndex, entryIndex;
     char entry[sizeof(struct block)];
     int entrySize;
     int type;
     int nFree;
 
-    static afs_int32(*checkEntry[NBLOCKTYPES]) ()
+    static afs_int32(*checkEntry[NBLOCKTYPES]) (struct ubik_trans *, 
+                                               afs_int32, int, int, void *)
        = {
+       /* FIXME: this list does not match typeName[] and may be incorrect */
        0,                      /* free block */
            verifyVolFragEntry, verifyVolInfoEntry, verifyTapeEntry, verifyDumpEntry, 0 /* text block */
     };
@@ -982,7 +967,8 @@ verifyEntryChains(ut)
                return BUDB_IO;
 
            /* check if entry is free by looking at the first "afs_int32" of the structure */
-           if (*((afs_int32 *) & entry[0]) == 0) {     /* zero is free */
+           memcpy(&start, entry, sizeof(start));
+           if (start == 0) {   /* zero is free */
                /* Is it on any hash chain? */
                if (blockMap[blockIndex]->entries[entryIndex] & MAP_HASHES) {
                    Log("Entry: blockindex %d, entryindex %d - marked free but hashed 0x%x\n", blockIndex, entryIndex, blockMap[blockIndex]->entries[entryIndex]);
@@ -1016,7 +1002,7 @@ verifyEntryChains(ut)
 
 
 afs_int32
-verifyFreeLists()
+verifyFreeLists(void)
 {
     int i;
     afs_int32 addr;
@@ -1044,7 +1030,7 @@ verifyFreeLists()
 
            /* check block type */
            if (blockMap[blockIndex]->header.type != i) {
-               Log("verifyFreeLists: Found %s type in %s free chain\n",
+               Log("verifyFreeLists: Found %s type in %s free chain (addr 0x%x)\n",
                    TypeName(blockMap[blockIndex]->header.type), TypeName(i),
                    addr);
                if (BumpErrors())
@@ -1081,7 +1067,7 @@ verifyFreeLists()
  *     checking the bits for compatibility.
  */
 afs_int32
-verifyMapBits()
+verifyMapBits(void)
 {
     int blockIndex, entryIndex, i, entrySize, type, bits;
     afs_int32 offset;
@@ -1097,9 +1083,10 @@ verifyMapBits()
 
        /* check each entry */
        for (entryIndex = 0; entryIndex < blockMap[blockIndex]->nEntries; entryIndex++) {       /*f */
+#ifndef AFS_PTHREAD_ENV
            if ((entryIndex % 1024) == 0)
                IOMGR_Poll();
-
+#endif
            bits = blockMap[blockIndex]->entries[entryIndex];
 
            for (i = 0; i < NMAPCs; i++)
@@ -1180,12 +1167,10 @@ verifyMapBits()
 }
 
 afs_int32
-verifyText(ut)
-     struct ubik_trans *ut;
+verifyText(struct ubik_trans *ut)
 {
     int i;
     afs_int32 code;
-    extern afs_int32 verifyTextChain();
 
     /* check each of the text types in use */
     for (i = 0; i < TB_NUM; i++) {
@@ -1201,9 +1186,7 @@ verifyText(ut)
  *     check the integrity of a text chain. Also checks the new chain.
  */
 afs_int32
-verifyTextChain(ut, tbPtr)
-     struct ubik_trans *ut;
-     struct textBlock *tbPtr;
+verifyTextChain(struct ubik_trans *ut, struct textBlock *tbPtr)
 {
     dbadr blockAddr;
     int blockIndex, entryIndex;
@@ -1264,16 +1247,14 @@ verifyTextChain(ut, tbPtr)
  */
 
 afs_int32
-verifyDatabase(ut, recreateFile)
-     struct ubik_trans *ut;
-     FILE *recreateFile;       /* not used */
+verifyDatabase(struct ubik_trans *ut,
+              FILE *recreateFile)      /* not used */
 {
     afs_int32 eof;
     int bmsize;
-    afs_int32 code = 0, tcode;
+    afs_int32 code = 0, tcode = 0;
 
     extern int nBlocks;                /* no. blocks in database */
-    extern struct ubik_dbase *BU_dbase;
 
     /* clear verification statistics */
     misc = &miscData;
@@ -1428,13 +1409,9 @@ verifyDatabase(ut, recreateFile)
  *     orphans - no. of orphan blocks
  *     host - address of host that did verification
  */
-afs_int32 DbVerify();
 afs_int32
-SBUDB_DbVerify(call, status, orphans, host)
-     struct rx_call *call;
-     afs_int32 *status;
-     afs_int32 *orphans;
-     afs_int32 *host;
+SBUDB_DbVerify(struct rx_call *call, afs_int32 *status, afs_int32 *orphans,
+              afs_int32 *host)
 {
     afs_int32 code;
 
@@ -1444,11 +1421,8 @@ SBUDB_DbVerify(call, status, orphans, host)
 }
 
 afs_int32
-DbVerify(call, status, orphans, host)
-     struct rx_call *call;
-     afs_int32 *status;
-     afs_int32 *orphans;
-     afs_int32 *host;
+DbVerify(struct rx_call *call, afs_int32 *status, afs_int32 *orphans, 
+        afs_int32 *host)
 {
     struct ubik_trans *ut = 0;
     afs_int32 code = 0, tcode;
@@ -1497,9 +1471,8 @@ DbVerify(call, status, orphans, host)
 /* check_header
  *     do a simple sanity check on the database header
  */
-
-check_header(callerst)
-     char *callerst;
+void
+check_header(char *callerst)
 {
     static int iteration_count = 0;
     afs_int32 eof;