FTK. Changes to import SetFileValidData on Windows (if available).

git-svn-id: https://svn.code.sf.net/p/flaim/code/trunk@1000 0109f412-320b-0410-ab79-c3e0c5ffbbe6
This commit is contained in:
ahodgkinson
2006-10-18 16:30:01 +00:00
parent 7d2fb4a5e8
commit dea37b9618
4 changed files with 58 additions and 28 deletions

View File

@@ -4697,10 +4697,10 @@
/// of memory blocks that are used for pool memory allocation.
typedef struct
{
FLMUINT uiAllocBytes; ///< Total number of bytes requested from
///< GedPoolAlloc and GedPoolCalloc calls
FLMUINT uiCount; ///< Number of frees and resets performed on
///< the pool
FLMUINT uiAllocBytes; ///< Total number of bytes requested from
///< GedPoolAlloc and GedPoolCalloc calls
FLMUINT uiCount; ///< Number of frees and resets performed on
///< the pool
} POOL_STATS;
class FLMEXP F_Pool : public F_Object

View File

@@ -39,9 +39,9 @@ F_MUTEX F_FileHdl::m_hAsyncListMutex = F_MUTEX_NULL;
F_FileAsyncClient * F_FileHdl::m_pFirstAvailAsync = NULL;
FLMUINT F_FileHdl::m_uiAvailAsyncCount = 0;
FSTATIC RCODE f_initRandomGenerator( void);
FSTATIC void f_freeRandomGenerator( void);
#ifdef FLM_WIN
SET_FILE_VALID_DATA_FUNC gv_SetFileValidDataFunc = NULL;
#endif
#ifdef FLM_AIX
#ifndef nsleep
@@ -52,6 +52,10 @@ FSTATIC void f_freeRandomGenerator( void);
#endif
#endif
FSTATIC RCODE f_initRandomGenerator( void);
FSTATIC void f_freeRandomGenerator( void);
/****************************************************************************
Desc:
****************************************************************************/
@@ -203,13 +207,28 @@ RCODE FLMAPI ftkStartup( void)
setrlimit( RLIMIT_FSIZE, &rlim);
#endif
#if defined( FLM_WIN)
{
HINSTANCE hLibrary;
// Get a handle to the DLL. If the handle is valid, try to get the
// function address.
if( (hLibrary = LoadLibrary( TEXT( "kernel32.dll"))) != NULL)
{
gv_SetFileValidDataFunc = (SET_FILE_VALID_DATA_FUNC)GetProcAddress(
hLibrary, TEXT( "SetFileValidData"));
FreeLibrary( hLibrary);
}
}
#endif
// Setup logger
if (RC_BAD( rc = f_loggerInit()))
{
goto Exit;
}
Exit:

View File

@@ -1302,5 +1302,11 @@
RCODE f_netwareRenameFile(
const char * pOldFilePath,
const char * pNewFilePath);
#if defined(FLM_WIN)
typedef WINBASEAPI BOOL (WINAPI * SET_FILE_VALID_DATA_FUNC) (
HANDLE hFile,
LONGLONG ValidDataLength);
#endif
#endif // FTKSYS_H

View File

@@ -27,7 +27,8 @@
#if defined( FLM_WIN)
extern FLMATOMIC gv_openFiles;
extern FLMATOMIC gv_openFiles;
extern SET_FILE_VALID_DATA_FUNC gv_SetFileValidDataFunc;
/****************************************************************************
Desc:
@@ -193,23 +194,26 @@ RCODE F_FileHdl::openOrCreate(
// opened/created. This will allow subsequent file extend operations to
// be done via calls to SetFileValidData().
if( OpenProcessToken( GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
if( gv_SetFileValidDataFunc)
{
bClosePrivToken = TRUE;
if( LookupPrivilegeValue( NULL, SE_MANAGE_VOLUME_NAME, &luid))
if( OpenProcessToken( GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
{
ZeroMemory ( &tp, sizeof( tp));
bClosePrivToken = TRUE;
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if( AdjustTokenPrivileges( hToken, FALSE, &tp,
sizeof( TOKEN_PRIVILEGES), &oldtp, &udTokenPrivSize))
if( LookupPrivilegeValue( NULL, SE_MANAGE_VOLUME_NAME, &luid))
{
bRestoreTokenPrivileges = TRUE;
ZeroMemory ( &tp, sizeof( tp));
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if( AdjustTokenPrivileges( hToken, FALSE, &tp,
sizeof( TOKEN_PRIVILEGES), &oldtp, &udTokenPrivSize))
{
bRestoreTokenPrivileges = TRUE;
}
}
}
}
@@ -864,13 +868,14 @@ RCODE F_FileHdl::extendFile(
goto Exit;
}
if( SetFileValidData( m_hFile, ui64NewFileSize))
if( gv_SetFileValidDataFunc)
{
// The call was successful. We are done.
goto Exit;
if( (gv_SetFileValidDataFunc)( m_hFile, ui64NewFileSize))
{
goto Exit;
}
}
// Determine the number of bytes to extend
ui64TotalBytesToExtend = ui64NewFileSize - ui64FileSize;