persistentstorage/sql/OsLayer/os_symbian.cpp
branchRCL_3
changeset 44 26645d81f48d
parent 42 28839de615b4
child 45 cc28652e0254
--- a/persistentstorage/sql/OsLayer/os_symbian.cpp	Thu Aug 19 11:36:21 2010 +0300
+++ b/persistentstorage/sql/OsLayer/os_symbian.cpp	Tue Aug 31 16:57:14 2010 +0300
@@ -40,50 +40,21 @@
 #include "SqliteSymbian.h"
 #include "FileBuf64.h"
 #include <e32math.h>
-#include "UTraceSql.h"
 #ifdef _SQLPROFILER
 #include <hal.h>
 #include "../INC/SqlResourceProfiler.h"
 #endif
+#include "SqliteUtil.h"
+#include "OstTraceDefinitions.h"
+#ifdef OST_TRACE_COMPILER_IN_USE
+#include "os_symbianTraces.h"
+#endif
+#include "SqliteTraceDef.h"
 
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
-/**
-Panic category - used by asserts in this file (the OS porting layer).
-
-@see TPanicCodes
-
-@internalComponent
-*/
-_LIT(KPanicCategory, "Sqlite");
-
-/**
-Panic codes - used by asserts in this file (the OS porting layer).
-
-@see KPanicCategory
-
-@internalComponent
-*/
-enum TPanicCodes
-	{
-	EPanicNullOsLayerDataPtr	= 1,
-	EPanicInvalidWAmount 		= 2,
-	EPanicOffset64bit 			= 3,
-	EPanicInvalidOpType			=11,
-	EPanicInvalidFhStr			=12,
-	EPanicInvalidFhData			=13,
-	EPanicInvalidArg			=14,
-	EPanicInvalidRAmount 		=15,
-	EPanicOsLayerDataExists		=16,
-	EPanicInvalidDrive			=17,
-	EPanicInvalidSectorSize		=18,
-	EPanicInternalError			=19,
-	EPanicNullDbFilePtr			=20,
-	EPanicFastCounterFreq		=21
-	};
-
 //The SQLite temp files willl be created in this subdir
 _LIT(KTempFileDir, "temp");
 
@@ -424,7 +395,7 @@
 						fname.Copy(fn8);
 						}
 					//                                           0    1  2  3  4  5   6  7   8   9   10
-					RDebug::Print(_L("[SQL-OS]¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬\"%X\"¬%c¬%S¬%d¬%d¬%ld¬%d¬%ld¬%ld¬%ld¬%S\r\n"),
+					RDebug::Print(_L("[SQL-OS]¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬\"%X\"¬%c¬%S¬%d¬%d¬%ld¬%d¬%ld¬%ld¬%ld¬%S\n"),
 															//[SQL-OS]
 															//Handle
 															//Time from start, microseconds
@@ -488,7 +459,7 @@
 	{
 	TInt ticksPerSec = 0;
 	TInt err = HAL::Get(HAL::EFastCounterFrequency, ticksPerSec);
-	__ASSERT_ALWAYS(err == KErrNone, User::Panic(KPanicCategory, EPanicFastCounterFreq));
+	__ASSERT_ALWAYS(err == KErrNone, __SQLITEPANIC2(ESqliteOsPanicFastCounterFreq));
 	return ticksPerSec;
 	}
 
@@ -682,6 +653,47 @@
 #endif//_SQLPROFILER
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+/**
+Os2SqliteErr() is called at the end of many of the interface functions of the OS porting layer (wherever it is appropriate - 
+TFileIo and TVfs interfaces). The purpose of this function is to identify the "out of memory" and "disk is full" errors
+reported by the used Symbian OS APIs (aOsErr parameter) and report them to SQLite as SQLITE_FULL and SQLITE_NOMEM errors.
+The KErrEof error (TFileIo::Read() can return KErrEof) is reported to SQLite as SQLITE_IOERR_SHORT_READ. The rest of failures
+are reported as the error specified in aDefaultErr parameter.
+ 
+@param aOsErr      Symbian OS error
+@param aDefaultErr The default SQLite error that should be used if the aOsErr parameter is not one of:
+                     KErrNone, KErrEof, KErrNoMemory, KErrDiskFull
+@return SQLITE_OK,               The OS porting layer function call has completed successfully, 
+          SQLITE_IOERR_SHORT_READ, The amount of the data read is less than the requested amount,
+          SQLITE_IOERR_NOMEM,      Out of memory,
+          SQLITE_FULL,             The disk is full,
+          aDefaultErr,             The rest of failures will be reported as aDefaultErr.
+*/
+static TInt Os2SqliteErr(TInt aOsErr, TInt aDefaultErr)
+	{
+	switch(aOsErr)
+		{
+		case KErrNone:
+			return SQLITE_OK;	
+		case KErrEof:
+			return SQLITE_IOERR_SHORT_READ;
+		case KErrNoMemory:
+			return SQLITE_IOERR_NOMEM;
+		case KErrDiskFull:
+			return SQLITE_FULL;
+		default:
+#ifdef _DEBUG		
+			RDebug::Print(_L("SQLite OS porting layer, Os2SqliteErr(), err=%d\n"), aOsErr);
+			SQLITE_TRACE_OS(OstTrace1(TRACE_INTERNALS, OS2SQLITEERR, "OS;0;Os2SqliteErr;aOsErr=%d", aOsErr));
+#endif			
+			break;
+		}
+	return aDefaultErr;
+	}
+	
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 /////////////////////       COsLayerData class declaration   //////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -847,8 +859,7 @@
 	static int Sleep(sqlite3_vfs* aVfs, int aMicrosec);
 	static int CurrentTime(sqlite3_vfs* aVfs, double* aNow);
 	static int GetLastError(sqlite3_vfs *sVfs, int aBufLen, char* aBuf);
-    static TInt DoGetDeviceCharacteristicsAndSectorSize(TDbFile& aDbFile, TInt& aRecReadBufSize);
-
+	static TInt DoGetDeviceCharacteristicsAndSectorSize(TDbFile& aDbFile, TInt& aRecReadBufSize);
 private:
 	static TInt DoOpenFromHandle(TDbFile& aDbFile, const RMessage2& aMsg, TBool aReadOnly);
 	static inline TInt DoGetVolumeIoParamInfo(RFs& aFs, TInt aDriveNo, TVolumeIOParamInfo& aVolumeInfo);
@@ -958,12 +969,14 @@
 */
 /* static */ TInt COsLayerData::Create()
 	{
-	__ASSERT_DEBUG(!COsLayerData::iOsLayerData, User::Panic(KPanicCategory, EPanicOsLayerDataExists));
+	SQLITE_TRACE_OS(OstTrace0(TRACE_INTERNALS, COSLAYERDATA_CREATE_ENTRY, "OS-Entry;0;COsLayerData::Create"));
+	__ASSERT_DEBUG(!COsLayerData::iOsLayerData, __SQLITEPANIC2(ESqliteOsPanicOsLayerDataExists));
 	if(!COsLayerData::iOsLayerData)
 		{
 		COsLayerData::iOsLayerData = new COsLayerData;
 		if(!COsLayerData::iOsLayerData)
 			{
+			SQLITE_TRACE_OS(OstTrace0(TRACE_INTERNALS, COSLAYERDATA_CREATE_EXIT1, "OS-Exit;0;COsLayerData::Create;err=KErrNoMemory"));
 			return KErrNoMemory;	
 			}
 		TInt err = COsLayerData::iOsLayerData->DoCreate();
@@ -971,9 +984,11 @@
 			{
 			delete COsLayerData::iOsLayerData;
 			COsLayerData::iOsLayerData = NULL;
+			SQLITE_TRACE_OS(OstTrace1(TRACE_INTERNALS, COSLAYERDATA_CREATE_EXIT2, "OS-Exit;0;COsLayerData::Create;err=%d", err));
 			return err;
 			}
 		}
+	SQLITE_TRACE_OS(OstTrace0(TRACE_INTERNALS, COSLAYERDATA_CREATE_EXIT3, "OS-Exit;0;COsLayerData::Create;err=KErrNone"));
 	return KErrNone;
 	}
 
@@ -984,6 +999,7 @@
 	{
 	delete COsLayerData::iOsLayerData;
 	COsLayerData::iOsLayerData = NULL;
+	SQLITE_TRACE_OS(OstTrace0(TRACE_INTERNALS, COSLAYERDATA_DESTROY, "OS;0;COsLayerData::Destroy"));
 	}
 
 /**
@@ -993,7 +1009,7 @@
 */
 /* static */ inline COsLayerData& COsLayerData::Instance()
 	{
-	__ASSERT_DEBUG(COsLayerData::iOsLayerData != NULL, User::Panic(KPanicCategory, EPanicNullOsLayerDataPtr));
+	__ASSERT_DEBUG(COsLayerData::iOsLayerData != NULL, __SQLITEPANIC2(ESqliteOsPanicNullOsLayerDataPtr));
 	return *COsLayerData::iOsLayerData;
 	}
 
@@ -1067,7 +1083,7 @@
 */
 inline void COsLayerData::RetrieveAndResetFhData(const RMessage2*& aMsg, TBool& aReadOnly)
 	{
-	__ASSERT_DEBUG(iMessage != NULL, User::Panic(KPanicCategory, EPanicInvalidFhData));
+	__ASSERT_DEBUG(iMessage != NULL, __SQLITEPANIC(ESqliteOsPanicInvalidFhData));
 	aMsg = iMessage; 
 	aReadOnly = iReadOnly;
 	iMessage = NULL;
@@ -1093,6 +1109,7 @@
 */
 inline COsLayerData::~COsLayerData()
 	{
+	SQLITE_TRACE_OS(OstTrace1(TRACE_INTERNALS, COSLAYERDATA_COSLAYERDATA2, "OS;0;COsLayerData::~COsLayerData;iFs.Handle()=0x%X", (TUint)iFs.Handle()));
 	__FS_CALL(EFsOpFsClose, 0);
 	iFs.Close();	
 	}
@@ -1149,6 +1166,7 @@
     	{
 		return err;
     	}
+	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)));
 	return KErrNone;
 	}
 
