kerneltest/e32test/mediaext/d_nfe.cpp
branchRCL_3
changeset 257 3e88ff8f41d5
parent 256 c1f20ce4abcf
--- a/kerneltest/e32test/mediaext/d_nfe.cpp	Tue Aug 31 16:34:26 2010 +0300
+++ b/kerneltest/e32test/mediaext/d_nfe.cpp	Wed Sep 01 12:34:56 2010 +0100
@@ -22,6 +22,7 @@
 
 #if defined(_DEBUG)
 //	#define TRACE_ENABLED
+#define TRACE_ENABLED	//*test*
 #else
 #endif
 
@@ -1051,9 +1052,6 @@
 
 //	__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++;
 
@@ -1215,30 +1213,40 @@
 
 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, aReq.Length(), di->Status()));
+//	__KTRACE_PRINT(Kern::Printf("NFE%d: HandleFormat pos %lx len %lx status %d", iInstance, currentPos, remainingLength, di->Status()));
+
 
-	if (di->Status() == ENfeEncrypting)
+	// 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)
 		{
-		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())));
+		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;
 		}
 
-	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 ));
-		}
-
-
-	return ForwardRequest(aReq);
+	return r == KErrNone ? KErrCompletion : r;
 	}
 
 
@@ -1355,13 +1363,9 @@
 TBool DMediaDriverNFE::ValidBootSector(TUint8* aBuffer)
 	{
 	if (aBuffer[0] == 0xEB || aBuffer[0] == 0xE9)
-		{
 		return ETrue;
-		}
 	else
-		{
 		return EFalse;
-		}
 	}
 
 
@@ -1406,7 +1410,7 @@
 
 	// Find out whether the volume has changed
 	TUint32 uniqueID = VolumeId(iBuffer);   
-	TBool volumeChanged = (aDi.iUniqueID != 0) && (uniqueID != aDi.iUniqueID);
+	TBool volumeChanged = 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));
@@ -1534,6 +1538,9 @@
 		return KErrNone;
 		}
 
+//	TInt KBackgroundPriority = 7;						//*test*
+//	Kern::SetThreadPriority(KBackgroundPriority);		//*test*
+
 	TInt r = KErrNone;
 	for (;;)
 		{
@@ -1620,6 +1627,8 @@
 	if (r != KErrCompletion)
 		iIdleTimer.OneShot(NKern::TimerTicks(KNotBusyInterval));
 
+//	Kern::SetThreadPriority(KNfeThreadPriority);	//*test*
+	
 	return r;
 	}