persistentstorage/sql/OsLayer/os_symbian.cpp
branchGCC_SURGE
changeset 38 c4e342fcf0c8
parent 35 0d6db0a14001
child 41 3256212fc81f
equal deleted inserted replaced
27:ba32e40d9f36 38:c4e342fcf0c8
    81 	EPanicInvalidSectorSize		=18,
    81 	EPanicInvalidSectorSize		=18,
    82 	EPanicInternalError			=19,
    82 	EPanicInternalError			=19,
    83 	EPanicNullDbFilePtr			=20,
    83 	EPanicNullDbFilePtr			=20,
    84 	EPanicFastCounterFreq		=21
    84 	EPanicFastCounterFreq		=21
    85 	};
    85 	};
       
    86 
       
    87 //Bit-mask constant. If xOpen()'s "aFlag" parameter contains one of these bits set, then the the file top be
       
    88 //opened or created is a journal file.
       
    89 const TUint KJournalFileTypeBitMask = SQLITE_OPEN_MAIN_JOURNAL | SQLITE_OPEN_TEMP_JOURNAL | SQLITE_OPEN_SUBJOURNAL | SQLITE_OPEN_MASTER_JOURNAL; 
    86 
    90 
    87 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    91 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    88 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    92 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    89 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    93 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    90 #ifdef _SQLPROFILER
    94 #ifdef _SQLPROFILER
   326 	// - iCallCounter - how many times the monitored OS porting layer function has been called;	
   330 	// - iCallCounter - how many times the monitored OS porting layer function has been called;	
   327 	// - iTicksTotal  - the total amount of time in ticks spent in the monitored OS porting layer function;	
   331 	// - iTicksTotal  - the total amount of time in ticks spent in the monitored OS porting layer function;	
   328 	// - iBytesTotal  - the total amount of bytes passed to the monitored OS porting layer function (if it is read or write);
   332 	// - iBytesTotal  - the total amount of bytes passed to the monitored OS porting layer function (if it is read or write);
   329 	struct TOsCallProfile
   333 	struct TOsCallProfile
   330 		{
   334 		{
   331 		TOsCallProfile(char aType, char aIdentifier[]) :
   335 		TOsCallProfile(char aType, const TDesC& aIdentifier) :
   332 			iType(aType),
   336 			iType(aType),
       
   337 			iIdentifier(aIdentifier),
   333 			iCallCounter(0),
   338 			iCallCounter(0),
   334 			iTicksTotal(0),
   339 			iTicksTotal(0),
   335 			iBytesTotal(0)
   340 			iBytesTotal(0)
   336 			{
   341 			{
   337 			iIdentifier[0] = aIdentifier[0];
       
   338 			iIdentifier[1] = aIdentifier[1];
       
   339 			}
   342 			}
   340 		void Zero()
   343 		void Zero()
   341 			{
   344 			{
   342 			iCallCounter = 0;	
   345 			iCallCounter = 0;	
   343 			iTicksTotal = 0;	
   346 			iTicksTotal = 0;	
   344 			iBytesTotal = 0;
   347 			iBytesTotal = 0;
   345 			}
   348 			}
   346 		char	iType;
   349 		char	iType;
   347 		char	iIdentifier[2];
   350 		TBuf<32> iIdentifier;
   348 		TInt	iCallCounter;
   351 		TInt	iCallCounter;
   349 		TInt64	iTicksTotal;
   352 		TInt64	iTicksTotal;
   350 		TInt64	iBytesTotal;
   353 		TInt64	iBytesTotal;
   351 		};
   354 		};
   352 
   355 
   353 	//An array of TOsCallProfile entries, each entry keeps the profile of a specifc OS porting layer function, when
   356 	//An array of TOsCallProfile entries, each entry keeps the profile of a specifc OS porting layer function, when
   354 	//the function was used on the main database file
   357 	//the function was used on the main database file
   355 	TOsCallProfile TheOsCallMProfile[EOsOpLast] = 
   358 	TOsCallProfile TheOsCallMProfile[EOsOpLast] = 
   356 		{
   359 		{
   357 		TOsCallProfile('M', "CL"), TOsCallProfile('M', "RD"), TOsCallProfile('M', "WR"), TOsCallProfile('M', "TR"),
   360 		TOsCallProfile('M', _L("Close")), TOsCallProfile('M', _L("Read")), TOsCallProfile('M', _L("Write")), TOsCallProfile('M', _L("Truncate")),
   358 		TOsCallProfile('M', "SY"), TOsCallProfile('M', "FS"), TOsCallProfile('M', "LK"), TOsCallProfile('M', "UL"),
   361 		TOsCallProfile('M', _L("Sync")), TOsCallProfile('M', _L("Size")), TOsCallProfile('M', _L("Lock")), TOsCallProfile('M', _L("Unlock")),
   359 		TOsCallProfile('M', "CL"), TOsCallProfile('M', "FC"), TOsCallProfile('M', "SS"), TOsCallProfile('M', "DC"),
   362 		TOsCallProfile('M', _L("CheckReservedLock")), TOsCallProfile('M', _L("FileControl")), TOsCallProfile('M', _L("SetSize")), TOsCallProfile('M', _L("DeviceCharacteristics")),
   360 		TOsCallProfile('M', "OP"), TOsCallProfile('M', "DE"), TOsCallProfile('M', "AC"), TOsCallProfile('M', "FN"),
   363 		TOsCallProfile('M', _L("Open")), TOsCallProfile('M', _L("Delete")), TOsCallProfile('M', _L("Access")), TOsCallProfile('M', _L("FullPath")),
   361 		TOsCallProfile('M', "RN"), TOsCallProfile('M', "SL"), TOsCallProfile('M', "CT"), TOsCallProfile('M', "LE")
   364 		TOsCallProfile('M', _L("Randomness")), TOsCallProfile('M', _L("Sleep")), TOsCallProfile('M', _L("CurrentTime")), TOsCallProfile('M', _L("GetLastError"))
   362 		};
   365 		};
   363 
   366 
   364 	//An array of TOsCallProfile entries, each entry keeps the profile of a specifc OS porting layer function, when
   367 	//An array of TOsCallProfile entries, each entry keeps the profile of a specifc OS porting layer function, when
   365 	//the function was used on the journal file
   368 	//the function was used on the journal file
   366 	TOsCallProfile TheOsCallJProfile[EOsOpLast] = 
   369 	TOsCallProfile TheOsCallJProfile[EOsOpLast] = 
   367 		{
   370 		{
   368 		TOsCallProfile('J', "CL"), TOsCallProfile('J', "RD"), TOsCallProfile('J', "WR"), TOsCallProfile('J', "TR"),
   371 		TOsCallProfile('J', _L("Close")), TOsCallProfile('J', _L("Read")), TOsCallProfile('J', _L("Write")), TOsCallProfile('J', _L("Truncate")),
   369 		TOsCallProfile('J', "SY"), TOsCallProfile('J', "FS"), TOsCallProfile('J', "LK"), TOsCallProfile('J', "UL"),
   372 		TOsCallProfile('J', _L("Sync")), TOsCallProfile('J', _L("Size")), TOsCallProfile('J', _L("Lock")), TOsCallProfile('J', _L("Unlock")),
   370 		TOsCallProfile('J', "CL"), TOsCallProfile('J', "FC"), TOsCallProfile('J', "SS"), TOsCallProfile('J', "DC"),
   373 		TOsCallProfile('J', _L("CheckReservedLock")), TOsCallProfile('J', _L("FileControl")), TOsCallProfile('J', _L("SetSize")), TOsCallProfile('J', _L("DeviceCharacteristics")),
   371 		TOsCallProfile('J', "OP"), TOsCallProfile('J', "DE"), TOsCallProfile('J', "AC"), TOsCallProfile('J', "FN"),
   374 		TOsCallProfile('J', _L("Open")), TOsCallProfile('J', _L("Delete")), TOsCallProfile('J', _L("Access")), TOsCallProfile('J', _L("FullPath")),
   372 		TOsCallProfile('J', "RN"), TOsCallProfile('J', "SL"), TOsCallProfile('J', "CT"), TOsCallProfile('J', "LE")
   375 		TOsCallProfile('J', _L("Randomness")), TOsCallProfile('J', _L("Sleep")), TOsCallProfile('J', _L("CurrentTime")), TOsCallProfile('J', _L("GetLastError"))
   373 		};
   376 		};
   374 	
   377 	
   375 	//The main class for the OS porting layer call profiles.
   378 	//The main class for the OS porting layer call profiles.
   376 	class TOsCallCounter
   379 	class TOsCallCounter
   377 		{
   380 		{
   378 	public:
   381 	public:
   379 		//aOsCallTicksEntryRef - a reference to the related TheOsCallTicks[] entry;
   382 		//aOsCallTicksEntryRef - a reference to the related TheOsCallTicks[] entry;
   380 		//aProfileRef          - a reference to the related TOsCallProfile object - TheOsCallMProfile[] or TheOsCallJProfile[] entry;
   383 		//aProfileRef          - a reference to the related TOsCallProfile object - TheOsCallMProfile[] or TheOsCallJProfile[] entry;
   381 		//aOffset              - file offset in bytes;
   384 		//aOffset              - file offset in bytes;
   382 		//aBytes               - amount of bytes to be read/written;
   385 		//aBytes               - amount of bytes to be read/written;
   383 		TOsCallCounter(TInt64& aOsCallTicksEntryRef, TOsCallProfile& aOsCallProfileRef, TInt64 aOffset, TInt aBytes) :
   386 		//aOptional			   - might be NULL. Used to print out the name of the file being processed.
       
   387 		TOsCallCounter(TInt64& aOsCallTicksEntryRef, TOsCallProfile& aOsCallProfileRef, TInt64 aOffset, TInt aBytes, 
       
   388 				       const sqlite3_file* aHandle, const char* aOptional) :
   384 			iOsCallTicksEntryRef(aOsCallTicksEntryRef),
   389 			iOsCallTicksEntryRef(aOsCallTicksEntryRef),
   385 			iOsCallProfileRef(aOsCallProfileRef),
   390 			iOsCallProfileRef(aOsCallProfileRef),
   386 			iOffset(aOffset),
   391 			iOffset(aOffset),
   387 			iBytes(aBytes)	
   392 			iBytes(aBytes),
       
   393 			iHandle((TUint)aHandle),
       
   394 			iOptional((const TUint8*)aOptional)
   388 			{
   395 			{
   389 			if(TheOsCallTimeProfileEnabled)
   396 			if(TheOsCallTimeProfileEnabled)
   390 				{
   397 				{
   391 				iStartTicks = User::FastCounter();
   398 				iStartTicks = User::FastCounter();
   392 				}
   399 				}
   405 					{
   412 					{
   406 					++TheOpCounter;
   413 					++TheOpCounter;
   407 					++iOsCallProfileRef.iCallCounter;
   414 					++iOsCallProfileRef.iCallCounter;
   408 					iOsCallProfileRef.iTicksTotal += diffTicks;
   415 					iOsCallProfileRef.iTicksTotal += diffTicks;
   409 					iOsCallProfileRef.iBytesTotal += iBytes;
   416 					iOsCallProfileRef.iBytesTotal += iBytes;
   410 					//                 1    2 3   4  5  6   7   8   9   10
   417 					TFileName fname;
   411 					RDebug::Print(_L("'%c','%c%c',%d,%d,%ld,%d,%ld,%ld,%ld\n"), 
   418 					if(iOptional)
   412 						iOsCallProfileRef.iType, 			//1
   419 						{
   413 						iOsCallProfileRef.iIdentifier[0], 	//2
   420 						TPtrC8 fn8(iOptional);
   414 						iOsCallProfileRef.iIdentifier[1],	//3
   421 						fname.Copy(fn8);
   415 						TheOpCounter, 						//4
   422 						}
   416 						iOsCallProfileRef.iCallCounter, 	//5
   423 					//                                           0    1  2  3  4  5   6  7   8   9   10
   417 						iOffset, 							//6
   424 					RDebug::Print(_L("[SQL-OS]¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬\"%X\"¬%c¬%S¬%d¬%d¬%ld¬%d¬%ld¬%ld¬%ld¬%S\n"),
   418 						iBytes, 							//7
   425 															//[SQL-OS]
   419 						diffTicks, 							//8
   426 															//Handle
   420 						iOsCallProfileRef.iBytesTotal, 		//9
   427 															//Time from start, microseconds
   421 						iOsCallProfileRef.iTicksTotal);		//10
   428 															//Subtype
       
   429 															//IPC sequence counter
       
   430 															//IPC call name
       
   431 					    iHandle,							//sqlite3_file*
       
   432 						iOsCallProfileRef.iType, 			//1 - main or journal file
       
   433 						&iOsCallProfileRef.iIdentifier, 	//2 - operation type
       
   434 						TheOpCounter, 						//3 - Operation counter
       
   435 						iOsCallProfileRef.iCallCounter, 	//4 - This call type counter
       
   436 						iOffset, 							//5 - File offset
       
   437 						iBytes, 							//6 - Data, bytes
       
   438 						diffTicks, 							//7 - Ticks
       
   439 						iOsCallProfileRef.iBytesTotal, 		//8 - Data total, bytes
       
   440 						iOsCallProfileRef.iTicksTotal,		//9 - Ticks total
       
   441 						&fname);							//10- File name
   422 					}
   442 					}
   423 				}
   443 				}
   424 			}
   444 			}
   425 	private:
   445 	private:
   426 		TInt64&			iOsCallTicksEntryRef;
   446 		TInt64&			iOsCallTicksEntryRef;
   427 		TOsCallProfile&	iOsCallProfileRef;
   447 		TOsCallProfile&	iOsCallProfileRef;
   428 		TInt64			iOffset;
   448 		TInt64			iOffset;
   429 		TInt			iBytes;			
   449 		TInt			iBytes;			
   430 		TUint32 		iStartTicks;
   450 		TUint32 		iStartTicks;
       
   451 		TUint			iHandle;
       
   452 		const TUint8*	iOptional;
   431 		};
   453 		};
   432 		
   454 		
   433 	inline TOsCallProfile& OsCallProfile(TBool aType, TInt aIndex)
   455 	inline TOsCallProfile& OsCallProfile(TBool aType, TInt aIndex)
   434 		{
   456 		{
   435 		return aType ? TheOsCallJProfile[aIndex] : TheOsCallMProfile[aIndex];
   457 		return aType ? TheOsCallJProfile[aIndex] : TheOsCallMProfile[aIndex];
   436 		}
   458 		}
   437 		
   459 		
   438 #	define __OSTIME_COUNTER(aOsCallTicksRef, aOsCallProfileRef, aOffset, aBytes)	TOsCallCounter osCallCounter(aOsCallTicksRef, aOsCallProfileRef, aOffset, aBytes)
   460 #	define __OSTIME_COUNTER(aOsCallTicksRef, aOsCallProfileRef, aOffset, aBytes, aHandle, aOpt)	TOsCallCounter osCallCounter(aOsCallTicksRef, aOsCallProfileRef, aOffset, aBytes, aHandle, aOpt)
   439 
   461 
   440 #else //_SQLPROFILER
   462 #else //_SQLPROFILER
   441 
   463 
   442 #   define __COUNTER_INCR(counter) void(0)
   464 #   define __COUNTER_INCR(counter) void(0)
   443 	
   465 	
   445 
   467 
   446 #	define __MEM_CALL(aMemOpType, a1, a2) void(0)
   468 #	define __MEM_CALL(aMemOpType, a1, a2) void(0)
   447 
   469 
   448 #	define __OS_CALL(aOpType, a1, a2) void(0)
   470 #	define __OS_CALL(aOpType, a1, a2) void(0)
   449 
   471 
   450 #	define __OSTIME_COUNTER(aOsCallTicksRef, aOsCallProfileRef, aOffset, aBytes)	void(0)
   472 #	define __OSTIME_COUNTER(aOsCallTicksRef, aOsCallProfileRef, aOffset, aBytes, aHandle, aOpt)	void(0)
   451 
   473 
   452 #endif//_SQLPROFILER
   474 #endif//_SQLPROFILER
   453 
   475 
   454 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   476 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   455 /////////////////////       Profiling                          ////////////////////////////////////////////////////////////////
   477 /////////////////////       Profiling                          ////////////////////////////////////////////////////////////////
  1216 	{
  1238 	{
  1217 	if(aFileName)
  1239 	if(aFileName)
  1218 		{
  1240 		{
  1219 		wchar_t* dest = reinterpret_cast <wchar_t*> (const_cast <TUint16*> (aFileNameDestBuf.Ptr()));
  1241 		wchar_t* dest = reinterpret_cast <wchar_t*> (const_cast <TUint16*> (aFileNameDestBuf.Ptr()));
  1220 		TInt len = mbstowcs(dest, aFileName, aFileNameDestBuf.MaxLength());
  1242 		TInt len = mbstowcs(dest, aFileName, aFileNameDestBuf.MaxLength());
       
  1243 		__ASSERT_DEBUG(len >= 0, User::Panic(KPanicCategory, EPanicInternalError));
  1221 		//If len == aFileNameDestBuf.MaxLength(), then the output buffer is too small.
  1244 		//If len == aFileNameDestBuf.MaxLength(), then the output buffer is too small.
  1222 		if(len > 0 && len < aFileNameDestBuf.MaxLength())
  1245 		if(len < aFileNameDestBuf.MaxLength())
  1223 			{
  1246 			{
  1224 			aFileNameDestBuf.SetLength(len);
  1247 			aFileNameDestBuf.SetLength(len);
  1225 			return ETrue;
  1248 			return ETrue;
  1226 			}
  1249 			}
  1227 		}
  1250 		}
  1244 static TBool ConvertFromUnicode(const TDesC& aFileName, TDes8& aFileNameDestBuf)
  1267 static TBool ConvertFromUnicode(const TDesC& aFileName, TDes8& aFileNameDestBuf)
  1245 	{
  1268 	{
  1246 	char* dest = reinterpret_cast <char*> (const_cast <TUint8*> (aFileNameDestBuf.Ptr()));
  1269 	char* dest = reinterpret_cast <char*> (const_cast <TUint8*> (aFileNameDestBuf.Ptr()));
  1247 	const wchar_t* src = reinterpret_cast <const wchar_t*> (aFileName.Ptr());
  1270 	const wchar_t* src = reinterpret_cast <const wchar_t*> (aFileName.Ptr());
  1248 	TInt len = wcstombs(dest, src, aFileNameDestBuf.MaxLength());
  1271 	TInt len = wcstombs(dest, src, aFileNameDestBuf.MaxLength());
       
  1272 	__ASSERT_DEBUG(len >= 0, User::Panic(KPanicCategory, EPanicInternalError));
  1249 	//If len == aFileNameDestBuf.MaxLength(), then the output buffer is too small.
  1273 	//If len == aFileNameDestBuf.MaxLength(), then the output buffer is too small.
  1250 	if(len > 0 && len < aFileNameDestBuf.MaxLength())
  1274 	if(len < aFileNameDestBuf.MaxLength())
  1251 		{
  1275 		{
  1252 		aFileNameDestBuf.SetLength(len);
  1276 		aFileNameDestBuf.SetLength(len);
  1253 		return ETrue;
  1277 		return ETrue;
  1254 		}
  1278 		}
  1255 	return EFalse;
  1279 	return EFalse;
  1475 /* static */ int TFileIo::Close(sqlite3_file* aDbFile)
  1499 /* static */ int TFileIo::Close(sqlite3_file* aDbFile)
  1476 	{
  1500 	{
  1477 	SQLUTRACE_PROFILER(aDbFile);
  1501 	SQLUTRACE_PROFILER(aDbFile);
  1478 	TDbFile& dbFile = ::DbFile(aDbFile);
  1502 	TDbFile& dbFile = ::DbFile(aDbFile);
  1479 	__OS_CALL(EOsFileClose, 0, 0);
  1503 	__OS_CALL(EOsFileClose, 0, 0);
  1480 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileClose], ::OsCallProfile(dbFile.iIsJournal, EOsFileClose), 0, 0);
  1504 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileClose], ::OsCallProfile(dbFile.iIsJournal, EOsFileClose), 0, 0, aDbFile, 0);
  1481 	__FS_CALL(EFsOpFileClose, 0);
  1505 	__FS_CALL(EFsOpFileClose, 0);
  1482 	dbFile.iFileBuf.Close();
  1506 	dbFile.iFileBuf.Close();
  1483 	if(dbFile.iFullName)
  1507 	if(dbFile.iFullName)
  1484 		{//"iFullName" will not be NULL only when TVfs::Open() is called with SQLITE_OPEN_DELETEONCLOSE flag.
  1508 		{//"iFullName" will not be NULL only when TVfs::Open() is called with SQLITE_OPEN_DELETEONCLOSE flag.
  1485 		 //That means - SQlite expects the file to be deleted after the file close operation. 
  1509 		 //That means - SQlite expects the file to be deleted after the file close operation. 
  1517 	SQLUTRACE_PROFILER(aDbFile);
  1541 	SQLUTRACE_PROFILER(aDbFile);
  1518 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KFileRead, aAmt, aOffset));
  1542 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KFileRead, aAmt, aOffset));
  1519 	TDbFile& dbFile = ::DbFile(aDbFile);
  1543 	TDbFile& dbFile = ::DbFile(aDbFile);
  1520 	__OS_CALL(EOsFileRead, 0, 0);
  1544 	__OS_CALL(EOsFileRead, 0, 0);
  1521 	__COUNTER_INCR(TheSqlSrvProfilerFileRead);
  1545 	__COUNTER_INCR(TheSqlSrvProfilerFileRead);
  1522 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileRead], ::OsCallProfile(dbFile.iIsJournal, EOsFileRead), aOffset, aAmt);
  1546 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileRead], ::OsCallProfile(dbFile.iIsJournal, EOsFileRead), aOffset, aAmt, aDbFile, 0);
  1523 	TPtr8 ptr((TUint8*)aBuf, 0, aAmt);
  1547 	TPtr8 ptr((TUint8*)aBuf, 0, aAmt);
  1524 	TInt err = dbFile.iFileBuf.Read(aOffset, ptr);
  1548 	TInt err = dbFile.iFileBuf.Read(aOffset, ptr);
  1525 	TInt cnt = ptr.Length();
  1549 	TInt cnt = ptr.Length();
  1526 	TInt sqliteErr = SQLITE_IOERR_READ;
  1550 	TInt sqliteErr = SQLITE_IOERR_READ;
  1527 	switch(err)
  1551 	switch(err)
  1580 	SQLUTRACE_PROFILER(aDbFile);
  1604 	SQLUTRACE_PROFILER(aDbFile);
  1581 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KFileWrite, aAmt, aOffset));
  1605 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KFileWrite, aAmt, aOffset));
  1582 	TDbFile& dbFile = ::DbFile(aDbFile);
  1606 	TDbFile& dbFile = ::DbFile(aDbFile);
  1583 	__OS_CALL(EOsFileWrite, 0, 0);
  1607 	__OS_CALL(EOsFileWrite, 0, 0);
  1584     __COUNTER_INCR(TheSqlSrvProfilerFileWrite);
  1608     __COUNTER_INCR(TheSqlSrvProfilerFileWrite);
  1585 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileWrite], ::OsCallProfile(dbFile.iIsJournal, EOsFileWrite), aOffset, aAmt);
  1609 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileWrite], ::OsCallProfile(dbFile.iIsJournal, EOsFileWrite), aOffset, aAmt, aDbFile, 0);
  1586 	TInt err = KErrAccessDenied;
  1610 	TInt err = KErrAccessDenied;
  1587 	if(!dbFile.iReadOnly)
  1611 	if(!dbFile.iReadOnly)
  1588 		{
  1612 		{
  1589 		TPtrC8 ptr((const TUint8*)aData, aAmt);
  1613 		TPtrC8 ptr((const TUint8*)aData, aAmt);
  1590 		err = dbFile.iFileBuf.Write(aOffset, ptr);
  1614 		err = dbFile.iFileBuf.Write(aOffset, ptr);
  1634 	SQLUTRACE_PROFILER(aDbFile);
  1658 	SQLUTRACE_PROFILER(aDbFile);
  1635 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KFileTruncate, aLength));
  1659 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KFileTruncate, aLength));
  1636 	TDbFile& dbFile = ::DbFile(aDbFile);
  1660 	TDbFile& dbFile = ::DbFile(aDbFile);
  1637 	__OS_CALL(EOsFileTruncate, 0, 0);
  1661 	__OS_CALL(EOsFileTruncate, 0, 0);
  1638     __COUNTER_INCR(TheSqlSrvProfilerFileSetSize);
  1662     __COUNTER_INCR(TheSqlSrvProfilerFileSetSize);
  1639 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileTruncate], ::OsCallProfile(dbFile.iIsJournal, EOsFileTruncate), aLength, 0);
  1663 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileTruncate], ::OsCallProfile(dbFile.iIsJournal, EOsFileTruncate), aLength, 0, aDbFile, 0);
  1640 	if(dbFile.iReadOnly)
  1664 	if(dbFile.iReadOnly)
  1641 		{
  1665 		{
  1642 		COsLayerData::Instance().SetOsErrorCode(KErrAccessDenied);
  1666 		COsLayerData::Instance().SetOsErrorCode(KErrAccessDenied);
  1643   		return SQLITE_IOERR;	
  1667   		return SQLITE_IOERR;	
  1644 		}
  1668 		}
  1670 	{
  1694 	{
  1671 	SQLUTRACE_PROFILER(aDbFile);
  1695 	SQLUTRACE_PROFILER(aDbFile);
  1672 	TDbFile& dbFile = ::DbFile(aDbFile);
  1696 	TDbFile& dbFile = ::DbFile(aDbFile);
  1673 	__OS_CALL(EOsFileSync, 0, 0);
  1697 	__OS_CALL(EOsFileSync, 0, 0);
  1674     __COUNTER_INCR(TheSqlSrvProfilerFileSync);
  1698     __COUNTER_INCR(TheSqlSrvProfilerFileSync);
  1675 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileSync], ::OsCallProfile(dbFile.iIsJournal, EOsFileSync), 0, 0);
  1699 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileSync], ::OsCallProfile(dbFile.iIsJournal, EOsFileSync), 0, 0, aDbFile, 0);
  1676 	if(dbFile.iReadOnly)
  1700 	if(dbFile.iReadOnly)
  1677 		{
  1701 		{
  1678 		COsLayerData::Instance().SetOsErrorCode(KErrAccessDenied);
  1702 		COsLayerData::Instance().SetOsErrorCode(KErrAccessDenied);
  1679 		return SQLITE_IOERR;
  1703 		return SQLITE_IOERR;
  1680 		}
  1704 		}
  1705 /* static */ int TFileIo::FileSize(sqlite3_file* aDbFile, sqlite3_int64* aSize)
  1729 /* static */ int TFileIo::FileSize(sqlite3_file* aDbFile, sqlite3_int64* aSize)
  1706 	{
  1730 	{
  1707 	SQLUTRACE_PROFILER(aDbFile);
  1731 	SQLUTRACE_PROFILER(aDbFile);
  1708 	TDbFile& dbFile = ::DbFile(aDbFile);
  1732 	TDbFile& dbFile = ::DbFile(aDbFile);
  1709 	__OS_CALL(EOsFileFileSize, 0, 0);
  1733 	__OS_CALL(EOsFileFileSize, 0, 0);
  1710 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileFileSize], ::OsCallProfile(dbFile.iIsJournal, EOsFileFileSize), 0, 0);
  1734 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileFileSize], ::OsCallProfile(dbFile.iIsJournal, EOsFileFileSize), 0, 0, aDbFile, 0);
  1711 	__FS_CALL(EFsOpFileSize, 0);
  1735 	__FS_CALL(EFsOpFileSize, 0);
  1712 	TInt err =  dbFile.iFileBuf.Size(*aSize);
  1736 	TInt err =  dbFile.iFileBuf.Size(*aSize);
  1713 	COsLayerData::Instance().SetOsErrorCode(err);
  1737 	COsLayerData::Instance().SetOsErrorCode(err);
  1714 	if(err == KErrNone)
  1738 	if(err == KErrNone)
  1715 		{
  1739 		{
  1739 /* static */ int TFileIo::Lock(sqlite3_file* aDbFile, int aLockType)
  1763 /* static */ int TFileIo::Lock(sqlite3_file* aDbFile, int aLockType)
  1740 	{
  1764 	{
  1741 	SQLUTRACE_PROFILER(aDbFile);
  1765 	SQLUTRACE_PROFILER(aDbFile);
  1742 	TDbFile& dbFile = ::DbFile(aDbFile);
  1766 	TDbFile& dbFile = ::DbFile(aDbFile);
  1743 	__OS_CALL(EOsFileLock, 0, 0);
  1767 	__OS_CALL(EOsFileLock, 0, 0);
  1744 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileLock], ::OsCallProfile(dbFile.iIsJournal, EOsFileLock), aLockType, 0);
  1768 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileLock], ::OsCallProfile(dbFile.iIsJournal, EOsFileLock), aLockType, 0, aDbFile, 0);
  1745 	//If there is already a lock of this type or more restrictive on the database file, do nothing.
  1769 	//If there is already a lock of this type or more restrictive on the database file, do nothing.
  1746 	if(dbFile.iLockType >= aLockType)
  1770 	if(dbFile.iLockType >= aLockType)
  1747 		{
  1771 		{
  1748 		return SQLITE_OK;
  1772 		return SQLITE_OK;
  1749 		}
  1773 		}
  1772 /* static */ int TFileIo::Unlock(sqlite3_file* aDbFile, int aLockType)
  1796 /* static */ int TFileIo::Unlock(sqlite3_file* aDbFile, int aLockType)
  1773 	{
  1797 	{
  1774 	SQLUTRACE_PROFILER(aDbFile);
  1798 	SQLUTRACE_PROFILER(aDbFile);
  1775 	TDbFile& dbFile = ::DbFile(aDbFile);
  1799 	TDbFile& dbFile = ::DbFile(aDbFile);
  1776 	__OS_CALL(EOsFileUnlock, 0, 0);
  1800 	__OS_CALL(EOsFileUnlock, 0, 0);
  1777 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileUnlock], ::OsCallProfile(dbFile.iIsJournal, EOsFileUnlock), aLockType, 0);
  1801 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileUnlock], ::OsCallProfile(dbFile.iIsJournal, EOsFileUnlock), aLockType, 0, aDbFile, 0);
  1778 	dbFile.iLockType = aLockType;
  1802 	dbFile.iLockType = aLockType;
  1779 	return SQLITE_OK;
  1803 	return SQLITE_OK;
  1780 	}
  1804 	}
  1781 
  1805 
  1782 /**
  1806 /**
  1801 /* static */ int TFileIo::CheckReservedLock(sqlite3_file* aDbFile, int *aResOut)
  1825 /* static */ int TFileIo::CheckReservedLock(sqlite3_file* aDbFile, int *aResOut)
  1802 	{
  1826 	{
  1803 	SQLUTRACE_PROFILER(aDbFile);
  1827 	SQLUTRACE_PROFILER(aDbFile);
  1804 	TDbFile& dbFile = ::DbFile(aDbFile);
  1828 	TDbFile& dbFile = ::DbFile(aDbFile);
  1805 	__OS_CALL(EOsFileCheckReservedLock, 0, 0);
  1829 	__OS_CALL(EOsFileCheckReservedLock, 0, 0);
  1806 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileCheckReservedLock], ::OsCallProfile(dbFile.iIsJournal, EOsFileCheckReservedLock), 0, 0);
  1830 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileCheckReservedLock], ::OsCallProfile(dbFile.iIsJournal, EOsFileCheckReservedLock), 0, 0, aDbFile, 0);
  1807 	*aResOut = dbFile.iLockType >= SQLITE_LOCK_RESERVED ? 1 : 0;
  1831 	*aResOut = dbFile.iLockType >= SQLITE_LOCK_RESERVED ? 1 : 0;
  1808   	return SQLITE_OK;
  1832   	return SQLITE_OK;
  1809 	}
  1833 	}
  1810 
  1834 
  1811 /**
  1835 /**
  1837 	{
  1861 	{
  1838 	SQLUTRACE_PROFILER(aDbFile);
  1862 	SQLUTRACE_PROFILER(aDbFile);
  1839 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KFileFileCtr, aOp));
  1863 	SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KFileFileCtr, aOp));
  1840 	TDbFile& dbFile = ::DbFile(aDbFile);
  1864 	TDbFile& dbFile = ::DbFile(aDbFile);
  1841 	__OS_CALL(EOsFileFileControl, 0, 0);
  1865 	__OS_CALL(EOsFileFileControl, 0, 0);
  1842 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileFileControl], ::OsCallProfile(dbFile.iIsJournal, EOsFileFileControl), aOp, 0);
  1866 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileFileControl], ::OsCallProfile(dbFile.iIsJournal, EOsFileFileControl), aOp, 0, aDbFile, 0);
  1843 	TInt err = KErrNone;
  1867 	TInt err = KErrNone;
  1844 	switch(aOp)
  1868 	switch(aOp)
  1845 		{
  1869 		{
  1846 		case SQLITE_FCNTL_LOCKSTATE:
  1870 		case SQLITE_FCNTL_LOCKSTATE:
  1847 			*(int*)aArg = dbFile.iLockType;
  1871 			*(int*)aArg = dbFile.iLockType;
  1888 /* static */ int TFileIo::SectorSize(sqlite3_file* aDbFile)
  1912 /* static */ int TFileIo::SectorSize(sqlite3_file* aDbFile)
  1889 	{
  1913 	{
  1890 	SQLUTRACE_PROFILER(aDbFile);
  1914 	SQLUTRACE_PROFILER(aDbFile);
  1891 	TDbFile& dbFile = ::DbFile(aDbFile);
  1915 	TDbFile& dbFile = ::DbFile(aDbFile);
  1892 	__OS_CALL(EOsFileSectorSize, 0, 0);
  1916 	__OS_CALL(EOsFileSectorSize, 0, 0);
  1893 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileSectorSize], ::OsCallProfile(dbFile.iIsJournal, EOsFileSectorSize), 0, 0);
  1917 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileSectorSize], ::OsCallProfile(dbFile.iIsJournal, EOsFileSectorSize), 0, 0, aDbFile, 0);
  1894 	__ASSERT_DEBUG(dbFile.iSectorSize > 0, User::Panic(KPanicCategory, EPanicInternalError));
  1918 	__ASSERT_DEBUG(dbFile.iSectorSize > 0, User::Panic(KPanicCategory, EPanicInternalError));
  1895 	if(dbFile.iSectorSize > 0)
  1919 	if(dbFile.iSectorSize > 0)
  1896 		{
  1920 		{
  1897 		return dbFile.iSectorSize;	
  1921 		return dbFile.iSectorSize;	
  1898 		}
  1922 		}
  1919 /* static */ int TFileIo::DeviceCharacteristics(sqlite3_file* aDbFile)
  1943 /* static */ int TFileIo::DeviceCharacteristics(sqlite3_file* aDbFile)
  1920 	{
  1944 	{
  1921 	SQLUTRACE_PROFILER(aDbFile);
  1945 	SQLUTRACE_PROFILER(aDbFile);
  1922 	TDbFile& dbFile = ::DbFile(aDbFile);
  1946 	TDbFile& dbFile = ::DbFile(aDbFile);
  1923 	__OS_CALL(EOsFileDeviceCharacteristics, 0, 0);
  1947 	__OS_CALL(EOsFileDeviceCharacteristics, 0, 0);
  1924 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileDeviceCharacteristics], ::OsCallProfile(dbFile.iIsJournal, EOsFileDeviceCharacteristics), 0, 0);
  1948 	__OSTIME_COUNTER(TheOsCallTicks[EOsFileDeviceCharacteristics], ::OsCallProfile(dbFile.iIsJournal, EOsFileDeviceCharacteristics), 0, 0, aDbFile, 0);
  1925 	__ASSERT_DEBUG(dbFile.iDeviceCharacteristics >= 0, User::Panic(KPanicCategory, EPanicInternalError));
  1949 	__ASSERT_DEBUG(dbFile.iDeviceCharacteristics >= 0, User::Panic(KPanicCategory, EPanicInternalError));
  1926 	if(dbFile.iDeviceCharacteristics >= 0)
  1950 	if(dbFile.iDeviceCharacteristics >= 0)
  1927 		{
  1951 		{
  1928 		return dbFile.iDeviceCharacteristics;	
  1952 		return dbFile.iDeviceCharacteristics;	
  1929 		}
  1953 		}
  2003 		}
  2027 		}
  2004 	if(aDriveInfo.iDriveAtt & KDriveAttTransaction)
  2028 	if(aDriveInfo.iDriveAtt & KDriveAttTransaction)
  2005 		{
  2029 		{
  2006 		deviceCharacteristics |= SQLITE_IOCAP_ATOMIC;	
  2030 		deviceCharacteristics |= SQLITE_IOCAP_ATOMIC;	
  2007 		}
  2031 		}
  2008 	if(aVolumeInfo.iBlockSize >= SQLITE_DEFAULT_SECTOR_SIZE && (aVolumeInfo.iBlockSize & (aVolumeInfo.iBlockSize - 1)) == 0)	
  2032 	switch(aVolumeInfo.iBlockSize)
  2009 		{
  2033 		{
  2010 		switch(aVolumeInfo.iBlockSize)
  2034 		case 512:
  2011 			{
  2035 			deviceCharacteristics |= SQLITE_IOCAP_ATOMIC512;
  2012 			case 512:
  2036 			break;
  2013 				deviceCharacteristics |= SQLITE_IOCAP_ATOMIC512;
  2037 		case 1024:
  2014 				break;
  2038 			deviceCharacteristics |= SQLITE_IOCAP_ATOMIC1K;
  2015 			case 1024:
  2039 			break;
  2016 				deviceCharacteristics |= SQLITE_IOCAP_ATOMIC1K;
  2040 		case 2048:
  2017 				break;
  2041 			deviceCharacteristics |= SQLITE_IOCAP_ATOMIC2K;
  2018 			case 2048:
  2042 			break;
  2019 				deviceCharacteristics |= SQLITE_IOCAP_ATOMIC2K;
  2043 		case 4096:
  2020 				break;
  2044 			deviceCharacteristics |= SQLITE_IOCAP_ATOMIC4K;
  2021 			case 4096:
  2045 			break;
  2022 				deviceCharacteristics |= SQLITE_IOCAP_ATOMIC4K;
  2046 		case 8192:
  2023 				break;
  2047 			deviceCharacteristics |= SQLITE_IOCAP_ATOMIC8K;
  2024 			case 8192:
  2048 			break;
  2025 				deviceCharacteristics |= SQLITE_IOCAP_ATOMIC8K;
  2049 		case 16384:
  2026 				break;
  2050 			deviceCharacteristics |= SQLITE_IOCAP_ATOMIC16K;
  2027 			case 16384:
  2051 			break;
  2028 				deviceCharacteristics |= SQLITE_IOCAP_ATOMIC16K;
  2052 		case 32768:
  2029 				break;
  2053 			deviceCharacteristics |= SQLITE_IOCAP_ATOMIC32K;
  2030 			case 32768:
  2054 			break;
  2031 				deviceCharacteristics |= SQLITE_IOCAP_ATOMIC32K;
  2055 		case 65536:
  2032 				break;
  2056 			deviceCharacteristics |= SQLITE_IOCAP_ATOMIC64K;
  2033 			case 65536:
  2057 			break;
  2034 				deviceCharacteristics |= SQLITE_IOCAP_ATOMIC64K;
  2058 		default:
  2035 				break;
  2059 			//Do nothing. deviceCharacteristics was initialized with 0 at the beginning of the function body.
  2036 			default:
  2060 			break;
  2037 				//Do nothing. deviceCharacteristics was initialized with 0 at the beginning of the function body.
       
  2038 				break;
       
  2039 			}
       
  2040 		}
  2061 		}
  2041 	return deviceCharacteristics;
  2062 	return deviceCharacteristics;
  2042 	}
  2063 	}
  2043 
  2064 
  2044 /**
  2065 /**
  2213 */
  2234 */
  2214 /* static */ int TVfs::Open(sqlite3_vfs* aVfs, const char* aFileName, sqlite3_file* aDbFile, int aFlags, int* aOutFlags)
  2235 /* static */ int TVfs::Open(sqlite3_vfs* aVfs, const char* aFileName, sqlite3_file* aDbFile, int aFlags, int* aOutFlags)
  2215 	{
  2236 	{
  2216 	SQLUTRACE_PROFILER(aVfs);
  2237 	SQLUTRACE_PROFILER(aVfs);
  2217 	__OS_CALL(EOsVfsOpen, 0, 0);
  2238 	__OS_CALL(EOsVfsOpen, 0, 0);
  2218 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsOpen], ::OsCallProfile(EFalse, EOsVfsOpen), 0, 0);
  2239 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsOpen], ::OsCallProfile(EFalse, EOsVfsOpen), 0, 0, aDbFile, aFileName);
  2219 	COsLayerData& osLayerData = COsLayerData::Instance();
  2240 	COsLayerData& osLayerData = COsLayerData::Instance();
  2220 	TFileName fname;
  2241 	TFileName fname;
  2221 	if(aFileName && !::ConvertToUnicode(aFileName, fname))
  2242 	if(aFileName && !::ConvertToUnicode(aFileName, fname))
  2222 		{
  2243 		{
  2223 		osLayerData.SetOsErrorCode(KErrBadName);
  2244 		osLayerData.SetOsErrorCode(KErrBadName);
  2285 			if(err != KErrNone && err != KErrNoMemory && err != KErrDiskFull)
  2306 			if(err != KErrNone && err != KErrNoMemory && err != KErrDiskFull)
  2286 				{
  2307 				{
  2287 				__FS_CALL(EFsOpFileOpen, 0);
  2308 				__FS_CALL(EFsOpFileOpen, 0);
  2288 				err = dbFile.iFileBuf.Open(osLayerData.iFs, fname, fmode);
  2309 				err = dbFile.iFileBuf.Open(osLayerData.iFs, fname, fmode);
  2289 				
  2310 				
  2290 				if(err == KErrNone && ((aFlags & SQLITE_OPEN_MAIN_JOURNAL) || (aFlags & SQLITE_OPEN_TEMP_JOURNAL) || 
  2311 				if(err == KErrNone && (aFlags & KJournalFileTypeBitMask))
  2291                         (aFlags & SQLITE_OPEN_SUBJOURNAL) || (aFlags & SQLITE_OPEN_MASTER_JOURNAL)))
       
  2292 				    {
  2312 				    {
  2293                     err = TVfs::DoFileSizeCorruptionCheck(dbFile, fname, fmode);
  2313                     err = TVfs::DoFileSizeCorruptionCheck(dbFile, fname, fmode);
  2294 				    }
  2314 				    }
  2295 				}
  2315 				}
  2296 			if((err != KErrNone && err != KErrNoMemory && err != KErrDiskFull) && (aFlags & SQLITE_OPEN_READWRITE))
  2316 			if((err != KErrNone && err != KErrNoMemory && err != KErrDiskFull) && (aFlags & SQLITE_OPEN_READWRITE))
  2336 			*aOutFlags = dbFile.iReadOnly ? SQLITE_OPEN_READONLY : SQLITE_OPEN_READWRITE;
  2356 			*aOutFlags = dbFile.iReadOnly ? SQLITE_OPEN_READONLY : SQLITE_OPEN_READWRITE;
  2337 			}
  2357 			}
  2338 		(void)dbFile.iFileBuf.SetReadAheadSize(dbFile.iSectorSize, recReadBufSize);
  2358 		(void)dbFile.iFileBuf.SetReadAheadSize(dbFile.iSectorSize, recReadBufSize);
  2339 		}
  2359 		}
  2340 #ifdef _SQLPROFILER
  2360 #ifdef _SQLPROFILER
  2341 	dbFile.iIsJournal = (aFlags & SQLITE_OPEN_MAIN_JOURNAL) || (aFlags & SQLITE_OPEN_TEMP_JOURNAL) || 
  2361 	dbFile.iIsJournal = aFlags & KJournalFileTypeBitMask; 
  2342 						(aFlags & SQLITE_OPEN_SUBJOURNAL) || (aFlags & SQLITE_OPEN_MASTER_JOURNAL);
       
  2343 #endif
  2362 #endif
  2344 	return err == KErrNone ? SQLITE_OK : (err == KErrNoMemory ? SQLITE_IOERR_NOMEM : SQLITE_CANTOPEN);
  2363 	return err == KErrNone ? SQLITE_OK : (err == KErrNoMemory ? SQLITE_IOERR_NOMEM : SQLITE_CANTOPEN);
  2345 	}
  2364 	}
  2346 
  2365 
  2347 /**
  2366 /**
  2364 */
  2383 */
  2365 /* static */ int TVfs::Delete(sqlite3_vfs* aVfs, const char* aFileName, int /*aSyncDir*/)
  2384 /* static */ int TVfs::Delete(sqlite3_vfs* aVfs, const char* aFileName, int /*aSyncDir*/)
  2366 	{
  2385 	{
  2367 	SQLUTRACE_PROFILER(aVfs);
  2386 	SQLUTRACE_PROFILER(aVfs);
  2368 	__OS_CALL(EOsVfsDelete, 0, 0);
  2387 	__OS_CALL(EOsVfsDelete, 0, 0);
  2369 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsDelete], ::OsCallProfile(EFalse, EOsVfsDelete), 0, 0);
  2388 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsDelete], ::OsCallProfile(EFalse, EOsVfsDelete), 0, 0, 0, aFileName);
  2370 	COsLayerData& osLayerData = COsLayerData::Instance();
  2389 	COsLayerData& osLayerData = COsLayerData::Instance();
  2371 	TBuf<KMaxFileName + 1> fname;
  2390 	TBuf<KMaxFileName + 1> fname;
  2372 	if(!::ConvertToUnicode(aFileName, fname))
  2391 	if(!::ConvertToUnicode(aFileName, fname))
  2373 		{
  2392 		{
  2374 		osLayerData.SetOsErrorCode(KErrBadName);
  2393 		osLayerData.SetOsErrorCode(KErrBadName);
  2412 */
  2431 */
  2413 /* static */ int TVfs::Access(sqlite3_vfs* aVfs, const char* aFileName, int aFlags, int* aResOut)
  2432 /* static */ int TVfs::Access(sqlite3_vfs* aVfs, const char* aFileName, int aFlags, int* aResOut)
  2414 	{
  2433 	{
  2415 	SQLUTRACE_PROFILER(aVfs);
  2434 	SQLUTRACE_PROFILER(aVfs);
  2416 	__OS_CALL(EOsVfsAccess, 0, 0);
  2435 	__OS_CALL(EOsVfsAccess, 0, 0);
  2417 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsAccess], ::OsCallProfile(EFalse, EOsVfsAccess), aFlags, 0);
  2436 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsAccess], ::OsCallProfile(EFalse, EOsVfsAccess), aFlags, 0, 0, aFileName);
  2418 	COsLayerData& osLayerData = COsLayerData::Instance();
  2437 	COsLayerData& osLayerData = COsLayerData::Instance();
  2419 	TBuf<KMaxFileName + 1> fname;
  2438 	TBuf<KMaxFileName + 1> fname;
  2420 	if(!::ConvertToUnicode(aFileName, fname))
  2439 	if(!::ConvertToUnicode(aFileName, fname))
  2421 		{
  2440 		{
  2422 		osLayerData.SetOsErrorCode(KErrGeneral);
  2441 		osLayerData.SetOsErrorCode(KErrGeneral);
  2489 */
  2508 */
  2490 /* static */ int TVfs::FullPathName(sqlite3_vfs* aVfs, const char* aRelative, int aBufLen, char* aBuf)
  2509 /* static */ int TVfs::FullPathName(sqlite3_vfs* aVfs, const char* aRelative, int aBufLen, char* aBuf)
  2491 	{
  2510 	{
  2492 	SQLUTRACE_PROFILER(aVfs);
  2511 	SQLUTRACE_PROFILER(aVfs);
  2493 	__OS_CALL(EOsVfsFullPathName, 0, 0);
  2512 	__OS_CALL(EOsVfsFullPathName, 0, 0);
  2494 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsFullPathName], ::OsCallProfile(EFalse, EOsVfsFullPathName), aBufLen, 0);
  2513 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsFullPathName], ::OsCallProfile(EFalse, EOsVfsFullPathName), aBufLen, 0, 0, aRelative);
  2495 	COsLayerData& osLayerData = COsLayerData::Instance();
  2514 	COsLayerData& osLayerData = COsLayerData::Instance();
  2496 	osLayerData.StoreFhData(NULL, EFalse);
  2515 	osLayerData.StoreFhData(NULL, EFalse);
  2497 	//Convert the received file name to UTF16
  2516 	//Convert the received file name to UTF16
  2498 	TBuf<KMaxFileName + 1> fname;
  2517 	TBuf<KMaxFileName + 1> fname;
  2499 	if(!::ConvertToUnicode(aRelative, fname))
  2518 	if(!::ConvertToUnicode(aRelative, fname))
  2536 */
  2555 */
  2537 /* static */ int TVfs::Randomness(sqlite3_vfs* aVfs, int aBufLen, char* aBuf)
  2556 /* static */ int TVfs::Randomness(sqlite3_vfs* aVfs, int aBufLen, char* aBuf)
  2538 	{
  2557 	{
  2539 	SQLUTRACE_PROFILER(aVfs);
  2558 	SQLUTRACE_PROFILER(aVfs);
  2540 	__OS_CALL(EOsVfsRandomness, 0, 0);
  2559 	__OS_CALL(EOsVfsRandomness, 0, 0);
  2541 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsRandomness], ::OsCallProfile(EFalse, EOsVfsRandomness), aBufLen, 0);
  2560 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsRandomness], ::OsCallProfile(EFalse, EOsVfsRandomness), aBufLen, 0, 0, 0);
  2542 	COsLayerData& osLayerData = COsLayerData::Instance();
  2561 	COsLayerData& osLayerData = COsLayerData::Instance();
  2543 	const TInt KRandIterations = aBufLen / sizeof(int);
  2562 	const TInt KRandIterations = aBufLen / sizeof(int);
  2544 	for(TInt i=0;i<KRandIterations;++i)
  2563 	for(TInt i=0;i<KRandIterations;++i)
  2545 		{
  2564 		{
  2546 		TInt val = Math::Rand(osLayerData.iSeed);
  2565 		TInt val = Math::Rand(osLayerData.iSeed);
  2560 */
  2579 */
  2561 /* static */ int TVfs::Sleep(sqlite3_vfs* aVfs, int aMicrosec)
  2580 /* static */ int TVfs::Sleep(sqlite3_vfs* aVfs, int aMicrosec)
  2562 	{
  2581 	{
  2563 	SQLUTRACE_PROFILER(aVfs);
  2582 	SQLUTRACE_PROFILER(aVfs);
  2564 	__OS_CALL(EOsVfsSleep, 0, 0);
  2583 	__OS_CALL(EOsVfsSleep, 0, 0);
  2565 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsSleep], ::OsCallProfile(EFalse, EOsVfsSleep), aMicrosec, 0);
  2584 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsSleep], ::OsCallProfile(EFalse, EOsVfsSleep), aMicrosec, 0, 0, 0);
  2566 	User::AfterHighRes(TTimeIntervalMicroSeconds32(aMicrosec));
  2585 	User::AfterHighRes(TTimeIntervalMicroSeconds32(aMicrosec));
  2567 	return aMicrosec;
  2586 	return aMicrosec;
  2568 	}
  2587 	}
  2569 
  2588 
  2570 /**
  2589 /**
  2580 */
  2599 */
  2581 /* static */ int TVfs::CurrentTime(sqlite3_vfs* aVfs, double* aNow)
  2600 /* static */ int TVfs::CurrentTime(sqlite3_vfs* aVfs, double* aNow)
  2582 	{
  2601 	{
  2583 	SQLUTRACE_PROFILER(aVfs);
  2602 	SQLUTRACE_PROFILER(aVfs);
  2584 	__OS_CALL(EOsVfsCurrentTime, 0, 0);
  2603 	__OS_CALL(EOsVfsCurrentTime, 0, 0);
  2585 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsCurrentTime], ::OsCallProfile(EFalse, EOsVfsCurrentTime), 0, 0);
  2604 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsCurrentTime], ::OsCallProfile(EFalse, EOsVfsCurrentTime), 0, 0, 0, 0);
  2586 	TTime now;
  2605 	TTime now;
  2587 	now.UniversalTime();
  2606 	now.UniversalTime();
  2588 	TDateTime date = now.DateTime();
  2607 	TDateTime date = now.DateTime();
  2589 	TInt year = date.Year();
  2608 	TInt year = date.Year();
  2590 	TInt month = date.Month() + 1;
  2609 	TInt month = date.Month() + 1;
  2616 */
  2635 */
  2617 /* static */int TVfs::GetLastError(sqlite3_vfs* aVfs, int /*aBufLen*/, char* /*aBuf*/)
  2636 /* static */int TVfs::GetLastError(sqlite3_vfs* aVfs, int /*aBufLen*/, char* /*aBuf*/)
  2618 	{
  2637 	{
  2619 	SQLUTRACE_PROFILER(aVfs);
  2638 	SQLUTRACE_PROFILER(aVfs);
  2620 	__OS_CALL(EOsVfsGetLastError, 0, 0);
  2639 	__OS_CALL(EOsVfsGetLastError, 0, 0);
  2621 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsGetLastError], ::OsCallProfile(EFalse, EOsVfsGetLastError), 0, 0);
  2640 	__OSTIME_COUNTER(TheOsCallTicks[EOsVfsGetLastError], ::OsCallProfile(EFalse, EOsVfsGetLastError), 0, 0, 0, 0);
  2622 	return 0;
  2641 	return 0;
  2623 	}
  2642 	}
  2624 
  2643 
  2625 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2644 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2626 ///////////////////////////////////       Memory allocation functions     /////////////////////////////////////////////////////
  2645 ///////////////////////////////////       Memory allocation functions     /////////////////////////////////////////////////////