Don't cast the return from realloc()
[openafs.git] / src / volser / volprocs.c
index 94f4586..c002b32 100644 (file)
 #include <afsconfig.h>
 #include <afs/param.h>
 
+#include <roken.h>
 
-#include <stdio.h>
-#include <sys/types.h>
-#include <string.h>
-#include <errno.h>
-#ifdef AFS_NT40_ENV
-#include <stdlib.h>
-#include <fcntl.h>
-#include <winsock2.h>
-#else
-#include <sys/file.h>
-#include <netinet/in.h>
-#include <unistd.h>
-#endif
-
-#include <dirent.h>
-#include <sys/stat.h>
 #include <rx/xdr.h>
 #include <rx/rx.h>
 #include <rx/rxkad.h>
 #include <afs/afsint.h>
-#include <signal.h>
-#ifdef AFS_PTHREAD_ENV
-#include <assert.h>
-#else /* AFS_PTHREAD_ENV */
-#include <afs/assert.h>
-#endif /* AFS_PTHREAD_ENV */
 #include <afs/prs_fs.h>
 #include <afs/nfs.h>
 #include <lwp.h>
@@ -61,6 +40,7 @@
 #include "afs/audit.h"
 #include <afs/dir.h>
 #include <afs/afsutil.h>
+#include <afs/com_err.h>
 #include <afs/vol_prototypes.h>
 #include <afs/errors.h>
 
@@ -74,6 +54,7 @@
 
 extern int DoLogging;
 extern struct afsconf_dir *tdir;
+extern int DoPreserveVolumeStats;
 
 extern void LogError(afs_int32 errcode);
 
@@ -132,6 +113,21 @@ static afs_int32 VolSetIdsTypes(struct rx_call *, afs_int32, char [],
                                afs_uint32);
 static afs_int32 VolSetDate(struct rx_call *, afs_int32, afs_int32);
 
+/**
+ * Return the host address of the caller as a string.
+ *
+ * @param[in]  acid    incoming rx call
+ * @param[out] buffer  buffer to be filled with the addess string
+ *
+ * @return address as formatted by inet_ntoa
+ */
+static_inline char *
+callerAddress(struct rx_call *acid, char *buffer)
+{
+    afs_uint32 ip = rx_HostOf(rx_PeerOf(rx_ConnectionOf(acid)));
+    return afs_inet_ntoa_r(ip, buffer);
+}
+
 /* this call unlocks all of the partition locks we've set */
 int
 VPFullUnlock_r(void)
@@ -139,7 +135,7 @@ VPFullUnlock_r(void)
     struct DiskPartition64 *tp;
     for (tp = DiskPartitionList; tp; tp = tp->next) {
        if (tp->lock_fd != INVALID_FD) {
-           close(tp->lock_fd); /* releases flock held on this partition */
+            OS_CLOSE(tp->lock_fd);
            tp->lock_fd = INVALID_FD;
        }
     }
@@ -200,7 +196,7 @@ ConvertVolume(afs_uint32 avol, char *aname, afs_int32 asize)
     if (asize < 18)
        return -1;
     /* It's better using the Generic VFORMAT since otherwise we have to make changes to too many places... The 14 char limitation in names hits us again in AIX; print in field of 9 digits (still 10 for the rest), right justified with 0 padding */
-    (void)afs_snprintf(aname, asize, VFORMAT, (unsigned long)avol);
+    snprintf(aname, asize, VFORMAT, (unsigned long)avol);
     return 0;
 }
 
@@ -324,13 +320,13 @@ XAttachVolume(afs_int32 *error, afs_uint32 avolid, afs_int32 apartid, int amode)
 }
 
 /* Adapted from the file server; create a root directory for this volume */
