home *** CD-ROM | disk | FTP | other *** search
- // TapeDrives.c
- // 18 Jan 1996 17:59:45
-
- #ifndef BACKUP_INCLUDE
- #include "IncludeAll.c"
- #endif
- #include "Backup.h"
- #include "Backup_proto.h"
- #include "TapeDrive.h"
- #include "BackupStrings.h"
-
-
- static struct TapeDriveProperties *SizeDriveData(size_t NeededLength, size_t *AllocLength, struct TapeDriveProperties *Old);
- static BOOL WriteTapeDDEntry(FILE *fd, const struct TapeDriveProperties *DriveData);
-
-
- // aus Revision.c
- extern short Version; // aktuelle Versionsnummer
-
- // aus Backup.c
- extern struct BackupOptions myOptions; // Einstellungen für die aktuelle Sicherung
-
-
- struct TapeDriveProperties *ReadTapeDriveDataBase(void)
- {
- static const struct TapeDriveProperties BuiltInDrives[] =
- {
- { "CALIPER CP150 ", { 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0 } },
- { "HP HP35470A 8 09", { 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1 } },
- { "TANDBERG TDC 3800 =04Y", { 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0 } },
- { "", { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }
- };
- struct TapeDriveProperties *DriveData = NULL;
- const struct TapeDriveProperties *BuiltInDriveData;
- size_t DriveDataAlloc = 0;
- size_t DriveDataCount = 0;
- FILE *fd;
-
- // zuerst die eingebauten Laufwerke eintragen
- BuiltInDriveData = BuiltInDrives;
- while (BuiltInDriveData->Name[0])
- {
- DriveData = SizeDriveData(DriveDataCount + 1, &DriveDataAlloc, DriveData);
- if (NULL == DriveData)
- return NULL;
-
- DriveData[DriveDataCount] = *BuiltInDriveData;
- DriveDataCount++;
- BuiltInDriveData++;
- }
-
- fd = fopen(myOptions.bo_TapeDriveDataFileName, "r");
- if (fd)
- {
- static const char *DDTemplate="Name/K/A,QFA/K/S,FastSpace/K/S,SpaceBack/K/S,Locate/K/S,"
- "PageFormat/K/S,InvertEOT/K/S,EraseLONG/K/S,AppendQFA/K/S,SpaceEOR/K/S,UpdateInPlace/K/S";
- LONG DDResult[12];
- struct RDArgs *RdArgs;
-
- RdArgs = AllocDosObject(DOS_RDARGS, NULL);
- if (NULL == RdArgs)
- {
- // AllocDosObject hat versagt!
- alarm(GetString(MSG_ALLOCDOSOBJ_FAIL), __FUNC__, "DOS_RDARGS");
- }
- else
- {
- RdArgs->RDA_DAList = NULL;
- RdArgs->RDA_Buffer = NULL;
- RdArgs->RDA_BufSiz = 0;
- RdArgs->RDA_ExtHelp = (char *) "";
- RdArgs->RDA_Flags = 0;
- }
-
- while (RdArgs && !feof(fd))
- {
- char Line[250];
- long LineNr = 0;
-
- if (fgets(Line, sizeof(Line), fd))
- {
- LineNr++;
-
- // Kommentarzeilen ("%" am Anfang) überlesen!!
- if ('%' != Line[0])
- {
- RdArgs->RDA_Source.CS_Buffer = (UBYTE *) Line;
- RdArgs->RDA_Source.CS_Length = strlen(Line);
- RdArgs->RDA_Source.CS_CurChr = 0;
- memset(DDResult, 0, sizeof(DDResult));
-
- if (ReadArgs((STRPTR) DDTemplate, DDResult, RdArgs))
- {
- size_t n;
- BOOL Found;
- struct TapeDriveProperties *NewDD;
- struct TapeDriveProperties *DDInsert = DriveData;
-
- // prüfen ob dieser Eintrag schon vorhanden ist
- for (Found=FALSE, n=0, NewDD=DriveData; n<DriveDataCount; n++, NewDD++)
- {
- if (0 == strcmp(NewDD->Name, (char *) DDResult[0]))
- {
- // den Eintrag gibt es schon: er wird überschrieben
- DDInsert = NewDD;
- Found = TRUE;
- break;
- }
- }
-
- if (!Found)
- {
- // neuen Eintrag am Ende anhängen
- DriveData = SizeDriveData(DriveDataCount + 1, &DriveDataAlloc, DriveData);
- if (NULL == DriveData)
- break;
- DDInsert = &DriveData[DriveDataCount];
- DriveDataCount++;
- }
-
- stccpy(DDInsert->Name, (char *) DDResult[0], sizeof(DDInsert->Name));
- DDInsert->Properties.Valid = 1;
- DDInsert->Properties.DriveKnown = 1;
-
- DDInsert->Properties.canQFA = ~0 == DDResult[1];
- DDInsert->Properties.FastSpace = ~0 == DDResult[2];
- DDInsert->Properties.canLocate = ~0 == DDResult[4];
- DDInsert->Properties.SpaceBack = ~0 == DDResult[3];
- DDInsert->Properties.PageFormat = ~0 == DDResult[5];
- DDInsert->Properties.InvertEOT = ~0 == DDResult[6];
- DDInsert->Properties.EraseLONG = ~0 == DDResult[7];
- DDInsert->Properties.AppendQFA = ~0 == DDResult[8];
- DDInsert->Properties.SpaceEOR = ~0 == DDResult[9];
- DDInsert->Properties.UpdateInPlace = ~0 == DDResult[10];
- }
- else
- {
- // Formatfehler in dieser Zeile
- alarm(GetString(MSG_DDFORMAT_ERROR), myOptions.bo_TapeDriveDataFileName, LineNr, Line);
- }
- }
- }
- }
-
- if (RdArgs)
- FreeDosObject(DOS_RDARGS, RdArgs);
- fclose(fd);
- }
-
- // Ende-Marke setzen
- DriveData = SizeDriveData(DriveDataCount + 1, &DriveDataAlloc, DriveData);
- if (DriveData)
- {
- DriveData[DriveDataCount].Name[0] = '\0';
- DriveData[DriveDataCount].Properties.Valid = 0;
- }
-
- return DriveData;
- }
-
-
- static struct TapeDriveProperties *SizeDriveData(size_t NeededLength, size_t *AllocLength, struct TapeDriveProperties *Old)
- {
- struct TapeDriveProperties *DriveData = Old;
-
- if (NeededLength > *AllocLength)
- {
- *AllocLength += DRIVEDATA_ALLOC_STEP;
-
- DriveData = realloc(Old, *AllocLength * sizeof(struct TapeDriveProperties));
- }
-
- return DriveData;
- }
-
-
- void WriteTapeDriveDataBase(const struct TapeDriveProperties *NewDriveData)
- {
- struct TapeDriveProperties *DriveData, *NewDD;
- FILE *fd;
- BOOL Found;
-
- DriveData = ReadTapeDriveDataBase();
-
- for (Found=FALSE, NewDD=DriveData; NewDD->Name[0]; NewDD++)
- {
- if (0 == strcmp(NewDD->Name, NewDriveData->Name))
- {
- // den Eintrag gibt es schon: er wird überschrieben
- *NewDD = *NewDriveData;
- Found = TRUE;
- break;
- }
- }
-
- fd = fopen(myOptions.bo_TapeDriveDataFileName, "w");
- if (fd)
- {
- char zeit[8];
-
- // Kopfzeile schreiben
- getclk(zeit);
- fprintf(fd, GetString(MSG_TAPEDD_HEADER), Version/100, Version % 100,
- DateString(zeit[3], zeit[2], zeit[1]+80));
-
- for (NewDD=DriveData; NewDD->Name[0]; NewDD++)
- {
- WriteTapeDDEntry(fd, NewDD);
- }
- if (!Found)
- WriteTapeDDEntry(fd, NewDriveData);
-
- fclose(fd);
- }
- else
- {
- // Datenbank kann nicht geöffnet werden
- alarm(GetString(MSG_CANNOTOPEN_TAPEDD), myOptions.bo_TapeDriveDataFileName, GetIoErrText());
- }
-
- if (DriveData)
- free(DriveData);
- }
-
-
- static BOOL WriteTapeDDEntry(FILE *fd, const struct TapeDriveProperties *DriveData)
- {
- fprintf(fd, "Name=\"%s\"", DriveData->Name);
- if (DriveData->Properties.canQFA)
- fputs(" QFA", fd);
- if (DriveData->Properties.FastSpace)
- fputs(" FastSpace", fd);
- if (DriveData->Properties.canLocate)
- fputs(" Locate", fd);
- if (DriveData->Properties.SpaceBack)
- fputs(" SpaceBack", fd);
- if (DriveData->Properties.PageFormat)
- fputs(" PageFormat", fd);
- if (DriveData->Properties.InvertEOT)
- fputs(" InvertEOT", fd);
- if (DriveData->Properties.EraseLONG)
- fputs(" EraseLONG", fd);
- if (DriveData->Properties.AppendQFA)
- fputs(" AppendQFA", fd);
- if (DriveData->Properties.SpaceEOR)
- fputs(" SpaceEOR", fd);
- if (DriveData->Properties.UpdateInPlace)
- fputs(" UpdateInPlace", fd);
-
- fputs("\n", fd);
-
- return TRUE;
- }
-
-
- struct TapeDriveProperties *FindTapeDrive(struct TapeDriveProperties *DriveData, const char *InquiryName)
- {
- struct TapeDriveProperties *Result = NULL;
-
- while (DriveData->Name[0])
- {
- if (0 == strncmp(InquiryName, DriveData->Name, strlen(DriveData->Name)))
- {
- DriveData->Properties.DriveKnown = 1;
- Result = DriveData;
- break;
- }
- DriveData++;
- }
-
- return Result;
- }
-
-
-