@@ -1198,6 +1216,7 @@
 		osErr = sqliteErr == SQLITE_NOMEM ? KErrNoMemory : KErrGeneral;
 		COsLayerData::Destroy();
 		}
+	SQLITE_TRACE_OS(OstTrace1(TRACE_INTERNALS, SQLITE3SYMBIANLIBINIT, "OS;0;sqlite3SymbianLibInit;osErr=%d", osErr));
 	return osErr;
 	}
 
@@ -1217,6 +1236,7 @@
 	{
 	(void)sqlite3_shutdown();
 	COsLayerData::Destroy();
+	SQLITE_TRACE_OS(OstTrace0(TRACE_INTERNALS, SQLITE3SYMBIANLIBFINALIZE, "OS;0;sqlite3SymbianLibFinalize"));
 	}
 
 /**
@@ -1253,7 +1273,7 @@
 		{
 		wchar_t* dest = reinterpret_cast <wchar_t*> (const_cast <TUint16*> (aFileNameDestBuf.Ptr()));
 		TInt len = mbstowcs(dest, aFileName, aFileNameDestBuf.MaxLength());
-		__ASSERT_DEBUG(len >= 0, User::Panic(KPanicCategory, EPanicInternalError));
+		__ASSERT_DEBUG(len >= 0, __SQLITEPANIC2(ESqliteOsPanicInternalError));
 		//If len == aFileNameDestBuf.MaxLength(), then the output buffer is too small.
 		if(len < aFileNameDestBuf.MaxLength())
 			{
@@ -1282,7 +1302,7 @@
 	char* dest = reinterpret_cast <char*> (const_cast <TUint8*> (aFileNameDestBuf.Ptr()));
 	const wchar_t* src = reinterpret_cast <const wchar_t*> (aFileName.Ptr());
 	TInt len = wcstombs(dest, src, aFileNameDestBuf.MaxLength());
-	__ASSERT_DEBUG(len >= 0, User::Panic(KPanicCategory, EPanicInternalError));
+	__ASSERT_DEBUG(len >= 0, __SQLITEPANIC2(ESqliteOsPanicInternalError));
 	//If len == aFileNameDestBuf.MaxLength(), then the output buffer is too small.
 	if(len < aFileNameDestBuf.MaxLength())
 		{
@@ -1424,7 +1444,7 @@
 static void FhExtractAndStore(TDes& aDbFileName)
 	{
 	TInt fhStartPos = aDbFileName.Locate(TChar(KFhSeparator));
-	__ASSERT_DEBUG(fhStartPos == KFhMarkPos, User::Panic(KPanicCategory, EPanicInvalidFhStr));
+	__ASSERT_DEBUG(fhStartPos == KFhMarkPos, __SQLITEPANIC2(ESqliteOsPanicInvalidFhStr));
 	//If this file name string contains file handles
 	if(fhStartPos == KFhMarkPos)
 		{
@@ -1432,12 +1452,12 @@
 		TLex lex(aDbFileName.Mid(fhStartPos + KFhMsgAddrPos, KFhMsgAddrLen));
 		TUint32 addr;
 		TInt err = lex.Val(addr, EHex);
-		__ASSERT_DEBUG(err == KErrNone, User::Panic(KPanicCategory, EPanicInvalidFhStr));
+		__ASSERT_DEBUG(err == KErrNone, __SQLITEPANIC2(ESqliteOsPanicInvalidFhStr));
 		if(err == KErrNone)
 			{
 			//Cast the address to RMessage2 pointer.
 			const RMessage2* msg = reinterpret_cast <const RMessage2*> (addr);
-			__ASSERT_DEBUG(msg != NULL, User::Panic(KPanicCategory, EPanicInvalidFhStr));
+			__ASSERT_DEBUG(msg != NULL, __SQLITEPANIC2(ESqliteOsPanicInvalidFhStr));
 			if(msg)
 				{
 				//Store the data from aDbFileName in the single COsLayerData instance.
@@ -1469,6 +1489,7 @@
 	iIsJournal = EFalse;
 #endif
 	pMethods = 0;
+	SQLITE_TRACE_OS(OstTrace1(TRACE_INTERNALS, TDBFILE_TDBFILE, "OS;0x%X;TDbFile::TDbFile", (TUint)this));
 	}
 
 /**
@@ -1489,7 +1510,7 @@
 */
 static inline TDbFile& DbFile(sqlite3_file* aDbFile)
 	{
-	__ASSERT_DEBUG(aDbFile != 0, User::Panic(KPanicCategory, EPanicNullDbFilePtr));
+	__ASSERT_DEBUG(aDbFile != 0, __SQLITEPANIC2(ESqliteOsPanicNullDbFilePtr));
 	return *(static_cast <TDbFile*> (aDbFile));
 	}
 
