kerneltest/e32test/mediaext/d_nfe.cpp
changeset 259 57b9594f5772
parent 152 657f875b013e
equal deleted inserted replaced
247:d8d70de2bd36 259:57b9594f5772
  1048 	TInt64 remainingLength = aReq.Length();
  1048 	TInt64 remainingLength = aReq.Length();
  1049 	TInt desPos = 0;
  1049 	TInt desPos = 0;
  1050 	TNfeDriveInfo* di = &iInfo.iDrives[DriveIndex(aReq.Drive()->iDriveNumber)];
  1050 	TNfeDriveInfo* di = &iInfo.iDrives[DriveIndex(aReq.Drive()->iDriveNumber)];
  1051 
  1051 
  1052 //	__KTRACE_PRINT(Kern::Printf("NFE%d: HandleRead pos %lx len %lx status %d", iInstance, currentPos, remainingLength, di->Status()));
  1052 //	__KTRACE_PRINT(Kern::Printf("NFE%d: HandleRead pos %lx len %lx status %d", iInstance, currentPos, remainingLength, di->Status()));
       
  1053 
       
  1054 	if (di->iEntry.iPartitionLen == 0)
       
  1055 		return KErrNotReady;
  1053 
  1056 
  1054 
  1057 
  1055 	di->iReadRequestCount++;
  1058 	di->iReadRequestCount++;
  1056 
  1059 
  1057 	if (aReq.Flags() & TLocDrvRequest::ECodePaging)
  1060 	if (aReq.Flags() & TLocDrvRequest::ECodePaging)
  1210 	return r == KErrNone ? KErrCompletion : r;
  1213 	return r == KErrNone ? KErrCompletion : r;
  1211 	}
  1214 	}
  1212 
  1215 
  1213 TInt DMediaDriverNFE::HandleFormat(TLocDrvRequest& aReq)
  1216 TInt DMediaDriverNFE::HandleFormat(TLocDrvRequest& aReq)
  1214 	{
  1217 	{
  1215 	TInt r = KErrNone;
       
  1216 	TInt64 currentPos =  aReq.Pos();
  1218 	TInt64 currentPos =  aReq.Pos();
  1217 	TInt64 remainingLength = aReq.Length();
       
  1218 	TNfeDriveInfo* di = &iInfo.iDrives[DriveIndex(aReq.Drive()->iDriveNumber)];
  1219 	TNfeDriveInfo* di = &iInfo.iDrives[DriveIndex(aReq.Drive()->iDriveNumber)];
  1219 
  1220 
  1220 //	__KTRACE_PRINT(Kern::Printf("NFE%d: HandleFormat pos %lx len %lx status %d", iInstance, currentPos, remainingLength, di->Status()));
  1221 	__KTRACE_PRINT(Kern::Printf("NFE%d: HandleFormat pos %lx len %lx status %d", iInstance, currentPos, aReq.Length(), di->Status()));
  1221 
  1222 
  1222 
  1223 	if (di->Status() == ENfeEncrypting)
  1223 	// just forward the request if the drive is not encrypted
  1224 		{
  1224 	if (di->Status() == ENfeDecrypted)
  1225 		di->iEncryptEndPos = di->iEntry.iPartitionBaseAddr + di->iEntry.iPartitionLen;
  1225 		return ForwardRequest(aReq);
  1226 		SetStatus(*di,  ENfeEncrypted);
  1226 
  1227 		__KTRACE_PRINT(Kern::Printf("NFE%d: HandleFormat() , Setting status to %s", iInstance, DriveStatus(di->Status())));
  1227 	// otherwise create a buffer containing NULLs, encrypt it and write that to the attached drive
  1228 		}
  1228 	while(remainingLength && r == KErrNone)
  1229 
  1229 		{
  1230 	if (currentPos >= di->iEntry.iPartitionBaseAddr && 
  1230 		TInt64 currentLength = (remainingLength <= KBufSize ? remainingLength : KBufSize);
  1231 		currentPos < di->iEntry.iPartitionBaseAddr + KSectorSize && 
  1231 
  1232 		di->IsUDADrive() &&
  1232 		TBool encryptBuffer = AdjustRequest(di, currentPos, currentLength);
  1233 		di->Status() == ENfeEncrypted)
  1233 
  1234 		{
  1234 		memclr(iBuffer, KBufSize);
  1235 		__KTRACE_PRINT(Kern::Printf("NFE%d: Write to sector #0 detected", iInstance));
  1235 		TPtr8 des(iBuffer,KBufSize,KBufSize);
  1236 		di->iUniqueID = 0;	// undefined
  1236 
  1237 		__KTRACE_PRINT(Kern::Printf("NFE%d: Setting Volume ID to %08X", iInstance, di->iUniqueID ));
  1237 		if (encryptBuffer)
  1238 		}
  1238 			EncryptBuffer(des);
  1239 
  1239 		
  1240 
  1240 		r = Write(di->iLocalDriveNum, currentPos, (TLinAddr) iBuffer, I64LOW(currentLength));
  1241 	return ForwardRequest(aReq);
  1241 		if(r != KErrNone)
       
  1242 			break;
       
  1243 
       
  1244 		remainingLength-= currentLength;
       
  1245 		currentPos+= currentLength;
       
  1246 		}
       
  1247 
       
  1248 	return r == KErrNone ? KErrCompletion : r;
       
  1249 	}
  1242 	}
  1250 
  1243 
  1251 
  1244 
  1252 void DMediaDriverNFE::EncryptBuffer(TDes8& aBuffer)
  1245 void DMediaDriverNFE::EncryptBuffer(TDes8& aBuffer)
  1253 	{
  1246 	{
  1360 
  1353 
  1361 
  1354 
  1362 TBool DMediaDriverNFE::ValidBootSector(TUint8* aBuffer)
  1355 TBool DMediaDriverNFE::ValidBootSector(TUint8* aBuffer)
  1363 	{
  1356 	{
  1364 	if (aBuffer[0] == 0xEB || aBuffer[0] == 0xE9)
  1357 	if (aBuffer[0] == 0xEB || aBuffer[0] == 0xE9)
       
  1358 		{
  1365 		return ETrue;
  1359 		return ETrue;
       
  1360 		}
  1366 	else
  1361 	else
       
  1362 		{
  1367 		return EFalse;
  1363 		return EFalse;
       
  1364 		}
  1368 	}
  1365 	}
  1369 
  1366 
  1370 
  1367 
  1371 TUint32 DMediaDriverNFE::VolumeId(TUint8* aBuffer)
  1368 TUint32 DMediaDriverNFE::VolumeId(TUint8* aBuffer)
  1372 	{
  1369 	{
  1407 
  1404 
  1408 	__KTRACE_PRINT(Kern::Printf("NFE%d: fatBootSectorStatus %d", iInstance, fatBootSectorStatus));
  1405 	__KTRACE_PRINT(Kern::Printf("NFE%d: fatBootSectorStatus %d", iInstance, fatBootSectorStatus));
  1409 
  1406 
  1410 	// Find out whether the volume has changed
  1407 	// Find out whether the volume has changed
  1411 	TUint32 uniqueID = VolumeId(iBuffer);   
  1408 	TUint32 uniqueID = VolumeId(iBuffer);   
  1412 	TBool volumeChanged = uniqueID != aDi.iUniqueID;
  1409 	TBool volumeChanged = (aDi.iUniqueID != 0) && (uniqueID != aDi.iUniqueID);
  1413 	__KTRACE_PRINT(Kern::Printf("NFE%d: Old Volume ID %08X", iInstance, aDi.iUniqueID));
  1410 	__KTRACE_PRINT(Kern::Printf("NFE%d: Old Volume ID %08X", iInstance, aDi.iUniqueID));
  1414 	__KTRACE_PRINT(Kern::Printf("NFE%d: New Volume ID %08X", iInstance, uniqueID));
  1411 	__KTRACE_PRINT(Kern::Printf("NFE%d: New Volume ID %08X", iInstance, uniqueID));
  1415 	__KTRACE_PRINT(Kern::Printf("NFE%d: volumeChanged %d", iInstance, volumeChanged));
  1412 	__KTRACE_PRINT(Kern::Printf("NFE%d: volumeChanged %d", iInstance, volumeChanged));
  1416 	aDi.iUniqueID = uniqueID;
  1413 	aDi.iUniqueID = uniqueID;
  1417 
  1414 
  1534 	if (di->iDriveFinalised)
  1531 	if (di->iDriveFinalised)
  1535 		{
  1532 		{
  1536 	    __KTRACE_PRINT(Kern::Printf("HandleDiskContent aborting as drive has been finalised", iInstance));
  1533 	    __KTRACE_PRINT(Kern::Printf("HandleDiskContent aborting as drive has been finalised", iInstance));
  1537 		return KErrNone;
  1534 		return KErrNone;
  1538 		}
  1535 		}
  1539 
       
  1540 //	TInt KBackgroundPriority = 7;						//*test*
       
  1541 //	Kern::SetThreadPriority(KBackgroundPriority);		//*test*
       
  1542 
  1536 
  1543 	TInt r = KErrNone;
  1537 	TInt r = KErrNone;
  1544 	for (;;)
  1538 	for (;;)
  1545 		{
  1539 		{
  1546 		// If we've finished encryting this drive, change the state and move on to the next drive
  1540 		// If we've finished encryting this drive, change the state and move on to the next drive
  1624 
  1618 
  1625 	// If not completed, start the idle timer & try again later
  1619 	// If not completed, start the idle timer & try again later
  1626 	if (r != KErrCompletion)
  1620 	if (r != KErrCompletion)
  1627 		iIdleTimer.OneShot(NKern::TimerTicks(KNotBusyInterval));
  1621 		iIdleTimer.OneShot(NKern::TimerTicks(KNotBusyInterval));
  1628 
  1622 
  1629 //	Kern::SetThreadPriority(KNfeThreadPriority);	//*test*
       
  1630 	
       
  1631 	return r;
  1623 	return r;
  1632 	}
  1624 	}
  1633 
  1625 
  1634 
  1626 
  1635 
  1627