Fixed 64/32 bit files database issue

This commit is contained in:
Michiel Broek
2006-02-17 20:58:23 +00:00
parent fb9122255c
commit 2f779324e2
5 changed files with 70 additions and 15 deletions

View File

@@ -42,10 +42,10 @@
*/
struct _fdbarea *mbsedb_OpenFDB(int Area, int Timeout)
{
char *temp;
char *temp, *temp2;
struct _fdbarea *fdb_area = NULL;
int Tries = 0;
FILE *fp;
FILE *fp, *fp2;
temp = calloc(PATH_MAX, sizeof(char));
fdb_area = malloc(sizeof(struct _fdbarea)); /* Will be freed by CloseFDB */
@@ -86,6 +86,36 @@ struct _fdbarea *mbsedb_OpenFDB(int Area, int Timeout)
return NULL;
}
if ((fdbhdr.hdrsize == sizeof(fdbhdr)) && (fdbhdr.recsize == (sizeof(fdb) + 4))) {
Syslog('+', "Files area %d database 64/32 bit alignment error, fixing...", Area);
temp2 = calloc(PATH_MAX, sizeof(char));
snprintf(temp2, PATH_MAX -1, "%s/var/fdb/file%d.temp", getenv("MBSE_ROOT"), Area);
if ((fp2 = fopen(temp2, "w+"))) {
fdbhdr.recsize = (sizeof(fdb));
fwrite(&fdbhdr, sizeof(fdbhdr), 1, fp2);
fdbhdr.recsize = sizeof(fdb) + 4;
while (fread(&fdb, fdbhdr.recsize, 1, fp) == 1) {
/*
* Shift 4 bytes
*/
memmove(&fdb.Crc32, &fdb.Uploader, sizeof(fdb) - 179);
fwrite(&fdb, sizeof(fdb), 1, fp2);
}
fclose(fp2);
fclose(fp);
unlink(temp);
rename(temp2, temp);
if ((fp = fopen(temp, "r+"))) {
fread(&fdbhdr, sizeof(fdbhdr), 1, fp);
} else {
WriteError("$Can't reopen %s", temp);
}
} else {
WriteError("$Can't create %s", temp2);
}
free(temp2);
}
/*
* Fix attributes if needed
*/
@@ -93,8 +123,9 @@ struct _fdbarea *mbsedb_OpenFDB(int Area, int Timeout)
free(temp);
if ((fdbhdr.hdrsize != sizeof(fdbhdr)) || (fdbhdr.recsize != sizeof(fdb))) {
WriteError("Files database header in area %d is corrupt (%d:%d)", Area, fdbhdr.hdrsize, fdbhdr.recsize);
fclose(fdb_area->fp);
WriteError("Files database header in area %d is corrupt (%d:%d) [%d:%d]", Area, fdbhdr.hdrsize, fdbhdr.recsize,
sizeof(fdbhdr), sizeof(fdb));
fclose(fp);
return NULL;
}

View File

@@ -4,7 +4,7 @@
* Purpose ...............: Global variables for MBSE BBS
*
*****************************************************************************
* Copyright (C) 1997-2005
* Copyright (C) 1997-2006
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10
@@ -36,12 +36,12 @@
typedef struct _TagRec {
int Area; /* File Area number */
int Active; /* Not deleted from taglist */
int Cost; /* Free download */
off_t Size; /* File Size */
char SFile[13]; /* Short File Name */
char LFile[81]; /* Long FIle Name */
int Area; /* File Area number */
int Active; /* Not deleted from taglist */
int Cost; /* Free download */
unsigned int Size; /* File Size */
char SFile[13]; /* Short File Name */
char LFile[81]; /* Long FIle Name */
} _Tag;

View File

@@ -839,7 +839,7 @@ struct FILE_record {
char Name[13]; /* DOS style filename */
char LName[81]; /* Long filename */
char TicArea[21]; /* Tic area file came in */
off_t Size; /* File Size */
unsigned int Size; /* File Size */
unsigned int Crc32; /* File CRC-32 */
char Uploader[36]; /* Uploader name */
int32_t UploadDate; /* Date/Time uploaded */
@@ -865,7 +865,7 @@ struct OldFILERecord {
char LName[81]; /* Long filename */
char xTicArea[9]; /* Tic area file came in */
unsigned int TicAreaCRC; /* CRC of TIC area name */
off_t Size; /* File Size */
unsigned int Size; /* File Size */
unsigned int Crc32; /* File CRC-32 */
char Uploader[36]; /* Uploader name */
int32_t UploadDate; /* Date/Time uploaded */
@@ -1979,7 +1979,7 @@ struct _filerecord {
char Group[13]; /* Group */
char Name[13]; /* File Name */
char LName[81]; /* Long FileName */
off_t Size; /* File Size */
unsigned int Size; /* File Size */
unsigned int SizeKb; /* File Size in Kb */
int32_t Fdate; /* File Date */
char Origin[24]; /* Origin system */