969 */ |
969 */ |
970 /* static */ TInt COsLayerData::Create() |
970 /* static */ TInt COsLayerData::Create() |
971 { |
971 { |
972 SQLITE_TRACE_OS(OstTrace0(TRACE_INTERNALS, COSLAYERDATA_CREATE_ENTRY, "OS-Entry;0;COsLayerData::Create")); |
972 SQLITE_TRACE_OS(OstTrace0(TRACE_INTERNALS, COSLAYERDATA_CREATE_ENTRY, "OS-Entry;0;COsLayerData::Create")); |
973 __ASSERT_DEBUG(!COsLayerData::iOsLayerData, __SQLITEPANIC2(ESqliteOsPanicOsLayerDataExists)); |
973 __ASSERT_DEBUG(!COsLayerData::iOsLayerData, __SQLITEPANIC2(ESqliteOsPanicOsLayerDataExists)); |
|
974 COsLayerData::iOsLayerData = new COsLayerData; |
974 if(!COsLayerData::iOsLayerData) |
975 if(!COsLayerData::iOsLayerData) |
975 { |
976 { |
976 COsLayerData::iOsLayerData = new COsLayerData; |
977 SQLITE_TRACE_OS(OstTrace0(TRACE_INTERNALS, COSLAYERDATA_CREATE_EXIT1, "OS-Exit;0;COsLayerData::Create;err=KErrNoMemory")); |
977 if(!COsLayerData::iOsLayerData) |
978 return KErrNoMemory; |
978 { |
979 } |
979 SQLITE_TRACE_OS(OstTrace0(TRACE_INTERNALS, COSLAYERDATA_CREATE_EXIT1, "OS-Exit;0;COsLayerData::Create;err=KErrNoMemory")); |
980 TInt err = COsLayerData::iOsLayerData->DoCreate(); |
980 return KErrNoMemory; |
981 if(err != KErrNone) |
981 } |
982 { |
982 TInt err = COsLayerData::iOsLayerData->DoCreate(); |
983 delete COsLayerData::iOsLayerData; |
983 if(err != KErrNone) |
984 COsLayerData::iOsLayerData = NULL; |
984 { |
985 SQLITE_TRACE_OS(OstTrace1(TRACE_INTERNALS, COSLAYERDATA_CREATE_EXIT2, "OS-Exit;0;COsLayerData::Create;err=%d", err)); |
985 delete COsLayerData::iOsLayerData; |
986 return err; |
986 COsLayerData::iOsLayerData = NULL; |
|
987 SQLITE_TRACE_OS(OstTrace1(TRACE_INTERNALS, COSLAYERDATA_CREATE_EXIT2, "OS-Exit;0;COsLayerData::Create;err=%d", err)); |
|
988 return err; |
|
989 } |
|
990 } |
987 } |
991 SQLITE_TRACE_OS(OstTrace0(TRACE_INTERNALS, COSLAYERDATA_CREATE_EXIT3, "OS-Exit;0;COsLayerData::Create;err=KErrNone")); |
988 SQLITE_TRACE_OS(OstTrace0(TRACE_INTERNALS, COSLAYERDATA_CREATE_EXIT3, "OS-Exit;0;COsLayerData::Create;err=KErrNone")); |
992 return KErrNone; |
989 return KErrNone; |
993 } |
990 } |
994 |
991 |
1981 { |
1978 { |
1982 TDbFile& dbFile = ::DbFile(aDbFile); |
1979 TDbFile& dbFile = ::DbFile(aDbFile); |
1983 __OS_CALL(EOsFileSectorSize, 0, 0); |
1980 __OS_CALL(EOsFileSectorSize, 0, 0); |
1984 __OSTIME_COUNTER(TheOsCallTicks[EOsFileSectorSize], ::OsCallProfile(dbFile.iIsJournal, EOsFileSectorSize), 0, 0, aDbFile, 0); |
1981 __OSTIME_COUNTER(TheOsCallTicks[EOsFileSectorSize], ::OsCallProfile(dbFile.iIsJournal, EOsFileSectorSize), 0, 0, aDbFile, 0); |
1985 __ASSERT_DEBUG(dbFile.iSectorSize > 0, __SQLITEPANIC2(ESqliteOsPanicInternalError)); |
1982 __ASSERT_DEBUG(dbFile.iSectorSize > 0, __SQLITEPANIC2(ESqliteOsPanicInternalError)); |
1986 if(dbFile.iSectorSize > 0) |
1983 return dbFile.iSectorSize; |
1987 { |
|
1988 return dbFile.iSectorSize; |
|
1989 } |
|
1990 return SQLITE_DEFAULT_SECTOR_SIZE; |
|
1991 } |
1984 } |
1992 |
1985 |
1993 /** |
1986 /** |
1994 SQLite OS porting layer API. |
1987 SQLite OS porting layer API. |
1995 |
1988 |
2011 { |
2004 { |
2012 TDbFile& dbFile = ::DbFile(aDbFile); |
2005 TDbFile& dbFile = ::DbFile(aDbFile); |
2013 __OS_CALL(EOsFileDeviceCharacteristics, 0, 0); |
2006 __OS_CALL(EOsFileDeviceCharacteristics, 0, 0); |
2014 __OSTIME_COUNTER(TheOsCallTicks[EOsFileDeviceCharacteristics], ::OsCallProfile(dbFile.iIsJournal, EOsFileDeviceCharacteristics), 0, 0, aDbFile, 0); |
2007 __OSTIME_COUNTER(TheOsCallTicks[EOsFileDeviceCharacteristics], ::OsCallProfile(dbFile.iIsJournal, EOsFileDeviceCharacteristics), 0, 0, aDbFile, 0); |
2015 __ASSERT_DEBUG(dbFile.iDeviceCharacteristics >= 0, __SQLITEPANIC2(ESqliteOsPanicInternalError)); |
2008 __ASSERT_DEBUG(dbFile.iDeviceCharacteristics >= 0, __SQLITEPANIC2(ESqliteOsPanicInternalError)); |
2016 if(dbFile.iDeviceCharacteristics >= 0) |
2009 return dbFile.iDeviceCharacteristics; |
2017 { |
|
2018 return dbFile.iDeviceCharacteristics; |
|
2019 } |
|
2020 return 0; |
|
2021 } |
2010 } |
2022 |
2011 |
2023 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
2012 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
2024 /////////////////////////////////// TVfs class definition /////////////////////////////////////////////////////////// |
2013 /////////////////////////////////// TVfs class definition /////////////////////////////////////////////////////////// |
2025 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
2014 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
2072 TInt err = aFs.VolumeIOParam(aDriveNo, aVolumeInfo); |
2061 TInt err = aFs.VolumeIOParam(aDriveNo, aVolumeInfo); |
2073 SQLITE_TRACE_OS(OstTraceExt2(TRACE_INTERNALS, TVFS_DOGETVOLUMEIOPARAMINFO, "OS;0;TVfs::DoGetVolumeIoParamInfo;aDriveNo=%d;err=%d", aDriveNo, err)); |
2062 SQLITE_TRACE_OS(OstTraceExt2(TRACE_INTERNALS, TVFS_DOGETVOLUMEIOPARAMINFO, "OS;0;TVfs::DoGetVolumeIoParamInfo;aDriveNo=%d;err=%d", aDriveNo, err)); |
2074 return err; |
2063 return err; |
2075 } |
2064 } |
2076 |
2065 |
|
2066 //Maps disk sector sizes to SQLITE_IOCAP_ATOMIC<n> constants |
|
2067 |
|
2068 struct TSqliteSectorSizeMap |
|
2069 { |
|
2070 TInt iSectorSize; |
|
2071 TInt iSqliteSectorSizeConstant; |
|
2072 }; |
|
2073 |
|
2074 //Used in TVfs::DoGetDeviceCharacteristics() to find which SQLITE_IOCAP_ATOMIC<n> constant should be used |
|
2075 //for the specified sector size |
|
2076 const TSqliteSectorSizeMap KSqliteSectorSizeMap[] = |
|
2077 { |
|
2078 { 512, SQLITE_IOCAP_ATOMIC512}, |
|
2079 { 1024, SQLITE_IOCAP_ATOMIC1K}, |
|
2080 { 2048, SQLITE_IOCAP_ATOMIC2K}, |
|
2081 { 4096, SQLITE_IOCAP_ATOMIC4K}, |
|
2082 { 8192, SQLITE_IOCAP_ATOMIC8K}, |
|
2083 {16384, SQLITE_IOCAP_ATOMIC16K}, |
|
2084 {32768, SQLITE_IOCAP_ATOMIC32K}, |
|
2085 {65536, SQLITE_IOCAP_ATOMIC64K} |
|
2086 }; |
|
2087 |
2077 /** |
2088 /** |
2078 Retrieves and returns in a bit set the device characteristics. |
2089 Retrieves and returns in a bit set the device characteristics. |
2079 |
2090 |
2080 @param aDriveInfo A TDriveInfo reference from which the device characteristics will be extracted. |
2091 @param aDriveInfo A TDriveInfo reference from which the device characteristics will be extracted. |
2081 @param aVolumeInfo A TVolumeIOParamInfo reference from which the device characteristics will be extracted. |
2092 @param aVolumeInfo A TVolumeIOParamInfo reference from which the device characteristics will be extracted. |
2095 } |
2106 } |
2096 if(aDriveInfo.iDriveAtt & KDriveAttTransaction) |
2107 if(aDriveInfo.iDriveAtt & KDriveAttTransaction) |
2097 { |
2108 { |
2098 deviceCharacteristics |= SQLITE_IOCAP_ATOMIC; |
2109 deviceCharacteristics |= SQLITE_IOCAP_ATOMIC; |
2099 } |
2110 } |
2100 switch(aVolumeInfo.iBlockSize) |
2111 for(TInt i=0;i<(sizeof(KSqliteSectorSizeMap)/sizeof(KSqliteSectorSizeMap[0]));++i) |
2101 { |
2112 { |
2102 case 512: |
2113 if(KSqliteSectorSizeMap[i].iSectorSize == aVolumeInfo.iBlockSize) |
2103 deviceCharacteristics |= SQLITE_IOCAP_ATOMIC512; |
2114 { |
2104 break; |
2115 deviceCharacteristics |= KSqliteSectorSizeMap[i].iSqliteSectorSizeConstant; |
2105 case 1024: |
2116 break; |
2106 deviceCharacteristics |= SQLITE_IOCAP_ATOMIC1K; |
2117 } |
2107 break; |
|
2108 case 2048: |
|
2109 deviceCharacteristics |= SQLITE_IOCAP_ATOMIC2K; |
|
2110 break; |
|
2111 case 4096: |
|
2112 deviceCharacteristics |= SQLITE_IOCAP_ATOMIC4K; |
|
2113 break; |
|
2114 case 8192: |
|
2115 deviceCharacteristics |= SQLITE_IOCAP_ATOMIC8K; |
|
2116 break; |
|
2117 case 16384: |
|
2118 deviceCharacteristics |= SQLITE_IOCAP_ATOMIC16K; |
|
2119 break; |
|
2120 case 32768: |
|
2121 deviceCharacteristics |= SQLITE_IOCAP_ATOMIC32K; |
|
2122 break; |
|
2123 case 65536: |
|
2124 deviceCharacteristics |= SQLITE_IOCAP_ATOMIC64K; |
|
2125 break; |
|
2126 default: |
|
2127 //Do nothing. deviceCharacteristics was initialized with 0 at the beginning of the function body. |
|
2128 break; |
|
2129 } |
2118 } |
2130 return deviceCharacteristics; |
2119 return deviceCharacteristics; |
2131 } |
2120 } |
2132 |
2121 |
2133 /** |
2122 /** |