This commit is contained in:
Brian Cox 2016-05-24 18:50:12 -07:00
commit dbb7a57cdc
4 changed files with 51 additions and 16 deletions

View File

@ -1,4 +1,4 @@
//
// The developer of the original code and/or files is Tripwire, Inc. // The developer of the original code and/or files is Tripwire, Inc.
// Portions created by Tripwire, Inc. are copyright (C) 2000 Tripwire, // Portions created by Tripwire, Inc. are copyright (C) 2000 Tripwire,
// Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights // Inc. Tripwire is a registered trademark of Tripwire, Inc. All rights
@ -234,12 +234,12 @@ void cFile::Open( const TSTRING& sFileNameC, uint32 flags )
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
void cFile::Close() //throw(eFile) void cFile::Close() //throw(eFile)
{ {
#ifdef HAVE_POSIX_FADVISE
posix_fadvise(fileno(mpData->mpCurrStream),0,0, POSIX_FADV_DONTNEED);
#endif
if(mpData->mpCurrStream != NULL) if(mpData->mpCurrStream != NULL)
{ {
#ifdef HAVE_POSIX_FADVISE
posix_fadvise(fileno(mpData->mpCurrStream),0,0, POSIX_FADV_DONTNEED);
#endif
fclose( mpData->mpCurrStream ); fclose( mpData->mpCurrStream );
mpData->mpCurrStream = NULL; mpData->mpCurrStream = NULL;
} }

View File

@ -97,7 +97,22 @@ iFCOProp::CmpResult iSignature::Compare(const iFCOProp* rhs, Op op) const
return (op == iFCOProp::OP_NE) ? iFCOProp::CMP_TRUE : iFCOProp::CMP_FALSE; return (op == iFCOProp::OP_NE) ? iFCOProp::CMP_TRUE : iFCOProp::CMP_FALSE;
} }
bool cArchiveSigGen::mHex = false; bool cArchiveSigGen::s_hex = false;
int32 cArchiveSigGen::s_blocks = 1;
int32 cArchiveSigGen::s_bytes = iSignature::SUGGESTED_BLOCK_SIZE;
byte* cArchiveSigGen::s_buf = 0;
byte* cArchiveSigGen::s_base = 0;
bool cArchiveSigGen::s_direct = false;
void cArchiveSigGen::SetBlocks( int32 n )
{
s_blocks=n;
s_base = new byte[iSignature::SUGGESTED_BLOCK_SIZE * (s_blocks+1)];
unsigned long nMod = (unsigned long)s_base % iSignature::SUGGESTED_BLOCK_SIZE;
s_buf = s_base + (iSignature::SUGGESTED_BLOCK_SIZE - nMod);
s_bytes = iSignature::SUGGESTED_BLOCK_SIZE * s_blocks;
}
void cArchiveSigGen::AddSig( iSignature* pSig ) void cArchiveSigGen::AddSig( iSignature* pSig )
{ {
@ -107,10 +122,11 @@ void cArchiveSigGen::AddSig( iSignature* pSig )
void cArchiveSigGen::CalculateSignatures( cArchive& a ) void cArchiveSigGen::CalculateSignatures( cArchive& a )
{ {
byte abBuf[iSignature::SUGGESTED_BLOCK_SIZE]; byte abBuf[iSignature::SUGGESTED_BLOCK_SIZE];
const int cbToRead = iSignature::SUGGESTED_BLOCK_SIZE;
int cbRead; int cbRead;
container_type::size_type i; container_type::size_type i;
byte* pBuf = s_buf ? s_buf : abBuf;
// init hash // init hash
for( i = 0; i < mSigList.size(); i++ ) for( i = 0; i < mSigList.size(); i++ )
mSigList[i]->Init(); mSigList[i]->Init();
@ -118,12 +134,12 @@ void cArchiveSigGen::CalculateSignatures( cArchive& a )
// hash data // hash data
do do
{ {
cbRead = a.ReadBlob( abBuf, cbToRead ); cbRead = a.ReadBlob( pBuf, s_bytes );
for( i = 0; i < mSigList.size(); i++ ) for( i = 0; i < mSigList.size(); i++ )
mSigList[i]->Update( abBuf, cbRead ); mSigList[i]->Update( pBuf, cbRead );
} }
while( cbRead == cbToRead ); while( cbRead == s_bytes );
// finalize hash // finalize hash
for( i = 0; i < mSigList.size(); i++ ) for( i = 0; i < mSigList.size(); i++ )
@ -132,12 +148,12 @@ void cArchiveSigGen::CalculateSignatures( cArchive& a )
bool cArchiveSigGen::Hex() bool cArchiveSigGen::Hex()
{ {
return mHex; return s_hex;
} }
void cArchiveSigGen::SetHex(bool hex) void cArchiveSigGen::SetHex(bool hex)
{ {
mHex = hex; s_hex = hex;
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@ -150,6 +150,10 @@ public:
static bool Hex(); static bool Hex();
static void SetHex(bool); static void SetHex(bool);
static void SetBlocks( int32 n );
static bool UseDirectIO() { return s_direct; }
static void SetUseDirectIO( bool b ) { s_direct = b; }
private: private:
// don't let C++ create these functions // don't let C++ create these functions
cArchiveSigGen( const cArchiveSigGen& ); cArchiveSigGen( const cArchiveSigGen& );
@ -158,7 +162,12 @@ private:
typedef std::vector< iSignature* > container_type; typedef std::vector< iSignature* > container_type;
container_type mSigList; container_type mSigList;
static bool mHex; static bool s_hex;
static int32 s_blocks;
static int32 s_bytes;
static byte* s_buf;
static byte* s_base;
static bool s_direct;
}; };

View File

@ -433,14 +433,24 @@ static void FillOutConfigInfo(cTWModeCommon* pModeInfo, const cConfigFile& cf)
pModeInfo->mbCrossFileSystems = false; pModeInfo->mbCrossFileSystems = false;
} }
if(cf.Lookup(TSTRING(_T("DIRECT_IO")), str)) int blocks = 0;
if (cf.Lookup(TSTRING(_T("HASH_DIRECT")), str))
{ {
if (_tcsicmp(str.c_str(), _T("true")) == 0) if (_tcsicmp(str.c_str(), _T("true")) == 0)
{
pModeInfo->mbDirectIO = true; pModeInfo->mbDirectIO = true;
else cArchiveSigGen::SetUseDirectIO(true);
pModeInfo->mbDirectIO = false; blocks = 1;
}
} }
if (cf.Lookup(TSTRING(_T("HASH_BLOCKS")), str))
{
blocks = _ttoi( str.c_str() );
}
if( blocks > 0 )
cArchiveSigGen::SetBlocks(blocks);
// //
// turn all of the file names into full paths (they're relative to the exe dir) // turn all of the file names into full paths (they're relative to the exe dir)
// //