1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
1 // Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies). |
2 // All rights reserved. |
2 // All rights reserved. |
3 // This component and the accompanying materials are made available |
3 // This component and the accompanying materials are made available |
4 // under the terms of "Eclipse Public License v1.0" |
4 // under the terms of "Eclipse Public License v1.0" |
5 // which accompanies this distribution, and is available |
5 // which accompanies this distribution, and is available |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
817 static TInt DoOpenFromHandle(TDbFile& aDbFile, const RMessage2& aMsg, TBool aReadOnly); |
817 static TInt DoOpenFromHandle(TDbFile& aDbFile, const RMessage2& aMsg, TBool aReadOnly); |
818 static inline TInt DoGetVolumeIoParamInfo(RFs& aFs, TInt aDriveNo, TVolumeIOParamInfo& aVolumeInfo); |
818 static inline TInt DoGetVolumeIoParamInfo(RFs& aFs, TInt aDriveNo, TVolumeIOParamInfo& aVolumeInfo); |
819 static TInt DoGetDeviceCharacteristics(const TDriveInfo& aDriveInfo, const TVolumeIOParamInfo& aVolumeInfo); |
819 static TInt DoGetDeviceCharacteristics(const TDriveInfo& aDriveInfo, const TVolumeIOParamInfo& aVolumeInfo); |
820 static TInt DoGetSectorSize(const TDriveInfo& aDriveInfo, const TVolumeIOParamInfo& aVolumeInfo); |
820 static TInt DoGetSectorSize(const TDriveInfo& aDriveInfo, const TVolumeIOParamInfo& aVolumeInfo); |
821 static TInt DoGetDeviceCharacteristicsAndSectorSize(TDbFile& aDbFile, TInt& aRecReadBufSize); |
821 static TInt DoGetDeviceCharacteristicsAndSectorSize(TDbFile& aDbFile, TInt& aRecReadBufSize); |
822 |
822 static TInt DoFileSizeCorruptionCheck(TDbFile& aDbFile, const TDesC& aFname, TInt aFmode); |
823 }; |
823 }; |
824 |
824 |
825 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
825 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
826 ///////////////////// Global variables, constants //////////////////////////////////////////////////////////////////// |
826 ///////////////////// Global variables, constants //////////////////////////////////////////////////////////////////// |
827 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
827 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
2101 aDbFile.iDeviceCharacteristics = TVfs::DoGetDeviceCharacteristics(driveInfo, volumeInfo); |
2101 aDbFile.iDeviceCharacteristics = TVfs::DoGetDeviceCharacteristics(driveInfo, volumeInfo); |
2102 aDbFile.iSectorSize = TVfs::DoGetSectorSize(driveInfo, volumeInfo); |
2102 aDbFile.iSectorSize = TVfs::DoGetSectorSize(driveInfo, volumeInfo); |
2103 aRecReadBufSize = volumeInfo.iRecReadBufSize; |
2103 aRecReadBufSize = volumeInfo.iRecReadBufSize; |
2104 return KErrNone; |
2104 return KErrNone; |
2105 } |
2105 } |
|
2106 |
|
2107 /** |
|
2108 SQLite OS porting layer API. |
|
2109 |
|
2110 The behaviour of the RFile/RFile64::SetSize operation is not atomic for non-rugged drives. |
|
2111 When RFile/RFile64::SetSize() is called 2 operations occurs:- |
|
2112 |
|
2113 1)The cluster chain of the file is updated. |
|
2114 2)The new file size is added to the file cache. |
|
2115 |
|
2116 If a power loss occurs after a SetSize there is a chance that the cluster chain was updated |
|
2117 but the new file size is not yet flushed to the file. This puts the file into an inconsistent state. |
|
2118 This is most likely to occur in the journal file where the time between a SetSize and Flush can |
|
2119 be long. |
|
2120 |
|
2121 For this reason this check is added when the file is opened to see if the end of the file can |
|
2122 be read straight away, if an error is returned then it is assumed that the SetSize has not be |
|
2123 completed previously. In this case the file is deleted and re-created. |
|
2124 |
|
2125 @param aDbFile A pointer to a TDbFile instance, that contains the file handle. |
|
2126 @param aFname A string of 16-bit wide characters containing name of the file to be checked. |
|
2127 @param aFmode The mode in which the file is opened. These mode are documented in TFileMode. |
|
2128 |
|
2129 @return KErrNone, The operation has completed succesfully; |
|
2130 Note that other system-wide error codes may also be returned. |
|
2131 @see TFileMode |
|
2132 @see TVfs::Open() |
|
2133 @see TDbFile |
|
2134 */ |
|
2135 /* static */ TInt TVfs::DoFileSizeCorruptionCheck(TDbFile& aDbFile, const TDesC& aFname, TInt aFmode) |
|
2136 { |
|
2137 const TInt KMinSize = 16; |
|
2138 TInt64 size; |
|
2139 TInt err = KErrNone ; |
|
2140 TBuf8<KMinSize> buf; |
|
2141 |
|
2142 err = aDbFile.iFileBuf.Size(size); |
|
2143 if (err != KErrNone) |
|
2144 { |
|
2145 return err; |
|
2146 } |
|
2147 TBool IsMinFileSize = (size >= KMinSize); |
|
2148 |
|
2149 if (IsMinFileSize) |
|
2150 { |
|
2151 err = aDbFile.iFileBuf.Read(size - KMinSize, buf); |
|
2152 } |
|
2153 |
|
2154 if (err == KErrCorrupt || err == KErrEof || !IsMinFileSize) |
|
2155 { |
|
2156 COsLayerData& osLayerData = COsLayerData::Instance(); |
|
2157 |
|
2158 aDbFile.iFileBuf.Close(); |
|
2159 (void) osLayerData.iFs.Delete(aFname); |
|
2160 err = aDbFile.iFileBuf.Create(osLayerData.iFs, aFname, aFmode); |
|
2161 } |
|
2162 return err; |
|
2163 } |
2106 |
2164 |
2107 /** |
2165 /** |
2108 SQLite OS porting layer API. |
2166 SQLite OS porting layer API. |
2109 |
2167 |
2110 Opens or creates a file which name is in the aFileName parameter. |
2168 Opens or creates a file which name is in the aFileName parameter. |
2209 } |
2267 } |
2210 if(err != KErrNone && err != KErrNoMemory && err != KErrDiskFull) |
2268 if(err != KErrNone && err != KErrNoMemory && err != KErrDiskFull) |
2211 { |
2269 { |
2212 __FS_CALL(EFsOpFileOpen, 0); |
2270 __FS_CALL(EFsOpFileOpen, 0); |
2213 err = dbFile.iFileBuf.Open(osLayerData.iFs, fname, fmode); |
2271 err = dbFile.iFileBuf.Open(osLayerData.iFs, fname, fmode); |
|
2272 |
|
2273 if(err == KErrNone && ((aFlags & SQLITE_OPEN_MAIN_JOURNAL) || (aFlags & SQLITE_OPEN_TEMP_JOURNAL) || |
|
2274 (aFlags & SQLITE_OPEN_SUBJOURNAL) || (aFlags & SQLITE_OPEN_MASTER_JOURNAL))) |
|
2275 { |
|
2276 err = TVfs::DoFileSizeCorruptionCheck(dbFile, fname, fmode); |
|
2277 } |
2214 } |
2278 } |
2215 if((err != KErrNone && err != KErrNoMemory && err != KErrDiskFull) && (aFlags & SQLITE_OPEN_READWRITE)) |
2279 if((err != KErrNone && err != KErrNoMemory && err != KErrDiskFull) && (aFlags & SQLITE_OPEN_READWRITE)) |
2216 { |
2280 { |
2217 aFlags &= ~SQLITE_OPEN_READWRITE; |
2281 aFlags &= ~SQLITE_OPEN_READWRITE; |
2218 aFlags |= SQLITE_OPEN_READONLY; |
2282 aFlags |= SQLITE_OPEN_READONLY; |
2219 fmode &= ~EFileWrite; |
2283 fmode &= ~EFileWrite; |
2220 __FS_CALL(EFsOpFileOpen, 0); |
2284 __FS_CALL(EFsOpFileOpen, 0); |
2221 err = dbFile.iFileBuf.Open(osLayerData.iFs, fname, fmode); |
2285 err = dbFile.iFileBuf.Open(osLayerData.iFs, fname, fmode); |
2222 } |
2286 } |
2223 if(err != KErrNone && prevErr == KErrAccessDenied) |
2287 if(err != KErrNone && prevErr == KErrAccessDenied) |
2224 { |
2288 { |
2225 err = KErrAccessDenied; |
2289 err = KErrAccessDenied; |
2226 } |
2290 } |
2227 } |
2291 } |