ptserver: Don't ignore ubik_Write failures
[openafs.git] / src / ptserver / utils.c
index df0c6e8..60de047 100644 (file)
@@ -1,30 +1,21 @@
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
  */
 
-#include <assert.h>
 #include <afsconfig.h>
 #include <afs/param.h>
 
-RCSID
-    ("$Header$");
+#include <roken.h>
 
-#include <sys/types.h>
+#include <afs/opr.h>
 #include <lock.h>
 #include <ubik.h>
-#include <stdio.h>
-#ifdef AFS_NT40_ENV
-#include <winsock2.h>
-#else
-#include <netinet/in.h>
-#include <netdb.h>
-#endif
-#include <string.h>
+
 #include "ptserver.h"
 #include "pterror.h"
 
@@ -34,7 +25,7 @@ afs_int32 IsAMemberOfSG(struct ubik_trans *at, afs_int32 aid, afs_int32 gid,
                        afs_int32 depth);
 #endif
 
-afs_int32
+static afs_int32
 IDHash(afs_int32 x)
 {
     /* returns hash bucket for x */
@@ -42,20 +33,20 @@ IDHash(afs_int32 x)
 }
 
 afs_int32
-NameHash(register unsigned char *aname)
+NameHash(char *aname)
 {
     /* returns hash bucket for aname */
-    register unsigned int hash = 0;
-    register int i;
+    unsigned int hash = 0;
+    size_t i;
 /* stolen directly from the HashString function in the vol package */
     for (i = strlen(aname), aname += i - 1; i--; aname--)
-       hash = (hash * 31) + (*aname - 31);
+       hash = (hash * 31) + (*(unsigned char *)aname - 31);
     return (hash % HASHSIZE);
 }
 
 
 afs_int32
