Update contrib.
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
23 This contains CT_FsData
28 #include "T_VolumeInfoData.h"
29 #include "FileserverUtil.h"
34 _LIT(KPromptProcess, "t_prompt.exe");
38 _LIT(KMediaNotPresent, "EMediaNotPresent");
39 _LIT(KMediaUnknown, "EMediaUnknown");
40 _LIT(KMediaFloppy, "EMediaFloppy");
41 _LIT(KMediaHardDisk, "EMediaHardDisk");
42 _LIT(KMediaCdRom, "EMediaCdRom");
43 _LIT(KMediaRam, "EMediaRam");
44 _LIT(KMediaFlash, "EMediaFlash");
45 _LIT(KMediaRom, "EMediaRom");
46 _LIT(KMediaRemote, "EMediaRemote");
47 _LIT(KMediaNANDFlash, "EMediaNANDFlash");
49 _LIT(KBatNotSupported, "EBatNotSupported");
50 _LIT(KBatLow, "EBatLow");
51 _LIT(KBatGood, "EBatGood");
53 _LIT(KDriveAttLocalStr, "KDriveAttLocal");
54 _LIT(KDriveAttRomStr, "KDriveAttRom");
55 _LIT(KDriveAttRedirectedStr, "KDriveAttRedirected");
56 _LIT(KDriveAttSubstedStr, "KDriveAttSubsted");
57 _LIT(KDriveAttInternalStr, "KDriveAttInternal");
58 _LIT(KDriveAttRemovableStr, "KDriveAttRemovable");
60 _LIT(KMediaAttVariableSizeStr, "KMediaAttVariableSize");
61 _LIT(KMediaAttDualDensityStr, "KMediaAttDualDensity");
62 _LIT(KMediaAttFormattableStr, "KMediaAttFormattable");
63 _LIT(KMediaAttWriteProtectedStr, "KMediaAttWriteProtected");
64 _LIT(KMediaAttLockableStr, "KMediaAttLockable");
65 _LIT(KMediaAttLockedStr, "KMediaAttLocked");
69 _LIT(KStore, "store");
70 _LIT(KMediaType, "media_type");
71 _LIT(KDriveAtt, "drive_att");
72 _LIT(KMediaAtt, "media_att");
73 _LIT(KDriveIndex, "drive_index");
74 _LIT(KDriveChar, "drive_char");
75 _LIT(KArraySize, "array_size");
76 _LIT(KArrayIndex, "array_index_");
77 _LIT(KVolumeLabel, "volume_label");
78 _LIT(KSubstPath, "subst_path");
79 _LIT(KDriveName, "drive_name");
80 _LIT(KDriveOldPassword, "drive_old_password");
81 _LIT(KDriveNewPassword, "drive_new_password");
82 _LIT(KBytesToReserve, "bytes_to_reserve");
83 _LIT(KDriveIsValid, "drive_is_valid");
84 _LIT(KDrivePath, "drive_path");
85 _LIT(KDrive, "drive");
86 _LIT(KBatteryState, "battery_state");
87 _LIT(KSaveInInstance, "save_in_instance");
88 _LIT(KVolumeObject, "store_volume");
92 _LIT(KCmdDriveList, "DriveList");
93 _LIT(KCmdDrive, "Drive");
94 _LIT(KCmdVolume, "Volume");
95 _LIT(KCmdSetVolumeLabel, "SetVolumeLabel");
96 _LIT(KCmdSubst, "Subst");
97 _LIT(KCmdSetSubst, "SetSubst");
98 _LIT(KCmdGetMediaSerialNumber, "GetMediaSerialNumber");
99 _LIT(KCmdIsValidDrive, "IsValidDrive");
100 _LIT(KCmdCharToDrive, "CharToDrive");
101 _LIT(KCmdDriveToChar, "DriveToChar");
102 _LIT(KCmdCheckDisk, "CheckDisk");
103 _LIT(KCmdScanDrive, "ScanDrive");
104 _LIT(KCmdGetDriveName, "GetDriveName");
105 _LIT(KCmdSetDriveName, "SetDriveName");
106 _LIT(KCmdLockDrive, "LockDrive");
107 _LIT(KCmdUnlockDrive, "UnlockDrive");
108 _LIT(KCmdClearPassword, "ClearPassword");
109 _LIT(KCmdErasePassword, "ErasePassword");
110 _LIT(KCmdReserveDriveSpace, "ReserveDriveSpace");
111 _LIT(KCmdGetReserveAccess, "GetReserveAccess");
112 _LIT(KCmdReleaseReserveAccess, "ReleaseReserveAccess");
113 _LIT(KCmdPrompt, "prompt");
114 _LIT(KCmdGetSystemDrive, "GetSystemDrive");
115 _LIT(KCmdSetSystemDrive, "SetSystemDrive");
116 _LIT(KCmdGetSystemDriveChar, "GetSystemDriveChar");
117 _LIT(KCmdVolumeIOParam, "VolumeIOParam");
122 * Process a drives related command read from the ini file
124 * @param aCommand the command to process
125 * @param aSection the entry in the ini file requiring the command to be processed
127 * @return ETrue if the command is processed
129 TBool CT_FsData::DoCommandDrivesL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
131 TBool retVal = ETrue;
132 //Parsing the aCommand to choose which function has to be executed.
134 if (aCommand == KCmdDriveList)
136 DoCmdDriveList(aSection);
138 else if (aCommand == KCmdDrive)
140 DoCmdDriveL(aSection);
142 else if (aCommand == KCmdVolume)
144 DoCmdVolumeL(aSection);
146 else if (aCommand == KCmdSetVolumeLabel)
148 DoCmdSetVolumeLabel(aSection);
150 else if (aCommand == KCmdSubst)
152 DoCmdSubst(aSection);
154 else if (aCommand == KCmdSetSubst)
156 DoCmdSetSubst(aSection);
158 else if (aCommand == KCmdGetMediaSerialNumber)
160 DoCmdGetMediaSerialNumber(aSection);
162 else if (aCommand == KCmdIsValidDrive)
164 DoCmdIsValidDrive(aSection);
166 else if (aCommand == KCmdCharToDrive)
168 DoCmdCharToDrive(aSection);
170 else if (aCommand == KCmdDriveToChar)
172 DoCmdDriveToChar(aSection);
174 else if (aCommand == KCmdCheckDisk)
176 DoCmdCheckDisk(aSection);
178 else if (aCommand == KCmdScanDrive)
180 DoCmdScanDrive(aSection);
182 else if (aCommand == KCmdGetDriveName)
184 DoCmdGetDriveName(aSection);
186 else if (aCommand == KCmdSetDriveName)
188 DoCmdSetDriveName(aSection);
190 else if (aCommand == KCmdLockDrive)
192 DoCmdLockDrive(aSection);
194 else if (aCommand == KCmdUnlockDrive)
196 DoCmdUnlockDrive(aSection);
198 else if (aCommand == KCmdClearPassword)
200 DoCmdClearPassword(aSection);
202 else if (aCommand == KCmdErasePassword)
204 DoCmdErasePassword(aSection);
206 else if (aCommand == KCmdReserveDriveSpace)
208 DoCmdReserveDriveSpace(aSection);
210 else if (aCommand == KCmdGetReserveAccess)
212 DoCmdGetReserveAccess(aSection);
214 else if (aCommand == KCmdReleaseReserveAccess)
216 DoCmdReleaseReserveAccess(aSection);
218 else if (aCommand == KCmdPrompt)
220 DoCmdPromptL(aSection);
222 else if (aCommand == KCmdGetSystemDrive)
224 DoCmdGetSystemDrive(aSection);
226 else if (aCommand == KCmdGetSystemDriveChar)
228 DoCmdGetSystemDriveChar(aSection);
230 else if (aCommand == KCmdSetSystemDrive)
232 DoCmdSetSystemDrive(aSection);
234 else if (aCommand == KCmdVolumeIOParam)
236 DoCmdVolumeIOParam(aSection);
247 TBool CT_FsData::GetMediaTypeFromConfig(const TDesC& aSection, TMediaType& aMediaType)
249 // Read media type from INI file
251 TBool ret = GET_OPTIONAL_STRING_PARAMETER(KMediaType(), aSection, mediaTypeStr);
255 if (mediaTypeStr == KMediaNotPresent)
257 aMediaType = EMediaNotPresent;
259 else if (mediaTypeStr == KMediaUnknown)
261 aMediaType = EMediaUnknown;
263 else if (mediaTypeStr == KMediaFloppy)
265 aMediaType = EMediaFloppy;
267 else if (mediaTypeStr == KMediaHardDisk)
269 aMediaType = EMediaHardDisk;
271 else if (mediaTypeStr == KMediaCdRom)
273 aMediaType = EMediaCdRom;
275 else if (mediaTypeStr == KMediaRam)
277 aMediaType = EMediaRam;
279 else if (mediaTypeStr == KMediaFlash)
281 aMediaType = EMediaFlash;
283 else if (mediaTypeStr == KMediaRom)
285 aMediaType = EMediaRom;
287 else if (mediaTypeStr == KMediaRemote)
289 aMediaType = EMediaRemote;
291 else if (mediaTypeStr == KMediaNANDFlash)
293 aMediaType = EMediaNANDFlash;
298 ret = GET_MANDATORY_INT_PARAMETER(KMediaType, aSection, mediaType);
301 aMediaType = (TMediaType) mediaType;
308 TBool CT_FsData::ConvertToDriveAtts(const TDesC& aDriveAttStr, TUint& aDriveAtt)
311 if ( aDriveAttStr==KDriveAttLocalStr )
313 aDriveAtt=KDriveAttLocal;
315 else if ( aDriveAttStr==KDriveAttRomStr )
317 aDriveAtt=KDriveAttRom;
319 else if ( aDriveAttStr==KDriveAttRedirectedStr )
321 aDriveAtt=KDriveAttRedirected;
323 else if ( aDriveAttStr==KDriveAttSubstedStr )
325 aDriveAtt=KDriveAttSubsted;
327 else if ( aDriveAttStr==KDriveAttInternalStr )
329 aDriveAtt=KDriveAttInternal;
331 else if ( aDriveAttStr==KDriveAttRemovableStr )
333 aDriveAtt=KDriveAttRemovable;
337 TInt location = aDriveAttStr.Match(_L("*|*"));
338 if( location!=KErrNotFound )
340 //Converting Left part of the data
341 TPtrC tempStr = aDriveAttStr.Left(location);
342 ret=ConvertToDriveAtts(tempStr, aDriveAtt);
344 //Converting right data can be with another "|"
345 tempStr.Set(aDriveAttStr.Mid(location+1));
348 if ( ConvertToDriveAtts(tempStr, driveAttTmp) )
350 aDriveAtt=aDriveAtt|driveAttTmp;
366 void CT_FsData::DoCmdPromptL(const TDesC& /*aSection*/)
368 RProcess promptProcess;
369 TInt err = promptProcess.Create(KPromptProcess, KNullDesC);
373 CleanupClosePushL(promptProcess);
374 TRequestStatus promptStatus;
375 promptProcess.Rendezvous(promptStatus);
377 if (promptStatus == KRequestPending)
379 promptProcess.Resume();
380 User::WaitForRequest(promptStatus);
383 ERR_PRINTF2(_L("Prompt process finished with error %d"), promptStatus.Int());
384 SetBlockResult(EFail);
389 promptProcess.RendezvousCancel(promptStatus);
390 promptProcess.Kill(0);
391 ERR_PRINTF2(_L("Executing of prompt process failed with error %d"), promptStatus.Int());
392 SetBlockResult(EFail);
395 CleanupStack::PopAndDestroy();
399 ERR_PRINTF2(_L("Failed to create prompt process with error %d"), err);
400 SetBlockResult(EFail);
404 TBool CT_FsData::GetDriveAttsFromConfig(const TDesC& aSection, TUint& aDriveAtt)
409 TBool ret = GET_OPTIONAL_STRING_PARAMETER(KDriveAtt(), aSection, driveAttStr);
412 if ( !ConvertToDriveAtts(driveAttStr, aDriveAtt) )
415 ret=GET_MANDATORY_INT_PARAMETER(KDriveAtt(), aSection, intTemp);
426 TBool CT_FsData::GetBatteryStateFromConfig(const TDesC& aSection, TBatteryState& aBatteryState)
428 // Read media type from INI file
429 aBatteryState = EBatLow;
431 TPtrC batteryStateStr;
432 TBool ret = GET_OPTIONAL_STRING_PARAMETER(KBatteryState(), aSection, batteryStateStr);
436 if (batteryStateStr == KBatNotSupported)
438 aBatteryState = EBatNotSupported;
440 else if (batteryStateStr == KBatGood)
442 aBatteryState = EBatGood;
445 if (batteryStateStr == KBatLow)
447 aBatteryState = EBatLow;
451 aBatteryState = EBatNotSupported;
458 TBool CT_FsData::ConvertToMediaAtts(const TDesC& aMediaAttStr, TUint& aMediaAtt)
461 if ( aMediaAttStr==KMediaAttVariableSizeStr )
463 aMediaAtt=KMediaAttVariableSize;
465 else if ( aMediaAttStr==KMediaAttDualDensityStr )
467 aMediaAtt=KMediaAttDualDensity;
469 else if ( aMediaAttStr==KMediaAttFormattableStr )
471 aMediaAtt=KMediaAttFormattable;
473 else if ( aMediaAttStr==KMediaAttWriteProtectedStr )
475 aMediaAtt=KMediaAttWriteProtected;
477 else if ( aMediaAttStr==KMediaAttLockableStr )
479 aMediaAtt=KMediaAttLockable;
481 else if ( aMediaAttStr==KMediaAttLockedStr )
483 aMediaAtt=KMediaAttLocked;
487 TInt location = aMediaAttStr.Match(_L("*|*"));
488 if( location!=KErrNotFound )
490 //Converting Left part of the data
491 TPtrC tempStr = aMediaAttStr.Left(location);
492 ret=ConvertToMediaAtts(tempStr, aMediaAtt);
494 //Converting right data can be with another "|"
495 tempStr.Set(aMediaAttStr.Mid(location+1));
498 if ( ConvertToMediaAtts(tempStr, mediaAttTmp) )
500 aMediaAtt=aMediaAtt|mediaAttTmp;
516 TBool CT_FsData::GetMediaAttsFromConfig(const TDesC& aSection, TUint& aMediaAtt)
521 TBool ret = GET_OPTIONAL_STRING_PARAMETER(KMediaAtt(), aSection, mediaAttStr);
524 if ( !ConvertToMediaAtts(mediaAttStr, aMediaAtt) )
527 ret=GET_MANDATORY_INT_PARAMETER(KMediaAtt(), aSection, intTemp);
538 void CT_FsData::DoCmdDriveList(const TDesC& aSection)
540 INFO_PRINTF1(_L("Calls RFs::DriveList()."));
542 //Get the list of drives which presents in system. There should be 26 slots where each non-zero slot means a drive in system.
543 TDriveList driveList;
544 TInt errorCode = iFs->DriveList(driveList);
547 if (errorCode != KErrNone)
549 ERR_PRINTF2(_L("Function DriveList() failed with %d error code."), errorCode);
554 //Get data from config
555 //Get first drive index from config.
558 if (GET_MANDATORY_INT_PARAMETER(KArraySize(), aSection, arraySize))
562 for(TInt i = 0; i < arraySize; i++)
564 TBuf<KBufferStringLength>tmpBuff;
566 tmpBuff.Append(KArrayIndex);
567 tmpBuff.AppendNum(i+1);
568 if (GET_MANDATORY_INT_PARAMETER( tmpBuff, aSection, arrayIndex))
571 //Check that drive C and drive Z or others what realy present are in list. Also user can change the drives and check their presence.
572 if (driveList[arrayIndex] == 0)
574 ERR_PRINTF2(_L(" Disk no. %d not present."), arrayIndex);
575 SetBlockResult(EFail);
585 void CT_FsData::DoCmdDriveL(const TDesC& aSection)
587 INFO_PRINTF1(_L("Calls RFs::Drive()."));
589 //Get drive index from config.
590 TDriveNumber driveIndex;
591 TBool nonDefault = GetDriveNumberFromConfig(aSection, KDrive(), driveIndex);
593 //Get info about drive.
594 TDriveInfo driveInfo;
598 errorCode = iFs->Drive(driveInfo, driveIndex);
602 errorCode = iFs->Drive(driveInfo);
605 if(errorCode == KErrNone)
607 if ( !VerifyTDriveInfoDataFromIniL(aSection, driveInfo))
609 SetBlockResult(EFail);
614 ERR_PRINTF2(_L("Function Drive() failed with %d error code"), errorCode);
619 TBool CT_FsData::VerifyTDriveInfoDataFromIniL(const TDesC& aSection, TDriveInfo& aDriveInfo)
623 INFO_PRINTF2(_L("TDriveInfo.iType =%d"), aDriveInfo.iType);
624 INFO_PRINTF2(_L("TDriveInfo.iBattery =%d"), aDriveInfo.iBattery);
625 INFO_PRINTF2(_L("TDriveInfo.iDriveAtt=0x%X"), aDriveInfo.iDriveAtt);
626 TUint driveAttMask[]=
635 TPtrC driveAttText[]=
639 KDriveAttRedirectedStr(),
640 KDriveAttSubstedStr(),
641 KDriveAttInternalStr(),
642 KDriveAttRemovableStr(),
644 TInt size = sizeof(driveAttMask) / sizeof(driveAttMask[0]);
646 for ( index=0; index<size; ++index )
648 if ( aDriveInfo.iDriveAtt&driveAttMask[index] )
650 INFO_PRINTF2(_L("DriveAtt %S ON"), &driveAttText[index]);
653 INFO_PRINTF2(_L("TDriveInfo.iMediaAtt=0x%X"), aDriveInfo.iMediaAtt);
654 TUint mediaAttMask[]=
656 KMediaAttVariableSize,
657 KMediaAttDualDensity,
658 KMediaAttFormattable,
659 KMediaAttWriteProtected,
663 TPtrC mediaAttText[]=
665 KMediaAttVariableSizeStr(),
666 KMediaAttDualDensityStr(),
667 KMediaAttFormattableStr(),
668 KMediaAttWriteProtectedStr(),
669 KMediaAttLockableStr(),
670 KMediaAttLockedStr(),
673 size = sizeof(mediaAttMask) / sizeof(mediaAttMask[0]);
674 for ( index=0; index<size; ++index )
676 if ( aDriveInfo.iMediaAtt&mediaAttMask[index] )
678 INFO_PRINTF2(_L("MediaAtt %S ON"), &mediaAttText[index]);
682 //Get drive type from config.
683 TMediaType mediaType;
684 if (GetMediaTypeFromConfig(aSection, mediaType))
686 //Checking that type of drive is equal to passed through config file.
687 if (aDriveInfo.iType != mediaType)
689 ERR_PRINTF3(_L("Drive has wrong type. actual: %d, expected: %d"), aDriveInfo.iType, mediaType);
694 //Optional battery state checking
695 TBatteryState batteryState;
696 if (GetBatteryStateFromConfig(aSection, batteryState))
698 //Checking that type of drive is equal to passed through config file.
699 if (aDriveInfo.iBattery != batteryState)
701 ERR_PRINTF3(_L("BatteryState is wrong. actual: %d, expected: %d"), aDriveInfo.iBattery, batteryState);
706 //Optional media attributes checking
708 if (GetMediaAttsFromConfig(aSection, mediaAtts))
710 //Checking that type of drive is equal to passed through config file.
711 if ( (aDriveInfo.iMediaAtt&mediaAtts)==mediaAtts )
713 ERR_PRINTF1(_L("Media attributes are wrong"));
718 //Optional drive attributes checking.
720 if (GetDriveAttsFromConfig(aSection, driveAtts))
722 //Checking that type of drive is equal to passed through config file.
723 if ( (aDriveInfo.iDriveAtt!=driveAtts)==driveAtts )
725 ERR_PRINTF1(_L("Drive attributes are wrong"));
733 void CT_FsData::DoCmdVolumeL(const TDesC& aSection)
735 INFO_PRINTF1(_L("Calls RFs:: Volume()."));
737 //Get drive index from config.
738 TDriveNumber driveIndex;
740 TBool nonDefault = GetDriveNumberFromConfig(aSection, KDrive(), driveIndex);
742 //Get info about volume.
747 errorCode = iFs->Volume(iVolumeInfo, driveIndex);
751 errorCode = iFs->Volume(iVolumeInfo);
754 if (errorCode != KErrNone)
756 ERR_PRINTF2(_L("Function Volume() failed with %d error code"), errorCode);
761 if ( !FileserverUtil::VerifyTVolumeInfoDataFromIniL(*this, aSection, iVolumeInfo))
763 SetBlockResult(EFail);
766 if ( !VerifyTDriveInfoDataFromIniL(aSection, iVolumeInfo.iDrive))
768 SetBlockResult(EFail);
773 if(GET_OPTIONAL_BOOL_PARAMETER(KSaveInInstance(), aSection, save))
777 iVolumeLabel.Copy(iVolumeInfo.iName);
781 TPtrC volumeObjectName;
782 if (GET_OPTIONAL_STRING_PARAMETER(KVolumeObject, aSection, volumeObjectName))
784 CT_VolumeInfoData* volumeWrapperObject = NULL;
785 volumeWrapperObject = static_cast<CT_VolumeInfoData*>(GetDataWrapperL(volumeObjectName));
786 if(volumeWrapperObject)
788 TVolumeInfo* volumeObject = new(ELeave) TVolumeInfo();
789 *volumeObject = iVolumeInfo;
790 volumeWrapperObject->SetObjectL(volumeObject);
798 void CT_FsData::DoCmdSetVolumeLabel(const TDesC& aSection)
800 INFO_PRINTF1(_L("Calls RFs:: SetVolumeLabel()."));
802 //Get drive index from config.
803 TDriveNumber driveIndex;
804 TBool nonDefault = GetDriveNumberFromConfig(aSection, KDrive(), driveIndex);
806 //Get volume name from config.
808 if (!GET_OPTIONAL_STRING_PARAMETER(KVolumeLabel(), aSection, volumeLabel))
810 volumeLabel.Set(iVolumeLabel);
813 //Trying to set the volume label. By some reason it always retturn KErrNotSupported.
817 errorCode = iFs->SetVolumeLabel(volumeLabel, driveIndex);
821 errorCode = iFs->SetVolumeLabel(volumeLabel);
825 if (errorCode != KErrNone)
827 ERR_PRINTF2(_L("Function SetVolumeLabel() failed with %d error code"), errorCode);
833 void CT_FsData::DoCmdSubst(const TDesC& aSection)
835 INFO_PRINTF1(_L("Calls RFs:: Subst()."));
837 //Get drive index from config.
838 TDriveNumber driveIndex;
841 TBool nonDefault = GetDriveNumberFromConfig(aSection, KDrive(), driveIndex);
844 TBuf16<KBufferStringLength> substPath;
846 //Get the path to substed drive.
851 errorCode = iFs->Subst(substPath, driveIndex);
855 errorCode = iFs->Subst(substPath);
859 if (errorCode != KErrNone)
861 ERR_PRINTF2(_L("Function Subst() failed with %d error code"), errorCode);
866 //Get drive index from config.
867 TPtrC substPathFromConf;
868 if (GET_MANDATORY_STRING_PARAMETER(KSubstPath(), aSection, substPathFromConf))
871 //As long as it has to be in similar format we must convert substPathFromConf to TBuf16<255>
874 if (substPathFromConf.CompareF(substPath) != 0)
876 ERR_PRINTF2(_L("Subst path is wrong %S"), &substPathFromConf);
877 SetBlockResult(EFail);
886 void CT_FsData::DoCmdSetSubst(const TDesC& aSection)
888 INFO_PRINTF1(_L("Calls RFs:: SetSubst()."));
891 //Get drive index from config.
892 TDriveNumber driveIndex;
893 TBool nonDefault = GetDriveNumberFromConfig(aSection, KDrive(), driveIndex);
896 //Get drive index from config.
898 if (GET_MANDATORY_STRING_PARAMETER(KSubstPath(), aSection, substPath))
901 //Substing the drive with index driveIndex to path substPath.
905 errorCode = iFs->SetSubst(substPath, driveIndex);
909 errorCode = iFs->SetSubst(substPath);
913 if (errorCode != KErrNone)
915 ERR_PRINTF2(_L("Function SetSubst() failed with %d error code"), errorCode);
926 void CT_FsData::DoCmdGetMediaSerialNumber(const TDesC& aSection)
928 INFO_PRINTF1(_L("Calls RFs::GetMediaSerialNumber()."));
930 //Get drive index from config.
931 TDriveNumber driveIndex;
932 if (GetDriveNumberFromConfig(aSection, KDrive(), driveIndex))
934 //Get the media serial number.
935 TMediaSerialNumber mediaSerialNumber;
936 TInt errorCode = iFs->GetMediaSerialNumber(mediaSerialNumber, driveIndex);
939 if (errorCode != KErrNone)
941 ERR_PRINTF2(_L("Function GetMediaSerialNumber() failed with %d error code"), errorCode);
947 ERR_PRINTF2(_L("Not found %S parameter"), &KDrive());
948 SetBlockResult(EFail);
954 void CT_FsData::DoCmdIsValidDrive(const TDesC& aSection)
956 INFO_PRINTF1(_L("Calls RFs::IsValidDirve()."));
958 //Get drive index from config.
959 TDriveNumber driveIndex;
960 if (GetDriveNumberFromConfig(aSection, KDrive(), driveIndex))
962 TBool actualValid = RFs::IsValidDrive(driveIndex);
963 INFO_PRINTF2(_L("iFs->IsValidDrive = %d"), actualValid);
965 //Get drive validity flag rom config.
967 if ( GET_OPTIONAL_BOOL_PARAMETER(KDriveIsValid(), aSection, expectedValid) )
969 if ( actualValid!=expectedValid )
971 ERR_PRINTF1(_L("Function IsValid() returned unexpected result"));
972 SetBlockResult(EFail);
978 ERR_PRINTF2(_L("Not found %S parameter"), &KDrive());
979 SetBlockResult(EFail);
984 void CT_FsData::DoCmdCharToDrive(const TDesC& aSection)
986 INFO_PRINTF1(_L("Calls RFs:: CharToDrive()."));
988 //Get drive index from config.
989 //We meed integer there, because function uses TInt, not TDriveNumber.
991 TDriveNumber driveIndex;
994 //Get drive char from config.
996 if (GET_MANDATORY_STRING_PARAMETER(KDriveChar(), aSection, driveCharTmp))
999 TChar driveChar = driveCharTmp.Ptr()[0];
1001 TInt errorCode = RFs::CharToDrive(driveChar, driveIndex2);
1004 if (errorCode != KErrNone)
1006 ERR_PRINTF2(_L("Function CharToDrive() failed with %d error code"), errorCode);
1007 SetError(errorCode);
1011 //Get drive index from config
1012 if (GetDriveNumberFromConfig(aSection, KDriveIndex(), driveIndex))
1014 if (driveIndex != driveIndex2)
1016 ERR_PRINTF1(_L("Wrong conversion from char to index"));
1017 SetBlockResult(EFail);
1024 ERR_PRINTF2(_L("Not found %S parameter"), &KDrive());
1025 SetBlockResult(EFail);
1030 void CT_FsData::DoCmdDriveToChar(const TDesC& aSection)
1032 INFO_PRINTF1(_L("Calls RFs:: DriveToChar()."));
1036 //Get drive path from config.
1037 TDriveNumber driveIndex;
1038 if (GetDriveNumberFromConfig(aSection, KDriveIndex(), driveIndex))
1042 TInt errorCode = RFs::DriveToChar(driveIndex, driveChar2);
1045 if (errorCode != KErrNone)
1047 ERR_PRINTF2(_L("Function DriveToChar() failed with %d error code"), errorCode);
1048 SetError(errorCode);
1052 INFO_PRINTF3(_L("DriveToChar(%d) = %c"), driveIndex, TUint(driveChar2));
1054 //Get drive char from config.
1055 if (GET_OPTIONAL_STRING_PARAMETER(KDriveChar(), aSection, driveCharTmp))
1058 TChar driveChar= driveCharTmp.Ptr()[0];
1059 if (driveChar != driveChar2)
1061 ERR_PRINTF1(_L("Wrong conversion from char to index"));
1062 SetBlockResult(EFail);
1069 ERR_PRINTF2(_L("Not found %S parameter"), &KDrive());
1070 SetBlockResult(EFail);
1075 void CT_FsData::DoCmdCheckDisk(const TDesC& aSection)
1077 INFO_PRINTF1(_L("Calls RFs:: CheckDisk()."));
1079 //Get drive path from config.
1081 if (GET_MANDATORY_STRING_PARAMETER(KDrivePath(), aSection, drivePath))
1084 TInt errorCode = iFs->CheckDisk(drivePath);
1087 if (errorCode != KErrNone)
1089 ERR_PRINTF2(_L("Function CheckDisk() failed with %d error code"), errorCode);
1090 SetError(errorCode);
1097 void CT_FsData::DoCmdScanDrive(const TDesC& aSection)
1099 INFO_PRINTF1(_L("Calls RFs:: ScanDisk()."));
1101 //Get drive path from config.
1103 if (GET_MANDATORY_STRING_PARAMETER(KDrivePath(), aSection, drivePath))
1106 TInt errorCode = iFs->ScanDrive(drivePath);
1109 if (errorCode != KErrNone)
1111 ERR_PRINTF2(_L("Function ScanDrive() failed with %d error code"), errorCode);
1112 SetError(errorCode);
1120 void CT_FsData::DoCmdGetDriveName(const TDesC& aSection)
1122 INFO_PRINTF1(_L("Calls RFs::Calls GetDriveName()"));
1124 //Get drive index from config.
1125 TDriveNumber driveIndex;
1127 if (GetDriveNumberFromConfig(aSection, KDrive(), driveIndex))
1129 TBuf<KBufferStringLength> driveName;
1130 TInt errorCode = iFs->GetDriveName(driveIndex, driveName);
1133 if (errorCode != KErrNone)
1135 ERR_PRINTF2(_L("Function SetDriveLabel() failed with %d error code"), errorCode);
1136 SetError(errorCode);
1140 //Get drive name from config.
1141 TPtrC driveNameFromConf;
1142 if(GET_OPTIONAL_STRING_PARAMETER(KDriveName(), aSection, driveNameFromConf))
1144 TPtrC driveNamePtr = driveName;
1145 if (driveNamePtr != driveNameFromConf)
1147 ERR_PRINTF3(_L("Names mismatch: %S != %S"), &driveNamePtr, &driveNameFromConf);
1148 SetBlockResult(EFail);
1154 if(GET_OPTIONAL_BOOL_PARAMETER(KSaveInInstance(), aSection, save))
1158 iDriveName.Copy(iDriveName);
1165 ERR_PRINTF2(_L("Not found %S parameter"), &KDrive());
1166 SetBlockResult(EFail);
1171 void CT_FsData::DoCmdSetDriveName(const TDesC& aSection)
1173 INFO_PRINTF1(_L("Calls RFs::SetDriveName()."));
1175 //Get drive index from config.
1176 TDriveNumber driveIndex;
1177 if ( GetDriveNumberFromConfig(aSection, KDrive(), driveIndex) )
1179 //Get drive name from config.
1181 if ( !GET_OPTIONAL_STRING_PARAMETER(KDriveName(), aSection, driveName) )
1183 driveName.Set(iDriveName);
1187 TInt errorCode = iFs->SetDriveName(driveIndex, driveName);
1188 if (errorCode != KErrNone)
1190 ERR_PRINTF2(_L("Function SetDriveLabel() failed with %d error code"), errorCode);
1191 SetError(errorCode);
1196 ERR_PRINTF2(_L("Not found %S parameter"), KDriveIndex);
1197 SetBlockResult(EFail);
1202 void CT_FsData::DoCmdLockDrive(const TDesC& aSection)
1204 INFO_PRINTF1(_L("Calls RFs::LockDrive()."));
1206 //Get old password from config.
1207 TPtrC drivePassword;
1208 if ( GET_MANDATORY_STRING_PARAMETER(KDriveOldPassword(), aSection, drivePassword) )
1210 //Get drive index from config.
1211 TDriveNumber driveIndex;
1212 if ( GetDriveNumberFromConfig(aSection, KDrive(), driveIndex) )
1214 //Get new password from config.
1215 TPtrC driveNewPassword;
1216 if ( GET_MANDATORY_STRING_PARAMETER(KDriveNewPassword(), aSection, driveNewPassword) )
1218 // get boolean value from config
1220 if (GET_MANDATORY_BOOL_PARAMETER(KStore(), aSection, store))
1222 TMediaPassword password;
1223 password.Copy(driveNewPassword);
1224 iPassword.Copy(drivePassword);
1226 TInt errorCode = iFs->LockDrive(driveIndex, iPassword, password, store);
1229 if (errorCode == KErrNone)
1235 ERR_PRINTF2(_L("Function LockDrive() failed with %d error code"), errorCode);
1236 SetError(errorCode);
1245 void CT_FsData::DoCmdUnlockDrive(const TDesC& aSection)
1247 INFO_PRINTF1(_L("Calls RFs::UnlockDrive()."));
1249 //Get old password from config.
1250 TPtrC drivePassword;
1251 if ( GET_MANDATORY_STRING_PARAMETER(KDriveOldPassword(), aSection, drivePassword) )
1253 //Get drive index from config.
1254 TDriveNumber driveIndex;
1255 if (GetDriveNumberFromConfig(aSection, KDrive(), driveIndex))
1257 // get boolean value from config
1259 if (GET_MANDATORY_BOOL_PARAMETER(KStore(), aSection, store))
1261 TMediaPassword password;
1262 //Converting string to appropriative password format(TMediaPassword is typedef for TBuf<16>)
1263 password.Copy(drivePassword);
1265 TInt errorCode = iFs->UnlockDrive(driveIndex, password, store);
1268 if (errorCode == KErrNone)
1274 ERR_PRINTF2(_L("Function UnlockDrive() failed with %d error code"), errorCode);
1275 SetError(errorCode);
1281 ERR_PRINTF2(_L("Not found %S parameter"),KDrive);
1282 SetBlockResult(EFail);
1288 void CT_FsData::DoCmdClearPassword(const TDesC& aSection)
1290 INFO_PRINTF1(_L("Calls RFs::ClearPassword()."));
1292 //Get old password from config.
1293 TPtrC driveOldPasswordTmp;
1294 if (GET_MANDATORY_STRING_PARAMETER(KDriveOldPassword(), aSection, driveOldPasswordTmp))
1296 //Get drive index from config.
1297 TDriveNumber driveIndex;
1298 if (GetDriveNumberFromConfig(aSection, KDrive(), driveIndex))
1300 //Converting string to appropriative password format(TMediaPassword is typedef for TBuf<16>)
1301 TMediaPassword driveOldPassword;
1302 driveOldPassword.Copy(driveOldPasswordTmp);
1304 TInt errorCode = iFs->ClearPassword(driveIndex, driveOldPassword);
1305 if (errorCode != KErrNone)
1307 ERR_PRINTF2(_L("Function ClearPassword() failed with %d error code"), errorCode);
1308 SetError(errorCode);
1313 ERR_PRINTF2(_L("Not found %S parameter"),KDrive);
1314 SetBlockResult(EFail);
1320 void CT_FsData::DoCmdErasePassword(const TDesC& aSection)
1322 INFO_PRINTF1(_L("Calls RFs::ErasePassword()."));
1324 //Get drive from config.
1325 TDriveNumber driveIndex;
1326 if (GetDriveNumberFromConfig(aSection, KDrive(), driveIndex))
1328 TInt errorCode = iFs->ErasePassword(driveIndex);
1331 if (errorCode != KErrNone)
1333 ERR_PRINTF2(_L("Function ErasePassword() failed with %d error code"), errorCode);
1334 SetError(errorCode);
1339 ERR_PRINTF2(_L("Not found %S parameter"), &KDrive());
1340 SetBlockResult(EFail);
1345 void CT_FsData::DoCmdReserveDriveSpace(const TDesC& aSection)
1347 INFO_PRINTF1(_L("Calls RFs::ReserveDriveSpace()."));
1349 //Get amount of bytes to be reserved from config.
1350 TInt bytesToReserve;
1351 if (GET_MANDATORY_INT_PARAMETER(KBytesToReserve(), aSection, bytesToReserve))
1353 TDriveNumber driveIndex;
1355 if (GetDriveNumberFromConfig(aSection, KDrive(), driveIndex))
1357 TInt errorCode = iFs->ReserveDriveSpace(driveIndex, bytesToReserve);
1360 if (errorCode != KErrNone)
1362 ERR_PRINTF2(_L("Function ReserveDriveSpace() failed with %d error code"), errorCode);
1363 SetError(errorCode);
1368 ERR_PRINTF2(_L("Not found %S parameter"),KDrive);
1369 SetBlockResult(EFail);
1375 void CT_FsData::DoCmdGetReserveAccess(const TDesC& aSection)
1377 INFO_PRINTF1(_L("Calls RFs::GetReserveAccess()."));
1379 //Get drive index from config.
1380 TDriveNumber driveIndex;
1381 if (GetDriveNumberFromConfig(aSection, KDrive(), driveIndex))
1383 TInt errorCode = iFs->GetReserveAccess(driveIndex);
1386 if (errorCode != KErrNone)
1388 ERR_PRINTF2(_L("Function GetReserveAccess() failed with %d error code"), errorCode);
1389 SetError(errorCode);
1394 ERR_PRINTF2(_L("Not found %S parameter"), &KDrive());
1395 SetBlockResult(EFail);
1400 void CT_FsData::DoCmdReleaseReserveAccess(const TDesC& aSection)
1402 INFO_PRINTF1(_L("Calls RFs::ReleaseReserveAccess()."));
1404 //Get drive index from config.
1405 TDriveNumber driveIndex;
1406 if (GetDriveNumberFromConfig(aSection, KDrive(), driveIndex))
1408 TInt errorCode = iFs->ReleaseReserveAccess(driveIndex);
1411 if (errorCode != KErrNone)
1413 ERR_PRINTF2(_L("Function ReleaseReserveAccess() failed with %d error code"), errorCode);
1414 SetError(errorCode);
1419 ERR_PRINTF2(_L("Not found %S parameter"), &KDrive());
1420 SetBlockResult(EFail);
1424 void CT_FsData::DoCmdGetSystemDrive(const TDesC& aSection)
1426 INFO_PRINTF1(_L("Calls RFs::GetSystemDrive()."));
1428 TDriveNumber driveNumber = RFs::GetSystemDrive();
1429 INFO_PRINTF2(_L("System Drive = %d"), driveNumber);
1431 //Get drive index from config.
1432 TDriveNumber driveIndex;
1433 if ( GetDriveNumberFromConfig(aSection, KDrive(), driveIndex) )
1436 if (driveNumber != driveIndex)
1438 ERR_PRINTF1(_L("GetSystemDrive() returned unexpected drive"));
1439 SetBlockResult(EFail);
1444 ERR_PRINTF2(_L("Not found %S parameter"), &KDrive());
1445 SetBlockResult(EFail);
1449 void CT_FsData::DoCmdSetSystemDrive(const TDesC& aSection)
1451 INFO_PRINTF1(_L("Calls RFs::SetSystemDrive()"));
1453 // get drive number from parameters
1454 TDriveNumber driveNumber = EDriveA;
1455 if (GetDriveNumberFromConfig(aSection, KDrive(), driveNumber))
1457 TInt err = iFs->SetSystemDrive(driveNumber);
1459 if (err != KErrNone)
1461 ERR_PRINTF2(_L("SetSystemDrive() error: %d"), err);
1467 ERR_PRINTF2(_L("No %S"), &KDrive());
1468 SetBlockResult(EFail);
1473 void CT_FsData::DoCmdGetSystemDriveChar(const TDesC& aSection)
1475 INFO_PRINTF1(_L("Calls RFs::GetSystemDriveChar()"));
1477 TChar drvChar = RFs::GetSystemDriveChar();
1478 INFO_PRINTF2(_L("GetSystemDriveChar() = %c"), TUint(drvChar));
1479 //Get drive char from config.
1481 if (GET_OPTIONAL_STRING_PARAMETER(KDriveChar(), aSection, driveCharTmp))
1483 TChar driveCharExpect = driveCharTmp.Ptr()[0];
1484 driveCharExpect.UpperCase();
1485 drvChar.UpperCase();
1486 if ( drvChar != driveCharExpect)
1488 ERR_PRINTF1(_L("Drive char != expected drive char"));
1489 SetBlockResult(EFail);
1494 void CT_FsData::DoCmdVolumeIOParam(const TDesC& aSection)
1496 INFO_PRINTF1(_L("Calls RFs::VolumeIOParam()"));
1498 // get drive number from parameters
1499 TDriveNumber driveNumber = EDriveA;
1500 if (GetDriveNumberFromConfig(aSection, KDrive(), driveNumber))
1502 TVolumeIOParamInfo volumeIOParamInf;
1503 TInt err = iFs->VolumeIOParam(driveNumber, volumeIOParamInf);
1505 if (err != KErrNone)
1507 ERR_PRINTF2(_L("VolumeIOParam() error: %d"), err);
1512 INFO_PRINTF2(_L("VolumeIOParam BlockSize: %d"), volumeIOParamInf.iBlockSize );
1513 INFO_PRINTF2(_L("VolumeIOParam ClusterSize: %d"), volumeIOParamInf.iClusterSize );
1514 INFO_PRINTF2(_L("VolumeIOParam RecReadBufSize: %d"), volumeIOParamInf.iRecReadBufSize );
1515 INFO_PRINTF2(_L("VolumeIOParam RecWriteBufSize: %d"), volumeIOParamInf.iRecWriteBufSize );
1520 ERR_PRINTF2(_L("No %S"), &KDrive());
1521 SetBlockResult(EFail);