Align buffer on page boundary if user enables HASH_DIRECT (formerly DIRECT_IO); let user specify num blocks per read.
This commit is contained in:
parent
5ffab7f278
commit
9214316bbd
|
@ -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;
|
||||
}
|
||||
|
||||
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 )
|
||||
{
|
||||
|
@ -107,10 +122,11 @@ void cArchiveSigGen::AddSig( iSignature* pSig )
|
|||
void cArchiveSigGen::CalculateSignatures( cArchive& a )
|
||||
{
|
||||
byte abBuf[iSignature::SUGGESTED_BLOCK_SIZE];
|
||||
const int cbToRead = iSignature::SUGGESTED_BLOCK_SIZE;
|
||||
int cbRead;
|
||||
container_type::size_type i;
|
||||
|
||||
byte* pBuf = s_buf ? s_buf : abBuf;
|
||||
|
||||
// init hash
|
||||
for( i = 0; i < mSigList.size(); i++ )
|
||||
mSigList[i]->Init();
|
||||
|
@ -118,12 +134,12 @@ void cArchiveSigGen::CalculateSignatures( cArchive& a )
|
|||
// hash data
|
||||
do
|
||||
{
|
||||
cbRead = a.ReadBlob( abBuf, cbToRead );
|
||||
cbRead = a.ReadBlob( pBuf, s_bytes );
|
||||
|
||||
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
|
||||
for( i = 0; i < mSigList.size(); i++ )
|
||||
|
@ -132,12 +148,12 @@ void cArchiveSigGen::CalculateSignatures( cArchive& a )
|
|||
|
||||
bool cArchiveSigGen::Hex()
|
||||
{
|
||||
return mHex;
|
||||
return s_hex;
|
||||
}
|
||||
|
||||
void cArchiveSigGen::SetHex(bool hex)
|
||||
{
|
||||
mHex = hex;
|
||||
s_hex = hex;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -150,6 +150,10 @@ public:
|
|||
static bool Hex();
|
||||
static void SetHex(bool);
|
||||
|
||||
static void SetBlocks( int32 n );
|
||||
static bool UseDirectIO() { return s_direct; }
|
||||
static void SetUseDirectIO( bool b ) { s_direct = b; }
|
||||
|
||||
private:
|
||||
// don't let C++ create these functions
|
||||
cArchiveSigGen( const cArchiveSigGen& );
|
||||
|
@ -158,7 +162,12 @@ private:
|
|||
typedef std::vector< iSignature* > container_type;
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -433,14 +433,24 @@ static void FillOutConfigInfo(cTWModeCommon* pModeInfo, const cConfigFile& cf)
|
|||
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)
|
||||
{
|
||||
pModeInfo->mbDirectIO = true;
|
||||
else
|
||||
pModeInfo->mbDirectIO = false;
|
||||
cArchiveSigGen::SetUseDirectIO(true);
|
||||
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)
|
||||
//
|
||||
|
|
Loading…
Reference in New Issue