userlibandfileserver/fileserver/etshell/ts_com.cpp
changeset 6 0173bcd7697c
parent 0 a41df078684a
child 19 4a8fed1c0ef6
equal deleted inserted replaced
4:56f325a607ea 6:0173bcd7697c
    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     TPtrC ptrFormatHelp=_L("Drive:[\\] [fat12|fat16|fat32] [spc:X] [rs:Y] [ft:Z] [/Q] [/S] [/E]\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 ");
    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)");
    35     TPtrC ptrMountHelp=_L("Drive:[\\]  <fsy:X> <fs:Y> [pext:Z] [/S][/U][/F]\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 - mout drive as synchronous ");
    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 ");
    36 
    36 
    37 
    37 
    38 //	lint -e40,e30
    38 //	lint -e40,e30
    39 const TShellCommand CShell::iCommand[ENoShellCommands]=
    39 const TShellCommand CShell::iCommand[ENoShellCommands]=
    40 	{
    40 	{
    45 	TShellCommand(_L("CHKDSK"),_L("Check disk for corruption"),_L("[drive:] [/s][/f|/u]\n\n/s - start ScanDrive instead of CheckDisk\n/f - finalise drive\n/u - unfinalise drive"),TShellCommand::ESSwitch|TShellCommand::EFSwitch|TShellCommand::EUSwitch,ShellFunction::ChkDsk),
    45 	TShellCommand(_L("CHKDSK"),_L("Check disk for corruption"),_L("[drive:] [/s][/f|/u]\n\n/s - start ScanDrive instead of CheckDisk\n/f - finalise drive\n/u - unfinalise drive"),TShellCommand::ESSwitch|TShellCommand::EFSwitch|TShellCommand::EUSwitch,ShellFunction::ChkDsk),
    46 	TShellCommand(_L("COPY"),_L("Copy one (or more) file(s)"),_L("source [destination]"),TShellCommand::ESSwitch,ShellFunction::Copy),
    46 	TShellCommand(_L("COPY"),_L("Copy one (or more) file(s)"),_L("source [destination]"),TShellCommand::ESSwitch,ShellFunction::Copy),
    47 	TShellCommand(_L("DEL"),_L("Delete one file"),_L("[drive:][path][filename]"),TShellCommand::ESSwitch,ShellFunction::Del),
    47 	TShellCommand(_L("DEL"),_L("Delete one file"),_L("[drive:][path][filename]"),TShellCommand::ESSwitch,ShellFunction::Del),
    48 	TShellCommand(_L("DIR"),_L("Show directory contents"),_L("[drive:][path][filename] [/p][/w]\n\n  /p - Pause after each screen of information\n  /w - Wide format"),TShellCommand::EPSwitch|TShellCommand::EWSwitch|TShellCommand::EASwitch,ShellFunction::Dir),
    48 	TShellCommand(_L("DIR"),_L("Show directory contents"),_L("[drive:][path][filename] [/p][/w]\n\n  /p - Pause after each screen of information\n  /w - Wide format"),TShellCommand::EPSwitch|TShellCommand::EWSwitch|TShellCommand::EASwitch,ShellFunction::Dir),
    49 //	TShellCommand(_L("EDLIN"),_L("Edit a text file"),_L("[drive:][path][filename] [/p]\n\n  /p - Pause after each screen of information"),TShellCommand::EPSwitch,ShellFunction::Edit),
    49 //	TShellCommand(_L("EDLIN"),_L("Edit a text file"),_L("[drive:][path][filename] [/p]\n\n  /p - Pause after each screen of information"),TShellCommand::EPSwitch,ShellFunction::Edit),
    50     TShellCommand(_L("FORMAT"),_L("Format a disk"),ptrFormatHelp,TShellCommand::EQSwitch|TShellCommand::ESSwitch|TShellCommand::EESwitch,ShellFunction::Format),
    50     TShellCommand(_L("FORMAT"),_L("Format a disk"),ptrFormatHelp,TShellCommand::EQSwitch|TShellCommand::ESSwitch|TShellCommand::EESwitch|TShellCommand::EFSwitch,ShellFunction::Format),
    51     TShellCommand(_L("GOBBLE"),_L("Create a file"),_L("[filename] size [/e]\n\n /e - create an empty file, without writing any data"),TShellCommand::EESwitch,ShellFunction::Gobble),
    51     TShellCommand(_L("GOBBLE"),_L("Create a file"),_L("[filename] size [/e]\n\n /e - create an empty file, without writing any data"),TShellCommand::EESwitch,ShellFunction::Gobble),
    52 	TShellCommand(_L("HEXDUMP"),_L("Display the contents of a file in hexadecimal"),_L("[drive:][path][filename] [/p]\n\n  /p - Pause after each screen of information\n\n  Hit escape to exit from hexdump "),TShellCommand::EPSwitch,ShellFunction::Hexdump),
    52 	TShellCommand(_L("HEXDUMP"),_L("Display the contents of a file in hexadecimal"),_L("[drive:][path][filename] [/p]\n\n  /p - Pause after each screen of information\n\n  Hit escape to exit from hexdump "),TShellCommand::EPSwitch,ShellFunction::Hexdump),
    53 	TShellCommand(_L("LABEL"),_L("Set or return the volume label"),_L("[newlabel]"),0,ShellFunction::VolumeLabel),
    53 	TShellCommand(_L("LABEL"),_L("Set or return the volume label"),_L("[newlabel]"),0,ShellFunction::VolumeLabel),
    54 	TShellCommand(_L("MD"),_L("Make a new directory"),_L("name"),0,ShellFunction::Md),
    54 	TShellCommand(_L("MD"),_L("Make a new directory"),_L("name"),0,ShellFunction::Md),
    55 	TShellCommand(_L("MOVE"),_L("Move files"),_L("name [destination]"),TShellCommand::ESSwitch,ShellFunction::Move),
    55 	TShellCommand(_L("MOVE"),_L("Move files"),_L("name [destination]"),TShellCommand::ESSwitch,ShellFunction::Move),
    68 	TShellCommand(_L("SETSIZE"),_L("Set size of a file"),_L("[filename] size"),0,ShellFunction::SetSize),
    68 	TShellCommand(_L("SETSIZE"),_L("Set size of a file"),_L("[filename] size"),0,ShellFunction::SetSize),
    69 	TShellCommand(_L("DEBUGPORT"),_L("Set or get debug port"),_L("[port]"),0,ShellFunction::DebugPort),
    69 	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),
    70 	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),
    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),
    72 	TShellCommand(_L("SYSINFO"),_L("Print information about system features and status"),_L(""),0,ShellFunction::SysInfo),
    72 	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,ShellFunction::MountFileSystem),
    73     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),
    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),
    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),
    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),
    76 
    76 
    77     };
    77     };
    78 
    78 
  1172 	if(aFlags & EMediaTypeInfo)
  1172 	if(aFlags & EMediaTypeInfo)
  1173     {
  1173     {
  1174         FormatDrvMediaTypeInfo(driveInfo, Buf);
  1174         FormatDrvMediaTypeInfo(driveInfo, Buf);
  1175 	    apConsole->Printf(Buf);
  1175 	    apConsole->Printf(Buf);
  1176 
  1176 
  1177 	    //apConsole->Printf(_L("BatteryState:%d\n"),driveInfo.iBattery);
       
  1178 	}
  1177 	}
  1179     
  1178     
  1180     //-- print drive attributes
  1179     //-- print drive attributes
  1181 	if(aFlags & EDrvAttInfo)
  1180 	if(aFlags & EDrvAttInfo)
  1182     {
  1181     {
  1382     CShell::TheConsole->Printf(_L("'%S' filesystem dismounted from drive %c:\n"), &fsName, 'A'+aDrvNum);
  1381     CShell::TheConsole->Printf(_L("'%S' filesystem dismounted from drive %c:\n"), &fsName, 'A'+aDrvNum);
  1383     return KErrNone;
  1382     return KErrNone;
  1384     }
  1383     }
  1385 }
  1384 }
  1386 
  1385 
       
  1386 //-----------------------------------------------------------------------------------------------------------------------
       
  1387 TInt DoRemountFS(RFs& aFs, TInt aDrvNum)
       
  1388 {
       
  1389     TInt        nRes;
       
  1390     TBuf<40>    fsName;
       
  1391     TBuf<40>    pextName;
       
  1392 
       
  1393     //-- 1. get file system name
       
  1394     nRes = aFs.FileSystemName(fsName, aDrvNum);
       
  1395     if(nRes != KErrNone)
       
  1396         return KErrNotFound;
       
  1397 
       
  1398     //-- 2. find out if the drive sync/async
       
  1399     TPckgBuf<TBool> drvSyncBuf;
       
  1400     TBool& drvSynch = drvSyncBuf();
       
  1401 
       
  1402     nRes = aFs.QueryVolumeInfoExt(aDrvNum, EIsDriveSync, drvSyncBuf);
       
  1403     if(nRes != KErrNone)
       
  1404     {//-- pretend that the drive is asynch. in the case of file system being corrupted. this is 99.9% true
       
  1405        drvSynch = EFalse;
       
  1406     }
       
  1407    
       
  1408     //-- 3. find out primary extension name if it is present; we will need to add it again when mounting the FS
       
  1409     //-- other extensions (non-primary) are not supported yet
       
  1410     nRes = aFs.ExtensionName(pextName, aDrvNum, 0);
       
  1411     if(nRes != KErrNone)
       
  1412     {
       
  1413         pextName.SetLength(0);
       
  1414     }
       
  1415     
       
  1416     //-- 3.1 check if the drive has non-primary extensions, fail in this case
       
  1417     {
       
  1418         TBuf<40> extName;
       
  1419         nRes = aFs.ExtensionName(extName, aDrvNum, 1);
       
  1420         if(nRes == KErrNone)
       
  1421         {   
       
  1422             CShell::TheConsole->Printf(_L("Non-primary extensions are not supported!\n"));
       
  1423             return KErrNotSupported;
       
  1424         }
       
  1425     }
       
  1426 
       
  1427     //-- 4. dismount the file system
       
  1428     nRes = DoDismountFS(aFs, aDrvNum);
       
  1429     if(nRes != KErrNone)
       
  1430         return nRes;
       
  1431 
       
  1432     //-- 5. mount the FS back
       
  1433     if(pextName.Length() > 0)
       
  1434     {//-- we need to mount FS with the primary extension
       
  1435         nRes = aFs.AddExtension(pextName);
       
  1436         if(nRes != KErrNone && nRes != KErrAlreadyExists)
       
  1437         {
       
  1438             return nRes;
       
  1439         }
       
  1440         
       
  1441         nRes = aFs.MountFileSystem(fsName, pextName, aDrvNum, drvSynch);
       
  1442     }
       
  1443     else
       
  1444     {//-- the FS did not have primary extension
       
  1445         nRes = aFs.MountFileSystem(fsName, aDrvNum, drvSynch);
       
  1446     }
       
  1447 
       
  1448     if(nRes == KErrNone)
       
  1449     {
       
  1450         CShell::TheConsole->Printf(_L("mounted filesystem:%S\n"), &fsName);
       
  1451     }
       
  1452 
       
  1453     return nRes;
       
  1454 }
  1387 
  1455 
  1388 //-----------------------------------------------------------------------------------------------------------------------
  1456 //-----------------------------------------------------------------------------------------------------------------------
  1389 /**
  1457 /**
  1390     Mount or dismount the file system on the specified drive.
  1458     Mount or dismount the file system on the specified drive.
  1391 
  1459 
  1396     zzz is the optional parameter that specifies primary extension name
  1464     zzz is the optional parameter that specifies primary extension name
  1397 
  1465 
  1398     /u dismounts a filesystem on the specified drive; e.g. "mount d: /u"
  1466     /u dismounts a filesystem on the specified drive; e.g. "mount d: /u"
  1399     /s for mounting FS specifies that the drive will be mounted as synchronous one.
  1467     /s for mounting FS specifies that the drive will be mounted as synchronous one.
  1400     /f for forcing mounting the FS; the previous one will be automatically dismounted
  1468     /f for forcing mounting the FS; the previous one will be automatically dismounted
       
  1469     /r remount existing FS (dismount and mount it back)
  1401 */
  1470 */
  1402 TInt ShellFunction::MountFileSystem(TDes& aArgs, TUint aSwitches)
  1471 TInt ShellFunction::MountFileSystem(TDes& aArgs, TUint aSwitches)
  1403 {
  1472 {
  1404 	ShellFunction::StripQuotes(aArgs);
  1473 	ShellFunction::StripQuotes(aArgs);
  1405     aArgs.UpperCase();
  1474     aArgs.UpperCase();
  1422         return KErrArgument;
  1491         return KErrArgument;
  1423     }
  1492     }
  1424 
  1493 
  1425     const TInt drvNum = nRes; //-- this is the drive number;
  1494     const TInt drvNum = nRes; //-- this is the drive number;
  1426 
  1495 
       
  1496 
       
  1497     //-- remounting the existing FS (/R switch)
       
  1498     if(aSwitches & TShellCommand::ERSwitch)
       
  1499     {
       
  1500         nRes = DoRemountFS(fs, drvNum);
       
  1501         return nRes;
       
  1502     }
       
  1503     
  1427     //-- check if we dismounting the FS (/U switch)
  1504     //-- check if we dismounting the FS (/U switch)
  1428     if(aSwitches & TShellCommand::EUSwitch)
  1505     if(aSwitches & TShellCommand::EUSwitch)
  1429     {
  1506     {
  1430         nRes = DoDismountFS(fs, drvNum);
  1507         nRes = DoDismountFS(fs, drvNum);
  1431         
  1508         
  1545         rs:Y    "Y" specifies the number of reserved sectors  (FAT FS only)
  1622         rs:Y    "Y" specifies the number of reserved sectors  (FAT FS only)
  1546         ft:Z    "Z" specifies the number of FAT tables 1 or 2 (FAT FS only)
  1623         ft:Z    "Z" specifies the number of FAT tables 1 or 2 (FAT FS only)
  1547 		/Q : Quick Format
  1624 		/Q : Quick Format
  1548 		/S : Special Format
  1625 		/S : Special Format
  1549 		/E : Remove Password and Format
  1626 		/E : Remove Password and Format
  1550 
  1627         /F : force formatting, even if there are files opened on the drive
  1551 */
  1628 */
  1552 
  1629 
  1553 TInt ShellFunction::Format(TDes& aPath, TUint aSwitches)
  1630 TInt ShellFunction::Format(TDes& aPath, TUint aSwitches)
  1554 	{
  1631 	{
  1555     _LIT(KFormatStars,"********************");
  1632     _LIT(KFormatStars,"********************");
  1570 		fmtMode|=ESpecialFormat;
  1647 		fmtMode|=ESpecialFormat;
  1571 
  1648 
  1572 	//-- Format /E - force erase
  1649 	//-- Format /E - force erase
  1573     if (aSwitches & TShellCommand::EESwitch)
  1650     if (aSwitches & TShellCommand::EESwitch)
  1574 		fmtMode|=EForceErase;
  1651 		fmtMode|=EForceErase;
       
  1652 
       
  1653 	//-- Format /F - force format. The volume will be formatted even if there are files or directories opened on this drive
       
  1654     if (aSwitches & TShellCommand::EFSwitch)
       
  1655 		fmtMode|=EForceFormat;
       
  1656 
  1575 
  1657 
  1576 	TInt    fmtCnt = 0;
  1658 	TInt    fmtCnt = 0;
  1577 	RFormat format;
  1659 	RFormat format;
  1578 	TInt    nRes;
  1660 	TInt    nRes;
  1579     TLex    lex(aPath);
  1661     TLex    lex(aPath);