@@ -1510,12 +1531,12 @@
 */
 /* static */ int TFileIo::Close(sqlite3_file* aDbFile)
 	{
-	SQLUTRACE_PROFILER(aDbFile);
 	TDbFile& dbFile = ::DbFile(aDbFile);
+	SQLITE_TRACE_OS(OstTrace1(TRACE_INTERNALS, TFILEIO_CLOSE1, "OS;0x%X;TFileIo::Close", (TUint)&dbFile));
 	__OS_CALL(EOsFileClose, 0, 0);
 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileClose], ::OsCallProfile(dbFile.iIsJournal, EOsFileClose), 0, 0, aDbFile, 0);
 	__FS_CALL(EFsOpFileClose, 0);
-  dbFile.iFileBuf.Close();
+	dbFile.iFileBuf.Close();
 	return SQLITE_OK;
 	}
 
@@ -1543,38 +1564,23 @@
 */
 /* static */ int TFileIo::Read(sqlite3_file* aDbFile, void* aBuf, int aAmt, sqlite3_int64 aOffset)
 	{
-	SQLUTRACE_PROFILER(aDbFile);
-	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KFileRead, aAmt, aOffset));
 	TDbFile& dbFile = ::DbFile(aDbFile);
+	SQLITE_TRACE_OS(OstTraceExt3(TRACE_INTERNALS, TFILEIO_READ_ENTRY, "OS-Entry;0x%X;TFileIo::Read;aAmt=%d;aOffset=%lld", (TUint)&dbFile, aAmt, aOffset));
 	__OS_CALL(EOsFileRead, 0, 0);
 	__COUNTER_INCR(TheSqlSrvProfilerFileRead);
 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileRead], ::OsCallProfile(dbFile.iIsJournal, EOsFileRead), aOffset, aAmt, aDbFile, 0);
 	TPtr8 ptr((TUint8*)aBuf, 0, aAmt);
 	TInt err = dbFile.iFileBuf.Read(aOffset, ptr);
 	TInt cnt = ptr.Length();
-	TInt sqliteErr = SQLITE_IOERR_READ;
-	switch(err)
+	TInt sqliteErr = ::Os2SqliteErr(err, SQLITE_IOERR_READ);
+	if(cnt != aAmt && (sqliteErr == SQLITE_OK || sqliteErr == SQLITE_IOERR_SHORT_READ))
 		{
-		case KErrNone:
-			sqliteErr = SQLITE_OK;	
-			if(cnt != aAmt)
-				{
-				Mem::FillZ(static_cast <TUint8*> (aBuf) + cnt, aAmt - cnt);
-				sqliteErr = SQLITE_IOERR_SHORT_READ;
-				err = KErrEof;
-				}
-			break;
-		case KErrEof:
-			Mem::FillZ(static_cast <TUint8*> (aBuf) + cnt, aAmt - cnt);
-			sqliteErr = SQLITE_IOERR_SHORT_READ;
-			break;
-		case KErrNoMemory:
-			sqliteErr = SQLITE_IOERR_NOMEM;
-			break;
-		default:
-			break;
+		Mem::FillZ(static_cast <TUint8*> (aBuf) + cnt, aAmt - cnt);
+		err = KErrEof;
+		sqliteErr = SQLITE_IOERR_SHORT_READ;
 		}
 	COsLayerData::Instance().SetOsErrorCode(err);
+	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));
 	return sqliteErr;
 	}
 
@@ -1653,9 +1659,11 @@
 */
 /* static */ int TFileIo::Write(sqlite3_file* aDbFile, const void* aData, int aAmt, sqlite3_int64 aOffset)
 	{
-	SQLUTRACE_PROFILER(aDbFile);
-	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KFileWrite, aAmt, aOffset));
 	TDbFile& dbFile = ::DbFile(aDbFile);
