userlibandfileserver/fileserver/etshell/ts_com.cpp
branchGCC_SURGE
changeset 221 39b39e1a406e
parent 201 43365a9b78a3
child 189 a5496987b1da
equal deleted inserted replaced
219:0ff03867bdb6 221:39b39e1a406e
     1 // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 1996-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    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 
   254     		aPath.Insert(0,TheShell->currentPath);
   258     		aPath.Insert(0,TheShell->currentPath);
   255 		else
   259 		else
   256 			aPath.Insert(0,TheShell->currentPath.Left(2));
   260 			aPath.Insert(0,TheShell->currentPath.Left(2));
   257 		}
   261 		}
   258 
   262 
   259 	RFile file;
   263 	RFile64 file;
   260 	r=file.Open(CShell::TheFs,aPath,EFileStream);
   264 	r=file.Open(CShell::TheFs,aPath,EFileStream);
   261 	if (r!=KErrNone)	//		File could not be opened
   265 	if (r!=KErrNone)	//		File could not be opened
   262 		{
   266 		{
   263 		if (appendedExe)	//	If .EXE was appended earlier
   267 		if (appendedExe)	//	If .EXE was appended earlier
   264 			{
   268 			{
   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;
   976         case EMediaRotatingMedia:   aPrintBuf.Append(_L("EMediaRotatingMedia"));break;
   981         case EMediaRotatingMedia:   aPrintBuf.Append(_L("EMediaRotatingMedia"));break;
   977         
   982         
   978         default:                    aPrintBuf.Append(_L("??? Unknown Type"));   break;
   983         default:                    aPrintBuf.Append(_L("??? Unknown Type"));   break;
   979         };
   984         };
   980 
   985 
   981 
   986         if (aDrvInfo.iConnectionBusType)
       
   987             {
       
   988             aPrintBuf.Append(_L(" USB"));
       
   989             }
       
   990         
   982         aPrintBuf.Append(_L("\n"));
   991         aPrintBuf.Append(_L("\n"));
   983     }
   992     }
   984 
   993 
   985 //--------------------------------------------------------
   994 //--------------------------------------------------------
   986 
   995 
  1047     @param  volInfo     volume information
  1056     @param  volInfo     volume information
  1048     @param  aPrintBuf   buffer where the information will be printed to.
  1057     @param  aPrintBuf   buffer where the information will be printed to.
  1049 */
  1058 */
  1050 void FormatVolInfo(const TVolumeInfo& volInfo , TDes& aPrintBuf)
  1059 void FormatVolInfo(const TVolumeInfo& volInfo , TDes& aPrintBuf)
  1051     {
  1060     {
  1052    	aPrintBuf.Format(_L("VolSz:%ld Free:%ld\n"),volInfo.iSize, volInfo.iFree);
  1061    	aPrintBuf.Format(_L("VolSz:%ld Free:%ld"),volInfo.iSize, volInfo.iFree);
  1053    	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);
  1054     }
  1063     }
  1055 
  1064 
  1056 //--------------------------------------------------------
  1065 //--------------------------------------------------------
  1057 
  1066 
  1058 /** Bit flags that specify which information will be printed by PrintDrvInfo() */
  1067 /** Bit flags that specify which information will be printed by PrintDrvInfo() */
  1077     @param  apConsole   pointer to the console to print information into
  1086     @param  apConsole   pointer to the console to print information into
  1078     @param  aFlags      specifies which information to print out, @see TPrintDrvInfoFlags
  1087     @param  aFlags      specifies which information to print out, @see TPrintDrvInfoFlags
  1079 
  1088 
  1080     @return standard error code
  1089     @return standard error code
  1081 */
  1090 */
  1082 TInt PrintDrvInfo(RFs& aFs, TInt aDrvNum, CConsoleBase* apConsole, TUint aFlags = EAll)
  1091 TInt PrintDrvInfo(RFs& aFs, TInt aDrvNum, TUint aFlags = EAll)
  1083     {
  1092     {
  1084 	TInt        nRes;
  1093 	TInt        nRes;
  1085 	TDriveInfo 	driveInfo;
  1094 	TDriveInfo 	driveInfo;
  1086 	TVolumeInfo volInfo;
  1095 	TVolumeInfo volInfo;
  1087 	TBuf<256>   Buf;
  1096 	TBuf<256>   Buf;
  1088 
  1097 
  1089 	//-- get drive info
  1098 	//-- get drive info
  1090 	nRes = aFs.Drive(driveInfo, aDrvNum);
  1099 	nRes = aFs.Drive(driveInfo, aDrvNum);
  1091 	if(nRes != KErrNone)
  1100 	if(nRes != KErrNone)
  1092 		{
  1101 		{
  1093 		CShell::TheConsole->Printf(_L("Error: %d\n"), nRes);
  1102         CShell::Printf(_L("Error: %d\n"), nRes);
  1094 		return nRes;   //-- can't get information about the drive
  1103 		return nRes;   //-- can't get information about the drive
  1095 		}
  1104 		}
  1096 
  1105 
  1097 	
  1106 	
  1098     nRes = aFs.Volume(volInfo, aDrvNum);
  1107     nRes = aFs.Volume(volInfo, aDrvNum);
  1099     const TBool bVolumeOK  = (nRes == KErrNone);
  1108     const TBool bVolumeOK  = (nRes == KErrNone);
  1100 	if(!bVolumeOK)
  1109 	if(!bVolumeOK)
  1101 	{//-- 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
  1102 		CShell::TheConsole->Printf(_L("Error getting volume info. code: %d\n"), nRes);
  1111         CShell::Printf(_L("Error getting volume info. code: %d\n"), nRes);
  1103         if(nRes == KErrCorrupt)
  1112         if(nRes == KErrCorrupt)
  1104         {
  1113         {
  1105             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"));
  1106         }
  1115         }
  1107 	}
  1116 	}
  1108 
  1117 
  1109 
  1118 
  1110 	//-- Print out information about file system installed
  1119 	//-- Print out information about file system installed
  1111 	if(aFlags & EFSInfo)
  1120 	if(aFlags & EFSInfo)
  1112     {
  1121     {
  1113         //-- print out drive properties
  1122         //-- print out drive properties
  1114         Buf.Format(_L("\nDrive %c: No:%d"), 'A'+aDrvNum, aDrvNum);
  1123         Buf.Format(_L("Drive %c: No:%d"), 'A'+aDrvNum, aDrvNum);
  1115         
  1124         
  1116         //-- find out if the drive is synchronous / asynchronous
  1125         //-- find out if the drive is synchronous / asynchronous
  1117         TPckgBuf<TBool> drvSyncBuf;
  1126         TPckgBuf<TBool> drvSyncBuf;
  1118         nRes = aFs.QueryVolumeInfoExt(aDrvNum, EIsDriveSync, drvSyncBuf);
  1127         nRes = aFs.QueryVolumeInfoExt(aDrvNum, EIsDriveSync, drvSyncBuf);
  1119         if(nRes == KErrNone)
  1128         if(nRes == KErrNone)
  1120         {
  1129         {
  1121             Buf.AppendFormat(_L(", Sync:%d"), drvSyncBuf() ? 1:0);        
  1130             Buf.AppendFormat(_L(" Sync:%d"), drvSyncBuf() ? 1:0);        
  1122         }
  1131         }
  1123 
  1132 
  1124         //-- find out if drive runs a rugged FS (debug mode only)
  1133         //-- find out if drive runs a rugged FS (debug mode only)
  1125         const TInt KControlIoIsRugged=4;
  1134         const TInt KControlIoIsRugged=4;
  1126         TUint8 ruggedFS;
  1135         TUint8 ruggedFS;
  1127         TPtr8 pRugged(&ruggedFS, 1, 1);
  1136         TPtr8 pRugged(&ruggedFS, 1, 1);
  1128         nRes=aFs.ControlIo(aDrvNum, KControlIoIsRugged, pRugged);
  1137         nRes=aFs.ControlIo(aDrvNum, KControlIoIsRugged, pRugged);
  1129         if(nRes == KErrNone)
  1138         if(nRes == KErrNone)
  1130         {
  1139         {
  1131             Buf.AppendFormat(_L(", Rugged:%d"), ruggedFS ? 1:0);        
  1140             Buf.AppendFormat(_L(" Rugged:%d"), ruggedFS ? 1:0);        
  1132         }
  1141         }
  1133 
  1142 
  1134         Buf.Append(_L("\n"));
  1143         CShell::Printf(KNl);
  1135         apConsole->Printf(Buf);
  1144         Buf.Append(KNl);
  1136 
  1145         CShell::Printf(Buf);
  1137 
  1146 
  1138 	    //-- print the FS name
  1147 	    //-- print the FS name
  1139 	    if(aFs.FileSystemName(Buf, aDrvNum) == KErrNone)
  1148 	    if(aFs.FileSystemName(Buf, aDrvNum) == KErrNone)
  1140 	    {
  1149 	    {
  1141 	        TFSName fsName;
  1150 	        TFSName fsName;
  1151             if(nRes == KErrNone)
  1160             if(nRes == KErrNone)
  1152             {   
  1161             {   
  1153                  Buf.AppendFormat(_L(" PExt:%S"), &fsName);
  1162                  Buf.AppendFormat(_L(" PExt:%S"), &fsName);
  1154             }
  1163             }
  1155 
  1164 
  1156 
  1165             CShell::Printf(_L("Mounted FS:%S\n"), &Buf);
  1157             apConsole->Printf(_L("Mounted FS:%S\n"), &Buf);
       
  1158 
  1166 
  1159             //-- 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
  1160             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
  1161             if(nRes == KErrNone)
  1169             if(nRes == KErrNone)
  1162             {
  1170             {
  1168                         break;
  1176                         break;
  1169 
  1177 
  1170                     Buf.AppendFormat(_L("%S, "), &fsName);
  1178                     Buf.AppendFormat(_L("%S, "), &fsName);
  1171                 }
  1179                 }
  1172             
  1180             
  1173                 Buf.Append(_L("\n"));
  1181                 Buf.Append(KNl);
  1174                 apConsole->Printf(Buf);
  1182                 CShell::Printf(Buf);
  1175             }
  1183             }
  1176 
  1184 
  1177 
  1185 
  1178 
  1186 
  1179             
  1187             
  1193                 }
  1201                 }
  1194 
  1202 
  1195                 //-- print out cluster size that FS reported
  1203                 //-- print out cluster size that FS reported
  1196                 TVolumeIOParamInfo volIoInfo;
  1204                 TVolumeIOParamInfo volIoInfo;
  1197                 nRes = aFs.VolumeIOParam(aDrvNum, volIoInfo);
  1205                 nRes = aFs.VolumeIOParam(aDrvNum, volIoInfo);
  1198                 if(nRes == KErrNone && volIoInfo.iClusterSize >= 512)
  1206                 if(nRes == KErrNone)
  1199                 {
  1207                 {
  1200                     Buf.AppendFormat(_L(", Cluster Sz:%d"), volIoInfo.iClusterSize);
  1208                     if(volIoInfo.iBlockSize >= 0)
       
  1209                     {
       
  1210                         Buf.AppendFormat(_L("BlkSz:%d "), volIoInfo.iBlockSize);
       
  1211                     }
       
  1212                     
       
  1213                     if(volIoInfo.iClusterSize >= 0)
       
  1214                     {
       
  1215                         Buf.AppendFormat(_L("ClSz:%d "), volIoInfo.iClusterSize);
       
  1216                     }
       
  1217 
       
  1218                     Buf.AppendFormat(_L("CacheFlags:0x%x "), volInfo.iFileCacheFlags);
       
  1219                 
  1201                 }
  1220                 }
       
  1221 
  1202 
  1222 
  1203                 if(Buf.Length())
  1223                 if(Buf.Length())
  1204                 {
  1224                 {
  1205                     Buf.Append(_L("\n"));
  1225                     Buf.Append(KNl);
  1206                     apConsole->Printf(Buf);    
  1226                     CShell::Printf(Buf);
  1207                 }
  1227                 }
  1208 
  1228 
  1209             }
  1229             }
  1210 	    }
  1230 	    }
  1211     }//if(aFlags & EFSInfo)
  1231     }//if(aFlags & EFSInfo)
  1212 
  1232 
  1213 	//-- print media attributes
  1233 	//-- print media attributes
  1214 	if(aFlags & EMediaTypeInfo)
  1234 	if(aFlags & EMediaTypeInfo)
  1215     {
  1235     {
  1216         FormatDrvMediaTypeInfo(driveInfo, Buf);
  1236         FormatDrvMediaTypeInfo(driveInfo, Buf);
  1217 	    apConsole->Printf(Buf);
  1237         CShell::Printf(Buf);
  1218 
       
  1219 	}
  1238 	}
  1220     
  1239     
  1221     //-- print drive attributes
  1240     //-- print drive attributes
  1222 	if(aFlags & EDrvAttInfo)
  1241 	if(aFlags & EDrvAttInfo)
  1223     {
  1242     {
  1224         FormatDriveAttInfo(driveInfo, Buf);
  1243         FormatDriveAttInfo(driveInfo, Buf);
  1225 	    apConsole->Printf(Buf);
  1244         CShell::Printf(Buf);
  1226     }
  1245     }
  1227 
  1246 
  1228     //-- print media attributes
  1247     //-- print media attributes
  1229 	if(aFlags & EMediaAttInfo)
  1248 	if(aFlags & EMediaAttInfo)
  1230     {
  1249     {
  1231 	    FormatMediaAttInfo(driveInfo, Buf);
  1250 	    FormatMediaAttInfo(driveInfo, Buf);
  1232 	    apConsole->Printf(Buf);
  1251         CShell::Printf(Buf);
  1233     }
  1252     }
  1234 
  1253 
  1235 
  1254 
  1236 	//-- print volume information
  1255 	//-- print volume information
  1237 	if(bVolumeOK && (aFlags & EVolInfo))
  1256 	if(bVolumeOK && (aFlags & EVolInfo))
  1238     {
  1257     {
  1239 	    FormatVolInfo(volInfo, Buf);
  1258 	    FormatVolInfo(volInfo, Buf);
  1240 	    apConsole->Printf(Buf);
  1259         CShell::Printf(Buf);
  1241     }
  1260     }
  1242 	
  1261 	
  1243     return KErrNone;
  1262     return KErrNone;
  1244 	}
  1263 	}
  1245 
  1264 
  1306 	else
  1325 	else
  1307 		{//-- print info about specified drive
  1326 		{//-- print info about specified drive
  1308 		nDrv = DoExtractDriveLetter(aArgs);
  1327 		nDrv = DoExtractDriveLetter(aArgs);
  1309         if(nDrv < 0)
  1328         if(nDrv < 0)
  1310             {
  1329             {
  1311             CShell::TheConsole->Printf(_L("Invalid drive specifier!\n"));    
  1330             CShell::Printf(_L("Invalid drive specification\n"));    
  1312             return KErrNone;
  1331             return KErrNone;
  1313             }
  1332             }
  1314 		}
  1333 		}
  1315 
  1334 
  1316 	TInt nRes;
  1335 	TInt nRes;
  1318 
  1337 
  1319 	//-- get drives list
  1338 	//-- get drives list
  1320 	nRes=TheShell->TheFs.DriveList(driveList);
  1339 	nRes=TheShell->TheFs.DriveList(driveList);
  1321 	if(nRes != KErrNone)
  1340 	if(nRes != KErrNone)
  1322 		{
  1341 		{
  1323 		CShell::TheConsole->Printf(_L("\nError: %d"), nRes);
  1342         CShell::Printf(_L("\nError: %d"), nRes);
  1324 		return nRes;
  1343 		return nRes;
  1325 		}
  1344 		}
  1326 
  1345 
  1327 	if(nDrv >=0)
  1346 	if(nDrv >=0)
  1328 		{//-- the drive is specified
  1347 		{//-- the drive is specified
  1329 		if(!driveList[nDrv])
  1348 		if(!driveList[nDrv])
  1330 			{
  1349 			{
  1331 			CShell::TheConsole->Printf(_L("Invalid drive specification\n"));
  1350             CShell::Printf(_L("Invalid drive specification\n"));
  1332 			return KErrNone;
  1351 			return KErrNone;
  1333 			}
  1352 			}
  1334 
  1353 
  1335 		PrintDrvInfo(TheShell->TheFs, nDrv, CShell::TheConsole);
  1354 		PrintDrvInfo(TheShell->TheFs, nDrv);
  1336 		}
  1355 		}
  1337 	else
  1356 	else
  1338 		{//-- print information about all drives in the system
  1357 		{//-- print information about all drives in the system
  1339 		for (nDrv=0; nDrv < KMaxDrives; nDrv++)
  1358 		for (nDrv=0; nDrv < KMaxDrives; nDrv++)
  1340 			{
  1359 			{
  1341 			if(!driveList[nDrv])
  1360 			if(!driveList[nDrv])
  1342 				continue;   //-- skip unexisting drive
  1361 				continue;   //-- skip unexisting drive
  1343 
  1362 
  1344 			PrintDrvInfo(TheShell->TheFs, nDrv, CShell::TheConsole);
  1363 			PrintDrvInfo(TheShell->TheFs, nDrv);
  1345 
  1364 
  1346 			if(aSwitches & TShellCommand::EPSwitch)
  1365 			if(aSwitches & TShellCommand::EPSwitch)
  1347 				{//-- /p switch, pause after each drive
  1366 				{//-- /p switch, pause after each drive
  1348 				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"));
  1349 
  1368 
  1350 				TKeyCode key = CShell::TheConsole->Getch();
  1369 				TKeyCode key = CShell::TheConsole->Getch();
  1351 				if (key==EKeyEscape)
  1370 				if (key==EKeyEscape)
  1352 					break;
  1371 					break;
  1353 				}
  1372 				}
  1354 			else
  1373 			else
  1355 				{
  1374 				{
  1356 				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 
  1357 				}
  1378 				}
  1358 		}
  1379 		}
  1359 	}
  1380 	}
  1360 
  1381 
  1361 	return KErrNone;
  1382 	return KErrNone;
  1400 
  1421 
  1401 
  1422 
  1402 
  1423 
  1403 
  1424 
  1404 //-----------------------------------------------------------------------------------------------------------------------
  1425 //-----------------------------------------------------------------------------------------------------------------------
  1405 TInt DoDismountFS(RFs& aFs, TInt aDrvNum)
  1426 TInt DoDismountFS(RFs& aFs, TInt aDrvNum, TBool aForceDismount)
  1406 {
  1427 {
  1407     TInt        nRes;
  1428     TInt        nRes;
  1408     TBuf<40>    fsName;
  1429     TBuf<40>    fsName;
  1409 
  1430 
  1410     nRes = aFs.FileSystemName(fsName, aDrvNum);
  1431     nRes = aFs.FileSystemName(fsName, aDrvNum);
  1411 
  1432 
  1412     if(nRes != KErrNone)
  1433     if(nRes != KErrNone)
  1413         return KErrNotFound;//-- nothing to dismount
  1434         return KErrNotFound;//-- nothing to dismount
  1414         
  1435         
       
  1436     if(!aForceDismount)    
       
  1437     {//-- gaceful attempt to dismount the FS
  1415     nRes = aFs.DismountFileSystem(fsName, aDrvNum);
  1438     nRes = aFs.DismountFileSystem(fsName, aDrvNum);
  1416     if(nRes != KErrNone)
  1439     if(nRes != KErrNone)
  1417     {
  1440     {
  1418         CShell::TheConsole->Printf(_L("Can't dismount FS!\n"));
  1441         CShell::TheConsole->Printf(_L("Can't dismount FS!\n"));
  1419         return nRes;
  1442         return nRes;
  1420     }
  1443     }
  1421     else
  1444     else
  1422     {
  1445     {
  1423     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);
  1424     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(); 
  1425     }
  1459     }
  1426 }
  1460 }
  1427 
  1461 
  1428 //-----------------------------------------------------------------------------------------------------------------------
  1462 //-----------------------------------------------------------------------------------------------------------------------
  1429 TInt DoRemountFS(RFs& aFs, TInt aDrvNum)
  1463 TInt DoRemountFS(RFs& aFs, TInt aDrvNum)
  1465             return KErrNotSupported;
  1499             return KErrNotSupported;
  1466         }
  1500         }
  1467     }
  1501     }
  1468 
  1502 
  1469     //-- 4. dismount the file system
  1503     //-- 4. dismount the file system
  1470     nRes = DoDismountFS(aFs, aDrvNum);
  1504     nRes = DoDismountFS(aFs, aDrvNum, EFalse);
  1471     if(nRes != KErrNone)
  1505     if(nRes != KErrNone)
  1472         return nRes;
  1506         return nRes;
  1473 
  1507 
  1474     //-- 5. mount the FS back
  1508     //-- 5. mount the FS back
  1475     if(pextName.Length() > 0)
  1509     if(pextName.Length() > 0)
  1497 
  1531 
  1498 //-----------------------------------------------------------------------------------------------------------------------
  1532 //-----------------------------------------------------------------------------------------------------------------------
  1499 /**
  1533 /**
  1500     Mount or dismount the file system on the specified drive.
  1534     Mount or dismount the file system on the specified drive.
  1501 
  1535 
  1502     MOUNT <DriveLetter:[\]> <FSY:xxx> <FS:yyy> [PEXT:zzz] [/S] [/U]
  1536     MOUNT <DriveLetter:[\]> <FSY:xxx> <FS:yyy> [PEXT:zzz] [/S] [/U] [/F]
  1503   
  1537   
  1504     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"
  1505     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"
  1506     zzz is the optional parameter that specifies primary extension name
  1540     zzz is the optional parameter that specifies primary extension name
  1507 
  1541 
  1508     /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"
  1509     /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 
  1510     /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"
  1511     /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"
  1512 */
  1557 */
  1513 TInt ShellFunction::MountFileSystem(TDes& aArgs, TUint aSwitches)
  1558 TInt ShellFunction::MountFileSystem(TDes& aArgs, TUint aSwitches)
  1514 {
  1559 {
  1515 	ShellFunction::StripQuotes(aArgs);
  1560 	ShellFunction::StripQuotes(aArgs);
  1516     aArgs.UpperCase();
  1561     aArgs.UpperCase();
  1541     {
  1586     {
  1542         nRes = DoRemountFS(fs, drvNum);
  1587         nRes = DoRemountFS(fs, drvNum);
  1543         return nRes;
  1588         return nRes;
  1544     }
  1589     }
  1545     
  1590     
  1546     //-- check if we dismounting the FS (/U switch)
  1591     //-- check if we dismounting the FS (/U switch).
  1547     if(aSwitches & TShellCommand::EUSwitch)
  1592     if(aSwitches & TShellCommand::EUSwitch)
  1548     {
  1593     {//-- also take nto account "/f" switch for forced dismounting
  1549         nRes = DoDismountFS(fs, drvNum);
  1594         nRes = DoDismountFS(fs, drvNum, (aSwitches & TShellCommand::EFSwitch));
  1550         
  1595         
  1551         if(nRes == KErrNotFound)
  1596         if(nRes == KErrNotFound)
  1552         {//-- nothing to dismount
  1597         {//-- nothing to dismount
  1553             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"));
  1554             return KErrNone;
  1599             return KErrNone;
  1558     }
  1603     }
  1559     
  1604     
  1560     //-- 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)
  1561     if(aSwitches & TShellCommand::EFSwitch)
  1606     if(aSwitches & TShellCommand::EFSwitch)
  1562     {
  1607     {
  1563         nRes = DoDismountFS(fs, drvNum);
  1608         nRes = DoDismountFS(fs, drvNum, EFalse);
  1564         
  1609         
  1565         if(nRes != KErrNotFound && nRes !=KErrNone)
  1610         if(nRes != KErrNotFound && nRes !=KErrNone)
  1566             return nRes;
  1611             return nRes;
  1567     }
  1612     }
  1568 
  1613 
  1644         CShell::TheConsole->Printf(_L("Error mounting the filesystem! (%d)\n"), nRes);
  1689         CShell::TheConsole->Printf(_L("Error mounting the filesystem! (%d)\n"), nRes);
  1645         return nRes;
  1690         return nRes;
  1646     }
  1691     }
  1647 
  1692 
  1648 
  1693 
  1649     PrintDrvInfo(fs, drvNum, CShell::TheConsole, EFSInfo | EVolInfo);
  1694     PrintDrvInfo(fs, drvNum, EFSInfo | EVolInfo);
  1650 
  1695 
  1651     return KErrNone;
  1696     return KErrNone;
  1652 }
  1697 }
  1653 
  1698 
  1654 
  1699 
  1966 TInt ShellFunction::Hexdump(TDes& aPath,TUint aSwitches)
  2011 TInt ShellFunction::Hexdump(TDes& aPath,TUint aSwitches)
  1967 	{
  2012 	{
  1968 	ShellFunction::StripQuotes(aPath);
  2013 	ShellFunction::StripQuotes(aPath);
  1969 
  2014 
  1970 	ParsePath(aPath);
  2015 	ParsePath(aPath);
  1971 	RFile file;
  2016 	RFile64 file;
  1972 	TInt r=file.Open(TheShell->TheFs,aPath,EFileStream);
  2017 	TInt r=file.Open(TheShell->TheFs,aPath,EFileStream);
  1973 	if (r!=KErrNone)
  2018 	if (r!=KErrNone)
  1974 		return(r);
  2019 		return(r);
  1975 
  2020 
  1976 	TInt offset=0;
  2021 	TInt offset=0;
  3102 
  3147 
  3103 _LIT(KLitPercentS, "%S");
  3148 _LIT(KLitPercentS, "%S");
  3104 TInt ShellFunction::Type(TDes& aPath,TUint aSwitches)
  3149 TInt ShellFunction::Type(TDes& aPath,TUint aSwitches)
  3105 	{
  3150 	{
  3106 	ParsePath(aPath);
  3151 	ParsePath(aPath);
  3107 	RFile file;
  3152 	RFile64 file;
  3108 	TInt r=file.Open(TheShell->TheFs,aPath,EFileStreamText|EFileShareReadersOnly);
  3153 	TInt r=file.Open(TheShell->TheFs,aPath,EFileStreamText|EFileShareReadersOnly);
  3109 	if (r!=KErrNone)
  3154 	if (r!=KErrNone)
  3110 		return r;
  3155 		return r;
  3111 	TBuf8<0x200> tmpbuf;
  3156 	TBuf8<0x200> tmpbuf;
  3112 	TBuf<0x200> ubuf;
  3157 	TBuf<0x200> ubuf;
  3586 			}
  3631 			}
  3587 		}
  3632 		}
  3588 	return err;
  3633 	return err;
  3589 	}
  3634 	}
  3590 
  3635 
  3591 _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 }
  3592 
  3664 
  3593 void SIPrintf(TRefByValue<const TDesC16> aFmt, ...)
  3665 void SIPrintf(TRefByValue<const TDesC16> aFmt, ...)
  3594 	{
  3666 	{
  3595 	TBuf<256> buf;
  3667 	TBuf<256> buf;
  3596 	VA_LIST list;					
  3668 	VA_LIST list;					
  3761 
  3833 
  3762 
  3834 
  3763 //-------------------------------------------------------------------------
  3835 //-------------------------------------------------------------------------
  3764 /**
  3836 /**
  3765     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 
  3766 */
  3844 */
  3767 TInt ShellFunction::ConsoleEcho(TDes& aArgs, TUint /*aSwitches*/)
  3845 TInt ShellFunction::ConsoleEcho(TDes& aArgs, TUint aSwitches)
  3768 {
  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())
  3769     SIPrintf(aArgs);
  3858     SIPrintf(aArgs);
       
  3859     
  3770     return KErrNone;
  3860     return KErrNone;
  3771 }
  3861 }
       
  3862 
       
  3863