-static int
+static Error
 ViceCreateRoot(Volume *vp)
 {
     DirHandle dir;
     struct acl_accessList *ACL;
     AFSFid did;
-    Inode inodeNumber, nearInode;
+    Inode inodeNumber, AFS_UNUSED nearInode;
     struct VnodeDiskObject *vnode;
     struct VnodeClassInfo *vcp = &VnodeClassInfo[vLarge];
     IHandle_t *h;
@@ -338,27 +334,30 @@ ViceCreateRoot(Volume *vp)
     afs_fsize_t length;
     ssize_t nBytes;
 
-    vnode = (struct VnodeDiskObject *)malloc(SIZEOF_LARGEDISKVNODE);
+    vnode = calloc(1, SIZEOF_LARGEDISKVNODE);
     if (!vnode)
        return ENOMEM;
-    memset(vnode, 0, SIZEOF_LARGEDISKVNODE);
 
     V_pref(vp, nearInode);
     inodeNumber =
        IH_CREATE(V_linkHandle(vp), V_device(vp),
                  VPartitionPath(V_partition(vp)), nearInode, V_parentId(vp),
                  1, 1, 0);
-    assert(VALID_INO(inodeNumber));
+    if (!VALID_INO(inodeNumber)) {
+       Log("ViceCreateRoot: IH_CREATE: %s\n", afs_error_message(errno));
+       free(vnode);
+       return EIO;
+    }
 
     SetSalvageDirHandle(&dir, V_parentId(vp), vp->device, inodeNumber);
     did.Volume = V_id(vp);
     did.Vnode = (VnodeId) 1;
     did.Unique = 1;
 
-    assert(!(MakeDir(&dir, (afs_int32 *)&did, (afs_int32 *)&did)));
+    osi_Assert(!(afs_dir_MakeDir(&dir, (afs_int32 *)&did, (afs_int32 *)&did)));
     DFlush();                  /* flush all modified dir buffers out */
-    DZap((afs_int32 *)&dir);                   /* Remove all buffers for this dir */
-    length = Length(&dir);     /* Remember size of this directory */
+    DZap(&dir);                        /* Remove all buffers for this dir */
+    length = afs_dir_Length(&dir);     /* Remember size of this directory */
 
     FidZap(&dir);              /* Done with the dir handle obtained via SetSalvageDirHandle() */
 
@@ -395,16 +394,16 @@ ViceCreateRoot(Volume *vp)
     IH_INIT(h, vp->device, V_parentId(vp),
            vp->vnodeIndex[vLarge].handle->ih_ino);
     fdP = IH_OPEN(h);
-    assert(fdP != NULL);
+    osi_Assert(fdP != NULL);
     nBytes = FDH_PWRITE(fdP, vnode, SIZEOF_LARGEDISKVNODE, vnodeIndexOffset(vcp, 1));
-    assert(nBytes == SIZEOF_LARGEDISKVNODE);
+    osi_Assert(nBytes == SIZEOF_LARGEDISKVNODE);
     FDH_REALLYCLOSE(fdP);
     IH_RELEASE(h);
     VNDISK_GET_LEN(length, vnode);
     V_diskused(vp) = nBlocks(length);
 
     free(vnode);
-    return 1;
+    return 0;
 }
 
 afs_int32
@@ -485,8 +484,11 @@ VolNukeVolume(struct rx_call *acid, afs_int32 apartID, afs_uint32 avolID)
     /* check for access */
     if (!afsconf_SuperUser(tdir, acid, caller))
        return VOLSERBAD_ACCESS;
-    if (DoLogging)
-       Log("%s is executing VolNukeVolume %u\n", caller, avolID);
+    if (DoLogging) {
+       char buffer[16];
+       Log("%s on %s is executing VolNukeVolume %u\n", caller,
+           callerAddress(acid, buffer), avolID);
+    }
 
     if (volutil_PartitionName2_r(apartID, partName, sizeof(partName)) != 0)
        return VOLSERNOVOL;
