persistentstorage/sql/OsLayer/os_symbian.cpp
branchRCL_3
changeset 24 cc28652e0254
parent 23 26645d81f48d
equal deleted inserted replaced
23:26645d81f48d 24:cc28652e0254
    38 }
    38 }
    39 #include "os_common.h"
    39 #include "os_common.h"
    40 #include "SqliteSymbian.h"
    40 #include "SqliteSymbian.h"
    41 #include "FileBuf64.h"
    41 #include "FileBuf64.h"
    42 #include <e32math.h>
    42 #include <e32math.h>
       
    43 #include "UTraceSql.h"
    43 #ifdef _SQLPROFILER
    44 #ifdef _SQLPROFILER
    44 #include <hal.h>
    45 #include <hal.h>
    45 #include "../INC/SqlResourceProfiler.h"
    46 #include "../INC/SqlResourceProfiler.h"
    46 #endif
    47 #endif
    47 #include "SqliteUtil.h"
       
    48 #include "OstTraceDefinitions.h"
       
    49 #ifdef OST_TRACE_COMPILER_IN_USE
       
    50 #include "os_symbianTraces.h"
       
    51 #endif
       
    52 #include "SqliteTraceDef.h"
       
    53 
    48 
    54 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    49 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    55 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    50 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    56 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    51 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
    52 
       
    53 /**
       
    54 Panic category - used by asserts in this file (the OS porting layer).
       
    55 
       
    56 @see TPanicCodes
       
    57 
       
    58 @internalComponent
       
    59 */
       
    60 _LIT(KPanicCategory, "Sqlite");
       
    61 
       
    62 /**
       
    63 Panic codes - used by asserts in this file (the OS porting layer).
       
    64 
       
    65 @see KPanicCategory
       
    66 
       
    67 @internalComponent
       
    68 */
       
    69 enum TPanicCodes
       
    70 	{
       
    71 	EPanicNullOsLayerDataPtr	= 1,
       
    72 	EPanicInvalidWAmount 		= 2,
       
    73 	EPanicOffset64bit 			= 3,
       
    74 	EPanicInvalidOpType			=11,
       
    75 	EPanicInvalidFhStr			=12,
       
    76 	EPanicInvalidFhData			=13,
       
    77 	EPanicInvalidArg			=14,
       
    78 	EPanicInvalidRAmount 		=15,
       
    79 	EPanicOsLayerDataExists		=16,
       
    80 	EPanicInvalidDrive			=17,
       
    81 	EPanicInvalidSectorSize		=18,
       
    82 	EPanicInternalError			=19,
       
    83 	EPanicNullDbFilePtr			=20,
       
    84 	EPanicFastCounterFreq		=21
       
    85 	};
    57 
    86 
    58 //The SQLite temp files willl be created in this subdir
    87 //The SQLite temp files willl be created in this subdir
    59 _LIT(KTempFileDir, "temp");
    88 _LIT(KTempFileDir, "temp");
    60 
    89 
    61 //Bit-mask constant. If xOpen()'s "aFlag" parameter contains one of these bits set, then the the file top be
    90 //Bit-mask constant. If xOpen()'s "aFlag" parameter contains one of these bits set, then the the file top be
   393 						{
   422 						{
   394 						TPtrC8 fn8(iOptional);
   423 						TPtrC8 fn8(iOptional);
   395 						fname.Copy(fn8);
   424 						fname.Copy(fn8);
   396 						}
   425 						}
   397 					//                                           0    1  2  3  4  5   6  7   8   9   10
   426 					//                                           0    1  2  3  4  5   6  7   8   9   10
   398 					RDebug::Print(_L("[SQL-OS]¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬\"%X\"¬%c¬%S¬%d¬%d¬%ld¬%d¬%ld¬%ld¬%ld¬%S\n"),
   427 					RDebug::Print(_L("[SQL-OS]¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬\"%X\"¬%c¬%S¬%d¬%d¬%ld¬%d¬%ld¬%ld¬%ld¬%S\r\n"),
   399 															//[SQL-OS]
   428 															//[SQL-OS]
   400 															//Handle
   429 															//Handle
   401 															//Time from start, microseconds
   430 															//Time from start, microseconds
   402 															//Subtype
   431 															//Subtype
   403 															//IPC sequence counter
   432 															//IPC sequence counter
   457 
   486 
   458 TInt FastCounterFrequency()
   487 TInt FastCounterFrequency()
   459 	{
   488 	{
   460 	TInt ticksPerSec = 0;
   489 	TInt ticksPerSec = 0;
   461 	TInt err = HAL::Get(HAL::EFastCounterFrequency, ticksPerSec);
   490 	TInt err = HAL::Get(HAL::EFastCounterFrequency, ticksPerSec);
   462 	__ASSERT_ALWAYS(err == KErrNone, __SQLITEPANIC2(ESqliteOsPanicFastCounterFreq));
   491 	__ASSERT_ALWAYS(err == KErrNone, User::Panic(KPanicCategory, EPanicFastCounterFreq));
   463 	return ticksPerSec;
   492 	return ticksPerSec;
   464 	}
   493 	}
   465 
   494 
   466 TInt sqlite3SymbianProfilerStart(TInt aCounterType)
   495 TInt sqlite3SymbianProfilerStart(TInt aCounterType)
   467 	{
   496 	{
   651 	}
   680 	}
   652 
   681 
   653 #endif//_SQLPROFILER
   682 #endif//_SQLPROFILER
   654 
   683 
   655 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   684 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   656 
       
   657 /**
       
   658 Os2SqliteErr() is called at the end of many of the interface functions of the OS porting layer (wherever it is appropriate - 
       
   659 TFileIo and TVfs interfaces). The purpose of this function is to identify the "out of memory" and "disk is full" errors
       
   660 reported by the used Symbian OS APIs (aOsErr parameter) and report them to SQLite as SQLITE_FULL and SQLITE_NOMEM errors.
       
   661 The KErrEof error (TFileIo::Read() can return KErrEof) is reported to SQLite as SQLITE_IOERR_SHORT_READ. The rest of failures
       
   662 are reported as the error specified in aDefaultErr parameter.
       
   663  
       
   664 @param aOsErr      Symbian OS error
       
   665 @param aDefaultErr The default SQLite error that should be used if the aOsErr parameter is not one of:
       
   666                      KErrNone, KErrEof, KErrNoMemory, KErrDiskFull
       
   667 @return SQLITE_OK,               The OS porting layer function call has completed successfully, 
       
   668           SQLITE_IOERR_SHORT_READ, The amount of the data read is less than the requested amount,
       
   669           SQLITE_IOERR_NOMEM,      Out of memory,
       
   670           SQLITE_FULL,             The disk is full,
       
   671           aDefaultErr,             The rest of failures will be reported as aDefaultErr.
       
   672 */
       
   673 static TInt Os2SqliteErr(TInt aOsErr, TInt aDefaultErr)
       
   674 	{
       
   675 	switch(aOsErr)
       
   676 		{
       
   677 		case KErrNone:
       
   678 			return SQLITE_OK;	
       
   679 		case KErrEof:
       
   680 			return SQLITE_IOERR_SHORT_READ;
       
   681 		case KErrNoMemory:
       
   682 			return SQLITE_IOERR_NOMEM;
       
   683 		case KErrDiskFull:
       
   684 			return SQLITE_FULL;
       
   685 		default:
       
   686 #ifdef _DEBUG		
       
   687 			RDebug::Print(_L("SQLite OS porting layer, Os2SqliteErr(), err=%d\n"), aOsErr);
       
   688 			SQLITE_TRACE_OS(OstTrace1(TRACE_INTERNALS, OS2SQLITEERR, "OS;0;Os2SqliteErr;aOsErr=%d", aOsErr));
       
   689 #endif			
       
   690 			break;
       
   691 		}
       
   692 	return aDefaultErr;
       
   693 	}
       
   694 	
       
   695 
       
   696 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
   697 /////////////////////       COsLayerData class declaration   //////////////////////////////////////////////////////////////////
   685 /////////////////////       COsLayerData class declaration   //////////////////////////////////////////////////////////////////
   698 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   686 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   699 
   687 
   700 /**
   688 /**
   701 COsLayerData singleton class manages a single SQLite OS layer copy of the following data: 
   689 COsLayerData singleton class manages a single SQLite OS layer copy of the following data: 
   857 	static int FullPathName(sqlite3_vfs* aVfs, const char* aRelative, int aBufLen, char* aBuf);
   845 	static int FullPathName(sqlite3_vfs* aVfs, const char* aRelative, int aBufLen, char* aBuf);
   858 	static int Randomness(sqlite3_vfs* aVfs, int aBufLen, char* aBuf);
   846 	static int Randomness(sqlite3_vfs* aVfs, int aBufLen, char* aBuf);
   859 	static int Sleep(sqlite3_vfs* aVfs, int aMicrosec);
   847 	static int Sleep(sqlite3_vfs* aVfs, int aMicrosec);
   860 	static int CurrentTime(sqlite3_vfs* aVfs, double* aNow);
   848 	static int CurrentTime(sqlite3_vfs* aVfs, double* aNow);
   861 	static int GetLastError(sqlite3_vfs *sVfs, int aBufLen, char* aBuf);
   849 	static int GetLastError(sqlite3_vfs *sVfs, int aBufLen, char* aBuf);
   862 	static TInt DoGetDeviceCharacteristicsAndSectorSize(TDbFile& aDbFile, TInt& aRecReadBufSize);
   850     static TInt DoGetDeviceCharacteristicsAndSectorSize(TDbFile& aDbFile, TInt& aRecReadBufSize);
       
   851 
   863 private:
   852 private:
   864 	static TInt DoOpenFromHandle(TDbFile& aDbFile, const RMessage2& aMsg, TBool aReadOnly);
   853 	static TInt DoOpenFromHandle(TDbFile& aDbFile, const RMessage2& aMsg, TBool aReadOnly);
   865 	static inline TInt DoGetVolumeIoParamInfo(RFs& aFs, TInt aDriveNo, TVolumeIOParamInfo& aVolumeInfo);
   854 	static inline TInt DoGetVolumeIoParamInfo(RFs& aFs, TInt aDriveNo, TVolumeIOParamInfo& aVolumeInfo);
   866 	static TInt DoGetDeviceCharacteristics(const TDriveInfo& aDriveInfo, const TVolumeIOParamInfo& aVolumeInfo);
   855 	static TInt DoGetDeviceCharacteristics(const TDriveInfo& aDriveInfo, const TVolumeIOParamInfo& aVolumeInfo);
   867 	static TInt DoGetSectorSize(const TDriveInfo& aDriveInfo, const TVolumeIOParamInfo& aVolumeInfo);
   856 	static TInt DoGetSectorSize(const TDriveInfo& aDriveInfo, const TVolumeIOParamInfo& aVolumeInfo);
   967                            
   956                            
   968 @panic Sqlite 16 In _DEBUG mode - the COsLayerData instance has been created already.
   957 @panic Sqlite 16 In _DEBUG mode - the COsLayerData instance has been created already.
   969 */
   958 */
   970 /* static */ TInt COsLayerData::Create()
   959 /* static */ TInt COsLayerData::Create()
   971 	{
   960 	{
   972 	SQLITE_TRACE_OS(OstTrace0(TRACE_INTERNALS, COSLAYERDATA_CREATE_ENTRY, "OS-Entry;0;COsLayerData::Create"));
   961 	__ASSERT_DEBUG(!COsLayerData::iOsLayerData, User::Panic(KPanicCategory, EPanicOsLayerDataExists));
   973 	__ASSERT_DEBUG(!COsLayerData::iOsLayerData, __SQLITEPANIC2(ESqliteOsPanicOsLayerDataExists));
       
   974 	if(!COsLayerData::iOsLayerData)
   962 	if(!COsLayerData::iOsLayerData)
   975 		{
   963 		{
   976 		COsLayerData::iOsLayerData = new COsLayerData;
   964 		COsLayerData::iOsLayerData = new COsLayerData;
   977 		if(!COsLayerData::iOsLayerData)
   965 		if(!COsLayerData::iOsLayerData)
   978 			{
   966 			{
   979 			SQLITE_TRACE_OS(OstTrace0(TRACE_INTERNALS, COSLAYERDATA_CREATE_EXIT1, "OS-Exit;0;COsLayerData::Create;err=KErrNoMemory"));
       
   980 			return KErrNoMemory;	
   967 			return KErrNoMemory;	
   981 			}
   968 			}
   982 		TInt err = COsLayerData::iOsLayerData->DoCreate();
   969 		TInt err = COsLayerData::iOsLayerData->DoCreate();
   983 		if(err != KErrNone)
   970 		if(err != KErrNone)
   984 			{
   971 			{
   985 			delete COsLayerData::iOsLayerData;
   972 			delete COsLayerData::iOsLayerData;
   986 			COsLayerData::iOsLayerData = NULL;
   973 			COsLayerData::iOsLayerData = NULL;
   987 			SQLITE_TRACE_OS(OstTrace1(TRACE_INTERNALS, COSLAYERDATA_CREATE_EXIT2, "OS-Exit;0;COsLayerData::Create;err=%d", err));
       
   988 			return err;
   974 			return err;
   989 			}
   975 			}
   990 		}
   976 		}
   991 	SQLITE_TRACE_OS(OstTrace0(TRACE_INTERNALS, COSLAYERDATA_CREATE_EXIT3, "OS-Exit;0;COsLayerData::Create;err=KErrNone"));
       
   992 	return KErrNone;
   977 	return KErrNone;
   993 	}
   978 	}
   994 
   979 
   995 /**
   980 /**
   996 Destroys the COsLayerData instance.
   981 Destroys the COsLayerData instance.
   997 */
   982 */
   998 /* static */ inline void COsLayerData::Destroy()
   983 /* static */ inline void COsLayerData::Destroy()
   999 	{
   984 	{
  1000 	delete COsLayerData::iOsLayerData;
   985 	delete COsLayerData::iOsLayerData;
  1001 	COsLayerData::iOsLayerData = NULL;
   986 	COsLayerData::iOsLayerData = NULL;
  1002 	SQLITE_TRACE_OS(OstTrace0(TRACE_INTERNALS, COSLAYERDATA_DESTROY, "OS;0;COsLayerData::Destroy"));
       
  1003 	}
   987 	}
  1004 
   988 
  1005 /**
   989 /**
  1006 Returns a reference to the single COsLayerData instance.
   990 Returns a reference to the single COsLayerData instance.
  1007 
   991 
  1008 @panic Sqlite 1 In _DEBUG mode if the COsLayerData instance is NULL.
   992 @panic Sqlite 1 In _DEBUG mode if the COsLayerData instance is NULL.
  1009 */
   993 */
  1010 /* static */ inline COsLayerData& COsLayerData::Instance()
   994 /* static */ inline COsLayerData& COsLayerData::Instance()
  1011 	{
   995 	{
  1012 	__ASSERT_DEBUG(COsLayerData::iOsLayerData != NULL, __SQLITEPANIC2(ESqliteOsPanicNullOsLayerDataPtr));
   996 	__ASSERT_DEBUG(COsLayerData::iOsLayerData != NULL, User::Panic(KPanicCategory, EPanicNullOsLayerDataPtr));
  1013 	return *COsLayerData::iOsLayerData;
   997 	return *COsLayerData::iOsLayerData;
  1014 	}
   998 	}
  1015 
   999 
  1016 /**
  1000 /**
  1017 Sets the last OS error code data member. The stored OS error code data member will be set only if it is
  1001 Sets the last OS error code data member. The stored OS error code data member will be set only if it is
  1081 
  1065 
  1082 @panic Sqlite 13 In _DEBUG mode - aMsg is NULL.
  1066 @panic Sqlite 13 In _DEBUG mode - aMsg is NULL.
  1083 */
  1067 */
  1084 inline void COsLayerData::RetrieveAndResetFhData(const RMessage2*& aMsg, TBool& aReadOnly)
  1068 inline void COsLayerData::RetrieveAndResetFhData(const RMessage2*& aMsg, TBool& aReadOnly)
  1085 	{
  1069 	{
  1086 	__ASSERT_DEBUG(iMessage != NULL, __SQLITEPANIC(ESqliteOsPanicInvalidFhData));
  1070 	__ASSERT_DEBUG(iMessage != NULL, User::Panic(KPanicCategory, EPanicInvalidFhData));
  1087 	aMsg = iMessage; 
  1071 	aMsg = iMessage; 
  1088 	aReadOnly = iReadOnly;
  1072 	aReadOnly = iReadOnly;
  1089 	iMessage = NULL;
  1073 	iMessage = NULL;
  1090 	}
  1074 	}
  1091 
  1075 
  1107 
  1091 
  1108 Note: No SQLite functions should be called inside the destructor, because SQLite is already shutdown-ed!
  1092 Note: No SQLite functions should be called inside the destructor, because SQLite is already shutdown-ed!
  1109 */
  1093 */
  1110 inline COsLayerData::~COsLayerData()
  1094 inline COsLayerData::~COsLayerData()
  1111 	{
  1095 	{
  1112 	SQLITE_TRACE_OS(OstTrace1(TRACE_INTERNALS, COSLAYERDATA_COSLAYERDATA2, "OS;0;COsLayerData::~COsLayerData;iFs.Handle()=0x%X", (TUint)iFs.Handle()));
       
  1113 	__FS_CALL(EFsOpFsClose, 0);
  1096 	__FS_CALL(EFsOpFsClose, 0);
  1114 	iFs.Close();	
  1097 	iFs.Close();	
  1115 	}
  1098 	}
  1116 
  1099 
  1117 /**
  1100 /**
  1164 	err = iFs.MkDir(parse.DriveAndPath());
  1147 	err = iFs.MkDir(parse.DriveAndPath());
  1165     if(err != KErrNone && err != KErrAlreadyExists)
  1148     if(err != KErrNone && err != KErrAlreadyExists)
  1166     	{
  1149     	{
  1167 		return err;
  1150 		return err;
  1168     	}
  1151     	}
  1169 	SQLITE_TRACE_OS(OstTraceExt3(TRACE_INTERNALS, COSLAYERDATA_DOCREATE, "OS;0;COsLayerData::DoCreate;iFs.Handle()=0x%X;sysDrive=%d;iSysPrivDir=%S", (TUint)iFs.Handle(), sysDrive, __SQLITEPRNSTR(iSysPrivDir)));
       
  1170 	return KErrNone;
  1152 	return KErrNone;
  1171 	}
  1153 	}
  1172 
  1154 
  1173 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1155 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1174 ///////////////////////     Symbian OS specific functions (called by the SQL server)        ///////////////////////////////////
  1156 ///////////////////////     Symbian OS specific functions (called by the SQL server)        ///////////////////////////////////
  1214 	if(sqliteErr != SQLITE_OK)
  1196 	if(sqliteErr != SQLITE_OK)
  1215 		{
  1197 		{
  1216 		osErr = sqliteErr == SQLITE_NOMEM ? KErrNoMemory : KErrGeneral;
  1198 		osErr = sqliteErr == SQLITE_NOMEM ? KErrNoMemory : KErrGeneral;
  1217 		COsLayerData::Destroy();
  1199 		COsLayerData::Destroy();
  1218 		}
  1200 		}
  1219 	SQLITE_TRACE_OS(OstTrace1(TRACE_INTERNALS, SQLITE3SYMBIANLIBINIT, "OS;0;sqlite3SymbianLibInit;osErr=%d", osErr));
       
  1220 	return osErr;
  1201 	return osErr;
  1221 	}
  1202 	}
  1222 
  1203 
  1223 /**
  1204 /**
  1224 This function must be called once after finishing working with sqlite.
  1205 This function must be called once after finishing working with sqlite.
  1234 */
  1215 */
  1235 void sqlite3SymbianLibFinalize(void)
  1216 void sqlite3SymbianLibFinalize(void)
  1236 	{
  1217 	{
  1237 	(void)sqlite3_shutdown();
  1218 	(void)sqlite3_shutdown();
  1238 	COsLayerData::Destroy();
  1219 	COsLayerData::Destroy();
  1239 	SQLITE_TRACE_OS(OstTrace0(TRACE_INTERNALS, SQLITE3SYMBIANLIBFINALIZE, "OS;0;sqlite3SymbianLibFinalize"));
       
  1240 	}
  1220 	}
  1241 
  1221 
  1242 /**
  1222 /**
  1243 This function is part of Symbian OS specific SQLITE API.
  1223 This function is part of Symbian OS specific SQLITE API.
  1244 
  1224 
  1271 	{
  1251 	{
  1272 	if(aFileName)
  1252 	if(aFileName)
  1273 		{
  1253 		{
  1274 		wchar_t* dest = reinterpret_cast <wchar_t*> (const_cast <TUint16*> (aFileNameDestBuf.Ptr()));
  1254 		wchar_t* dest = reinterpret_cast <wchar_t*> (const_cast <TUint16*> (aFileNameDestBuf.Ptr()));
  1275 		TInt len = mbstowcs(dest, aFileName, aFileNameDestBuf.MaxLength());
  1255 		TInt len = mbstowcs(dest, aFileName, aFileNameDestBuf.MaxLength());
  1276 		__ASSERT_DEBUG(len >= 0, __SQLITEPANIC2(ESqliteOsPanicInternalError));
  1256 		__ASSERT_DEBUG(len >= 0, User::Panic(KPanicCategory, EPanicInternalError));
  1277 		//If len == aFileNameDestBuf.MaxLength(), then the output buffer is too small.
  1257 		//If len == aFileNameDestBuf.MaxLength(), then the output buffer is too small.
  1278 		if(len < aFileNameDestBuf.MaxLength())
  1258 		if(len < aFileNameDestBuf.MaxLength())
  1279 			{
  1259 			{
  1280 			aFileNameDestBuf.SetLength(len);
  1260 			aFileNameDestBuf.SetLength(len);
  1281 			return ETrue;
  1261 			return ETrue;
  1300 static TBool ConvertFromUnicode(const TDesC& aFileName, TDes8& aFileNameDestBuf)
  1280 static TBool ConvertFromUnicode(const TDesC& aFileName, TDes8& aFileNameDestBuf)
  1301 	{
  1281 	{
  1302 	char* dest = reinterpret_cast <char*> (const_cast <TUint8*> (aFileNameDestBuf.Ptr()));
  1282 	char* dest = reinterpret_cast <char*> (const_cast <TUint8*> (aFileNameDestBuf.Ptr()));
  1303 	const wchar_t* src = reinterpret_cast <const wchar_t*> (aFileName.Ptr());
  1283 	const wchar_t* src = reinterpret_cast <const wchar_t*> (aFileName.Ptr());
  1304 	TInt len = wcstombs(dest, src, aFileNameDestBuf.MaxLength());
  1284 	TInt len = wcstombs(dest, src, aFileNameDestBuf.MaxLength());
  1305 	__ASSERT_DEBUG(len >= 0, __SQLITEPANIC2(ESqliteOsPanicInternalError));
  1285 	__ASSERT_DEBUG(len >= 0, User::Panic(KPanicCategory, EPanicInternalError));
  1306 	//If len == aFileNameDestBuf.MaxLength(), then the output buffer is too small.
  1286 	//If len == aFileNameDestBuf.MaxLength(), then the output buffer is too small.
  1307 	if(len < aFileNameDestBuf.MaxLength())
  1287 	if(len < aFileNameDestBuf.MaxLength())
  1308 		{
  1288 		{
  1309 		aFileNameDestBuf.SetLength(len);
  1289 		aFileNameDestBuf.SetLength(len);
  1310 		return ETrue;
  1290 		return ETrue;
  1442 @panic Sqlite 12 In _DEBUG mode - the extracted RMessage2 pointer is NULL.
  1422 @panic Sqlite 12 In _DEBUG mode - the extracted RMessage2 pointer is NULL.
  1443 */
  1423 */
  1444 static void FhExtractAndStore(TDes& aDbFileName)
  1424 static void FhExtractAndStore(TDes& aDbFileName)
  1445 	{
  1425 	{
  1446 	TInt fhStartPos = aDbFileName.Locate(TChar(KFhSeparator));
  1426 	TInt fhStartPos = aDbFileName.Locate(TChar(KFhSeparator));
  1447 	__ASSERT_DEBUG(fhStartPos == KFhMarkPos, __SQLITEPANIC2(ESqliteOsPanicInvalidFhStr));
  1427 	__ASSERT_DEBUG(fhStartPos == KFhMarkPos, User::Panic(KPanicCategory, EPanicInvalidFhStr));
  1448 	//If this file name string contains file handles
  1428 	//If this file name string contains file handles
  1449 	if(fhStartPos == KFhMarkPos)
  1429 	if(fhStartPos == KFhMarkPos)
  1450 		{
  1430 		{
  1451 		//Extract from aDbFileName string RMessage2 object's address
  1431 		//Extract from aDbFileName string RMessage2 object's address
  1452 		TLex lex(aDbFileName.Mid(fhStartPos + KFhMsgAddrPos, KFhMsgAddrLen));
  1432 		TLex lex(aDbFileName.Mid(fhStartPos + KFhMsgAddrPos, KFhMsgAddrLen));
  1453 		TUint32 addr;
  1433 		TUint32 addr;
  1454 		TInt err = lex.Val(addr, EHex);
  1434 		TInt err = lex.Val(addr, EHex);
  1455 		__ASSERT_DEBUG(err == KErrNone, __SQLITEPANIC2(ESqliteOsPanicInvalidFhStr));
  1435 		__ASSERT_DEBUG(err == KErrNone, User::Panic(KPanicCategory, EPanicInvalidFhStr));
  1456 		if(err == KErrNone)
  1436 		if(err == KErrNone)
  1457 			{
  1437 			{
  1458 			//Cast the address to RMessage2 pointer.
  1438 			//Cast the address to RMessage2 pointer.
  1459 			const RMessage2* msg = reinterpret_cast <const RMessage2*> (addr);
  1439 			const RMessage2* msg = reinterpret_cast <const RMessage2*> (addr);
  1460 			__ASSERT_DEBUG(msg != NULL, __SQLITEPANIC2(ESqliteOsPanicInvalidFhStr));
  1440 			__ASSERT_DEBUG(msg != NULL, User::Panic(KPanicCategory, EPanicInvalidFhStr));
  1461 			if(msg)
  1441 			if(msg)
  1462 				{
  1442 				{
  1463 				//Store the data from aDbFileName in the single COsLayerData instance.
  1443 				//Store the data from aDbFileName in the single COsLayerData instance.
  1464 				TBool readOnly = aDbFileName[fhStartPos + KFhRoPos] > '0';
  1444 				TBool readOnly = aDbFileName[fhStartPos + KFhRoPos] > '0';
  1465 				COsLayerData::Instance().StoreFhData(msg, readOnly);
  1445 				COsLayerData::Instance().StoreFhData(msg, readOnly);
  1487 	{
  1467 	{
  1488 #ifdef _SQLPROFILER
  1468 #ifdef _SQLPROFILER
  1489 	iIsJournal = EFalse;
  1469 	iIsJournal = EFalse;
  1490 #endif
  1470 #endif
  1491 	pMethods = 0;
  1471 	pMethods = 0;
  1492 	SQLITE_TRACE_OS(OstTrace1(TRACE_INTERNALS, TDBFILE_TDBFILE, "OS;0x%X;TDbFile::TDbFile", (TUint)this));
       
  1493 	}
  1472 	}
  1494 
  1473 
  1495 /**
  1474 /**
  1496 Casts the passed sqlite3_file pointer to a reference to the derived class - TDbFile&.
  1475 Casts the passed sqlite3_file pointer to a reference to the derived class - TDbFile&.
  1497 All sqlite3_file pointers passed to TFileIo methods are actually pointers to TDbFile instances. 
  1476 All sqlite3_file pointers passed to TFileIo methods are actually pointers to TDbFile instances. 
  1508 
  1487 
  1509 @internalComponent
  1488 @internalComponent
  1510 */
  1489 */
  1511 static inline TDbFile& DbFile(sqlite3_file* aDbFile)
  1490 static inline TDbFile& DbFile(sqlite3_file* aDbFile)
  1512 	{
  1491 	{
  1513 	__ASSERT_DEBUG(aDbFile != 0, __SQLITEPANIC2(ESqliteOsPanicNullDbFilePtr));
  1492 	__ASSERT_DEBUG(aDbFile != 0, User::Panic(KPanicCategory, EPanicNullDbFilePtr));
  1514 	return *(static_cast <TDbFile*> (aDbFile));
  1493 	return *(static_cast <TDbFile*> (aDbFile));
  1515 	}
  1494 	}
  1516 
  1495 
  1517 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1496 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1518 /////////////////////       TFileIo class definition    ///////////////////////////////////////////////////////////////////////
  1497 /////////////////////       TFileIo class definition    ///////////////////////////////////////////////////////////////////////
  1529 
  1508 
  1530 @see TDbFile
  1509 @see TDbFile
  1531 */
  1510 */
  1532 /* static */ int TFileIo::Close(sqlite3_file* aDbFile)
  1511 /* static */ int TFileIo::Close(sqlite3_file* aDbFile)
  1533 	{
  1512 	{
       
  1513 	SQLUTRACE_PROFILER(aDbFile);
  1534 	TDbFile& dbFile = ::DbFile(aDbFile);
  1514 	TDbFile& dbFile = ::DbFile(aDbFile);
  1535 	SQLITE_TRACE_OS(OstTrace1(TRACE_INTERNALS, TFILEIO_CLOSE1, "OS;0x%X;TFileIo::Close", (TUint)&dbFile));
       
  1536 	__OS_CALL(EOsFileClose, 0, 0);
  1515 	__OS_CALL(EOsFileClose, 0, 0);
  1537 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileClose], ::OsCallProfile(dbFile.iIsJournal, EOsFileClose), 0, 0, aDbFile, 0);
  1516 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileClose], ::OsCallProfile(dbFile.iIsJournal, EOsFileClose), 0, 0, aDbFile, 0);
  1538 	__FS_CALL(EFsOpFileClose, 0);
  1517 	__FS_CALL(EFsOpFileClose, 0);
  1539 	dbFile.iFileBuf.Close();
  1518   dbFile.iFileBuf.Close();
  1540 	return SQLITE_OK;
  1519 	return SQLITE_OK;
  1541 	}
  1520 	}
  1542 
  1521 
  1543 /**
  1522 /**
  1544 SQLite OS porting layer API.
  1523 SQLite OS porting layer API.
  1562 @see COsLayerData::SetOsErrorCode()
  1541 @see COsLayerData::SetOsErrorCode()
  1563 @see TDbFile
  1542 @see TDbFile
  1564 */
  1543 */
  1565 /* static */ int TFileIo::Read(sqlite3_file* aDbFile, void* aBuf, int aAmt, sqlite3_int64 aOffset)
  1544 /* static */ int TFileIo::Read(sqlite3_file* aDbFile, void* aBuf, int aAmt, sqlite3_int64 aOffset)
  1566 	{
  1545 	{
       
  1546 	SQLUTRACE_PROFILER(aDbFile);
       
  1547 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KFileRead, aAmt, aOffset));
  1567 	TDbFile& dbFile = ::DbFile(aDbFile);
  1548 	TDbFile& dbFile = ::DbFile(aDbFile);
  1568 	SQLITE_TRACE_OS(OstTraceExt3(TRACE_INTERNALS, TFILEIO_READ_ENTRY, "OS-Entry;0x%X;TFileIo::Read;aAmt=%d;aOffset=%lld", (TUint)&dbFile, aAmt, aOffset));
       
  1569 	__OS_CALL(EOsFileRead, 0, 0);
  1549 	__OS_CALL(EOsFileRead, 0, 0);
  1570 	__COUNTER_INCR(TheSqlSrvProfilerFileRead);
  1550 	__COUNTER_INCR(TheSqlSrvProfilerFileRead);
  1571 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileRead], ::OsCallProfile(dbFile.iIsJournal, EOsFileRead), aOffset, aAmt, aDbFile, 0);
  1551 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileRead], ::OsCallProfile(dbFile.iIsJournal, EOsFileRead), aOffset, aAmt, aDbFile, 0);
  1572 	TPtr8 ptr((TUint8*)aBuf, 0, aAmt);
  1552 	TPtr8 ptr((TUint8*)aBuf, 0, aAmt);
  1573 	TInt err = dbFile.iFileBuf.Read(aOffset, ptr);
  1553 	TInt err = dbFile.iFileBuf.Read(aOffset, ptr);
  1574 	TInt cnt = ptr.Length();
  1554 	TInt cnt = ptr.Length();
  1575 	TInt sqliteErr = ::Os2SqliteErr(err, SQLITE_IOERR_READ);
  1555 	TInt sqliteErr = SQLITE_IOERR_READ;
  1576 	if(cnt != aAmt && (sqliteErr == SQLITE_OK || sqliteErr == SQLITE_IOERR_SHORT_READ))
  1556 	switch(err)
  1577 		{
  1557 		{
  1578 		Mem::FillZ(static_cast <TUint8*> (aBuf) + cnt, aAmt - cnt);
  1558 		case KErrNone:
  1579 		err = KErrEof;
  1559 			sqliteErr = SQLITE_OK;	
  1580 		sqliteErr = SQLITE_IOERR_SHORT_READ;
  1560 			if(cnt != aAmt)
       
  1561 				{
       
  1562 				Mem::FillZ(static_cast <TUint8*> (aBuf) + cnt, aAmt - cnt);
       
  1563 				sqliteErr = SQLITE_IOERR_SHORT_READ;
       
  1564 				err = KErrEof;
       
  1565 				}
       
  1566 			break;
       
  1567 		case KErrEof:
       
  1568 			Mem::FillZ(static_cast <TUint8*> (aBuf) + cnt, aAmt - cnt);
       
  1569 			sqliteErr = SQLITE_IOERR_SHORT_READ;
       
  1570 			break;
       
  1571 		case KErrNoMemory:
       
  1572 			sqliteErr = SQLITE_IOERR_NOMEM;
       
  1573 			break;
       
  1574 		default:
       
  1575 			break;
  1581 		}
  1576 		}
  1582 	COsLayerData::Instance().SetOsErrorCode(err);
  1577 	COsLayerData::Instance().SetOsErrorCode(err);
  1583 	SQLITE_TRACE_OS(OstTraceExt4(TRACE_INTERNALS, TFILEIO_READ_EXIT, "OS-Exit;0x%X;TFileIo::Read;cnt=%d;err=%d;sqliteErr=%d", (TUint)&dbFile, cnt, err, sqliteErr));
       
  1584 	return sqliteErr;
  1578 	return sqliteErr;
  1585 	}
  1579 	}
  1586 
  1580 
  1587 //Creates a temporary file in "\temp" subdirectory of osLayerData.iSysPrivDir directory.
  1581 //Creates a temporary file in "\temp" subdirectory of osLayerData.iSysPrivDir directory.
  1588 //If the function fails, the temp file will be closed and deleted, 
  1582 //If the function fails, the temp file will be closed and deleted, 
  1657 @see COsLayerData::SetOsErrorCode()
  1651 @see COsLayerData::SetOsErrorCode()
  1658 @see TDbFile
  1652 @see TDbFile
  1659 */
  1653 */
  1660 /* static */ int TFileIo::Write(sqlite3_file* aDbFile, const void* aData, int aAmt, sqlite3_int64 aOffset)
  1654 /* static */ int TFileIo::Write(sqlite3_file* aDbFile, const void* aData, int aAmt, sqlite3_int64 aOffset)
  1661 	{
  1655 	{
       
  1656 	SQLUTRACE_PROFILER(aDbFile);
       
  1657 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KFileWrite, aAmt, aOffset));
  1662 	TDbFile& dbFile = ::DbFile(aDbFile);
  1658 	TDbFile& dbFile = ::DbFile(aDbFile);
  1663 	SQLITE_TRACE_OS(OstTraceExt3(TRACE_INTERNALS, TFILEIO_WRITE_ENTRY, "OS-Entry;0x%X;TFileIo::Write;aAmt=%d;aOffset=%lld", (TUint)&dbFile, aAmt, aOffset));
       
  1664 	__OS_CALL(EOsFileWrite, 0, 0);
       
  1665     __COUNTER_INCR(TheSqlSrvProfilerFileWrite);
       
  1666 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileWrite], ::OsCallProfile(dbFile.iIsJournal, EOsFileWrite), aOffset, aAmt, aDbFile, 0);
       
  1667 	TInt err = KErrNone;
  1659 	TInt err = KErrNone;
  1668 	if(!dbFile.iIsFileCreated)
  1660 	if(!dbFile.iIsFileCreated)
  1669 	    {//Create a temp file if it has not been created. 
  1661 	    {//Create a temp file if it has not been created. 
  1670 	    err = TFileIo::DoCreateTempFile(dbFile);
  1662 	    err = TFileIo::DoCreateTempFile(dbFile);
  1671 	    }
  1663 	    }
  1672 	if(err != KErrNone)
  1664 	if(err != KErrNone)
  1673 	    {
  1665 	    {
  1674         COsLayerData::Instance().SetOsErrorCode(err);
  1666         COsLayerData::Instance().SetOsErrorCode(err);
  1675 		return ::Os2SqliteErr(err, SQLITE_FULL);
  1667         return err == KErrNoMemory ? SQLITE_IOERR_NOMEM : SQLITE_FULL;
  1676 	    }
  1668 	    }
  1677 	err = KErrAccessDenied;
       
  1678 	if(!dbFile.iReadOnly)
       
  1679 		{
       
  1680 		TPtrC8 ptr((const TUint8*)aData, aAmt);
       
  1681 		err = dbFile.iFileBuf.Write(aOffset, ptr);
       
  1682 		}
       
  1683 	COsLayerData::Instance().SetOsErrorCode(err);
       
  1684 	
  1669 	
  1685 	const TInt KFreePageCountOffset = 36;//hard-coded constant. SQLite does not offer anything - a constant or #define.
  1670     __OS_CALL(EOsFileWrite, 0, 0);
  1686 	//The checks in the "if" bellow do:
  1671     __COUNTER_INCR(TheSqlSrvProfilerFileWrite);
  1687 	// - "err == KErrNone" - check the free page count only after a successful "write";
  1672     __OSTIME_COUNTER(TheOsCallTicks[EOsFileWrite], ::OsCallProfile(dbFile.iIsJournal, EOsFileWrite), aOffset, aAmt, aDbFile, 0);
  1688 	// - "aOffset == 0"    - check the free page count only if the write operation affects the system page (at aOffset = 0);
  1673     err = KErrAccessDenied;
  1689 	// - "aAmt >= (KFreePageCountOffset + sizeof(int))" - check the free page count only if the amount of bytes to be written
  1674     if(!dbFile.iReadOnly)
  1690 	//						 is more than the offset of the free page counter (othewrise the free page counter is not affected
  1675         {
  1691 	//						 by this write operation);
  1676         TPtrC8 ptr((const TUint8*)aData, aAmt);
  1692 	// - "dbFile.iFreePageCallback.IsValid()" - check the free page count only if there is a valid callback;
  1677         err = dbFile.iFileBuf.Write(aOffset, ptr);
  1693 	if(err == KErrNone  && aOffset == 0 && aAmt >= (KFreePageCountOffset + sizeof(int)) && dbFile.iFreePageCallback.IsValid())
  1678         }
  1694 		{
  1679     COsLayerData::Instance().SetOsErrorCode(err);
  1695 		const TUint8* ptr = static_cast <const TUint8*> (aData) + KFreePageCountOffset;
  1680     
  1696 		TInt freePageCount = (ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | ptr[3];
  1681     const TInt KFreePageCountOffset = 36;//hard-coded constant. SQLite does not offer anything - a constant or #define.
  1697 		dbFile.iFreePageCallback.CheckAndCallback(freePageCount);
  1682     //The checks in the "if" bellow do:
  1698 		}
  1683     // - "err == KErrNone" - check the free page count only after a successful "write";
  1699 		
  1684     // - "aOffset == 0"    - check the free page count only if the write operation affects the system page (at aOffset = 0);
  1700 	TInt sqliteErr = ::Os2SqliteErr(err, SQLITE_FULL);
  1685     // - "aAmt >= (KFreePageCountOffset + sizeof(int))" - check the free page count only if the amount of bytes to be written
  1701 	SQLITE_TRACE_OS(OstTraceExt3(TRACE_INTERNALS, TFILEIO_WRITE_EXIT, "OS-Exit;0x%X;TFileIo::Write;err=%d;sqliteErr=%d", (TUint)&dbFile, err, sqliteErr));
  1686     //						 is more than the offset of the free page counter (othewrise the free page counter is not affected
  1702 	return sqliteErr;
  1687     //						 by this write operation);
       
  1688     // - "dbFile.iFreePageCallback.IsValid()" - check the free page count only if there is a valid callback;
       
  1689     if(err == KErrNone  && aOffset == 0 && aAmt >= (KFreePageCountOffset + sizeof(int)) && dbFile.iFreePageCallback.IsValid())
       
  1690         {
       
  1691         const TUint8* ptr = static_cast <const TUint8*> (aData) + KFreePageCountOffset;
       
  1692         TInt freePageCount = (ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | ptr[3];
       
  1693         dbFile.iFreePageCallback.CheckAndCallback(freePageCount);
       
  1694         }
       
  1695 	return err == KErrNone ? SQLITE_OK : (err == KErrNoMemory ? SQLITE_IOERR_NOMEM : SQLITE_FULL);
  1703 	}
  1696 	}
  1704 
  1697 
  1705 /**
  1698 /**
  1706 SQLite OS porting layer API.
  1699 SQLite OS porting layer API.
  1707 
  1700 
  1722 @see COsLayerData::SetOsErrorCode()
  1715 @see COsLayerData::SetOsErrorCode()
  1723 @see TDbFile
  1716 @see TDbFile
  1724 */
  1717 */
  1725 /* static */ int TFileIo::Truncate(sqlite3_file* aDbFile, sqlite3_int64 aLength)
  1718 /* static */ int TFileIo::Truncate(sqlite3_file* aDbFile, sqlite3_int64 aLength)
  1726 	{
  1719 	{
       
  1720 	SQLUTRACE_PROFILER(aDbFile);
       
  1721 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KFileTruncate, aLength));
  1727 	TDbFile& dbFile = ::DbFile(aDbFile);
  1722 	TDbFile& dbFile = ::DbFile(aDbFile);
  1728 	SQLITE_TRACE_OS(OstTraceExt2(TRACE_INTERNALS, TFILEIO_TRUNCATE_ENTRY, "OS-Entry;0x%X;TFileIo::Truncate;aLength=%lld", (TUint)&dbFile, aLength));
       
  1729 	__OS_CALL(EOsFileTruncate, 0, 0);
  1723 	__OS_CALL(EOsFileTruncate, 0, 0);
  1730     __COUNTER_INCR(TheSqlSrvProfilerFileSetSize);
  1724     __COUNTER_INCR(TheSqlSrvProfilerFileSetSize);
  1731 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileTruncate], ::OsCallProfile(dbFile.iIsJournal, EOsFileTruncate), aLength, 0, aDbFile, 0);
  1725 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileTruncate], ::OsCallProfile(dbFile.iIsJournal, EOsFileTruncate), aLength, 0, aDbFile, 0);
  1732 	if(dbFile.iReadOnly)
  1726 	if(dbFile.iReadOnly)
  1733 		{
  1727 		{
  1735   		return SQLITE_IOERR;	
  1729   		return SQLITE_IOERR;	
  1736 		}
  1730 		}
  1737 	__FS_CALL(EFsOpFileSetSize, 0);
  1731 	__FS_CALL(EFsOpFileSetSize, 0);
  1738 	TInt err = dbFile.iFileBuf.SetSize(aLength);
  1732 	TInt err = dbFile.iFileBuf.SetSize(aLength);
  1739 	COsLayerData::Instance().SetOsErrorCode(err);
  1733 	COsLayerData::Instance().SetOsErrorCode(err);
  1740 	TInt sqliteErr = ::Os2SqliteErr(err, SQLITE_IOERR);
  1734 	return err == KErrNone ? SQLITE_OK : (err == KErrNoMemory ? SQLITE_IOERR_NOMEM : SQLITE_IOERR);
  1741 	SQLITE_TRACE_OS(OstTraceExt3(TRACE_INTERNALS, TFILEIO_TRUNCATE_EXIT, "OS-Exit;0x%X;TFileIo::Truncate;err=%d;sqliteErr=%d", (TUint)&dbFile, err, sqliteErr));
       
  1742 	return sqliteErr;
       
  1743 	}
  1735 	}
  1744 
  1736 
  1745 /**
  1737 /**
  1746 SQLite OS porting layer API.
  1738 SQLite OS porting layer API.
  1747 
  1739 
  1760 @see COsLayerData::SetOsErrorCode()
  1752 @see COsLayerData::SetOsErrorCode()
  1761 @see TDbFile
  1753 @see TDbFile
  1762 */
  1754 */
  1763 /* static */int TFileIo::Sync(sqlite3_file* aDbFile, int /* aFlags */)
  1755 /* static */int TFileIo::Sync(sqlite3_file* aDbFile, int /* aFlags */)
  1764 	{
  1756 	{
       
  1757 	SQLUTRACE_PROFILER(aDbFile);
  1765 	TDbFile& dbFile = ::DbFile(aDbFile);
  1758 	TDbFile& dbFile = ::DbFile(aDbFile);
  1766 	SQLITE_TRACE_OS(OstTrace1(TRACE_INTERNALS, TFILEIO_SYNC_ENTRY, "OS-Entry;0x%X;TFileIo::Sync", (TUint)&dbFile));
       
  1767 	__OS_CALL(EOsFileSync, 0, 0);
  1759 	__OS_CALL(EOsFileSync, 0, 0);
  1768     __COUNTER_INCR(TheSqlSrvProfilerFileSync);
  1760     __COUNTER_INCR(TheSqlSrvProfilerFileSync);
  1769 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileSync], ::OsCallProfile(dbFile.iIsJournal, EOsFileSync), 0, 0, aDbFile, 0);
  1761 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileSync], ::OsCallProfile(dbFile.iIsJournal, EOsFileSync), 0, 0, aDbFile, 0);
  1770 	if(dbFile.iReadOnly)
  1762 	if(dbFile.iReadOnly)
  1771 		{
  1763 		{
  1773 		return SQLITE_IOERR;
  1765 		return SQLITE_IOERR;
  1774 		}
  1766 		}
  1775 	__FS_CALL(EFsOpFileSync, 0);
  1767 	__FS_CALL(EFsOpFileSync, 0);
  1776 	TInt err = dbFile.iFileBuf.Flush();
  1768 	TInt err = dbFile.iFileBuf.Flush();
  1777 	COsLayerData::Instance().SetOsErrorCode(err);
  1769 	COsLayerData::Instance().SetOsErrorCode(err);
  1778 	TInt sqliteErr = ::Os2SqliteErr(err, SQLITE_IOERR);
  1770 	return err == KErrNone ? SQLITE_OK : (err == KErrNoMemory ? SQLITE_IOERR_NOMEM : SQLITE_IOERR);
  1779 	SQLITE_TRACE_OS(OstTraceExt3(TRACE_INTERNALS, TFILEIO_SYNC_EXIT, "OS-Exit;0x%X;TFileIo::Sync;err=%d;sqliteErr=%d", (TUint)&dbFile, err, sqliteErr));
       
  1780 	return sqliteErr;
       
  1781 	}
  1771 	}
  1782 
  1772 
  1783 /**
  1773 /**
  1784 SQLite OS porting layer API.
  1774 SQLite OS porting layer API.
  1785 
  1775 
  1798 @see COsLayerData::SetOsErrorCode()
  1788 @see COsLayerData::SetOsErrorCode()
  1799 @see TDbFile
  1789 @see TDbFile
  1800 */
  1790 */
  1801 /* static */ int TFileIo::FileSize(sqlite3_file* aDbFile, sqlite3_int64* aSize)
  1791 /* static */ int TFileIo::FileSize(sqlite3_file* aDbFile, sqlite3_int64* aSize)
  1802 	{
  1792 	{
       
  1793 	SQLUTRACE_PROFILER(aDbFile);
  1803 	TDbFile& dbFile = ::DbFile(aDbFile);
  1794 	TDbFile& dbFile = ::DbFile(aDbFile);
  1804 	SQLITE_TRACE_OS(OstTrace1(TRACE_INTERNALS, TFILEIO_FILESIZE_ENTRY, "OS-Entry;0x%X;TFileIo::FileSize", (TUint)&dbFile));
       
  1805 	__OS_CALL(EOsFileFileSize, 0, 0);
  1795 	__OS_CALL(EOsFileFileSize, 0, 0);
  1806 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileFileSize], ::OsCallProfile(dbFile.iIsJournal, EOsFileFileSize), 0, 0, aDbFile, 0);
  1796 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileFileSize], ::OsCallProfile(dbFile.iIsJournal, EOsFileFileSize), 0, 0, aDbFile, 0);
  1807 	__FS_CALL(EFsOpFileSize, 0);
  1797 	__FS_CALL(EFsOpFileSize, 0);
  1808 	TInt err =  dbFile.iFileBuf.Size(*aSize);
  1798 	TInt err =  dbFile.iFileBuf.Size(*aSize);
  1809 	COsLayerData::Instance().SetOsErrorCode(err);
  1799 	COsLayerData::Instance().SetOsErrorCode(err);
  1810 	TInt sqliteErr = ::Os2SqliteErr(err, SQLITE_IOERR);
  1800 	if(err == KErrNone)
  1811 	SQLITE_TRACE_OS(OstTraceExt3(TRACE_INTERNALS, TFILEIO_FILESIZE_EXIT, "OS-Exit;0x%X;TFileIo::FileSize;err=%d;sqliteErr=%d", (TUint)&dbFile, err, sqliteErr));
  1801 		{
  1812 	return sqliteErr;
  1802 		return SQLITE_OK;
       
  1803 		}
       
  1804 	return err == KErrNoMemory ? SQLITE_IOERR_NOMEM : SQLITE_IOERR;
  1813 	}
  1805 	}
  1814 
  1806 
  1815 /**
  1807 /**
  1816 SQLite OS porting layer API.
  1808 SQLite OS porting layer API.
  1817 
  1809 
  1830 	    
  1822 	    
  1831 @see TDbFile
  1823 @see TDbFile
  1832 */
  1824 */
  1833 /* static */ int TFileIo::Lock(sqlite3_file* aDbFile, int aLockType)
  1825 /* static */ int TFileIo::Lock(sqlite3_file* aDbFile, int aLockType)
  1834 	{
  1826 	{
       
  1827 	SQLUTRACE_PROFILER(aDbFile);
  1835 	TDbFile& dbFile = ::DbFile(aDbFile);
  1828 	TDbFile& dbFile = ::DbFile(aDbFile);
  1836 	__OS_CALL(EOsFileLock, 0, 0);
  1829 	__OS_CALL(EOsFileLock, 0, 0);
  1837 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileLock], ::OsCallProfile(dbFile.iIsJournal, EOsFileLock), aLockType, 0, aDbFile, 0);
  1830 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileLock], ::OsCallProfile(dbFile.iIsJournal, EOsFileLock), aLockType, 0, aDbFile, 0);
  1838 	//If there is already a lock of this type or more restrictive on the database file, do nothing.
  1831 	//If there is already a lock of this type or more restrictive on the database file, do nothing.
  1839 	if(dbFile.iLockType >= aLockType)
  1832 	if(dbFile.iLockType >= aLockType)
  1862 	    
  1855 	    
  1863 @see TDbFile
  1856 @see TDbFile
  1864 */
  1857 */
  1865 /* static */ int TFileIo::Unlock(sqlite3_file* aDbFile, int aLockType)
  1858 /* static */ int TFileIo::Unlock(sqlite3_file* aDbFile, int aLockType)
  1866 	{
  1859 	{
       
  1860 	SQLUTRACE_PROFILER(aDbFile);
  1867 	TDbFile& dbFile = ::DbFile(aDbFile);
  1861 	TDbFile& dbFile = ::DbFile(aDbFile);
  1868 	__OS_CALL(EOsFileUnlock, 0, 0);
  1862 	__OS_CALL(EOsFileUnlock, 0, 0);
  1869 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileUnlock], ::OsCallProfile(dbFile.iIsJournal, EOsFileUnlock), aLockType, 0, aDbFile, 0);
  1863 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileUnlock], ::OsCallProfile(dbFile.iIsJournal, EOsFileUnlock), aLockType, 0, aDbFile, 0);
  1870 	dbFile.iLockType = aLockType;
  1864 	dbFile.iLockType = aLockType;
  1871 	return SQLITE_OK;
  1865 	return SQLITE_OK;
  1890 	    
  1884 	    
  1891 @see TDbFile
  1885 @see TDbFile
  1892 */
  1886 */
  1893 /* static */ int TFileIo::CheckReservedLock(sqlite3_file* aDbFile, int *aResOut)
  1887 /* static */ int TFileIo::CheckReservedLock(sqlite3_file* aDbFile, int *aResOut)
  1894 	{
  1888 	{
       
  1889 	SQLUTRACE_PROFILER(aDbFile);
  1895 	TDbFile& dbFile = ::DbFile(aDbFile);
  1890 	TDbFile& dbFile = ::DbFile(aDbFile);
  1896 	__OS_CALL(EOsFileCheckReservedLock, 0, 0);
  1891 	__OS_CALL(EOsFileCheckReservedLock, 0, 0);
  1897 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileCheckReservedLock], ::OsCallProfile(dbFile.iIsJournal, EOsFileCheckReservedLock), 0, 0, aDbFile, 0);
  1892 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileCheckReservedLock], ::OsCallProfile(dbFile.iIsJournal, EOsFileCheckReservedLock), 0, 0, aDbFile, 0);
  1898 	*aResOut = dbFile.iLockType >= SQLITE_LOCK_RESERVED ? 1 : 0;
  1893 	*aResOut = dbFile.iLockType >= SQLITE_LOCK_RESERVED ? 1 : 0;
  1899   	return SQLITE_OK;
  1894   	return SQLITE_OK;
  1924 	    
  1919 	    
  1925 @see TDbFile
  1920 @see TDbFile
  1926 */
  1921 */
  1927 /* static */ int TFileIo::FileControl(sqlite3_file* aDbFile, int aOp, void* aArg)
  1922 /* static */ int TFileIo::FileControl(sqlite3_file* aDbFile, int aOp, void* aArg)
  1928 	{
  1923 	{
       
  1924 	SQLUTRACE_PROFILER(aDbFile);
       
  1925 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KFileFileCtr, aOp));
  1929 	TDbFile& dbFile = ::DbFile(aDbFile);
  1926 	TDbFile& dbFile = ::DbFile(aDbFile);
  1930 	SQLITE_TRACE_OS(OstTraceExt2(TRACE_INTERNALS, TFILEIO_FILECONTROL_ENTRY, "OS-Entry;0x%X;TFileIo::FileControl;aOp=%d", (TUint)&dbFile, aOp));
       
  1931 	__OS_CALL(EOsFileFileControl, 0, 0);
  1927 	__OS_CALL(EOsFileFileControl, 0, 0);
  1932 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileFileControl], ::OsCallProfile(dbFile.iIsJournal, EOsFileFileControl), aOp, 0, aDbFile, 0);
  1928 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileFileControl], ::OsCallProfile(dbFile.iIsJournal, EOsFileFileControl), aOp, 0, aDbFile, 0);
  1933 	TInt err = KErrNone;
  1929 	TInt err = KErrNone;
  1934 	switch(aOp)
  1930 	switch(aOp)
  1935 		{
  1931 		{
  1953 		default:
  1949 		default:
  1954 			err = KErrArgument;
  1950 			err = KErrArgument;
  1955 			break;
  1951 			break;
  1956 		}
  1952 		}
  1957 	COsLayerData::Instance().SetOsErrorCode(err);
  1953 	COsLayerData::Instance().SetOsErrorCode(err);
  1958 	TInt sqliteErr = ::Os2SqliteErr(err, SQLITE_ERROR);
  1954 	return err == KErrNone ? SQLITE_OK : SQLITE_ERROR;
  1959 	SQLITE_TRACE_OS(OstTraceExt3(TRACE_INTERNALS, TFILEIO_FILECONTROL_EXIT, "OS-Exit;0x%X;TFileIo::FileControl;err=%d;sqliteErr=%d", (TUint)&dbFile, err, sqliteErr));
       
  1960 	return sqliteErr;
       
  1961 	}
  1955 	}
  1962 
  1956 
  1963 /**
  1957 /**
  1964 SQLite OS porting layer API.
  1958 SQLite OS porting layer API.
  1965 
  1959 
  1977 @see TDbFile
  1971 @see TDbFile
  1978 @see TVfs::Open()
  1972 @see TVfs::Open()
  1979 */
  1973 */
  1980 /* static */ int TFileIo::SectorSize(sqlite3_file* aDbFile)
  1974 /* static */ int TFileIo::SectorSize(sqlite3_file* aDbFile)
  1981 	{
  1975 	{
       
  1976 	SQLUTRACE_PROFILER(aDbFile);
  1982 	TDbFile& dbFile = ::DbFile(aDbFile);
  1977 	TDbFile& dbFile = ::DbFile(aDbFile);
  1983 	__OS_CALL(EOsFileSectorSize, 0, 0);
  1978 	__OS_CALL(EOsFileSectorSize, 0, 0);
  1984 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileSectorSize], ::OsCallProfile(dbFile.iIsJournal, EOsFileSectorSize), 0, 0, aDbFile, 0);
  1979 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileSectorSize], ::OsCallProfile(dbFile.iIsJournal, EOsFileSectorSize), 0, 0, aDbFile, 0);
  1985 	__ASSERT_DEBUG(dbFile.iSectorSize > 0, __SQLITEPANIC2(ESqliteOsPanicInternalError));
  1980 	__ASSERT_DEBUG(dbFile.iSectorSize > 0, User::Panic(KPanicCategory, EPanicInternalError));
  1986 	if(dbFile.iSectorSize > 0)
  1981 	if(dbFile.iSectorSize > 0)
  1987 		{
  1982 		{
  1988 		return dbFile.iSectorSize;	
  1983 		return dbFile.iSectorSize;	
  1989 		}
  1984 		}
  1990 	return SQLITE_DEFAULT_SECTOR_SIZE;
  1985 	return SQLITE_DEFAULT_SECTOR_SIZE;
  2007 @see TDbFile
  2002 @see TDbFile
  2008 @see TVfs::Open()
  2003 @see TVfs::Open()
  2009 */
  2004 */
  2010 /* static */ int TFileIo::DeviceCharacteristics(sqlite3_file* aDbFile)
  2005 /* static */ int TFileIo::DeviceCharacteristics(sqlite3_file* aDbFile)
  2011 	{
  2006 	{
       
  2007 	SQLUTRACE_PROFILER(aDbFile);
  2012 	TDbFile& dbFile = ::DbFile(aDbFile);
  2008 	TDbFile& dbFile = ::DbFile(aDbFile);
  2013 	__OS_CALL(EOsFileDeviceCharacteristics, 0, 0);
  2009 	__OS_CALL(EOsFileDeviceCharacteristics, 0, 0);
  2014 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileDeviceCharacteristics], ::OsCallProfile(dbFile.iIsJournal, EOsFileDeviceCharacteristics), 0, 0, aDbFile, 0);
  2010 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileDeviceCharacteristics], ::OsCallProfile(dbFile.iIsJournal, EOsFileDeviceCharacteristics), 0, 0, aDbFile, 0);
  2015 	__ASSERT_DEBUG(dbFile.iDeviceCharacteristics >= 0, __SQLITEPANIC2(ESqliteOsPanicInternalError));
  2011 	__ASSERT_DEBUG(dbFile.iDeviceCharacteristics >= 0, User::Panic(KPanicCategory, EPanicInternalError));
  2016 	if(dbFile.iDeviceCharacteristics >= 0)
  2012 	if(dbFile.iDeviceCharacteristics >= 0)
  2017 		{
  2013 		{
  2018 		return dbFile.iDeviceCharacteristics;	
  2014 		return dbFile.iDeviceCharacteristics;	
  2019 		}
  2015 		}
  2020 	return 0;
  2016 	return 0;
  2067 @see TVfs::Open()
  2063 @see TVfs::Open()
  2068 */
  2064 */
  2069 /* static */ inline TInt TVfs::DoGetVolumeIoParamInfo(RFs& aFs, TInt aDriveNo, TVolumeIOParamInfo& aVolumeInfo)
  2065 /* static */ inline TInt TVfs::DoGetVolumeIoParamInfo(RFs& aFs, TInt aDriveNo, TVolumeIOParamInfo& aVolumeInfo)
  2070 	{
  2066 	{
  2071 	__FS_CALL(EFsOpFsVolumeIoParam, 0);
  2067 	__FS_CALL(EFsOpFsVolumeIoParam, 0);
  2072 	TInt err = aFs.VolumeIOParam(aDriveNo, aVolumeInfo); 
  2068 	return aFs.VolumeIOParam(aDriveNo, aVolumeInfo);
  2073 	SQLITE_TRACE_OS(OstTraceExt2(TRACE_INTERNALS, TVFS_DOGETVOLUMEIOPARAMINFO, "OS;0;TVfs::DoGetVolumeIoParamInfo;aDriveNo=%d;err=%d", aDriveNo, err));
       
  2074 	return err;		
       
  2075 	}
  2069 	}
  2076 
  2070 
  2077 /**
  2071 /**
  2078 Retrieves and returns in a bit set the device characteristics.
  2072 Retrieves and returns in a bit set the device characteristics.
  2079 
  2073 
  2157 		if(aVolumeInfo.iBlockSize > SQLITE_DEFAULT_SECTOR_SIZE && (aVolumeInfo.iBlockSize & (aVolumeInfo.iBlockSize - 1)) == 0)
  2151 		if(aVolumeInfo.iBlockSize > SQLITE_DEFAULT_SECTOR_SIZE && (aVolumeInfo.iBlockSize & (aVolumeInfo.iBlockSize - 1)) == 0)
  2158 			{
  2152 			{
  2159 			sectorSize = aVolumeInfo.iBlockSize;
  2153 			sectorSize = aVolumeInfo.iBlockSize;
  2160 			}
  2154 			}
  2161 		}
  2155 		}
  2162 	__ASSERT_DEBUG(sectorSize > 0 && (sectorSize & (sectorSize - 1)) == 0, __SQLITEPANIC2(ESqliteOsPanicInternalError));
  2156 	__ASSERT_DEBUG(sectorSize > 0 && (sectorSize & (sectorSize - 1)) == 0, User::Panic(KPanicCategory, EPanicInternalError));
  2163 	return sectorSize;
  2157 	return sectorSize;
  2164 	}
  2158 	}
  2165 
  2159 
  2166 /**
  2160 /**
  2167 Retrieves in a bit set the device characteristics of the device of the file referred by the aDbFile parameter.
  2161 Retrieves in a bit set the device characteristics of the device of the file referred by the aDbFile parameter.
  2186 @see TFileIo::DeviceCharacteristics()
  2180 @see TFileIo::DeviceCharacteristics()
  2187 @see TFileIo::SectorSize()
  2181 @see TFileIo::SectorSize()
  2188 */
  2182 */
  2189 /* static */ TInt TVfs::DoGetDeviceCharacteristicsAndSectorSize(TDbFile& aDbFile, TInt& aRecReadBufSize)
  2183 /* static */ TInt TVfs::DoGetDeviceCharacteristicsAndSectorSize(TDbFile& aDbFile, TInt& aRecReadBufSize)
  2190 	{
  2184 	{
  2191 	__ASSERT_DEBUG(aDbFile.iDeviceCharacteristics < 0, __SQLITEPANIC2(ESqliteOsPanicInternalError));
  2185 	__ASSERT_DEBUG(aDbFile.iDeviceCharacteristics < 0, User::Panic(KPanicCategory, EPanicInternalError));
  2192 	__ASSERT_DEBUG(aDbFile.iSectorSize <= 0, __SQLITEPANIC2(ESqliteOsPanicInternalError));
  2186 	__ASSERT_DEBUG(aDbFile.iSectorSize <= 0, User::Panic(KPanicCategory, EPanicInternalError));
  2193 	TInt driveNo;
  2187 	TInt driveNo;
  2194 	TDriveInfo driveInfo;
  2188 	TDriveInfo driveInfo;
  2195 	__FS_CALL(EFsOpFileDrive, 0);
  2189 	__FS_CALL(EFsOpFileDrive, 0);
  2196 	TInt err = aDbFile.iFileBuf.Drive(driveNo, driveInfo);
  2190 	TInt err = aDbFile.iFileBuf.Drive(driveNo, driveInfo);
  2197 	if(err != KErrNone)
  2191 	if(err != KErrNone)
  2205 		return err;	
  2199 		return err;	
  2206 		}
  2200 		}
  2207 	aDbFile.iDeviceCharacteristics = TVfs::DoGetDeviceCharacteristics(driveInfo, volumeInfo);
  2201 	aDbFile.iDeviceCharacteristics = TVfs::DoGetDeviceCharacteristics(driveInfo, volumeInfo);
  2208 	aDbFile.iSectorSize = TVfs::DoGetSectorSize(driveInfo, volumeInfo);
  2202 	aDbFile.iSectorSize = TVfs::DoGetSectorSize(driveInfo, volumeInfo);
  2209 	aRecReadBufSize = volumeInfo.iRecReadBufSize;
  2203 	aRecReadBufSize = volumeInfo.iRecReadBufSize;
  2210 	SQLITE_TRACE_OS(OstTraceExt5(TRACE_INTERNALS, TVFS_DOGETGETDEVICECHARACTERISTICSANDSECTORSIZE, "OS;0x%X;TVfs::DoGetDeviceCharacteristicsAndSectorSize;driveNo=%d;sectorSize=%d;devCharact=0x%X;readBufSize=%d", (TUint)&aDbFile, driveNo, aDbFile.iSectorSize, (TUint)aDbFile.iDeviceCharacteristics, volumeInfo.iRecReadBufSize));
       
  2211 	return KErrNone;
  2204 	return KErrNone;
  2212 	}
  2205 	}
  2213 
  2206 
  2214 /**
  2207 /**
  2215 SQLite OS porting layer API.
  2208 SQLite OS porting layer API.
  2261     if (err == KErrCorrupt || err == KErrEof || !IsMinFileSize)
  2254     if (err == KErrCorrupt || err == KErrEof || !IsMinFileSize)
  2262         {
  2255         {
  2263         COsLayerData& osLayerData = COsLayerData::Instance();
  2256         COsLayerData& osLayerData = COsLayerData::Instance();
  2264     
  2257     
  2265         aDbFile.iFileBuf.Close();
  2258         aDbFile.iFileBuf.Close();
  2266         __SQLITETRACE_OSEXPR(TInt err2 =) osLayerData.iFs.Delete(aFname);
  2259         (void) osLayerData.iFs.Delete(aFname);
  2267 		SQLITE_TRACE_OS(OstTraceExt4(TRACE_INTERNALS, TVFS_DOFILESIZECORRUPTIONCHECK1, "OS;0x%X;TVfs::DoFileSizeCorruptionCheck;size=%lld;err=%d;deleteErr=%d", (TUint)&aDbFile, size, err, err2));
       
  2268         err = aDbFile.iFileBuf.Create(osLayerData.iFs, aFname, aFmode);
  2260         err = aDbFile.iFileBuf.Create(osLayerData.iFs, aFname, aFmode);
  2269 		SQLITE_TRACE_OS(OstTraceExt2(TRACE_INTERNALS, TVFS_DOFILESIZECORRUPTIONCHECK2, "OS;0x%X;TVfs::DoFileSizeCorruptionCheck;createErr=%d", (TUint)&aDbFile, err));
       
  2270         }
  2261         }
  2271     return err;
  2262     return err;
  2272     }
  2263     }
  2273 
  2264 
  2274 /**
  2265 /**
  2302 
  2293 
  2303 @see COsLayerData::SetOsErrorCode()
  2294 @see COsLayerData::SetOsErrorCode()
  2304 @see TDbFile
  2295 @see TDbFile
  2305 */
  2296 */
  2306 /* static */ int TVfs::Open(sqlite3_vfs* aVfs, const char* aFileName, sqlite3_file* aDbFile, int aFlags, int* aOutFlags)
  2297 /* static */ int TVfs::Open(sqlite3_vfs* aVfs, const char* aFileName, sqlite3_file* aDbFile, int aFlags, int* aOutFlags)
  2307 	{
  2298 	{   
  2308 	__OS_CALL(EOsVfsOpen, 0, 0);
  2299     SQLUTRACE_PROFILER(aVfs);
  2309 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsOpen], ::OsCallProfile(EFalse, EOsVfsOpen), 0, 0, aDbFile, aFileName);
  2300     __OS_CALL(EOsVfsOpen, 0, 0);
  2310 	COsLayerData& osLayerData = COsLayerData::Instance();
  2301     __OSTIME_COUNTER(TheOsCallTicks[EOsVfsOpen], ::OsCallProfile(EFalse, EOsVfsOpen), 0, 0, aDbFile, aFileName);
  2311 	new (aDbFile) TDbFile;
  2302  
  2312 	TDbFile& dbFile = ::DbFile(aDbFile);
  2303     COsLayerData& osLayerData = COsLayerData::Instance();
       
  2304     TFhStrType fhStrType = ENotFhStr;
       
  2305     new (aDbFile) TDbFile;
       
  2306     TDbFile& dbFile = ::DbFile(aDbFile);
       
  2307 
  2313     if(!aFileName)
  2308     if(!aFileName)
  2314         {  
  2309         {  
  2315         //It is to create and open a temp file if aFileName is NULL. In this case,
  2310         //It is to create and open a temp file if aFileName is NULL. In this case,
  2316         //we will defer the file creation util it is needed.  
  2311         //we will defer the file creation util it is needed.  
       
  2312     
  2317         dbFile.pMethods = &TheFileIoApi;
  2313         dbFile.pMethods = &TheFileIoApi;
  2318         dbFile.iIsFileCreated = EFalse;
  2314         dbFile.iIsFileCreated = EFalse;
  2319         if(aOutFlags)
  2315         if(aOutFlags)
  2320             {
  2316             {
  2321             *aOutFlags = SQLITE_OPEN_READWRITE;
  2317             *aOutFlags = SQLITE_OPEN_READWRITE;
  2322             }
  2318             }
  2323 		osLayerData.SetOsErrorCode(KErrNone);
       
  2324         return SQLITE_OK;
  2319         return SQLITE_OK;
  2325         }  
  2320         }  
  2326 	TFileName fname;
  2321     
       
  2322     TFileName fname;
  2327     if(!::ConvertToUnicode(aFileName, fname))
  2323     if(!::ConvertToUnicode(aFileName, fname))
  2328 		{
  2324         {
  2329         osLayerData.SetOsErrorCode(KErrBadName);
  2325         osLayerData.SetOsErrorCode(KErrBadName);
  2330         return SQLITE_CANTOPEN;	
  2326         return SQLITE_CANTOPEN;	
  2331     	}
  2327         }
  2332 	SQLITE_TRACE_OS(OstTraceExt3(TRACE_INTERNALS, TVFS_OPEN_ENTRY, "OS-Entry;0x%X;TVfs::Open;fname=%S;aFlags=0x%X", (TUint)&aDbFile, __SQLITEPRNSTR(fname), (TUint)aFlags));
  2328     SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KFileOpen, aDbFile, &fname));
  2333 	TFhStrType fhStrType = aFileName ? ::FhStringProps(aFileName) : ENotFhStr;
  2329     fhStrType = ::FhStringProps(aFileName);
  2334 	TInt err = KErrNone;
  2330     TInt err = KErrNone;
  2335 	if(fhStrType == EFhMainDbStr)
  2331     TInt recReadBufSize = -1;
  2336 		{//Main db file, open from handle
  2332     if(fhStrType == EFhMainDbStr)
  2337 		const RMessage2* msg;
  2333         {//Main db file, open from handle
  2338 		TBool readOnly;
  2334         const RMessage2* msg;
  2339 		osLayerData.RetrieveAndResetFhData(msg, readOnly);
  2335         TBool readOnly;
  2340 		err = msg != NULL ? TVfs::DoOpenFromHandle(dbFile, *msg, readOnly) : KErrGeneral;
  2336         osLayerData.RetrieveAndResetFhData(msg, readOnly);
  2341 		}
  2337         err = msg != NULL ? TVfs::DoOpenFromHandle(dbFile, *msg, readOnly) : KErrGeneral;
  2342 	else
  2338         }
  2343 		{
  2339     else
  2344 		if(fhStrType == EFhStr)
  2340         {
  2345 			{//Not the main db file. Remove invalid characters in the file name
  2341         if(fhStrType == EFhStr)
  2346 			::FhConvertToFileName(fname, osLayerData.iSysPrivDir);//If fname does not have a path, iSysPrivDir will be used
  2342             {//Not the main db file. Remove invalid characters in the file name
  2347 			}
  2343             ::FhConvertToFileName(fname, osLayerData.iSysPrivDir);//If fname does not have a path, iSysPrivDir will be used
  2348 		TInt fmode = EFileRead;
  2344             }
  2349 		if(aFlags & SQLITE_OPEN_READWRITE)
  2345         TInt fmode = EFileRead;
  2350 			{
  2346         if(aFlags & SQLITE_OPEN_READWRITE)
  2351 			fmode |= EFileWrite;
  2347             {
  2352 			}
  2348             fmode |= EFileWrite;
  2353 		if(aFlags & SQLITE_OPEN_EXCLUSIVE)
  2349             }
  2354 			{
  2350         if(aFlags & SQLITE_OPEN_EXCLUSIVE)
  2355 			fmode |= EFileShareExclusive;
  2351             {
  2356 			}
  2352             fmode |= EFileShareExclusive;
  2357 		if(aFlags & SQLITE_OPEN_DELETEONCLOSE)
  2353             }
  2358 			{
  2354             err = KErrAccessDenied;
  2359 			fmode |= EDeleteOnClose;
  2355             TInt prevErr = KErrNone;
  2360 			}
  2356             if(aFlags & SQLITE_OPEN_DELETEONCLOSE)
  2361 		err = KErrAccessDenied;
  2357                 {
  2362 		TInt prevErr = KErrNone;
  2358                 fmode |= EDeleteOnClose;
  2363 		if(aFlags & SQLITE_OPEN_CREATE)
  2359                 }
  2364 			{
  2360             if(aFlags & SQLITE_OPEN_CREATE)
  2365 			__FS_CALL(EFsOpFileCreate, 0);
  2361                 {
  2366 			prevErr = err = dbFile.iFileBuf.Create(osLayerData.iFs, fname, fmode);
  2362                 __FS_CALL(EFsOpFileCreate, 0);
  2367 			}
  2363                 prevErr = err = dbFile.iFileBuf.Create(osLayerData.iFs, fname, fmode);
  2368 		if(err != KErrNone && err != KErrNoMemory && err != KErrDiskFull)
  2364                 }
  2369 			{
  2365             if(err != KErrNone && err != KErrNoMemory && err != KErrDiskFull)
  2370 			__FS_CALL(EFsOpFileOpen, 0);
  2366                 {
  2371 			err = dbFile.iFileBuf.Open(osLayerData.iFs, fname, fmode);
  2367                 __FS_CALL(EFsOpFileOpen, 0);
  2372 
  2368                 err = dbFile.iFileBuf.Open(osLayerData.iFs, fname, fmode);
  2373 			if(err == KErrNone && (aFlags & KJournalFileTypeBitMask))
  2369                 
  2374 				{
  2370                 if(err == KErrNone && (aFlags & KJournalFileTypeBitMask))
  2375 				err = TVfs::DoFileSizeCorruptionCheck(dbFile, fname, fmode);
  2371                     {
  2376 				}
  2372                     err = TVfs::DoFileSizeCorruptionCheck(dbFile, fname, fmode);
  2377 			}
  2373                     }
  2378 		if((err != KErrNone && err != KErrNoMemory && err != KErrDiskFull) && (aFlags & SQLITE_OPEN_READWRITE))
  2374                 }
  2379 			{
  2375             if((err != KErrNone && err != KErrNoMemory && err != KErrDiskFull) && (aFlags & SQLITE_OPEN_READWRITE))
  2380 			aFlags &= ~SQLITE_OPEN_READWRITE;
  2376                 {
  2381 			aFlags |= SQLITE_OPEN_READONLY;
  2377                 aFlags &= ~SQLITE_OPEN_READWRITE;
  2382 			fmode &= ~EFileWrite;
  2378                 aFlags |= SQLITE_OPEN_READONLY;
  2383 			__FS_CALL(EFsOpFileOpen, 0);
  2379                 fmode &= ~EFileWrite;
  2384 			err = dbFile.iFileBuf.Open(osLayerData.iFs, fname, fmode);
  2380                 __FS_CALL(EFsOpFileOpen, 0);
  2385 			}
  2381                 err = dbFile.iFileBuf.Open(osLayerData.iFs, fname, fmode);
  2386 		if(err != KErrNone && prevErr == KErrAccessDenied)
  2382                 }
  2387 			{
  2383             if(err != KErrNone && prevErr == KErrAccessDenied)
  2388 			err = KErrAccessDenied;
  2384                 {
  2389 			}
  2385                 err = KErrAccessDenied;
  2390 		}
  2386                 }
  2391 	TInt recReadBufSize = -1;
  2387         }
  2392 	if(err == KErrNone)
  2388     if(err == KErrNone)
  2393 		{
  2389         {
  2394 		err = TVfs::DoGetDeviceCharacteristicsAndSectorSize(dbFile, recReadBufSize);
  2390         err = TVfs::DoGetDeviceCharacteristicsAndSectorSize(dbFile, recReadBufSize);
  2395 		}
  2391         }	
       
  2392  	
  2396 	osLayerData.SetOsErrorCode(err);
  2393 	osLayerData.SetOsErrorCode(err);
  2397 	if(err != KErrNone)
  2394 	if(err != KErrNone)
  2398 		{
  2395 		{
  2399 		__FS_CALL(EFsOpFileClose, 0);
  2396 		__FS_CALL(EFsOpFileClose, 0);
  2400 		dbFile.iFileBuf.Close();	
  2397 		dbFile.iFileBuf.Close();	
  2413 		(void)dbFile.iFileBuf.SetReadAheadSize(dbFile.iSectorSize, recReadBufSize);
  2410 		(void)dbFile.iFileBuf.SetReadAheadSize(dbFile.iSectorSize, recReadBufSize);
  2414 		}
  2411 		}
  2415 #ifdef _SQLPROFILER
  2412 #ifdef _SQLPROFILER
  2416 	dbFile.iIsJournal = aFlags & KJournalFileTypeBitMask; 
  2413 	dbFile.iIsJournal = aFlags & KJournalFileTypeBitMask; 
  2417 #endif
  2414 #endif
  2418 	TInt sqliteErr = ::Os2SqliteErr(err, SQLITE_CANTOPEN);
  2415 	return err == KErrNone ? SQLITE_OK : (err == KErrNoMemory ? SQLITE_IOERR_NOMEM : SQLITE_CANTOPEN);
  2419 	SQLITE_TRACE_OS(OstTraceExt4(TRACE_INTERNALS, TVFS_OPEN_EXIT, "OS-Exit;0x%X;TVfs::Open;outFlags=0x%X;err=%d;sqliteErr=%d", (TUint)&aDbFile, aOutFlags ? (TUint)*aOutFlags : 0, err, sqliteErr));
       
  2420 	return sqliteErr;
       
  2421 	}
  2416 	}
  2422 
  2417 
  2423 /**
  2418 /**
  2424 SQLite OS porting layer API.
  2419 SQLite OS porting layer API.
  2425 
  2420 
  2438 
  2433 
  2439 @see COsLayerData::SetOsErrorCode()
  2434 @see COsLayerData::SetOsErrorCode()
  2440 */
  2435 */
  2441 /* static */ int TVfs::Delete(sqlite3_vfs* aVfs, const char* aFileName, int /*aSyncDir*/)
  2436 /* static */ int TVfs::Delete(sqlite3_vfs* aVfs, const char* aFileName, int /*aSyncDir*/)
  2442 	{
  2437 	{
       
  2438 	SQLUTRACE_PROFILER(aVfs);
  2443 	__OS_CALL(EOsVfsDelete, 0, 0);
  2439 	__OS_CALL(EOsVfsDelete, 0, 0);
  2444 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsDelete], ::OsCallProfile(EFalse, EOsVfsDelete), 0, 0, 0, aFileName);
  2440 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsDelete], ::OsCallProfile(EFalse, EOsVfsDelete), 0, 0, 0, aFileName);
  2445 	COsLayerData& osLayerData = COsLayerData::Instance();
  2441 	COsLayerData& osLayerData = COsLayerData::Instance();
  2446 	TBuf<KMaxFileName + 1> fname;
  2442 	TBuf<KMaxFileName + 1> fname;
  2447 	if(!::ConvertToUnicode(aFileName, fname))
  2443 	if(!::ConvertToUnicode(aFileName, fname))
  2448 		{
  2444 		{
  2449 		osLayerData.SetOsErrorCode(KErrBadName);
  2445 		osLayerData.SetOsErrorCode(KErrBadName);
  2450 		SQLITE_TRACE_OS(OstTrace0(TRACE_INTERNALS, TVFS_DELETE1, "OS;0;TVfs::Delete;err=KErrBadName"));
       
  2451 		return SQLITE_ERROR;	
  2446 		return SQLITE_ERROR;	
  2452 		}
  2447 		}
  2453 	SQLITE_TRACE_OS(OstTraceExt1(TRACE_INTERNALS, TVFS_DELETE_ENTRY, "OS-Entry;0;TVfs::Delete;fname=%S", __SQLITEPRNSTR(fname)));
  2448 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KFileName, &fname));
  2454 	TFhStrType fhStrType = FhStringProps(aFileName);
  2449 	TFhStrType fhStrType = FhStringProps(aFileName);
  2455 	if(fhStrType == EFhMainDbStr)
  2450 	if(fhStrType == EFhMainDbStr)
  2456 		{//Deleting files not in your own private data cage - not allowed!
  2451 		{//Deleting files not in your own private data cage - not allowed!
  2457 		osLayerData.SetOsErrorCode(KErrPermissionDenied);
  2452 		osLayerData.SetOsErrorCode(KErrPermissionDenied);
  2458 		SQLITE_TRACE_OS(OstTraceExt1(TRACE_INTERNALS, TVFS_DELETE2, "OS;0;TVfs::Delete;err=KErrPermissionDenied;fname=%S", __SQLITEPRNSTR(fname)));
       
  2459 		return SQLITE_ERROR;	
  2453 		return SQLITE_ERROR;	
  2460 		}
  2454 		}
  2461 	if(fhStrType == EFhStr)
  2455 	if(fhStrType == EFhStr)
  2462 		{
  2456 		{
  2463 		::FhConvertToFileName(fname, osLayerData.iSysPrivDir);//If fname does not have a path, iSysPrivDir will be used
  2457 		::FhConvertToFileName(fname, osLayerData.iSysPrivDir);//If fname does not have a path, iSysPrivDir will be used
  2464 		}
  2458 		}
  2465 	__FS_CALL(EFsOpFileDelete, 0);
  2459 	__FS_CALL(EFsOpFileDelete, 0);
  2466 	TInt err = osLayerData.iFs.Delete(fname);
  2460 	TInt err = osLayerData.iFs.Delete(fname);
  2467 	osLayerData.SetOsErrorCode(err);
  2461 	osLayerData.SetOsErrorCode(err);
  2468 	TInt sqliteErr = ::Os2SqliteErr(err, SQLITE_IOERR_DELETE);	
  2462 	return err == KErrNone ? SQLITE_OK : (err == KErrNoMemory ? SQLITE_IOERR_NOMEM : SQLITE_IOERR_DELETE);
  2469 	SQLITE_TRACE_OS(OstTraceExt2(TRACE_INTERNALS, TVFS_DELETE_EXIT, "OS-Exit;0;TVfs::Delete;err=%d;sqliteErr=%d", err, sqliteErr));
       
  2470 	return sqliteErr;
       
  2471 	}
  2463 	}
  2472 
  2464 
  2473 /**
  2465 /**
  2474 SQLite OS porting layer API.
  2466 SQLite OS porting layer API.
  2475 
  2467 
  2489 
  2481 
  2490 @see COsLayerData::SetOsErrorCode()
  2482 @see COsLayerData::SetOsErrorCode()
  2491 */
  2483 */
  2492 /* static */ int TVfs::Access(sqlite3_vfs* aVfs, const char* aFileName, int aFlags, int* aResOut)
  2484 /* static */ int TVfs::Access(sqlite3_vfs* aVfs, const char* aFileName, int aFlags, int* aResOut)
  2493 	{
  2485 	{
       
  2486 	SQLUTRACE_PROFILER(aVfs);
  2494 	__OS_CALL(EOsVfsAccess, 0, 0);
  2487 	__OS_CALL(EOsVfsAccess, 0, 0);
  2495 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsAccess], ::OsCallProfile(EFalse, EOsVfsAccess), aFlags, 0, 0, aFileName);
  2488 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsAccess], ::OsCallProfile(EFalse, EOsVfsAccess), aFlags, 0, 0, aFileName);
  2496 	COsLayerData& osLayerData = COsLayerData::Instance();
  2489 	COsLayerData& osLayerData = COsLayerData::Instance();
  2497 	TBuf<KMaxFileName + 1> fname;
  2490 	TBuf<KMaxFileName + 1> fname;
  2498 	if(!::ConvertToUnicode(aFileName, fname))
  2491 	if(!::ConvertToUnicode(aFileName, fname))
  2499 		{
  2492 		{
  2500 		osLayerData.SetOsErrorCode(KErrGeneral);
  2493 		osLayerData.SetOsErrorCode(KErrGeneral);
  2501 		SQLITE_TRACE_OS(OstTrace0(TRACE_INTERNALS, TVFS_ACCESS1, "OS;0;TVfs::Access;err=KErrGeneral"));
       
  2502 		return SQLITE_IOERR_ACCESS;
  2494 		return SQLITE_IOERR_ACCESS;
  2503 		}
  2495 		}
  2504 	SQLITE_TRACE_OS(OstTraceExt2(TRACE_INTERNALS, TVFS_ACCESS_ENTRY, "OS-Entry;0;TVfs::Access;fname=%S;aFlags=0x%X", __SQLITEPRNSTR(fname), (TUint)aFlags));
  2496 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KFileName, &fname));
  2505 	TFhStrType fhStrType = ::FhStringProps(aFileName);
  2497 	TFhStrType fhStrType = ::FhStringProps(aFileName);
  2506 	if(fhStrType == EFhStr)
  2498 	if(fhStrType == EFhStr)
  2507 		{
  2499 		{
  2508 		::FhConvertToFileName(fname, osLayerData.iSysPrivDir);//If fname does not have a path, iSysPrivDir will be used
  2500 		::FhConvertToFileName(fname, osLayerData.iSysPrivDir);//If fname does not have a path, iSysPrivDir will be used
  2509 		}
  2501 		}
  2512 	TInt err = osLayerData.iFs.Entry(fname, entry);
  2504 	TInt err = osLayerData.iFs.Entry(fname, entry);
  2513 	if(aFlags == SQLITE_ACCESS_EXISTS && err == KErrNotFound)
  2505 	if(aFlags == SQLITE_ACCESS_EXISTS && err == KErrNotFound)
  2514 		{
  2506 		{
  2515 		osLayerData.SetOsErrorCode(KErrNone);
  2507 		osLayerData.SetOsErrorCode(KErrNone);
  2516 		*aResOut = 0;
  2508 		*aResOut = 0;
  2517 		SQLITE_TRACE_OS(OstTrace0(TRACE_INTERNALS, TVFS_ACCESS_EXIT1, "OS-Exit;0;TVfs::Access;Exists-NoFound"));
       
  2518 		return SQLITE_OK;
  2509 		return SQLITE_OK;
  2519 		}
  2510 		}
  2520 	if(err != KErrNone)
  2511 	if(err != KErrNone)
  2521 		{
  2512 		{
  2522 		osLayerData.SetOsErrorCode(err);
  2513 		osLayerData.SetOsErrorCode(err);
  2523 		SQLITE_TRACE_OS(OstTrace1(TRACE_INTERNALS, TVFS_ACCESS_EXIT2, "OS-Exit;0;TVfs::Access;err=%d", err));
       
  2524 		return err == KErrNoMemory ? SQLITE_IOERR_NOMEM : SQLITE_IOERR_ACCESS;
  2514 		return err == KErrNoMemory ? SQLITE_IOERR_NOMEM : SQLITE_IOERR_ACCESS;
  2525 		}
  2515 		}
  2526 	*aResOut = 0;
  2516 	*aResOut = 0;
  2527 	switch(aFlags)
  2517 	switch(aFlags)
  2528 		{
  2518 		{
  2537 			break;
  2527 			break;
  2538 		default:
  2528 		default:
  2539 			break;			
  2529 			break;			
  2540 		}
  2530 		}
  2541 	osLayerData.SetOsErrorCode(KErrNone);
  2531 	osLayerData.SetOsErrorCode(KErrNone);
  2542 	SQLITE_TRACE_OS(OstTrace1(TRACE_INTERNALS, TVFS_ACCESS_EXIT3, "OS-Exit;0;TVfs::Access;aResOut=%d", *aResOut));
       
  2543 	return SQLITE_OK;
  2532 	return SQLITE_OK;
  2544 	}
  2533 	}
  2545 
  2534 
  2546 /**
  2535 /**
  2547 SQLite OS porting layer API.
  2536 SQLite OS porting layer API.
  2569 @return SQLITE_ERROR, The aRelative parameter is NULL or cannot be converted to UTF16;
  2558 @return SQLITE_ERROR, The aRelative parameter is NULL or cannot be converted to UTF16;
  2570 		SQLITE_OK The operation has completed successfully.
  2559 		SQLITE_OK The operation has completed successfully.
  2571 */
  2560 */
  2572 /* static */ int TVfs::FullPathName(sqlite3_vfs* aVfs, const char* aRelative, int aBufLen, char* aBuf)
  2561 /* static */ int TVfs::FullPathName(sqlite3_vfs* aVfs, const char* aRelative, int aBufLen, char* aBuf)
  2573 	{
  2562 	{
       
  2563 	SQLUTRACE_PROFILER(aVfs);
  2574 	__OS_CALL(EOsVfsFullPathName, 0, 0);
  2564 	__OS_CALL(EOsVfsFullPathName, 0, 0);
  2575 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsFullPathName], ::OsCallProfile(EFalse, EOsVfsFullPathName), aBufLen, 0, 0, aRelative);
  2565 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsFullPathName], ::OsCallProfile(EFalse, EOsVfsFullPathName), aBufLen, 0, 0, aRelative);
  2576 	COsLayerData& osLayerData = COsLayerData::Instance();
  2566 	COsLayerData& osLayerData = COsLayerData::Instance();
  2577 	osLayerData.StoreFhData(NULL, EFalse);
  2567 	osLayerData.StoreFhData(NULL, EFalse);
  2578 	//Convert the received file name to UTF16
  2568 	//Convert the received file name to UTF16
  2579 	TBuf<KMaxFileName + 1> fname;
  2569 	TBuf<KMaxFileName + 1> fname;
  2580 	if(!::ConvertToUnicode(aRelative, fname))
  2570 	if(!::ConvertToUnicode(aRelative, fname))
  2581 		{
  2571 		{
  2582 		SQLITE_TRACE_OS(OstTrace0(TRACE_INTERNALS, TVFS_FULLPATHNAME1, "OS;0;TVfs::FullPathName;err=SQLITE_ERROR"));
       
  2583 		return SQLITE_ERROR;
  2572 		return SQLITE_ERROR;
  2584 		}
  2573 		}
  2585 	SQLITE_TRACE_OS(OstTraceExt2(TRACE_INTERNALS, TVFS_FULLPATHNAME_ENTRY, "OS-Entry;0;TVfs::FullPathName;fname=%S;aBufLen=%d", __SQLITEPRNSTR(fname), aBufLen));
  2574 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KFileName, &fname));
  2586 	//Zero-terminate the converted file name
  2575 	//Zero-terminate the converted file name
  2587 	fname.Append(TChar(0));
  2576 	fname.Append(TChar(0));
  2588 	TParse parse;
  2577 	TParse parse;
  2589 	TFhStrType strType = ::FhStringProps(aRelative);//Detect string type - it may not be a real file name
  2578 	TFhStrType strType = ::FhStringProps(aRelative);//Detect string type - it may not be a real file name
  2590 	if(strType == EFhMainDbStr)
  2579 	if(strType == EFhMainDbStr)
  2599 		}
  2588 		}
  2600 	TPtr8 dest8(reinterpret_cast <TUint8*> (aBuf), aBufLen);	
  2589 	TPtr8 dest8(reinterpret_cast <TUint8*> (aBuf), aBufLen);	
  2601 	if(!::ConvertFromUnicode(parse.FullName(), dest8))
  2590 	if(!::ConvertFromUnicode(parse.FullName(), dest8))
  2602 		{//Zero the stored fh data, because it has been initialized by the FhExtractAndStore(fname) call (couple of lines above)
  2591 		{//Zero the stored fh data, because it has been initialized by the FhExtractAndStore(fname) call (couple of lines above)
  2603 		osLayerData.StoreFhData(NULL, EFalse);
  2592 		osLayerData.StoreFhData(NULL, EFalse);
  2604 		SQLITE_TRACE_OS(OstTrace0(TRACE_INTERNALS, TVFS_FULLPATHNAME_EXIT1, "OS-Exit;0;TVfs::FullPathName;err=SQLITE_ERROR"));
       
  2605 		return SQLITE_ERROR;	
  2593 		return SQLITE_ERROR;	
  2606 		}
  2594 		}
  2607 	SQLITE_TRACE_OS(OstTrace0(TRACE_INTERNALS, TVFS_FULLPATHNAME_EXIT2, "OS-Exit;0;TVfs::FullPathName;err=SQLITE_OK"));
       
  2608 	return SQLITE_OK;
  2595 	return SQLITE_OK;
  2609 	}
  2596 	}
  2610 
  2597 
  2611 /**
  2598 /**
  2612 SQLite OS porting layer API.
  2599 SQLite OS porting layer API.
  2618 
  2605 
  2619 @return The length of the used part of the output buffer.
  2606 @return The length of the used part of the output buffer.
  2620 */
  2607 */
  2621 /* static */ int TVfs::Randomness(sqlite3_vfs* aVfs, int aBufLen, char* aBuf)
  2608 /* static */ int TVfs::Randomness(sqlite3_vfs* aVfs, int aBufLen, char* aBuf)
  2622 	{
  2609 	{
       
  2610 	SQLUTRACE_PROFILER(aVfs);
  2623 	__OS_CALL(EOsVfsRandomness, 0, 0);
  2611 	__OS_CALL(EOsVfsRandomness, 0, 0);
  2624 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsRandomness], ::OsCallProfile(EFalse, EOsVfsRandomness), aBufLen, 0, 0, 0);
  2612 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsRandomness], ::OsCallProfile(EFalse, EOsVfsRandomness), aBufLen, 0, 0, 0);
  2625 	COsLayerData& osLayerData = COsLayerData::Instance();
  2613 	COsLayerData& osLayerData = COsLayerData::Instance();
  2626 	const TInt KRandIterations = aBufLen / sizeof(int);
  2614 	const TInt KRandIterations = aBufLen / sizeof(int);
  2627 	for(TInt i=0;i<KRandIterations;++i)
  2615 	for(TInt i=0;i<KRandIterations;++i)
  2641 
  2629 
  2642 @return The aMicrosec value.
  2630 @return The aMicrosec value.
  2643 */
  2631 */
  2644 /* static */ int TVfs::Sleep(sqlite3_vfs* aVfs, int aMicrosec)
  2632 /* static */ int TVfs::Sleep(sqlite3_vfs* aVfs, int aMicrosec)
  2645 	{
  2633 	{
       
  2634 	SQLUTRACE_PROFILER(aVfs);
  2646 	__OS_CALL(EOsVfsSleep, 0, 0);
  2635 	__OS_CALL(EOsVfsSleep, 0, 0);
  2647 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsSleep], ::OsCallProfile(EFalse, EOsVfsSleep), aMicrosec, 0, 0, 0);
  2636 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsSleep], ::OsCallProfile(EFalse, EOsVfsSleep), aMicrosec, 0, 0, 0);
  2648 	User::AfterHighRes(TTimeIntervalMicroSeconds32(aMicrosec));
  2637 	User::AfterHighRes(TTimeIntervalMicroSeconds32(aMicrosec));
  2649 	return aMicrosec;
  2638 	return aMicrosec;
  2650 	}
  2639 	}
  2660 
  2649 
  2661 @return 0.
  2650 @return 0.
  2662 */
  2651 */
  2663 /* static */ int TVfs::CurrentTime(sqlite3_vfs* aVfs, double* aNow)
  2652 /* static */ int TVfs::CurrentTime(sqlite3_vfs* aVfs, double* aNow)
  2664 	{
  2653 	{
       
  2654 	SQLUTRACE_PROFILER(aVfs);
  2665 	__OS_CALL(EOsVfsCurrentTime, 0, 0);
  2655 	__OS_CALL(EOsVfsCurrentTime, 0, 0);
  2666 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsCurrentTime], ::OsCallProfile(EFalse, EOsVfsCurrentTime), 0, 0, 0, 0);
  2656 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsCurrentTime], ::OsCallProfile(EFalse, EOsVfsCurrentTime), 0, 0, 0, 0);
  2667 	TTime now;
  2657 	TTime now;
  2668 	now.UniversalTime();
  2658 	now.UniversalTime();
  2669 	TDateTime date = now.DateTime();
  2659 	TDateTime date = now.DateTime();
  2695 
  2685 
  2696 @return 0.
  2686 @return 0.
  2697 */
  2687 */
  2698 /* static */int TVfs::GetLastError(sqlite3_vfs* aVfs, int /*aBufLen*/, char* /*aBuf*/)
  2688 /* static */int TVfs::GetLastError(sqlite3_vfs* aVfs, int /*aBufLen*/, char* /*aBuf*/)
  2699 	{
  2689 	{
       
  2690 	SQLUTRACE_PROFILER(aVfs);
  2700 	__OS_CALL(EOsVfsGetLastError, 0, 0);
  2691 	__OS_CALL(EOsVfsGetLastError, 0, 0);
  2701 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsGetLastError], ::OsCallProfile(EFalse, EOsVfsGetLastError), 0, 0, 0, 0);
  2692 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsGetLastError], ::OsCallProfile(EFalse, EOsVfsGetLastError), 0, 0, 0, 0);
  2702 	return 0;
  2693 	return 0;
  2703 	}
  2694 	}
  2704 
  2695 
  2709 /**
  2700 /**
  2710 SQLite OS porting layer API.
  2701 SQLite OS porting layer API.
  2711 
  2702 
  2712 Memory allocation routine.
  2703 Memory allocation routine.
  2713 
  2704 
  2714 EXPORT_C required to match IMPORT_C in stdlib.h and avoid compiler warning
       
  2715 
       
  2716 @internalComponent
  2705 @internalComponent
  2717 */
  2706 */
  2718 extern "C" EXPORT_C void* sqlite3SymbianMalloc(size_t aSize)
  2707 extern "C" void* sqlite3SymbianMalloc(size_t aSize)
  2719 	{
  2708 	{
  2720 	__MEM_CALL(EMemOpAlloc, aSize, 0);
  2709 	__MEM_CALL(EMemOpAlloc, aSize, 0);
  2721 	return Allocator().Alloc(aSize);
  2710 	return Allocator().Alloc(aSize);
  2722 	}
  2711 	}
  2723 
  2712 
  2724 /**
  2713 /**
  2725 SQLite OS porting layer API.
  2714 SQLite OS porting layer API.
  2726 
  2715 
  2727 Memory reallocation routine.
  2716 Memory reallocation routine.
  2728 
  2717 
  2729 EXPORT_C required to match IMPORT_C in stdlib.h and avoid compiler warning
       
  2730 
       
  2731 @internalComponent
  2718 @internalComponent
  2732 */
  2719 */
  2733 extern "C" EXPORT_C void* sqlite3SymbianRealloc(void* aPtr, size_t aSize)
  2720 extern "C" void* sqlite3SymbianRealloc(void* aPtr, size_t aSize)
  2734 	{
  2721 	{
  2735 #ifdef _SQLPROFILER
  2722 #ifdef _SQLPROFILER
  2736 	TInt size = Allocator().AllocLen(aPtr);
  2723 	TInt size = Allocator().AllocLen(aPtr);
  2737 	__MEM_CALL(EMemOpRealloc, aSize, size);
  2724 	__MEM_CALL(EMemOpRealloc, aSize, size);
  2738 #endif
  2725 #endif
  2742 /**
  2729 /**
  2743 SQLite OS porting layer API.
  2730 SQLite OS porting layer API.
  2744 
  2731 
  2745 Memory free routine.
  2732 Memory free routine.
  2746 
  2733 
  2747 EXPORT_C required to match IMPORT_C in stdlib.h and avoid compiler warning
       
  2748 
       
  2749 @internalComponent
  2734 @internalComponent
  2750 */
  2735 */
  2751 extern "C" EXPORT_C void sqlite3SymbianFree(void* aPtr)
  2736 extern "C" void sqlite3SymbianFree(void* aPtr)
  2752 	{
  2737 	{
  2753 #ifdef _SQLPROFILER
  2738 #ifdef _SQLPROFILER
  2754 	TInt size = Allocator().AllocLen(aPtr);
  2739 	TInt size = Allocator().AllocLen(aPtr);
  2755 	__MEM_CALL(EMemOpFree, size, 0);
  2740 	__MEM_CALL(EMemOpFree, size, 0);
  2756 #endif
  2741 #endif