userlibandfileserver/fileserver/etshell/ts_com.cpp
changeset 201 43365a9b78a3
parent 152 657f875b013e
child 189 a5496987b1da
equal deleted inserted replaced
200:73ea206103e6 201:43365a9b78a3
    29 #include "u32std.h"
    29 #include "u32std.h"
    30 #include <u32hal.h>
    30 #include <u32hal.h>
    31 #include <nkern/nk_trace.h>
    31 #include <nkern/nk_trace.h>
    32 #include "filesystem_fat.h"
    32 #include "filesystem_fat.h"
    33 
    33 
       
    34 _LIT(KCrNl, "\r\n");
       
    35 _LIT(KNl, "\n");
       
    36 
    34     TPtrC ptrFormatHelp=_L("Drive:[\\] [fat12|fat16|fat32] [spc:X] [rs:Y] [ft:Z] [/Q][/S][/E][/F]\nfat12 or fat16 or fat32 specifies explicit FAT type\nspc:X specifies \"X\" sectors per cluster\nrs:Y specifies \"Y\" reserved sectors\nft:Z specifies \"Z\" FAT tables (1 or 2)\n\n/q - QuickFormat, /s - SpecialFormat, /e - ForcedErase\n/f - force formatting (ignore volume being in use)");
    37     TPtrC ptrFormatHelp=_L("Drive:[\\] [fat12|fat16|fat32] [spc:X] [rs:Y] [ft:Z] [/Q][/S][/E][/F]\nfat12 or fat16 or fat32 specifies explicit FAT type\nspc:X specifies \"X\" sectors per cluster\nrs:Y specifies \"Y\" reserved sectors\nft:Z specifies \"Z\" FAT tables (1 or 2)\n\n/q - QuickFormat, /s - SpecialFormat, /e - ForcedErase\n/f - force formatting (ignore volume being in use)");
    35     TPtrC ptrMountHelp=_L("Drive:[\\]  <fsy:X> <fs:Y> [pext:Z] [/S][/U][/F][/R]\n'X' *.fsy module name, like elocal.fsy\n'Y' file system name, like 'FAT'\n'Z' optional primary extension module name\n/U - dismount FS from the drive e.g 'mount d: /u' \n/F - force mounting with dismounting existing FS \n/S - mount drive as synchronous\n/R - remount the file system ");
    38 TPtrC ptrMountHelp=_L("Drive:[\\]  <fsy:X> <fs:Y> [pext:Z] [/S][/U][/F][/R]\n'X' *.fsy module name, like elocal.fsy\n'Y' file system name, like 'FAT'\n'Z' optional primary extension module name\n/U - dismount FS from the drive e.g 'mount d: /u' \n/U /F force dismounting the FS even if there are opened files on it \n/F - force mounting with dismounting existing FS \n/S - mount drive as synchronous\n/R - remount the file system ");
    36 
    39 
       
    40 TBool CShell::iDbgPrint = EFalse;
    37 
    41 
    38 //	lint -e40,e30
    42 //	lint -e40,e30
    39 const TShellCommand CShell::iCommand[ENoShellCommands]=
    43 const TShellCommand CShell::iCommand[ENoShellCommands]=
    40 	{
    44 	{
    41 //	TShellCommand(_L("BLANK"),_L("Help"),_L("-?"),TShellCommand::EDSwitch,ShellFunction::BLANK),
    45 //	TShellCommand(_L("BLANK"),_L("Help"),_L("-?"),TShellCommand::EDSwitch,ShellFunction::BLANK),
    69 	TShellCommand(_L("DEBUGPORT"),_L("Set or get debug port"),_L("[port]"),0,ShellFunction::DebugPort),
    73 	TShellCommand(_L("DEBUGPORT"),_L("Set or get debug port"),_L("[port]"),0,ShellFunction::DebugPort),
    70 	TShellCommand(_L("PLUGIN"),_L("Manage Plugins"),_L("[name][/A][/R][/M][/D]"),TShellCommand::EASwitch|TShellCommand::ERSwitch|TShellCommand::EMSwitch|TShellCommand::EDSwitch,ShellFunction::Plugin),
    74 	TShellCommand(_L("PLUGIN"),_L("Manage Plugins"),_L("[name][/A][/R][/M][/D]"),TShellCommand::EASwitch|TShellCommand::ERSwitch|TShellCommand::EMSwitch|TShellCommand::EDSwitch,ShellFunction::Plugin),
    71     TShellCommand(_L("DRVINFO"),_L("Print information about present drive(s) in the system"),_L("[DriveLetter:[\\]] [/p]\n/p - pause after each drive"),TShellCommand::EPSwitch,ShellFunction::DrvInfo),
    75     TShellCommand(_L("DRVINFO"),_L("Print information about present drive(s) in the system"),_L("[DriveLetter:[\\]] [/p]\n/p - pause after each drive"),TShellCommand::EPSwitch,ShellFunction::DrvInfo),
    72 	TShellCommand(_L("SYSINFO"),_L("Print information about system features and status"),_L(""),0,ShellFunction::SysInfo),
    76 	TShellCommand(_L("SYSINFO"),_L("Print information about system features and status"),_L(""),0,ShellFunction::SysInfo),
    73     TShellCommand(_L("MOUNT"),_L("Mount / dismount file system on specified drive"),ptrMountHelp,TShellCommand::EUSwitch|TShellCommand::ESSwitch|TShellCommand::EFSwitch|TShellCommand::ERSwitch,ShellFunction::MountFileSystem),
    77     TShellCommand(_L("MOUNT"),_L("Mount / dismount file system on specified drive"),ptrMountHelp,TShellCommand::EUSwitch|TShellCommand::ESSwitch|TShellCommand::EFSwitch|TShellCommand::ERSwitch,ShellFunction::MountFileSystem),
    74     TShellCommand(_L("ECHO"),_L("Print out the command line to the console and standard debug port."),_L("[line to print out]"),0,ShellFunction::ConsoleEcho),
    78     TShellCommand(_L("ECHO"),_L("Print out the command line to the console and standard debug port."),_L("[line to print out] [/Y/N]\n /Y turn ON copying console output to debug port\n /N turn it OFF "),TShellCommand::EYSwitch|TShellCommand::ENSwitch,ShellFunction::ConsoleEcho),
    75 	TShellCommand(_L("RUNEXEC"),_L("Run a program in a loop"),_L("count filename[.exe] [/E/S/R]\n	/E - exit early on error\n	/S - count in seconds\n	     zero - run forever\n	/R - reset debug regs after each run"),TShellCommand::EESwitch|TShellCommand::ESSwitch|TShellCommand::ERSwitch,ShellFunction::RunExec),
    79 	TShellCommand(_L("RUNEXEC"),_L("Run a program in a loop"),_L("count filename[.exe] [/E/S/R]\n	/E - exit early on error\n	/S - count in seconds\n	     zero - run forever\n	/R - reset debug regs after each run"),TShellCommand::EESwitch|TShellCommand::ESSwitch|TShellCommand::ERSwitch,ShellFunction::RunExec),
    76 
    80 
    77     };
    81     };
    78 
    82 
    79 
    83 
   361     {//-- run CheckDisk on the specified drive
   365     {//-- run CheckDisk on the specified drive
   362         nRes=TheShell->TheFs.CheckDisk(aPath);
   366         nRes=TheShell->TheFs.CheckDisk(aPath);
   363 	    if (nRes<0)
   367 	    if (nRes<0)
   364 		    return(nRes);
   368 		    return(nRes);
   365 
   369 
       
   370 	    //-- this is, actually, FAT FS specific error codes. Other file systems can report different values.
   366 	    switch(nRes)
   371 	    switch(nRes)
   367 		    {
   372 		    {
   368 	    case 0:
   373 	    case 0:
   369 		    CShell::TheConsole->Printf(_L("Complete - no errors\n"));
   374 		    CShell::TheConsole->Printf(_L("Complete - no errors\n"));
   370 		    break;
   375 		    break;
  1051     @param  volInfo     volume information
  1056     @param  volInfo     volume information
  1052     @param  aPrintBuf   buffer where the information will be printed to.
  1057     @param  aPrintBuf   buffer where the information will be printed to.
  1053 */
  1058 */
  1054 void FormatVolInfo(const TVolumeInfo& volInfo , TDes& aPrintBuf)
  1059 void FormatVolInfo(const TVolumeInfo& volInfo , TDes& aPrintBuf)
  1055     {
  1060     {
  1056    	aPrintBuf.Format(_L("VolSz:%ld Free:%ld\n"),volInfo.iSize, volInfo.iFree);
  1061    	aPrintBuf.Format(_L("VolSz:%ld Free:%ld"),volInfo.iSize, volInfo.iFree);
  1057    	aPrintBuf.AppendFormat(_L("VolId:0x%x VolName:%S\n"),volInfo.iUniqueID, &volInfo.iName);
  1062    	aPrintBuf.AppendFormat(_L("\r\nVolId:0x%x VolName:%S\n"),volInfo.iUniqueID, &volInfo.iName);
  1058     }
  1063     }
  1059 
  1064 
  1060 //--------------------------------------------------------
  1065 //--------------------------------------------------------
  1061 
  1066 
  1062 /** Bit flags that specify which information will be printed by PrintDrvInfo() */
  1067 /** Bit flags that specify which information will be printed by PrintDrvInfo() */
  1081     @param  apConsole   pointer to the console to print information into
  1086     @param  apConsole   pointer to the console to print information into
  1082     @param  aFlags      specifies which information to print out, @see TPrintDrvInfoFlags
  1087     @param  aFlags      specifies which information to print out, @see TPrintDrvInfoFlags
  1083 
  1088 
  1084     @return standard error code
  1089     @return standard error code
  1085 */
  1090 */
  1086 TInt PrintDrvInfo(RFs& aFs, TInt aDrvNum, CConsoleBase* apConsole, TUint aFlags = EAll)
  1091 TInt PrintDrvInfo(RFs& aFs, TInt aDrvNum, TUint aFlags = EAll)
  1087     {
  1092     {
  1088 	TInt        nRes;
  1093 	TInt        nRes;
  1089 	TDriveInfo 	driveInfo;
  1094 	TDriveInfo 	driveInfo;
  1090 	TVolumeInfo volInfo;
  1095 	TVolumeInfo volInfo;
  1091 	TBuf<256>   Buf;
  1096 	TBuf<256>   Buf;
  1092 
  1097 
  1093 	//-- get drive info
  1098 	//-- get drive info
  1094 	nRes = aFs.Drive(driveInfo, aDrvNum);
  1099 	nRes = aFs.Drive(driveInfo, aDrvNum);
  1095 	if(nRes != KErrNone)
  1100 	if(nRes != KErrNone)
  1096 		{
  1101 		{
  1097 		CShell::TheConsole->Printf(_L("Error: %d\n"), nRes);
  1102         CShell::Printf(_L("Error: %d\n"), nRes);
  1098 		return nRes;   //-- can't get information about the drive
  1103 		return nRes;   //-- can't get information about the drive
  1099 		}
  1104 		}
  1100 
  1105 
  1101 	
  1106 	
  1102     nRes = aFs.Volume(volInfo, aDrvNum);
  1107     nRes = aFs.Volume(volInfo, aDrvNum);
  1103     const TBool bVolumeOK  = (nRes == KErrNone);
  1108     const TBool bVolumeOK  = (nRes == KErrNone);
  1104 	if(!bVolumeOK)
  1109 	if(!bVolumeOK)
  1105 	{//-- can't get information about the volume. It might be just corrupt/unformatted
  1110 	{//-- can't get information about the volume. It might be just corrupt/unformatted
  1106 		CShell::TheConsole->Printf(_L("Error getting volume info. code: %d\n"), nRes);
  1111         CShell::Printf(_L("Error getting volume info. code: %d\n"), nRes);
  1107         if(nRes == KErrCorrupt)
  1112         if(nRes == KErrCorrupt)
  1108         {
  1113         {
  1109             CShell::TheConsole->Printf(_L("The volume might be corrupted or not formatted.\n"));
  1114             CShell::Printf(_L("The volume might be corrupted or not formatted.\n"));
  1110         }
  1115         }
  1111 	}
  1116 	}
  1112 
  1117 
  1113 
  1118 
  1114 	//-- Print out information about file system installed
  1119 	//-- Print out information about file system installed
  1115 	if(aFlags & EFSInfo)
  1120 	if(aFlags & EFSInfo)
  1116     {
  1121     {
  1117         //-- print out drive properties
  1122         //-- print out drive properties
  1118         Buf.Format(_L("\nDrive %c: No:%d"), 'A'+aDrvNum, aDrvNum);
  1123         Buf.Format(_L("Drive %c: No:%d"), 'A'+aDrvNum, aDrvNum);
  1119         
  1124         
  1120         //-- find out if the drive is synchronous / asynchronous
  1125         //-- find out if the drive is synchronous / asynchronous
  1121         TPckgBuf<TBool> drvSyncBuf;
  1126         TPckgBuf<TBool> drvSyncBuf;
  1122         nRes = aFs.QueryVolumeInfoExt(aDrvNum, EIsDriveSync, drvSyncBuf);
  1127         nRes = aFs.QueryVolumeInfoExt(aDrvNum, EIsDriveSync, drvSyncBuf);
  1123         if(nRes == KErrNone)
  1128         if(nRes == KErrNone)
  1124         {
  1129         {
  1125             Buf.AppendFormat(_L(", Sync:%d"), drvSyncBuf() ? 1:0);        
  1130             Buf.AppendFormat(_L(" Sync:%d"), drvSyncBuf() ? 1:0);        
  1126         }
  1131         }
  1127 
  1132 
  1128         //-- find out if drive runs a rugged FS (debug mode only)
  1133         //-- find out if drive runs a rugged FS (debug mode only)
  1129         const TInt KControlIoIsRugged=4;
  1134         const TInt KControlIoIsRugged=4;
  1130         TUint8 ruggedFS;
  1135         TUint8 ruggedFS;
  1131         TPtr8 pRugged(&ruggedFS, 1, 1);
  1136         TPtr8 pRugged(&ruggedFS, 1, 1);
  1132         nRes=aFs.ControlIo(aDrvNum, KControlIoIsRugged, pRugged);
  1137         nRes=aFs.ControlIo(aDrvNum, KControlIoIsRugged, pRugged);
  1133         if(nRes == KErrNone)
  1138         if(nRes == KErrNone)
  1134         {
  1139         {
  1135             Buf.AppendFormat(_L(", Rugged:%d"), ruggedFS ? 1:0);        
  1140             Buf.AppendFormat(_L(" Rugged:%d"), ruggedFS ? 1:0);        
  1136         }
  1141         }
  1137 
  1142 
  1138         Buf.Append(_L("\n"));
  1143         CShell::Printf(KNl);
  1139         apConsole->Printf(Buf);
  1144         Buf.Append(KNl);
  1140 
  1145         CShell::Printf(Buf);
  1141 
  1146 
  1142 	    //-- print the FS name
  1147 	    //-- print the FS name
  1143 	    if(aFs.FileSystemName(Buf, aDrvNum) == KErrNone)
  1148 	    if(aFs.FileSystemName(Buf, aDrvNum) == KErrNone)
  1144 	    {
  1149 	    {
  1145 	        TFSName fsName;
  1150 	        TFSName fsName;
  1155             if(nRes == KErrNone)
  1160             if(nRes == KErrNone)
  1156             {   
  1161             {   
  1157                  Buf.AppendFormat(_L(" PExt:%S"), &fsName);
  1162                  Buf.AppendFormat(_L(" PExt:%S"), &fsName);
  1158             }
  1163             }
  1159 
  1164 
  1160 
  1165             CShell::Printf(_L("Mounted FS:%S\n"), &Buf);
  1161             apConsole->Printf(_L("Mounted FS:%S\n"), &Buf);
       
  1162 
  1166 
  1163             //-- print out the list of supported file systems if there are more than 1
  1167             //-- print out the list of supported file systems if there are more than 1
  1164             nRes = aFs.SupportedFileSystemName(fsName, aDrvNum, 0+1); //-- try to get 2nd child name
  1168             nRes = aFs.SupportedFileSystemName(fsName, aDrvNum, 0+1); //-- try to get 2nd child name
  1165             if(nRes == KErrNone)
  1169             if(nRes == KErrNone)
  1166             {
  1170             {
  1172                         break;
  1176                         break;
  1173 
  1177 
  1174                     Buf.AppendFormat(_L("%S, "), &fsName);
  1178                     Buf.AppendFormat(_L("%S, "), &fsName);
  1175                 }
  1179                 }
  1176             
  1180             
  1177                 Buf.Append(_L("\n"));
  1181                 Buf.Append(KNl);
  1178                 apConsole->Printf(Buf);
  1182                 CShell::Printf(Buf);
  1179             }
  1183             }
  1180 
  1184 
  1181 
  1185 
  1182 
  1186 
  1183             
  1187             
  1201                 nRes = aFs.VolumeIOParam(aDrvNum, volIoInfo);
  1205                 nRes = aFs.VolumeIOParam(aDrvNum, volIoInfo);
  1202                 if(nRes == KErrNone)
  1206                 if(nRes == KErrNone)
  1203                 {
  1207                 {
  1204                     if(volIoInfo.iBlockSize >= 0)
  1208                     if(volIoInfo.iBlockSize >= 0)
  1205                     {
  1209                     {
  1206                         Buf.AppendFormat(_L(", BlkSz:%d"), volIoInfo.iBlockSize);
  1210                         Buf.AppendFormat(_L("BlkSz:%d "), volIoInfo.iBlockSize);
  1207                     }
  1211                     }
  1208                     
  1212                     
  1209                     if(volIoInfo.iClusterSize >= 0)
  1213                     if(volIoInfo.iClusterSize >= 0)
  1210                     {
  1214                     {
  1211                         Buf.AppendFormat(_L(", ClSz:%d"), volIoInfo.iClusterSize);
  1215                         Buf.AppendFormat(_L("ClSz:%d "), volIoInfo.iClusterSize);
  1212                     }
  1216                     }
  1213 
  1217 
  1214                     Buf.AppendFormat(_L(", CacheFlags:0x%x"), volInfo.iFileCacheFlags);
  1218                     Buf.AppendFormat(_L("CacheFlags:0x%x "), volInfo.iFileCacheFlags);
  1215                 
  1219                 
  1216                 }
  1220                 }
  1217 
  1221 
  1218 
  1222 
  1219                 if(Buf.Length())
  1223                 if(Buf.Length())
  1220                 {
  1224                 {
  1221                     Buf.Append(_L("\n"));
  1225                     Buf.Append(KNl);
  1222                     apConsole->Printf(Buf);    
  1226                     CShell::Printf(Buf);
  1223                 }
  1227                 }
  1224 
  1228 
  1225             }
  1229             }
  1226 	    }
  1230 	    }
  1227     }//if(aFlags & EFSInfo)
  1231     }//if(aFlags & EFSInfo)
  1228 
  1232 
  1229 	//-- print media attributes
  1233 	//-- print media attributes
  1230 	if(aFlags & EMediaTypeInfo)
  1234 	if(aFlags & EMediaTypeInfo)
  1231     {
  1235     {
  1232         FormatDrvMediaTypeInfo(driveInfo, Buf);
  1236         FormatDrvMediaTypeInfo(driveInfo, Buf);
  1233 	    apConsole->Printf(Buf);
  1237         CShell::Printf(Buf);
  1234 
       
  1235 	}
  1238 	}
  1236     
  1239     
  1237     //-- print drive attributes
  1240     //-- print drive attributes
  1238 	if(aFlags & EDrvAttInfo)
  1241 	if(aFlags & EDrvAttInfo)
  1239     {
  1242     {
  1240         FormatDriveAttInfo(driveInfo, Buf);
  1243         FormatDriveAttInfo(driveInfo, Buf);
  1241 	    apConsole->Printf(Buf);
  1244         CShell::Printf(Buf);
  1242     }
  1245     }
  1243 
  1246 
  1244     //-- print media attributes
  1247     //-- print media attributes
  1245 	if(aFlags & EMediaAttInfo)
  1248 	if(aFlags & EMediaAttInfo)
  1246     {
  1249     {
  1247 	    FormatMediaAttInfo(driveInfo, Buf);
  1250 	    FormatMediaAttInfo(driveInfo, Buf);
  1248 	    apConsole->Printf(Buf);
  1251         CShell::Printf(Buf);
  1249     }
  1252     }
  1250 
  1253 
  1251 
  1254 
  1252 	//-- print volume information
  1255 	//-- print volume information
  1253 	if(bVolumeOK && (aFlags & EVolInfo))
  1256 	if(bVolumeOK && (aFlags & EVolInfo))
  1254     {
  1257     {
  1255 	    FormatVolInfo(volInfo, Buf);
  1258 	    FormatVolInfo(volInfo, Buf);
  1256 	    apConsole->Printf(Buf);
  1259         CShell::Printf(Buf);
  1257     }
  1260     }
  1258 	
  1261 	
  1259     return KErrNone;
  1262     return KErrNone;
  1260 	}
  1263 	}
  1261 
  1264 
  1322 	else
  1325 	else
  1323 		{//-- print info about specified drive
  1326 		{//-- print info about specified drive
  1324 		nDrv = DoExtractDriveLetter(aArgs);
  1327 		nDrv = DoExtractDriveLetter(aArgs);
  1325         if(nDrv < 0)
  1328         if(nDrv < 0)
  1326             {
  1329             {
  1327             CShell::TheConsole->Printf(_L("Invalid drive specifier!\n"));    
  1330             CShell::Printf(_L("Invalid drive specification\n"));    
  1328             return KErrNone;
  1331             return KErrNone;
  1329             }
  1332             }
  1330 		}
  1333 		}
  1331 
  1334 
  1332 	TInt nRes;
  1335 	TInt nRes;
  1334 
  1337 
  1335 	//-- get drives list
  1338 	//-- get drives list
  1336 	nRes=TheShell->TheFs.DriveList(driveList);
  1339 	nRes=TheShell->TheFs.DriveList(driveList);
  1337 	if(nRes != KErrNone)
  1340 	if(nRes != KErrNone)
  1338 		{
  1341 		{
  1339 		CShell::TheConsole->Printf(_L("\nError: %d"), nRes);
  1342         CShell::Printf(_L("\nError: %d"), nRes);
  1340 		return nRes;
  1343 		return nRes;
  1341 		}
  1344 		}
  1342 
  1345 
  1343 	if(nDrv >=0)
  1346 	if(nDrv >=0)
  1344 		{//-- the drive is specified
  1347 		{//-- the drive is specified
  1345 		if(!driveList[nDrv])
  1348 		if(!driveList[nDrv])
  1346 			{
  1349 			{
  1347 			CShell::TheConsole->Printf(_L("Invalid drive specification\n"));
  1350             CShell::Printf(_L("Invalid drive specification\n"));
  1348 			return KErrNone;
  1351 			return KErrNone;
  1349 			}
  1352 			}
  1350 
  1353 
  1351 		PrintDrvInfo(TheShell->TheFs, nDrv, CShell::TheConsole);
  1354 		PrintDrvInfo(TheShell->TheFs, nDrv);
  1352 		}
  1355 		}
  1353 	else
  1356 	else
  1354 		{//-- print information about all drives in the system
  1357 		{//-- print information about all drives in the system
  1355 		for (nDrv=0; nDrv < KMaxDrives; nDrv++)
  1358 		for (nDrv=0; nDrv < KMaxDrives; nDrv++)
  1356 			{
  1359 			{
  1357 			if(!driveList[nDrv])
  1360 			if(!driveList[nDrv])
  1358 				continue;   //-- skip unexisting drive
  1361 				continue;   //-- skip unexisting drive
  1359 
  1362 
  1360 			PrintDrvInfo(TheShell->TheFs, nDrv, CShell::TheConsole);
  1363 			PrintDrvInfo(TheShell->TheFs, nDrv);
  1361 
  1364 
  1362 			if(aSwitches & TShellCommand::EPSwitch)
  1365 			if(aSwitches & TShellCommand::EPSwitch)
  1363 				{//-- /p switch, pause after each drive
  1366 				{//-- /p switch, pause after each drive
  1364 				CShell::TheConsole->Printf(_L("\n--- press any key to continue or Esc to exit ---\n"));
  1367                 CShell::Printf(_L("\n--- press any key to continue or Esc to exit ---\n"));
  1365 
  1368 
  1366 				TKeyCode key = CShell::TheConsole->Getch();
  1369 				TKeyCode key = CShell::TheConsole->Getch();
  1367 				if (key==EKeyEscape)
  1370 				if (key==EKeyEscape)
  1368 					break;
  1371 					break;
  1369 				}
  1372 				}
  1370 			else
  1373 			else
  1371 				{
  1374 				{
  1372 				CShell::TheConsole->Printf(_L("\n----------\n"));
  1375 				CShell::Printf(_L("\n----------\n"));
       
  1376                 CShell::Printf(_L("\n--- press any key to continue or Esc to exit ---\n"));
       
  1377 
  1373 				}
  1378 				}
  1374 		}
  1379 		}
  1375 	}
  1380 	}
  1376 
  1381 
  1377 	return KErrNone;
  1382 	return KErrNone;
  1416 
  1421 
  1417 
  1422 
  1418 
  1423 
  1419 
  1424 
  1420 //-----------------------------------------------------------------------------------------------------------------------
  1425 //-----------------------------------------------------------------------------------------------------------------------
  1421 TInt DoDismountFS(RFs& aFs, TInt aDrvNum)
  1426 TInt DoDismountFS(RFs& aFs, TInt aDrvNum, TBool aForceDismount)
  1422 {
  1427 {
  1423     TInt        nRes;
  1428     TInt        nRes;
  1424     TBuf<40>    fsName;
  1429     TBuf<40>    fsName;
  1425 
  1430 
  1426     nRes = aFs.FileSystemName(fsName, aDrvNum);
  1431     nRes = aFs.FileSystemName(fsName, aDrvNum);
  1427 
  1432 
  1428     if(nRes != KErrNone)
  1433     if(nRes != KErrNone)
  1429         return KErrNotFound;//-- nothing to dismount
  1434         return KErrNotFound;//-- nothing to dismount
  1430         
  1435         
       
  1436     if(!aForceDismount)    
       
  1437     {//-- gaceful attempt to dismount the FS
  1431     nRes = aFs.DismountFileSystem(fsName, aDrvNum);
  1438     nRes = aFs.DismountFileSystem(fsName, aDrvNum);
  1432     if(nRes != KErrNone)
  1439     if(nRes != KErrNone)
  1433     {
  1440     {
  1434         CShell::TheConsole->Printf(_L("Can't dismount FS!\n"));
  1441         CShell::TheConsole->Printf(_L("Can't dismount FS!\n"));
  1435         return nRes;
  1442         return nRes;
  1436     }
  1443     }
  1437     else
  1444     else
  1438     {
  1445     {
  1439     CShell::TheConsole->Printf(_L("'%S' filesystem dismounted from drive %c:\n"), &fsName, 'A'+aDrvNum);
  1446     CShell::TheConsole->Printf(_L("'%S' filesystem dismounted from drive %c:\n"), &fsName, 'A'+aDrvNum);
  1440     return KErrNone;
  1447     return KErrNone;
       
  1448     }
       
  1449 }
       
  1450     else
       
  1451     {//-- dismount by force
       
  1452         TRequestStatus rqStat;
       
  1453         aFs.NotifyDismount(aDrvNum, rqStat, EFsDismountForceDismount);  
       
  1454         User::WaitForRequest(rqStat);
       
  1455         
       
  1456         CShell::TheConsole->Printf(_L("'%S' filesystem Forcedly dismounted from drive %c:\n"), &fsName, 'A'+aDrvNum);
       
  1457 
       
  1458         return rqStat.Int(); 
  1441     }
  1459     }
  1442 }
  1460 }
  1443 
  1461 
  1444 //-----------------------------------------------------------------------------------------------------------------------
  1462 //-----------------------------------------------------------------------------------------------------------------------
  1445 TInt DoRemountFS(RFs& aFs, TInt aDrvNum)
  1463 TInt DoRemountFS(RFs& aFs, TInt aDrvNum)
  1481             return KErrNotSupported;
  1499             return KErrNotSupported;
  1482         }
  1500         }
  1483     }
  1501     }
  1484 
  1502 
  1485     //-- 4. dismount the file system
  1503     //-- 4. dismount the file system
  1486     nRes = DoDismountFS(aFs, aDrvNum);
  1504     nRes = DoDismountFS(aFs, aDrvNum, EFalse);
  1487     if(nRes != KErrNone)
  1505     if(nRes != KErrNone)
  1488         return nRes;
  1506         return nRes;
  1489 
  1507 
  1490     //-- 5. mount the FS back
  1508     //-- 5. mount the FS back
  1491     if(pextName.Length() > 0)
  1509     if(pextName.Length() > 0)
  1513 
  1531 
  1514 //-----------------------------------------------------------------------------------------------------------------------
  1532 //-----------------------------------------------------------------------------------------------------------------------
  1515 /**
  1533 /**
  1516     Mount or dismount the file system on the specified drive.
  1534     Mount or dismount the file system on the specified drive.
  1517 
  1535 
  1518     MOUNT <DriveLetter:[\]> <FSY:xxx> <FS:yyy> [PEXT:zzz] [/S] [/U]
  1536     MOUNT <DriveLetter:[\]> <FSY:xxx> <FS:yyy> [PEXT:zzz] [/S] [/U] [/F]
  1519   
  1537   
  1520     xxx is the *.fsy file system plugin name, like "elocal.fsy" or "elocal"
  1538     xxx is the *.fsy file system plugin name, like "elocal.fsy" or "elocal"
  1521     yyy is the file system name that the fsy module exports, like "FAT"
  1539     yyy is the file system name that the fsy module exports, like "FAT"
  1522     zzz is the optional parameter that specifies primary extension name
  1540     zzz is the optional parameter that specifies primary extension name
  1523 
  1541 
  1524     /u dismounts a filesystem on the specified drive; e.g. "mount d: /u"
  1542     /u dismounts a filesystem on the specified drive; e.g. "mount d: /u"
  1525     /s for mounting FS specifies that the drive will be mounted as synchronous one.
  1543         additional switch /f in conjunction with /u will perform "forced unmounting" i.e. unmounting the FS 
  1526     /f for forcing mounting the FS; the previous one will be automatically dismounted
  1544         even it has opened files and / or directories. E.g. "mount d: /u /f"
  1527     /r remount existing FS (dismount and mount it back)
  1545 
       
  1546     
       
  1547     /s for mounting FS specifies that the drive will be mounted as a synchronous one.
       
  1548         
       
  1549 
       
  1550     /f for forcing mounting the FS; the previous one will be automatically dismounted. 
       
  1551         example: "mount d: /f fsy:exfat fs:exfat" this command will dismount whatever FS ic currently mounted and 
       
  1552         mount exFAT FS instead
       
  1553 
       
  1554 
       
  1555     
       
  1556     /r remount existing FS (dismount and mount it back); example: "mount d: /r"
  1528 */
  1557 */
  1529 TInt ShellFunction::MountFileSystem(TDes& aArgs, TUint aSwitches)
  1558 TInt ShellFunction::MountFileSystem(TDes& aArgs, TUint aSwitches)
  1530 {
  1559 {
  1531 	ShellFunction::StripQuotes(aArgs);
  1560 	ShellFunction::StripQuotes(aArgs);
  1532     aArgs.UpperCase();
  1561     aArgs.UpperCase();
  1557     {
  1586     {
  1558         nRes = DoRemountFS(fs, drvNum);
  1587         nRes = DoRemountFS(fs, drvNum);
  1559         return nRes;
  1588         return nRes;
  1560     }
  1589     }
  1561     
  1590     
  1562     //-- check if we dismounting the FS (/U switch)
  1591     //-- check if we dismounting the FS (/U switch).
  1563     if(aSwitches & TShellCommand::EUSwitch)
  1592     if(aSwitches & TShellCommand::EUSwitch)
  1564     {
  1593     {//-- also take nto account "/f" switch for forced dismounting
  1565         nRes = DoDismountFS(fs, drvNum);
  1594         nRes = DoDismountFS(fs, drvNum, (aSwitches & TShellCommand::EFSwitch));
  1566         
  1595         
  1567         if(nRes == KErrNotFound)
  1596         if(nRes == KErrNotFound)
  1568         {//-- nothing to dismount
  1597         {//-- nothing to dismount
  1569             CShell::TheConsole->Printf(_L("specified drive doesn't have FS mounted\n"));
  1598             CShell::TheConsole->Printf(_L("specified drive doesn't have FS mounted\n"));
  1570             return KErrNone;
  1599             return KErrNone;
  1574     }
  1603     }
  1575     
  1604     
  1576     //-- check if we need to forcedly dismount the existing FS (/F switch)
  1605     //-- check if we need to forcedly dismount the existing FS (/F switch)
  1577     if(aSwitches & TShellCommand::EFSwitch)
  1606     if(aSwitches & TShellCommand::EFSwitch)
  1578     {
  1607     {
  1579         nRes = DoDismountFS(fs, drvNum);
  1608         nRes = DoDismountFS(fs, drvNum, EFalse);
  1580         
  1609         
  1581         if(nRes != KErrNotFound && nRes !=KErrNone)
  1610         if(nRes != KErrNotFound && nRes !=KErrNone)
  1582             return nRes;
  1611             return nRes;
  1583     }
  1612     }
  1584 
  1613 
  1660         CShell::TheConsole->Printf(_L("Error mounting the filesystem! (%d)\n"), nRes);
  1689         CShell::TheConsole->Printf(_L("Error mounting the filesystem! (%d)\n"), nRes);
  1661         return nRes;
  1690         return nRes;
  1662     }
  1691     }
  1663 
  1692 
  1664 
  1693 
  1665     PrintDrvInfo(fs, drvNum, CShell::TheConsole, EFSInfo | EVolInfo);
  1694     PrintDrvInfo(fs, drvNum, EFSInfo | EVolInfo);
  1666 
  1695 
  1667     return KErrNone;
  1696     return KErrNone;
  1668 }
  1697 }
  1669 
  1698 
  1670 
  1699 
  3602 			}
  3631 			}
  3603 		}
  3632 		}
  3604 	return err;
  3633 	return err;
  3605 	}
  3634 	}
  3606 
  3635 
  3607 _LIT(KCrNl, "\r\n");
  3636 
       
  3637 
       
  3638 //----------------------------------------------------------------------
       
  3639 void CShell::Printf(TRefByValue<const TDesC16> aFmt, ...)
       
  3640 {
       
  3641 	TBuf<256> buf;
       
  3642 	VA_LIST list;					
       
  3643 	VA_START(list, aFmt);
       
  3644 	// coverity[uninit_use_in_call]
       
  3645 	buf.FormatList(aFmt, list);			
       
  3646 
       
  3647     if(!buf.Length())
       
  3648         return;
       
  3649 
       
  3650     TheConsole->Printf(buf);
       
  3651 
       
  3652     if(iDbgPrint)
       
  3653     {
       
  3654         const TInt bufLen = buf.Length();
       
  3655         if(buf[bufLen-1] == '\n')
       
  3656         {
       
  3657             buf.Insert(bufLen-1, _L("\r"));
       
  3658         }
       
  3659     
       
  3660         RDebug::RawPrint(buf);
       
  3661     }
       
  3662 
       
  3663 }
  3608 
  3664 
  3609 void SIPrintf(TRefByValue<const TDesC16> aFmt, ...)
  3665 void SIPrintf(TRefByValue<const TDesC16> aFmt, ...)
  3610 	{
  3666 	{
  3611 	TBuf<256> buf;
  3667 	TBuf<256> buf;
  3612 	VA_LIST list;					
  3668 	VA_LIST list;					
  3777 
  3833 
  3778 
  3834 
  3779 //-------------------------------------------------------------------------
  3835 //-------------------------------------------------------------------------
  3780 /**
  3836 /**
  3781     Print out the command line to the console and standard debug port.
  3837     Print out the command line to the console and standard debug port.
       
  3838 
       
  3839     echo [some text] [/y] [/n]
       
  3840 
       
  3841 		/Y : switches ON copying console output to the debug port
       
  3842 		/N : switches OFF copying console output to the debug port
       
  3843 
  3782 */
  3844 */
  3783 TInt ShellFunction::ConsoleEcho(TDes& aArgs, TUint /*aSwitches*/)
  3845 TInt ShellFunction::ConsoleEcho(TDes& aArgs, TUint aSwitches)
  3784 {
  3846 {
       
  3847     if(aSwitches & TShellCommand::EYSwitch)
       
  3848     {
       
  3849         CShell::SetDbgConsoleEcho(ETrue);
       
  3850     }
       
  3851     else
       
  3852     if(aSwitches & TShellCommand::ENSwitch)
       
  3853     {
       
  3854         CShell::SetDbgConsoleEcho(EFalse);
       
  3855     }
       
  3856 
       
  3857     if(aArgs.Length())
  3785     SIPrintf(aArgs);
  3858     SIPrintf(aArgs);
       
  3859     
  3786     return KErrNone;
  3860     return KErrNone;
  3787 }
  3861 }
       
  3862 
       
  3863