/*
* 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 <afsconfig.h>
#include <afs/param.h>
-RCSID("$Header$");
+#include <roken.h>
-#include <sys/types.h>
#include <afs/cmd.h>
-#ifdef AFS_NT40_ENV
-#include <winsock2.h>
-#else
-#include <strings.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#endif
-#include <stdio.h>
-#include <dirent.h>
#include <afs/afsutil.h>
#include <afs/budb.h>
#include <afs/bubasics.h>
+#include <afs/afsint.h>
#include <afs/volser.h>
-#define dprintf /* debug */
+#include "bc.h"
+
+/* protos */
+
+static char * TapeName(char *);
+static char * DumpName(afs_int32 adumpID);
+static FILE * OpenDump(afs_int32 , char * );
+FILE * OpenTape(char * , char * );
+static afs_int32 ScanForChildren(afs_int32 );
+static afs_int32 DeleteDump(afs_int32 );
+char * tailCompPtr(char *);
+afs_int32 ScanDumpHdr(FILE *, char *, char *, afs_int32 *, afs_int32 *,
+ afs_int32 *, afs_int32 *);
+afs_int32 ScanTapeVolume(FILE *, char *, afs_int32 *, char *, afs_int32 *, afs_int32 *,
+ afs_int32 *, afs_int32 *);
+afs_int32 ScanVolClone(FILE *, char *, afs_int32 *);
+
/* basic format of a tape file is a file, whose name is "T<tapename>.db", and
* which contains the fields
* Note that dumpEndTime is stored and returned in the dump creation time field.
*/
-afs_int32 DeleteDump();
-afs_int32 ScanDumpHdr();
-
/* return the tape file name corresponding to a particular tape */
-static char *TapeName(atapeName)
-register char *atapeName; {
- static char tbuffer[AFSDIR_PATH_MAX];
-
- /* construct the backup dir path */
- strcpy(tbuffer, AFSDIR_SERVER_BACKUP_DIRPATH);
- strcat(tbuffer, "/T");
- strcat(tbuffer+1, atapeName);
- strcat(tbuffer, ".db");
+
+static char * TapeName(char *atapeName)
+{
+ char *tbuffer;
+
+ if (asprintf(&tbuffer, "%s/T%s.db", AFSDIR_SERVER_BACKUP_DIRPATH,
+ atapeName) < 0)
+ return NULL;
return tbuffer;
}
/* return the dump file name corresponding to a particular dump ID */
-static char *DumpName(adumpID)
-register afs_int32 adumpID;
+
+static char * DumpName(afs_int32 adumpID)
{
- static char tbuffer[AFSDIR_PATH_MAX];
- char buf[AFSDIR_PATH_MAX];
+ char *tbuffer;
- /* construct the backup dir path */
- strcpy(buf, AFSDIR_SERVER_BACKUP_DIRPATH);
- strcat(buf, "/D%d.db");
- sprintf(tbuffer, buf, adumpID);
+ if (asprintf(&tbuffer, "%s/D%d.db", AFSDIR_SERVER_BACKUP_DIRPATH,
+ adumpID) < 0)
+ return NULL;
return tbuffer;
}
-static FILE *OpenDump(adumpID, awrite)
-char *awrite;
-afs_int32 adumpID; {
- register char *tp;
- register FILE *tfile;
+static FILE * OpenDump(afs_int32 adumpID, char * awrite)
+{
+ char *tp;
+ FILE *tfile;
tp = DumpName(adumpID);
+ if (tp == NULL)
+ return NULL;
tfile = fopen(tp, awrite);
+ free(tp);
return tfile;
}
/* OpenTape
- * notes:
+ * notes:
* non-static for recoverDB
*/
-FILE *OpenTape(atapeName, awrite)
-char *awrite;
-char *atapeName; {
- register char *tp;
- register FILE *tfile;
+FILE * OpenTape(char * atapeName, char * awrite)
+{
+ char *tp;
+ FILE *tfile;
+
tp = TapeName(atapeName);
+ if (tp == NULL)
+ return NULL;
tfile = fopen(tp, awrite);
+ free(tp);
return tfile;
}
/* scan for, and delete, all dumps whose parent dump ID is aparentID */
-static afs_int32 ScanForChildren(aparentID)
-afs_int32 aparentID; {
+
+static afs_int32 ScanForChildren(afs_int32 aparentID)
+{
DIR *tdir;
- register struct dirent *tde;
+ struct dirent *tde;
afs_int32 dumpID, parent;
- register FILE *tfile;
- register afs_int32 code;
+ FILE *tfile;
+ afs_int32 code;
afs_int32 j2, j3, j4;
char dname[256];
char dumpName[1024];
-
- tdir = opendir(AFSDIR_SERVER_BACKUP_DIRPATH);
- if (!tdir) return -1;
- for(tde=readdir(tdir); tde; tde=readdir(tdir)) {
- code = sscanf(tde->d_name, "D%ld.db", &dumpID);
- if (code != 1) continue;
+ tdir = opendir(AFSDIR_SERVER_BACKUP_DIRPATH);
+ if (!tdir)
+ return -1;
+
+ for (tde = readdir(tdir); tde; tde = readdir(tdir)) {
+ code = sscanf(tde->d_name, "D%ld.db", (long int *) &dumpID);
+ if (code != 1)
+ continue;
tfile = OpenDump(dumpID, "r");
- if (!tfile) continue; /* shouldn't happen, but should continue anyway */
+ if (!tfile)
+ continue; /* shouldn't happen, but should continue anyway */
code = ScanDumpHdr(tfile, dname, dumpName, &parent, &j2, &j3, &j4);
fclose(tfile);
/* if this guy's parent is the ID we're scanning for, delete it */
if (aparentID == parent) {
code = DeleteDump(dumpID);
- if (code) printf("backup:dsstub: failed to delete child dump %d\n", dumpID);
+ if (code)
+ printf("backup:dsstub: failed to delete child dump %d\n",
+ dumpID);
}
}
closedir(tdir);
return 0;
}
-static afs_int32 DeleteDump(adumpID)
-afs_int32 adumpID; {
- register char *tp;
- register afs_int32 code;
+static afs_int32 DeleteDump(afs_int32 adumpID)
+{
+ char *tp;
+ afs_int32 code;
+
tp = DumpName(adumpID);
+ if (tp == NULL)
+ return ENOMEM;
code = unlink(tp);
- if (code) return code;
+ free(tp);
+ if (code)
+ return code;
code = ScanForChildren(adumpID);
return code;
}
-static afs_int32 DeleteTape(atapeName)
-char *atapeName; {
- register char *tp;
- register afs_int32 code;
+#if 0
+static afs_int32 DeleteTape(char * atapeName)
+{
+ char *tp;
+ afs_int32 code;
+
tp = TapeName(atapeName);
+ if (tp == NULL)
+ return ENOMEM;
code = unlink(tp);
+ free(tp);
return code;
}
+#endif
/* tailCompPtr
* name is a pathname style name, determine trailing name and return
*/
char *
-tailCompPtr(pathNamePtr)
- char *pathNamePtr;
+tailCompPtr(char *pathNamePtr)
{
char *ptr;
ptr = strrchr(pathNamePtr, '/');
- if ( ptr == 0 )
- {
- /* this should never happen */
- printf("tailCompPtr: could not find / in name(%s)\n",
- pathNamePtr);
- return(pathNamePtr);
- }
- else
- ptr++; /* skip the / */
- return(ptr);
+ if (ptr == 0) {
+ /* this should never happen */
+ printf("tailCompPtr: could not find / in name(%s)\n", pathNamePtr);
+ return (pathNamePtr);
+ } else
+ ptr++; /* skip the / */
+ return (ptr);
}
-
+
/* ScanDumpHdr
* scan a dump header out of a dump file, leaving the file ptr set after
- * the header.
+ * the header.
* entry:
* afile - ptr to file, for reading.
* various - ptrs for return values
* alevel - level of dump (0 = full, 1+ are incrementals)
*/
afs_int32
-ScanDumpHdr(afile, aname, dumpName, aparent, aincTime, acreateTime, alevel)
- register FILE *afile;
- char *aname;
- char *dumpName;
- afs_int32 *aparent;
- afs_int32 *acreateTime;
- afs_int32 *aincTime;
- afs_int32 *alevel;
+ScanDumpHdr(FILE *afile, char *aname, char *dumpName, afs_int32 *aparent, afs_int32 *aincTime, afs_int32 *acreateTime, afs_int32 *alevel)
{
char tbuffer[256];
char *tp;
afs_int32 dbmagic, dbversion;
- register afs_int32 code;
+ afs_int32 code;
tp = fgets(tbuffer, sizeof(tbuffer), afile);
- if (!tp) return -1;
- code = sscanf(tbuffer, "%d %d %s %s %ld %ld %ld %ld",
- &dbmagic, &dbversion,
- aname, dumpName, aparent, aincTime, acreateTime, alevel);
- if (code != 8) return -1;
+ if (!tp)
+ return -1;
+ code =
+ sscanf(tbuffer, "%d %d %s %s %ld %ld %ld %ld", &dbmagic, &dbversion,
+ aname, dumpName, (long int *) aparent, (long int *) aincTime,
+ (long int *) acreateTime, (long int *) alevel);
+ if (code != 8)
+ return -1;
/* now check the magic and version numbers */
- if ( (dbmagic != BC_DUMPDB_MAGIC) || (dbversion != BC_DUMPDB_VERSION) )
- return(-1);
+ if ((dbmagic != BC_DUMPDB_MAGIC) || (dbversion != BC_DUMPDB_VERSION))
+ return (-1);
return 0;
}
+#if 0
/* scan a tape header out of a tape file, leaving the file ptr positioned just past the header */
-static afs_int32 ScanTapeHdr(afile, adumpID, aseq, adamage)
-register FILE *afile;
-afs_int32 *adumpID;
-afs_int32 *aseq;
-afs_int32 *adamage; {
+static afs_int32 ScanTapeHdr(FILE *afile, afs_int32 *adumpID, afs_int32 *aseq, afs_int32 *adamage)
+{
char tbuffer[256];
char *tp;
- register afs_int32 code;
+ afs_int32 code;
tp = fgets(tbuffer, sizeof(tbuffer), afile);
- if (!tp) return -1;
- code = sscanf(tbuffer, "%ld %ld %ld", adumpID, aseq, adamage);
- if (code != 3) return -1;
+ if (!tp)
+ return -1;
+ code = sscanf(tbuffer, "%ld %ld %ld", (long int *)adumpID,
+ (long int *)aseq, (long int *)adamage);
+ if (code != 3)
+ return -1;
return 0;
}
+#endif
/* ScanTapeVolume
* scan a tape volume record from a dump file, leaving the file ptr
* -1 for error
*/
-afs_int32
-ScanTapeVolume(afile, avolName, avolID, atapeName, apos, aseq, alastp,
- cloneTime)
-FILE *afile;
-char *avolName;
-afs_int32 *avolID;
-char *atapeName;
-afs_int32 *apos, *aseq, *alastp, *cloneTime; {
+afs_int32 ScanTapeVolume(FILE *afile, char *avolName, afs_int32 *avolID, char *atapeName, afs_int32 *apos, afs_int32 *aseq, afs_int32 *alastp, afs_int32 *cloneTime)
+{
char tbuffer[256];
- register afs_int32 code;
- register char *tp;
+ afs_int32 code;
+ char *tp;
tp = fgets(tbuffer, sizeof(tbuffer), afile);
- if (!tp) { /* something went wrong, or eof hit */
- if (ferror(afile)) return -1; /* error occurred */
- else return 1; /* eof */
+ if (!tp) { /* something went wrong, or eof hit */
+ if (ferror(afile))
+ return -1; /* error occurred */
+ else
+ return 1; /* eof */
}
- code = sscanf(tbuffer, "%s %ld %s %ld %ld %ld %ld", avolName, avolID,
- atapeName, apos, aseq, alastp, cloneTime);
- if (code != 7) return -1; /* bad input line */
+ code =
+ sscanf(tbuffer, "%s %ld %s %ld %ld %ld %ld", avolName,
+ (long int *) avolID, atapeName, (long int *)apos,
+ (long int *) aseq, (long int *) alastp,
+ (long int *) cloneTime);
+ if (code != 7)
+ return -1; /* bad input line */
return 0;
}
* -1 - volume with volName not found
*/
-afs_int32
-ScanVolClone(tdump, volName, cloneTime)
- FILE *tdump;
- char *volName;
- afs_int32 *cloneTime;
+afs_int32 ScanVolClone(FILE *tdump, char *volName, afs_int32 *cloneTime)
{
char avolName[256], atapeName[256];
afs_int32 retval, avolID, apos, aseq, alastp;
-
- retval = ScanTapeVolume(tdump, &avolName[0], &avolID, &atapeName[0],
- &apos, &aseq, &alastp, cloneTime);
- while ( retval == 0 )
- {
- if ( strcmp(avolName, volName) == 0 )
- return(0);
- retval = ScanTapeVolume(tdump, &avolName[0], &avolID, &atapeName[0],
- &apos, &aseq, &alastp, cloneTime);
+
+ retval =
+ ScanTapeVolume(tdump, &avolName[0], &avolID, &atapeName[0], &apos,
+ &aseq, &alastp, cloneTime);
+ while (retval == 0) {
+ if (strcmp(avolName, volName) == 0)
+ return (0);
+ retval =
+ ScanTapeVolume(tdump, &avolName[0], &avolID, &atapeName[0], &apos,
+ &aseq, &alastp, cloneTime);
}
- return(-1);
+ return (-1);
}
+#if 0
/* seek a dump file (after a header scan has been done) to position apos */
-static SeekDump(afile, apos)
-register FILE *afile;
-afs_int32 apos; {
- register afs_int32 i;
- register char *tp;
+static int SeekDump(FILE *afile, afs_int32 apos)
+{
+ afs_int32 i;
+ char *tp;
char tbuffer[256];
/* now skip to appropriate position */
- for(i=0;i<apos; i++) {
+ for (i = 0; i < apos; i++) {
tp = fgets(tbuffer, sizeof(tbuffer), afile);
if (!tp) {
fclose(afile);
}
return 0;
}
-
+#endif