vldb_check: write mh entry header flags in network order
[openafs.git] / src / vlserver / vldb_check.c
index 1b5ee18..5e454d2 100644 (file)
@@ -213,7 +213,7 @@ NameHash(char *volname)
 afs_int32
 IdHash(afs_uint32 volid)
 {
-    return ((abs(volid)) % HASHSIZE);
+    return (volid % HASHSIZE);
 }
 
 #define LEGALCHARS ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
@@ -479,9 +479,13 @@ writeMH(afs_int32 addr, int block, struct extentaddr *mhblockP)
     if (verbose) {
        quiet_println("Writing back MH block % at addr %u\n", block,  addr);
     }
+    mhblockP->ex_hdrflags = htonl(mhblockP->ex_hdrflags);
     if (block == 0) {
+       /*
+        * These header fields are only used in the first mh block, so were
+        * converted to host byte order only when the first mh block was read.
+        */
        mhblockP->ex_count = htonl(mhblockP->ex_count);
-       mhblockP->ex_hdrflags = htonl(mhblockP->ex_hdrflags);
        for (i = 0; i < VL_MAX_ADDREXTBLKS; i++) {
            mhblockP->ex_contaddrs[i] = htonl(mhblockP->ex_contaddrs[i]);
        }
@@ -1429,8 +1433,9 @@ WorkerBee(struct cmd_syndesc *as, void *arock)
 
     if (fix) {
        /*
-        * If we are fixing we will rebuild all the hash lists from the ground up
+        * If we are fixing we will rebuild the free and hash lists from the ground up.
         */
+       header.vital_header.freePtr = 0;
        memcpy(oldnamehash, header.VolnameHash, sizeof(oldnamehash));
        memset(header.VolnameHash, 0, sizeof(header.VolnameHash));
 
@@ -1585,6 +1590,18 @@ WorkerBee(struct cmd_syndesc *as, void *arock)
                }
                writeMH(record[i].addr, block, MHblock);
            }
+       } else if (record[i].type & FR) {
+           if (fix) {
+               readentry(record[i].addr, &vlentry, &type);
+               vlentry.nextIdHash[0] = header.vital_header.freePtr;
+               header.vital_header.freePtr = record[i].addr;
+               if ((record[i].type & FRC) == 0) {
+                   quiet_println
+                       ("FIX: Putting free entry on the free chain: addr=%lu (offset 0x%0x)\n",
+                        record[i].addr, OFFSET(record[i].addr));
+               }
+               writeentry(record[i].addr, &vlentry);
+           }
        }
     }
     if (fix) {
@@ -1605,7 +1622,7 @@ main(int argc, char **argv)
 
     setlinebuf(stdout);
 
-    ts = cmd_CreateSyntax(NULL, WorkerBee, NULL, "vldb check");
+    ts = cmd_CreateSyntax(NULL, WorkerBee, NULL, 0, "vldb check");
     cmd_AddParm(ts, "-database", CMD_SINGLE, CMD_REQUIRED, "vldb_file");
     cmd_AddParm(ts, "-uheader", CMD_FLAG, CMD_OPTIONAL,
                "Display UBIK header");