@@ -540,8 +542,11 @@ VolCreateVolume(struct rx_call *acid, afs_int32 apart, char *aname,
        return VOLSERBADNAME;
     if (!afsconf_SuperUser(tdir, acid, caller))
        return VOLSERBAD_ACCESS;
-    if (DoLogging)
-       Log("%s is executing CreateVolume '%s'\n", caller, aname);
+    if (DoLogging) {
+       char buffer[16];
+       Log("%s on %s is executing CreateVolume '%s'\n", caller,
+           callerAddress(acid, buffer), aname);
+    }
     if ((error = ConvertPartition(apart, ppath, sizeof(ppath))))
        return error;           /*a standard unix error */
     if (atype != readwriteVolume && atype != readonlyVolume
@@ -580,8 +585,17 @@ VolCreateVolume(struct rx_call *acid, afs_int32 apart, char *aname,
     V_inService(vp) = V_blessed(vp) = 1;
     V_type(vp) = atype;
     AssignVolumeName(&V_disk(vp), aname, 0);
-    if (doCreateRoot)
-       ViceCreateRoot(vp);
+    if (doCreateRoot) {
+       error = ViceCreateRoot(vp);
+       if (error) {
+           Log("1 Volser: CreateVolume: Unable to create volume root dir; "
+               "error code %u\n", (unsigned)error);
+           DeleteTrans(tt, 1);
+           V_needsSalvaged(vp) = 1;
+           VDetachVolume(&junk, vp);
+           return EIO;
+       }
+    }
     V_destroyMe(vp) = DESTROY_ME;
     V_inService(vp) = 0;
     V_maxquota(vp) = 5000;     /* set a quota of 5000 at init time */
@@ -633,11 +647,17 @@ VolDeleteVolume(struct rx_call *acid, afs_int32 atrans)
        TRELE(tt);
        return ENOENT;
     }
-    if (DoLogging)
-       Log("%s is executing Delete Volume %u\n", caller, tt->volid);
+    if (DoLogging) {
+       char buffer[16];
+       Log("%s on %s is executing Delete Volume %u\n", caller,
+           callerAddress(acid, buffer), tt->volid);
+    }
     TSetRxCall(tt, acid, "DeleteVolume");
     VPurgeVolume(&error, tt->volume);  /* don't check error code, it is not set! */
-    V_destroyMe(tt->volume) = DESTROY_ME; /* so endtrans does the right fssync opcode */
+    V_destroyMe(tt->volume) = DESTROY_ME;
+    if (tt->volume->needsPutBack) {
+       tt->volume->needsPutBack = VOL_PUTBACK_DELETE; /* so endtrans does the right fssync opcode */
+    }
     VTRANS_OBJ_LOCK(tt);
     tt->vflags |= VTDeleted;   /* so we know not to do anything else to it */
     TClearRxCall_r(tt);
@@ -690,8 +710,11 @@ VolClone(struct rx_call *acid, afs_int32 atrans, afs_uint32 purgeId,
        return VOLSERBADNAME;
     if (!afsconf_SuperUser(tdir, acid, caller))
        return VOLSERBAD_ACCESS;        /*not a super user */
-    if (DoLogging)
-       Log("%s is executing Clone Volume new name=%s\n", caller, newName);
+    if (DoLogging) {
+       char buffer[16];
+       Log("%s on %s is executing Clone Volume new name=%s\n", caller,
+           callerAddress(acid, buffer), newName);
+    }
     error = 0;
     originalvp = (Volume *) 0;
     purgevp = (Volume *) 0;
@@ -704,8 +727,6 @@ VolClone(struct rx_call *acid, afs_int32 atrans, afs_uint32 purgeId,
     }
     newId = *newNumber;
 
-    if (newType != readonlyVolume && newType != backupVolume)
-       return EINVAL;
     tt = FindTrans(atrans);
     if (!tt)
        return ENOENT;
@@ -732,12 +753,6 @@ VolClone(struct rx_call *acid, afs_int32 atrans, afs_uint32 purgeId,
        purgevp = NULL;
     }
     originalvp = tt->volume;
-    if ((V_type(originalvp) == backupVolume)
-       || (V_type(originalvp) == readonlyVolume)) {
-       Log("1 Volser: Clone: The volume to be cloned must be a read/write; aborted\n");
-       error = EROFS;
-       goto fail;
-    }
     if ((V_destroyMe(originalvp) == DESTROY_ME) || !V_inService(originalvp)) {
        Log("1 Volser: Clone: Volume %d is offline and cannot be cloned\n",
            V_id(originalvp));
@@ -755,15 +770,8 @@ VolClone(struct rx_call *acid, afs_int32 atrans, afs_uint32 purgeId,
            error = EINVAL;
            goto fail;
        }
-       if (V_type(originalvp) == readonlyVolume
-           && V_parentId(originalvp) != V_parentId(purgevp)) {
-           Log("1 Volser: Clone: Volume %u and volume %u were not cloned from the same parent volume; aborted\n", tt->volid, purgeId);
-           error = EXDEV;
-           goto fail;
-       }
-       if (V_type(originalvp) == readwriteVolume
-           && tt->volid != V_parentId(purgevp)) {
-           Log("1 Volser: Clone: Volume %u was not originally cloned from volume %u; aborted\n", purgeId, tt->volid);
+       if (V_parentId(originalvp) != V_parentId(purgevp)) {
+           Log("1 Volser: Clone: Volume %u and volume %u were not originally cloned from the same parent; aborted\n", purgeId, tt->volid);
            error = EXDEV;
            goto fail;
        }
@@ -774,13 +782,17 @@ VolClone(struct rx_call *acid, afs_int32 atrans, afs_uint32 purgeId,
     salv_vp = originalvp;
 #endif
 
-    newvp =
-       VCreateVolume(&error, originalvp->partition->name, newId,
-                     V_parentId(originalvp));
-    if (error) {
-       Log("1 Volser: Clone: Couldn't create new volume; clone aborted\n");
-       newvp = (Volume *) 0;
-       goto fail;
+    if (purgeId == newId) {
+       newvp = purgevp;
+    } else {
+       newvp =
+           VCreateVolume(&error, originalvp->partition->name, newId,
+                         V_parentId(originalvp));
+       if (error) {
+           Log("1 Volser: Clone: Couldn't create new volume; clone aborted\n");
+           newvp = (Volume *) 0;
+           goto fail;
+       }
     }
     if (newType == readonlyVolume)
        V_cloneId(originalvp) = newId;
@@ -852,8 +864,7 @@ VolClone(struct rx_call *acid, afs_int32 atrans, afs_uint32 purgeId,
        DeleteTrans(ttc, 1);
 #ifdef AFS_DEMAND_ATTACH_FS
     if (salv_vp && error != VVOLEXISTS && error != EXDEV) {
-       Error salv_error;
-       VRequestSalvage_r(&salv_error, salv_vp, FSYNC_SALVAGE, 0);
+       V_needsSalvaged(salv_vp) = 1;
     }
 #endif /* AFS_DEMAND_ATTACH_FS */
     return error;
@@ -879,12 +890,16 @@ VolReClone(struct rx_call *acid, afs_int32 atrans, afs_int32 cloneId)
     afs_int32 newType;
     struct volser_trans *tt, *ttc;
     char caller[MAXKTCNAMELEN];
+    VolumeDiskData saved_header;
 
     /*not a super user */
     if (!afsconf_SuperUser(tdir, acid, caller))
        return VOLSERBAD_ACCESS;
-    if (DoLogging)
-       Log("%s is executing Reclone Volume %u\n", caller, cloneId);
+    if (DoLogging) {
+       char buffer[16];
+       Log("%s on %s is executing Reclone Volume %u\n", caller,
+           callerAddress(acid, buffer), cloneId);
+    }
     error = 0;
     clonevp = originalvp = (Volume *) 0;
     tt = (struct volser_trans *)0;
@@ -905,12 +920,6 @@ VolReClone(struct rx_call *acid, afs_int32 atrans, afs_int32 cloneId)
     TSetRxCall(tt, acid, "ReClone");
 
     originalvp = tt->volume;
-    if ((V_type(originalvp) == backupVolume)
-       || (V_type(originalvp) == readonlyVolume)) {
-       Log("1 Volser: Clone: The volume to be cloned must be a read/write; aborted\n");
-       error = EROFS;
-       goto fail;
-    }
     if ((V_destroyMe(originalvp) == DESTROY_ME) || !V_inService(originalvp)) {
        Log("1 Volser: Clone: Volume %d is offline and cannot be cloned\n",
            V_id(originalvp));
@@ -932,24 +941,16 @@ VolReClone(struct rx_call *acid, afs_int32 atrans, afs_int32 cloneId)
        error = EXDEV;
        goto fail;
     }
-    if (V_type(clonevp) != readonlyVolume && V_type(clonevp) != backupVolume) {
-       Log("1 Volser: Clone: The \"recloned\" volume must be a read only volume; aborted\n");
-       error = EINVAL;
-       goto fail;
-    }
-    if (V_type(originalvp) == readonlyVolume
-       && V_parentId(originalvp) != V_parentId(clonevp)) {
-       Log("1 Volser: Clone: Volume %u and volume %u were not cloned from the same parent volume; aborted\n", tt->volid, cloneId);
-       error = EXDEV;
-       goto fail;
-    }
-    if (V_type(originalvp) == readwriteVolume
-       && tt->volid != V_parentId(clonevp)) {
+    if (V_parentId(originalvp) != V_parentId(clonevp)) {
        Log("1 Volser: Clone: Volume %u was not originally cloned from volume %u; aborted\n", cloneId, tt->volid);
        error = EXDEV;
        goto fail;
     }
 
+    if (DoPreserveVolumeStats) {
+       CopyVolumeStats(&V_disk(clonevp), &saved_header);
+    }
+
     error = 0;
     Log("1 Volser: Clone: Recloning volume %u to volume %u\n", tt->volid,
        cloneId);
@@ -972,15 +973,20 @@ VolReClone(struct rx_call *acid, afs_int32 atrans, afs_int32 cloneId)
     }
     /* don't do strcpy onto diskstuff.name, it's still OK from 1st clone */
 
-    /* pretend recloned volume is a totally new instance */
-    V_copyDate(clonevp) = time(0);
-    V_creationDate(clonevp) = V_copyDate(clonevp);
-    ClearVolumeStats(&V_disk(clonevp));
+    /* update the creationDate, since this represents the last cloning date
+     * for ROs. But do not update copyDate; let it stay so we can identify
+     * when the clone was first created. */
+    V_creationDate(clonevp) = time(0);
+    if (DoPreserveVolumeStats) {
+       CopyVolumeStats(&saved_header, &V_disk(clonevp));
+    } else {
+       ClearVolumeStats(&V_disk(clonevp));
+    }
     V_destroyMe(clonevp) = 0;
     V_inService(clonevp) = 0;
     if (newType == backupVolume) {
-       V_backupDate(originalvp) = V_copyDate(clonevp);
-       V_backupDate(clonevp) = V_copyDate(clonevp);
+       V_backupDate(originalvp) = V_creationDate(clonevp);
+       V_backupDate(clonevp) = V_creationDate(clonevp);
     }
     V_inUse(clonevp) = 0;
     VUpdateVolume(&error, clonevp);
@@ -1238,7 +1244,7 @@ SAFSVolForward(struct rx_call *acid, afs_int32 fromTrans, afs_int32 fromDate,
     code =
        VolForward(acid, fromTrans, fromDate, destination, destTrans, cookie);
     osi_auditU(acid, VS_ForwardEvent, code, AUD_LONG, fromTrans, AUD_HOST,
-              destination->destHost, AUD_LONG, destTrans, AUD_END);
+              htonl(destination->destHost), AUD_LONG, destTrans, AUD_END);
     return code;
 }
 
@@ -1441,7 +1447,7 @@ SAFSVolForwardMultiple(struct rx_call *acid, afs_int32 fromTrans, afs_int32
        }
 
        osi_auditU(acid, VS_ForwardEvent, (code ? code : codes[i]), AUD_LONG,
-                  fromTrans, AUD_HOST, dest->server.destHost, AUD_LONG,
+                  fromTrans, AUD_HOST, htonl(dest->server.destHost), AUD_LONG,
                   dest->trans, AUD_END);
     }
     free(tcons);
@@ -1591,7 +1597,7 @@ SAFSVolSetForwarding(struct rx_call *acid, afs_int32 atid, afs_int32 anewsite)
 
     code = VolSetForwarding(acid, atid, anewsite);
     osi_auditU(acid, VS_SetForwEvent, code, AUD_LONG, atid, AUD_HOST,
-              anewsite, AUD_END);
+              htonl(anewsite), AUD_END);
     return code;
 }
 
@@ -1792,7 +1798,7 @@ VolGetName(struct rx_call *acid, afs_int32 atrans, char **aname)
        TRELE(tt);
        return E2BIG;
     }
-    *aname = (char *)realloc(*aname, len);
+    *aname = realloc(*aname, len);
     strcpy(*aname, td->name);
     TClearRxCall(tt);
     if (TRELE(tt))
@@ -1884,32 +1890,21 @@ XVolListPartitions(struct rx_call *acid, struct partEntries *pEntries)
        if (dp)
            partList.partId[j++] = i;
     }
-    pEntries->partEntries_val = (afs_int32 *) malloc(j * sizeof(int));
-    if (!pEntries->partEntries_val)
-       return ENOMEM;
-    memcpy((char *)pEntries->partEntries_val, (char *)&partList,
-          j * sizeof(int));
-    pEntries->partEntries_len = j;
+    if (j > 0) {
+       pEntries->partEntries_val = (afs_int32 *) malloc(j * sizeof(int));
+       if (!pEntries->partEntries_val)
+           return ENOMEM;
+       memcpy((char *)pEntries->partEntries_val, (char *)&partList,
+               j * sizeof(int));
+       pEntries->partEntries_len = j;
+    } else {
+       pEntries->partEntries_val = NULL;
+       pEntries->partEntries_len = 0;
+    }
     return 0;
 
 }
 
-/*extract the volume id from string vname. Its of the form " V0*<id>.vol  "*/
-afs_int32
-ExtractVolId(char vname[])
-{
-    int i;
-    char name[VOLSER_MAXVOLNAME + 1];
-
-    strcpy(name, vname);
-    i = 0;
-    while (name[i] == 'V' || name[i] == '0')
-       i++;
-
-    name[11] = '\0';           /* smash the "." */
-    return (atol(&name[i]));
-}
-
 /*return the name of the next volume header in the directory associated with dirp and dp.
 *the volume id is  returned in volid, and volume header name is returned in volname*/
 int
@@ -1920,7 +1915,7 @@ GetNextVol(DIR * dirp, char *volname, afs_uint32 * volid)
     dp = readdir(dirp);                /*read next entry in the directory */
     if (dp) {
        if ((dp->d_name[0] == 'V') && !strcmp(&(dp->d_name[11]), VHDREXT)) {
-           *volid = ExtractVolId(dp->d_name);
+           *volid = VolumeNumber(dp->d_name);
            strcpy(volname, dp->d_name);
            return 0;           /*return the name of the file representing a volume */
        } else {
@@ -2224,7 +2219,10 @@ GetVolInfo(afs_uint32 partId,
     }
 
     /* Get volume from volserver */
-    tv = VAttachVolumeByName_retry(&error, pname, volname, V_PEEK);
+    if (mode == VOL_INFO_LIST_MULTIPLE)
+       tv = VAttachVolumeByName(&error, pname, volname, V_PEEK);
+    else
+       tv = VAttachVolumeByName_retry(&error, pname, volname, V_PEEK);
     if (error) {
        Log("1 Volser: GetVolInfo: Could not attach volume %u (%s:%s) error=%d\n",
            volumeId, pname, volname, error);
@@ -2336,10 +2334,9 @@ VolListOneVolume(struct rx_call *acid, afs_int32 partid,
     int code;
     volint_info_handle_t handle;
 
-    volumeInfo->volEntries_val = (volintInfo *) malloc(sizeof(volintInfo));
+    volumeInfo->volEntries_val = calloc(1, sizeof(volintInfo));
     if (!volumeInfo->volEntries_val)
        return ENOMEM;
-    memset(volumeInfo->volEntries_val, 0, sizeof(volintInfo)); /* Clear structure */
 
     volumeInfo->volEntries_len = 1;
     if (GetPartName(partid, pname))
@@ -2384,7 +2381,10 @@ VolListOneVolume(struct rx_call *acid, afs_int32 partid,
     }
 
     closedir(dirp);
-    return (found) ? 0 : ENODEV;
+    if (found)
+        return code ? ENODEV: 0;
+    else
+        return ENODEV;
 }
 
 /*------------------------------------------------------------------------
@@ -2438,11 +2438,9 @@ VolXListOneVolume(struct rx_call *a_rxCidP, afs_int32 a_partID,
      * Set up our pointers for action, marking our structure to hold exactly
      * one entry.  Also, assume we'll fail in our quest.
      */
-    a_volumeXInfoP->volXEntries_val =
-       (volintXInfo *) malloc(sizeof(volintXInfo));
+    a_volumeXInfoP->volXEntries_val = calloc(1, sizeof(volintXInfo));
     if (!a_volumeXInfoP->volXEntries_val)
        return ENOMEM;
-    memset(a_volumeXInfoP->volXEntries_val, 0, sizeof(volintXInfo)); /* Clear structure */
 
     a_volumeXInfoP->volXEntries_len = 1;
     code = ENODEV;
@@ -2515,7 +2513,10 @@ VolXListOneVolume(struct rx_call *a_rxCidP, afs_int32 a_partID,
      * return the proper value.
      */
     closedir(dirp);
-    return (found) ? 0 : ENODEV;
+    if (found)
+        return code ? ENODEV: 0;
+    else
+        return ENODEV;
 }                              /*SAFSVolXListOneVolume */
 
 /*returns all the volumes on partition partid. If flags = 1 then all the
@@ -2544,11 +2545,9 @@ VolListVolumes(struct rx_call *acid, afs_int32 partid, afs_int32 flags,
     int code;
     volint_info_handle_t handle;
 
-    volumeInfo->volEntries_val =
-       (volintInfo *) malloc(allocSize * sizeof(volintInfo));
+    volumeInfo->volEntries_val = calloc(allocSize, sizeof(volintInfo));
     if (!volumeInfo->volEntries_val)
        return ENOMEM;
-    memset(volumeInfo->volEntries_val, 0, sizeof(volintInfo)); /* Clear structure */
 
     pntr = volumeInfo->volEntries_val;
     volumeInfo->volEntries_len = 0;
@@ -2596,9 +2595,8 @@ VolListVolumes(struct rx_call *acid, afs_int32 partid, afs_int32 flags,
        if ((allocSize - volumeInfo->volEntries_len) < 5) {
            /*running out of space, allocate more space */
            allocSize = (allocSize * 3) / 2;
-           pntr =
-               (volintInfo *) realloc((char *)volumeInfo->volEntries_val,
-                                      allocSize * sizeof(volintInfo));
+           pntr = realloc(volumeInfo->volEntries_val,
+                          allocSize * sizeof(volintInfo));
            if (pntr == NULL) {
                closedir(dirp);
                return VOLSERNO_MEMORY;
@@ -2674,11 +2672,9 @@ VolXListVolumes(struct rx_call *a_rxCidP, afs_int32 a_partID,
      * Allocate a large array of extended volume info structures, then
      * set it up for action.
      */
-    a_volumeXInfoP->volXEntries_val =
-       (volintXInfo *) malloc(allocSize * sizeof(volintXInfo));
+    a_volumeXInfoP->volXEntries_val = calloc(allocSize, sizeof(volintXInfo));
     if (!a_volumeXInfoP->volXEntries_val)
        return ENOMEM;
-    memset(a_volumeXInfoP->volXEntries_val, 0, sizeof(volintXInfo)); /* Clear structure */
 
     xInfoP = a_volumeXInfoP->volXEntries_val;
     a_volumeXInfoP->volXEntries_len = 0;
@@ -2835,21 +2831,20 @@ VolMonitor(struct rx_call *acid, transDebugEntries *transInfo)
        pntr->callValid = 0;
        if (tt->rxCallPtr) {    /*record call related info */
            pntr->callValid = 1;
+#if 0
            pntr->readNext = tt->rxCallPtr->rnext;
            pntr->transmitNext = tt->rxCallPtr->tnext;
            pntr->lastSendTime = tt->rxCallPtr->lastSendTime;
            pntr->lastReceiveTime = tt->rxCallPtr->lastReceiveTime;
+#endif
        }
         VTRANS_OBJ_UNLOCK(tt);
        pntr++;
        transInfo->transDebugEntries_len += 1;
        if ((allocSize - transInfo->transDebugEntries_len) < 5) {       /*alloc some more space */
            allocSize = (allocSize * 3) / 2;
-           pntr =
-               (transDebugInfo *) realloc((char *)transInfo->
-                                          transDebugEntries_val,
-                                          allocSize *
-                                          sizeof(transDebugInfo));
+           pntr = realloc(transInfo->transDebugEntries_val,
+                          allocSize * sizeof(transDebugInfo));
            transInfo->transDebugEntries_val = pntr;
            pntr =
                transInfo->transDebugEntries_val +