Updates for new fdb code
This commit is contained in:
parent
75b991af56
commit
7aa6f678c2
19
lib/dbfdb.c
19
lib/dbfdb.c
@ -39,7 +39,7 @@
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Open files database Area number, with path. Do some checks and abort
|
* Open files database Area number. Do some checks and abort
|
||||||
* if they fail.
|
* if they fail.
|
||||||
*/
|
*/
|
||||||
struct _fdbarea *mbsedb_OpenFDB(long Area, int Timeout)
|
struct _fdbarea *mbsedb_OpenFDB(long Area, int Timeout)
|
||||||
@ -68,12 +68,27 @@ struct _fdbarea *mbsedb_OpenFDB(long Area, int Timeout)
|
|||||||
msleep(250);
|
msleep(250);
|
||||||
Syslog('f', "Open file area %ld, try %d", Area, Tries);
|
Syslog('f', "Open file area %ld, try %d", Area, Tries);
|
||||||
}
|
}
|
||||||
|
if (fp == NULL) {
|
||||||
|
if (errno == ENOENT) {
|
||||||
|
Syslog('+', "Create empty FDB for area %ld", Area);
|
||||||
|
fdbhdr.hdrsize = sizeof(fdbhdr);
|
||||||
|
fdbhdr.recsize = sizeof(fdb);
|
||||||
|
if ((fp = fopen(temp, "w+"))) {
|
||||||
|
fwrite(&fdbhdr, sizeof(fdbhdr), 1, fp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fread(&fdbhdr, sizeof(fdbhdr), 1, fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If still not open, it's fatal.
|
||||||
|
*/
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
WriteError("$Can't open %s", temp);
|
WriteError("$Can't open %s", temp);
|
||||||
free(temp);
|
free(temp);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
fread(&fdbhdr, sizeof(fdbhdr), 1, fp);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Fix attributes if needed
|
* Fix attributes if needed
|
||||||
|
@ -200,9 +200,8 @@ void Check(long AreaNr)
|
|||||||
|
|
||||||
void CheckArea(long Area)
|
void CheckArea(long Area)
|
||||||
{
|
{
|
||||||
FILE *pFile;
|
|
||||||
int j, Fix, inArea, rc;
|
int j, Fix, inArea, rc;
|
||||||
char *fAreas, *newdir, *temp, *mname, *tname;
|
char *newdir, *temp, *mname, *tname;
|
||||||
DIR *dp;
|
DIR *dp;
|
||||||
struct dirent *de;
|
struct dirent *de;
|
||||||
int Found, Update;
|
int Found, Update;
|
||||||
@ -210,8 +209,14 @@ void CheckArea(long Area)
|
|||||||
struct stat stb;
|
struct stat stb;
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
struct group *gr;
|
struct group *gr;
|
||||||
|
#ifdef USE_EXPERIMENT
|
||||||
|
struct _fdbarea *fdb_area = NULL;
|
||||||
|
#else
|
||||||
|
FILE *pFile;
|
||||||
|
char *fAreas;
|
||||||
|
|
||||||
fAreas = calloc(PATH_MAX, sizeof(char));
|
fAreas = calloc(PATH_MAX, sizeof(char));
|
||||||
|
#endif
|
||||||
newdir = calloc(PATH_MAX, sizeof(char));
|
newdir = calloc(PATH_MAX, sizeof(char));
|
||||||
temp = calloc(PATH_MAX, sizeof(char));
|
temp = calloc(PATH_MAX, sizeof(char));
|
||||||
mname = calloc(PATH_MAX, sizeof(char));
|
mname = calloc(PATH_MAX, sizeof(char));
|
||||||
@ -289,6 +294,10 @@ void CheckArea(long Area)
|
|||||||
WriteError("Can't stat %s", area.Path);
|
WriteError("Can't stat %s", area.Path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_EXPERIMENT
|
||||||
|
if ((fdb_area = mbsedb_OpenFDB(Area, 30)) == NULL)
|
||||||
|
return;
|
||||||
|
#else
|
||||||
sprintf(fAreas, "%s/fdb/file%ld.data", getenv("MBSE_ROOT"), Area);
|
sprintf(fAreas, "%s/fdb/file%ld.data", getenv("MBSE_ROOT"), Area);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -319,13 +328,18 @@ void CheckArea(long Area)
|
|||||||
Syslog('+', "fAreas recordsize is corrupt: %d, expected %d", fdbhdr.recsize, sizeof(fdbhdr));
|
Syslog('+', "fAreas recordsize is corrupt: %d, expected %d", fdbhdr.recsize, sizeof(fdbhdr));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Now start checking the files in the filedatabase
|
* Now start checking the files in the filedatabase
|
||||||
* against the contents of the directory.
|
* against the contents of the directory.
|
||||||
*/
|
*/
|
||||||
inArea = 0;
|
inArea = 0;
|
||||||
|
#ifdef USE_EXPERIMENT
|
||||||
|
while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) {
|
||||||
|
#else
|
||||||
while (fread(&fdb, fdbhdr.recsize, 1, pFile) == 1) {
|
while (fread(&fdb, fdbhdr.recsize, 1, pFile) == 1) {
|
||||||
|
#endif
|
||||||
|
|
||||||
iTotal++;
|
iTotal++;
|
||||||
inArea++;
|
inArea++;
|
||||||
@ -339,8 +353,16 @@ void CheckArea(long Area)
|
|||||||
do_pack = TRUE;
|
do_pack = TRUE;
|
||||||
}
|
}
|
||||||
iErrors++;
|
iErrors++;
|
||||||
|
#ifdef USE_EXPERIMENT
|
||||||
|
if (mbsedb_LockFDB(fdb_area, 30)) {
|
||||||
|
fseek(fdb_area->fp, - fdbhdr.recsize, SEEK_CUR);
|
||||||
|
fwrite(&fdb, fdbhdr.recsize, 1, fdb_area->fp);
|
||||||
|
mbsedb_UnlockFDB(fdb_area);
|
||||||
|
}
|
||||||
|
#else
|
||||||
fseek(pFile, - fdbhdr.recsize, SEEK_CUR);
|
fseek(pFile, - fdbhdr.recsize, SEEK_CUR);
|
||||||
fwrite(&fdb, fdbhdr.recsize, 1, pFile);
|
fwrite(&fdb, fdbhdr.recsize, 1, pFile);
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
* File exists, now check the file.
|
* File exists, now check the file.
|
||||||
@ -488,21 +510,39 @@ void CheckArea(long Area)
|
|||||||
}
|
}
|
||||||
Marker();
|
Marker();
|
||||||
if (Update) {
|
if (Update) {
|
||||||
|
#ifdef USE_EXPERIMENT
|
||||||
|
if (mbsedb_LockFDB(fdb_area, 30)) {
|
||||||
|
fseek(fdb_area->fp, - fdbhdr.recsize, SEEK_CUR);
|
||||||
|
fwrite(&fdb, fdbhdr.recsize, 1, fdb_area->fp);
|
||||||
|
mbsedb_UnlockFDB(fdb_area);
|
||||||
|
}
|
||||||
|
#else
|
||||||
fseek(pFile, - fdbhdr.recsize, SEEK_CUR);
|
fseek(pFile, - fdbhdr.recsize, SEEK_CUR);
|
||||||
fwrite(&fdb, fdbhdr.recsize, 1, pFile);
|
fwrite(&fdb, fdbhdr.recsize, 1, pFile);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(fdb.Magic)) {
|
if (strlen(fdb.Magic)) {
|
||||||
rc = magic_check(fdb.Magic, fdb.Name);
|
rc = magic_check(fdb.Magic, fdb.Name);
|
||||||
if (rc == -1) {
|
if (rc == -1) {
|
||||||
Syslog('+', "Area %ld magic alias %s file %s is invalid", Area, fdb.Magic, fdb.Name);
|
Syslog('+', "Area %ld magic alias %s file %s is invalid", Area, fdb.Magic, fdb.Name);
|
||||||
memset(&fdb.Magic, 0, sizeof(fdb.Magic));
|
memset(&fdb.Magic, 0, sizeof(fdb.Magic));
|
||||||
|
#ifdef USE_EXPERIMENT
|
||||||
|
if (mbsedb_LockFDB(fdb_area, 30)) {
|
||||||
|
fseek(fdb_area->fp, - fdbhdr.recsize, SEEK_CUR);
|
||||||
|
fwrite(&fdb, fdbhdr.recsize, 1, fdb_area->fp);
|
||||||
|
mbsedb_UnlockFDB(fdb_area);
|
||||||
|
}
|
||||||
|
#else
|
||||||
fseek(pFile, - fdbhdr.recsize, SEEK_CUR);
|
fseek(pFile, - fdbhdr.recsize, SEEK_CUR);
|
||||||
fwrite(&fdb, fdbhdr.recsize, 1, pFile);
|
fwrite(&fdb, fdbhdr.recsize, 1, pFile);
|
||||||
|
#endif
|
||||||
iErrors++;
|
iErrors++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inArea == 0)
|
if (inArea == 0)
|
||||||
Syslog('+', "Warning: area %ld (%s) is empty", Area, area.Name);
|
Syslog('+', "Warning: area %ld (%s) is empty", Area, area.Name);
|
||||||
|
|
||||||
@ -516,8 +556,13 @@ void CheckArea(long Area)
|
|||||||
if (de->d_name[0] != '.') {
|
if (de->d_name[0] != '.') {
|
||||||
Marker();
|
Marker();
|
||||||
Found = FALSE;
|
Found = FALSE;
|
||||||
|
#ifdef USE_EXPERIMENT
|
||||||
|
fseek(fdb_area->fp, fdbhdr.hdrsize, SEEK_SET);
|
||||||
|
while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) {
|
||||||
|
#else
|
||||||
fseek(pFile, fdbhdr.hdrsize, SEEK_SET);
|
fseek(pFile, fdbhdr.hdrsize, SEEK_SET);
|
||||||
while (fread(&fdb, fdbhdr.recsize, 1, pFile) == 1) {
|
while (fread(&fdb, fdbhdr.recsize, 1, pFile) == 1) {
|
||||||
|
#endif
|
||||||
if ((strcmp(fdb.LName, de->d_name) == 0) || (strcmp(fdb.Name, de->d_name) == 0)) {
|
if ((strcmp(fdb.LName, de->d_name) == 0) || (strcmp(fdb.Name, de->d_name) == 0)) {
|
||||||
if (!Found) {
|
if (!Found) {
|
||||||
Found = TRUE;
|
Found = TRUE;
|
||||||
@ -530,8 +575,16 @@ void CheckArea(long Area)
|
|||||||
iErrors++;
|
iErrors++;
|
||||||
fdb.Double = TRUE;
|
fdb.Double = TRUE;
|
||||||
do_pack = TRUE;
|
do_pack = TRUE;
|
||||||
|
#ifdef USE_EXPERIMENT
|
||||||
|
if (mbsedb_LockFDB(fdb_area, 30)) {
|
||||||
|
fseek(fdb_area->fp, - fdbhdr.recsize, SEEK_CUR);
|
||||||
|
fwrite(&fdb, fdbhdr.recsize, 1, fdb_area->fp);
|
||||||
|
mbsedb_UnlockFDB(fdb_area);
|
||||||
|
}
|
||||||
|
#else
|
||||||
fseek(pFile, - fdbhdr.recsize, SEEK_CUR);
|
fseek(pFile, - fdbhdr.recsize, SEEK_CUR);
|
||||||
fwrite(&fdb, fdbhdr.recsize, 1, pFile);
|
fwrite(&fdb, fdbhdr.recsize, 1, pFile);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -560,11 +613,15 @@ void CheckArea(long Area)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_EXPERIMENT
|
||||||
|
mbsedb_CloseFDB(fdb_area);
|
||||||
|
#else
|
||||||
fclose(pFile);
|
fclose(pFile);
|
||||||
chmod(fAreas, 0660);
|
chmod(fAreas, 0660);
|
||||||
iAreasNew++;
|
|
||||||
|
|
||||||
free(fAreas);
|
free(fAreas);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
iAreasNew++;
|
||||||
free(newdir);
|
free(newdir);
|
||||||
free(temp);
|
free(temp);
|
||||||
free(mname);
|
free(mname);
|
||||||
|
Reference in New Issue
Block a user