equal
deleted
inserted
replaced
101 __ASSERT_DEBUG(seekPos<KSeekIndexSize,Fault(EFatFileSeekIndexTooSmall)); |
101 __ASSERT_DEBUG(seekPos<KSeekIndexSize,Fault(EFatFileSeekIndexTooSmall)); |
102 __ASSERT_DEBUG(seekPos>=0,Fault(EFatFileSeekIndexTooSmall2)); |
102 __ASSERT_DEBUG(seekPos>=0,Fault(EFatFileSeekIndexTooSmall2)); |
103 iSeekIndex[seekPos] = aStoredCluster; |
103 iSeekIndex[seekPos] = aStoredCluster; |
104 } |
104 } |
105 |
105 |
106 TBool CFatFileCB::IsSeekBackwards(TUint aPos) |
|
107 // |
|
108 // Return true if aPos<currentPos |
|
109 // |
|
110 { |
|
111 |
|
112 TUint cluster=iCurrentPos.iCluster<<ClusterSizeLog2(); |
|
113 TInt offset=ClusterRelativePos(iCurrentPos.iPos); |
|
114 TUint currentPos=cluster+offset; |
|
115 return(aPos<currentPos); |
|
116 } |
|
117 |
|
118 void CFatFileCB::CheckPosL(TUint aPos) |
106 void CFatFileCB::CheckPosL(TUint aPos) |
119 // |
107 // |
120 // Check that the file is positioned correctly. |
108 // Check that the file is positioned correctly. |
121 // If aPos<currentPos attempt to guess the new position. |
109 // If aPos<currentPos attempt to guess the new position. |
122 // |
110 // |
124 __PRINT1(_L("CFatFileCB::CheckPosL(%d)"), aPos); |
112 __PRINT1(_L("CFatFileCB::CheckPosL(%d)"), aPos); |
125 if (aPos==iCurrentPos.iPos) |
113 if (aPos==iCurrentPos.iPos) |
126 return; |
114 return; |
127 __ASSERT_DEBUG(aPos <= FCB_FileSize(), Fault(EFatFilePosBeyondEnd)); |
115 __ASSERT_DEBUG(aPos <= FCB_FileSize(), Fault(EFatFilePosBeyondEnd)); |
128 |
116 |
129 if (FileSizeModified() && IsSeekBackwards(aPos)) |
|
130 FlushDataL(); |
|
131 |
|
132 TUint newRelCluster=aPos>>ClusterSizeLog2(); |
117 TUint newRelCluster=aPos>>ClusterSizeLog2(); |
133 if ( aPos && (aPos==(newRelCluster<<ClusterSizeLog2())) ) |
118 if ( aPos && (aPos==(newRelCluster<<ClusterSizeLog2())) ) |
134 newRelCluster--; |
119 newRelCluster--; |
135 TUint oldRelCluster=iCurrentPos.iPos>>ClusterSizeLog2(); |
120 TUint oldRelCluster=iCurrentPos.iPos>>ClusterSizeLog2(); |
136 |
121 |
243 const TUint curSize = FCB_FileSize(); |
228 const TUint curSize = FCB_FileSize(); |
244 const TUint length = (TUint)aLength; |
229 const TUint length = (TUint)aLength; |
245 |
230 |
246 if((startPos + length > curSize) || (startPos > startPos + length) ) |
231 if((startPos + length > curSize) || (startPos > startPos + length) ) |
247 aLength=curSize-startPos; |
232 aLength=curSize-startPos; |
248 |
233 |
249 FatMount().ReadFromClusterListL(iCurrentPos,aLength,aDes,aMessage,aOffset); |
234 TUint flag = DirectIOMode(aMessage) ? RLocalDrive::ELocDrvDirectIO : 0; |
|
235 |
|
236 FatMount().ReadFromClusterListL(iCurrentPos,aLength,aDes,aMessage,aOffset, flag); |
250 aLength=iCurrentPos.iPos-startPos; |
237 aLength=iCurrentPos.iPos-startPos; |
251 } |
238 } |
252 |
239 |
253 |
240 |
254 void CFatFileCB::ReadL(TInt aFilePos,TInt& aLength,const TAny* aTrg,const RMessagePtr2& aMessage) |
241 void CFatFileCB::ReadL(TInt aFilePos,TInt& aLength,const TAny* aTrg,const RMessagePtr2& aMessage) |
293 |
280 |
294 TUint startPos=iCurrentPos.iPos; |
281 TUint startPos=iCurrentPos.iPos; |
295 TUint badcluster=0; |
282 TUint badcluster=0; |
296 TUint goodcluster=0; |
283 TUint goodcluster=0; |
297 |
284 |
298 TRAPD(ret, FatMount().WriteToClusterListL(iCurrentPos,aLength,aSrc,aMessage,aOffset,badcluster, goodcluster)); |
285 TUint flag = DirectIOMode(aMessage) ? RLocalDrive::ELocDrvDirectIO : 0; |
|
286 |
|
287 TRAPD(ret, FatMount().WriteToClusterListL(iCurrentPos,aLength,aSrc,aMessage,aOffset,badcluster, goodcluster, flag)); |
299 |
288 |
300 if (ret == KErrCorrupt || ret == KErrDied) |
289 if (ret == KErrCorrupt || ret == KErrDied) |
301 { |
290 { |
302 if(startCluster == 0) |
291 if(startCluster == 0) |
303 { //Empty File, revert all the clusters allocated. |
292 { //Empty File, revert all the clusters allocated. |
862 if((fatMount.LocalDrive()->GetLocalDrive(locDrv)==KErrNone) && ((drvNo=GetLocalDriveNumber(locDrv))>=0) && (drvNo<KMaxLocalDrives)) |
851 if((fatMount.LocalDrive()->GetLocalDrive(locDrv)==KErrNone) && ((drvNo=GetLocalDriveNumber(locDrv))>=0) && (drvNo<KMaxLocalDrives)) |
863 aInfo.iLocalDriveNumber=drvNo; |
852 aInfo.iLocalDriveNumber=drvNo; |
864 else |
853 else |
865 return KErrNotSupported; |
854 return KErrNotSupported; |
866 |
855 |
867 // Fetch the address of cluster 0 |
856 TInt r; |
868 aInfo.iStartBlockAddress = fatMount.FAT().DataPositionInBytes(KFirstClusterNum); |
857 |
869 |
858 // Fetch the address of cluster 0 |
870 TRAPD(r, CheckPosL(startPos)); |
859 TRAP(r, aInfo.iStartBlockAddress = fatMount.FAT().DataPositionInBytesL(KFirstClusterNum)); |
|
860 if (r != KErrNone) |
|
861 return r; |
|
862 |
|
863 |
|
864 TRAP(r, CheckPosL(startPos)); |
871 if (r != KErrNone) |
865 if (r != KErrNone) |
872 return r; |
866 return r; |
873 |
867 |
874 aInfo.iBlockStartOffset = fatMount.ClusterRelativePos(iCurrentPos.iPos); |
868 aInfo.iBlockStartOffset = fatMount.ClusterRelativePos(iCurrentPos.iPos); |
875 aInfo.iBlockGranularity = 1 << FatMount().ClusterSizeLog2(); |
869 aInfo.iBlockGranularity = 1 << FatMount().ClusterSizeLog2(); |