Commit 3e551fc5 authored by Ivan Donchevskiy's avatar Ivan Donchevskiy

Added function to check heading match in file in CycleStorage

parent 2f13c1c9
...@@ -192,6 +192,9 @@ class CycleStorage ...@@ -192,6 +192,9 @@ class CycleStorage
inline int getSize(){ return size; } inline int getSize(){ return size; }
inline int getInfSize(){ return inf_size; } inline int getInfSize(){ return inf_size; }
inline int getFullSize(){ return full_size; } inline int getFullSize(){ return full_size; }
bool checkAttr(int inf_sz, int inf_count, int seek);
protected: protected:
FILE *file; FILE *file;
int inf_size; int inf_size;
......
...@@ -138,6 +138,26 @@ bool CycleStorage::findHead() ...@@ -138,6 +138,26 @@ bool CycleStorage::findHead()
return true; return true;
} }
/*! */
bool CycleStorage::checkAttr(int inf_sz, int inf_count, int seek)
{
if( file==NULL ) return false;
fseek(file,seek,0);
/*! */
CycleStorageAttr csa;
fread(&csa, sizeof(csa), 1, file);
/*! */
if( ( csa.size!=inf_count ) || ( csa.inf_size!=inf_sz ) || ( csa.seekpos!=seek ) )
{
fclose(file);
file=NULL;
return false;
}
return true;
}
bool CycleStorage::open(const char* name, int byte_sz, int inf_sz, int inf_count, int seek) bool CycleStorage::open(const char* name, int byte_sz, int inf_sz, int inf_count, int seek)
{ {
/*! , /*! ,
...@@ -155,17 +175,9 @@ bool CycleStorage::open(const char* name, int byte_sz, int inf_sz, int inf_count ...@@ -155,17 +175,9 @@ bool CycleStorage::open(const char* name, int byte_sz, int inf_sz, int inf_count
return false; return false;
} }
/*! */ if( !checkAttr(inf_sz, inf_count, seek) )
CycleStorageAttr csa;
fread(&csa, sizeof(csa), 1, file);
/*! */
if( ( csa.size!=inf_count ) || ( csa.inf_size!=inf_sz ) || ( csa.seekpos!=seek ) )
{
fclose(file);
file=NULL;
return false; return false;
}
inf_size=inf_sz; inf_size=inf_sz;
full_size=sizeof(CycleStorageElem)+inf_size; full_size=sizeof(CycleStorageElem)+inf_size;
size=inf_count; size=inf_count;
......
...@@ -115,7 +115,7 @@ bool TableBlockStorage::copyToNextBlock(void) ...@@ -115,7 +115,7 @@ bool TableBlockStorage::copyToNextBlock(void)
return true; return true;
} }
/*! */ /*! */
bool TableBlockStorage::checkAttr( int key_sz, int inf_sz, int inf_count, int block_num, int block_lim, int seek ) bool TableBlockStorage::checkAttr( int key_sz, int inf_sz, int inf_count, int block_num, int block_lim, int seek )
{ {
if( file==NULL ) return false; if( file==NULL ) return false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment