diff -r a179b74831c9 -r c1f20ce4abcf kerneltest/e32test/mediaext/d_nfe.cpp --- a/kerneltest/e32test/mediaext/d_nfe.cpp Thu Aug 19 11:14:22 2010 +0300 +++ b/kerneltest/e32test/mediaext/d_nfe.cpp Tue Aug 31 16:34:26 2010 +0300 @@ -22,7 +22,6 @@ #if defined(_DEBUG) // #define TRACE_ENABLED -#define TRACE_ENABLED //*test* #else #endif @@ -1052,6 +1051,9 @@ // __KTRACE_PRINT(Kern::Printf("NFE%d: HandleRead pos %lx len %lx status %d", iInstance, currentPos, remainingLength, di->Status())); + if (di->iEntry.iPartitionLen == 0) + return KErrNotReady; + di->iReadRequestCount++; @@ -1213,40 +1215,30 @@ TInt DMediaDriverNFE::HandleFormat(TLocDrvRequest& aReq) { - TInt r = KErrNone; TInt64 currentPos = aReq.Pos(); - TInt64 remainingLength = aReq.Length(); TNfeDriveInfo* di = &iInfo.iDrives[DriveIndex(aReq.Drive()->iDriveNumber)]; -// __KTRACE_PRINT(Kern::Printf("NFE%d: HandleFormat pos %lx len %lx status %d", iInstance, currentPos, remainingLength, di->Status())); + __KTRACE_PRINT(Kern::Printf("NFE%d: HandleFormat pos %lx len %lx status %d", iInstance, currentPos, aReq.Length(), di->Status())); + + if (di->Status() == ENfeEncrypting) + { + di->iEncryptEndPos = di->iEntry.iPartitionBaseAddr + di->iEntry.iPartitionLen; + SetStatus(*di, ENfeEncrypted); + __KTRACE_PRINT(Kern::Printf("NFE%d: HandleFormat() , Setting status to %s", iInstance, DriveStatus(di->Status()))); + } + + if (currentPos >= di->iEntry.iPartitionBaseAddr && + currentPos < di->iEntry.iPartitionBaseAddr + KSectorSize && + di->IsUDADrive() && + di->Status() == ENfeEncrypted) + { + __KTRACE_PRINT(Kern::Printf("NFE%d: Write to sector #0 detected", iInstance)); + di->iUniqueID = 0; // undefined + __KTRACE_PRINT(Kern::Printf("NFE%d: Setting Volume ID to %08X", iInstance, di->iUniqueID )); + } - // just forward the request if the drive is not encrypted - if (di->Status() == ENfeDecrypted) - return ForwardRequest(aReq); - - // otherwise create a buffer containing NULLs, encrypt it and write that to the attached drive - while(remainingLength && r == KErrNone) - { - TInt64 currentLength = (remainingLength <= KBufSize ? remainingLength : KBufSize); - - TBool encryptBuffer = AdjustRequest(di, currentPos, currentLength); - - memclr(iBuffer, KBufSize); - TPtr8 des(iBuffer,KBufSize,KBufSize); - - if (encryptBuffer) - EncryptBuffer(des); - - r = Write(di->iLocalDriveNum, currentPos, (TLinAddr) iBuffer, I64LOW(currentLength)); - if(r != KErrNone) - break; - - remainingLength-= currentLength; - currentPos+= currentLength; - } - - return r == KErrNone ? KErrCompletion : r; + return ForwardRequest(aReq); } @@ -1363,9 +1355,13 @@ TBool DMediaDriverNFE::ValidBootSector(TUint8* aBuffer) { if (aBuffer[0] == 0xEB || aBuffer[0] == 0xE9) + { return ETrue; + } else + { return EFalse; + } } @@ -1410,7 +1406,7 @@ // Find out whether the volume has changed TUint32 uniqueID = VolumeId(iBuffer); - TBool volumeChanged = uniqueID != aDi.iUniqueID; + TBool volumeChanged = (aDi.iUniqueID != 0) && (uniqueID != aDi.iUniqueID); __KTRACE_PRINT(Kern::Printf("NFE%d: Old Volume ID %08X", iInstance, aDi.iUniqueID)); __KTRACE_PRINT(Kern::Printf("NFE%d: New Volume ID %08X", iInstance, uniqueID)); __KTRACE_PRINT(Kern::Printf("NFE%d: volumeChanged %d", iInstance, volumeChanged)); @@ -1538,9 +1534,6 @@ return KErrNone; } -// TInt KBackgroundPriority = 7; //*test* -// Kern::SetThreadPriority(KBackgroundPriority); //*test* - TInt r = KErrNone; for (;;) { @@ -1627,8 +1620,6 @@ if (r != KErrCompletion) iIdleTimer.OneShot(NKern::TimerTicks(KNotBusyInterval)); -// Kern::SetThreadPriority(KNfeThreadPriority); //*test* - return r; }