+	SQLITE_TRACE_OS(OstTraceExt3(TRACE_INTERNALS, TFILEIO_WRITE_ENTRY, "OS-Entry;0x%X;TFileIo::Write;aAmt=%d;aOffset=%lld", (TUint)&dbFile, aAmt, aOffset));
+	__OS_CALL(EOsFileWrite, 0, 0);
+    __COUNTER_INCR(TheSqlSrvProfilerFileWrite);
+	__OSTIME_COUNTER(TheOsCallTicks[EOsFileWrite], ::OsCallProfile(dbFile.iIsJournal, EOsFileWrite), aOffset, aAmt, aDbFile, 0);
 	TInt err = KErrNone;
 	if(!dbFile.iIsFileCreated)
 	    {//Create a temp file if it has not been created. 
@@ -1664,35 +1672,34 @@
 	if(err != KErrNone)
 	    {
         COsLayerData::Instance().SetOsErrorCode(err);
-        return err == KErrNoMemory ? SQLITE_IOERR_NOMEM : SQLITE_FULL;
+		return ::Os2SqliteErr(err, SQLITE_FULL);
 	    }
+	err = KErrAccessDenied;
+	if(!dbFile.iReadOnly)
+		{
+		TPtrC8 ptr((const TUint8*)aData, aAmt);
+		err = dbFile.iFileBuf.Write(aOffset, ptr);
+		}
+	COsLayerData::Instance().SetOsErrorCode(err);
 	
-    __OS_CALL(EOsFileWrite, 0, 0);
-    __COUNTER_INCR(TheSqlSrvProfilerFileWrite);
-    __OSTIME_COUNTER(TheOsCallTicks[EOsFileWrite], ::OsCallProfile(dbFile.iIsJournal, EOsFileWrite), aOffset, aAmt, aDbFile, 0);
-    err = KErrAccessDenied;
-    if(!dbFile.iReadOnly)
-        {
-        TPtrC8 ptr((const TUint8*)aData, aAmt);
-        err = dbFile.iFileBuf.Write(aOffset, ptr);
-        }
-    COsLayerData::Instance().SetOsErrorCode(err);
-    
-    const TInt KFreePageCountOffset = 36;//hard-coded constant. SQLite does not offer anything - a constant or #define.
-    //The checks in the "if" bellow do:
-    // - "err == KErrNone" - check the free page count only after a successful "write";
-    // - "aOffset == 0"    - check the free page count only if the write operation affects the system page (at aOffset = 0);
-    // - "aAmt >= (KFreePageCountOffset + sizeof(int))" - check the free page count only if the amount of bytes to be written
-    //						 is more than the offset of the free page counter (othewrise the free page counter is not affected
-    //						 by this write operation);
-    // - "dbFile.iFreePageCallback.IsValid()" - check the free page count only if there is a valid callback;
-    if(err == KErrNone  && aOffset == 0 && aAmt >= (KFreePageCountOffset + sizeof(int)) && dbFile.iFreePageCallback.IsValid())
-        {
-        const TUint8* ptr = static_cast <const TUint8*> (aData) + KFreePageCountOffset;
-        TInt freePageCount = (ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | ptr[3];
-        dbFile.iFreePageCallback.CheckAndCallback(freePageCount);
-        }
-	return err == KErrNone ? SQLITE_OK : (err == KErrNoMemory ? SQLITE_IOERR_NOMEM : SQLITE_FULL);
+	const TInt KFreePageCountOffset = 36;//hard-coded constant. SQLite does not offer anything - a constant or #define.
+	//The checks in the "if" bellow do:
+	// - "err == KErrNone" - check the free page count only after a successful "write";
+	// - "aOffset == 0"    - check the free page count only if the write operation affects the system page (at aOffset = 0);
+	// - "aAmt >= (KFreePageCountOffset + sizeof(int))" - check the free page count only if the amount of bytes to be written
+	//						 is more than the offset of the free page counter (othewrise the free page counter is not affected
+	//						 by this write operation);
+	// - "dbFile.iFreePageCallback.IsValid()" - check the free page count only if there is a valid callback;
+	if(err == KErrNone  && aOffset == 0 && aAmt >= (KFreePageCountOffset + sizeof(int)) && dbFile.iFreePageCallback.IsValid())
+		{
+		const TUint8* ptr = static_cast <const TUint8*> (aData) + KFreePageCountOffset;
+		TInt freePageCount = (ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | ptr[3];
+		dbFile.iFreePageCallback.CheckAndCallback(freePageCount);
+		}
+		
+	TInt sqliteErr = ::Os2SqliteErr(err, SQLITE_FULL);
+	SQLITE_TRACE_OS(OstTraceExt3(TRACE_INTERNALS, TFILEIO_WRITE_EXIT, "OS-Exit;0x%X;TFileIo::Write;err=%d;sqliteErr=%d", (TUint)&dbFile, err, sqliteErr));
+	return sqliteErr;
 	}
 
 /**
@@ -1717,9 +1724,8 @@
 */
 /* static */ int TFileIo::Truncate(sqlite3_file* aDbFile, sqlite3_int64 aLength)
 	{
-	SQLUTRACE_PROFILER(aDbFile);
-	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KFileTruncate, aLength));
 	TDbFile& dbFile = ::DbFile(aDbFile);
+	SQLITE_TRACE_OS(OstTraceExt2(TRACE_INTERNALS, TFILEIO_TRUNCATE_ENTRY, "OS-Entry;0x%X;TFileIo::Truncate;aLength=%lld", (TUint)&dbFile, aLength));
 	__OS_CALL(EOsFileTruncate, 0, 0);
     __COUNTER_INCR(TheSqlSrvProfilerFileSetSize);
 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileTruncate], ::OsCallProfile(dbFile.iIsJournal, EOsFileTruncate), aLength, 0, aDbFile, 0);
@@ -1731,7 +1737,9 @@
 	__FS_CALL(EFsOpFileSetSize, 0);
 	TInt err = dbFile.iFileBuf.SetSize(aLength);
 	COsLayerData::Instance().SetOsErrorCode(err);
-	return err == KErrNone ? SQLITE_OK : (err == KErrNoMemory ? SQLITE_IOERR_NOMEM : SQLITE_IOERR);
+	TInt sqliteErr = ::Os2SqliteErr(err, SQLITE_IOERR);
+	SQLITE_TRACE_OS(OstTraceExt3(TRACE_INTERNALS, TFILEIO_TRUNCATE_EXIT, "OS-Exit;0x%X;TFileIo::Truncate;err=%d;sqliteErr=%d", (TUint)&dbFile, err, sqliteErr));
+	return sqliteErr;
 	}
 
 /**
@@ -1754,8 +1762,8 @@
 */
 /* static */int TFileIo::Sync(sqlite3_file* aDbFile, int /* aFlags */)
 	{
-	SQLUTRACE_PROFILER(aDbFile);
 	TDbFile& dbFile = ::DbFile(aDbFile);
+	SQLITE_TRACE_OS(OstTrace1(TRACE_INTERNALS, TFILEIO_SYNC_ENTRY, "OS-Entry;0x%X;TFileIo::Sync", (TUint)&dbFile));
 	__OS_CALL(EOsFileSync, 0, 0);
     __COUNTER_INCR(TheSqlSrvProfilerFileSync);
 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileSync], ::OsCallProfile(dbFile.iIsJournal, EOsFileSync), 0, 0, aDbFile, 0);
@@ -1767,7 +1775,9 @@
 	__FS_CALL(EFsOpFileSync, 0);
 	TInt err = dbFile.iFileBuf.Flush();
 	COsLayerData::Instance().SetOsErrorCode(err);
-	return err == KErrNone ? SQLITE_OK : (err == KErrNoMemory ? SQLITE_IOERR_NOMEM : SQLITE_IOERR);
+	TInt sqliteErr = ::Os2SqliteErr(err, SQLITE_IOERR);
+	SQLITE_TRACE_OS(OstTraceExt3(TRACE_INTERNALS, TFILEIO_SYNC_EXIT, "OS-Exit;0x%X;TFileIo::Sync;err=%d;sqliteErr=%d", (TUint)&dbFile, err, sqliteErr));
+	return sqliteErr;
 	}
 
 /**
@@ -1790,18 +1800,16 @@
 */
 /* static */ int TFileIo::FileSize(sqlite3_file* aDbFile, sqlite3_int64* aSize)
 	{
-	SQLUTRACE_PROFILER(aDbFile);
 	TDbFile& dbFile = ::DbFile(aDbFile);
+	SQLITE_TRACE_OS(OstTrace1(TRACE_INTERNALS, TFILEIO_FILESIZE_ENTRY, "OS-Entry;0x%X;TFileIo::FileSize", (TUint)&dbFile));
 	__OS_CALL(EOsFileFileSize, 0, 0);
 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileFileSize], ::OsCallProfile(dbFile.iIsJournal, EOsFileFileSize), 0, 0, aDbFile, 0);
 	__FS_CALL(EFsOpFileSize, 0);
 	TInt err =  dbFile.iFileBuf.Size(*aSize);
 	COsLayerData::Instance().SetOsErrorCode(err);