-pr_Write(struct ubik_trans *tt, afs_int32 afd, afs_int32 pos, char *buff, afs_int32 len)
+pr_Write(struct ubik_trans *tt, afs_int32 afd, afs_int32 pos, void *buff, afs_int32 len)
 {
     /* package up seek and write into one procedure for ease of use */
     afs_int32 code;
@@ -72,7 +63,7 @@ pr_Write(struct ubik_trans *tt, afs_int32 afd, afs_int32 pos, char *buff, afs_in
 }
 
 afs_int32
-pr_Read(struct ubik_trans *tt, afs_int32 afd, afs_int32 pos, char *buff, afs_int32 len)
+pr_Read(struct ubik_trans *tt, afs_int32 afd, afs_int32 pos, void *buff, afs_int32 len)
 {
     /* same thing for read */
     afs_int32 code;
@@ -87,7 +78,7 @@ int
 pr_WriteEntry(struct ubik_trans *tt, afs_int32 afd, afs_int32 pos, struct prentry *tentry)
 {
     afs_int32 code;
-    register afs_int32 i;
+    afs_int32 i;
     struct prentry nentry;
 
     if (ntohl(1) != 1) {       /* Need to swap bytes. */
@@ -110,12 +101,10 @@ pr_WriteEntry(struct ubik_trans *tt, afs_int32 afd, afs_int32 pos, struct prentr
        nentry.sibling = htonl(tentry->sibling);
        nentry.child = htonl(tentry->child);
        strncpy(nentry.name, tentry->name, PR_MAXNAMELEN);
-#ifdef PR_REMEMBER_TIMES
        nentry.createTime = htonl(tentry->createTime);
        nentry.addTime = htonl(tentry->addTime);
        nentry.removeTime = htonl(tentry->removeTime);
        nentry.changeTime = htonl(tentry->changeTime);
-#endif
        for (i = 0; i < PRSIZE; i++)
            nentry.entries[i] = htonl(tentry->entries[i]);
        tentry = &nentry;
@@ -128,7 +117,7 @@ int
 pr_ReadEntry(struct ubik_trans *tt, afs_int32 afd, afs_int32 pos, struct prentry *tentry)
 {
     afs_int32 code;
-    register afs_int32 i;
+    afs_int32 i;
     struct prentry nentry;
     code = ubik_Seek(tt, afd, pos);
     if (code)
@@ -159,12 +148,10 @@ pr_ReadEntry(struct ubik_trans *tt, afs_int32 afd, afs_int32 pos, struct prentry
     tentry->sibling = ntohl(nentry.sibling);
     tentry->child = ntohl(nentry.child);
     strncpy(tentry->name, nentry.name, PR_MAXNAMELEN);
-#ifdef PR_REMEMBER_TIMES
     tentry->createTime = ntohl(nentry.createTime);
     tentry->addTime = ntohl(nentry.addTime);
     tentry->removeTime = ntohl(nentry.removeTime);
     tentry->changeTime = ntohl(nentry.changeTime);
-#endif
     for (i = 0; i < PRSIZE; i++)
        tentry->entries[i] = ntohl(nentry.entries[i]);
     return (code);
@@ -174,7 +161,7 @@ int
 pr_WriteCoEntry(struct ubik_trans *tt, afs_int32 afd, afs_int32 pos, struct contentry *tentry)
 {
     afs_int32 code;
-    register afs_int32 i;
+    afs_int32 i;
     struct contentry nentry;
 
     if (ntohl(1) != 1) {       /* No need to swap */
@@ -195,7 +182,7 @@ int
 pr_ReadCoEntry(struct ubik_trans *tt, afs_int32 afd, afs_int32 pos, struct contentry *tentry)
 {
     afs_int32 code;
-    register afs_int32 i;
+    afs_int32 i;
     struct contentry nentry;
     code = ubik_Seek(tt, afd, pos);
     if (code)
@@ -221,9 +208,9 @@ pr_ReadCoEntry(struct ubik_trans *tt, afs_int32 afd, afs_int32 pos, struct conte
  * new entry */
 
 afs_int32
-AllocBlock(register struct ubik_trans *at)
+AllocBlock(struct ubik_trans *at)
 {
-    register afs_int32 code;
+    afs_int32 code;
     afs_int32 temp;
     struct prentry tentry;
 
@@ -254,10 +241,10 @@ AllocBlock(register struct ubik_trans *at)
 }
 
 afs_int32
-FreeBlock(register struct ubik_trans *at, afs_int32 pos)
+FreeBlock(struct ubik_trans *at, afs_int32 pos)
 {
     /* add a block of storage to the free list */
-    register afs_int32 code;
+    afs_int32 code;
     struct prentry tentry;
 
     memset(&tentry, 0, sizeof(tentry));
@@ -275,10 +262,10 @@ FreeBlock(register struct ubik_trans *at, afs_int32 pos)
 }
 
 afs_int32
-FindByID(register struct ubik_trans *at, afs_int32 aid)
+FindByID(struct ubik_trans *at, afs_int32 aid)
 {
     /* returns address of entry if found, 0 otherwise */
-    register afs_int32 code;
+    afs_int32 code;
     afs_int32 i;
     struct prentry tentry;
     afs_int32 entry;
@@ -295,7 +282,7 @@ FindByID(register struct ubik_trans *at, afs_int32 aid)
        return 0;
     if (aid == tentry.id)
        return entry;
-    assert(entry != tentry.nextID);
+    opr_Assert(entry != tentry.nextID);
     entry = tentry.nextID;
     while (entry != 0) {
        memset(&tentry, 0, sizeof(tentry));
@@ -304,17 +291,17 @@ FindByID(register struct ubik_trans *at, afs_int32 aid)
            return 0;
        if (aid == tentry.id)
            return entry;
-       assert(entry != tentry.nextID);
+       opr_Assert(entry != tentry.nextID);
        entry = tentry.nextID;
     }
     return 0;
 }
 
 afs_int32
-FindByName(register struct ubik_trans *at, char aname[PR_MAXNAMELEN], struct prentry *tentryp)
+FindByName(struct ubik_trans *at, char aname[PR_MAXNAMELEN], struct prentry *tentryp)
 {
     /* ditto */
-    register afs_int32 code;
+    afs_int32 code;
     afs_int32 i;
     afs_int32 entry;
 
@@ -328,7 +315,7 @@ FindByName(register struct ubik_trans *at, char aname[PR_MAXNAMELEN], struct pre
        return 0;
     if ((strncmp(aname, tentryp->name, PR_MAXNAMELEN)) == 0)
        return entry;
-    assert(entry != tentryp->nextName);
+    opr_Assert(entry != tentryp->nextName);
     entry = tentryp->nextName;
     while (entry != 0) {
        memset(tentryp, 0, sizeof(struct prentry));
@@ -337,19 +324,19 @@ FindByName(register struct ubik_trans *at, char aname[PR_MAXNAMELEN], struct pre
            return 0;
        if ((strncmp(aname, tentryp->name, PR_MAXNAMELEN)) == 0)
            return entry;
-       assert(entry != tentryp->nextName);
+       opr_Assert(entry != tentryp->nextName);
        entry = tentryp->nextName;
     }
     return 0;
 }
 
 afs_int32
-AllocID(register struct ubik_trans *at, afs_int32 flag, afs_int32 *aid)
+AllocID(struct ubik_trans *at, afs_int32 flag, afs_int32 *aid)
 {
     /* allocs an id from the proper area of address space, based on flag */
-    register afs_int32 code = 1;
-    register afs_int32 i = 0;
-    register maxcount = 50;    /* to prevent infinite loops */
+    afs_int32 code = 1;
+    afs_int32 i = 0;
+    int maxcount = 50; /* to prevent infinite loops */
 
     if (flag & PRGRP) {
        *aid = ntohl(cheader.maxGroup);
@@ -403,11 +390,11 @@ AllocID(register struct ubik_trans *at, afs_int32 flag, afs_int32 *aid)
 }
 
 afs_int32
-IDToName(register struct ubik_trans *at, afs_int32 aid, char aname[PR_MAXNAMELEN])
+IDToName(struct ubik_trans *at, afs_int32 aid, char aname[PR_MAXNAMELEN])
 {
     afs_int32 temp;
     struct prentry tentry;
-    register afs_int32 code;
+    afs_int32 code;
 
     temp = FindByID(at, aid);
     if (temp == 0)
@@ -420,7 +407,7 @@ IDToName(register struct ubik_trans *at, afs_int32 aid, char aname[PR_MAXNAMELEN
 }
 
 afs_int32
-NameToID(register struct ubik_trans *at, char aname[PR_MAXNAMELEN], afs_int32 *aid)
+NameToID(struct ubik_trans *at, char aname[PR_MAXNAMELEN], afs_int32 *aid)
 {
     afs_int32 temp;
     struct prentry tentry;
@@ -433,12 +420,12 @@ NameToID(register struct ubik_trans *at, char aname[PR_MAXNAMELEN], afs_int32 *a
 }
 
 int
-IDCmp(afs_int32 *a, afs_int32 *b)
+IDCmp(const void *a, const void *b)
 {
     /* used to sort CPS's so that comparison with acl's is easier */
-    if (*a > *b) {
+    if (*(afs_int32 *)a > *(afs_int32 *)b) {
        return 1;
-    } else if (*a == *b) {
+    } else if (*(afs_int32 *)a == *(afs_int32 *)b) {
        return 0;
     } else /* (*a < *b) */ {
        return -1;
@@ -449,7 +436,7 @@ afs_int32
 RemoveFromIDHash(struct ubik_trans *tt, afs_int32 aid, afs_int32 *loc)         /* ??? in case ID hashed twice ??? */
 {
     /* remove entry designated by aid from id hash table */
-    register afs_int32 code;
+    afs_int32 code;
     afs_int32 current, trail, i;
     struct prentry tentry;
     struct prentry bentry;
@@ -467,7 +454,7 @@ RemoveFromIDHash(struct ubik_trans *tt, afs_int32 aid, afs_int32 *loc)              /* ??? i
     if (code)
        return PRDBFAIL;
     while (aid != tentry.id) {
-       assert(trail != current);
+       opr_Assert(trail != current);
        trail = current;
        current = tentry.nextID;
        if (current == 0)
@@ -492,6 +479,8 @@ RemoveFromIDHash(struct ubik_trans *tt, afs_int32 aid, afs_int32 *loc)              /* ??? i
            return PRDBFAIL;
        bentry.nextID = tentry.nextID;
        code = pr_WriteEntry(tt, 0, trail, &bentry);
+       if (code)
+           return PRDBFAIL;
     }
     *loc = current;
     return PRSUCCESS;
@@ -501,7 +490,7 @@ afs_int32
 AddToIDHash(struct ubik_trans *tt, afs_int32 aid, afs_int32 loc)
 {
     /* add entry at loc designated by aid to id hash table */
-    register afs_int32 code;
+    afs_int32 code;
     afs_int32 i;
     struct prentry tentry;
 
@@ -529,7 +518,7 @@ afs_int32
 RemoveFromNameHash(struct ubik_trans *tt, char *aname, afs_int32 *loc)
 {
     /* remove from name hash */
-    register afs_int32 code;
+    afs_int32 code;
     afs_int32 current, trail, i;
     struct prentry tentry;
     struct prentry bentry;
@@ -545,7 +534,7 @@ RemoveFromNameHash(struct ubik_trans *tt, char *aname, afs_int32 *loc)
     if (code)
        return PRDBFAIL;
     while (strcmp(aname, tentry.name)) {
-       assert(trail != current);
+       opr_Assert(trail != current);
        trail = current;
        current = tentry.nextName;
        if (current == 0)
@@ -570,6 +559,8 @@ RemoveFromNameHash(struct ubik_trans *tt, char *aname, afs_int32 *loc)
            return PRDBFAIL;
        bentry.nextName = tentry.nextName;
        code = pr_WriteEntry(tt, 0, trail, &bentry);
+       if (code)
+           return PRDBFAIL;
     }
     *loc = current;
     return PRSUCCESS;
@@ -579,7 +570,7 @@ afs_int32
 AddToNameHash(struct ubik_trans *tt, char *aname, afs_int32 loc)
 {
     /* add to name hash */
-    register afs_int32 code;
+    afs_int32 code;
     afs_int32 i;
     struct prentry tentry;
 
@@ -605,7 +596,7 @@ afs_int32
 AddToOwnerChain(struct ubik_trans *at, afs_int32 gid, afs_int32 oid)
 {
     /* add entry designated by gid to owner chain of entry designated by oid */
-    register afs_int32 code;
+    afs_int32 code;
     afs_int32 loc;
     struct prentry tentry;
     struct prentry gentry;
@@ -642,7 +633,7 @@ AddToOwnerChain(struct ubik_trans *at, afs_int32 gid, afs_int32 oid)
 afs_int32
 RemoveFromOwnerChain(struct ubik_trans *at, afs_int32 gid, afs_int32 oid)
 {
-    register afs_int32 code;
+    afs_int32 code;
     afs_int32 nptr;
     struct prentry thisEntry;
     struct prentry thatEntry;
@@ -701,7 +692,7 @@ RemoveFromOwnerChain(struct ubik_trans *at, afs_int32 gid, afs_int32 oid)
 afs_int32
 AddToOrphan(struct ubik_trans *at, afs_int32 gid)
 {
-    register afs_int32 code;
+    afs_int32 code;
     afs_int32 loc;
     struct prentry tentry;
 
@@ -726,7 +717,7 @@ afs_int32
 RemoveFromOrphan(struct ubik_trans *at, afs_int32 gid)
 {
     /* remove gid from the orphan list */
-    register afs_int32 code;
+    afs_int32 code;
     afs_int32 loc;
     afs_int32 nptr;
     struct prentry tentry;
@@ -781,7 +772,7 @@ afs_int32
 IsOwnerOf(struct ubik_trans *at, afs_int32 aid, afs_int32 gid)
 {
     /* returns 1 if aid is the owner of gid, 0 otherwise */
-    register afs_int32 code;
+    afs_int32 code;
     struct prentry tentry;
     afs_int32 loc;
 
@@ -800,7 +791,7 @@ afs_int32
 OwnerOf(struct ubik_trans *at, afs_int32 gid)
 {
     /* returns the owner of gid */
-    register afs_int32 code;
+    afs_int32 code;
     afs_int32 loc;
     struct prentry tentry;
 
@@ -821,7 +812,7 @@ IsAMemberOf(struct ubik_trans *at, afs_int32 aid, afs_int32 gid)
 #if !defined(SUPERGROUPS)
     struct prentry tentry;
     struct contentry centry;
-    register afs_int32 code;
+    afs_int32 code;
     afs_int32 i;
     afs_int32 loc;
 #endif
@@ -877,12 +868,12 @@ IsAMemberOf(struct ubik_trans *at, afs_int32 aid, afs_int32 gid)
 
 #if defined(SUPERGROUPS)
 afs_int32
-IsAMemberOfSG(struct ubik_trans *at, afs_int32 aid, afs_int32 gid, afs_int32 depth) 
+IsAMemberOfSG(struct ubik_trans *at, afs_int32 aid, afs_int32 gid, afs_int32 depth)
 {
     /* returns true if aid is a member of gid */
     struct prentry tentry;
     struct contentry centry;
-    register afs_int32 code;
+    afs_int32 code;
     afs_int32 i;
     afs_int32 loc;