Make direct i/o option work properly (ie don't use fread(), and use full block size on EOF), & rename it to HASH_DIRECT_IO for clarity

This commit is contained in:
Brian Cox 2016-07-03 14:29:05 -07:00
parent 1c8ec94fd2
commit c4440c5d29
5 changed files with 32 additions and 29 deletions

View File

@ -671,7 +671,8 @@ void cFileArchive::OpenRead(const TCHAR* filename, uint32 openFlags)
flags |= ( ( openFlags & FA_OPEN_TEXT ) ? cFile::OPEN_TEXT : 0 );
flags |= ( ( openFlags & FA_SCANNING ) ? cFile::OPEN_SCANNING : 0 );
flags |= ( ( openFlags & FA_DIRECT ) ? cFile::OPEN_DIRECT : 0 );
mOpenFlags = openFlags;
mCurrentFilename = filename;
mCurrentFile.Open( filename, flags );
isWritable = false;
@ -699,6 +700,7 @@ void cFileArchive::OpenReadWrite(const TCHAR* filename, uint32 openFlags)
flags |= ( ( openFlags & FA_SCANNING ) ? cFile::OPEN_SCANNING : 0 );
flags |= ( ( openFlags & FA_DIRECT ) ? cFile::OPEN_DIRECT : 0 );
mOpenFlags = openFlags;
mCurrentFilename = filename;
mCurrentFile.Open( filename, flags );
isWritable = true;
@ -746,9 +748,10 @@ void cFileArchive::Close()
/////////////////////////////////////////////////////////////////////////
int cFileArchive::Read(void* pDest, int count)
{
try
{
if ( mReadHead + count > mFileSize )
if ( mReadHead + count > mFileSize && !(mOpenFlags & FA_DIRECT))
count = static_cast<int>( mFileSize - mReadHead );
if ( pDest != NULL )

View File

@ -293,6 +293,7 @@ protected:
bool isWritable;
cFile mCurrentFile;
TSTRING mCurrentFilename; //current file
uint32 mOpenFlags;
};
///////////////////////////////////////////////////////////////

View File

@ -62,22 +62,6 @@
#include "core/fsservices.h"
#include "core/errorutil.h"
///////////////////////////////////////////////////////////////////////////////
// util_GetErrnoString -- return the result of strerror(errno) as a tstring
///////////////////////////////////////////////////////////////////////////////
/*static TSTRING util_GetErrnoString()
{
TSTRING ret;
char* pErrorStr = strerror(errno);
#ifdef _UNICODE
#error We dont currently support unicode on unix
#else
ret = pErrorStr;
#endif
return ret;
}*/
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
// cFile_i : Insulated implementation for cFile objects.
///////////////////////////////////////////////////////////////////////////
@ -87,6 +71,7 @@ struct cFile_i
cFile_i();
~cFile_i();
int m_fd; //underlying file descriptor
FILE* mpCurrStream; //currently defined file stream
TSTRING mFileName; //the name of the file we are currently referencing.
uint32 mFlags; //Flags used to open the file
@ -218,6 +203,7 @@ void cFile::Open( const TSTRING& sFileNameC, uint32 flags )
{
throw( eFileOpen( sFileName, iFSServices::GetInstance()->GetErrString() ) );
}
mpData->m_fd = fh;
#if !IS_AROS
if( flags & OPEN_LOCKED_TEMP )
@ -263,7 +249,7 @@ void cFile::Open( const TSTRING& sFileNameC, uint32 flags )
#ifdef HAVE_POSIX_FADVISE
if (flags & OPEN_SCANNING)
if (flags & OPEN_SCANNING && !(flags & OPEN_DIRECT))
{
posix_fadvise(fh,0,0, POSIX_FADV_SEQUENTIAL);
posix_fadvise(fh,0,0, POSIX_FADV_NOREUSE);
@ -363,12 +349,19 @@ cFile::File_t cFile::Read( void* buffer, File_t nBytes ) const //throw(eFile)
if( nBytes == 0 )
return 0;
iBytesRead = fread( buffer, sizeof(byte), nBytes, mpData->mpCurrStream );
if( ferror( mpData->mpCurrStream ) != 0 )
throw eFileRead( mpData->mFileName, iFSServices::GetInstance()->GetErrString() ) ;
else
return iBytesRead;
if (mpData->mFlags & OPEN_DIRECT) {
iBytesRead = read(mpData->m_fd, buffer, nBytes);
if (iBytesRead<0) {
throw eFileRead(mpData->mFileName, iFSServices::GetInstance()->GetErrString());
}
} else {
iBytesRead = fread( buffer, sizeof(byte), nBytes, mpData->mpCurrStream );
if( ferror( mpData->mpCurrStream ) != 0 ) {
throw eFileRead( mpData->mFileName, iFSServices::GetInstance()->GetErrString() ) ;
}
}
return iBytesRead;
}
///////////////////////////////////////////////////////////////////////////

View File

@ -41,6 +41,7 @@
#include <iomanip>
#include "fcoundefprop.h"
#include "core/archive.h"
#include "core/debug.h"
#ifndef HAVE_OPENSSL_MD5_H
# ifdef HAVE_STRINGS_H
# include <strings.h> /* for bcopy(), this is only needed for Solaris */
@ -107,10 +108,15 @@ bool cArchiveSigGen::s_direct = false;
void cArchiveSigGen::SetBlocks( int32 n )
{
cDebug d("cArchiveSigGen::SetBlocks");
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);
d.TraceDebug("Num blocks = %u\n", s_blocks);
s_base = new byte[iSignature::SUGGESTED_BLOCK_SIZE * (s_blocks+2)];
unsigned long mod = (unsigned long)s_base % iSignature::SUGGESTED_BLOCK_SIZE;
unsigned long offset = (iSignature::SUGGESTED_BLOCK_SIZE - mod);
d.TraceDebug("mod = %u | offset = %u\n", mod, offset);
s_buf = s_base + offset;
s_bytes = iSignature::SUGGESTED_BLOCK_SIZE * s_blocks;
}

View File

@ -435,7 +435,7 @@ static void FillOutConfigInfo(cTWModeCommon* pModeInfo, const cConfigFile& cf)
}
int blocks = 0;
if (cf.Lookup(TSTRING(_T("HASH_DIRECT")), str))
if (cf.Lookup(TSTRING(_T("HASH_DIRECT_IO")), str))
{
if (_tcsicmp(str.c_str(), _T("true")) == 0)
{