diff -r 345b1ca54e88 -r 039a3e647356 userlibandfileserver/fileserver/sfat32/sl_mnt.cpp --- a/userlibandfileserver/fileserver/sfat32/sl_mnt.cpp Wed Sep 15 13:42:27 2010 +0300 +++ b/userlibandfileserver/fileserver/sfat32/sl_mnt.cpp Wed Oct 13 16:04:24 2010 +0300 @@ -539,7 +539,7 @@ User::Leave(KErrAccessDenied); //-- can't override RO flag } - (void)LocalDrive()->Finalise(ETrue); + (void)LocalDrive()->Finalise(ETrue); if(aOperation == RFs::EFinal_RO) { @@ -550,8 +550,10 @@ return; } - if(Locked()) - {//-- can't finalise the volume if it has opened disk access objects, like Format or RawAccess + if(LockStatus() != 0) + {//-- can't finalise the volume if it has opened objects and not in the consistent state. + //-- Theoretically, we can finalise the mount if we have files opened only for read, but at present, + //-- it's impossible to detect such situation. User::Leave(KErrInUse); } @@ -599,8 +601,6 @@ if(aOperation == RFs::EFinal_RO) SetReadOnly(ETrue); - (void)LocalDrive()->Finalise(ETrue); - SetState(EFinalised); } @@ -1610,7 +1610,7 @@ /** Overwrite as many contiguous file clusters as possible. */ -void CFatMountCB::DoWriteToClusterListL(TEntryPos& aPos,TInt aLength,const TAny* aSrc,const RMessagePtr2& aMessage,TInt anOffset, TUint aLastcluster, TUint& aBadcluster, TUint& aGoodcluster, TUint aFlag) +void CFatMountCB::DoWriteToClusterListL(TEntryPos& aPos,TInt aLength,const TAny* aSrc,const RMessagePtr2& aMessage,TInt anOffset, TUint aLastcluster, TUint& aBadcluster, TUint& aGoodcluster) { __PRINT(_L("CFatMountCB::DoWriteToClusterListL")); @@ -1622,9 +1622,9 @@ const TInt maxClusters=((aLength+clusterRelativePos-1)>>ClusterSizeLog2())+1; const TInt clusterListLen=FAT().CountContiguousClustersL(aPos.iCluster,endCluster,maxClusters); const TInt writeLength=Min(aLength,(clusterListLen<WriteL(dataStart,writeLength,aSrc,aMessage,anOffset, aFlag)); + TInt64 dataStart=FAT().DataPositionInBytes(aPos.iCluster)+clusterRelativePos; + + TRAPD(r, iRawDisk->WriteL(dataStart,writeLength,aSrc,aMessage,anOffset)); if(r == KErrNone) // Write succeded { @@ -1653,7 +1653,7 @@ if((aPos.iPos != 0) && (badcluster == aPos.iCluster) && (aLastcluster == 0) && (aPos.iCluster == cluster)) { //Copy the contents already present in this cluster to new cluster allocated. const TInt sizeToRead = aPos.iPos - ((aPos.iPos >> ClusterSizeLog2()) << ClusterSizeLog2()); - dataStart = FAT().DataPositionInBytesL(aPos.iCluster) + ClusterRelativePos((aPos.iPos - sizeToRead)); + dataStart = FAT().DataPositionInBytes(aPos.iCluster) + ClusterRelativePos((aPos.iPos - sizeToRead)); //-- Allocate the buffer required to copy the contents from bad cluster @@ -1682,7 +1682,7 @@ { //Calculate and copy the contents to new cluster. aPos.iCluster = goodcluster; - dataStart = FAT().DataPositionInBytesL(aPos.iCluster) + ClusterRelativePos(aPos.iPos - sizeToRead); + dataStart = FAT().DataPositionInBytes(aPos.iCluster) + ClusterRelativePos(aPos.iPos - sizeToRead); r = LocalDrive()->Write(dataStart, clustBuf); if(r == KErrNone) @@ -1739,7 +1739,7 @@ //----------------------------------------------------------------------------------------- -void CFatMountCB::WriteToClusterListL(TEntryPos& aPos,TInt aLength,const TAny* aSrc,const RMessagePtr2& aMessage,TInt anOffset, TUint& aBadcluster, TUint& aGoodcluster, TUint aFlag) +void CFatMountCB::WriteToClusterListL(TEntryPos& aPos,TInt aLength,const TAny* aSrc,const RMessagePtr2& aMessage,TInt anOffset, TUint& aBadcluster, TUint& aGoodcluster) // // Overwrite cluster list. // @@ -1761,7 +1761,7 @@ TInt previouscluster=0; FOREVER { - DoWriteToClusterListL(aPos,length-offset,aSrc,aMessage,anOffset+offset, previouscluster, aBadcluster, aGoodcluster, aFlag); + DoWriteToClusterListL(aPos,length-offset,aSrc,aMessage,anOffset+offset, previouscluster, aBadcluster, aGoodcluster); if (offset == (aPos.iPos-startPos)) continue; offset=aPos.iPos-startPos; @@ -1776,7 +1776,7 @@ //----------------------------------------------------------------------------------------- -void CFatMountCB::DoReadFromClusterListL(TEntryPos& aPos,TInt aLength,const TAny* aTrg,const RMessagePtr2& aMessage,TInt anOffset, TUint aFlag) const +void CFatMountCB::DoReadFromClusterListL(TEntryPos& aPos,TInt aLength,const TAny* aTrg,const RMessagePtr2& aMessage,TInt anOffset) const // // Read from as many contiguous file clusters as possible // @@ -1790,9 +1790,9 @@ const TInt maxClusters=((aLength+clusterRelativePos-1)>>ClusterSizeLog2())+1; const TInt clusterListLen=FAT().CountContiguousClustersL(aPos.iCluster,endCluster,maxClusters); const TInt readLength=Min(aLength,(clusterListLen<ReadL(dataStart,readLength,aTrg,aMessage,anOffset, aFlag)); + const TInt64 dataStart=FAT().DataPositionInBytes(aPos.iCluster)+clusterRelativePos; + + TRAPD(r, iRawDisk->ReadL(dataStart,readLength,aTrg,aMessage,anOffset)); if(r == KErrNone) // Read succeded { @@ -1817,7 +1817,7 @@ //----------------------------------------------------------------------------------------- -void CFatMountCB::ReadFromClusterListL(TEntryPos& aPos,TInt aLength,const TAny* aTrg,const RMessagePtr2& aMessage,TInt anOffset, TUint aFlag) const +void CFatMountCB::ReadFromClusterListL(TEntryPos& aPos,TInt aLength,const TAny* aTrg,const RMessagePtr2& aMessage,TInt anOffset) const // // Read from cluster list // @@ -1837,7 +1837,7 @@ TInt offset=0; FOREVER { - DoReadFromClusterListL(aPos,aLength-offset,aTrg,aMessage,anOffset+offset, aFlag); + DoReadFromClusterListL(aPos,aLength-offset,aTrg,aMessage,anOffset+offset); offset=aPos.iPos-startPos; if ((offset uidBuf; - iRawDisk->ReadCachedL(FAT().DataPositionInBytesL(aCluster),sizeof(TCheckedUid),uidBuf); + iRawDisk->ReadCachedL(FAT().DataPositionInBytes(aCluster),sizeof(TCheckedUid),uidBuf); __ASSERT_DEBUG(uidBuf.Length()==sizeof(TCheckedUid),Fault(EFatReadUidFailed)); TCheckedUid uid(uidBuf); anEntry.iType=uid.UidType(); @@ -3230,8 +3230,8 @@ // Read the remaining length or the entire cluster block whichever is smaller TInt readLength = Min(aLength-readTotal,(clusterListLen<0,Fault(EReadFileSectionFailed)); - TInt64 dataAddress=(FAT().DataPositionInBytesL(cluster))+pos; - iRawDisk->ReadL(dataAddress,readLength,aTrg,aMessage,readTotal, 0); + TInt64 dataAddress=(FAT().DataPositionInBytes(cluster))+pos; + iRawDisk->ReadL(dataAddress,readLength,aTrg,aMessage,readTotal); readTotal += readLength; if (readTotal == aLength) @@ -3259,7 +3259,7 @@ // Read aLength of data from disk directly to thread relative descriptor // { - iRawDisk->ReadL(aPos,aLength,aTrg,aMessage,anOffset, 0); + iRawDisk->ReadL(aPos,aLength,aTrg,aMessage,anOffset); } //----------------------------------------------------------------------------------------- @@ -3274,7 +3274,7 @@ //-- check if we are trying to write to the FAT directly and wait until FAT scan thread finishes in this case. FAT().RequestRawWriteAccess(aPos, aLength); - iRawDisk->WriteL(aPos,aLength,aSrc,aMessage,anOffset, 0); + iRawDisk->WriteL(aPos,aLength,aSrc,aMessage,anOffset); //-- Note: FAT directory cache will be invalidated in MountL() } @@ -3434,7 +3434,7 @@ if (!IsRootDir(aPos)) { TInt relPos=ClusterRelativePos(aPos.iPos); - return FAT().DataPositionInBytesL(aPos.iCluster)+relPos; + return FAT().DataPositionInBytes(aPos.iCluster)+relPos; } if (aPos.iPos+StartOfRootDirInBytes()>=RootDirEnd()) User::Leave(KErrDirFull); // Past last root dir entry @@ -4070,7 +4070,7 @@ User::LeaveIfError(r); if ( caps().iType&EMediaRam ) { - realPosition = FAT().DataPositionInBytesL( aPos.iCluster ); + realPosition = FAT().DataPositionInBytes( aPos.iCluster ); aPos.iCluster = I64LOW((realPosition - aInfo.iStartBlockAddress)>>ClusterSizeLog2()); blockMapEntry.SetStartBlock( aPos.iCluster ); }