1049 TInt64 remainingLength = aReq.Length(); |
1048 TInt64 remainingLength = aReq.Length(); |
1050 TInt desPos = 0; |
1049 TInt desPos = 0; |
1051 TNfeDriveInfo* di = &iInfo.iDrives[DriveIndex(aReq.Drive()->iDriveNumber)]; |
1050 TNfeDriveInfo* di = &iInfo.iDrives[DriveIndex(aReq.Drive()->iDriveNumber)]; |
1052 |
1051 |
1053 // __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; |
1054 |
1056 |
1055 |
1057 |
1056 di->iReadRequestCount++; |
1058 di->iReadRequestCount++; |
1057 |
1059 |
1058 if (aReq.Flags() & TLocDrvRequest::ECodePaging) |
1060 if (aReq.Flags() & TLocDrvRequest::ECodePaging) |
1211 return r == KErrNone ? KErrCompletion : r; |
1213 return r == KErrNone ? KErrCompletion : r; |
1212 } |
1214 } |
1213 |
1215 |
1214 TInt DMediaDriverNFE::HandleFormat(TLocDrvRequest& aReq) |
1216 TInt DMediaDriverNFE::HandleFormat(TLocDrvRequest& aReq) |
1215 { |
1217 { |
1216 TInt r = KErrNone; |
|
1217 TInt64 currentPos = aReq.Pos(); |
1218 TInt64 currentPos = aReq.Pos(); |
1218 TInt64 remainingLength = aReq.Length(); |
|
1219 TNfeDriveInfo* di = &iInfo.iDrives[DriveIndex(aReq.Drive()->iDriveNumber)]; |
1219 TNfeDriveInfo* di = &iInfo.iDrives[DriveIndex(aReq.Drive()->iDriveNumber)]; |
1220 |
1220 |
1221 // __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())); |
1222 |
1222 |
1223 |
1223 if (di->Status() == ENfeEncrypting) |
1224 // just forward the request if the drive is not encrypted |
1224 { |
1225 if (di->Status() == ENfeDecrypted) |
1225 di->iEncryptEndPos = di->iEntry.iPartitionBaseAddr + di->iEntry.iPartitionLen; |
1226 return ForwardRequest(aReq); |
1226 SetStatus(*di, ENfeEncrypted); |
1227 |
1227 __KTRACE_PRINT(Kern::Printf("NFE%d: HandleFormat() , Setting status to %s", iInstance, DriveStatus(di->Status()))); |
1228 // otherwise create a buffer containing NULLs, encrypt it and write that to the attached drive |
1228 } |
1229 while(remainingLength && r == KErrNone) |
1229 |
1230 { |
1230 if (currentPos >= di->iEntry.iPartitionBaseAddr && |
1231 TInt64 currentLength = (remainingLength <= KBufSize ? remainingLength : KBufSize); |
1231 currentPos < di->iEntry.iPartitionBaseAddr + KSectorSize && |
1232 |
1232 di->IsUDADrive() && |
1233 TBool encryptBuffer = AdjustRequest(di, currentPos, currentLength); |
1233 di->Status() == ENfeEncrypted) |
1234 |
1234 { |
1235 memclr(iBuffer, KBufSize); |
1235 __KTRACE_PRINT(Kern::Printf("NFE%d: Write to sector #0 detected", iInstance)); |
1236 TPtr8 des(iBuffer,KBufSize,KBufSize); |
1236 di->iUniqueID = 0; // undefined |
1237 |
1237 __KTRACE_PRINT(Kern::Printf("NFE%d: Setting Volume ID to %08X", iInstance, di->iUniqueID )); |
1238 if (encryptBuffer) |
1238 } |
1239 EncryptBuffer(des); |
1239 |
1240 |
1240 |
1241 r = Write(di->iLocalDriveNum, currentPos, (TLinAddr) iBuffer, I64LOW(currentLength)); |
1241 return ForwardRequest(aReq); |
1242 if(r != KErrNone) |
|
1243 break; |
|
1244 |
|
1245 remainingLength-= currentLength; |
|
1246 currentPos+= currentLength; |
|
1247 } |
|
1248 |
|
1249 return r == KErrNone ? KErrCompletion : r; |
|
1250 } |
1242 } |
1251 |
1243 |
1252 |
1244 |
1253 void DMediaDriverNFE::EncryptBuffer(TDes8& aBuffer) |
1245 void DMediaDriverNFE::EncryptBuffer(TDes8& aBuffer) |
1254 { |
1246 { |
1408 |
1404 |
1409 __KTRACE_PRINT(Kern::Printf("NFE%d: fatBootSectorStatus %d", iInstance, fatBootSectorStatus)); |
1405 __KTRACE_PRINT(Kern::Printf("NFE%d: fatBootSectorStatus %d", iInstance, fatBootSectorStatus)); |
1410 |
1406 |
1411 // Find out whether the volume has changed |
1407 // Find out whether the volume has changed |
1412 TUint32 uniqueID = VolumeId(iBuffer); |
1408 TUint32 uniqueID = VolumeId(iBuffer); |
1413 TBool volumeChanged = uniqueID != aDi.iUniqueID; |
1409 TBool volumeChanged = (aDi.iUniqueID != 0) && (uniqueID != aDi.iUniqueID); |
1414 __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)); |
1415 __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)); |
1416 __KTRACE_PRINT(Kern::Printf("NFE%d: volumeChanged %d", iInstance, volumeChanged)); |
1412 __KTRACE_PRINT(Kern::Printf("NFE%d: volumeChanged %d", iInstance, volumeChanged)); |
1417 aDi.iUniqueID = uniqueID; |
1413 aDi.iUniqueID = uniqueID; |
1418 |
1414 |
1535 if (di->iDriveFinalised) |
1531 if (di->iDriveFinalised) |
1536 { |
1532 { |
1537 __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)); |
1538 return KErrNone; |
1534 return KErrNone; |
1539 } |
1535 } |
1540 |
|
1541 // TInt KBackgroundPriority = 7; //*test* |
|
1542 // Kern::SetThreadPriority(KBackgroundPriority); //*test* |
|
1543 |
1536 |
1544 TInt r = KErrNone; |
1537 TInt r = KErrNone; |
1545 for (;;) |
1538 for (;;) |
1546 { |
1539 { |
1547 // 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 |