diff --git a/ftk/src/ftk.h b/ftk/src/ftk.h index 70f1cf8..ea6e29c 100644 --- a/ftk/src/ftk.h +++ b/ftk/src/ftk.h @@ -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 diff --git a/ftk/src/ftkmisc.cpp b/ftk/src/ftkmisc.cpp index 0d2bfc4..e9ac16e 100644 --- a/ftk/src/ftkmisc.cpp +++ b/ftk/src/ftkmisc.cpp @@ -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: diff --git a/ftk/src/ftksys.h b/ftk/src/ftksys.h index 6bee0a1..9628f86 100644 --- a/ftk/src/ftksys.h +++ b/ftk/src/ftksys.h @@ -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 diff --git a/ftk/src/ftkwin.cpp b/ftk/src/ftkwin.cpp index 3126b2d..06c951e 100644 --- a/ftk/src/ftkwin.cpp +++ b/ftk/src/ftkwin.cpp @@ -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;