backup deletedump: Change -port to -portoffset
[openafs.git] / src / bucoord / commands.c
index ea8b9c0..daeb791 100644 (file)
@@ -24,6 +24,7 @@
 #include <afs/budb_prototypes.h>
 #include <afs/butc.h>
 #include <afs/bubasics.h>      /* PA */
+#include <afs/afsint.h>
 #include <afs/volser.h>
 #include <afs/voldefs.h>       /* PA */
 #include <afs/vldbint.h>       /* PA */
@@ -107,13 +108,12 @@ getSPEntries(afs_uint32 server, afs_int32 partition,
     }
     /* No server entry added. Add one */
     if (!(*ss)) {
-       *ss = (struct serversort *)malloc(sizeof(struct serversort));
+       *ss = calloc(1, sizeof(struct serversort));
        if (!(*ss)) {
            afs_com_err(whoami, BC_NOMEM, NULL);
            *ss = 0;
            return (BC_NOMEM);
        }
-       memset(*ss, 0, sizeof(struct serversort));
        (*ss)->ipaddr = server;
        (*ss)->next = *serverlist;
        *serverlist = *ss;
@@ -128,7 +128,7 @@ getSPEntries(afs_uint32 server, afs_int32 partition,
     }
     /* No partition entry added. Add one */
     if (!(*ps)) {
-       *ps = (struct partitionsort *)malloc(sizeof(struct partitionsort));
+       *ps = calloc(1, sizeof(struct partitionsort));
        if (!(*ps)) {
            afs_com_err(whoami, BC_NOMEM, NULL);
            free(*ss);
@@ -136,7 +136,6 @@ getSPEntries(afs_uint32 server, afs_int32 partition,
            *ss = 0;
            return (BC_NOMEM);
        }
-       memset(*ps, 0, sizeof(struct partitionsort));
        (*ps)->part = partition;
        (*ps)->next = (*ss)->partitions;
        (*ss)->partitions = *ps;
@@ -309,15 +308,13 @@ EvalVolumeSet2(struct bc_config *aconfig,
 
                if (add) {
                    /* Allocate a volume dump structure and its name */
-                   tvd = (struct bc_volumeDump *)
-                       malloc(sizeof(struct bc_volumeDump));
+                   tvd = calloc(1, sizeof(struct bc_volumeDump));
                    if (!tvd) {
                        afs_com_err(whoami, BC_NOMEM, NULL);
                        ERROR(BC_NOMEM);
                    }
-                   memset(tvd, 0, sizeof(*tvd));
 
-                   tvd->name = (char *)malloc(strlen(entries[e].name) + 10);
+                   tvd->name = malloc(strlen(entries[e].name) + 10);
                    if (!(tvd->name)) {
                        afs_com_err(whoami, BC_NOMEM, NULL);
                        free(tvd);
@@ -579,15 +576,13 @@ EvalVolumeSet1(struct bc_config *aconfig,
                }
 
                total++;
-               tvd = (struct bc_volumeDump *)
-                   malloc(sizeof(struct bc_volumeDump));
+               tvd = calloc(1, sizeof(struct bc_volumeDump));
                if (!tvd) {
                    afs_com_err(whoami, BC_NOMEM, NULL);
                    return (BC_NOMEM);
                }
-               memset(tvd, 0, sizeof(*tvd));
 
-               tvd->name = (char *)malloc(strlen(entry.name) + 10);
+               tvd->name = malloc(strlen(entry.name) + 10);
                if (!(tvd->name)) {
                    afs_com_err(whoami, BC_NOMEM, NULL);
                    free(tvd);
@@ -765,7 +760,7 @@ concatParams(struct cmd_item *itemPtr)
        return (NULL);
     }
 
-    string = (char *)malloc(length);   /* allocate the string */
+    string = malloc(length);   /* allocate the string */
     if (!string) {
        afs_com_err(whoami, BC_NOMEM, NULL);
        return (NULL);
@@ -1167,33 +1162,28 @@ bc_VolRestoreCmd(struct cmd_syndesc *as, void *arock)
     }
 
     /* specified other destination host */
-    if (as->parms[0].items) {
-       tp = as->parms[0].items->data;
-       if (bc_ParseHost(tp, &destServ)) {
-           afs_com_err(whoami, 0, "Failed to locate destination host '%s'", tp);
-           return -1;
-       }
+    tp = as->parms[0].items->data;
+    if (bc_ParseHost(tp, &destServ)) {
+       afs_com_err(whoami, 0, "Failed to locate destination host '%s'", tp);
+       return -1;
     }
 
     /* specified other destination partition */
-    if (as->parms[1].items) {
-       tp = as->parms[1].items->data;
-       if (bc_GetPartitionID(tp, &destPartition)) {
-           afs_com_err(whoami, 0, "Can't parse destination partition '%s'", tp);
-           return -1;
-       }
+    tp = as->parms[1].items->data;
+    if (bc_GetPartitionID(tp, &destPartition)) {
+       afs_com_err(whoami, 0, "Can't parse destination partition '%s'", tp);
+       return -1;
     }
 
     for (ti = as->parms[2].items; ti; ti = ti->next) {
        /* build list of volume items */
-       tvol = (struct bc_volumeDump *)malloc(sizeof(struct bc_volumeDump));
+       tvol = calloc(1, sizeof(struct bc_volumeDump));
        if (!tvol) {
            afs_com_err(whoami, BC_NOMEM, NULL);
            return BC_NOMEM;
        }
-       memset(tvol, 0, sizeof(struct bc_volumeDump));
 
-       tvol->name = (char *)malloc(VOLSER_MAXVOLNAME + 1);
+       tvol->name = malloc(VOLSER_MAXVOLNAME + 1);
        if (!tvol->name) {
            afs_com_err(whoami, BC_NOMEM, NULL);
            return BC_NOMEM;
@@ -1233,7 +1223,7 @@ bc_VolRestoreCmd(struct cmd_syndesc *as, void *arock)
     if (as->parms[5].items) {
        for (ti = as->parms[5].items; ti; ti = ti->next)
            portCount++;
-       ports = (afs_int32 *) malloc(portCount * sizeof(afs_int32));
+       ports = malloc(portCount * sizeof(afs_int32));
        if (!ports) {
            afs_com_err(whoami, BC_NOMEM, NULL);
            return BC_NOMEM;
@@ -1363,7 +1353,7 @@ bc_DiskRestoreCmd(struct cmd_syndesc *as, void *arock)
     if (as->parms[2].items) {
        for (ti = as->parms[2].items; ti; ti = ti->next)
            portCount++;
-       ports = (afs_int32 *) malloc(portCount * sizeof(afs_int32));
+       ports = malloc(portCount * sizeof(afs_int32));
        if (!ports) {
            afs_com_err(whoami, BC_NOMEM, NULL);
            return BC_NOMEM;
@@ -1530,11 +1520,9 @@ bc_VolsetRestoreCmd(struct cmd_syndesc *as, void *arock)
            }
 
            /* Allocate a volumeDump structure and link it in */
-           tvol =
-               (struct bc_volumeDump *)malloc(sizeof(struct bc_volumeDump));
-           memset(tvol, 0, sizeof(struct bc_volumeDump));
+           tvol = calloc(1, sizeof(struct bc_volumeDump));
 
-           tvol->name = (char *)malloc(VOLSER_MAXVOLNAME + 1);
+           tvol->name = malloc(VOLSER_MAXVOLNAME + 1);
            if (!tvol->name) {
                afs_com_err(whoami, BC_NOMEM, NULL);
                return BC_NOMEM;
@@ -1560,7 +1548,7 @@ bc_VolsetRestoreCmd(struct cmd_syndesc *as, void *arock)
     if (as->parms[2].items) {
        for (ti = as->parms[2].items; ti; ti = ti->next)
            portCount++;
-       ports = (afs_int32 *) malloc(portCount * sizeof(afs_int32));
+       ports = malloc(portCount * sizeof(afs_int32));
        if (!ports) {
            afs_com_err(whoami, BC_NOMEM, NULL);
            return BC_NOMEM;
@@ -1715,7 +1703,7 @@ bc_DumpCmd(struct cmd_syndesc *as, void *arock)
 
        /* get the port number, if one was specified */
        if (as->parms[2].items) {
-           portp = (afs_int32 *) malloc(sizeof(afs_int32));
+           portp = malloc(sizeof(afs_int32));
            if (!portp) {
                afs_com_err(whoami, BC_NOMEM, NULL);
                return BC_NOMEM;
@@ -1796,7 +1784,7 @@ bc_DumpCmd(struct cmd_syndesc *as, void *arock)
            sprintf(statusPtr->taskName, "Scheduled Dump");
            statusPtr->jobNumber = bc_jobNumber();
            statusPtr->scheduledDump = atTime;
-           statusPtr->cmdLine = (char *)malloc(length);
+           statusPtr->cmdLine = malloc(length);
            if (!statusPtr->cmdLine) {
                afs_com_err(whoami, BC_NOMEM, NULL);
                return BC_NOMEM;
@@ -2457,7 +2445,7 @@ bc_deleteDumpCmd(struct cmd_syndesc *as, void *arock)
        havetime = 1;
     }
 
-    port = (as->parms[3].items ? getPortOffset(as->parms[3].items->data) : 0); /* -port */
+    port = (as->parms[3].items ? getPortOffset(as->parms[3].items->data) : 0); /* -portoffset */
     if (as->parms[5].items)    /* -dbonly */
        port = -1;
 
@@ -2761,12 +2749,10 @@ DBLookupByVolume(char *volumeName)
            for (i = 0; i < numEntries; i++) {  /*f */
                struct dumpedVol *insPtr, **prevPtr;
 
-               tempPtr =
-                   (struct dumpedVol *)malloc(sizeof(struct dumpedVol));
+               tempPtr = calloc(1, sizeof(struct dumpedVol));
                if (!tempPtr)
                    ERROR(BC_NOMEM);
 
-               memset(tempPtr, 0, sizeof(*tempPtr));
                tempPtr->incTime = volumeEntry[i].clone;
                tempPtr->dumpID = volumeEntry[i].dump;
                strncpy(tempPtr->tapeName, volumeEntry[i].tape,
@@ -2919,13 +2905,12 @@ dumpInfo(afs_int32 dumpid, afs_int32 detailFlag)
 
     /* now get the list of tapes */
     for (tapeNumber = dumpEntry.tapes.b; tapeNumber <= dumpEntry.tapes.maxTapes; tapeNumber++) {       /*f */
-       tapeLinkPtr = (struct tapeLink *)malloc(sizeof(struct tapeLink));
+       tapeLinkPtr = calloc(1, sizeof(struct tapeLink));
        if (!tapeLinkPtr) {
            afs_com_err(whoami, BC_NOMEM, NULL);
            ERROR(BC_NOMEM);
        }
 
-       memset(tapeLinkPtr, 0, sizeof(*tapeLinkPtr));
        code = bcdb_FindTapeSeq(dumpid, tapeNumber, &tapeLinkPtr->tapeEntry);
        if (code) {
            code = 0;
@@ -2970,13 +2955,11 @@ dumpInfo(afs_int32 dumpid, afs_int32 detailFlag)
            for (i = 0; i < vl.budb_volumeList_len; i++) {
                link = &tapeLinkPtr->firstVolume;
 
-               volumeLinkPtr =
-                   (struct volumeLink *)malloc(sizeof(struct volumeLink));
+               volumeLinkPtr = calloc(1, sizeof(struct volumeLink));
                if (!volumeLinkPtr) {
                    afs_com_err(whoami, BC_NOMEM, NULL);
                    ERROR(BC_NOMEM);
                }
-               memset(volumeLinkPtr, 0, sizeof(*volumeLinkPtr));
 
                memcpy(&volumeLinkPtr->volumeEntry,
                       &vl.budb_volumeList_val[i],