-	if(err == KErrNone)
-		{
-		return SQLITE_OK;
-		}
-	return err == KErrNoMemory ? SQLITE_IOERR_NOMEM : SQLITE_IOERR;
+	TInt sqliteErr = ::Os2SqliteErr(err, SQLITE_IOERR);
+	SQLITE_TRACE_OS(OstTraceExt3(TRACE_INTERNALS, TFILEIO_FILESIZE_EXIT, "OS-Exit;0x%X;TFileIo::FileSize;err=%d;sqliteErr=%d", (TUint)&dbFile, err, sqliteErr));
+	return sqliteErr;
 	}
 
 /**
@@ -1824,7 +1832,6 @@
 */
 /* static */ int TFileIo::Lock(sqlite3_file* aDbFile, int aLockType)
 	{
-	SQLUTRACE_PROFILER(aDbFile);
 	TDbFile& dbFile = ::DbFile(aDbFile);
 	__OS_CALL(EOsFileLock, 0, 0);
 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileLock], ::OsCallProfile(dbFile.iIsJournal, EOsFileLock), aLockType, 0, aDbFile, 0);
@@ -1857,7 +1864,6 @@
 */
 /* static */ int TFileIo::Unlock(sqlite3_file* aDbFile, int aLockType)
 	{
-	SQLUTRACE_PROFILER(aDbFile);
 	TDbFile& dbFile = ::DbFile(aDbFile);
 	__OS_CALL(EOsFileUnlock, 0, 0);
 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileUnlock], ::OsCallProfile(dbFile.iIsJournal, EOsFileUnlock), aLockType, 0, aDbFile, 0);
@@ -1886,7 +1892,6 @@
 */
 /* static */ int TFileIo::CheckReservedLock(sqlite3_file* aDbFile, int *aResOut)
 	{
-	SQLUTRACE_PROFILER(aDbFile);
 	TDbFile& dbFile = ::DbFile(aDbFile);
 	__OS_CALL(EOsFileCheckReservedLock, 0, 0);
 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileCheckReservedLock], ::OsCallProfile(dbFile.iIsJournal, EOsFileCheckReservedLock), 0, 0, aDbFile, 0);
@@ -1921,9 +1926,8 @@
 */
 /* static */ int TFileIo::FileControl(sqlite3_file* aDbFile, int aOp, void* aArg)
 	{
-	SQLUTRACE_PROFILER(aDbFile);
-	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KFileFileCtr, aOp));
 	TDbFile& dbFile = ::DbFile(aDbFile);
+	SQLITE_TRACE_OS(OstTraceExt2(TRACE_INTERNALS, TFILEIO_FILECONTROL_ENTRY, "OS-Entry;0x%X;TFileIo::FileControl;aOp=%d", (TUint)&dbFile, aOp));
 	__OS_CALL(EOsFileFileControl, 0, 0);
 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileFileControl], ::OsCallProfile(dbFile.iIsJournal, EOsFileFileControl), aOp, 0, aDbFile, 0);
 	TInt err = KErrNone;
@@ -1951,7 +1955,9 @@
 			break;
 		}
 	COsLayerData::Instance().SetOsErrorCode(err);
-	return err == KErrNone ? SQLITE_OK : SQLITE_ERROR;
+	TInt sqliteErr = ::Os2SqliteErr(err, SQLITE_ERROR);
+	SQLITE_TRACE_OS(OstTraceExt3(TRACE_INTERNALS, TFILEIO_FILECONTROL_EXIT, "OS-Exit;0x%X;TFileIo::FileControl;err=%d;sqliteErr=%d", (TUint)&dbFile, err, sqliteErr));
+	return sqliteErr;
 	}
 
 /**
@@ -1973,11 +1979,10 @@
 */
 /* static */ int TFileIo::SectorSize(sqlite3_file* aDbFile)
 	{
-	SQLUTRACE_PROFILER(aDbFile);
 	TDbFile& dbFile = ::DbFile(aDbFile);
 	__OS_CALL(EOsFileSectorSize, 0, 0);
 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileSectorSize], ::OsCallProfile(dbFile.iIsJournal, EOsFileSectorSize), 0, 0, aDbFile, 0);
-	__ASSERT_DEBUG(dbFile.iSectorSize > 0, User::Panic(KPanicCategory, EPanicInternalError));
+	__ASSERT_DEBUG(dbFile.iSectorSize > 0, __SQLITEPANIC2(ESqliteOsPanicInternalError));
 	if(dbFile.iSectorSize > 0)
 		{
 		return dbFile.iSectorSize;	
@@ -2004,11 +2009,10 @@
 */
 /* static */ int TFileIo::DeviceCharacteristics(sqlite3_file* aDbFile)
 	{
-	SQLUTRACE_PROFILER(aDbFile);
 	TDbFile& dbFile = ::DbFile(aDbFile);
 	__OS_CALL(EOsFileDeviceCharacteristics, 0, 0);
 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileDeviceCharacteristics], ::OsCallProfile(dbFile.iIsJournal, EOsFileDeviceCharacteristics), 0, 0, aDbFile, 0);
-	__ASSERT_DEBUG(dbFile.iDeviceCharacteristics >= 0, User::Panic(KPanicCategory, EPanicInternalError));
+	__ASSERT_DEBUG(dbFile.iDeviceCharacteristics >= 0, __SQLITEPANIC2(ESqliteOsPanicInternalError));
 	if(dbFile.iDeviceCharacteristics >= 0)
 		{
 		return dbFile.iDeviceCharacteristics;	
@@ -2065,7 +2069,9 @@
 /* static */ inline TInt TVfs::DoGetVolumeIoParamInfo(RFs& aFs, TInt aDriveNo, TVolumeIOParamInfo& aVolumeInfo)
 	{
 	__FS_CALL(EFsOpFsVolumeIoParam, 0);
-	return aFs.VolumeIOParam(aDriveNo, aVolumeInfo);
+	TInt err = aFs.VolumeIOParam(aDriveNo, aVolumeInfo); 
+	SQLITE_TRACE_OS(OstTraceExt2(TRACE_INTERNALS, TVFS_DOGETVOLUMEIOPARAMINFO, "OS;0;TVfs::DoGetVolumeIoParamInfo;aDriveNo=%d;err=%d", aDriveNo, err));
+	return err;		
 	}
 
 /**
@@ -2153,7 +2159,7 @@
 			sectorSize = aVolumeInfo.iBlockSize;
 			}
 		}
-	__ASSERT_DEBUG(sectorSize > 0 && (sectorSize & (sectorSize - 1)) == 0, User::Panic(KPanicCategory, EPanicInternalError));
+	__ASSERT_DEBUG(sectorSize > 0 && (sectorSize & (sectorSize - 1)) == 0, __SQLITEPANIC2(ESqliteOsPanicInternalError));
 	return sectorSize;
 	}
 
@@ -2182,8 +2188,8 @@
 */
 /* static */ TInt TVfs::DoGetDeviceCharacteristicsAndSectorSize(TDbFile& aDbFile, TInt& aRecReadBufSize)
 	{
-	__ASSERT_DEBUG(aDbFile.iDeviceCharacteristics < 0, User::Panic(KPanicCategory, EPanicInternalError));
-	__ASSERT_DEBUG(aDbFile.iSectorSize <= 0, User::Panic(KPanicCategory, EPanicInternalError));
+	__ASSERT_DEBUG(aDbFile.iDeviceCharacteristics < 0, __SQLITEPANIC2(ESqliteOsPanicInternalError));
+	__ASSERT_DEBUG(aDbFile.iSectorSize <= 0, __SQLITEPANIC2(ESqliteOsPanicInternalError));
 	TInt driveNo;
 	TDriveInfo driveInfo;
 	__FS_CALL(EFsOpFileDrive, 0);
@@ -2201,6 +2207,7 @@
 	aDbFile.iDeviceCharacteristics = TVfs::DoGetDeviceCharacteristics(driveInfo, volumeInfo);
 	aDbFile.iSectorSize = TVfs::DoGetSectorSize(driveInfo, volumeInfo);
 	aRecReadBufSize = volumeInfo.iRecReadBufSize;
+	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));
 	return KErrNone;
 	}
 
