1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/store/USTRM/US_FRAME.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,560 @@
1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include "US_STD.H"
1.20 +
1.21 +TInt RFrame16Buf::Offset(TStreamPos aBase,TStreamPos aPos)
1.22 + {
1.23 + TInt off=aPos-aBase;
1.24 + __ASSERT_DEBUG(off>=0,Panic(EStreamPosInvalid));
1.25 + TInt n=off/(KFrameFullLength16+KSizeFrameDes16);
1.26 + // number of full frames from base
1.27 + off-=n<<KShiftFrameDes16;
1.28 + // target offset in frame coordinates
1.29 + TInt over=off-(n<<KShiftFrameLength16)-KFrameFullLength16;
1.30 + // adjust for overshoot into the frame descriptor
1.31 + __ASSERT_DEBUG(over>=-KFrameFullLength16&&over<TInt(KSizeFrameDes16),User::Invariant());
1.32 + if (over>0)
1.33 + off-=over;
1.34 + return off;
1.35 + }
1.36 +
1.37 +TStreamPos RFrame16Buf::Position(TStreamPos aBase,TInt anOffset)
1.38 + {
1.39 + return aBase+(anOffset+(anOffset>>KShiftFrameLength16<<KShiftFrameDes16));
1.40 + }
1.41 +
1.42 +RFrame16Buf::RFrame16Buf(TStreamPos aBase)
1.43 + : iBase(aBase),iHost(NULL),iExt(KFrameNonexistent16)
1.44 + {
1.45 + __ASSERT_DEBUG(aBase>=KStreamBeginning+KSizeFrameDes16,Panic(EStreamPosInvalid));
1.46 + }
1.47 +
1.48 +TInt RFrame16Buf::ExtendL(TStreamExchange& aHost,TInt anExtent,TInt aMode)
1.49 + {
1.50 + __ASSERT_DEBUG(anExtent>=0,Panic(EStreamExtentNegative));
1.51 + __ASSERT_DEBUG((KMaskFrameType16&aMode)!=EFrameContinuation16,Panic(EStreamTypeInvalid));
1.52 + TFrameDes16 des[2]={0,TFrameDes16(KMaskFrameType16&aMode|KFrameOpen16)};
1.53 + TUint8* ptr=(TUint8*)&des[1];
1.54 + TInt len=KSizeFrameDes16;
1.55 + TStreamPos pos=Position(anExtent);
1.56 + TInt off=anExtent;
1.57 + anExtent&=KMaskFrameLength16;
1.58 + if (anExtent==0)
1.59 + pos-=KSizeFrameDes16;
1.60 + else
1.61 + {
1.62 + anExtent=KFrameFullLength16-anExtent;
1.63 + if (anExtent>KSizeFrameDes16)
1.64 + off+=KSizeFrameDes16;
1.65 + else
1.66 + {
1.67 + ptr-=anExtent;
1.68 + len+=anExtent;
1.69 + off+=anExtent;
1.70 + }
1.71 + }
1.72 +//
1.73 + TStreamMark mark(pos);
1.74 + mark.WriteL(aHost,ptr,len); // platform dependency
1.75 + mark.Withdraw(aHost);
1.76 + Set(aHost,off,0,aMode);
1.77 + return off;
1.78 + }
1.79 +
1.80 +void RFrame16Buf::OpenL(TStreamExchange& aHost,TInt anOffset,TInt aMode)
1.81 + {
1.82 + __ASSERT_DEBUG(anOffset>=0,Panic(EStreamOffsetNegative));
1.83 + __ASSERT_DEBUG((KMaskFrameType16&aMode)!=EFrameContinuation16,Panic(EStreamTypeInvalid));
1.84 + TStreamMark mark(Position(anOffset)-KSizeFrameDes16);
1.85 + TFrameDes16 des;
1.86 + TInt frame=mark.ReadL(aHost,&des,KSizeFrameDes16);
1.87 + // platform dependency
1.88 + mark.Withdraw(aHost);
1.89 + __ASSERT_DEBUG(frame>=0&&frame<=KSizeFrameDes16,Panic(EStreamReadInBreach));
1.90 + if (frame<KSizeFrameDes16)
1.91 + __LEAVE(KErrEof);
1.92 +//
1.93 + frame=des;
1.94 + if ((frame^aMode)&KMaskFrameType16)
1.95 + __LEAVE(KErrCorrupt);
1.96 +//
1.97 + TInt in=anOffset&KMaskFrameLength16;
1.98 + frame&=KMaskFrameLength16;
1.99 + if (frame==KFrameOpen16)
1.100 + frame=KFrameFullLength16-in;
1.101 + if (in+frame>KFrameFullLength16)
1.102 + __LEAVE(KErrCorrupt);
1.103 +//
1.104 + Set(aHost,anOffset,anOffset+frame,aMode);
1.105 + }
1.106 +
1.107 +void RFrame16Buf::Set(TStreamExchange& aHost,TInt anOffset,TInt anExtent,TInt aMode)
1.108 + {
1.109 + __ASSERT_DEBUG(anOffset>=0||anOffset==anExtent,Panic(EStreamOffsetNegative));
1.110 + __ASSERT_DEBUG(anExtent>=0||anOffset==anExtent,Panic(EStreamExtentNegative));
1.111 + iHost=&aHost;
1.112 + iOff=anOffset;
1.113 + iExt=anExtent;
1.114 + TInt lim;
1.115 + if (anOffset<0)
1.116 + lim=anExtent;
1.117 + else
1.118 + {
1.119 + TStreamPos start=Position(anOffset);
1.120 + if (aMode&ERead)
1.121 + iRMark=start;
1.122 + else
1.123 + iRMark.Clear();
1.124 + if (aMode&EWrite)
1.125 + iWMark=start;
1.126 + else
1.127 + iWMark.Clear();
1.128 + lim=(anOffset&~KMaskFrameLength16)+KFrameFullLength16;
1.129 + if (anExtent>0&&lim>anExtent)
1.130 + lim=anExtent;
1.131 + }
1.132 + iRAvail=iWAvail=lim-anOffset;
1.133 + iRLim=iWLim=lim;
1.134 + iMode=aMode;
1.135 + }
1.136 +
1.137 +void RFrame16Buf::CommitL()
1.138 + {
1.139 + __ASSERT_DEBUG(!IsCommitted(),Panic(EStreamCommitted));
1.140 + TInt ext=Host().SizeL()-Base().Offset();
1.141 + if (ext<0)
1.142 + __LEAVE(KErrCorrupt);
1.143 +//
1.144 + TInt n=ext/(KFrameFullLength16+KSizeFrameDes16);
1.145 + // number of full frames from base
1.146 + ext-=n<<KShiftFrameDes16;
1.147 + // end in frame coordinates
1.148 + TInt off=Offset();
1.149 + if (ext==off)
1.150 + { // committing an empty stream
1.151 + iOff=iExt=KFrameNonexistent16;
1.152 + return;
1.153 + }
1.154 +//
1.155 + TInt frame=ext-(n<<KShiftFrameLength16);
1.156 + // size of final frame (remainder of the division above)
1.157 + __ASSERT_DEBUG(frame>=0&&frame<KFrameFullLength16+KSizeFrameDes16,User::Invariant());
1.158 + if (ext<off||frame==0||frame>KFrameFullLength16)
1.159 + __LEAVE(KErrCorrupt); // bad offset, empty frame or partial frame descriptor
1.160 +//
1.161 + if (frame<KFrameFullLength16)
1.162 + {
1.163 + TFrameDes16 des;
1.164 + if ((off^ext)&~KMaskFrameLength16)
1.165 + { // in a different frame from the one we started in
1.166 + off=ext&~KMaskFrameLength16;
1.167 + des=TFrameDes16(EFrameContinuation16|frame);
1.168 + }
1.169 + else
1.170 + {
1.171 + frame-=off&KMaskFrameLength16;
1.172 + __ASSERT_DEBUG(frame>0&&frame<KFrameFullLength16,User::Invariant());
1.173 + des=TFrameDes16(iMode&KMaskFrameType16|frame);
1.174 + }
1.175 + TStreamMark mark(Position(off)-KSizeFrameDes16);
1.176 + mark.WriteL(Host(),&des,KSizeFrameDes16);
1.177 + mark.Withdraw(Host());
1.178 + }
1.179 + iExt=ext;
1.180 + }
1.181 +
1.182 +void RFrame16Buf::DoRelease()
1.183 + {
1.184 + if (iHost!=NULL)
1.185 + {
1.186 + iRMark.Withdraw(*iHost);
1.187 + iWMark.Withdraw(*iHost);
1.188 + iHost=NULL;
1.189 + iExt=KFrameNonexistent16;
1.190 + }
1.191 + }
1.192 +
1.193 +void RFrame16Buf::DoSynchL()
1.194 + {
1.195 + if (IsCommitted())
1.196 + return;
1.197 +//
1.198 + CommitL();
1.199 + }
1.200 +
1.201 +TInt RFrame16Buf::DoReadL(TAny* aPtr,TInt aMaxLength)
1.202 + {
1.203 + __ASSERT_DEBUG(aMaxLength>=0,Panic(EStreamReadLengthNegative));
1.204 + __ASSERT_DEBUG(aMaxLength>0,Panic(EStreamReadNoTransfer));
1.205 + TInt left=aMaxLength;
1.206 + TInt avail=iRAvail;
1.207 + if (avail==0)
1.208 + goto underflow; // we'd used up the whole frame
1.209 +//
1.210 + do
1.211 + {
1.212 + __ASSERT_DEBUG(left>0&&avail>0,User::Invariant());
1.213 + {
1.214 + TInt len=iRMark.ReadL(Host(),aPtr,Min(left,avail));
1.215 + __ASSERT_DEBUG(len>=0&&len<=left&&len<=avail,Panic(EStreamReadInBreach));
1.216 + iRAvail=avail-=len;
1.217 + left-=len;
1.218 + if (left==0)
1.219 + return aMaxLength; // that's it
1.220 +//
1.221 + aPtr=(TUint8*)aPtr+len;
1.222 + }
1.223 + if (avail>0)
1.224 + { // we've run out of host
1.225 + if ((Extent()&KMaskFrameLength16)==KFrameOpen16)
1.226 + break; // all's well, provided we're open-ended
1.227 +//
1.228 + iRMark.Withdraw(Host());
1.229 + __LEAVE(KErrCorrupt);
1.230 + }
1.231 +//
1.232 + underflow:
1.233 + avail=UnderflowL();
1.234 + } while (avail>0);
1.235 + return aMaxLength-left;
1.236 + }
1.237 +
1.238 +TInt RFrame16Buf::DoReadL(TDes8& aDes,TInt aMaxLength,TRequestStatus& aStatus)
1.239 +//
1.240 +// Read up to aMaxLength bytes asynchronously.
1.241 +//
1.242 + {
1.243 +//#pragma message( __FILE__ " : 'RFrame16Buf::DoReadL(TDes8&,TInt,TRequestStatus&)' not implemented" )
1.244 + __ASSERT_DEBUG(aMaxLength<=aDes.MaxLength(),Panic(EStreamReadBeyondEnd));
1.245 + aDes.SetLength(DoReadL((TUint8*)aDes.Ptr(),aMaxLength));
1.246 + TRequestStatus* stat=&aStatus;
1.247 + User::RequestComplete(stat,KErrNone);
1.248 + return aMaxLength;
1.249 + }
1.250 +
1.251 +TStreamTransfer RFrame16Buf::DoReadL(MStreamInput& anInput,TStreamTransfer aTransfer)
1.252 + {
1.253 + __ASSERT_DEBUG(aTransfer>0,Panic(EStreamReadNoTransfer));
1.254 + if (iRAvail>0)
1.255 + {
1.256 + TInt len=iRMark.ReadL(Host(),anInput,aTransfer[iRAvail]);
1.257 + aTransfer-=len;
1.258 + iRAvail-=len;
1.259 + }
1.260 + if (aTransfer>0)
1.261 + return anInput.ReadFromL(*this,aTransfer);
1.262 +//
1.263 + return aTransfer;
1.264 + }
1.265 +
1.266 +void RFrame16Buf::DoWriteL(const TAny* aPtr,TInt aLength)
1.267 + {
1.268 + __ASSERT_DEBUG(aLength>=0,Panic(EStreamWriteLengthNegative));
1.269 + __ASSERT_DEBUG(aLength>0,Panic(EStreamWriteNoTransfer));
1.270 + TInt avail=iWAvail;
1.271 + if (avail==0)
1.272 + goto overflow; // we'd used up the whole frame
1.273 +//
1.274 + for (;;)
1.275 + {
1.276 + __ASSERT_DEBUG(aLength>0&&avail>0,User::Invariant());
1.277 + {
1.278 + TInt len=Min(aLength,avail);
1.279 + iWMark.WriteL(Host(),aPtr,len);
1.280 + iWAvail=avail-len;
1.281 + aLength-=len;
1.282 + if (aLength==0)
1.283 + return; // won't worry about the next frame just yet
1.284 +//
1.285 + aPtr=(TUint8*)aPtr+len;
1.286 + }
1.287 + overflow:
1.288 + OverflowL();
1.289 + avail=iWAvail;
1.290 + };
1.291 + }
1.292 +
1.293 +TInt RFrame16Buf::DoWriteL(const TDesC8& aDes,TInt aMaxLength,TRequestStatus& aStatus)
1.294 +//
1.295 +// Write up to aMaxLength bytes asynchronously.
1.296 +//
1.297 + {
1.298 +//#pragma message( __FILE__ " : 'RFrame16Buf::DoWriteL(const TDesC8&,TInt,TRequestStatus&)' not implemented" )
1.299 + __ASSERT_DEBUG(aMaxLength<=aDes.Length(),Panic(EStreamWriteBeyondEnd));
1.300 + DoWriteL(aDes.Ptr(),aMaxLength);
1.301 + TRequestStatus* stat=&aStatus;
1.302 + User::RequestComplete(stat,KErrNone);
1.303 + return aMaxLength;
1.304 + }
1.305 +
1.306 +TStreamTransfer RFrame16Buf::DoWriteL(MStreamOutput& anOutput,TStreamTransfer aTransfer)
1.307 + {
1.308 + __ASSERT_DEBUG(aTransfer>0,Panic(EStreamWriteNoTransfer));
1.309 + if (iWAvail>0)
1.310 + {
1.311 + TInt len=iWMark.WriteL(Host(),anOutput,aTransfer[iWAvail]);
1.312 + aTransfer-=len;
1.313 + iWAvail-=len;
1.314 + }
1.315 + if (aTransfer>0)
1.316 + return anOutput.WriteToL(*this,aTransfer);
1.317 +//
1.318 + return aTransfer;
1.319 + }
1.320 +
1.321 +TStreamPos RFrame16Buf::DoSeekL(TMark aMark,TStreamLocation aLocation,TInt anOffset)
1.322 +//
1.323 +// Position the mark(s) indicated by aMark at anOffset from aLocation.
1.324 +//
1.325 + {
1.326 + switch (aLocation)
1.327 + {
1.328 + case EStreamBeginning:
1.329 + anOffset+=Offset();
1.330 + break;
1.331 + case EStreamMark:
1.332 + if (aMark==ERead)
1.333 + anOffset+=iRLim-iRAvail;
1.334 + else
1.335 + {
1.336 + __ASSERT_ALWAYS(aMark==EWrite,Panic(EStreamMarkInvalid));
1.337 + anOffset+=iWLim-iWAvail;
1.338 + }
1.339 + break;
1.340 + case EStreamEnd:
1.341 + anOffset+=EndL();
1.342 + break;
1.343 + default:
1.344 + Panic(EStreamLocationInvalid);
1.345 + break;
1.346 + }
1.347 + TInt r=KErrNone;
1.348 + if (anOffset<Offset())
1.349 + {
1.350 + anOffset=Offset();
1.351 + r=KErrEof;
1.352 + }
1.353 + else if (anOffset>=0&&!ReachL(anOffset))
1.354 + {
1.355 + __ASSERT_DEBUG(Extent()!=0,User::Invariant());
1.356 + anOffset=Extent();
1.357 + r=KErrEof;
1.358 + }
1.359 +//
1.360 + if (aMark&&anOffset>=0)
1.361 + {
1.362 + __ASSERT_ALWAYS(!(aMark&~(ERead|EWrite)),Panic(EStreamMarkInvalid));
1.363 + TInt in=anOffset&KMaskFrameLength16;
1.364 + TInt off=anOffset-in;
1.365 + __ASSERT_DEBUG(Extent()==0||anOffset<=Extent(),User::Invariant());
1.366 + if (in==0&&off>Offset()&&(Extent()==0||off==Extent()))
1.367 + { // positioning at the start of a frame that may not exist
1.368 + in=KFrameFullLength16;
1.369 + off-=in;
1.370 + }
1.371 + TStreamPos pos=Base()+(off+(off>>KShiftFrameLength16<<KShiftFrameDes16))+in;
1.372 + TInt lim=off+KFrameFullLength16;
1.373 + if (Extent()>0&&lim>Extent())
1.374 + lim=Extent();
1.375 + TInt left=lim-anOffset;
1.376 + __ASSERT_DEBUG(left>=0&&left<=KFrameFullLength16,User::Invariant());
1.377 +//
1.378 + if (aMark&ERead)
1.379 + {
1.380 + if (iMode&ERead)
1.381 + iRMark.SeekL(Host(),pos);
1.382 + iRAvail=left;
1.383 + iRLim=lim;
1.384 + }
1.385 + if (aMark&EWrite)
1.386 + {
1.387 + if (iMode&EWrite)
1.388 + iWMark.SeekL(Host(),pos);
1.389 + iWAvail=left;
1.390 + iWLim=lim;
1.391 + }
1.392 + }
1.393 + __LEAVE_IF_ERROR(r);
1.394 + return TStreamPos(anOffset-Offset());
1.395 + }
1.396 +
1.397 +TInt RFrame16Buf::UnderflowL()
1.398 + {
1.399 + __ASSERT_DEBUG(iRAvail==0,User::Invariant());
1.400 + if ((iRLim&KMaskFrameLength16)!=KFrameOpen16)
1.401 + {
1.402 + __ASSERT_DEBUG(iExt==iRLim,User::Invariant());
1.403 + return 0; // we've used up the closing, partial frame
1.404 + }
1.405 +//
1.406 + __ASSERT_DEBUG(iRLim>0&&(iExt>0&&iRLim<=iExt||iExt==0),User::Invariant());
1.407 + // let's see if there's a continuation frame
1.408 + TFrameDes16 des;
1.409 + TInt frame=iRMark.ReadL(Host(),&des,KSizeFrameDes16);
1.410 + // platform dependency
1.411 + __ASSERT_DEBUG(frame>=0&&frame<=KSizeFrameDes16,Panic(EStreamReadInBreach));
1.412 + if (frame==KSizeFrameDes16)
1.413 + {
1.414 + frame=des;
1.415 + if ((frame&KMaskFrameType16)==EFrameContinuation16)
1.416 + { // we have a continuation frame, prepare ourselves for it
1.417 + frame&=KMaskFrameLength16;
1.418 + if (frame==KFrameOpen16)
1.419 + frame=KFrameFullLength16;
1.420 + iRAvail=frame;
1.421 + TInt lim=iRLim;
1.422 + iRLim=lim+frame;
1.423 + if (iExt==lim)
1.424 + iExt=iRLim;
1.425 + return frame;
1.426 + }
1.427 + iRMark.SeekL(Host(),-KSizeFrameDes16);
1.428 + frame=0;
1.429 + }
1.430 +//
1.431 + if (frame>0||iRLim<iExt)
1.432 + { // we'd definitely seen a continuation frame here before
1.433 + iRMark.Withdraw(Host());
1.434 + __LEAVE(KErrCorrupt);
1.435 + }
1.436 + return 0;
1.437 + }
1.438 +
1.439 +void RFrame16Buf::OverflowL()
1.440 + {
1.441 + __ASSERT_DEBUG(iWAvail==0,User::Invariant());
1.442 + if ((iWLim&KMaskFrameLength16)!=KFrameOpen16)
1.443 + { // filled the closing, partial frame
1.444 + __ASSERT_DEBUG(iExt==iWLim,User::Invariant());
1.445 + overflow:
1.446 + iWMark.Withdraw(Host());
1.447 + __LEAVE(KErrOverflow);
1.448 + }
1.449 +//
1.450 + __ASSERT_DEBUG(iWLim>0&&(iExt>0&&iWLim<=iExt||iExt==0),User::Invariant());
1.451 + if (iWLim==iExt)
1.452 + { // let's see if this carries on
1.453 + TFrameDes16 des;
1.454 + TInt frame=iWMark.ReadL(Host(),&des,KSizeFrameDes16);
1.455 + // platform dependency
1.456 + __ASSERT_DEBUG(frame>=0&&frame<=KSizeFrameDes16,Panic(EStreamReadInBreach));
1.457 + if (frame==0)
1.458 + iExt=0; // end-of-host, let's start extending
1.459 + else
1.460 + {
1.461 + if (frame==KSizeFrameDes16)
1.462 + {
1.463 + frame=des;
1.464 + if ((frame&KMaskFrameType16)==EFrameContinuation16)
1.465 + { // there's more, set up for the next frame
1.466 + frame&=KMaskFrameLength16;
1.467 + if (frame==KFrameOpen16)
1.468 + frame=KFrameFullLength16;
1.469 + iWAvail=frame;
1.470 + iExt=iWLim+=frame;
1.471 + return;
1.472 + }
1.473 + goto overflow;
1.474 + }
1.475 +//
1.476 + iWMark.Withdraw(Host());
1.477 + __LEAVE(KErrCorrupt);
1.478 + }
1.479 + }
1.480 +//
1.481 + __ASSERT_DEBUG(iWLim<iExt||iExt==0,User::Invariant());
1.482 + // calculate the frame descriptor to be written
1.483 + TInt frame=iExt&KMaskFrameLength16;
1.484 + if (iWLim<iExt-frame)
1.485 + frame=KFrameOpen16;
1.486 + TFrameDes16 des=TFrameDes16(EFrameContinuation16|frame);
1.487 + if (frame==KFrameOpen16)
1.488 + frame=KFrameFullLength16;
1.489 + iWMark.WriteL(Host(),&des,KSizeFrameDes16);
1.490 + // platform dependency
1.491 + iWAvail=frame;
1.492 + iWLim+=frame;
1.493 + }
1.494 +
1.495 +TBool RFrame16Buf::ReachL(TInt anOffset)
1.496 + {
1.497 + if (iExt<=0)
1.498 + return iExt==0;
1.499 +//
1.500 + TStreamMark mark(Base());
1.501 + TInt frame=(iExt+(iExt>>KShiftFrameLength16<<KShiftFrameDes16))-KSizeFrameDes16;
1.502 + while (iExt<anOffset)
1.503 + {
1.504 + if ((iExt&KMaskFrameLength16)!=KFrameOpen16)
1.505 + {
1.506 + mark.Withdraw(Host());
1.507 + return EFalse;
1.508 + }
1.509 +//
1.510 + TFrameDes16 des;
1.511 + mark.SeekL(Host(),EStreamMark,frame);
1.512 + frame=mark.ReadL(Host(),&des,KSizeFrameDes16);
1.513 + // platform dependency
1.514 + __ASSERT_DEBUG(frame>=0&&frame<=KSizeFrameDes16,Panic(EStreamReadInBreach));
1.515 + if (frame==KSizeFrameDes16)
1.516 + {
1.517 + frame=des;
1.518 + if ((frame&KMaskFrameType16)==EFrameContinuation16)
1.519 + { // we have a continuation frame, boost upper
1.520 + frame&=KMaskFrameLength16;
1.521 + if (frame==KFrameOpen16)
1.522 + frame=KFrameFullLength16;
1.523 + iExt+=frame;
1.524 + continue;
1.525 + }
1.526 + frame=0;
1.527 + }
1.528 +//
1.529 + mark.Withdraw(Host());
1.530 + if (frame>0)
1.531 + __LEAVE(KErrCorrupt);
1.532 +//
1.533 + return EFalse;
1.534 + }
1.535 + mark.Withdraw(Host());
1.536 + return ETrue;
1.537 + }
1.538 +
1.539 +TInt RFrame16Buf::EndL()
1.540 + {
1.541 + TInt ext=Host().SizeL()-Base().Offset();
1.542 + if (ext<0)
1.543 + __LEAVE(KErrCorrupt);
1.544 +//
1.545 + TInt n=ext/(KFrameFullLength16+KSizeFrameDes16);
1.546 + // number of full frames from base
1.547 + ext-=n<<KShiftFrameDes16;
1.548 + // end in frame coordinates
1.549 + TInt frame=ext-(n<<KShiftFrameLength16);
1.550 + // size of final frame (remainder of the division above)
1.551 + __ASSERT_DEBUG(frame>=0&&frame<KFrameFullLength16+KSizeFrameDes16,User::Invariant());
1.552 + if (ext<Offset()||frame>KFrameFullLength16)
1.553 + __LEAVE(KErrCorrupt); // bad offset or partial frame descriptor
1.554 +//
1.555 + if (!ReachL(ext))
1.556 + {
1.557 + __ASSERT_DEBUG(Extent()!=0,User::Invariant());
1.558 + return Extent();
1.559 + }
1.560 +//
1.561 + return ext;
1.562 + }
1.563 +