reindent-20030715
[openafs.git] / src / budb / database.c
index ebc38be..af6cd3a 100644 (file)
@@ -10,7 +10,8 @@
 #include <afsconfig.h>
 #include <afs/param.h>
 
-RCSID("$Header$");
+RCSID
+    ("$Header$");
 
 #ifdef AFS_NT40_ENV
 #include <winsock2.h>
@@ -36,25 +37,28 @@ RCSID("$Header$");
 #endif
 
 
-int    pollCount;
-struct memoryDB db;                    /* really allocate it here */
+int pollCount;
+struct memoryDB db;            /* really allocate it here */
 
-void db_panic (reason)
-  char *reason;
+void
+db_panic(reason)
+     char *reason;
 {
     LogError(0, "db_panic: %s\n", reason);
     BUDB_EXIT(-1);
 }
 
-afs_int32 InitDB ()
-{   afs_int32  code;
+afs_int32
+InitDB()
+{
+    afs_int32 code;
 
     pollCount = 0;
 
     memset(&db, 0, sizeof(db));
-    Lock_Init (&db.lock);
-    if ((code = InitDBalloc ()) || (code = InitDBhash ())) 
-        return code;
+    Lock_Init(&db.lock);
+    if ((code = InitDBalloc()) || (code = InitDBhash()))
+       return code;
     return 0;
 }
 
@@ -70,37 +74,34 @@ afs_int32 InitDB ()
  *     len - size of the write
  */
 
-afs_int32 dbwrite (ut, pos, buff, len)
-  struct ubik_trans *ut;
-  afs_int32  pos;
-  char *buff;
-  afs_int32  len;
+afs_int32
+dbwrite(ut, pos, buff, len)
+     struct ubik_trans *ut;
+     afs_int32 pos;
+     char *buff;
+     afs_int32 len;
 {
     afs_int32 code = 0;
 
-    if ( ( (pos < sizeof(db.h)) && (buff != (char *)&db.h + pos) ) ||
-        (pos >= ntohl(db.h.eofPtr)) )
-    {
+    if (((pos < sizeof(db.h)) && (buff != (char *)&db.h + pos))
+       || (pos >= ntohl(db.h.eofPtr))) {
        Log("dbwrite: Illegal attempt to write at location 0 or past EOF\n");
        ERROR(BUDB_IO);
     }
 
     code = ubik_Seek(ut, 0, pos);
-    if (code)
-    {
+    if (code) {
        LogError(code, "dbwrite: ubik_Seek to %d failed\n", pos);
        ERROR(code);
     }
-    code = ubik_Write(ut,buff,len);
-    if (code)
-    {
+    code = ubik_Write(ut, buff, len);
+    if (code) {
        LogError(code, "dbwrite: ubik_Write failed\n");
        ERROR(code);
     }
 
   error_exit:
-    if (((++pollCount) % 4) == 0)     /* Poll every 4 reads/writes */
-    {
+    if (((++pollCount) % 4) == 0) {    /* Poll every 4 reads/writes */
        IOMGR_Poll();
        pollCount = 0;
     }
@@ -109,36 +110,34 @@ afs_int32 dbwrite (ut, pos, buff, len)
 
 /* same thing for read */
 
-afs_int32 dbread (ut, pos, buff, len)
-  struct ubik_trans *ut;
-  afs_int32  pos;
-  char *buff;
-  afs_int32  len;
+afs_int32
+dbread(ut, pos, buff, len)
+     struct ubik_trans *ut;
+     afs_int32 pos;
+     char *buff;
+     afs_int32 len;
 {
     afs_int32 code = 0;
 
-    if (pos >= ntohl(db.h.eofPtr))
-    {
+    if (pos >= ntohl(db.h.eofPtr)) {
        LogError(0, "dbread: Attempt to read @%d (past EOF)\n", pos);
        ERROR(BUDB_IO);
     }
 
     code = ubik_Seek(ut, 0, pos);
-    if (code)
-    {
+    if (code) {
        LogError(code, "dbread: ubik_Seek to %d failed\n", pos);
        ERROR(code);
     }
     code = ubik_Read(ut, buff, len);
-    if (code)
-    {
-       LogError(code, "dbread: ubik_Read pos %d, buff %d, len %d\n", pos, buff, len);
+    if (code) {
+       LogError(code, "dbread: ubik_Read pos %d, buff %d, len %d\n", pos,
+                buff, len);
        ERROR(code);
     }
 
   error_exit:
-    if (((++pollCount) % 4) == 0)     /* Poll every 4 reads/writes */
-    {
+    if (((++pollCount) % 4) == 0) {    /* Poll every 4 reads/writes */
        IOMGR_Poll();
        pollCount = 0;
     }
@@ -146,39 +145,37 @@ afs_int32 dbread (ut, pos, buff, len)
 }
 
 /* Same as dbread excepts it does checking */
-afs_int32 cdbread (ut, type, pos, buff, len)
-  struct ubik_trans *ut;
-  int    type;
-  afs_int32  pos;
-  char   *buff;
-  afs_int32  len;
+afs_int32
+cdbread(ut, type, pos, buff, len)
+     struct ubik_trans *ut;
+     int type;
+     afs_int32 pos;
+     char *buff;
+     afs_int32 len;
 {
     afs_int32 code = 0;
 
     code = checkDiskAddress(pos, type, 0, 0);
-    if (code)
-    {
-       LogError(code, "cdbread: Bad Address for block %d (addr 0x%x)\n", 
+    if (code) {
+       LogError(code, "cdbread: Bad Address for block %d (addr 0x%x)\n",
                 type, pos);
        ERROR(code);
     }
 
     code = ubik_Seek(ut, 0, pos);
-    if (code)
-    {
+    if (code) {
        LogError(code, "cdbread: ubik_Seek to 0x%x failed\n", pos);
        ERROR(code);
     }
     code = ubik_Read(ut, buff, len);
-    if (code)
-    {
-       LogError(code, "cdbread: ubik_Read pos 0x%x, buff %d, len %d\n", pos, buff, len);
+    if (code) {
+       LogError(code, "cdbread: ubik_Read pos 0x%x, buff %d, len %d\n", pos,
+                buff, len);
        ERROR(code);
     }
 
   error_exit:
-    if (((++pollCount) % 4) == 0)     /* Poll every 4 reads/writes */
-    {
+    if (((++pollCount) % 4) == 0) {    /* Poll every 4 reads/writes */
        IOMGR_Poll();
        pollCount = 0;
     }
@@ -189,46 +186,45 @@ afs_int32 cdbread (ut, type, pos, buff, len)
    manner, to avoid bogusly reinitializing the db.  */
 
 afs_int32
-CheckInit (ut, db_init)
+CheckInit(ut, db_init)
      struct ubik_trans *ut;
-     int (*db_init)();         /* procedure to call if rebuilding DB */
-{   
+     int (*db_init) ();                /* procedure to call if rebuilding DB */
+{
     register afs_int32 code;
 
     /* Don't read header if not necessary */
-    if (!ubik_CacheUpdate (ut)) return 0;
+    if (!ubik_CacheUpdate(ut))
+       return 0;
 
-    ObtainWriteLock (&db.lock);
+    ObtainWriteLock(&db.lock);
 
     db.h.eofPtr = htonl(sizeof(db.h)); /* for sanity check in dbread */
-    code = dbread(ut, 0, (char *) &db.h, sizeof(db.h));
-    if (code) ERROR(code);
+    code = dbread(ut, 0, (char *)&db.h, sizeof(db.h));
+    if (code)
+       ERROR(code);
 
-    if ((ntohl(db.h.version) != BUDB_VERSION) || (ntohl(db.h.checkVersion) != BUDB_VERSION))
-    {
+    if ((ntohl(db.h.version) != BUDB_VERSION)
+       || (ntohl(db.h.checkVersion) != BUDB_VERSION)) {
 
-        if ((ntohl(db.h.version) == 0) || (ntohl(db.h.checkVersion) == 0))
+       if ((ntohl(db.h.version) == 0) || (ntohl(db.h.checkVersion) == 0))
            ERROR(BUDB_EMPTY);
 
-        LogError(0, "DB version should be %d; Initial = %d; Terminal = %d\n",
-                   BUDB_VERSION, ntohl(db.h.version), ntohl(db.h.checkVersion));
+       LogError(0, "DB version should be %d; Initial = %d; Terminal = %d\n",
+                BUDB_VERSION, ntohl(db.h.version), ntohl(db.h.checkVersion));
        ERROR(BUDB_IO);
     }
 
     db.readTime = time(0);
-    ht_Reset (&db.volName);
-    ht_Reset (&db.tapeName);
-    ht_Reset (&db.dumpName);
-    ht_Reset (&db.dumpIden);
+    ht_Reset(&db.volName);
+    ht_Reset(&db.tapeName);
+    ht_Reset(&db.dumpName);
+    ht_Reset(&db.dumpIden);
 
   error_exit:
-    ReleaseWriteLock (&db.lock);
-    if (code)
-    {
-       if ((code == UEOF) || (code == BUDB_EMPTY))
-       {
-           if (db_init)
-           {
+    ReleaseWriteLock(&db.lock);
+    if (code) {
+       if ((code == UEOF) || (code == BUDB_EMPTY)) {
+           if (db_init) {
                LogDebug(0, "No data base - Building new one\n");
 
                /* try to write a good header */
@@ -239,20 +235,18 @@ CheckInit (ut, db_init)
                db.h.eofPtr = htonl(sizeof(db.h));
 
                /* text ptrs cleared by bzero */
-               ht_DBInit ();
-
-               code = dbwrite(ut, 0, (char *) &db.h, sizeof(db.h));
-               if (code) code = BUDB_IO;       /* return the error code */
-               else      code = db_init(ut);   /* initialize the db */
+               ht_DBInit();
+
+               code = dbwrite(ut, 0, (char *)&db.h, sizeof(db.h));
+               if (code)
+                   code = BUDB_IO;     /* return the error code */
+               else
+                   code = db_init(ut); /* initialize the db */
+           } else {
+               LogDebug(0, "No data base\n");
+               code = BUDB_EMPTY;
            }
-           else
-           {
-               LogDebug(0, "No data base\n");
-               code = BUDB_EMPTY;
-           }
-       }
-       else
-       {
+       } else {
            LogDebug(0, "I/O Error\n");
            code = BUDB_IO;
        }