@@ -2256,8 +2263,10 @@
         COsLayerData& osLayerData = COsLayerData::Instance();
     
         aDbFile.iFileBuf.Close();
-        (void) osLayerData.iFs.Delete(aFname);
+        __SQLITETRACE_OSEXPR(TInt err2 =) osLayerData.iFs.Delete(aFname);
+		SQLITE_TRACE_OS(OstTraceExt4(TRACE_INTERNALS, TVFS_DOFILESIZECORRUPTIONCHECK1, "OS;0x%X;TVfs::DoFileSizeCorruptionCheck;size=%lld;err=%d;deleteErr=%d", (TUint)&aDbFile, size, err, err2));
         err = aDbFile.iFileBuf.Create(osLayerData.iFs, aFname, aFmode);
+		SQLITE_TRACE_OS(OstTraceExt2(TRACE_INTERNALS, TVFS_DOFILESIZECORRUPTIONCHECK2, "OS;0x%X;TVfs::DoFileSizeCorruptionCheck;createErr=%d", (TUint)&aDbFile, err));
         }
     return err;
     }
@@ -2295,101 +2304,95 @@
 @see TDbFile
 */
 /* static */ int TVfs::Open(sqlite3_vfs* aVfs, const char* aFileName, sqlite3_file* aDbFile, int aFlags, int* aOutFlags)
-	{   
-    SQLUTRACE_PROFILER(aVfs);
-    __OS_CALL(EOsVfsOpen, 0, 0);
-    __OSTIME_COUNTER(TheOsCallTicks[EOsVfsOpen], ::OsCallProfile(EFalse, EOsVfsOpen), 0, 0, aDbFile, aFileName);
- 
-    COsLayerData& osLayerData = COsLayerData::Instance();
-    TFhStrType fhStrType = ENotFhStr;
-    new (aDbFile) TDbFile;
-    TDbFile& dbFile = ::DbFile(aDbFile);
-
+	{
+	__OS_CALL(EOsVfsOpen, 0, 0);
+	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsOpen], ::OsCallProfile(EFalse, EOsVfsOpen), 0, 0, aDbFile, aFileName);
+	COsLayerData& osLayerData = COsLayerData::Instance();
+	new (aDbFile) TDbFile;
+	TDbFile& dbFile = ::DbFile(aDbFile);
     if(!aFileName)
         {  
         //It is to create and open a temp file if aFileName is NULL. In this case,
         //we will defer the file creation util it is needed.  
-    
         dbFile.pMethods = &TheFileIoApi;
         dbFile.iIsFileCreated = EFalse;
         if(aOutFlags)
             {
             *aOutFlags = SQLITE_OPEN_READWRITE;
             }
+		osLayerData.SetOsErrorCode(KErrNone);
         return SQLITE_OK;
         }  
-    
-    TFileName fname;
+	TFileName fname;
     if(!::ConvertToUnicode(aFileName, fname))
