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" |
|
44 #ifdef _SQLPROFILER |
43 #ifdef _SQLPROFILER |
45 #include <hal.h> |
44 #include <hal.h> |
46 #include "../INC/SqlResourceProfiler.h" |
45 #include "../INC/SqlResourceProfiler.h" |
47 #endif |
46 #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" |
48 |
53 |
49 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
54 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
50 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
55 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
51 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
56 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
52 |
57 |
53 /** |
58 //The SQLite temp files willl be created in this subdir |
54 Panic category - used by asserts in this file (the OS porting layer). |
59 _LIT(KTempFileDir, "temp"); |
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 }; |
|
86 |
60 |
87 //Bit-mask constant. If xOpen()'s "aFlag" parameter contains one of these bits set, then the the file top be |
61 //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. |
62 //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; |
63 const TUint KJournalFileTypeBitMask = SQLITE_OPEN_MAIN_JOURNAL | SQLITE_OPEN_TEMP_JOURNAL | SQLITE_OPEN_SUBJOURNAL | SQLITE_OPEN_MASTER_JOURNAL; |
90 |
64 |
677 } |
651 } |
678 |
652 |
679 #endif//_SQLPROFILER |
653 #endif//_SQLPROFILER |
680 |
654 |
681 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
655 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
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 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
682 ///////////////////// COsLayerData class declaration ////////////////////////////////////////////////////////////////// |
697 ///////////////////// COsLayerData class declaration ////////////////////////////////////////////////////////////////// |
683 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
698 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
684 |
699 |
685 /** |
700 /** |
686 COsLayerData singleton class manages a single SQLite OS layer copy of the following data: |
701 COsLayerData singleton class manages a single SQLite OS layer copy of the following data: |
812 static int Unlock(sqlite3_file* aDbFile, int aLockType); |
827 static int Unlock(sqlite3_file* aDbFile, int aLockType); |
813 static int CheckReservedLock(sqlite3_file* aDbFile, int *aResOut); |
828 static int CheckReservedLock(sqlite3_file* aDbFile, int *aResOut); |
814 static int FileControl(sqlite3_file* aDbFile, int aOp, void* aArg); |
829 static int FileControl(sqlite3_file* aDbFile, int aOp, void* aArg); |
815 static int SectorSize(sqlite3_file* aDbFile); |
830 static int SectorSize(sqlite3_file* aDbFile); |
816 static int DeviceCharacteristics(sqlite3_file* aDbFile); |
831 static int DeviceCharacteristics(sqlite3_file* aDbFile); |
|
832 private: |
|
833 static TInt DoCreateTempFile(TDbFile& aDbFile); |
817 }; |
834 }; |
818 |
835 |
819 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
836 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
820 /////////////////////////////////// TVfs class declaration ///////////////////////////////////////////////////////// |
837 /////////////////////////////////// TVfs class declaration ///////////////////////////////////////////////////////// |
821 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
838 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
840 static int FullPathName(sqlite3_vfs* aVfs, const char* aRelative, int aBufLen, char* aBuf); |
857 static int FullPathName(sqlite3_vfs* aVfs, const char* aRelative, int aBufLen, char* aBuf); |
841 static int Randomness(sqlite3_vfs* aVfs, int aBufLen, char* aBuf); |
858 static int Randomness(sqlite3_vfs* aVfs, int aBufLen, char* aBuf); |
842 static int Sleep(sqlite3_vfs* aVfs, int aMicrosec); |
859 static int Sleep(sqlite3_vfs* aVfs, int aMicrosec); |
843 static int CurrentTime(sqlite3_vfs* aVfs, double* aNow); |
860 static int CurrentTime(sqlite3_vfs* aVfs, double* aNow); |
844 static int GetLastError(sqlite3_vfs *sVfs, int aBufLen, char* aBuf); |
861 static int GetLastError(sqlite3_vfs *sVfs, int aBufLen, char* aBuf); |
|
862 static TInt DoGetDeviceCharacteristicsAndSectorSize(TDbFile& aDbFile, TInt& aRecReadBufSize); |
845 private: |
863 private: |
846 static TInt DoOpenFromHandle(TDbFile& aDbFile, const RMessage2& aMsg, TBool aReadOnly); |
864 static TInt DoOpenFromHandle(TDbFile& aDbFile, const RMessage2& aMsg, TBool aReadOnly); |
847 static inline TInt DoGetVolumeIoParamInfo(RFs& aFs, TInt aDriveNo, TVolumeIOParamInfo& aVolumeInfo); |
865 static inline TInt DoGetVolumeIoParamInfo(RFs& aFs, TInt aDriveNo, TVolumeIOParamInfo& aVolumeInfo); |
848 static TInt DoGetDeviceCharacteristics(const TDriveInfo& aDriveInfo, const TVolumeIOParamInfo& aVolumeInfo); |
866 static TInt DoGetDeviceCharacteristics(const TDriveInfo& aDriveInfo, const TVolumeIOParamInfo& aVolumeInfo); |
849 static TInt DoGetSectorSize(const TDriveInfo& aDriveInfo, const TVolumeIOParamInfo& aVolumeInfo); |
867 static TInt DoGetSectorSize(const TDriveInfo& aDriveInfo, const TVolumeIOParamInfo& aVolumeInfo); |
850 static TInt DoGetDeviceCharacteristicsAndSectorSize(TDbFile& aDbFile, TInt& aRecReadBufSize); |
|
851 static TInt DoFileSizeCorruptionCheck(TDbFile& aDbFile, const TDesC& aFname, TInt aFmode); |
868 static TInt DoFileSizeCorruptionCheck(TDbFile& aDbFile, const TDesC& aFname, TInt aFmode); |
852 }; |
869 }; |
853 |
870 |
854 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
871 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
855 ///////////////////// Global variables, constants //////////////////////////////////////////////////////////////////// |
872 ///////////////////// Global variables, constants //////////////////////////////////////////////////////////////////// |
950 |
967 |
951 @panic Sqlite 16 In _DEBUG mode - the COsLayerData instance has been created already. |
968 @panic Sqlite 16 In _DEBUG mode - the COsLayerData instance has been created already. |
952 */ |
969 */ |
953 /* static */ TInt COsLayerData::Create() |
970 /* static */ TInt COsLayerData::Create() |
954 { |
971 { |
955 __ASSERT_DEBUG(!COsLayerData::iOsLayerData, User::Panic(KPanicCategory, EPanicOsLayerDataExists)); |
972 SQLITE_TRACE_OS(OstTrace0(TRACE_INTERNALS, COSLAYERDATA_CREATE_ENTRY, "OS-Entry;0;COsLayerData::Create")); |
|
973 __ASSERT_DEBUG(!COsLayerData::iOsLayerData, __SQLITEPANIC2(ESqliteOsPanicOsLayerDataExists)); |
956 if(!COsLayerData::iOsLayerData) |
974 if(!COsLayerData::iOsLayerData) |
957 { |
975 { |
958 COsLayerData::iOsLayerData = new COsLayerData; |
976 COsLayerData::iOsLayerData = new COsLayerData; |
959 if(!COsLayerData::iOsLayerData) |
977 if(!COsLayerData::iOsLayerData) |
960 { |
978 { |
|
979 SQLITE_TRACE_OS(OstTrace0(TRACE_INTERNALS, COSLAYERDATA_CREATE_EXIT1, "OS-Exit;0;COsLayerData::Create;err=KErrNoMemory")); |
961 return KErrNoMemory; |
980 return KErrNoMemory; |
962 } |
981 } |
963 TInt err = COsLayerData::iOsLayerData->DoCreate(); |
982 TInt err = COsLayerData::iOsLayerData->DoCreate(); |
964 if(err != KErrNone) |
983 if(err != KErrNone) |
965 { |
984 { |
966 delete COsLayerData::iOsLayerData; |
985 delete COsLayerData::iOsLayerData; |
967 COsLayerData::iOsLayerData = NULL; |
986 COsLayerData::iOsLayerData = NULL; |
|
987 SQLITE_TRACE_OS(OstTrace1(TRACE_INTERNALS, COSLAYERDATA_CREATE_EXIT2, "OS-Exit;0;COsLayerData::Create;err=%d", err)); |
968 return err; |
988 return err; |
969 } |
989 } |
970 } |
990 } |
|
991 SQLITE_TRACE_OS(OstTrace0(TRACE_INTERNALS, COSLAYERDATA_CREATE_EXIT3, "OS-Exit;0;COsLayerData::Create;err=KErrNone")); |
971 return KErrNone; |
992 return KErrNone; |
972 } |
993 } |
973 |
994 |
974 /** |
995 /** |
975 Destroys the COsLayerData instance. |
996 Destroys the COsLayerData instance. |
976 */ |
997 */ |
977 /* static */ inline void COsLayerData::Destroy() |
998 /* static */ inline void COsLayerData::Destroy() |
978 { |
999 { |
979 delete COsLayerData::iOsLayerData; |
1000 delete COsLayerData::iOsLayerData; |
980 COsLayerData::iOsLayerData = NULL; |
1001 COsLayerData::iOsLayerData = NULL; |
|
1002 SQLITE_TRACE_OS(OstTrace0(TRACE_INTERNALS, COSLAYERDATA_DESTROY, "OS;0;COsLayerData::Destroy")); |
981 } |
1003 } |
982 |
1004 |
983 /** |
1005 /** |
984 Returns a reference to the single COsLayerData instance. |
1006 Returns a reference to the single COsLayerData instance. |
985 |
1007 |
986 @panic Sqlite 1 In _DEBUG mode if the COsLayerData instance is NULL. |
1008 @panic Sqlite 1 In _DEBUG mode if the COsLayerData instance is NULL. |
987 */ |
1009 */ |
988 /* static */ inline COsLayerData& COsLayerData::Instance() |
1010 /* static */ inline COsLayerData& COsLayerData::Instance() |
989 { |
1011 { |
990 __ASSERT_DEBUG(COsLayerData::iOsLayerData != NULL, User::Panic(KPanicCategory, EPanicNullOsLayerDataPtr)); |
1012 __ASSERT_DEBUG(COsLayerData::iOsLayerData != NULL, __SQLITEPANIC2(ESqliteOsPanicNullOsLayerDataPtr)); |
991 return *COsLayerData::iOsLayerData; |
1013 return *COsLayerData::iOsLayerData; |
992 } |
1014 } |
993 |
1015 |
994 /** |
1016 /** |
995 Sets the last OS error code data member. The stored OS error code data member will be set only if it is |
1017 Sets the last OS error code data member. The stored OS error code data member will be set only if it is |
1134 TDriveUnit drive(sysDrive); |
1157 TDriveUnit drive(sysDrive); |
1135 TDriveName driveName = drive.Name(); |
1158 TDriveName driveName = drive.Name(); |
1136 TParse parse; |
1159 TParse parse; |
1137 (void)parse.Set(driveName, &privateDir, 0);//this call can't fail |
1160 (void)parse.Set(driveName, &privateDir, 0);//this call can't fail |
1138 iSysPrivDir.Copy(parse.DriveAndPath()); |
1161 iSysPrivDir.Copy(parse.DriveAndPath()); |
|
1162 //Create the temp files directory |
|
1163 (void)parse.AddDir(KTempFileDir);//this call can't fail |
|
1164 err = iFs.MkDir(parse.DriveAndPath()); |
|
1165 if(err != KErrNone && err != KErrAlreadyExists) |
|
1166 { |
|
1167 return err; |
|
1168 } |
|
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))); |
1139 return KErrNone; |
1170 return KErrNone; |
1140 } |
1171 } |
1141 |
1172 |
1142 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
1173 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
1143 /////////////////////// Symbian OS specific functions (called by the SQL server) /////////////////////////////////// |
1174 /////////////////////// Symbian OS specific functions (called by the SQL server) /////////////////////////////////// |
1267 static TBool ConvertFromUnicode(const TDesC& aFileName, TDes8& aFileNameDestBuf) |
1300 static TBool ConvertFromUnicode(const TDesC& aFileName, TDes8& aFileNameDestBuf) |
1268 { |
1301 { |
1269 char* dest = reinterpret_cast <char*> (const_cast <TUint8*> (aFileNameDestBuf.Ptr())); |
1302 char* dest = reinterpret_cast <char*> (const_cast <TUint8*> (aFileNameDestBuf.Ptr())); |
1270 const wchar_t* src = reinterpret_cast <const wchar_t*> (aFileName.Ptr()); |
1303 const wchar_t* src = reinterpret_cast <const wchar_t*> (aFileName.Ptr()); |
1271 TInt len = wcstombs(dest, src, aFileNameDestBuf.MaxLength()); |
1304 TInt len = wcstombs(dest, src, aFileNameDestBuf.MaxLength()); |
1272 __ASSERT_DEBUG(len >= 0, User::Panic(KPanicCategory, EPanicInternalError)); |
1305 __ASSERT_DEBUG(len >= 0, __SQLITEPANIC2(ESqliteOsPanicInternalError)); |
1273 //If len == aFileNameDestBuf.MaxLength(), then the output buffer is too small. |
1306 //If len == aFileNameDestBuf.MaxLength(), then the output buffer is too small. |
1274 if(len < aFileNameDestBuf.MaxLength()) |
1307 if(len < aFileNameDestBuf.MaxLength()) |
1275 { |
1308 { |
1276 aFileNameDestBuf.SetLength(len); |
1309 aFileNameDestBuf.SetLength(len); |
1277 return ETrue; |
1310 return ETrue; |
1409 @panic Sqlite 12 In _DEBUG mode - the extracted RMessage2 pointer is NULL. |
1442 @panic Sqlite 12 In _DEBUG mode - the extracted RMessage2 pointer is NULL. |
1410 */ |
1443 */ |
1411 static void FhExtractAndStore(TDes& aDbFileName) |
1444 static void FhExtractAndStore(TDes& aDbFileName) |
1412 { |
1445 { |
1413 TInt fhStartPos = aDbFileName.Locate(TChar(KFhSeparator)); |
1446 TInt fhStartPos = aDbFileName.Locate(TChar(KFhSeparator)); |
1414 __ASSERT_DEBUG(fhStartPos == KFhMarkPos, User::Panic(KPanicCategory, EPanicInvalidFhStr)); |
1447 __ASSERT_DEBUG(fhStartPos == KFhMarkPos, __SQLITEPANIC2(ESqliteOsPanicInvalidFhStr)); |
1415 //If this file name string contains file handles |
1448 //If this file name string contains file handles |
1416 if(fhStartPos == KFhMarkPos) |
1449 if(fhStartPos == KFhMarkPos) |
1417 { |
1450 { |
1418 //Extract from aDbFileName string RMessage2 object's address |
1451 //Extract from aDbFileName string RMessage2 object's address |
1419 TLex lex(aDbFileName.Mid(fhStartPos + KFhMsgAddrPos, KFhMsgAddrLen)); |
1452 TLex lex(aDbFileName.Mid(fhStartPos + KFhMsgAddrPos, KFhMsgAddrLen)); |
1420 TUint32 addr; |
1453 TUint32 addr; |
1421 TInt err = lex.Val(addr, EHex); |
1454 TInt err = lex.Val(addr, EHex); |
1422 __ASSERT_DEBUG(err == KErrNone, User::Panic(KPanicCategory, EPanicInvalidFhStr)); |
1455 __ASSERT_DEBUG(err == KErrNone, __SQLITEPANIC2(ESqliteOsPanicInvalidFhStr)); |
1423 if(err == KErrNone) |
1456 if(err == KErrNone) |
1424 { |
1457 { |
1425 //Cast the address to RMessage2 pointer. |
1458 //Cast the address to RMessage2 pointer. |
1426 const RMessage2* msg = reinterpret_cast <const RMessage2*> (addr); |
1459 const RMessage2* msg = reinterpret_cast <const RMessage2*> (addr); |
1427 __ASSERT_DEBUG(msg != NULL, User::Panic(KPanicCategory, EPanicInvalidFhStr)); |
1460 __ASSERT_DEBUG(msg != NULL, __SQLITEPANIC2(ESqliteOsPanicInvalidFhStr)); |
1428 if(msg) |
1461 if(msg) |
1429 { |
1462 { |
1430 //Store the data from aDbFileName in the single COsLayerData instance. |
1463 //Store the data from aDbFileName in the single COsLayerData instance. |
1431 TBool readOnly = aDbFileName[fhStartPos + KFhRoPos] > '0'; |
1464 TBool readOnly = aDbFileName[fhStartPos + KFhRoPos] > '0'; |
1432 COsLayerData::Instance().StoreFhData(msg, readOnly); |
1465 COsLayerData::Instance().StoreFhData(msg, readOnly); |
1486 |
1520 |
1487 /** |
1521 /** |
1488 SQLite OS porting layer API. |
1522 SQLite OS porting layer API. |
1489 |
1523 |
1490 Closes the file referred by aDbFile parameter. |
1524 Closes the file referred by aDbFile parameter. |
1491 If aDbFile.iFullName data member is not NULL, then the file will be deleted. |
|
1492 |
1525 |
1493 @param aDbFile A pointer to a TDbFile instance, than contains the file handle to be closed. |
1526 @param aDbFile A pointer to a TDbFile instance, than contains the file handle to be closed. |
1494 |
1527 |
1495 @return SQLITE_OK |
1528 @return SQLITE_OK |
1496 |
1529 |
1497 @see TDbFile |
1530 @see TDbFile |
1498 */ |
1531 */ |
1499 /* static */ int TFileIo::Close(sqlite3_file* aDbFile) |
1532 /* static */ int TFileIo::Close(sqlite3_file* aDbFile) |
1500 { |
1533 { |
1501 SQLUTRACE_PROFILER(aDbFile); |
|
1502 TDbFile& dbFile = ::DbFile(aDbFile); |
1534 TDbFile& dbFile = ::DbFile(aDbFile); |
|
1535 SQLITE_TRACE_OS(OstTrace1(TRACE_INTERNALS, TFILEIO_CLOSE1, "OS;0x%X;TFileIo::Close", (TUint)&dbFile)); |
1503 __OS_CALL(EOsFileClose, 0, 0); |
1536 __OS_CALL(EOsFileClose, 0, 0); |
1504 __OSTIME_COUNTER(TheOsCallTicks[EOsFileClose], ::OsCallProfile(dbFile.iIsJournal, EOsFileClose), 0, 0, aDbFile, 0); |
1537 __OSTIME_COUNTER(TheOsCallTicks[EOsFileClose], ::OsCallProfile(dbFile.iIsJournal, EOsFileClose), 0, 0, aDbFile, 0); |
1505 __FS_CALL(EFsOpFileClose, 0); |
1538 __FS_CALL(EFsOpFileClose, 0); |
1506 dbFile.iFileBuf.Close(); |
1539 dbFile.iFileBuf.Close(); |
1507 if(dbFile.iFullName) |
|
1508 {//"iFullName" will not be NULL only when TVfs::Open() is called with SQLITE_OPEN_DELETEONCLOSE flag. |
|
1509 //That means - SQlite expects the file to be deleted after the file close operation. |
|
1510 __FS_CALL(EFsOpFileDelete, 0); |
|
1511 (void)COsLayerData::Instance().iFs.Delete(*dbFile.iFullName); |
|
1512 delete dbFile.iFullName; |
|
1513 } |
|
1514 return SQLITE_OK; |
1540 return SQLITE_OK; |
1515 } |
1541 } |
1516 |
1542 |
1517 /** |
1543 /** |
1518 SQLite OS porting layer API. |
1544 SQLite OS porting layer API. |
1536 @see COsLayerData::SetOsErrorCode() |
1562 @see COsLayerData::SetOsErrorCode() |
1537 @see TDbFile |
1563 @see TDbFile |
1538 */ |
1564 */ |
1539 /* static */ int TFileIo::Read(sqlite3_file* aDbFile, void* aBuf, int aAmt, sqlite3_int64 aOffset) |
1565 /* static */ int TFileIo::Read(sqlite3_file* aDbFile, void* aBuf, int aAmt, sqlite3_int64 aOffset) |
1540 { |
1566 { |
1541 SQLUTRACE_PROFILER(aDbFile); |
|
1542 SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KFileRead, aAmt, aOffset)); |
|
1543 TDbFile& dbFile = ::DbFile(aDbFile); |
1567 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)); |
1544 __OS_CALL(EOsFileRead, 0, 0); |
1569 __OS_CALL(EOsFileRead, 0, 0); |
1545 __COUNTER_INCR(TheSqlSrvProfilerFileRead); |
1570 __COUNTER_INCR(TheSqlSrvProfilerFileRead); |
1546 __OSTIME_COUNTER(TheOsCallTicks[EOsFileRead], ::OsCallProfile(dbFile.iIsJournal, EOsFileRead), aOffset, aAmt, aDbFile, 0); |
1571 __OSTIME_COUNTER(TheOsCallTicks[EOsFileRead], ::OsCallProfile(dbFile.iIsJournal, EOsFileRead), aOffset, aAmt, aDbFile, 0); |
1547 TPtr8 ptr((TUint8*)aBuf, 0, aAmt); |
1572 TPtr8 ptr((TUint8*)aBuf, 0, aAmt); |
1548 TInt err = dbFile.iFileBuf.Read(aOffset, ptr); |
1573 TInt err = dbFile.iFileBuf.Read(aOffset, ptr); |
1549 TInt cnt = ptr.Length(); |
1574 TInt cnt = ptr.Length(); |
1550 TInt sqliteErr = SQLITE_IOERR_READ; |
1575 TInt sqliteErr = ::Os2SqliteErr(err, SQLITE_IOERR_READ); |
1551 switch(err) |
1576 if(cnt != aAmt && (sqliteErr == SQLITE_OK || sqliteErr == SQLITE_IOERR_SHORT_READ)) |
1552 { |
1577 { |
1553 case KErrNone: |
1578 Mem::FillZ(static_cast <TUint8*> (aBuf) + cnt, aAmt - cnt); |
1554 sqliteErr = SQLITE_OK; |
1579 err = KErrEof; |
1555 if(cnt != aAmt) |
1580 sqliteErr = SQLITE_IOERR_SHORT_READ; |
1556 { |
|
1557 Mem::FillZ(static_cast <TUint8*> (aBuf) + cnt, aAmt - cnt); |
|
1558 sqliteErr = SQLITE_IOERR_SHORT_READ; |
|
1559 err = KErrEof; |
|
1560 } |
|
1561 break; |
|
1562 case KErrEof: |
|
1563 Mem::FillZ(static_cast <TUint8*> (aBuf) + cnt, aAmt - cnt); |
|
1564 sqliteErr = SQLITE_IOERR_SHORT_READ; |
|
1565 break; |
|
1566 case KErrNoMemory: |
|
1567 sqliteErr = SQLITE_IOERR_NOMEM; |
|
1568 break; |
|
1569 default: |
|
1570 break; |
|
1571 } |
1581 } |
1572 COsLayerData::Instance().SetOsErrorCode(err); |
1582 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)); |
1573 return sqliteErr; |
1584 return sqliteErr; |
1574 } |
1585 } |
|
1586 |
|
1587 //Creates a temporary file in "\temp" subdirectory of osLayerData.iSysPrivDir directory. |
|
1588 //If the function fails, the temp file will be closed and deleted, |
|
1589 //the related Symbian OS error will be returned to the caller. |
|
1590 /* static */TInt TFileIo::DoCreateTempFile(TDbFile& aDbFile) |
|
1591 { |
|
1592 COsLayerData& osLayerData = COsLayerData::Instance(); |
|
1593 //TParse2 is used in order to avoid the need of another TFileName stack based variable |
|
1594 class TParse2 : public TParse |
|
1595 { |
|
1596 public: |
|
1597 inline TFileName& FileName() |
|
1598 { |
|
1599 return static_cast <TFileName&> (NameBuf()); |
|
1600 } |
|
1601 }; |
|
1602 TParse2 parse; |
|
1603 (void)parse.Set(osLayerData.iSysPrivDir, 0, 0);//this call can't fail |
|
1604 (void)parse.AddDir(KTempFileDir);//this call can't fail |
|
1605 __FS_CALL(EFsOpFileCreateTemp, 0); |
|
1606 TInt err = aDbFile.iFileBuf.Temp(osLayerData.iFs, parse.FullName(), parse.FileName(), EFileRead|EFileWrite|EDeleteOnClose); |
|
1607 if(err == KErrNone) |
|
1608 { |
|
1609 TInt recReadBufSize = -1; |
|
1610 err = TVfs::DoGetDeviceCharacteristicsAndSectorSize(aDbFile, recReadBufSize); |
|
1611 if(err != KErrNone) |
|
1612 { |
|
1613 aDbFile.iFileBuf.Close();//With EDeleteOnClose flag set, the file will be deleted |
|
1614 } |
|
1615 else |
|
1616 { |
|
1617 (void)aDbFile.iFileBuf.SetReadAheadSize(aDbFile.iSectorSize, recReadBufSize); |
|
1618 aDbFile.iIsFileCreated = ETrue; |
|
1619 } |
|
1620 } |
|
1621 return err; |
|
1622 } |
1575 |
1623 |
1576 /** |
1624 /** |
1577 SQLite OS porting layer API. |
1625 SQLite OS porting layer API. |
1578 |
1626 |
1579 Writes to the file referred by the aDbFile parameter. |
1627 Writes to the file referred by the aDbFile parameter. |
1580 "Write beyond the end of the file" operations are allowed. |
1628 "Write beyond the end of the file" operations are allowed. |
1581 |
1629 |
1582 If the write operation is in the 1st db file page and there is a registered "free pages" callback |
1630 If the write operation is in the 1st db file page and there is a registered "free pages" callback |
1583 (TDbFile::iFreePageCallback) and the free pages count is above the defined value, |
1631 (TDbFile::iFreePageCallback) and the free pages count is above the defined value, |
1584 then the callback will be called. |
1632 then the callback will be called. |
|
1633 |
|
1634 If the file to be written to is a temp file, which is not created yet, then the file will be created. |
1585 |
1635 |
1586 @param aDbFile A pointer to a TDbFile instance, that contains the file handle to be written to. |
1636 @param aDbFile A pointer to a TDbFile instance, that contains the file handle to be written to. |
1587 @param aData The data to be written to the file. The buffer size must be at least aAmt bytes. |
1637 @param aData The data to be written to the file. The buffer size must be at least aAmt bytes. |
1588 @param aAmt The amount of data to be written to the file. |
1638 @param aAmt The amount of data to be written to the file. |
1589 @param aOffset The offset in the file where the write operation should start. |
1639 @param aOffset The offset in the file where the write operation should start. |
1599 @see COsLayerData::SetOsErrorCode() |
1649 @see COsLayerData::SetOsErrorCode() |
1600 @see TDbFile |
1650 @see TDbFile |
1601 */ |
1651 */ |
1602 /* static */ int TFileIo::Write(sqlite3_file* aDbFile, const void* aData, int aAmt, sqlite3_int64 aOffset) |
1652 /* static */ int TFileIo::Write(sqlite3_file* aDbFile, const void* aData, int aAmt, sqlite3_int64 aOffset) |
1603 { |
1653 { |
1604 SQLUTRACE_PROFILER(aDbFile); |
|
1605 SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KFileWrite, aAmt, aOffset)); |
|
1606 TDbFile& dbFile = ::DbFile(aDbFile); |
1654 TDbFile& dbFile = ::DbFile(aDbFile); |
|
1655 SQLITE_TRACE_OS(OstTraceExt3(TRACE_INTERNALS, TFILEIO_WRITE_ENTRY, "OS-Entry;0x%X;TFileIo::Write;aAmt=%d;aOffset=%lld", (TUint)&dbFile, aAmt, aOffset)); |
1607 __OS_CALL(EOsFileWrite, 0, 0); |
1656 __OS_CALL(EOsFileWrite, 0, 0); |
1608 __COUNTER_INCR(TheSqlSrvProfilerFileWrite); |
1657 __COUNTER_INCR(TheSqlSrvProfilerFileWrite); |
1609 __OSTIME_COUNTER(TheOsCallTicks[EOsFileWrite], ::OsCallProfile(dbFile.iIsJournal, EOsFileWrite), aOffset, aAmt, aDbFile, 0); |
1658 __OSTIME_COUNTER(TheOsCallTicks[EOsFileWrite], ::OsCallProfile(dbFile.iIsJournal, EOsFileWrite), aOffset, aAmt, aDbFile, 0); |
1610 TInt err = KErrAccessDenied; |
1659 TInt err = KErrNone; |
|
1660 if(!dbFile.iIsFileCreated) |
|
1661 {//Create a temp file if it has not been created. |
|
1662 err = TFileIo::DoCreateTempFile(dbFile); |
|
1663 } |
|
1664 if(err != KErrNone) |
|
1665 { |
|
1666 COsLayerData::Instance().SetOsErrorCode(err); |
|
1667 return ::Os2SqliteErr(err, SQLITE_FULL); |
|
1668 } |
|
1669 err = KErrAccessDenied; |
1611 if(!dbFile.iReadOnly) |
1670 if(!dbFile.iReadOnly) |
1612 { |
1671 { |
1613 TPtrC8 ptr((const TUint8*)aData, aAmt); |
1672 TPtrC8 ptr((const TUint8*)aData, aAmt); |
1614 err = dbFile.iFileBuf.Write(aOffset, ptr); |
1673 err = dbFile.iFileBuf.Write(aOffset, ptr); |
1615 } |
1674 } |
1653 @see COsLayerData::SetOsErrorCode() |
1714 @see COsLayerData::SetOsErrorCode() |
1654 @see TDbFile |
1715 @see TDbFile |
1655 */ |
1716 */ |
1656 /* static */ int TFileIo::Truncate(sqlite3_file* aDbFile, sqlite3_int64 aLength) |
1717 /* static */ int TFileIo::Truncate(sqlite3_file* aDbFile, sqlite3_int64 aLength) |
1657 { |
1718 { |
1658 SQLUTRACE_PROFILER(aDbFile); |
|
1659 SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KFileTruncate, aLength)); |
|
1660 TDbFile& dbFile = ::DbFile(aDbFile); |
1719 TDbFile& dbFile = ::DbFile(aDbFile); |
|
1720 SQLITE_TRACE_OS(OstTraceExt2(TRACE_INTERNALS, TFILEIO_TRUNCATE_ENTRY, "OS-Entry;0x%X;TFileIo::Truncate;aLength=%lld", (TUint)&dbFile, aLength)); |
1661 __OS_CALL(EOsFileTruncate, 0, 0); |
1721 __OS_CALL(EOsFileTruncate, 0, 0); |
1662 __COUNTER_INCR(TheSqlSrvProfilerFileSetSize); |
1722 __COUNTER_INCR(TheSqlSrvProfilerFileSetSize); |
1663 __OSTIME_COUNTER(TheOsCallTicks[EOsFileTruncate], ::OsCallProfile(dbFile.iIsJournal, EOsFileTruncate), aLength, 0, aDbFile, 0); |
1723 __OSTIME_COUNTER(TheOsCallTicks[EOsFileTruncate], ::OsCallProfile(dbFile.iIsJournal, EOsFileTruncate), aLength, 0, aDbFile, 0); |
1664 if(dbFile.iReadOnly) |
1724 if(dbFile.iReadOnly) |
1665 { |
1725 { |
1690 @see COsLayerData::SetOsErrorCode() |
1752 @see COsLayerData::SetOsErrorCode() |
1691 @see TDbFile |
1753 @see TDbFile |
1692 */ |
1754 */ |
1693 /* static */int TFileIo::Sync(sqlite3_file* aDbFile, int /* aFlags */) |
1755 /* static */int TFileIo::Sync(sqlite3_file* aDbFile, int /* aFlags */) |
1694 { |
1756 { |
1695 SQLUTRACE_PROFILER(aDbFile); |
|
1696 TDbFile& dbFile = ::DbFile(aDbFile); |
1757 TDbFile& dbFile = ::DbFile(aDbFile); |
|
1758 SQLITE_TRACE_OS(OstTrace1(TRACE_INTERNALS, TFILEIO_SYNC_ENTRY, "OS-Entry;0x%X;TFileIo::Sync", (TUint)&dbFile)); |
1697 __OS_CALL(EOsFileSync, 0, 0); |
1759 __OS_CALL(EOsFileSync, 0, 0); |
1698 __COUNTER_INCR(TheSqlSrvProfilerFileSync); |
1760 __COUNTER_INCR(TheSqlSrvProfilerFileSync); |
1699 __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); |
1700 if(dbFile.iReadOnly) |
1762 if(dbFile.iReadOnly) |
1701 { |
1763 { |
1726 @see COsLayerData::SetOsErrorCode() |
1790 @see COsLayerData::SetOsErrorCode() |
1727 @see TDbFile |
1791 @see TDbFile |
1728 */ |
1792 */ |
1729 /* static */ int TFileIo::FileSize(sqlite3_file* aDbFile, sqlite3_int64* aSize) |
1793 /* static */ int TFileIo::FileSize(sqlite3_file* aDbFile, sqlite3_int64* aSize) |
1730 { |
1794 { |
1731 SQLUTRACE_PROFILER(aDbFile); |
|
1732 TDbFile& dbFile = ::DbFile(aDbFile); |
1795 TDbFile& dbFile = ::DbFile(aDbFile); |
|
1796 SQLITE_TRACE_OS(OstTrace1(TRACE_INTERNALS, TFILEIO_FILESIZE_ENTRY, "OS-Entry;0x%X;TFileIo::FileSize", (TUint)&dbFile)); |
1733 __OS_CALL(EOsFileFileSize, 0, 0); |
1797 __OS_CALL(EOsFileFileSize, 0, 0); |
1734 __OSTIME_COUNTER(TheOsCallTicks[EOsFileFileSize], ::OsCallProfile(dbFile.iIsJournal, EOsFileFileSize), 0, 0, aDbFile, 0); |
1798 __OSTIME_COUNTER(TheOsCallTicks[EOsFileFileSize], ::OsCallProfile(dbFile.iIsJournal, EOsFileFileSize), 0, 0, aDbFile, 0); |
1735 __FS_CALL(EFsOpFileSize, 0); |
1799 __FS_CALL(EFsOpFileSize, 0); |
1736 TInt err = dbFile.iFileBuf.Size(*aSize); |
1800 TInt err = dbFile.iFileBuf.Size(*aSize); |
1737 COsLayerData::Instance().SetOsErrorCode(err); |
1801 COsLayerData::Instance().SetOsErrorCode(err); |
1738 if(err == KErrNone) |
1802 TInt sqliteErr = ::Os2SqliteErr(err, SQLITE_IOERR); |
1739 { |
1803 SQLITE_TRACE_OS(OstTraceExt3(TRACE_INTERNALS, TFILEIO_FILESIZE_EXIT, "OS-Exit;0x%X;TFileIo::FileSize;err=%d;sqliteErr=%d", (TUint)&dbFile, err, sqliteErr)); |
1740 return SQLITE_OK; |
1804 return sqliteErr; |
1741 } |
|
1742 return err == KErrNoMemory ? SQLITE_IOERR_NOMEM : SQLITE_IOERR; |
|
1743 } |
1805 } |
1744 |
1806 |
1745 /** |
1807 /** |
1746 SQLite OS porting layer API. |
1808 SQLite OS porting layer API. |
1747 |
1809 |
1760 |
1822 |
1761 @see TDbFile |
1823 @see TDbFile |
1762 */ |
1824 */ |
1763 /* static */ int TFileIo::Lock(sqlite3_file* aDbFile, int aLockType) |
1825 /* static */ int TFileIo::Lock(sqlite3_file* aDbFile, int aLockType) |
1764 { |
1826 { |
1765 SQLUTRACE_PROFILER(aDbFile); |
|
1766 TDbFile& dbFile = ::DbFile(aDbFile); |
1827 TDbFile& dbFile = ::DbFile(aDbFile); |
1767 __OS_CALL(EOsFileLock, 0, 0); |
1828 __OS_CALL(EOsFileLock, 0, 0); |
1768 __OSTIME_COUNTER(TheOsCallTicks[EOsFileLock], ::OsCallProfile(dbFile.iIsJournal, EOsFileLock), aLockType, 0, aDbFile, 0); |
1829 __OSTIME_COUNTER(TheOsCallTicks[EOsFileLock], ::OsCallProfile(dbFile.iIsJournal, EOsFileLock), aLockType, 0, aDbFile, 0); |
1769 //If there is already a lock of this type or more restrictive on the database file, do nothing. |
1830 //If there is already a lock of this type or more restrictive on the database file, do nothing. |
1770 if(dbFile.iLockType >= aLockType) |
1831 if(dbFile.iLockType >= aLockType) |
1857 |
1916 |
1858 @see TDbFile |
1917 @see TDbFile |
1859 */ |
1918 */ |
1860 /* static */ int TFileIo::FileControl(sqlite3_file* aDbFile, int aOp, void* aArg) |
1919 /* static */ int TFileIo::FileControl(sqlite3_file* aDbFile, int aOp, void* aArg) |
1861 { |
1920 { |
1862 SQLUTRACE_PROFILER(aDbFile); |
|
1863 SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KFileFileCtr, aOp)); |
|
1864 TDbFile& dbFile = ::DbFile(aDbFile); |
1921 TDbFile& dbFile = ::DbFile(aDbFile); |
|
1922 SQLITE_TRACE_OS(OstTraceExt2(TRACE_INTERNALS, TFILEIO_FILECONTROL_ENTRY, "OS-Entry;0x%X;TFileIo::FileControl;aOp=%d", (TUint)&dbFile, aOp)); |
1865 __OS_CALL(EOsFileFileControl, 0, 0); |
1923 __OS_CALL(EOsFileFileControl, 0, 0); |
1866 __OSTIME_COUNTER(TheOsCallTicks[EOsFileFileControl], ::OsCallProfile(dbFile.iIsJournal, EOsFileFileControl), aOp, 0, aDbFile, 0); |
1924 __OSTIME_COUNTER(TheOsCallTicks[EOsFileFileControl], ::OsCallProfile(dbFile.iIsJournal, EOsFileFileControl), aOp, 0, aDbFile, 0); |
1867 TInt err = KErrNone; |
1925 TInt err = KErrNone; |
1868 switch(aOp) |
1926 switch(aOp) |
1869 { |
1927 { |
1909 @see TDbFile |
1969 @see TDbFile |
1910 @see TVfs::Open() |
1970 @see TVfs::Open() |
1911 */ |
1971 */ |
1912 /* static */ int TFileIo::SectorSize(sqlite3_file* aDbFile) |
1972 /* static */ int TFileIo::SectorSize(sqlite3_file* aDbFile) |
1913 { |
1973 { |
1914 SQLUTRACE_PROFILER(aDbFile); |
|
1915 TDbFile& dbFile = ::DbFile(aDbFile); |
1974 TDbFile& dbFile = ::DbFile(aDbFile); |
1916 __OS_CALL(EOsFileSectorSize, 0, 0); |
1975 __OS_CALL(EOsFileSectorSize, 0, 0); |
1917 __OSTIME_COUNTER(TheOsCallTicks[EOsFileSectorSize], ::OsCallProfile(dbFile.iIsJournal, EOsFileSectorSize), 0, 0, aDbFile, 0); |
1976 __OSTIME_COUNTER(TheOsCallTicks[EOsFileSectorSize], ::OsCallProfile(dbFile.iIsJournal, EOsFileSectorSize), 0, 0, aDbFile, 0); |
1918 __ASSERT_DEBUG(dbFile.iSectorSize > 0, User::Panic(KPanicCategory, EPanicInternalError)); |
1977 __ASSERT_DEBUG(dbFile.iSectorSize > 0, __SQLITEPANIC2(ESqliteOsPanicInternalError)); |
1919 if(dbFile.iSectorSize > 0) |
1978 if(dbFile.iSectorSize > 0) |
1920 { |
1979 { |
1921 return dbFile.iSectorSize; |
1980 return dbFile.iSectorSize; |
1922 } |
1981 } |
1923 return SQLITE_DEFAULT_SECTOR_SIZE; |
1982 return SQLITE_DEFAULT_SECTOR_SIZE; |
1940 @see TDbFile |
1999 @see TDbFile |
1941 @see TVfs::Open() |
2000 @see TVfs::Open() |
1942 */ |
2001 */ |
1943 /* static */ int TFileIo::DeviceCharacteristics(sqlite3_file* aDbFile) |
2002 /* static */ int TFileIo::DeviceCharacteristics(sqlite3_file* aDbFile) |
1944 { |
2003 { |
1945 SQLUTRACE_PROFILER(aDbFile); |
|
1946 TDbFile& dbFile = ::DbFile(aDbFile); |
2004 TDbFile& dbFile = ::DbFile(aDbFile); |
1947 __OS_CALL(EOsFileDeviceCharacteristics, 0, 0); |
2005 __OS_CALL(EOsFileDeviceCharacteristics, 0, 0); |
1948 __OSTIME_COUNTER(TheOsCallTicks[EOsFileDeviceCharacteristics], ::OsCallProfile(dbFile.iIsJournal, EOsFileDeviceCharacteristics), 0, 0, aDbFile, 0); |
2006 __OSTIME_COUNTER(TheOsCallTicks[EOsFileDeviceCharacteristics], ::OsCallProfile(dbFile.iIsJournal, EOsFileDeviceCharacteristics), 0, 0, aDbFile, 0); |
1949 __ASSERT_DEBUG(dbFile.iDeviceCharacteristics >= 0, User::Panic(KPanicCategory, EPanicInternalError)); |
2007 __ASSERT_DEBUG(dbFile.iDeviceCharacteristics >= 0, __SQLITEPANIC2(ESqliteOsPanicInternalError)); |
1950 if(dbFile.iDeviceCharacteristics >= 0) |
2008 if(dbFile.iDeviceCharacteristics >= 0) |
1951 { |
2009 { |
1952 return dbFile.iDeviceCharacteristics; |
2010 return dbFile.iDeviceCharacteristics; |
1953 } |
2011 } |
1954 return 0; |
2012 return 0; |
2118 @see TFileIo::DeviceCharacteristics() |
2178 @see TFileIo::DeviceCharacteristics() |
2119 @see TFileIo::SectorSize() |
2179 @see TFileIo::SectorSize() |
2120 */ |
2180 */ |
2121 /* static */ TInt TVfs::DoGetDeviceCharacteristicsAndSectorSize(TDbFile& aDbFile, TInt& aRecReadBufSize) |
2181 /* static */ TInt TVfs::DoGetDeviceCharacteristicsAndSectorSize(TDbFile& aDbFile, TInt& aRecReadBufSize) |
2122 { |
2182 { |
2123 __ASSERT_DEBUG(aDbFile.iDeviceCharacteristics < 0, User::Panic(KPanicCategory, EPanicInternalError)); |
2183 __ASSERT_DEBUG(aDbFile.iDeviceCharacteristics < 0, __SQLITEPANIC2(ESqliteOsPanicInternalError)); |
2124 __ASSERT_DEBUG(aDbFile.iSectorSize <= 0, User::Panic(KPanicCategory, EPanicInternalError)); |
2184 __ASSERT_DEBUG(aDbFile.iSectorSize <= 0, __SQLITEPANIC2(ESqliteOsPanicInternalError)); |
2125 TInt driveNo; |
2185 TInt driveNo; |
2126 TDriveInfo driveInfo; |
2186 TDriveInfo driveInfo; |
2127 __FS_CALL(EFsOpFileDrive, 0); |
2187 __FS_CALL(EFsOpFileDrive, 0); |
2128 TInt err = aDbFile.iFileBuf.Drive(driveNo, driveInfo); |
2188 TInt err = aDbFile.iFileBuf.Drive(driveNo, driveInfo); |
2129 if(err != KErrNone) |
2189 if(err != KErrNone) |
2232 @see COsLayerData::SetOsErrorCode() |
2295 @see COsLayerData::SetOsErrorCode() |
2233 @see TDbFile |
2296 @see TDbFile |
2234 */ |
2297 */ |
2235 /* static */ int TVfs::Open(sqlite3_vfs* aVfs, const char* aFileName, sqlite3_file* aDbFile, int aFlags, int* aOutFlags) |
2298 /* static */ int TVfs::Open(sqlite3_vfs* aVfs, const char* aFileName, sqlite3_file* aDbFile, int aFlags, int* aOutFlags) |
2236 { |
2299 { |
2237 SQLUTRACE_PROFILER(aVfs); |
|
2238 __OS_CALL(EOsVfsOpen, 0, 0); |
2300 __OS_CALL(EOsVfsOpen, 0, 0); |
2239 __OSTIME_COUNTER(TheOsCallTicks[EOsVfsOpen], ::OsCallProfile(EFalse, EOsVfsOpen), 0, 0, aDbFile, aFileName); |
2301 __OSTIME_COUNTER(TheOsCallTicks[EOsVfsOpen], ::OsCallProfile(EFalse, EOsVfsOpen), 0, 0, aDbFile, aFileName); |
2240 COsLayerData& osLayerData = COsLayerData::Instance(); |
2302 COsLayerData& osLayerData = COsLayerData::Instance(); |
2241 TFileName fname; |
|
2242 if(aFileName && !::ConvertToUnicode(aFileName, fname)) |
|
2243 { |
|
2244 osLayerData.SetOsErrorCode(KErrBadName); |
|
2245 return SQLITE_CANTOPEN; |
|
2246 } |
|
2247 SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KFileOpen, aDbFile, &fname)); |
|
2248 new (aDbFile) TDbFile; |
2303 new (aDbFile) TDbFile; |
2249 TDbFile& dbFile = ::DbFile(aDbFile); |
2304 TDbFile& dbFile = ::DbFile(aDbFile); |
|
2305 if(!aFileName) |
|
2306 { |
|
2307 //It is to create and open a temp file if aFileName is NULL. In this case, |
|
2308 //we will defer the file creation util it is needed. |
|
2309 dbFile.pMethods = &TheFileIoApi; |
|
2310 dbFile.iIsFileCreated = EFalse; |
|
2311 if(aOutFlags) |
|
2312 { |
|
2313 *aOutFlags = SQLITE_OPEN_READWRITE; |
|
2314 } |
|
2315 osLayerData.SetOsErrorCode(KErrNone); |
|
2316 return SQLITE_OK; |
|
2317 } |
|
2318 TFileName fname; |
|
2319 if(!::ConvertToUnicode(aFileName, fname)) |
|
2320 { |
|
2321 osLayerData.SetOsErrorCode(KErrBadName); |
|
2322 return SQLITE_CANTOPEN; |
|
2323 } |
|
2324 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)); |
2250 TFhStrType fhStrType = aFileName ? ::FhStringProps(aFileName) : ENotFhStr; |
2325 TFhStrType fhStrType = aFileName ? ::FhStringProps(aFileName) : ENotFhStr; |
2251 if(aFileName && (aFlags & SQLITE_OPEN_DELETEONCLOSE)) |
|
2252 { |
|
2253 dbFile.iFullName = fname.Alloc(); |
|
2254 if(!dbFile.iFullName) |
|
2255 { |
|
2256 osLayerData.SetOsErrorCode(KErrNoMemory); |
|
2257 return SQLITE_IOERR_NOMEM; |
|
2258 } |
|
2259 } |
|
2260 TInt recReadBufSize = -1; |
|
2261 TInt err = KErrNone; |
2326 TInt err = KErrNone; |
2262 if(fhStrType == EFhMainDbStr) |
2327 if(fhStrType == EFhMainDbStr) |
2263 {//Main db file, open from handle |
2328 {//Main db file, open from handle |
2264 const RMessage2* msg; |
2329 const RMessage2* msg; |
2265 TBool readOnly; |
2330 TBool readOnly; |
2279 } |
2344 } |
2280 if(aFlags & SQLITE_OPEN_EXCLUSIVE) |
2345 if(aFlags & SQLITE_OPEN_EXCLUSIVE) |
2281 { |
2346 { |
2282 fmode |= EFileShareExclusive; |
2347 fmode |= EFileShareExclusive; |
2283 } |
2348 } |
2284 if(!aFileName) |
2349 if(aFlags & SQLITE_OPEN_DELETEONCLOSE) |
2285 { |
2350 { |
2286 __FS_CALL(EFsOpFileCreateTemp, 0); |
2351 fmode |= EDeleteOnClose; |
2287 err = dbFile.iFileBuf.Temp(osLayerData.iFs, osLayerData.iSysPrivDir, fname, fmode); |
2352 } |
2288 if(err == KErrNone) |
2353 err = KErrAccessDenied; |
|
2354 TInt prevErr = KErrNone; |
|
2355 if(aFlags & SQLITE_OPEN_CREATE) |
|
2356 { |
|
2357 __FS_CALL(EFsOpFileCreate, 0); |
|
2358 prevErr = err = dbFile.iFileBuf.Create(osLayerData.iFs, fname, fmode); |
|
2359 } |
|
2360 if(err != KErrNone && err != KErrNoMemory && err != KErrDiskFull) |
|
2361 { |
|
2362 __FS_CALL(EFsOpFileOpen, 0); |
|
2363 err = dbFile.iFileBuf.Open(osLayerData.iFs, fname, fmode); |
|
2364 |
|
2365 if(err == KErrNone && (aFlags & KJournalFileTypeBitMask)) |
2289 { |
2366 { |
2290 dbFile.iFullName = fname.Alloc(); |
2367 err = TVfs::DoFileSizeCorruptionCheck(dbFile, fname, fmode); |
2291 if(!dbFile.iFullName) |
|
2292 { |
|
2293 err = KErrNoMemory; |
|
2294 } |
|
2295 } |
2368 } |
2296 } |
2369 } |
2297 else |
2370 if((err != KErrNone && err != KErrNoMemory && err != KErrDiskFull) && (aFlags & SQLITE_OPEN_READWRITE)) |
|
2371 { |
|
2372 aFlags &= ~SQLITE_OPEN_READWRITE; |
|
2373 aFlags |= SQLITE_OPEN_READONLY; |
|
2374 fmode &= ~EFileWrite; |
|
2375 __FS_CALL(EFsOpFileOpen, 0); |
|
2376 err = dbFile.iFileBuf.Open(osLayerData.iFs, fname, fmode); |
|
2377 } |
|
2378 if(err != KErrNone && prevErr == KErrAccessDenied) |
2298 { |
2379 { |
2299 err = KErrAccessDenied; |
2380 err = KErrAccessDenied; |
2300 TInt prevErr = KErrNone; |
2381 } |
2301 if(aFlags & SQLITE_OPEN_CREATE) |
2382 } |
2302 { |
2383 TInt recReadBufSize = -1; |
2303 __FS_CALL(EFsOpFileCreate, 0); |
|
2304 prevErr = err = dbFile.iFileBuf.Create(osLayerData.iFs, fname, fmode); |
|
2305 } |
|
2306 if(err != KErrNone && err != KErrNoMemory && err != KErrDiskFull) |
|
2307 { |
|
2308 __FS_CALL(EFsOpFileOpen, 0); |
|
2309 err = dbFile.iFileBuf.Open(osLayerData.iFs, fname, fmode); |
|
2310 |
|
2311 if(err == KErrNone && (aFlags & KJournalFileTypeBitMask)) |
|
2312 { |
|
2313 err = TVfs::DoFileSizeCorruptionCheck(dbFile, fname, fmode); |
|
2314 } |
|
2315 } |
|
2316 if((err != KErrNone && err != KErrNoMemory && err != KErrDiskFull) && (aFlags & SQLITE_OPEN_READWRITE)) |
|
2317 { |
|
2318 aFlags &= ~SQLITE_OPEN_READWRITE; |
|
2319 aFlags |= SQLITE_OPEN_READONLY; |
|
2320 fmode &= ~EFileWrite; |
|
2321 __FS_CALL(EFsOpFileOpen, 0); |
|
2322 err = dbFile.iFileBuf.Open(osLayerData.iFs, fname, fmode); |
|
2323 } |
|
2324 if(err != KErrNone && prevErr == KErrAccessDenied) |
|
2325 { |
|
2326 err = KErrAccessDenied; |
|
2327 } |
|
2328 } |
|
2329 } |
|
2330 if(err == KErrNone) |
2384 if(err == KErrNone) |
2331 { |
2385 { |
2332 err = TVfs::DoGetDeviceCharacteristicsAndSectorSize(dbFile, recReadBufSize); |
2386 err = TVfs::DoGetDeviceCharacteristicsAndSectorSize(dbFile, recReadBufSize); |
2333 } |
2387 } |
2334 osLayerData.SetOsErrorCode(err); |
2388 osLayerData.SetOsErrorCode(err); |
2335 if(err != KErrNone) |
2389 if(err != KErrNone) |
2336 { |
2390 { |
2337 __FS_CALL(EFsOpFileClose, 0); |
2391 __FS_CALL(EFsOpFileClose, 0); |
2338 dbFile.iFileBuf.Close(); |
2392 dbFile.iFileBuf.Close(); |
2339 delete dbFile.iFullName; |
|
2340 dbFile.iFullName = NULL; |
|
2341 if(!aFileName && fname.Length() > 0) |
|
2342 {//temporary file, the error is not KErrNone. Then delete the file (after a successfull |
|
2343 //temporary file creation there could be a failed memory allocation) |
|
2344 (void)osLayerData.iFs.Delete(fname); |
|
2345 } |
|
2346 } |
2393 } |
2347 else |
2394 else |
2348 { |
2395 { |
2349 dbFile.pMethods = &TheFileIoApi; |
2396 dbFile.pMethods = &TheFileIoApi; |
2350 if(fhStrType != EFhMainDbStr) |
2397 if(fhStrType != EFhMainDbStr) |
2381 |
2430 |
2382 @see COsLayerData::SetOsErrorCode() |
2431 @see COsLayerData::SetOsErrorCode() |
2383 */ |
2432 */ |
2384 /* static */ int TVfs::Delete(sqlite3_vfs* aVfs, const char* aFileName, int /*aSyncDir*/) |
2433 /* static */ int TVfs::Delete(sqlite3_vfs* aVfs, const char* aFileName, int /*aSyncDir*/) |
2385 { |
2434 { |
2386 SQLUTRACE_PROFILER(aVfs); |
|
2387 __OS_CALL(EOsVfsDelete, 0, 0); |
2435 __OS_CALL(EOsVfsDelete, 0, 0); |
2388 __OSTIME_COUNTER(TheOsCallTicks[EOsVfsDelete], ::OsCallProfile(EFalse, EOsVfsDelete), 0, 0, 0, aFileName); |
2436 __OSTIME_COUNTER(TheOsCallTicks[EOsVfsDelete], ::OsCallProfile(EFalse, EOsVfsDelete), 0, 0, 0, aFileName); |
2389 COsLayerData& osLayerData = COsLayerData::Instance(); |
2437 COsLayerData& osLayerData = COsLayerData::Instance(); |
2390 TBuf<KMaxFileName + 1> fname; |
2438 TBuf<KMaxFileName + 1> fname; |
2391 if(!::ConvertToUnicode(aFileName, fname)) |
2439 if(!::ConvertToUnicode(aFileName, fname)) |
2392 { |
2440 { |
2393 osLayerData.SetOsErrorCode(KErrBadName); |
2441 osLayerData.SetOsErrorCode(KErrBadName); |
|
2442 SQLITE_TRACE_OS(OstTrace0(TRACE_INTERNALS, TVFS_DELETE1, "OS;0;TVfs::Delete;err=KErrBadName")); |
2394 return SQLITE_ERROR; |
2443 return SQLITE_ERROR; |
2395 } |
2444 } |
2396 SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KFileName, &fname)); |
2445 SQLITE_TRACE_OS(OstTraceExt1(TRACE_INTERNALS, TVFS_DELETE_ENTRY, "OS-Entry;0;TVfs::Delete;fname=%S", __SQLITEPRNSTR(fname))); |
2397 TFhStrType fhStrType = FhStringProps(aFileName); |
2446 TFhStrType fhStrType = FhStringProps(aFileName); |
2398 if(fhStrType == EFhMainDbStr) |
2447 if(fhStrType == EFhMainDbStr) |
2399 {//Deleting files not in your own private data cage - not allowed! |
2448 {//Deleting files not in your own private data cage - not allowed! |
2400 osLayerData.SetOsErrorCode(KErrPermissionDenied); |
2449 osLayerData.SetOsErrorCode(KErrPermissionDenied); |
|
2450 SQLITE_TRACE_OS(OstTraceExt1(TRACE_INTERNALS, TVFS_DELETE2, "OS;0;TVfs::Delete;err=KErrPermissionDenied;fname=%S", __SQLITEPRNSTR(fname))); |
2401 return SQLITE_ERROR; |
2451 return SQLITE_ERROR; |
2402 } |
2452 } |
2403 if(fhStrType == EFhStr) |
2453 if(fhStrType == EFhStr) |
2404 { |
2454 { |
2405 ::FhConvertToFileName(fname, osLayerData.iSysPrivDir);//If fname does not have a path, iSysPrivDir will be used |
2455 ::FhConvertToFileName(fname, osLayerData.iSysPrivDir);//If fname does not have a path, iSysPrivDir will be used |
2406 } |
2456 } |
2407 __FS_CALL(EFsOpFileDelete, 0); |
2457 __FS_CALL(EFsOpFileDelete, 0); |
2408 TInt err = osLayerData.iFs.Delete(fname); |
2458 TInt err = osLayerData.iFs.Delete(fname); |
2409 osLayerData.SetOsErrorCode(err); |
2459 osLayerData.SetOsErrorCode(err); |
2410 return err == KErrNone ? SQLITE_OK : (err == KErrNoMemory ? SQLITE_IOERR_NOMEM : SQLITE_IOERR_DELETE); |
2460 TInt sqliteErr = ::Os2SqliteErr(err, SQLITE_IOERR_DELETE); |
|
2461 SQLITE_TRACE_OS(OstTraceExt2(TRACE_INTERNALS, TVFS_DELETE_EXIT, "OS-Exit;0;TVfs::Delete;err=%d;sqliteErr=%d", err, sqliteErr)); |
|
2462 return sqliteErr; |
2411 } |
2463 } |
2412 |
2464 |
2413 /** |
2465 /** |
2414 SQLite OS porting layer API. |
2466 SQLite OS porting layer API. |
2415 |
2467 |
2429 |
2481 |
2430 @see COsLayerData::SetOsErrorCode() |
2482 @see COsLayerData::SetOsErrorCode() |
2431 */ |
2483 */ |
2432 /* 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) |
2433 { |
2485 { |
2434 SQLUTRACE_PROFILER(aVfs); |
|
2435 __OS_CALL(EOsVfsAccess, 0, 0); |
2486 __OS_CALL(EOsVfsAccess, 0, 0); |
2436 __OSTIME_COUNTER(TheOsCallTicks[EOsVfsAccess], ::OsCallProfile(EFalse, EOsVfsAccess), aFlags, 0, 0, aFileName); |
2487 __OSTIME_COUNTER(TheOsCallTicks[EOsVfsAccess], ::OsCallProfile(EFalse, EOsVfsAccess), aFlags, 0, 0, aFileName); |
2437 COsLayerData& osLayerData = COsLayerData::Instance(); |
2488 COsLayerData& osLayerData = COsLayerData::Instance(); |
2438 TBuf<KMaxFileName + 1> fname; |
2489 TBuf<KMaxFileName + 1> fname; |
2439 if(!::ConvertToUnicode(aFileName, fname)) |
2490 if(!::ConvertToUnicode(aFileName, fname)) |
2440 { |
2491 { |
2441 osLayerData.SetOsErrorCode(KErrGeneral); |
2492 osLayerData.SetOsErrorCode(KErrGeneral); |
|
2493 SQLITE_TRACE_OS(OstTrace0(TRACE_INTERNALS, TVFS_ACCESS1, "OS;0;TVfs::Access;err=KErrGeneral")); |
2442 return SQLITE_IOERR_ACCESS; |
2494 return SQLITE_IOERR_ACCESS; |
2443 } |
2495 } |
2444 SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KFileName, &fname)); |
2496 SQLITE_TRACE_OS(OstTraceExt2(TRACE_INTERNALS, TVFS_ACCESS_ENTRY, "OS-Entry;0;TVfs::Access;fname=%S;aFlags=0x%X", __SQLITEPRNSTR(fname), (TUint)aFlags)); |
2445 TFhStrType fhStrType = ::FhStringProps(aFileName); |
2497 TFhStrType fhStrType = ::FhStringProps(aFileName); |
2446 if(fhStrType == EFhStr) |
2498 if(fhStrType == EFhStr) |
2447 { |
2499 { |
2448 ::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 |
2449 } |
2501 } |
2506 @return SQLITE_ERROR, The aRelative parameter is NULL or cannot be converted to UTF16; |
2561 @return SQLITE_ERROR, The aRelative parameter is NULL or cannot be converted to UTF16; |
2507 SQLITE_OK The operation has completed successfully. |
2562 SQLITE_OK The operation has completed successfully. |
2508 */ |
2563 */ |
2509 /* static */ int TVfs::FullPathName(sqlite3_vfs* aVfs, const char* aRelative, int aBufLen, char* aBuf) |
2564 /* static */ int TVfs::FullPathName(sqlite3_vfs* aVfs, const char* aRelative, int aBufLen, char* aBuf) |
2510 { |
2565 { |
2511 SQLUTRACE_PROFILER(aVfs); |
|
2512 __OS_CALL(EOsVfsFullPathName, 0, 0); |
2566 __OS_CALL(EOsVfsFullPathName, 0, 0); |
2513 __OSTIME_COUNTER(TheOsCallTicks[EOsVfsFullPathName], ::OsCallProfile(EFalse, EOsVfsFullPathName), aBufLen, 0, 0, aRelative); |
2567 __OSTIME_COUNTER(TheOsCallTicks[EOsVfsFullPathName], ::OsCallProfile(EFalse, EOsVfsFullPathName), aBufLen, 0, 0, aRelative); |
2514 COsLayerData& osLayerData = COsLayerData::Instance(); |
2568 COsLayerData& osLayerData = COsLayerData::Instance(); |
2515 osLayerData.StoreFhData(NULL, EFalse); |
2569 osLayerData.StoreFhData(NULL, EFalse); |
2516 //Convert the received file name to UTF16 |
2570 //Convert the received file name to UTF16 |
2517 TBuf<KMaxFileName + 1> fname; |
2571 TBuf<KMaxFileName + 1> fname; |
2518 if(!::ConvertToUnicode(aRelative, fname)) |
2572 if(!::ConvertToUnicode(aRelative, fname)) |
2519 { |
2573 { |
|
2574 SQLITE_TRACE_OS(OstTrace0(TRACE_INTERNALS, TVFS_FULLPATHNAME1, "OS;0;TVfs::FullPathName;err=SQLITE_ERROR")); |
2520 return SQLITE_ERROR; |
2575 return SQLITE_ERROR; |
2521 } |
2576 } |
2522 SYMBIAN_TRACE_SQL_EVENTS_ONLY(UTF::Printf(UTF::TTraceContext(UTF::EInternals), KFileName, &fname)); |
2577 SQLITE_TRACE_OS(OstTraceExt2(TRACE_INTERNALS, TVFS_FULLPATHNAME_ENTRY, "OS-Entry;0;TVfs::FullPathName;fname=%S;aBufLen=%d", __SQLITEPRNSTR(fname), aBufLen)); |
2523 //Zero-terminate the converted file name |
2578 //Zero-terminate the converted file name |
2524 fname.Append(TChar(0)); |
2579 fname.Append(TChar(0)); |
2525 TParse parse; |
2580 TParse parse; |
2526 TFhStrType strType = ::FhStringProps(aRelative);//Detect string type - it may not be a real file name |
2581 TFhStrType strType = ::FhStringProps(aRelative);//Detect string type - it may not be a real file name |
2527 if(strType == EFhMainDbStr) |
2582 if(strType == EFhMainDbStr) |
2553 |
2610 |
2554 @return The length of the used part of the output buffer. |
2611 @return The length of the used part of the output buffer. |
2555 */ |
2612 */ |
2556 /* static */ int TVfs::Randomness(sqlite3_vfs* aVfs, int aBufLen, char* aBuf) |
2613 /* static */ int TVfs::Randomness(sqlite3_vfs* aVfs, int aBufLen, char* aBuf) |
2557 { |
2614 { |
2558 SQLUTRACE_PROFILER(aVfs); |
|
2559 __OS_CALL(EOsVfsRandomness, 0, 0); |
2615 __OS_CALL(EOsVfsRandomness, 0, 0); |
2560 __OSTIME_COUNTER(TheOsCallTicks[EOsVfsRandomness], ::OsCallProfile(EFalse, EOsVfsRandomness), aBufLen, 0, 0, 0); |
2616 __OSTIME_COUNTER(TheOsCallTicks[EOsVfsRandomness], ::OsCallProfile(EFalse, EOsVfsRandomness), aBufLen, 0, 0, 0); |
2561 COsLayerData& osLayerData = COsLayerData::Instance(); |
2617 COsLayerData& osLayerData = COsLayerData::Instance(); |
2562 const TInt KRandIterations = aBufLen / sizeof(int); |
2618 const TInt KRandIterations = aBufLen / sizeof(int); |
2563 for(TInt i=0;i<KRandIterations;++i) |
2619 for(TInt i=0;i<KRandIterations;++i) |