-        {
+		{
         osLayerData.SetOsErrorCode(KErrBadName);
         return SQLITE_CANTOPEN;	
-        }
-    SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KFileOpen, aDbFile, &fname));
-    fhStrType = ::FhStringProps(aFileName);
-    TInt err = KErrNone;
-    TInt recReadBufSize = -1;
-    if(fhStrType == EFhMainDbStr)
-        {//Main db file, open from handle
-        const RMessage2* msg;
-        TBool readOnly;
-        osLayerData.RetrieveAndResetFhData(msg, readOnly);
-        err = msg != NULL ? TVfs::DoOpenFromHandle(dbFile, *msg, readOnly) : KErrGeneral;
-        }
-    else
-        {
-        if(fhStrType == EFhStr)
-            {//Not the main db file. Remove invalid characters in the file name
-            ::FhConvertToFileName(fname, osLayerData.iSysPrivDir);//If fname does not have a path, iSysPrivDir will be used
-            }
-        TInt fmode = EFileRead;
-        if(aFlags & SQLITE_OPEN_READWRITE)
-            {
-            fmode |= EFileWrite;
-            }
-        if(aFlags & SQLITE_OPEN_EXCLUSIVE)
-            {
-            fmode |= EFileShareExclusive;
-            }
-            err = KErrAccessDenied;
-            TInt prevErr = KErrNone;
-            if(aFlags & SQLITE_OPEN_DELETEONCLOSE)
-                {
-                fmode |= EDeleteOnClose;
-                }
-            if(aFlags & SQLITE_OPEN_CREATE)
-                {
-                __FS_CALL(EFsOpFileCreate, 0);
-                prevErr = err = dbFile.iFileBuf.Create(osLayerData.iFs, fname, fmode);
-                }
-            if(err != KErrNone && err != KErrNoMemory && err != KErrDiskFull)
-                {
-                __FS_CALL(EFsOpFileOpen, 0);
-                err = dbFile.iFileBuf.Open(osLayerData.iFs, fname, fmode);
-                
-                if(err == KErrNone && (aFlags & KJournalFileTypeBitMask))
-                    {
-                    err = TVfs::DoFileSizeCorruptionCheck(dbFile, fname, fmode);
-                    }
-                }
-            if((err != KErrNone && err != KErrNoMemory && err != KErrDiskFull) && (aFlags & SQLITE_OPEN_READWRITE))
-                {
-                aFlags &= ~SQLITE_OPEN_READWRITE;
-                aFlags |= SQLITE_OPEN_READONLY;
-                fmode &= ~EFileWrite;
-                __FS_CALL(EFsOpFileOpen, 0);
-                err = dbFile.iFileBuf.Open(osLayerData.iFs, fname, fmode);
-                }
-            if(err != KErrNone && prevErr == KErrAccessDenied)
-                {
-                err = KErrAccessDenied;
-                }
-        }
-    if(err == KErrNone)
-        {
-        err = TVfs::DoGetDeviceCharacteristicsAndSectorSize(dbFile, recReadBufSize);
-        }	
- 	
+    	}
+	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));
+	TFhStrType fhStrType = aFileName ? ::FhStringProps(aFileName) : ENotFhStr;
+	TInt err = KErrNone;
+	if(fhStrType == EFhMainDbStr)
+		{//Main db file, open from handle
+		const RMessage2* msg;
+		TBool readOnly;
+		osLayerData.RetrieveAndResetFhData(msg, readOnly);
+		err = msg != NULL ? TVfs::DoOpenFromHandle(dbFile, *msg, readOnly) : KErrGeneral;
+		}
+	else
+		{
+		if(fhStrType == EFhStr)
+			{//Not the main db file. Remove invalid characters in the file name
+			::FhConvertToFileName(fname, osLayerData.iSysPrivDir);//If fname does not have a path, iSysPrivDir will be used
+			}
+		TInt fmode = EFileRead;
+		if(aFlags & SQLITE_OPEN_READWRITE)
+			{
+			fmode |= EFileWrite;
+			}
+		if(aFlags & SQLITE_OPEN_EXCLUSIVE)
+			{
+			fmode |= EFileShareExclusive;
+			}
+		if(aFlags & SQLITE_OPEN_DELETEONCLOSE)
+			{
+			fmode |= EDeleteOnClose;
+			}
+		err = KErrAccessDenied;
+		TInt prevErr = KErrNone;
+		if(aFlags & SQLITE_OPEN_CREATE)
+			{
+			__FS_CALL(EFsOpFileCreate, 0);
+			prevErr = err = dbFile.iFileBuf.Create(osLayerData.iFs, fname, fmode);
+			}
+		if(err != KErrNone && err != KErrNoMemory && err != KErrDiskFull)
+			{
+			__FS_CALL(EFsOpFileOpen, 0);
+			err = dbFile.iFileBuf.Open(osLayerData.iFs, fname, fmode);
+
+			if(err == KErrNone && (aFlags & KJournalFileTypeBitMask))
+				{
+				err = TVfs::DoFileSizeCorruptionCheck(dbFile, fname, fmode);
+				}
+			}
+		if((err != KErrNone && err != KErrNoMemory && err != KErrDiskFull) && (aFlags & SQLITE_OPEN_READWRITE))
+			{
+			aFlags &= ~SQLITE_OPEN_READWRITE;
+			aFlags |= SQLITE_OPEN_READONLY;
+			fmode &= ~EFileWrite;
+			__FS_CALL(EFsOpFileOpen, 0);
+			err = dbFile.iFileBuf.Open(osLayerData.iFs, fname, fmode);
+			}
+		if(err != KErrNone && prevErr == KErrAccessDenied)
+			{
+			err = KErrAccessDenied;
+			}
+		}
+	TInt recReadBufSize = -1;
+	if(err == KErrNone)
+		{
+		err = TVfs::DoGetDeviceCharacteristicsAndSectorSize(dbFile, recReadBufSize);
+		}
 	osLayerData.SetOsErrorCode(err);
 	if(err != KErrNone)
 		{
@@ -2412,7 +2415,9 @@
 #ifdef _SQLPROFILER
 	dbFile.iIsJournal = aFlags & KJournalFileTypeBitMask; 
 #endif
-	return err == KErrNone ? SQLITE_OK : (err == KErrNoMemory ? SQLITE_IOERR_NOMEM : SQLITE_CANTOPEN);
+	TInt sqliteErr = ::Os2SqliteErr(err, SQLITE_CANTOPEN);
+	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));
+	return sqliteErr;
 	}
 
 /**
@@ -2435,7 +2440,6 @@
 */
 /* static */ int TVfs::Delete(sqlite3_vfs* aVfs, const char* aFileName, int /*aSyncDir*/)
 	{
-	SQLUTRACE_PROFILER(aVfs);
 	__OS_CALL(EOsVfsDelete, 0, 0);
 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsDelete], ::OsCallProfile(EFalse, EOsVfsDelete), 0, 0, 0, aFileName);
 	COsLayerData& osLayerData = COsLayerData::Instance();
@@ -2443,13 +2447,15 @@
 	if(!::ConvertToUnicode(aFileName, fname))
 		{
 		osLayerData.SetOsErrorCode(KErrBadName);
+		SQLITE_TRACE_OS(OstTrace0(TRACE_INTERNALS, TVFS_DELETE1, "OS;0;TVfs::Delete;err=KErrBadName"));
 		return SQLITE_ERROR;	
 		}
-	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KFileName, &fname));
+	SQLITE_TRACE_OS(OstTraceExt1(TRACE_INTERNALS, TVFS_DELETE_ENTRY, "OS-Entry;0;TVfs::Delete;fname=%S", __SQLITEPRNSTR(fname)));
 	TFhStrType fhStrType = FhStringProps(aFileName);
 	if(fhStrType == EFhMainDbStr)
 		{//Deleting files not in your own private data cage - not allowed!
 		osLayerData.SetOsErrorCode(KErrPermissionDenied);
+		SQLITE_TRACE_OS(OstTraceExt1(TRACE_INTERNALS, TVFS_DELETE2, "OS;0;TVfs::Delete;err=KErrPermissionDenied;fname=%S", __SQLITEPRNSTR(fname)));
 		return SQLITE_ERROR;	
 		}
 	if(fhStrType == EFhStr)
@@ -2459,7 +2465,9 @@
 	__FS_CALL(EFsOpFileDelete, 0);
 	TInt err = osLayerData.iFs.Delete(fname);
 	osLayerData.SetOsErrorCode(err);
-	return err == KErrNone ? SQLITE_OK : (err == KErrNoMemory ? SQLITE_IOERR_NOMEM : SQLITE_IOERR_DELETE);
+	TInt sqliteErr = ::Os2SqliteErr(err, SQLITE_IOERR_DELETE);	
+	SQLITE_TRACE_OS(OstTraceExt2(TRACE_INTERNALS, TVFS_DELETE_EXIT, "OS-Exit;0;TVfs::Delete;err=%d;sqliteErr=%d", err, sqliteErr));
+	return sqliteErr;
 	}
 
 /**
@@ -2483,7 +2491,6 @@
 */
 /* static */ int TVfs::Access(sqlite3_vfs* aVfs, const char* aFileName, int aFlags, int* aResOut)
 	{
-	SQLUTRACE_PROFILER(aVfs);
 	__OS_CALL(EOsVfsAccess, 0, 0);
 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsAccess], ::OsCallProfile(EFalse, EOsVfsAccess), aFlags, 0, 0, aFileName);
 	COsLayerData& osLayerData = COsLayerData::Instance();
@@ -2491,9 +2498,10 @@
 	if(!::ConvertToUnicode(aFileName, fname))
 		{
 		osLayerData.SetOsErrorCode(KErrGeneral);
+		SQLITE_TRACE_OS(OstTrace0(TRACE_INTERNALS, TVFS_ACCESS1, "OS;0;TVfs::Access;err=KErrGeneral"));
 		return SQLITE_IOERR_ACCESS;
 		}
-	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KFileName, &fname));
+	SQLITE_TRACE_OS(OstTraceExt2(TRACE_INTERNALS, TVFS_ACCESS_ENTRY, "OS-Entry;0;TVfs::Access;fname=%S;aFlags=0x%X", __SQLITEPRNSTR(fname), (TUint)aFlags));
 	TFhStrType fhStrType = ::FhStringProps(aFileName);
 	if(fhStrType == EFhStr)
 		{
@@ -2506,11 +2514,13 @@
 		{
 		osLayerData.SetOsErrorCode(KErrNone);
 		*aResOut = 0;
+		SQLITE_TRACE_OS(OstTrace0(TRACE_INTERNALS, TVFS_ACCESS_EXIT1, "OS-Exit;0;TVfs::Access;Exists-NoFound"));
 		return SQLITE_OK;
 		}
 	if(err != KErrNone)
 		{
 		osLayerData.SetOsErrorCode(err);
+		SQLITE_TRACE_OS(OstTrace1(TRACE_INTERNALS, TVFS_ACCESS_EXIT2, "OS-Exit;0;TVfs::Access;err=%d", err));
 		return err == KErrNoMemory ? SQLITE_IOERR_NOMEM : SQLITE_IOERR_ACCESS;
 		}
 	*aResOut = 0;
@@ -2529,6 +2539,7 @@
 			break;			
 		}
 	osLayerData.SetOsErrorCode(KErrNone);
+	SQLITE_TRACE_OS(OstTrace1(TRACE_INTERNALS, TVFS_ACCESS_EXIT3, "OS-Exit;0;TVfs::Access;aResOut=%d", *aResOut));
 	return SQLITE_OK;
 	}
 
@@ -2560,7 +2571,6 @@
 */
 /* static */ int TVfs::FullPathName(sqlite3_vfs* aVfs, const char* aRelative, int aBufLen, char* aBuf)
 	{
-	SQLUTRACE_PROFILER(aVfs);
 	__OS_CALL(EOsVfsFullPathName, 0, 0);
 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsFullPathName], ::OsCallProfile(EFalse, EOsVfsFullPathName), aBufLen, 0, 0, aRelative);
 	COsLayerData& osLayerData = COsLayerData::Instance();
@@ -2569,9 +2579,10 @@
 	TBuf<KMaxFileName + 1> fname;
 	if(!::ConvertToUnicode(aRelative, fname))
 		{
+		SQLITE_TRACE_OS(OstTrace0(TRACE_INTERNALS, TVFS_FULLPATHNAME1, "OS;0;TVfs::FullPathName;err=SQLITE_ERROR"));
 		return SQLITE_ERROR;
 		}
-	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KFileName, &fname));
+	SQLITE_TRACE_OS(OstTraceExt2(TRACE_INTERNALS, TVFS_FULLPATHNAME_ENTRY, "OS-Entry;0;TVfs::FullPathName;fname=%S;aBufLen=%d", __SQLITEPRNSTR(fname), aBufLen));
 	//Zero-terminate the converted file name
 	fname.Append(TChar(0));
 	TParse parse;
@@ -2590,8 +2601,10 @@
 	if(!::ConvertFromUnicode(parse.FullName(), dest8))
 		{//Zero the stored fh data, because it has been initialized by the FhExtractAndStore(fname) call (couple of lines above)
 		osLayerData.StoreFhData(NULL, EFalse);
+		SQLITE_TRACE_OS(OstTrace0(TRACE_INTERNALS, TVFS_FULLPATHNAME_EXIT1, "OS-Exit;0;TVfs::FullPathName;err=SQLITE_ERROR"));
 		return SQLITE_ERROR;	
 		}
+	SQLITE_TRACE_OS(OstTrace0(TRACE_INTERNALS, TVFS_FULLPATHNAME_EXIT2, "OS-Exit;0;TVfs::FullPathName;err=SQLITE_OK"));
 	return SQLITE_OK;
 	}
 
@@ -2607,7 +2620,6 @@
 */
 /* static */ int TVfs::Randomness(sqlite3_vfs* aVfs, int aBufLen, char* aBuf)
 	{
-	SQLUTRACE_PROFILER(aVfs);
 	__OS_CALL(EOsVfsRandomness, 0, 0);
 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsRandomness], ::OsCallProfile(EFalse, EOsVfsRandomness), aBufLen, 0, 0, 0);
 	COsLayerData& osLayerData = COsLayerData::Instance();
@@ -2631,7 +2643,6 @@
 */
 /* static */ int TVfs::Sleep(sqlite3_vfs* aVfs, int aMicrosec)
 	{
-	SQLUTRACE_PROFILER(aVfs);
 	__OS_CALL(EOsVfsSleep, 0, 0);
 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsSleep], ::OsCallProfile(EFalse, EOsVfsSleep), aMicrosec, 0, 0, 0);
 	User::AfterHighRes(TTimeIntervalMicroSeconds32(aMicrosec));
@@ -2651,7 +2662,6 @@
 */
 /* static */ int TVfs::CurrentTime(sqlite3_vfs* aVfs, double* aNow)
 	{
-	SQLUTRACE_PROFILER(aVfs);
 	__OS_CALL(EOsVfsCurrentTime, 0, 0);
 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsCurrentTime], ::OsCallProfile(EFalse, EOsVfsCurrentTime), 0, 0, 0, 0);
 	TTime now;
@@ -2687,7 +2697,6 @@
 */
 /* static */int TVfs::GetLastError(sqlite3_vfs* aVfs, int /*aBufLen*/, char* /*aBuf*/)
 	{
-	SQLUTRACE_PROFILER(aVfs);
 	__OS_CALL(EOsVfsGetLastError, 0, 0);
 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsGetLastError], ::OsCallProfile(EFalse, EOsVfsGetLastError), 0, 0, 0, 0);
 	return 0;
@@ -2702,9 +2711,11 @@
 
 Memory allocation routine.
 
+EXPORT_C required to match IMPORT_C in stdlib.h and avoid compiler warning
+
 @internalComponent
 */
-extern "C" void* sqlite3SymbianMalloc(size_t aSize)
+extern "C" EXPORT_C void* sqlite3SymbianMalloc(size_t aSize)
 	{
 	__MEM_CALL(EMemOpAlloc, aSize, 0);
 	return Allocator().Alloc(aSize);
@@ -2715,9 +2726,11 @@
 
 Memory reallocation routine.
 
+EXPORT_C required to match IMPORT_C in stdlib.h and avoid compiler warning
+
 @internalComponent
 */
-extern "C" void* sqlite3SymbianRealloc(void* aPtr, size_t aSize)
+extern "C" EXPORT_C void* sqlite3SymbianRealloc(void* aPtr, size_t aSize)
 	{
 #ifdef _SQLPROFILER
 	TInt size = Allocator().AllocLen(aPtr);
@@ -2731,9 +2744,11 @@
 
 Memory free routine.
 
+EXPORT_C required to match IMPORT_C in stdlib.h and avoid compiler warning
+
 @internalComponent
 */
-extern "C" void sqlite3SymbianFree(void* aPtr)
+extern "C" EXPORT_C void sqlite3SymbianFree(void* aPtr)
 	{
 #ifdef _SQLPROFILER
 	TInt size = Allocator().AllocLen(aPtr);