author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Sat, 20 Feb 2010 00:10:51 +0200 | |
branch | RCL_3 |
changeset 62 | 4a8fed1c0ef6 |
parent 33 | 0173bcd7697c |
child 87 | 2f92ad2dc5db |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 |
// All rights reserved. |
|
3 |
// This component and the accompanying materials are made available |
|
4 |
// under the terms of the License "Eclipse Public License v1.0" |
|
5 |
// which accompanies this distribution, and is available |
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// f32\etshell\ts_com.cpp |
|
15 |
// Shell commands |
|
16 |
// |
|
17 |
// |
|
18 |
||
19 |
#ifdef __VC32__ |
|
20 |
// Solve compilation problem caused by non-English locale |
|
21 |
#pragma setlocale("english") |
|
22 |
#endif |
|
23 |
||
24 |
#include "ts_std.h" |
|
25 |
||
26 |
#include <hal.h> |
|
27 |
#include <d32locd.h> |
|
28 |
#include <e32math.h> |
|
29 |
#include "u32std.h" |
|
30 |
#include <u32hal.h> |
|
31 |
#include <nkern/nk_trace.h> |
|
32 |
#include "filesystem_fat.h" |
|
33 |
||
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
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)"); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
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 "); |
0 | 36 |
|
37 |
||
38 |
// lint -e40,e30 |
|
39 |
const TShellCommand CShell::iCommand[ENoShellCommands]= |
|
40 |
{ |
|
41 |
// TShellCommand(_L("BLANK"),_L("Help"),_L("-?"),TShellCommand::EDSwitch,ShellFunction::BLANK), |
|
42 |
TShellCommand(_L("ATTRIB"),_L("Displays or changes file attributes"),_L("[drive:][path][filename] [+R | -R] [+H |-H] [+S | -S] [+A | -A] [/p]\n\n /p - Pause after each screen of information"), TShellCommand::EPSwitch, ShellFunction::Attrib), |
|
43 |
TShellCommand(_L("CD"),_L("Change the current directory for a drive"),_L("[path] [/d]\n\n /d - Change drive"),TShellCommand::EDSwitch,ShellFunction::Cd), |
|
44 |
TShellCommand(_L("CHKDEPS"),_L("Check the dependencies of an executable or a Dll (ARM only)"),_L("[Filename.EXE] or [Filename.DLL]"),0,ShellFunction::ChkDeps), |
|
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), |
|
62
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
46 |
TShellCommand(_L("COPY"),_L("Copy one (or more) file(s), overwriting existing one(s)"),_L("source [destination]"),TShellCommand::ESSwitch,ShellFunction::Copy), |
0 | 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), |
|
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), |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
50 |
TShellCommand(_L("FORMAT"),_L("Format a disk"),ptrFormatHelp,TShellCommand::EQSwitch|TShellCommand::ESSwitch|TShellCommand::EESwitch|TShellCommand::EFSwitch,ShellFunction::Format), |
0 | 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), |
|
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), |
|
55 |
TShellCommand(_L("MOVE"),_L("Move files"),_L("name [destination]"),TShellCommand::ESSwitch,ShellFunction::Move), |
|
56 |
TShellCommand(_L("PS"),_L("Display information about processes"),_L(""),0,ShellFunction::Ps), |
|
57 |
TShellCommand(_L("RENAME"),_L("Rename a file"),_L("oldfilename newfilename"),TShellCommand::ESSwitch,ShellFunction::Rename), |
|
58 |
TShellCommand(_L("RD"),_L("Delete one directory"),_L("[drive:][path]directoryname"),TShellCommand::ESSwitch,ShellFunction::Rd), |
|
59 |
TShellCommand(_L("START"),_L("Run a program in a separate window"),_L("filename[.exe]"),0,ShellFunction::Start), |
|
60 |
TShellCommand(_L("TIME"),_L("Display the system time"),_L(""),0,ShellFunction::Time), |
|
61 |
TShellCommand(_L("TRACE"),_L("Set the debug trace mask"),_L("[mask value in hex] [index] [/S/L/F/T/I/N/M/O/C/H]\n /S - KFSERV\n /L - KFLDR\n /F - KFSYS\n /T - KLFFS\n /I - KISO9660\n /N - KNTFS\n /M - KTHRD\n /O - KROFS\n /C - KCOMPFS\n /H - KCACHE"),TShellCommand::ELSwitch|TShellCommand::ESSwitch|TShellCommand::EFSwitch|TShellCommand::ETSwitch|TShellCommand::EISwitch|TShellCommand::ENSwitch|TShellCommand::EMSwitch|TShellCommand::EOSwitch|TShellCommand::ECSwitch|TShellCommand::EHSwitch,ShellFunction::Trace), |
|
62 |
TShellCommand(_L("TREE"),_L("Graphically display the directory structure"),_L("[drive:][path] [/f][/p]\n\n /f - Show files\n /p - Pause after each screen of information"),TShellCommand::EFSwitch|TShellCommand::EPSwitch,ShellFunction::Tree), |
|
63 |
TShellCommand(_L("TYPE"),_L("Display the contents of a text file"),_L("[drive:][path]filename [/p]\n\n /p - Pause after each screen of information"),TShellCommand::EPSwitch,ShellFunction::Type), |
|
64 |
TShellCommand(_L("VNAME"),_L("Check whether a filename is valid. Return any invalid character"),_L("[drive:][path]filename \n\n "),0,ShellFunction::ValidName), |
|
65 |
TShellCommand(_L("LOCK"),_L("Lock a password-enabled media"),_L("drive-number cur-pswd new-pswd [/s]"), TShellCommand::ESSwitch, ShellFunction::Lock), |
|
66 |
TShellCommand(_L("UNLOCK"),_L("Unlock a locked password-enabled media"),_L("drive-number cur-pswd [/s]"), TShellCommand::ESSwitch, ShellFunction::Unlock), |
|
67 |
TShellCommand(_L("CLEAR"),_L("Clear password from password-enabled media"),_L("drive-number cur-pswd"), 0x00000000, ShellFunction::Clear), |
|
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), |
|
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), |
|
72 |
TShellCommand(_L("SYSINFO"),_L("Print information about system features and status"),_L(""),0,ShellFunction::SysInfo), |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
73 |
TShellCommand(_L("MOUNT"),_L("Mount / dismount file system on specified drive"),ptrMountHelp,TShellCommand::EUSwitch|TShellCommand::ESSwitch|TShellCommand::EFSwitch|TShellCommand::ERSwitch,ShellFunction::MountFileSystem), |
0 | 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), |
|
76 |
||
77 |
}; |
|
78 |
||
79 |
||
80 |
LOCAL_C TInt pswd_DrvNbr(TDes &aPath, TInt &aDN); |
|
81 |
LOCAL_C TInt pswd_Password(TDes &aPath, TInt aPWNbr, TMediaPassword &aPW); |
|
82 |
||
83 |
_LIT(KLitNewLine,"\n"); |
|
84 |
void CShell::NewLine() |
|
85 |
{ |
|
86 |
TheConsole->Printf(KLitNewLine()); |
|
87 |
} |
|
88 |
||
89 |
// |
|
90 |
// Skip the hexadecimal prefix if present and return EHex. Return |
|
91 |
// EDecimal otherwise. |
|
92 |
// |
|
93 |
||
94 |
static TRadix ParseHexaPrefixIfAny(TLex& aLex) |
|
95 |
{ |
|
96 |
_LIT(KPrefix, "0x"); |
|
97 |
if (aLex.Remainder().Length() > 2) |
|
98 |
{ |
|
99 |
aLex.Mark(); |
|
100 |
aLex.Inc(2); |
|
101 |
if (aLex.MarkedToken().MatchF(KPrefix) != KErrNotFound) |
|
102 |
return EHex; |
|
103 |
else |
|
104 |
aLex.UnGetToMark(); |
|
105 |
} |
|
106 |
||
107 |
return EDecimal; |
|
108 |
} |
|
109 |
||
110 |
||
111 |
// |
|
112 |
// TWord class |
|
113 |
// Used to locate spaces in the command line, and return the next word |
|
114 |
// |
|
115 |
||
116 |
TWord::TWord(const TDesC& aDes) |
|
117 |
: iSpace(0),iNextSpace(0) |
|
118 |
// |
|
119 |
// Constructor |
|
120 |
// |
|
121 |
{ |
|
122 |
Init(aDes); |
|
123 |
} |
|
124 |
||
125 |
||
126 |
void TWord::Init(const TDesC& aDes) |
|
127 |
// |
|
128 |
// Resets to the start of the buffer |
|
129 |
// |
|
130 |
{ |
|
131 |
iDes.Set(aDes); |
|
132 |
} |
|
133 |
||
134 |
TInt TWord::FindNextWord(TDes& aWord) |
|
135 |
// |
|
136 |
// Returns the next word from the buffer |
|
137 |
// |
|
138 |
{ |
|
139 |
iSpace=aWord.Locate(' '); |
|
140 |
||
141 |
if (iSpace==KErrNotFound) // No spaces in command line |
|
142 |
{ |
|
143 |
if (aWord.Length()==0) // Command line has zero length: |
|
144 |
return (KErrNotFound); // User just typed "command" |
|
145 |
else |
|
146 |
{ // User typed "command aWord" |
|
147 |
iRightString=aWord; |
|
148 |
iNextWord=aWord; |
|
149 |
return (0); |
|
150 |
} |
|
151 |
} |
|
152 |
||
153 |
else if (iSpace<aWord.Length()) // Spaces may be command switches or part of the filename |
|
154 |
{ |
|
155 |
iRightString=(aWord.Right((aWord.Length()-iSpace)-1)); |
|
156 |
||
157 |
iNextSpace=iRightString.Locate(' '); // Check for another space |
|
158 |
if (iNextSpace==KErrNotFound) // No more spaces |
|
159 |
{ |
|
160 |
iNextWord=iRightString; |
|
161 |
return((iDes.Length())-(iRightString.Length()));// Position of the (last) word |
|
162 |
} |
|
163 |
||
164 |
if (iNextSpace<iRightString.Length()) // More spaces - assign iNextWord to be |
|
165 |
{ // the text in between the two spaces |
|
166 |
iNextWord=(iRightString.Left(iNextSpace)); |
|
167 |
return ((iDes.Length())-(iRightString.Length()));// Position of the word |
|
168 |
} |
|
169 |
||
170 |
else |
|
171 |
return(KErrNotFound); |
|
172 |
} |
|
173 |
||
174 |
else |
|
175 |
return(KErrNotFound); |
|
176 |
} |
|
177 |
||
178 |
//------------------------------------------------------------------------- |
|
179 |
||
180 |
||
181 |
TInt ShellFunction::Cd(TDes& aPath,TUint aSwitches) |
|
182 |
// |
|
183 |
// Change directory |
|
184 |
// |
|
185 |
{ |
|
186 |
ShellFunction::StripQuotes(aPath); |
|
187 |
||
188 |
TBool drvNameOnly=aPath.Length()==2 && aPath[1]==KDriveDelimiter; |
|
189 |
TBool dSwitchSet=aSwitches&TShellCommand::EDSwitch; |
|
190 |
if (aPath.Length()==0 || (drvNameOnly && !dSwitchSet)) |
|
191 |
{ |
|
192 |
TInt drvNum=(aPath.Length() ? aPath[0] : TheShell->currentPath[0])-'A'; |
|
193 |
if (drvNum<0 || drvNum>=KMaxDrives) |
|
194 |
return(KErrBadName); |
|
195 |
CShell::TheConsole->Printf(_L("%S\n"),&TheShell->drivePaths[drvNum]); |
|
196 |
return(KErrNone); |
|
197 |
} |
|
198 |
if (aPath.Find(_L("*"))!=KErrNotFound) |
|
199 |
return(KErrBadName); |
|
200 |
if (aPath[aPath.Length()-1]!=KPathDelimiter && !drvNameOnly) |
|
201 |
aPath.Append(KPathDelimiter); |
|
202 |
aPath.Append('*'); |
|
203 |
TChar drvLetter = aPath[0]; |
|
204 |
drvLetter.UpperCase(); |
|
205 |
aPath[0] = (TText) drvLetter; |
|
206 |
TParse dirParse; |
|
207 |
TInt r=GetFullPath(aPath,dirParse); |
|
208 |
if (r!=KErrNone) |
|
209 |
return(KErrBadName); |
|
210 |
TPtrC fullName=dirParse.FullName(); |
|
211 |
RDir dir; |
|
212 |
r=dir.Open(TheShell->TheFs,fullName,KEntryAttMaskSupported); |
|
213 |
if (r!=KErrNone) |
|
214 |
return(r); |
|
215 |
dir.Close(); |
|
216 |
if (dSwitchSet || fullName[0]==TheShell->currentPath[0]) |
|
217 |
r=TheShell->TheFs.SetSessionPath(dirParse.DriveAndPath()); |
|
218 |
if (r==KErrNone) |
|
219 |
TheShell->SetDrivePath(dirParse.DriveAndPath()); |
|
220 |
return(r); |
|
221 |
} |
|
222 |
||
223 |
TInt ShellFunction::ChkDeps(TDes& aPath,TUint /*aSwitches*/) |
|
224 |
{ |
|
225 |
ShellFunction::StripQuotes(aPath); |
|
226 |
||
227 |
aPath.Trim(); |
|
228 |
TBool appendedExe=EFalse; |
|
229 |
||
230 |
// Determine whether aPath is an executable or a Dll |
|
231 |
||
232 |
TInt r=aPath.FindF(_L(".EXE")); |
|
233 |
if (r==KErrNotFound) |
|
234 |
{ |
|
235 |
r=aPath.FindF(_L(".DLL")); |
|
236 |
if (r==KErrNotFound)// aPath does not include .exe or .dll extensions |
|
237 |
{ |
|
238 |
aPath.Append(_L(".EXE")); // append a .exe extension |
|
239 |
appendedExe=ETrue; |
|
240 |
} |
|
241 |
} |
|
242 |
||
243 |
if (aPath.Length()>2 && aPath[1]==':' && aPath[2]!='\\') |
|
244 |
{ |
|
245 |
TInt drive; |
|
246 |
__ASSERT_ALWAYS(RFs::CharToDrive(aPath[0],drive)==KErrNone,User::Panic(_L("Invalid drive letter"),0)); |
|
247 |
TheShell->currentPath=TheShell->drivePaths[drive]; |
|
248 |
aPath.Delete(0,2); |
|
249 |
aPath.Insert(0,TheShell->currentPath); |
|
250 |
} |
|
251 |
if (aPath.Length()>2 && aPath[1]!=':') |
|
252 |
{ |
|
253 |
if (aPath[0]!='\\') |
|
254 |
aPath.Insert(0,TheShell->currentPath); |
|
255 |
else |
|
256 |
aPath.Insert(0,TheShell->currentPath.Left(2)); |
|
257 |
} |
|
258 |
||
259 |
RFile file; |
|
260 |
r=file.Open(CShell::TheFs,aPath,EFileStream); |
|
261 |
if (r!=KErrNone) // File could not be opened |
|
262 |
{ |
|
263 |
if (appendedExe) // If .EXE was appended earlier |
|
264 |
{ |
|
265 |
// Remove .EXE and append .DLL instead. Try to open the file again |
|
266 |
// If this fails too, the user entered an invalid filename that is neither |
|
267 |
// an executable or a Dll |
|
268 |
aPath.Delete(aPath.Length()-4,4); |
|
269 |
appendedExe=EFalse; |
|
270 |
aPath.Append(_L(".DLL")); // Try a .DLL extension |
|
271 |
r=file.Open(CShell::TheFs,aPath,EFileStream); |
|
272 |
if (r!=KErrNone) // Still could not open file |
|
273 |
return(r); // Neither an executable or a Dll |
|
274 |
// Runs to here if the file is opened -> .DLL extension appended |
|
275 |
} |
|
276 |
else |
|
277 |
return(r); // User had typed in an incorrect filename with |
|
278 |
// a .DLL or .EXE extension |
|
279 |
} |
|
280 |
||
281 |
file.Close(); |
|
282 |
CDllChecker check; |
|
283 |
TRAPD(leaveCode,check.ConstructL());// Allocates 4 elements at a time |
|
284 |
if (leaveCode!=KErrNone) // If function leaves |
|
285 |
return(leaveCode); // return the leave code |
|
286 |
||
287 |
TRAPD(result,check.GetImportDataL(aPath,NULL)); |
|
288 |
if (result==KErrGeneral) |
|
289 |
{ |
|
290 |
CShell::TheConsole->Printf(_L(" %S has no import data\n"),&aPath); |
|
291 |
return(KErrNone); |
|
292 |
} |
|
293 |
else |
|
294 |
check.ListArray(); // Print out the results of DllCheck |
|
295 |
return(KErrNone); |
|
296 |
} |
|
297 |
||
298 |
// |
|
299 |
// Check disk for corruption |
|
300 |
// |
|
301 |
// Spec: |
|
302 |
// |
|
303 |
// ChkDsk DriveLetter:[\] [/S] [/F] [/U] |
|
304 |
// |
|
305 |
// /S : Starts a ScanDrive instead of CheckDisk |
|
306 |
// /F : Finalise given drive |
|
307 |
// /U : UnFinalise given drive |
|
308 |
||
309 |
TInt ShellFunction::ChkDsk(TDes& aPath,TUint aSwitches) |
|
310 |
{ |
|
311 |
ShellFunction::StripQuotes(aPath); |
|
312 |
||
313 |
const TBool bRunScanDrv = aSwitches & TShellCommand::ESSwitch; |
|
314 |
const TBool bFinaliseDrv = aSwitches & TShellCommand::EFSwitch; |
|
315 |
const TBool bUnFinaliseDrv = aSwitches & TShellCommand::EUSwitch; |
|
316 |
||
317 |
TInt nRes; |
|
318 |
TInt drive=EDriveZ; |
|
319 |
||
320 |
if(aPath.Length() < 1) |
|
321 |
{ |
|
322 |
nRes = KErrArgument; |
|
323 |
} |
|
324 |
else |
|
325 |
{ |
|
326 |
nRes=CShell::TheFs.CharToDrive(aPath[0], drive); |
|
327 |
} |
|
328 |
||
329 |
if (nRes != KErrNone) |
|
330 |
{ |
|
331 |
CShell::TheConsole->Printf(_L("Wrong drive specified!\n")); |
|
332 |
return nRes; |
|
333 |
} |
|
334 |
||
335 |
if(bRunScanDrv) |
|
336 |
{//-- run ScanDrive on the specified drive |
|
337 |
CShell::TheConsole->Printf(_L("Starting ScanDrive...\n")); |
|
338 |
nRes=TheShell->TheFs.ScanDrive(aPath); |
|
339 |
if(nRes == KErrNone) |
|
340 |
{ |
|
341 |
CShell::TheConsole->Printf(_L("No errors.\n")); |
|
342 |
} |
|
343 |
} |
|
344 |
else if(bFinaliseDrv) |
|
345 |
{//-- finalise the drive |
|
346 |
nRes = CShell::TheFs.FinaliseDrive(drive, RFs::EFinal_RW); |
|
347 |
if(nRes != KErrNone) |
|
348 |
return nRes; |
|
349 |
||
350 |
CShell::TheConsole->Printf(_L("Drive %c: is finalised RW\n"), 'A'+drive); |
|
351 |
} |
|
352 |
else if(bUnFinaliseDrv) |
|
353 |
{//-- Unfinalise the drive |
|
354 |
nRes = CShell::TheFs.FinaliseDrive(drive, RFs::EForceUnfinalise); |
|
355 |
if(nRes != KErrNone) |
|
356 |
return nRes; |
|
357 |
||
358 |
CShell::TheConsole->Printf(_L("Drive %c: is Unfinalised\n"), 'A'+drive); |
|
359 |
} |
|
360 |
else |
|
361 |
{//-- run CheckDisk on the specified drive |
|
362 |
nRes=TheShell->TheFs.CheckDisk(aPath); |
|
363 |
if (nRes<0) |
|
364 |
return(nRes); |
|
365 |
||
366 |
switch(nRes) |
|
367 |
{ |
|
368 |
case 0: |
|
369 |
CShell::TheConsole->Printf(_L("Complete - no errors\n")); |
|
370 |
break; |
|
371 |
case 1: |
|
372 |
CShell::TheConsole->Printf(_L("Error - File cluster chain contains a bad value (<2 or >maxCluster)\n")); |
|
373 |
break; |
|
374 |
case 2: |
|
375 |
CShell::TheConsole->Printf(_L("Error - Two files are linked to the same cluster\n")); |
|
376 |
break; |
|
377 |
case 3: |
|
378 |
CShell::TheConsole->Printf(_L("Error - Unallocated cluster contains a value != 0\n")); |
|
379 |
break; |
|
380 |
case 4: |
|
381 |
CShell::TheConsole->Printf(_L("Error - Size of file != number of clusters in chain\n")); |
|
382 |
break; |
|
383 |
default: |
|
384 |
CShell::TheConsole->Printf(_L("Undefined Error value\n")); |
|
385 |
} |
|
386 |
} |
|
387 |
return nRes; |
|
388 |
} |
|
389 |
||
390 |
TInt ShellFunction::Copy(TDes& aPath,TUint aSwitches) |
|
391 |
// |
|
392 |
// DOS spec: |
|
393 |
// |
|
394 |
// COPY [/A | /B] source [/A | /B] [+ source [/A | /B] [+ ...]] [destination] [/A | /B]] [/V] [/N] |
|
395 |
// source Specifies the file or files to be copied. |
|
396 |
// /A Indicates an ASCII text file. |
|
397 |
// /B Indicates a binary file. |
|
398 |
// destination Specifies the directory and/or filename for the new file(s). |
|
399 |
// /V Verifies that new files are written correctly. |
|
400 |
// /Y Supresses prompting to confirm you want to overwrite existing destination file |
|
401 |
// /N Uses short filename, if available, when copying a file with a non-8dot3 name. |
|
402 |
// |
|
403 |
// To append files, specify a single file for destination, but multiple files |
|
404 |
// for source (using wildcards or file1+file2+file3 format). |
|
405 |
// |
|
62
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
406 |
// Overwrites existing file(s). |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
407 |
// |
0 | 408 |
// My spec: |
409 |
// |
|
410 |
// COPY source [destination] |
|
411 |
// source Specifies the file or files to be copied to the current directory |
|
412 |
||
413 |
// Modified November 1997 to allow spaces in filenames |
|
414 |
||
415 |
{ |
|
416 |
if (aPath.Length() == 0) |
|
417 |
return KErrNotFound; // no source file |
|
418 |
||
419 |
ShellFunction::StripQuotes(aPath); |
|
420 |
||
421 |
TBuf<KShellMaxCommandLine> destination; |
|
422 |
TBuf<KShellMaxCommandLine> tempPath; |
|
423 |
TWord word(aPath); |
|
424 |
||
425 |
TBool endOfCommandLine=EFalse; |
|
426 |
||
427 |
// Check if the word returned is a valid filename. If not, scan the next |
|
428 |
// word too in case the filename contains spaces. If, at the end of the |
|
429 |
// the line, the filename is not recognised, it is invalid. If there are no |
|
430 |
// spaces the user has not used the correct format for this command. |
|
431 |
||
432 |
TInt r=word.FindNextWord(aPath); |
|
433 |
do { |
|
434 |
TParse dirPath; |
|
435 |
||
436 |
if (r==0) // No destination was specified |
|
437 |
{ |
|
438 |
// Work out the destination |
|
439 |
tempPath.SetLength(0); |
|
440 |
r=GetFullPath(tempPath,dirPath); |
|
441 |
if (r!=KErrNone) |
|
442 |
return(r); |
|
443 |
destination=dirPath.FullName(); |
|
444 |
// Now get the path of the source |
|
445 |
tempPath=aPath; |
|
446 |
r=GetFullPath(tempPath,dirPath); |
|
447 |
if (r!=KErrNone) |
|
448 |
return(r); |
|
449 |
endOfCommandLine=ETrue; // So we don't get stuck in an infinite loop |
|
450 |
} |
|
451 |
else |
|
452 |
{ |
|
453 |
// Work out the destination |
|
454 |
destination=aPath.Right(aPath.Length()-r); |
|
455 |
if (!destination.Compare(_L("."))) |
|
456 |
GetFullPath(destination,dirPath); |
|
457 |
// Now get the path of the source |
|
458 |
tempPath=aPath; |
|
459 |
tempPath.SetLength(r); |
|
460 |
r=GetFullPath(tempPath,dirPath); |
|
461 |
if (r!=KErrNone) |
|
462 |
return(r); |
|
463 |
} |
|
464 |
||
465 |
TBool recursive=((aSwitches&TShellCommand::ESSwitch)!=0); |
|
62
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
466 |
// Automatically overwrites existing file(s) |
0 | 467 |
TUint switches=(recursive) ? CFileMan::EOverWrite|CFileMan::ERecurse : CFileMan::EOverWrite; |
468 |
r=CShell::TheFileMan->Copy(dirPath.FullName(),destination,switches); |
|
469 |
if (r==KErrNone) |
|
470 |
return(r); // Copy was successful |
|
471 |
||
472 |
else // Not a valid filename - move one word along the command line |
|
473 |
r=word.FindNextWord(word.iRightString); |
|
474 |
} while ((r>=0)&&(!endOfCommandLine)); |
|
475 |
||
476 |
if (r<0) // Some error |
|
477 |
return (r); |
|
478 |
else // End of command line, user typed invalid line, return not found |
|
479 |
return (KErrNotFound); |
|
480 |
} |
|
481 |
||
482 |
||
483 |
TInt ShellFunction::VolumeLabel(TDes& aPath,TUint /*aSwitches*/) |
|
484 |
/** |
|
485 |
Sets or returns the default path |
|
486 |
||
487 |
@param aPath The volume label being set or returned |
|
488 |
*/ |
|
489 |
{ |
|
490 |
ShellFunction::StripQuotes(aPath); |
|
491 |
||
492 |
TVolumeInfo vol; |
|
493 |
TInt drive; |
|
494 |
TInt r=CShell::TheFs.CharToDrive(CShell::currentPath[0], drive); |
|
495 |
if (r!=KErrNone) |
|
496 |
return(r); |
|
497 |
if (aPath.Length()==0) |
|
498 |
{ |
|
499 |
r=CShell::TheFs.Volume(vol, drive); |
|
500 |
if (r==KErrNone) |
|
501 |
CShell::TheConsole->Printf(_L("Volume = %S\n"),&vol.iName); |
|
502 |
return(r); |
|
503 |
} |
|
504 |
r=CShell::TheFs.SetVolumeLabel(aPath, drive); |
|
505 |
return(r); |
|
506 |
} |
|
507 |
||
508 |
TInt ShellFunction::Del(TDes& aPath,TUint aSwitches) |
|
509 |
{ |
|
510 |
TParse filePath; |
|
511 |
if (aPath.Length()==0) |
|
512 |
return(KErrNone); |
|
513 |
||
514 |
ShellFunction::StripQuotes(aPath); |
|
515 |
||
516 |
GetFullPath(aPath,filePath); |
|
517 |
TBool recursive=((aSwitches&TShellCommand::ESSwitch)!=0); |
|
518 |
TUint switches=(recursive) ? CFileMan::ERecurse : 0; |
|
519 |
TInt r=CShell::TheFileMan->Delete(filePath.FullName(),switches); |
|
520 |
return(r); |
|
521 |
} |
|
522 |
||
523 |
||
524 |
void ShellFunction::AlignTextIntoColumns(RPointerArray<HBufC>& aText) |
|
525 |
//function which tries to arrange text as a set of columns if console width greater then the longest string |
|
526 |
{ |
|
527 |
TInt ind=0; |
|
528 |
if (aText.Count()<=0) return; |
|
529 |
//detect the longest string |
|
530 |
for (TInt i=0;i<aText.Count();i++) |
|
531 |
if (aText[i]->Length()>aText[ind]->Length()) |
|
532 |
ind=i; |
|
533 |
TInt max_string_length=aText[ind]->Length()+2; |
|
534 |
||
535 |
//calculate how many columns fit into the screen |
|
536 |
TInt number_of_columns=(CShell::TheConsole->ScreenSize().iWidth)/max_string_length; |
|
537 |
||
538 |
//if we cannot fit more than one column into screen when we do nothing |
|
539 |
if (number_of_columns<2) return; |
|
540 |
||
541 |
//calculate column width |
|
542 |
TInt column_width=CShell::TheConsole->ScreenSize().iWidth/number_of_columns; |
|
543 |
||
544 |
TInt current_source_string=0; |
|
545 |
TInt current_destination_string=0; |
|
546 |
||
547 |
TInt count=aText.Count(); |
|
548 |
//join strings together into string which fits in a single line |
|
549 |
while (current_source_string<count) |
|
550 |
{ |
|
551 |
TPtr string= aText[current_destination_string++]->Des(); |
|
552 |
TInt to_skip=0; |
|
553 |
||
554 |
for (TInt i=0;i<number_of_columns;i++) |
|
555 |
{ |
|
556 |
if (current_source_string==count) |
|
557 |
break; |
|
558 |
//skip several characters to keep even distance between columns |
|
559 |
for (TInt j=0;j<to_skip;j++) |
|
560 |
string.Append(_L(" ")); |
|
561 |
||
562 |
if (i==0) |
|
563 |
string=(*aText[current_source_string]); |
|
564 |
else |
|
565 |
string.Append(*aText[current_source_string]); |
|
566 |
to_skip=column_width-aText[current_source_string]->Length(); |
|
567 |
current_source_string++; |
|
568 |
} |
|
569 |
} |
|
570 |
||
571 |
//resize aText array to the new size |
|
572 |
||
573 |
for (TInt j=aText.Count()-1;j>=current_destination_string;j--) |
|
574 |
{ |
|
575 |
delete aText[j]; |
|
576 |
aText.Remove(j); |
|
577 |
} |
|
578 |
||
579 |
} |
|
580 |
||
581 |
||
582 |
void ShellFunction::OutputContentsToConsole(RPointerArray<HBufC>& aText,TUint aSwitches) |
|
583 |
//outputs content of the buffer to console according to settings passed in aSwitches |
|
584 |
{ |
|
585 |
if ((aText.Count()>0)&&((aSwitches&TShellCommand::EWSwitch)!=0)) |
|
586 |
AlignTextIntoColumns(aText); |
|
587 |
||
588 |
for (TInt i=0;i<aText.Count();i++) |
|
589 |
{ |
|
590 |
CShell::OutputStringToConsole(((aSwitches&TShellCommand::EPSwitch)!=0),*aText[i]); |
|
591 |
CShell::OutputStringToConsole(EFalse,_L("\n")); |
|
592 |
delete aText[i]; |
|
593 |
} |
|
594 |
//empty string array |
|
595 |
aText.Reset(); |
|
596 |
} |
|
597 |
||
598 |
||
599 |
void ShellFunction::OutputDirContentL(CDir* aDirList,RPointerArray<HBufC>& aText,TUint aSwitches) |
|
600 |
//outputs content of a directory to console according to settings passed in aSwitches |
|
601 |
{ |
|
602 |
TInt count=aDirList->Count(); |
|
603 |
TInt fileCount=0, dirCount=0, printCount=0; |
|
604 |
TInt64 byteCount=0; |
|
605 |
||
606 |
//compose an array of strings describing entries in the directory |
|
607 |
for (TInt j=0;j<count;j++) |
|
608 |
{ |
|
609 |
HBufC* buf=NULL; |
|
610 |
TEntry entry=(*aDirList)[j]; |
|
611 |
TDateTime modTime=entry.iModified.DateTime(); |
|
612 |
if ((aSwitches&TShellCommand::EWSwitch)!=0)//if we are asked to output brief information about directory content |
|
613 |
{ |
|
614 |
TInt length=(KMaxFileName>CShell::TheConsole->ScreenSize().iWidth)?KMaxFileName:CShell::TheConsole->ScreenSize().iWidth; |
|
615 |
buf = HBufC::NewL(length); |
|
616 |
||
617 |
CleanupStack::PushL(buf); |
|
618 |
TPtr name=buf->Des(); |
|
619 |
name=entry.iName; |
|
620 |
||
621 |
if (entry.IsDir()) |
|
622 |
{ |
|
623 |
dirCount++; |
|
624 |
name.Insert(0,_L("[")); |
|
625 |
name.Append(']'); |
|
626 |
} |
|
627 |
else |
|
628 |
{ |
|
629 |
byteCount+=entry.FileSize(); |
|
630 |
fileCount++; |
|
631 |
} |
|
632 |
} |
|
633 |
else//if we are asked to output full information about directory content |
|
634 |
{ |
|
635 |
buf = HBufC::NewL(KMaxFileName+100);//reserve additional space for the creation time information |
|
636 |
CleanupStack::PushL(buf); |
|
637 |
TPtr name=buf->Des(); |
|
638 |
name=entry.iName; |
|
639 |
||
640 |
if (entry.IsDir()) |
|
641 |
{ |
|
642 |
dirCount++; |
|
643 |
name.Format(_L(" %- 26S <DIR> %+02d/%+02d/%- 4d %02d:%02d:%02d.%06d"), |
|
644 |
&entry.iName,modTime.Day()+1,modTime.Month()+1,modTime.Year(),modTime.Hour(),modTime.Minute(),modTime.Second(),modTime.MicroSecond()); |
|
645 |
} |
|
646 |
else |
|
647 |
{ |
|
648 |
TInt64 entrySize = entry.FileSize(); |
|
649 |
byteCount+=entrySize; |
|
650 |
fileCount++; |
|
651 |
name.Format(_L(" %- 32S%+ 15Lu %+02d/%+02d/%- 4d %02d:%02d:%02d.%06d"), |
|
652 |
&entry.iName,entrySize,modTime.Day()+1,modTime.Month()+1,modTime.Year(),modTime.Hour(),modTime.Minute(),modTime.Second(),modTime.MicroSecond()); |
|
653 |
} |
|
654 |
} |
|
655 |
User::LeaveIfError(aText.Append(buf )); |
|
656 |
printCount++; |
|
657 |
//print the contents if a screen size of data is available. This will prevent huge buffer allocation. |
|
658 |
if(printCount == CShell::TheConsole->ScreenSize().iHeight) |
|
659 |
{ |
|
660 |
OutputContentsToConsole(aText,aSwitches); |
|
661 |
printCount=0; |
|
662 |
} |
|
663 |
CleanupStack::Pop(); |
|
664 |
||
665 |
} |
|
666 |
OutputContentsToConsole(aText,aSwitches); |
|
667 |
||
668 |
//output summary information |
|
669 |
CShell::OutputStringToConsole(((aSwitches&TShellCommand::EPSwitch)!=0),_L(" %d File%c\n"),fileCount,(fileCount==1)?' ':'s'); |
|
670 |
if (fileCount!=0) |
|
671 |
{ |
|
672 |
CShell::OutputStringToConsole(((aSwitches&TShellCommand::EPSwitch)!=0),_L(" %lu byte%c\n"),byteCount,(fileCount==1)?' ':'s'); |
|
673 |
} |
|
674 |
||
675 |
TBuf<50> buf;// allocate string long enough for additional information(number of directories) |
|
676 |
buf.Format(_L(" %d Director"),dirCount); |
|
677 |
if (dirCount==1) |
|
678 |
buf.AppendFormat(_L("y\n")); |
|
679 |
else |
|
680 |
buf.AppendFormat(_L("ies\n")); |
|
681 |
||
682 |
CShell::OutputStringToConsole(((aSwitches&TShellCommand::EPSwitch)!=0),buf); |
|
683 |
} |
|
684 |
||
685 |
TInt ShellFunction::Dir(TDes& aPath,TUint aSwitches) |
|
686 |
// |
|
687 |
// Modified December 1997, to sort entries alphabetically |
|
688 |
// |
|
689 |
{ |
|
690 |
ShellFunction::StripQuotes(aPath); |
|
691 |
||
692 |
RDir dir; |
|
693 |
RFile64 file; |
|
694 |
TParse dirParse; |
|
695 |
// Parses the given path to give a full path |
|
696 |
GetFullPath(aPath,dirParse); |
|
697 |
// Sets aPath to a full path name |
|
698 |
aPath=dirParse.FullName(); |
|
699 |
if (aPath[aPath.Length()-1]==KPathDelimiter) |
|
700 |
aPath.Append('*'); |
|
701 |
else if (aPath.Locate(KMatchAny)==KErrNotFound && aPath.Locate(KMatchOne)==KErrNotFound && file.Open(TheShell->TheFs,aPath,KEntryAttMatchExclude|KEntryAttDir)!=KErrNone) |
|
702 |
aPath.Append(_L("\\*")); |
|
703 |
else file.Close(); |
|
704 |
||
705 |
TInt r=dir.Open(TheShell->TheFs,aPath,KEntryAttMaskSupported); |
|
706 |
if (r!=KErrNone) |
|
707 |
{ |
|
708 |
CShell::TheConsole->Printf(_L("File or directory not found\n")); |
|
709 |
return(KErrNone); |
|
710 |
} |
|
711 |
||
712 |
CDir* anEntryList; |
|
713 |
r=TheShell->TheFs.GetDir(aPath,KEntryAttMaskSupported,ESortByName,anEntryList); |
|
714 |
if (r!=KErrNone) |
|
715 |
{ |
|
716 |
dir.Close(); |
|
717 |
return(r); |
|
718 |
} |
|
719 |
CleanupStack::PushL(anEntryList); |
|
720 |
||
721 |
//Sets the new length of path to the position of the last path delimiter +1 |
|
722 |
aPath.SetLength(aPath.LocateReverse(KPathDelimiter)+1); |
|
723 |
CShell::TheConsole->Printf(_L("Directory of %S\n"),&aPath); |
|
724 |
||
725 |
//allocate array to be used as an output buffer |
|
726 |
RPointerArray<HBufC>* text=new(ELeave) RPointerArray<HBufC>(); |
|
727 |
TRAPD(error,OutputDirContentL(anEntryList,*text,aSwitches)); |
|
728 |
//we are not interesed in the error code because we need empty the buffer in any case |
|
729 |
for (TInt i=0;i<text->Count();i++) |
|
730 |
delete (*text)[i]; |
|
731 |
delete text; |
|
732 |
CleanupStack::PopAndDestroy(anEntryList); |
|
733 |
dir.Close(); |
|
734 |
if (error ) |
|
735 |
return (error); |
|
736 |
else |
|
737 |
return(KErrNone); |
|
738 |
}; |
|
739 |
||
740 |
||
741 |
TInt ShellFunction::Edit(TDes& /*aPath*/,TUint /*aSwitches*/) |
|
742 |
// |
|
743 |
// Dummy, used by edlin (now retired) |
|
744 |
// |
|
745 |
{ |
|
746 |
return(KErrNone); |
|
747 |
} |
|
748 |
||
749 |
||
750 |
TInt ShellFunction::Attrib(TDes& aPath,TUint aSwitches) |
|
751 |
{ |
|
752 |
ShellFunction::StripQuotes(aPath); |
|
753 |
||
754 |
// Use TWord::NextWord(aPath) to find any spaces in the command line |
|
755 |
TWord nextWord(aPath); |
|
756 |
TInt r=nextWord.FindNextWord(aPath); |
|
757 |
TInt signal=0; |
|
758 |
const TPtrC settings[8]={(_L("+R")),(_L("-R")),(_L("+H")),(_L("-H")),(_L("+S")),(_L("-S")),(_L("+A")),(_L("-A"))}; |
|
759 |
TInt numberOfSettings=(sizeof(settings)/sizeof(*settings)); |
|
760 |
||
761 |
if (r==KErrNotFound) // User just typed ATTRIB |
|
762 |
aPath.SetLength(aPath.Length()); |
|
763 |
else if (r==0) // User typed ATTRIB aWord |
|
764 |
{ // Check the word for a valid attributes |
|
765 |
for (TInt index=0; index<numberOfSettings; index++) |
|
766 |
{ |
|
767 |
signal=(nextWord.iNextWord).FindF(settings[index]); |
|
768 |
if (signal!=KErrNotFound) |
|
769 |
break; |
|
770 |
} |
|
771 |
if (signal==KErrNotFound) // No valid attributes settings |
|
772 |
aPath.SetLength(aPath.Length()); |
|
773 |
else // Valid attributes settings |
|
774 |
aPath.SetLength(r); |
|
775 |
} |
|
776 |
else // User typed ATTRIB aWord1 aWord2 |
|
777 |
{ // Check the word for a valid attributes switch |
|
778 |
while (r!=KErrNotFound) |
|
779 |
{ |
|
780 |
for (TInt index=0; index<numberOfSettings; index++) |
|
781 |
{ |
|
782 |
signal=(nextWord.iNextWord).FindF(settings[index]); |
|
783 |
if (signal!=KErrNotFound) |
|
784 |
break; |
|
785 |
} |
|
786 |
if (signal!=KErrNotFound) // Matched valid switches |
|
787 |
{ |
|
788 |
// Divide up command line |
|
789 |
// Include all settings (in case of "ATTRIB aWord +R +S") |
|
790 |
nextWord.iRightString=aPath.Right(aPath.Length()-r); |
|
791 |
aPath.SetLength(r); |
|
792 |
break; |
|
793 |
} |
|
794 |
else // No valid switches found in word |
|
795 |
r=nextWord.FindNextWord(nextWord.iRightString); // Check the next word |
|
796 |
if (r==0) // Reached the end of a spaced command line without finding settings |
|
797 |
{ |
|
798 |
nextWord.iRightString=aPath.Right(r); |
|
799 |
break; |
|
800 |
} |
|
801 |
} |
|
802 |
} |
|
803 |
||
804 |
TParse dirParse; |
|
805 |
GetFullPath(aPath,dirParse); |
|
806 |
aPath=dirParse.FullName(); |
|
807 |
||
808 |
RFile64 file; |
|
809 |
if (aPath[aPath.Length()-1]==KPathDelimiter) |
|
810 |
aPath.Append('*'); |
|
811 |
else if( (aPath.Locate(KMatchAny)==KErrNotFound) && (aPath.Locate(KMatchOne)==KErrNotFound) ) |
|
812 |
{ |
|
813 |
TInt error=file.Open(TheShell->TheFs,aPath,KEntryAttMatchExclude|KEntryAttDir); |
|
814 |
if (error!=KErrNone) |
|
815 |
aPath.Append(_L("\\*"));//Path does not end in a valid file |
|
816 |
else |
|
817 |
file.Close();// Path ends in a valid file |
|
818 |
} |
|
819 |
||
820 |
// Changes attributes settings (files only) if requested and if necessary |
|
821 |
if (r!=KErrNotFound) |
|
822 |
{ |
|
823 |
CDir* entryList; |
|
824 |
r=CShell::TheFs.GetDir(aPath,KEntryAttMaskSupported,ESortByName,entryList); |
|
825 |
if (r!=KErrNone) |
|
826 |
return (r); |
|
827 |
CleanupStack::PushL(entryList); |
|
828 |
TInt entryCount=entryList->Count(); |
|
829 |
// Save session path |
|
830 |
TBuf<KShellMaxCommandLine> aSessionPath; |
|
831 |
r=TheShell->TheFs.SessionPath(aSessionPath); |
|
832 |
// Temporarily assign session path to be the path requested |
|
833 |
// Use the heap as we're running out of stack space |
|
834 |
HBufC* pTempPath=NULL; |
|
835 |
TRAP(r,pTempPath=HBufC::NewL(aPath.Length())) |
|
836 |
if (r!=KErrNone) |
|
837 |
{ |
|
838 |
CleanupStack::PopAndDestroy(entryList); |
|
839 |
return (r); |
|
840 |
} |
|
841 |
*pTempPath=aPath; |
|
842 |
pTempPath->Des().SetLength(aPath.LocateReverse(KPathDelimiter)+1); |
|
843 |
r=TheShell->TheFs.SetSessionPath(pTempPath->Des()); |
|
844 |
User::Free(pTempPath); |
|
845 |
||
846 |
// Looks clumsy, but necessary to change attributes of files in higher level directories |
|
847 |
for (TInt i=0;i<entryCount;i++) |
|
848 |
{ |
|
849 |
TEntry entry=(*entryList)[i]; |
|
850 |
if (!entry.IsDir()) |
|
851 |
{ |
|
852 |
for (TInt index=0; index<numberOfSettings; index++) |
|
853 |
{ |
|
854 |
TInt attToSet=0; |
|
855 |
TInt attToRemove=0; |
|
856 |
signal=(nextWord.iRightString).FindF(settings[index]); |
|
857 |
if (signal==KErrNotFound) |
|
858 |
continue; |
|
859 |
else |
|
860 |
switch (index) |
|
861 |
{ |
|
862 |
case 0: |
|
863 |
attToSet|=KEntryAttReadOnly; |
|
864 |
break; |
|
865 |
case 1: |
|
866 |
attToRemove|=KEntryAttReadOnly; |
|
867 |
break; |
|
868 |
case 2: |
|
869 |
attToSet|=KEntryAttHidden; |
|
870 |
break; |
|
871 |
case 3: |
|
872 |
attToRemove|=KEntryAttHidden; |
|
873 |
break; |
|
874 |
case 4: |
|
875 |
attToSet|=KEntryAttSystem; |
|
876 |
break; |
|
877 |
case 5: |
|
878 |
attToRemove|=KEntryAttSystem; |
|
879 |
break; |
|
880 |
case 6: |
|
881 |
attToSet|=KEntryAttArchive; |
|
882 |
break; |
|
883 |
case 7: |
|
884 |
attToRemove|=KEntryAttArchive; |
|
885 |
break; |
|
886 |
default: // Will never reach here |
|
887 |
break; |
|
888 |
} |
|
889 |
r=TheShell->TheFs.SetAtt((entry.iName),attToSet,attToRemove); |
|
890 |
continue; |
|
891 |
} |
|
892 |
} |
|
893 |
else continue; |
|
894 |
} |
|
895 |
// Set session path to previous setting |
|
896 |
r=TheShell->TheFs.SetSessionPath(aSessionPath); |
|
897 |
CleanupStack::PopAndDestroy(entryList); |
|
898 |
} |
|
899 |
||
900 |
// Runs to here if no requested attributes changes: |
|
901 |
CDir* alphaEntryList; |
|
902 |
r=CShell::TheFs.GetDir(aPath,KEntryAttMaskSupported,ESortByName,alphaEntryList); |
|
903 |
if (r!=KErrNone) |
|
904 |
return (r); |
|
905 |
TInt count=alphaEntryList->Count(); |
|
906 |
||
907 |
RDir dir; |
|
908 |
r=dir.Open(TheShell->TheFs,aPath,KEntryAttMaskSupported); |
|
909 |
if (r!=KErrNone) |
|
910 |
{ |
|
911 |
delete alphaEntryList; |
|
912 |
return(r); |
|
913 |
} |
|
914 |
||
915 |
aPath.SetLength(aPath.LocateReverse(KPathDelimiter)+1); |
|
916 |
||
917 |
||
918 |
TEntry entry; |
|
919 |
TUint fileCount=0; |
|
920 |
||
921 |
// Lists attributes settings (files only) |
|
922 |
for (TInt j=0;j<count;j++) |
|
923 |
{ |
|
924 |
entry=alphaEntryList->operator[](j); |
|
925 |
if (!entry.IsDir()) |
|
926 |
{ |
|
927 |
TBuf<4> attrBuf=entry.IsReadOnly()?_L("R"):_L(""); |
|
928 |
if (entry.IsHidden()) |
|
929 |
attrBuf.Append('H'); |
|
930 |
if (entry.IsSystem()) |
|
931 |
attrBuf.Append('S'); |
|
932 |
if (entry.IsArchive()) |
|
933 |
attrBuf.Append('A'); |
|
934 |
CShell::OutputStringToConsole(((aSwitches&TShellCommand::EPSwitch)!=0),_L(" %-10S %S%S\n"),&attrBuf, &aPath,&entry.iName); |
|
935 |
fileCount++; |
|
936 |
} |
|
937 |
} |
|
938 |
||
939 |
dir.Close(); |
|
940 |
||
941 |
if (fileCount==0) |
|
942 |
CShell::OutputStringToConsole(((aSwitches&TShellCommand::EPSwitch)!=0),_L("No files found in %S\n"),&aPath); |
|
943 |
||
944 |
delete alphaEntryList; |
|
945 |
return(KErrNone); |
|
946 |
} |
|
947 |
||
948 |
||
949 |
||
950 |
||
951 |
||
952 |
//-------------------------------------------------------- |
|
953 |
||
954 |
/** |
|
955 |
Format TMediaType description. |
|
956 |
||
957 |
@param aDrvInfo drive info structure |
|
958 |
@param aPrintBuf buffer where the information will be printed to. |
|
959 |
*/ |
|
960 |
void FormatDrvMediaTypeInfo(const TDriveInfo& aDrvInfo, TDes& aPrintBuf) |
|
961 |
{ |
|
962 |
aPrintBuf.Format(_L("TMediaType:%d "),aDrvInfo.iType); |
|
963 |
||
964 |
switch(aDrvInfo.iType) |
|
965 |
{ |
|
966 |
case EMediaNotPresent: aPrintBuf.Append(_L("EMediaNotPresent")); break; |
|
967 |
case EMediaUnknown: aPrintBuf.Append(_L("EMediaUnknown")); break; |
|
968 |
case EMediaFloppy: aPrintBuf.Append(_L("EMediaFloppy")); break; |
|
969 |
case EMediaHardDisk: aPrintBuf.Append(_L("EMediaHardDisk")); break; |
|
970 |
case EMediaCdRom: aPrintBuf.Append(_L("EMediaCdRom")); break; |
|
971 |
case EMediaRam: aPrintBuf.Append(_L("EMediaRam")); break; |
|
972 |
case EMediaFlash: aPrintBuf.Append(_L("EMediaFlash")); break; |
|
973 |
case EMediaRom: aPrintBuf.Append(_L("EMediaRom")); break; |
|
974 |
case EMediaRemote: aPrintBuf.Append(_L("EMediaRemote")); break; |
|
975 |
case EMediaNANDFlash: aPrintBuf.Append(_L("EMediaNANDFlash")); break; |
|
976 |
case EMediaRotatingMedia: aPrintBuf.Append(_L("EMediaRotatingMedia"));break; |
|
977 |
||
978 |
default: aPrintBuf.Append(_L("??? Unknown Type")); break; |
|
979 |
}; |
|
980 |
||
981 |
||
982 |
aPrintBuf.Append(_L("\n")); |
|
983 |
} |
|
984 |
||
985 |
//-------------------------------------------------------- |
|
986 |
||
987 |
/** |
|
988 |
Format DriveAtt description. |
|
989 |
||
990 |
@param aDrvInfo drive info structure |
|
991 |
@param aPrintBuf buffer where the information will be printed to. |
|
992 |
*/ |
|
993 |
void FormatDriveAttInfo(const TDriveInfo& aDrvInfo, TDes& aPrintBuf) |
|
994 |
{ |
|
995 |
aPrintBuf.Format(_L("DriveAtt:0x%x "),aDrvInfo.iDriveAtt); |
|
996 |
||
997 |
if(aDrvInfo.iDriveAtt & KDriveAttLocal) aPrintBuf.Append(_L("KDriveAttLocal,")); |
|
998 |
if(aDrvInfo.iDriveAtt & KDriveAttRom) aPrintBuf.Append(_L("KDriveAttRom,")); |
|
999 |
if(aDrvInfo.iDriveAtt & KDriveAttRedirected) aPrintBuf.Append(_L("KDriveAttRedirected,")); |
|
1000 |
if(aDrvInfo.iDriveAtt & KDriveAttSubsted) aPrintBuf.Append(_L("KDriveAttSubsted,")); |
|
1001 |
if(aDrvInfo.iDriveAtt & KDriveAttInternal) aPrintBuf.Append(_L("KDriveAttInternal,")); |
|
1002 |
if(aDrvInfo.iDriveAtt & KDriveAttRemovable) aPrintBuf.Append(_L("KDriveAttRemovable")); |
|
1003 |
||
1004 |
if(aDrvInfo.iDriveAtt & KDriveAttRemote) aPrintBuf.Append(_L("KDriveAttRemote")); |
|
1005 |
if(aDrvInfo.iDriveAtt & KDriveAttTransaction) aPrintBuf.Append(_L("KDriveAttTransaction")); |
|
1006 |
||
1007 |
if(aDrvInfo.iDriveAtt & KDriveAttPageable) aPrintBuf.Append(_L("KDriveAttPageable")); |
|
1008 |
if(aDrvInfo.iDriveAtt & KDriveAttLogicallyRemovable) aPrintBuf.Append(_L("KDriveAttLogicallyRemovable")); |
|
1009 |
if(aDrvInfo.iDriveAtt & KDriveAttHidden) aPrintBuf.Append(_L("KDriveAttHidden")); |
|
1010 |
||
1011 |
aPrintBuf.Append(_L("\n")); |
|
1012 |
} |
|
1013 |
||
1014 |
//-------------------------------------------------------- |
|
1015 |
||
1016 |
/** |
|
1017 |
Format MediaAtt description. |
|
1018 |
||
1019 |
@param aDrvInfo drive info structure |
|
1020 |
@param aPrintBuf buffer where the information will be printed to. |
|
1021 |
*/ |
|
1022 |
void FormatMediaAttInfo(const TDriveInfo& aDrvInfo, TDes& aPrintBuf) |
|
1023 |
{ |
|
1024 |
aPrintBuf.Format(_L("MediaAtt:0x%x "),aDrvInfo.iMediaAtt); |
|
1025 |
||
1026 |
if(aDrvInfo.iMediaAtt & KMediaAttVariableSize) aPrintBuf.Append(_L("KMediaAttVariableSize,")); |
|
1027 |
if(aDrvInfo.iMediaAtt & KMediaAttDualDensity) aPrintBuf.Append(_L("KMediaAttDualDensity,")); |
|
1028 |
if(aDrvInfo.iMediaAtt & KMediaAttFormattable) aPrintBuf.Append(_L("KMediaAttFormattable,")); |
|
1029 |
if(aDrvInfo.iMediaAtt & KMediaAttWriteProtected) aPrintBuf.Append(_L("KMediaAttWriteProtected,")); |
|
1030 |
if(aDrvInfo.iMediaAtt & KMediaAttLockable) aPrintBuf.Append(_L("KMediaAttLockable,")); |
|
1031 |
if(aDrvInfo.iMediaAtt & KMediaAttLocked) aPrintBuf.Append(_L("KMediaAttLocked")); |
|
1032 |
||
1033 |
if(aDrvInfo.iMediaAtt & KMediaAttHasPassword) aPrintBuf.Append(_L("KMediaAttHasPassword")); |
|
1034 |
if(aDrvInfo.iMediaAtt & KMediaAttReadWhileWrite) aPrintBuf.Append(_L("KMediaAttReadWhileWrite")); |
|
1035 |
if(aDrvInfo.iMediaAtt & KMediaAttDeleteNotify) aPrintBuf.Append(_L("KMediaAttDeleteNotify")); |
|
1036 |
if(aDrvInfo.iMediaAtt & KMediaAttPageable) aPrintBuf.Append(_L("KMediaAttPageable")); |
|
1037 |
||
1038 |
||
1039 |
aPrintBuf.Append(_L("\n")); |
|
1040 |
} |
|
1041 |
||
1042 |
//-------------------------------------------------------- |
|
1043 |
||
1044 |
/** |
|
1045 |
Format TVolumeInfo description. |
|
1046 |
||
1047 |
@param volInfo volume information |
|
1048 |
@param aPrintBuf buffer where the information will be printed to. |
|
1049 |
*/ |
|
1050 |
void FormatVolInfo(const TVolumeInfo& volInfo , TDes& aPrintBuf) |
|
1051 |
{ |
|
1052 |
aPrintBuf.Format(_L("VolSz:%ld Free:%ld\n"),volInfo.iSize, volInfo.iFree); |
|
1053 |
aPrintBuf.AppendFormat(_L("VolId:0x%x VolName:%S\n"),volInfo.iUniqueID, &volInfo.iName); |
|
1054 |
} |
|
1055 |
||
1056 |
//-------------------------------------------------------- |
|
1057 |
||
1058 |
/** Bit flags that specify which information will be printed by PrintDrvInfo() */ |
|
1059 |
enum TPrintDrvInfoFlags |
|
1060 |
{ |
|
1061 |
EFSInfo = 0x01, //-- file system information |
|
1062 |
EFSInfoEx = 0x02, //-- extended file system information |
|
1063 |
EMediaTypeInfo = 0x04, //-- media type |
|
1064 |
EMediaAttInfo = 0x08, //-- media attributes etc. |
|
1065 |
EDrvAttInfo = 0x10, //-- drive attributes etc |
|
1066 |
EVolInfo = 0x20, //-- volume information |
|
1067 |
||
1068 |
EAll = 0xFFFF |
|
1069 |
}; |
|
1070 |
||
1071 |
//----------------------------------------------------------------------------------------------------------------------- |
|
1072 |
/** |
|
1073 |
Prints information about specified drive. |
|
1074 |
||
1075 |
@param aFs file system object |
|
1076 |
@param aDrvNum drive number |
|
1077 |
@param apConsole pointer to the console to print information into |
|
1078 |
@param aFlags specifies which information to print out, @see TPrintDrvInfoFlags |
|
1079 |
||
1080 |
@return standard error code |
|
1081 |
*/ |
|
1082 |
TInt PrintDrvInfo(RFs& aFs, TInt aDrvNum, CConsoleBase* apConsole, TUint aFlags = EAll) |
|
1083 |
{ |
|
1084 |
TInt nRes; |
|
1085 |
TDriveInfo driveInfo; |
|
1086 |
TVolumeInfo volInfo; |
|
1087 |
TBuf<256> Buf; |
|
1088 |
||
1089 |
//-- get drive info |
|
1090 |
nRes = aFs.Drive(driveInfo, aDrvNum); |
|
1091 |
if(nRes != KErrNone) |
|
1092 |
{ |
|
1093 |
CShell::TheConsole->Printf(_L("Error: %d\n"), nRes); |
|
1094 |
return nRes; //-- can't get information about the drive |
|
1095 |
} |
|
1096 |
||
1097 |
||
1098 |
nRes = aFs.Volume(volInfo, aDrvNum); |
|
1099 |
const TBool bVolumeOK = (nRes == KErrNone); |
|
1100 |
if(!bVolumeOK) |
|
1101 |
{//-- 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); |
|
1103 |
if(nRes == KErrCorrupt) |
|
1104 |
{ |
|
1105 |
CShell::TheConsole->Printf(_L("The volume might be corrupted or not formatted.\n")); |
|
1106 |
} |
|
1107 |
} |
|
1108 |
||
1109 |
||
1110 |
//-- Print out information about file system installed |
|
1111 |
if(aFlags & EFSInfo) |
|
1112 |
{ |
|
1113 |
||
1114 |
apConsole->Printf(_L("\nDrive %c: number:%d\n"), 'A'+aDrvNum, aDrvNum); |
|
1115 |
||
1116 |
//-- print the FS name |
|
1117 |
if(aFs.FileSystemName(Buf, aDrvNum) == KErrNone) |
|
1118 |
{ |
|
1119 |
TFSName fsName; |
|
1120 |
||
1121 |
nRes = aFs.FileSystemSubType(aDrvNum, fsName); |
|
1122 |
if(nRes == KErrNone && Buf.CompareF(fsName) !=KErrNone) |
|
1123 |
{ |
|
1124 |
Buf.AppendFormat(_L(" (%S)"), &fsName); |
|
1125 |
} |
|
1126 |
||
1127 |
//-- try to find out primary extension name if present |
|
1128 |
nRes = aFs.ExtensionName(fsName, aDrvNum, 0); |
|
1129 |
if(nRes == KErrNone) |
|
1130 |
{ |
|
1131 |
Buf.AppendFormat(_L(" PExt:%S"), &fsName); |
|
1132 |
} |
|
1133 |
||
1134 |
||
1135 |
apConsole->Printf(_L("Mounted FS:%S\n"), &Buf); |
|
1136 |
||
1137 |
//-- print out the list of supported file systems if there are more than 1 |
|
1138 |
nRes = aFs.SupportedFileSystemName(fsName, aDrvNum, 0+1); //-- try to get 2nd child name |
|
1139 |
if(nRes == KErrNone) |
|
1140 |
{ |
|
1141 |
Buf.Copy(_L("Supported FS: ")); |
|
1142 |
for(TInt i=0; ;++i) |
|
1143 |
{ |
|
1144 |
nRes = aFs.SupportedFileSystemName(fsName, aDrvNum, i); |
|
1145 |
if(nRes != KErrNone) |
|
1146 |
break; |
|
1147 |
||
1148 |
Buf.AppendFormat(_L("%S, "), &fsName); |
|
1149 |
} |
|
1150 |
||
1151 |
Buf.Append(_L("\n")); |
|
1152 |
apConsole->Printf(Buf); |
|
1153 |
} |
|
1154 |
||
1155 |
||
1156 |
||
1157 |
//-- print out FileSystem volume finalisation info |
|
1158 |
if(bVolumeOK && (aFlags & EFSInfoEx)) |
|
1159 |
{ |
|
1160 |
||
1161 |
TPckgBuf<TBool> boolPckg; |
|
1162 |
nRes = aFs.QueryVolumeInfoExt(aDrvNum, EIsDriveFinalised, boolPckg); |
|
1163 |
if(nRes == KErrNone) |
|
1164 |
{ |
|
1165 |
if(boolPckg() >0) |
|
1166 |
apConsole->Printf(_L("Volume Finalised\n")); |
|
1167 |
else |
|
1168 |
apConsole->Printf(_L("Volume Not finalised\n")); |
|
1169 |
} |
|
1170 |
} |
|
1171 |
} |
|
1172 |
}//if(aFlags & EFSInfo) |
|
1173 |
||
1174 |
//-- print media attributes |
|
1175 |
if(aFlags & EMediaTypeInfo) |
|
1176 |
{ |
|
1177 |
FormatDrvMediaTypeInfo(driveInfo, Buf); |
|
1178 |
apConsole->Printf(Buf); |
|
1179 |
||
1180 |
} |
|
1181 |
||
1182 |
//-- print drive attributes |
|
1183 |
if(aFlags & EDrvAttInfo) |
|
1184 |
{ |
|
1185 |
FormatDriveAttInfo(driveInfo, Buf); |
|
1186 |
apConsole->Printf(Buf); |
|
1187 |
} |
|
1188 |
||
1189 |
//-- print media attributes |
|
1190 |
if(aFlags & EMediaAttInfo) |
|
1191 |
{ |
|
1192 |
FormatMediaAttInfo(driveInfo, Buf); |
|
1193 |
apConsole->Printf(Buf); |
|
1194 |
} |
|
1195 |
||
1196 |
||
1197 |
//-- print volume information |
|
1198 |
if(bVolumeOK && (aFlags & EVolInfo)) |
|
1199 |
{ |
|
1200 |
FormatVolInfo(volInfo, Buf); |
|
1201 |
apConsole->Printf(Buf); |
|
1202 |
} |
|
1203 |
||
1204 |
return KErrNone; |
|
1205 |
} |
|
1206 |
||
1207 |
//----------------------------------------------------------------------------------------------------------------------- |
|
1208 |
||
1209 |
/** |
|
1210 |
Extracts drive specifier from the given string that shall look like 'd:\' or 'd:' |
|
1211 |
And converts it to the drive number. |
|
1212 |
||
1213 |
@param aStr a string with drive specifier |
|
1214 |
@return Drive number EDriveA..EDriveZ if drive letter is correct |
|
1215 |
negative value (KErrArgument) if drive specifier is incorrect |
|
1216 |
*/ |
|
1217 |
TInt DoExtractDriveLetter(const TDesC& aStr) |
|
1218 |
{ |
|
1219 |
TLex lex(aStr); |
|
1220 |
TPtrC token; |
|
1221 |
||
1222 |
lex.SkipSpace(); |
|
1223 |
token.Set(lex.NextToken()); |
|
1224 |
||
1225 |
if(token.Length() < 2 || token.Length() > 3 || token[1] != ':') |
|
1226 |
return KErrArgument; |
|
1227 |
||
1228 |
if(token.Length() == 3 && token[2] != '\\') |
|
1229 |
return KErrArgument; |
|
1230 |
||
1231 |
const TChar chDrv = token[0]; |
|
1232 |
const TInt drvNum = chDrv.GetUpperCase() - (TUint)'A'; //-- drive number |
|
1233 |
||
1234 |
if(drvNum < 0 || drvNum > EDriveZ) |
|
1235 |
return KErrArgument; |
|
1236 |
||
1237 |
||
1238 |
//-- ensure that the only drive token specified |
|
1239 |
token.Set(lex.NextToken()); |
|
1240 |
if(token.Length()) |
|
1241 |
return KErrArgument; |
|
1242 |
||
1243 |
return drvNum; |
|
1244 |
||
1245 |
} |
|
1246 |
||
1247 |
||
1248 |
//----------------------------------------------------------------------------------------------------------------------- |
|
1249 |
// |
|
1250 |
// Print information about specified drive or about all present drives in the system. |
|
1251 |
// |
|
1252 |
// DRVINFO [DriveLetter:[\]] [/p] |
|
1253 |
// |
|
1254 |
// if drive letter is specified print out information about only this one. |
|
1255 |
// /P : pause after each drive |
|
1256 |
// |
|
1257 |
TInt ShellFunction::DrvInfo(TDes& aArgs, TUint aSwitches) |
|
1258 |
{ |
|
1259 |
||
1260 |
TInt nDrv=-1; |
|
1261 |
||
1262 |
const TInt KCmdLineLen = aArgs.Length(); |
|
1263 |
if(KCmdLineLen == 0) |
|
1264 |
{//-- print information about all drives in the system |
|
1265 |
nDrv = -1; |
|
1266 |
} |
|
1267 |
else |
|
1268 |
{//-- print info about specified drive |
|
1269 |
nDrv = DoExtractDriveLetter(aArgs); |
|
1270 |
if(nDrv < 0) |
|
1271 |
{ |
|
1272 |
CShell::TheConsole->Printf(_L("Invalid drive specifier!\n")); |
|
1273 |
return KErrNone; |
|
1274 |
} |
|
1275 |
} |
|
1276 |
||
1277 |
TInt nRes; |
|
1278 |
TDriveList driveList; |
|
1279 |
||
1280 |
//-- get drives list |
|
1281 |
nRes=TheShell->TheFs.DriveList(driveList); |
|
1282 |
if(nRes != KErrNone) |
|
1283 |
{ |
|
1284 |
CShell::TheConsole->Printf(_L("\nError: %d"), nRes); |
|
1285 |
return nRes; |
|
1286 |
} |
|
1287 |
||
1288 |
if(nDrv >=0) |
|
1289 |
{//-- the drive is specified |
|
1290 |
if(!driveList[nDrv]) |
|
1291 |
{ |
|
1292 |
CShell::TheConsole->Printf(_L("Invalid drive specification\n")); |
|
1293 |
return KErrNone; |
|
1294 |
} |
|
1295 |
||
1296 |
PrintDrvInfo(TheShell->TheFs, nDrv, CShell::TheConsole); |
|
1297 |
} |
|
1298 |
else |
|
1299 |
{//-- print information about all drives in the system |
|
1300 |
for (nDrv=0; nDrv < KMaxDrives; nDrv++) |
|
1301 |
{ |
|
1302 |
if(!driveList[nDrv]) |
|
1303 |
continue; //-- skip unexisting drive |
|
1304 |
||
1305 |
PrintDrvInfo(TheShell->TheFs, nDrv, CShell::TheConsole); |
|
1306 |
||
1307 |
if(aSwitches & TShellCommand::EPSwitch) |
|
1308 |
{//-- /p switch, pause after each drive |
|
1309 |
CShell::TheConsole->Printf(_L("\n--- press any key to continue or Esc to exit ---\n")); |
|
1310 |
||
1311 |
TKeyCode key = CShell::TheConsole->Getch(); |
|
1312 |
if (key==EKeyEscape) |
|
1313 |
break; |
|
1314 |
} |
|
1315 |
else |
|
1316 |
{ |
|
1317 |
CShell::TheConsole->Printf(_L("\n----------\n")); |
|
1318 |
} |
|
1319 |
} |
|
1320 |
} |
|
1321 |
||
1322 |
return KErrNone; |
|
1323 |
} |
|
1324 |
||
1325 |
//----------------------------------------------------------------------------------------------------------------------- |
|
1326 |
||
1327 |
/** |
|
1328 |
Just a helper method. Looks for a given pattern in the given string and returns the rest of the found token. |
|
1329 |
@param aSrc source string |
|
1330 |
@param aPattern pattern to look for |
|
1331 |
@param aToken if the aPattern is found in the string, will contain characters from the pattern end to the next space. |
|
1332 |
||
1333 |
@return EFalse if the aPattern wasn't found in aSrc |
|
1334 |
ETrue otherwise and the rest of the token in aToken |
|
1335 |
*/ |
|
1336 |
static TBool DoFindToken(const TDesC& aSrc, const TDesC& aPattern, TPtrC& aToken) |
|
1337 |
{ |
|
1338 |
TLex lex(aSrc); |
|
1339 |
TPtrC token; |
|
1340 |
||
1341 |
for(;;) |
|
1342 |
{ |
|
1343 |
lex.SkipSpace(); |
|
1344 |
token.Set(lex.NextToken()); |
|
1345 |
||
1346 |
if(token.Length() == 0) |
|
1347 |
return EFalse; |
|
1348 |
||
1349 |
if(token.FindF(aPattern) == 0) |
|
1350 |
{//-- found a requires patern, extract substring next to it |
|
1351 |
aToken.Set(token.Right(token.Length() - aPattern.Length())); |
|
1352 |
break; |
|
1353 |
} |
|
1354 |
||
1355 |
||
1356 |
} |
|
1357 |
||
1358 |
return ETrue; |
|
1359 |
} |
|
1360 |
||
1361 |
||
1362 |
||
1363 |
||
1364 |
||
1365 |
//----------------------------------------------------------------------------------------------------------------------- |
|
1366 |
TInt DoDismountFS(RFs& aFs, TInt aDrvNum) |
|
1367 |
{ |
|
1368 |
TInt nRes; |
|
1369 |
TBuf<40> fsName; |
|
1370 |
||
1371 |
nRes = aFs.FileSystemName(fsName, aDrvNum); |
|
1372 |
||
1373 |
if(nRes != KErrNone) |
|
1374 |
return KErrNotFound;//-- nothing to dismount |
|
1375 |
||
1376 |
nRes = aFs.DismountFileSystem(fsName, aDrvNum); |
|
1377 |
if(nRes != KErrNone) |
|
1378 |
{ |
|
1379 |
CShell::TheConsole->Printf(_L("Can't dismount FS!\n")); |
|
1380 |
return nRes; |
|
1381 |
} |
|
1382 |
else |
|
1383 |
{ |
|
1384 |
CShell::TheConsole->Printf(_L("'%S' filesystem dismounted from drive %c:\n"), &fsName, 'A'+aDrvNum); |
|
1385 |
return KErrNone; |
|
1386 |
} |
|
1387 |
} |
|
1388 |
||
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1389 |
//----------------------------------------------------------------------------------------------------------------------- |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1390 |
TInt DoRemountFS(RFs& aFs, TInt aDrvNum) |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1391 |
{ |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1392 |
TInt nRes; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1393 |
TBuf<40> fsName; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1394 |
TBuf<40> pextName; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1395 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1396 |
//-- 1. get file system name |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1397 |
nRes = aFs.FileSystemName(fsName, aDrvNum); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1398 |
if(nRes != KErrNone) |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1399 |
return KErrNotFound; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1400 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1401 |
//-- 2. find out if the drive sync/async |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1402 |
TPckgBuf<TBool> drvSyncBuf; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1403 |
TBool& drvSynch = drvSyncBuf(); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1404 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1405 |
nRes = aFs.QueryVolumeInfoExt(aDrvNum, EIsDriveSync, drvSyncBuf); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1406 |
if(nRes != KErrNone) |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1407 |
{//-- pretend that the drive is asynch. in the case of file system being corrupted. this is 99.9% true |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1408 |
drvSynch = EFalse; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1409 |
} |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1410 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1411 |
//-- 3. find out primary extension name if it is present; we will need to add it again when mounting the FS |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1412 |
//-- other extensions (non-primary) are not supported yet |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1413 |
nRes = aFs.ExtensionName(pextName, aDrvNum, 0); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1414 |
if(nRes != KErrNone) |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1415 |
{ |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1416 |
pextName.SetLength(0); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1417 |
} |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1418 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1419 |
//-- 3.1 check if the drive has non-primary extensions, fail in this case |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1420 |
{ |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1421 |
TBuf<40> extName; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1422 |
nRes = aFs.ExtensionName(extName, aDrvNum, 1); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1423 |
if(nRes == KErrNone) |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1424 |
{ |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1425 |
CShell::TheConsole->Printf(_L("Non-primary extensions are not supported!\n")); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1426 |
return KErrNotSupported; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1427 |
} |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1428 |
} |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1429 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1430 |
//-- 4. dismount the file system |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1431 |
nRes = DoDismountFS(aFs, aDrvNum); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1432 |
if(nRes != KErrNone) |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1433 |
return nRes; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1434 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1435 |
//-- 5. mount the FS back |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1436 |
if(pextName.Length() > 0) |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1437 |
{//-- we need to mount FS with the primary extension |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1438 |
nRes = aFs.AddExtension(pextName); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1439 |
if(nRes != KErrNone && nRes != KErrAlreadyExists) |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1440 |
{ |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1441 |
return nRes; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1442 |
} |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1443 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1444 |
nRes = aFs.MountFileSystem(fsName, pextName, aDrvNum, drvSynch); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1445 |
} |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1446 |
else |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1447 |
{//-- the FS did not have primary extension |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1448 |
nRes = aFs.MountFileSystem(fsName, aDrvNum, drvSynch); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1449 |
} |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1450 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1451 |
if(nRes == KErrNone) |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1452 |
{ |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1453 |
CShell::TheConsole->Printf(_L("mounted filesystem:%S\n"), &fsName); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1454 |
} |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1455 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1456 |
return nRes; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1457 |
} |
0 | 1458 |
|
1459 |
//----------------------------------------------------------------------------------------------------------------------- |
|
1460 |
/** |
|
1461 |
Mount or dismount the file system on the specified drive. |
|
1462 |
||
1463 |
MOUNT <DriveLetter:[\]> <FSY:xxx> <FS:yyy> [PEXT:zzz] [/S] [/U] |
|
1464 |
||
1465 |
xxx is the *.fsy file system plugin name, like "elocal.fsy" or "elocal" |
|
1466 |
yyy is the file system name that the fsy module exports, like "FAT" |
|
1467 |
zzz is the optional parameter that specifies primary extension name |
|
1468 |
||
1469 |
/u dismounts a filesystem on the specified drive; e.g. "mount d: /u" |
|
1470 |
/s for mounting FS specifies that the drive will be mounted as synchronous one. |
|
1471 |
/f for forcing mounting the FS; the previous one will be automatically dismounted |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1472 |
/r remount existing FS (dismount and mount it back) |
0 | 1473 |
*/ |
1474 |
TInt ShellFunction::MountFileSystem(TDes& aArgs, TUint aSwitches) |
|
1475 |
{ |
|
1476 |
ShellFunction::StripQuotes(aArgs); |
|
1477 |
aArgs.UpperCase(); |
|
1478 |
||
1479 |
TLex lex(aArgs); |
|
1480 |
TInt nRes; |
|
1481 |
TBuf<40> fsName; |
|
1482 |
RFs& fs = TheShell->TheFs; |
|
1483 |
||
1484 |
||
1485 |
//-- extract drive specification; this must be 1st token |
|
1486 |
_LIT(KErrInvalidDrive, "Invalid drive specifier\n"); |
|
1487 |
lex.SkipSpace(); |
|
1488 |
TPtrC token = lex.NextToken(); |
|
1489 |
||
1490 |
nRes = DoExtractDriveLetter(token); |
|
1491 |
if(nRes < 0) |
|
1492 |
{ |
|
1493 |
CShell::TheConsole->Printf(KErrInvalidDrive); |
|
1494 |
return KErrArgument; |
|
1495 |
} |
|
1496 |
||
1497 |
const TInt drvNum = nRes; //-- this is the drive number; |
|
1498 |
||
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1499 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1500 |
//-- remounting the existing FS (/R switch) |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1501 |
if(aSwitches & TShellCommand::ERSwitch) |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1502 |
{ |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1503 |
nRes = DoRemountFS(fs, drvNum); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1504 |
return nRes; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1505 |
} |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1506 |
|
0 | 1507 |
//-- check if we dismounting the FS (/U switch) |
1508 |
if(aSwitches & TShellCommand::EUSwitch) |
|
1509 |
{ |
|
1510 |
nRes = DoDismountFS(fs, drvNum); |
|
1511 |
||
1512 |
if(nRes == KErrNotFound) |
|
1513 |
{//-- nothing to dismount |
|
1514 |
CShell::TheConsole->Printf(_L("specified drive doesn't have FS mounted\n")); |
|
1515 |
return KErrNone; |
|
1516 |
} |
|
1517 |
||
1518 |
return nRes; |
|
1519 |
} |
|
1520 |
||
1521 |
//-- check if we need to forcedly dismount the existing FS (/F switch) |
|
1522 |
if(aSwitches & TShellCommand::EFSwitch) |
|
1523 |
{ |
|
1524 |
nRes = DoDismountFS(fs, drvNum); |
|
1525 |
||
1526 |
if(nRes != KErrNotFound && nRes !=KErrNone) |
|
1527 |
return nRes; |
|
1528 |
} |
|
1529 |
||
1530 |
//-- request to mount the filesystem |
|
1531 |
||
1532 |
//-- 1. check that the specified drive doesn't have already mounted file system |
|
1533 |
nRes = fs.FileSystemName(fsName, drvNum); |
|
1534 |
if(nRes == KErrNone) |
|
1535 |
{ |
|
1536 |
CShell::TheConsole->Printf(_L("specified drive already has '%S' file system mounted.\n"), &fsName); |
|
1537 |
CShell::TheConsole->Printf(_L("Dismount it first using '/U' switch or use '/F' switch.\n")); |
|
1538 |
return KErrNone; |
|
1539 |
} |
|
1540 |
||
1541 |
//-- 2. check '/S' switch that specifies synchronous drive |
|
1542 |
const TBool bDrvSynch = aSwitches & TShellCommand::ESSwitch; |
|
1543 |
||
1544 |
//-- 3. extract FSY name, file system name and optional primary extension name from the command line parameters |
|
1545 |
_LIT(KFSY_Param, "fsy:"); |
|
1546 |
_LIT(KFsName_Param, "fs:"); |
|
1547 |
_LIT(KPrimExt_Param, "pext:"); |
|
1548 |
||
1549 |
TPtrC ptrFSYName; |
|
1550 |
TPtrC ptrFSName; |
|
1551 |
TPtrC ptrPExtName; |
|
1552 |
||
1553 |
if(!DoFindToken(aArgs, KFSY_Param, ptrFSYName)) |
|
1554 |
{//-- FSY plugin name, like "elocal.fsy" |
|
1555 |
CShell::TheConsole->Printf(_L("'%S' parameter is required!\n"), &KFSY_Param); |
|
1556 |
return KErrNone; |
|
1557 |
} |
|
1558 |
||
1559 |
if(!DoFindToken(aArgs, KFsName_Param, ptrFSName)) |
|
1560 |
{//-- file system name, like "FAT" |
|
1561 |
CShell::TheConsole->Printf(_L("'%S' parameter is required!\n"), &KFsName_Param); |
|
1562 |
return KErrNone; |
|
1563 |
} |
|
1564 |
||
1565 |
//-- note: it is possible to find out the file system name from loaded .fsy plugin. |
|
1566 |
//-- but it will require some coding. Probably later. |
|
1567 |
||
1568 |
||
1569 |
//-- optional primary extension name, like "something.fxt" |
|
1570 |
const TBool bPExtPresent = DoFindToken(aArgs, KPrimExt_Param, ptrPExtName); |
|
1571 |
||
1572 |
||
1573 |
//-- add new file system + optional extension |
|
1574 |
nRes = fs.AddFileSystem(ptrFSYName); |
|
1575 |
if(nRes != KErrNone && nRes != KErrAlreadyExists) |
|
1576 |
{ |
|
1577 |
CShell::TheConsole->Printf(_L("Can't load '%S' file system plugin!\n"), &ptrFSYName); |
|
1578 |
return nRes; |
|
1579 |
} |
|
1580 |
||
1581 |
if(bPExtPresent) |
|
1582 |
{ |
|
1583 |
nRes = fs.AddExtension(ptrPExtName); |
|
1584 |
if(nRes != KErrNone && nRes != KErrAlreadyExists) |
|
1585 |
{ |
|
1586 |
CShell::TheConsole->Printf(_L("Can't load '%S' FS extension plugin!\n"), &ptrPExtName); |
|
1587 |
return nRes; |
|
1588 |
} |
|
1589 |
} |
|
1590 |
||
1591 |
//-- 4. mount new file system + optional primary extension |
|
1592 |
if(bPExtPresent) |
|
1593 |
{ |
|
1594 |
nRes = fs.MountFileSystem(ptrFSName, ptrPExtName, drvNum, bDrvSynch); |
|
1595 |
} |
|
1596 |
else |
|
1597 |
{ |
|
1598 |
nRes = fs.MountFileSystem(ptrFSName, drvNum, bDrvSynch); |
|
1599 |
} |
|
1600 |
||
1601 |
CShell::TheConsole->Printf(_L("Mounting new file system...\n")); |
|
1602 |
||
1603 |
if(nRes != KErrNone && nRes != KErrCorrupt) |
|
1604 |
{//-- KErrCorrupt might mean that the FS mounted OK onto the drive, but ve volume itself needs formatting |
|
1605 |
CShell::TheConsole->Printf(_L("Error mounting the filesystem! (%d)\n"), nRes); |
|
1606 |
return nRes; |
|
1607 |
} |
|
1608 |
||
1609 |
||
1610 |
PrintDrvInfo(fs, drvNum, CShell::TheConsole, EFSInfo | EVolInfo); |
|
1611 |
||
1612 |
return KErrNone; |
|
1613 |
} |
|
1614 |
||
1615 |
||
1616 |
//----------------------------------------------------------------------------------------------------------------------- |
|
1617 |
||
1618 |
/** |
|
1619 |
Format the specified disk |
|
1620 |
||
1621 |
FORMAT DriveLetter:[\] [fat12|fat16|fat32] [spc:X] [rs:Y] [ft:Z] [/Q] [/S] [/E] |
|
1622 |
||
1623 |
fat12|fat16|fat32 : specifies explicitly FAT type to format drive with (if it is a FAT drive) |
|
1624 |
spc:X "X" specifies FAT sectors per cluster, e.g. spc:16 |
|
1625 |
rs:Y "Y" specifies the number of reserved sectors (FAT FS only) |
|
1626 |
ft:Z "Z" specifies the number of FAT tables 1 or 2 (FAT FS only) |
|
1627 |
/Q : Quick Format |
|
1628 |
/S : Special Format |
|
1629 |
/E : Remove Password and Format |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1630 |
/F : force formatting, even if there are files opened on the drive |
0 | 1631 |
*/ |
1632 |
||
1633 |
TInt ShellFunction::Format(TDes& aPath, TUint aSwitches) |
|
1634 |
{ |
|
1635 |
_LIT(KFormatStars,"********************"); |
|
1636 |
||
1637 |
using namespace FileSystem_FAT; |
|
1638 |
||
1639 |
ShellFunction::StripQuotes(aPath); |
|
1640 |
aPath.UpperCase(); |
|
1641 |
||
1642 |
TUint fmtMode = ESpecialFormat; |
|
1643 |
||
1644 |
//-- Format /Q - quick format |
|
1645 |
if (aSwitches & TShellCommand::EQSwitch) |
|
1646 |
fmtMode|=EQuickFormat; |
|
1647 |
||
1648 |
//-- Format /S - special format |
|
1649 |
if (aSwitches & TShellCommand::ESSwitch) |
|
1650 |
fmtMode|=ESpecialFormat; |
|
1651 |
||
1652 |
//-- Format /E - force erase |
|
1653 |
if (aSwitches & TShellCommand::EESwitch) |
|
1654 |
fmtMode|=EForceErase; |
|
1655 |
||
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1656 |
//-- Format /F - force format. The volume will be formatted even if there are files or directories opened on this drive |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1657 |
if (aSwitches & TShellCommand::EFSwitch) |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1658 |
fmtMode|=EForceFormat; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1659 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1660 |
|
0 | 1661 |
TInt fmtCnt = 0; |
1662 |
RFormat format; |
|
1663 |
TInt nRes; |
|
1664 |
TLex lex(aPath); |
|
1665 |
||
1666 |
//-- 1st token - drive path; it shall look like "d:" |
|
1667 |
lex.SkipSpace(); |
|
1668 |
TPtrC ptrPath = lex.NextToken(); |
|
1669 |
||
1670 |
const TInt nDrv = DoExtractDriveLetter(ptrPath); |
|
1671 |
if(nDrv < 0 ) |
|
1672 |
{ |
|
1673 |
CShell::TheConsole->Printf(_L("type \"format /?\" for help.\n")); |
|
1674 |
return KErrNone; |
|
1675 |
} |
|
1676 |
||
1677 |
enum TFmtState |
|
1678 |
{ |
|
1679 |
EFsNameNotSpecified, |
|
1680 |
EFormattingFAT, |
|
1681 |
EFormattingOtherFS |
|
1682 |
}; |
|
1683 |
||
1684 |
||
1685 |
TFmtState formattingState = EFsNameNotSpecified; |
|
1686 |
TName fsName; //-- file system name |
|
1687 |
||
1688 |
||
1689 |
TVolFormatParamBuf volFmtParamBuf; |
|
1690 |
TVolFormatParam& volFmtParam = volFmtParamBuf(); |
|
1691 |
||
1692 |
||
1693 |
||
1694 |
//-- 2nd token - file system name. |
|
1695 |
//-- FAT fs is a special case, because it has subtypes; FAT FS name can be: FAT, FAT12, FAT16, FAT32 |
|
1696 |
//-- everything else is considered as another file system name |
|
1697 |
lex.SkipSpace(); |
|
1698 |
TPtrC ptrFsName = lex.NextToken(); |
|
1699 |
TFatSubType fatSubType = ENotSpecified; |
|
1700 |
||
1701 |
if(ptrFsName.Length() > 0) |
|
1702 |
{//-- there is a 2nd token, though it is not guaranteed to be the FS name |
|
1703 |
formattingState = EFormattingOtherFS; |
|
1704 |
||
1705 |
if(ptrFsName.FindF(KFileSystemName_FAT) == 0) |
|
1706 |
{//-- it looks like "FATxx" |
|
1707 |
fsName.Copy(KFileSystemName_FAT); |
|
1708 |
||
1709 |
if(ptrFsName.CompareF(KFileSystemName_FAT) == 0) |
|
1710 |
fatSubType = ENotSpecified; //-- generic "FAT", no subtype |
|
1711 |
else if(ptrFsName.CompareF(KFSSubType_FAT12) == 0) |
|
1712 |
fatSubType = EFat12; |
|
1713 |
else if(ptrFsName.CompareF(KFSSubType_FAT16) == 0) |
|
1714 |
fatSubType = EFat16; |
|
1715 |
else if(ptrFsName.CompareF(KFSSubType_FAT32) == 0) |
|
1716 |
fatSubType = EFat32; |
|
1717 |
else |
|
1718 |
fsName.Copy(ptrFsName); //-- none of the FAT types, probably some weird FS name. |
|
1719 |
} |
|
1720 |
else |
|
1721 |
{ |
|
1722 |
fsName.Copy(ptrFsName); |
|
1723 |
} |
|
1724 |
} |
|
1725 |
||
1726 |
if(fsName == KFileSystemName_FAT) |
|
1727 |
formattingState = EFormattingFAT; |
|
1728 |
||
1729 |
volFmtParam.Init(); |
|
1730 |
||
1731 |
if(formattingState != EFsNameNotSpecified) |
|
1732 |
volFmtParam.SetFileSystemName(fsName); |
|
1733 |
||
1734 |
//-- process formatting parameters if they are present |
|
1735 |
||
1736 |
_LIT(KTok_SPC, "spc:"); //-- "sectors per cluster"; valid for: FAT, exFAT |
|
1737 |
_LIT(KTok_RsvdSect, "rs:"); //-- "reserved sectors" ; valid for: FAT |
|
1738 |
_LIT(KTok_NumFATs, "ft:"); //-- "number of FATs" ; valid for: FAT, exFAT |
|
1739 |
_LIT(KFsNameExFat, "exfat"); |
|
1740 |
||
1741 |
TPtrC token; |
|
1742 |
TPtrC ptrParams = lex.Remainder(); |
|
1743 |
TLex lexParam; |
|
1744 |
TInt nVal; |
|
1745 |
||
1746 |
||
1747 |
//-- if we formatting FAT, process FAT-specific formatting parameters |
|
1748 |
if(formattingState == EFormattingFAT) |
|
1749 |
{ |
|
1750 |
//-- Changing base class via derived class interface is OK here, all derived classes has the same layout and size as TVolFormatParam |
|
1751 |
TVolFormatParam_FAT& volFmtParamFAT = (TVolFormatParam_FAT&)volFmtParam; |
|
1752 |
||
1753 |
volFmtParamFAT.Init(); |
|
1754 |
||
1755 |
//-- FAT sub type |
|
1756 |
if(fatSubType != ENotSpecified) |
|
1757 |
volFmtParamFAT.SetFatSubType(fatSubType); |
|
1758 |
||
1759 |
//-- process "Sectors per cluster" token |
|
1760 |
if(DoFindToken(ptrParams, KTok_SPC, token)) |
|
1761 |
{ |
|
1762 |
lexParam.Assign(token); |
|
1763 |
lexParam.SkipSpace(); |
|
1764 |
nRes = lexParam.Val(nVal); |
|
1765 |
if(nRes == KErrNone) |
|
1766 |
{ |
|
1767 |
volFmtParamFAT.SetSectPerCluster(nVal); |
|
1768 |
} |
|
1769 |
else |
|
1770 |
{ |
|
1771 |
CShell::TheConsole->Printf(_L("Invalid SectorsPerCluster value!\n")); |
|
1772 |
return KErrNone; |
|
1773 |
} |
|
1774 |
} |
|
1775 |
||
1776 |
//-- process "reserved sectors" token |
|
1777 |
if(DoFindToken(ptrParams, KTok_RsvdSect, token)) |
|
1778 |
{ |
|
1779 |
lexParam.Assign(token); |
|
1780 |
lexParam.SkipSpace(); |
|
1781 |
nRes = lexParam.Val(nVal); |
|
1782 |
if(nRes == KErrNone && nVal >0 ) |
|
1783 |
{ |
|
1784 |
volFmtParamFAT.SetReservedSectors(nVal); |
|
1785 |
} |
|
1786 |
else |
|
1787 |
{ |
|
1788 |
CShell::TheConsole->Printf(_L("Invalid Reserved Sectors value!\n")); |
|
1789 |
return KErrNone; |
|
1790 |
} |
|
1791 |
} |
|
1792 |
||
1793 |
//-- process "FAT tables" token |
|
1794 |
if(DoFindToken(ptrParams, KTok_NumFATs, token)) |
|
1795 |
{ |
|
1796 |
lexParam.Assign(token); |
|
1797 |
lexParam.SkipSpace(); |
|
1798 |
nRes = lexParam.Val(nVal); |
|
1799 |
if(nRes == KErrNone && nVal >= 1 && nVal <= 2) |
|
1800 |
{ |
|
1801 |
volFmtParamFAT.SetNumFATs(nVal); |
|
1802 |
} |
|
1803 |
else |
|
1804 |
{ |
|
1805 |
CShell::TheConsole->Printf(_L("Invalid FAT tables number value!\n")); |
|
1806 |
return KErrNone; |
|
1807 |
} |
|
1808 |
} |
|
1809 |
||
1810 |
}//if(formattingState == EFormattingFAT) |
|
1811 |
else if(formattingState == EFormattingOtherFS && fsName.CompareF(KFsNameExFat)==0) |
|
1812 |
{//-- this is actually a h***k. exFAT exported public header file with specific data structures might not be available at all. |
|
1813 |
||
1814 |
//-- this is more serious hack. The parameters layout (SPC & NumFatTables) in the structure is the same for FAT and exFAT |
|
1815 |
//-- use TVolFormatParam_FAT because this code doesn't know about TVolFormatParam_exFAT |
|
1816 |
TVolFormatParam_FAT& volFmtParamFAT = (TVolFormatParam_FAT&)volFmtParam; |
|
1817 |
||
1818 |
//-- process "Sectors per cluster" token |
|
1819 |
if(DoFindToken(ptrParams, KTok_SPC, token)) |
|
1820 |
{ |
|
1821 |
lexParam.Assign(token); |
|
1822 |
lexParam.SkipSpace(); |
|
1823 |
nRes = lexParam.Val(nVal); |
|
1824 |
if(nRes == KErrNone) |
|
1825 |
{ |
|
1826 |
volFmtParamFAT.SetSectPerCluster(nVal); |
|
1827 |
} |
|
1828 |
else |
|
1829 |
{ |
|
1830 |
CShell::TheConsole->Printf(_L("Invalid SectorsPerCluster value!\n")); |
|
1831 |
return KErrNone; |
|
1832 |
} |
|
1833 |
} |
|
1834 |
||
1835 |
//-- process "FAT tables" token |
|
1836 |
if(DoFindToken(ptrParams, KTok_NumFATs, token)) |
|
1837 |
{ |
|
1838 |
lexParam.Assign(token); |
|
1839 |
lexParam.SkipSpace(); |
|
1840 |
nRes = lexParam.Val(nVal); |
|
1841 |
if(nRes == KErrNone && nVal >= 1 && nVal <= 2) |
|
1842 |
{ |
|
1843 |
volFmtParamFAT.SetNumFATs(nVal); |
|
1844 |
} |
|
1845 |
else |
|
1846 |
{ |
|
1847 |
CShell::TheConsole->Printf(_L("Invalid FAT tables number value!\n")); |
|
1848 |
return KErrNone; |
|
1849 |
} |
|
1850 |
} |
|
1851 |
||
1852 |
} |
|
1853 |
||
1854 |
||
1855 |
//-------- actual formatting |
|
1856 |
if(formattingState == EFsNameNotSpecified) |
|
1857 |
{ |
|
1858 |
nRes = format.Open(TheShell->TheFs, ptrPath, fmtMode, fmtCnt); |
|
1859 |
} |
|
1860 |
else |
|
1861 |
{ |
|
1862 |
CShell::TheConsole->Printf(_L("The new file system is:%S\n"), &fsName); |
|
1863 |
nRes = format.Open(TheShell->TheFs, ptrPath, fmtMode, fmtCnt, volFmtParamBuf); |
|
1864 |
} |
|
1865 |
||
1866 |
if(nRes == KErrNone) |
|
1867 |
{ |
|
1868 |
while(fmtCnt && nRes == KErrNone) |
|
1869 |
{ |
|
1870 |
TInt length=(104-fmtCnt)/5; |
|
1871 |
length=Min(length,KFormatStars().Length()); |
|
1872 |
TPtrC stars=KFormatStars().Left(length); |
|
1873 |
CShell::TheConsole->Printf(_L("\r%S"),&stars); |
|
1874 |
nRes=format.Next(fmtCnt); |
|
1875 |
} |
|
1876 |
||
1877 |
format.Close(); |
|
1878 |
||
1879 |
if(nRes == KErrNone) |
|
1880 |
{ |
|
1881 |
CShell::TheConsole->Printf(_L("\r%S"),&KFormatStars); |
|
1882 |
CShell::NewLine(); |
|
1883 |
} |
|
1884 |
||
1885 |
} |
|
1886 |
||
1887 |
||
1888 |
//-- format errors processing |
|
1889 |
if(nRes != KErrNone) |
|
1890 |
{ |
|
1891 |
CShell::TheConsole->Printf(_L("Format failed.\n")); |
|
1892 |
} |
|
1893 |
||
1894 |
switch(nRes) |
|
1895 |
{ |
|
1896 |
case KErrNone: |
|
1897 |
CShell::TheConsole->Printf(_L("Format complete.\n")); |
|
1898 |
break; |
|
1899 |
||
1900 |
||
1901 |
case KErrArgument: //-- FORMAT has rejected specified parameters |
|
1902 |
CShell::TheConsole->Printf(_L("Possible reason: Invalid combination of formatting parameters.\n")); |
|
1903 |
nRes = KErrNone; |
|
1904 |
break; |
|
1905 |
||
1906 |
case KErrNotSupported: //-- trying to format SD card with parameters or not supported FS name specified |
|
1907 |
CShell::TheConsole->Printf(_L("Possible reasons: media does not support special formatting or specified file system is not supported\n")); |
|
1908 |
nRes = KErrNone; |
|
1909 |
break; |
|
1910 |
||
1911 |
case KErrNotFound: //-- possible reason: unrecognisable media and automounter FS + formatting without specifying the FS name |
|
1912 |
CShell::TheConsole->Printf(_L("Possible reason: Unable to chose appropriate file system (not specified)\n")); |
|
1913 |
nRes = KErrNone; |
|
1914 |
break; |
|
1915 |
||
1916 |
||
1917 |
default: |
|
1918 |
break; |
|
1919 |
}; |
|
1920 |
||
1921 |
||
1922 |
return nRes; |
|
1923 |
} |
|
1924 |
||
1925 |
//----------------------------------------------------------------------------------------------------------------------- |
|
1926 |
||
1927 |
TInt ShellFunction::Hexdump(TDes& aPath,TUint aSwitches) |
|
1928 |
{ |
|
1929 |
ShellFunction::StripQuotes(aPath); |
|
1930 |
||
1931 |
ParsePath(aPath); |
|
1932 |
RFile file; |
|
1933 |
TInt r=file.Open(TheShell->TheFs,aPath,EFileStream); |
|
1934 |
if (r!=KErrNone) |
|
1935 |
return(r); |
|
1936 |
||
1937 |
TInt offset=0; |
|
1938 |
for (;;) |
|
1939 |
{ |
|
1940 |
const TInt KLineLength = 16; |
|
1941 |
||
1942 |
TBuf8<KLineLength> line; |
|
1943 |
r=file.Read(line); |
|
1944 |
if (r != KErrNone || line.Length() == 0) |
|
1945 |
break; |
|
1946 |
||
1947 |
TBuf<KLineLength*3+2> hexaRep; |
|
1948 |
TBuf<KLineLength> asciiRep; |
|
1949 |
for (TInt i=0; i<KLineLength; i++) |
|
1950 |
{ |
|
1951 |
if (i == KLineLength/2) |
|
1952 |
{ |
|
1953 |
hexaRep.Append(' '); |
|
1954 |
hexaRep.Append(i<line.Length() ? '|' : ' '); |
|
1955 |
} |
|
1956 |
||
1957 |
hexaRep.Append(' '); |
|
1958 |
||
1959 |
if (i<line.Length()) |
|
1960 |
{ |
|
1961 |
hexaRep.AppendNumFixedWidth(line[i], EHex, 2); |
|
1962 |
asciiRep.Append(TChar(line[i]).IsPrint() ? line[i] : '.'); |
|
1963 |
} |
|
1964 |
else |
|
1965 |
hexaRep.AppendFill(' ', 2); |
|
1966 |
} |
|
1967 |
||
1968 |
_LIT(KPrompt , " Hit escape to quit hexdump or any other key to continue\n"); |
|
1969 |
_LIT(KLineFmt, " %+07x0:%S %S\n"); |
|
1970 |
TKeyCode key=CShell::OutputStringToConsole(KPrompt ,(aSwitches&TShellCommand::EPSwitch)!=0,KLineFmt, offset++,&hexaRep, &asciiRep); |
|
1971 |
||
1972 |
if (key==EKeyEscape) |
|
1973 |
break; |
|
1974 |
} |
|
1975 |
||
1976 |
if (r == KErrNone) |
|
1977 |
CShell::NewLine(); |
|
1978 |
||
1979 |
file.Close(); |
|
1980 |
return r; |
|
1981 |
} |
|
1982 |
||
1983 |
/** |
|
1984 |
Create a file. The file can be empty or filled with random data. |
|
1985 |
The maximal file size depends on the file system of the drive. |
|
1986 |
||
1987 |
Gobble <file name> <aaaa|0xbbbb> [/E] |
|
1988 |
||
1989 |
aaaa file size decimal |
|
1990 |
bbbb file size hexadecimal, shall be prefixed with '0x' |
|
1991 |
||
1992 |
/e for creating an empty file, do not fill it with data |
|
1993 |
*/ |
|
1994 |
TInt ShellFunction::Gobble(TDes& aPath,TUint aSwitches) |
|
1995 |
{ |
|
1996 |
ShellFunction::StripQuotes(aPath); |
|
1997 |
||
1998 |
TInt fileNameLen=aPath.LocateReverse(' '); |
|
1999 |
if (fileNameLen==KErrNotFound) // No spaces implies no filelength specified |
|
2000 |
{ |
|
2001 |
CShell::TheConsole->Printf(_L("Please specify a file name and a file length\n")); |
|
2002 |
return (KErrNone); |
|
2003 |
} |
|
2004 |
||
2005 |
TInt fileLength=(aPath.Length()-fileNameLen); |
|
2006 |
if (fileLength>16) |
|
2007 |
return (KErrTooBig); // Too many digits - too large! |
|
2008 |
TBuf<16> rightString=aPath.Right(fileLength); |
|
2009 |
aPath.SetLength(fileNameLen); |
|
2010 |
||
2011 |
TLex size(rightString); |
|
2012 |
size.SkipSpace(); |
|
2013 |
TRadix radix=ParseHexaPrefixIfAny(size); |
|
2014 |
||
2015 |
TInt64 fileSize; |
|
2016 |
TInt r=size.Val(fileSize,radix); |
|
2017 |
if (r!=KErrNone || ! size.Eos()) |
|
2018 |
{ |
|
2019 |
CShell::TheConsole->Printf(_L("Please specify a file length\n")); |
|
2020 |
return (KErrNone); |
|
2021 |
} |
|
2022 |
||
2023 |
if (aPath.Length()==0) |
|
2024 |
aPath=_L("GOBBLE.DAT"); |
|
2025 |
||
2026 |
TParse fileName; |
|
2027 |
GetFullPath(aPath,fileName); |
|
2028 |
RFile64 file; |
|
2029 |
||
2030 |
const TInt KBufSize=65536; //-- buffer size for writing data |
|
2031 |
const TUint32 K1Megabyte = 1<<20; //-- 1M, 1048576 |
|
2032 |
TInt64 cntBytes = 0; |
|
2033 |
TUint32 cntMegaBytes =0; |
|
2034 |
||
2035 |
//-- allocate buffer for data |
|
2036 |
RBuf8 buf; |
|
2037 |
r = buf.CreateMax(KBufSize); |
|
2038 |
if(r != KErrNone) |
|
2039 |
return r; |
|
2040 |
||
2041 |
//-- initialize buffer with random rubbish |
|
2042 |
//Mem::Fill((void*)buf.Ptr(),KBufSize,0xa3); |
|
2043 |
{ |
|
2044 |
TInt64 rndSeed = Math::Random(); |
|
2045 |
for(TInt i=0; i<KBufSize; ++i) |
|
2046 |
{ |
|
2047 |
buf[i] = (TUint8)Math::Rand(rndSeed); |
|
2048 |
} |
|
2049 |
} |
|
2050 |
||
2051 |
||
2052 |
TInt64 rem = fileSize; |
|
2053 |
TTime startTime; |
|
2054 |
TTime endTime; |
|
2055 |
TTimeIntervalSeconds timeTaken; |
|
2056 |
||
2057 |
startTime.UniversalTime(); //-- take start time |
|
2058 |
||
2059 |
r=file.Create(CShell::TheFs,fileName.FullName(),EFileRead|EFileWrite); |
|
2060 |
if(r != KErrNone) |
|
2061 |
goto fail; |
|
2062 |
||
2063 |
//-- this can make write faster on rugged fat. |
|
2064 |
if(aSwitches&TShellCommand::EESwitch) |
|
2065 |
{//-- /e switch is specified, create an empty file without writing data |
|
2066 |
CShell::TheConsole->Printf(_L("Creating an empty file, size:%LD bytes\n"), fileSize); |
|
2067 |
} |
|
2068 |
||
2069 |
r=file.SetSize(fileSize); |
|
2070 |
if(r != KErrNone) |
|
2071 |
goto fail; |
|
2072 |
||
2073 |
||
2074 |
if(!(aSwitches&TShellCommand::EESwitch)) |
|
2075 |
{//-- fill created file with randomn data |
|
2076 |
||
2077 |
while(rem) |
|
2078 |
{ |
|
2079 |
const TInt s=(TInt)Min((TInt64)KBufSize, rem); |
|
2080 |
||
2081 |
r=file.Write(buf, s); |
|
2082 |
if(r!=KErrNone) |
|
2083 |
goto fail; |
|
2084 |
||
2085 |
rem-=s; |
|
2086 |
||
2087 |
//-- print out number of megabytes written |
|
2088 |
cntBytes+=s; |
|
2089 |
if(cntBytes > 0 && (cntBytes & (K1Megabyte-1))==0) |
|
2090 |
{ |
|
2091 |
++cntMegaBytes; |
|
2092 |
CShell::TheConsole->Printf(_L("%u MB written.\n"),cntMegaBytes); |
|
2093 |
} |
|
2094 |
}//while(rem) |
|
2095 |
||
2096 |
} |
|
2097 |
||
2098 |
file.Close(); |
|
2099 |
endTime.UniversalTime(); //-- take end time |
|
2100 |
buf.Close(); |
|
2101 |
||
2102 |
endTime.SecondsFrom(startTime, timeTaken); |
|
2103 |
||
2104 |
CShell::TheConsole->Printf(_L("Total bytes written:%LD\n"), cntBytes); |
|
2105 |
CShell::TheConsole->Printf(_L("Time taken:%d Sec.\n"), timeTaken.Int()); |
|
2106 |
||
2107 |
return r; |
|
2108 |
||
2109 |
//-- failure. |
|
2110 |
fail: |
|
2111 |
file.Close(); |
|
2112 |
buf.Close(); |
|
2113 |
if(r!= KErrAlreadyExists) //this is to ensure that an existing file does not get deleted |
|
2114 |
CShell::TheFs.Delete(fileName.FullName()); |
|
2115 |
||
2116 |
CShell::TheConsole->Printf(_L("Error - could not create file, code:%d\n"), r); |
|
2117 |
||
2118 |
return r; |
|
2119 |
} |
|
2120 |
||
2121 |
TInt ShellFunction::Md(TDes& aPath,TUint /*aSwitches*/) |
|
2122 |
{ |
|
2123 |
if (aPath.Length()==0) |
|
2124 |
return(KErrBadName); |
|
2125 |
||
2126 |
ShellFunction::StripQuotes(aPath); |
|
2127 |
||
2128 |
if (aPath[aPath.Length()-1]!=KPathDelimiter) |
|
2129 |
aPath.Append(KPathDelimiter); |
|
2130 |
||
2131 |
TParse dirPath; |
|
2132 |
TInt r = GetFullPath(aPath,dirPath); |
|
2133 |
if(r!=KErrNone) |
|
2134 |
{ |
|
2135 |
return(r); |
|
2136 |
} |
|
2137 |
return(TheShell->TheFs.MkDir(dirPath.FullName())); |
|
2138 |
} |
|
2139 |
||
2140 |
TInt ShellFunction::Move(TDes& aPath,TUint aSwitches) |
|
2141 |
{ |
|
2142 |
||
2143 |
// Modified to add more helpful error messages and allow spaced filenames |
|
2144 |
ShellFunction::StripQuotes(aPath); |
|
2145 |
||
2146 |
TBuf<KShellMaxCommandLine> newName; |
|
2147 |
TBuf<KShellMaxCommandLine> tempPath=aPath; |
|
2148 |
RFile64 file; |
|
2149 |
TWord word(aPath); |
|
2150 |
||
2151 |
TInt r=word.FindNextWord(aPath); |
|
2152 |
// Check if the word returned is a valid filename. If not, scan the next |
|
2153 |
// word too in case the filename contains spaces. If, at the end of the |
|
2154 |
// the line, the filename is not recognised, it is invalid. If there are no |
|
2155 |
// spaces the user has not used the correct format for this command. |
|
2156 |
||
2157 |
while (r>0) |
|
2158 |
{ |
|
2159 |
newName=aPath.Right(aPath.Length()-r); |
|
2160 |
tempPath.SetLength(r); |
|
2161 |
TParse oldName; |
|
2162 |
TInt result=GetFullPath(tempPath,oldName); |
|
2163 |
if (result!=KErrNone) |
|
2164 |
return(r); |
|
2165 |
||
2166 |
TBool validFileOrDir = EFalse; |
|
2167 |
||
2168 |
result=file.Open(TheShell->TheFs,tempPath,KEntryAttMatchExclude|KEntryAttDir); |
|
2169 |
if (result==KErrNone) // A valid filename |
|
2170 |
{ |
|
2171 |
file.Close(); |
|
2172 |
validFileOrDir = ETrue; |
|
2173 |
} |
|
2174 |
else // Not a valid filename - move one word along the command line |
|
2175 |
{ |
|
2176 |
// Not a valid filename - Could be a directory... |
|
2177 |
RDir directory; |
|
2178 |
result=directory.Open(TheShell->TheFs,tempPath,KEntryAttMatchExclusive|KEntryAttDir); |
|
2179 |
if (result == KErrNone) |
|
2180 |
{ |
|
2181 |
directory.Close(); |
|
2182 |
validFileOrDir = ETrue; |
|
2183 |
} |
|
2184 |
} |
|
2185 |
||
2186 |
if(validFileOrDir) |
|
2187 |
{ |
|
2188 |
TBool recursive=((aSwitches&TShellCommand::ESSwitch)!=0); |
|
2189 |
TUint switches=(recursive) ? CFileMan::EOverWrite|CFileMan::ERecurse : CFileMan::EOverWrite; |
|
2190 |
r=CShell::TheFileMan->Move(oldName.FullName(),newName,switches); |
|
2191 |
if (r==KErrAccessDenied) |
|
2192 |
{ |
|
2193 |
CShell::TheConsole->Printf(_L("Access denied - cannot move %S\n"),&tempPath); |
|
2194 |
CShell::TheConsole->Printf(_L("To move %Sinto directory %S append \\ to the full destination\n"),&tempPath,&newName); |
|
2195 |
return (KErrNone); |
|
2196 |
} |
|
2197 |
return(r); |
|
2198 |
} |
|
2199 |
||
2200 |
r=word.FindNextWord(word.iRightString); |
|
2201 |
} |
|
2202 |
if (r<0) // r = some error code |
|
2203 |
return (r); // Error in filename or destination |
|
2204 |
else // r = 0 |
|
2205 |
return (KErrNotFound); |
|
2206 |
} |
|
2207 |
||
2208 |
TInt GetChunkInfo(TAny* aPtr) |
|
2209 |
{ |
|
2210 |
||
2211 |
TFindChunk findHb; |
|
2212 |
TFullName* namePtr=(TFullName*)aPtr; |
|
2213 |
findHb.Find(*namePtr); |
|
2214 |
TFullName aFN; |
|
2215 |
findHb.Next(aFN); |
|
2216 |
RChunk c; |
|
2217 |
TInt r=c.Open(findHb); |
|
2218 |
if(r==KErrPermissionDenied) |
|
2219 |
{ |
|
2220 |
CShell::TheConsole->Printf(_L("...Chunk is protected. No info available.\n")); |
|
2221 |
} |
|
2222 |
else |
|
2223 |
{ |
|
2224 |
CShell::TheConsole->Printf(_L("...Size %dk MaxSize %dk Base 0x%x\n"),c.Size()/1024,c.MaxSize()/1024,c.Base()); |
|
2225 |
c.Close(); |
|
2226 |
} |
|
2227 |
/* |
|
2228 |
#if defined (__WINS__) |
|
2229 |
c.Close(); |
|
2230 |
#else |
|
2231 |
if (aFN.Match(_L("*ESHELL*"))<0) |
|
2232 |
c.Close(); |
|
2233 |
#endif |
|
2234 |
*/ |
|
2235 |
return r; |
|
2236 |
}; |
|
2237 |
||
2238 |
TInt GetThreadInfo(TAny* aPtr) |
|
2239 |
// New function added by WR, November 1997 |
|
2240 |
{ |
|
2241 |
TBuf<80> detail; |
|
2242 |
TFindThread* findHb = (TFindThread*)aPtr; |
|
2243 |
RThread t; |
|
2244 |
TInt err = t.Open(*findHb); |
|
2245 |
if (err != KErrNone) |
|
2246 |
{ |
|
2247 |
detail.Format(_L("... can't open thread, err=%d\n"), err); |
|
2248 |
CShell::TheConsole->Printf(detail); |
|
2249 |
return KErrNone; |
|
2250 |
} |
|
2251 |
||
2252 |
TExitType exit = t.ExitType(); |
|
2253 |
TBuf<KMaxExitCategoryName> exitCat=t.ExitCategory(); |
|
2254 |
TThreadId threadId = t.Id(); |
|
2255 |
TUint id = *(TUint*)&threadId; |
|
2256 |
RProcess proc; |
|
2257 |
TInt pid = t.Process(proc); |
|
2258 |
if (pid==KErrNone) |
|
2259 |
{ |
|
2260 |
TProcessId procId = proc.Id(); |
|
2261 |
pid = *(TInt*)&procId; |
|
2262 |
proc.Close(); |
|
2263 |
} |
|
2264 |
||
2265 |
switch (exit) |
|
2266 |
{ |
|
2267 |
case EExitPending: |
|
2268 |
detail.Format(_L("... ID %d (Proc %d), running\n"), id, pid); |
|
2269 |
break; |
|
2270 |
case EExitPanic: |
|
2271 |
// lint -e50 |
|
2272 |
detail.Format(_L("... ID %d (Proc %d), panic \"%S\" %d\n"), id, pid, |
|
2273 |
&exitCat, t.ExitReason()); |
|
2274 |
break; |
|
2275 |
case EExitKill: |
|
2276 |
detail.Format(_L("... ID %d (Proc %d), killed %d\n"), id, pid, t.ExitReason()); |
|
2277 |
break; |
|
2278 |
case EExitTerminate: |
|
2279 |
detail.Format(_L("... ID %d (Proc %d), terminated %d\n"), id, pid, t.ExitReason()); |
|
2280 |
break; |
|
2281 |
default: |
|
2282 |
detail.Format(_L("... ID %d (Proc %d), ?exit type %d?\n"), id, pid, exit); |
|
2283 |
break; |
|
2284 |
} |
|
2285 |
t.Close(); |
|
2286 |
CShell::TheConsole->Printf(detail); |
|
2287 |
return KErrNone; |
|
2288 |
}; |
|
2289 |
// End of modification |
|
2290 |
||
2291 |
// Class for showing information about processes |
|
2292 |
class TShowProcInfo |
|
2293 |
{ |
|
2294 |
public: |
|
2295 |
TInt DisplayHelp(); |
|
2296 |
TInt DisplayMessage(const TFullName& aName); |
|
2297 |
TInt DisplayCmdUnknown(); |
|
2298 |
TInt GetAll(const TDes& aName); |
|
2299 |
TInt GetProcesses(const TDes& aName); |
|
2300 |
TInt GetThreads(const TDes& aName); |
|
2301 |
TInt GetChunks(const TDes& aName); |
|
2302 |
TInt GetServers(const TDes& aName); |
|
2303 |
// TInt GetSessions(const TDes& aName); |
|
2304 |
TInt GetLibraries(const TDes& aName); |
|
2305 |
// TInt GetLogicalChannels(const TDes& aName); |
|
2306 |
TInt GetLogicalDevices(const TDes& aName); |
|
2307 |
TInt GetPhysicalDevices(const TDes& aName); |
|
2308 |
TInt GetSemaphores(const TDes& aName); |
|
2309 |
TInt GetMutexes(const TDes& aName); |
|
2310 |
private: |
|
2311 |
void DisplayHelpLine(const TDesC& aCommand, const TDesC& aDescription); |
|
2312 |
TInt Prepare(const TFullName& aName); |
|
2313 |
TInt Prepare(const TFullName& aName,TCallBack& aCallBack); |
|
2314 |
TInt Display(TFullName& aName); |
|
2315 |
TFullName iPrevName; |
|
2316 |
TCallBack iCallBack; |
|
2317 |
TBool useCallBack; |
|
2318 |
}; |
|
2319 |
||
2320 |
TInt TShowProcInfo::DisplayHelp() |
|
2321 |
{ |
|
2322 |
||
2323 |
DisplayHelpLine(_L("H or ?"),_L("Show Help")); |
|
2324 |
DisplayHelpLine(_L("Q"),_L("Quit Process Status Mode")); |
|
2325 |
DisplayHelpLine(_L("X<name>"),_L("Switch to a particular Process domain")); |
|
2326 |
DisplayHelpLine(_L("X"),_L("Go Back to standard Process Status Mode")); |
|
2327 |
DisplayHelpLine(_L("A"),_L("Display all container objects")); |
|
2328 |
DisplayHelpLine(_L("P"),_L("List all Processes (irrespective of current domain)")); |
|
2329 |
DisplayHelpLine(_L("T"),_L("List Threads")); |
|
2330 |
DisplayHelpLine(_L("C"),_L("List Chunks, their sizes, maximum sizes and addresses")); |
|
2331 |
DisplayHelpLine(_L("S"),_L("List Servers")); |
|
2332 |
// DisplayHelpLine(_L("I"),_L("List Sessions")); |
|
2333 |
DisplayHelpLine(_L("L"),_L("List Libraries")); |
|
2334 |
// DisplayHelpLine(_L("G"),_L("List Logical Channels")); |
|
2335 |
DisplayHelpLine(_L("V"),_L("List Logical Devices")); |
|
2336 |
DisplayHelpLine(_L("D"),_L("List Physical Devices")); |
|
2337 |
DisplayHelpLine(_L("E"),_L("List Semaphores")); |
|
2338 |
DisplayHelpLine(_L("M"),_L("List Mutexes")); |
|
2339 |
return KErrNone; |
|
2340 |
} |
|
2341 |
||
2342 |
TInt TShowProcInfo::DisplayMessage(const TFullName& aMessage) |
|
2343 |
{ |
|
2344 |
CShell::OutputStringToConsole(ETrue,aMessage); |
|
2345 |
CShell::NewLine(); |
|
2346 |
return KErrNone; |
|
2347 |
} |
|
2348 |
||
2349 |
TInt TShowProcInfo::DisplayCmdUnknown() |
|
2350 |
{ |
|
2351 |
CShell::OutputStringToConsole(ETrue,_L("Not supported\n")); |
|
2352 |
return KErrNone; |
|
2353 |
} |
|
2354 |
||
2355 |
TInt TShowProcInfo::GetAll(const TDes& aName) |
|
2356 |
{ |
|
2357 |
||
2358 |
GetProcesses(aName); |
|
2359 |
GetThreads(aName); |
|
2360 |
GetChunks(aName); |
|
2361 |
GetServers(aName); |
|
2362 |
// GetSessions(aName); |
|
2363 |
GetLibraries(aName); |
|
2364 |
// GetLogicalChannels(aName); |
|
2365 |
GetLogicalDevices(aName); |
|
2366 |
GetPhysicalDevices(aName); |
|
2367 |
GetSemaphores(aName); |
|
2368 |
GetMutexes(aName); |
|
2369 |
return KErrNone; |
|
2370 |
} |
|
2371 |
||
2372 |
TInt TShowProcInfo::GetProcesses(const TDes& aName) |
|
2373 |
{ |
|
2374 |
||
2375 |
TFindProcess findHb; |
|
2376 |
findHb.Find(aName); |
|
2377 |
TFullName name; |
|
2378 |
Prepare(_L("PROCESSES")); |
|
2379 |
while (findHb.Next(name)==KErrNone) |
|
2380 |
{ |
|
2381 |
Display(name); |
|
2382 |
} |
|
2383 |
return KErrNone; |
|
2384 |
} |
|
2385 |
||
2386 |
TInt TShowProcInfo::GetThreads(const TDes& aName) |
|
2387 |
{ |
|
2388 |
TInt threads=0; |
|
2389 |
TFindThread findHb; |
|
2390 |
findHb.Find(aName); |
|
2391 |
TFullName name; |
|
2392 |
TAny* findPtr=(TAny*)&findHb; |
|
2393 |
||
2394 |
// Modified by WR, November 1997 |
|
2395 |
TCallBack threadCallBack(GetThreadInfo,findPtr); |
|
2396 |
Prepare(_L("THREADS"),threadCallBack); |
|
2397 |
while (findHb.Next(name)==KErrNone) |
|
2398 |
{ |
|
2399 |
Display(name); |
|
2400 |
threads += 1; |
|
2401 |
} |
|
2402 |
if (threads==0) |
|
2403 |
{ |
|
2404 |
TFullName message; |
|
2405 |
message.Format(_L("? No threads called %S"), &aName); |
|
2406 |
DisplayMessage(message); |
|
2407 |
} |
|
2408 |
return KErrNone; |
|
2409 |
// End of modification |
|
2410 |
} |
|
2411 |
||
2412 |
||
2413 |
TInt TShowProcInfo::GetChunks(const TDes& aName) |
|
2414 |
{ |
|
2415 |
||
2416 |
TFindChunk findHb; |
|
2417 |
findHb.Find(aName); |
|
2418 |
TFullName name; |
|
2419 |
TAny* namePtr=(TAny*)&name; |
|
2420 |
TCallBack chunkCallBack(GetChunkInfo,namePtr); |
|
2421 |
Prepare(_L("CHUNKS & SIZES"),chunkCallBack); |
|
2422 |
TInt totalChunkSize=0; |
|
2423 |
TInt protectedChunks = 0; |
|
2424 |
while (findHb.Next(name)==KErrNone) |
|
2425 |
{ |
|
2426 |
Display(name); |
|
2427 |
RChunk c; |
|
2428 |
TInt r=c.Open(findHb); |
|
2429 |
if(r!=KErrNone) |
|
2430 |
++protectedChunks; |
|
2431 |
else |
|
2432 |
{ |
|
2433 |
totalChunkSize+=c.Size()/1024; |
|
2434 |
c.Close(); |
|
2435 |
} |
|
2436 |
/* |
|
2437 |
#if defined(__WINS__) |
|
2438 |
c.Close(); |
|
2439 |
#else |
|
2440 |
if (name.Match(_L("*ESHELL*"))<0) |
|
2441 |
c.Close(); |
|
2442 |
#endif |
|
2443 |
*/ |
|
2444 |
} |
|
2445 |
CShell::OutputStringToConsole(ETrue,_L(" Total Chunk Size = %dk\n"),totalChunkSize); |
|
2446 |
if(protectedChunks) |
|
2447 |
CShell::OutputStringToConsole(ETrue,_L(" %d Protected chunks not counted\n"),protectedChunks); |
|
2448 |
return KErrNone; |
|
2449 |
} |
|
2450 |
||
2451 |
TInt TShowProcInfo::GetServers(const TDes& aName) |
|
2452 |
{ |
|
2453 |
||
2454 |
TFindServer findHb; |
|
2455 |
findHb.Find(aName); |
|
2456 |
TFullName name; |
|
2457 |
Prepare(_L("SERVERS")); |
|
2458 |
while (findHb.Next(name)==KErrNone) |
|
2459 |
{ |
|
2460 |
Display(name); |
|
2461 |
} |
|
2462 |
return KErrNone; |
|
2463 |
} |
|
2464 |
||
2465 |
/* TInt TShowProcInfo::GetSessions(const TDes& aName) |
|
2466 |
{ |
|
2467 |
||
2468 |
TFindSession findHb; |
|
2469 |
findHb.Find(aName); |
|
2470 |
TFullName name; |
|
2471 |
Prepare(_L("SESSIONS")); |
|
2472 |
while (findHb.Next(name)==KErrNone) |
|
2473 |
{ |
|
2474 |
Display(name); |
|
2475 |
} |
|
2476 |
return KErrNone; |
|
2477 |
} |
|
2478 |
*/ |
|
2479 |
TInt TShowProcInfo::GetLibraries(const TDes& aName) |
|
2480 |
{ |
|
2481 |
||
2482 |
TFindLibrary findHb; |
|
2483 |
findHb.Find(aName); |
|
2484 |
TFullName name; |
|
2485 |
Prepare(_L("LIBRARIES")); |
|
2486 |
while (findHb.Next(name)==KErrNone) |
|
2487 |
{ |
|
2488 |
Display(name); |
|
2489 |
} |
|
2490 |
return KErrNone; |
|
2491 |
} |
|
2492 |
/* |
|
2493 |
TInt TShowProcInfo::GetLogicalChannels(const TDes& aName) |
|
2494 |
{ |
|
2495 |
||
2496 |
TFindLogicalChannel findHb; |
|
2497 |
findHb.Find(aName); |
|
2498 |
TFullName name; |
|
2499 |
Prepare(_L("LOGICAL CHANNELS")); |
|
2500 |
while (findHb.Next(name)==KErrNone) |
|
2501 |
{ |
|
2502 |
Display(name); |
|
2503 |
} |
|
2504 |
return KErrNone; |
|
2505 |
} |
|
2506 |
*/ |
|
2507 |
||
2508 |
TInt TShowProcInfo::GetLogicalDevices(const TDes& aName) |
|
2509 |
{ |
|
2510 |
||
2511 |
TFindLogicalDevice findHb; |
|
2512 |
findHb.Find(aName); |
|
2513 |
TFullName name; |
|
2514 |
Prepare(_L("LOGICAL DEVICES")); |
|
2515 |
while (findHb.Next(name)==KErrNone) |
|
2516 |
{ |
|
2517 |
Display(name); |
|
2518 |
} |
|
2519 |
return KErrNone; |
|
2520 |
} |
|
2521 |
||
2522 |
TInt TShowProcInfo::GetPhysicalDevices(const TDes& aName) |
|
2523 |
{ |
|
2524 |
||
2525 |
TFindPhysicalDevice findHb; |
|
2526 |
findHb.Find(aName); |
|
2527 |
TFullName name; |
|
2528 |
Prepare(_L("PHYSICAL DEVICES")); |
|
2529 |
while (findHb.Next(name)==KErrNone) |
|
2530 |
{ |
|
2531 |
Display(name); |
|
2532 |
} |
|
2533 |
return KErrNone; |
|
2534 |
} |
|
2535 |
||
2536 |
TInt TShowProcInfo::GetSemaphores(const TDes& aName) |
|
2537 |
{ |
|
2538 |
TFindSemaphore findHb; |
|
2539 |
findHb.Find(aName); |
|
2540 |
TFullName name; |
|
2541 |
Prepare(_L("SEMAPHORES")); |
|
2542 |
while (findHb.Next(name)==KErrNone) |
|
2543 |
{ |
|
2544 |
Display(name); |
|
2545 |
} |
|
2546 |
return KErrNone; |
|
2547 |
} |
|
2548 |
||
2549 |
TInt TShowProcInfo::GetMutexes(const TDes& aName) |
|
2550 |
{ |
|
2551 |
||
2552 |
TFindMutex findHb; |
|
2553 |
findHb.Find(aName); |
|
2554 |
TFullName name; |
|
2555 |
Prepare(_L("MUTEXES")); |
|
2556 |
while (findHb.Next(name)==KErrNone) |
|
2557 |
{ |
|
2558 |
Display(name); |
|
2559 |
} |
|
2560 |
return KErrNone; |
|
2561 |
} |
|
2562 |
||
2563 |
void TShowProcInfo::DisplayHelpLine(const TDesC& aCommand, const TDesC& aDescription) |
|
2564 |
{ |
|
2565 |
CShell::OutputStringToConsole(ETrue,_L("%- *S%S\n"),8,&aCommand,&aDescription); |
|
2566 |
} |
|
2567 |
||
2568 |
||
2569 |
TInt TShowProcInfo::Prepare(const TFullName& aName) |
|
2570 |
{ |
|
2571 |
||
2572 |
iPrevName=_L(""); |
|
2573 |
CShell::OutputStringToConsole(ETrue,_L("--%S-->\n"),&aName); |
|
2574 |
useCallBack=EFalse; |
|
2575 |
return KErrNone; |
|
2576 |
} |
|
2577 |
||
2578 |
TInt TShowProcInfo::Prepare(const TFullName& aName,TCallBack& aCallBack) |
|
2579 |
{ |
|
2580 |
||
2581 |
iPrevName=_L(""); |
|
2582 |
CShell::OutputStringToConsole(ETrue,_L("--%S-->\n"),&aName); |
|
2583 |
useCallBack=ETrue; |
|
2584 |
iCallBack=aCallBack; |
|
2585 |
return KErrNone; |
|
2586 |
} |
|
2587 |
||
2588 |
TInt TShowProcInfo::Display(TFullName& aName) |
|
2589 |
||
2590 |
// Modifications by WR, November 1997 |
|
2591 |
{ |
|
2592 |
||
2593 |
TFullName prevName=iPrevName; |
|
2594 |
iPrevName=aName; |
|
2595 |
TInt toTab=0; |
|
2596 |
TInt posA=aName.Match(_L("*::*")); |
|
2597 |
if (posA>=0) |
|
2598 |
{ |
|
2599 |
TInt posI=prevName.Match(_L("*::*")); |
|
2600 |
while ((posI>=0) && (posA>=0)) |
|
2601 |
{ |
|
2602 |
TFullName tempAName=(aName.Left(posA)); |
|
2603 |
TFullName tempIName=(prevName.Left(posI)); |
|
2604 |
if (tempAName.Compare(tempIName)==0) |
|
2605 |
{ |
|
2606 |
toTab+=3; |
|
2607 |
aName.Delete(0,posA+2); |
|
2608 |
prevName.Delete(0,posI+2); |
|
2609 |
posA=aName.Match(_L("*::*")); |
|
2610 |
posI=prevName.Match(_L("*::*")); |
|
2611 |
} |
|
2612 |
else |
|
2613 |
break; |
|
2614 |
} |
|
2615 |
while (posA>=0) |
|
2616 |
{ |
|
2617 |
TPtrC16 temp_desc=aName.Left(posA); |
|
2618 |
CShell::OutputStringToConsole(ETrue,_L("%+ *S\n"),toTab+temp_desc.Left(posA).Length(),&temp_desc); |
|
2619 |
toTab+=3; |
|
2620 |
aName.Delete(0,posA+2); |
|
2621 |
posA=aName.Match(_L("*::*")); |
|
2622 |
} |
|
2623 |
} |
|
2624 |
CShell::OutputStringToConsole(ETrue,_L("%+ *S\n"),toTab+aName.Length(),&(aName)); |
|
2625 |
||
2626 |
||
2627 |
if (useCallBack) |
|
2628 |
{ |
|
2629 |
toTab+=3; |
|
2630 |
CShell::TheConsole->SetCursorPosRel(TPoint(toTab,0)); |
|
2631 |
iCallBack.CallBack(); |
|
2632 |
} |
|
2633 |
return KErrNone; |
|
2634 |
} |
|
2635 |
// End of modification |
|
2636 |
TInt ShellFunction::Ps(TDes& /* aPath */,TUint /* aSwitches */) |
|
2637 |
// |
|
2638 |
// satisfy information requests about container objects |
|
2639 |
// |
|
2640 |
{ |
|
2641 |
||
2642 |
TShowProcInfo showProcInfo; |
|
2643 |
TInt r=KErrNone; |
|
2644 |
TBuf<0x1> asterisk=_L("*"); |
|
2645 |
TName processPrefix=asterisk; |
|
2646 |
TBool abort=EFalse; |
|
2647 |
TBool processSelected=EFalse; |
|
2648 |
TBuf<0x16> prompt=_L("ps>"); |
|
2649 |
r=showProcInfo.GetProcesses(processPrefix); |
|
2650 |
do |
|
2651 |
{ |
|
2652 |
TBuf<0x10> command; |
|
2653 |
CShell::TheEditor->Edit(prompt, &command, ETrue); |
|
2654 |
while (command.Length() && !abort && r==KErrNone) |
|
2655 |
{ |
|
2656 |
TInt pos; |
|
2657 |
while ((pos=command.Locate(' '))>=0) |
|
2658 |
command.Delete(pos,1); |
|
2659 |
if (!command.Length()) |
|
2660 |
break; |
|
2661 |
command.UpperCase(); |
|
2662 |
if (command.CompareF(_L("EXIT"))==0) |
|
2663 |
{ |
|
2664 |
abort=ETrue; |
|
2665 |
break; |
|
2666 |
} |
|
2667 |
TText c=command[0]; |
|
2668 |
command.Delete(0,1); |
|
2669 |
switch (c) |
|
2670 |
{ |
|
2671 |
case 'Q': |
|
2672 |
abort=ETrue; |
|
2673 |
break; |
|
2674 |
case 'H': |
|
2675 |
case '?': |
|
2676 |
{ |
|
2677 |
showProcInfo.DisplayHelp(); |
|
2678 |
command.Zero(); |
|
2679 |
} |
|
2680 |
break; |
|
2681 |
case 'X': |
|
2682 |
{ |
|
2683 |
TBuf<0x11> chosenP=command; |
|
2684 |
if (chosenP.Length()<1) |
|
2685 |
{ |
|
2686 |
if (processSelected) |
|
2687 |
{ |
|
2688 |
r=showProcInfo.DisplayMessage(_L(" -> back to standard Process Status mode")); |
|
2689 |
processPrefix=asterisk; |
|
2690 |
prompt=_L("ps>"); |
|
2691 |
processSelected=EFalse; |
|
2692 |
} |
|
2693 |
command.Zero(); |
|
2694 |
break; |
|
2695 |
} |
|
2696 |
command.Zero(); |
|
2697 |
chosenP.Append(asterisk); |
|
2698 |
TFindProcess findP; |
|
2699 |
findP.Find(chosenP); |
|
2700 |
TFullName findName; |
|
2701 |
if (findP.Next(findName)!=KErrNone) |
|
2702 |
{ |
|
2703 |
r=showProcInfo.DisplayMessage(_L("command prefixes no processes")); |
|
2704 |
//r=showProcInfo.GetProcesses(asterisk); |
|
2705 |
} |
|
2706 |
else |
|
2707 |
{ |
|
2708 |
if (findP.Next(findName)==KErrNone) |
|
2709 |
{ |
|
2710 |
r=showProcInfo.DisplayMessage(_L("command prefixes more than one process")); |
|
2711 |
r=showProcInfo.GetProcesses(chosenP); |
|
2712 |
} |
|
2713 |
else |
|
2714 |
{ |
|
2715 |
processSelected=ETrue; |
|
2716 |
processPrefix=chosenP; |
|
2717 |
prompt=processPrefix; |
|
2718 |
prompt.Append(_L(">")); |
|
2719 |
} |
|
2720 |
} |
|
2721 |
} |
|
2722 |
break; |
|
2723 |
case 'A': |
|
2724 |
{ |
|
2725 |
r=showProcInfo.GetAll(processPrefix); |
|
2726 |
command.Zero(); |
|
2727 |
} |
|
2728 |
break; |
|
2729 |
case 'P': |
|
2730 |
r=showProcInfo.GetProcesses(asterisk); |
|
2731 |
break; |
|
2732 |
case 'T': |
|
2733 |
r=showProcInfo.GetThreads(processPrefix); |
|
2734 |
break; |
|
2735 |
case 'C': |
|
2736 |
r=showProcInfo.GetChunks(processPrefix); |
|
2737 |
break; |
|
2738 |
case 'S': |
|
2739 |
r=showProcInfo.GetServers(processPrefix); |
|
2740 |
break; |
|
2741 |
/* case 'I': |
|
2742 |
r=showProcInfo.GetSessions(processPrefix); |
|
2743 |
break; |
|
2744 |
*/ case 'L': |
|
2745 |
r=showProcInfo.GetLibraries(processPrefix); |
|
2746 |
break; |
|
2747 |
// case 'G': |
|
2748 |
// r=showProcInfo.GetLogicalChannels(processPrefix); |
|
2749 |
// break; |
|
2750 |
case 'V': |
|
2751 |
r=showProcInfo.GetLogicalDevices(processPrefix); |
|
2752 |
break; |
|
2753 |
case 'D': |
|
2754 |
r=showProcInfo.GetPhysicalDevices(processPrefix); |
|
2755 |
break; |
|
2756 |
case 'E': |
|
2757 |
r=showProcInfo.GetSemaphores(processPrefix); |
|
2758 |
break; |
|
2759 |
case 'M': |
|
2760 |
r=showProcInfo.GetMutexes(processPrefix); |
|
2761 |
break; |
|
2762 |
default: |
|
2763 |
{ |
|
2764 |
showProcInfo.DisplayCmdUnknown(); |
|
2765 |
command.Zero(); |
|
2766 |
} |
|
2767 |
} |
|
2768 |
} |
|
2769 |
} |
|
2770 |
while(!abort && r==KErrNone); |
|
2771 |
return KErrNone; |
|
2772 |
} |
|
2773 |
||
2774 |
TInt ShellFunction::Rename(TDes& aPath,TUint aSwitches) |
|
2775 |
{ |
|
2776 |
// Modified December 1997 to allow for filenames containing spaces |
|
2777 |
||
2778 |
TBuf<KShellMaxCommandLine> newName; |
|
2779 |
TBuf<KShellMaxCommandLine> tempPath=aPath; |
|
2780 |
RFile64 file; |
|
2781 |
TWord word(aPath); |
|
2782 |
||
2783 |
TInt r=word.FindNextWord(aPath); |
|
2784 |
// Check if the word returned is a valid filename. If not, scan the next |
|
2785 |
// word too in case the filename contains spaces. If, at the end of the |
|
2786 |
// the line, the filename is not recognised, it is invalid. If there are no |
|
2787 |
// spaces the user has not used the correct format for this command. |
|
2788 |
||
2789 |
while (r>0) |
|
2790 |
{ |
|
2791 |
newName=aPath.Right(aPath.Length()-r); |
|
2792 |
tempPath.SetLength(r); |
|
2793 |
TParse oldName; |
|
2794 |
TInt result=GetFullPath(tempPath,oldName); |
|
2795 |
if (result!=KErrNone) |
|
2796 |
return(r); |
|
2797 |
||
2798 |
if (tempPath[tempPath.Length()-2]==KPathDelimiter) |
|
2799 |
tempPath.SetLength(tempPath.Length()-2); |
|
2800 |
||
2801 |
result=file.Open(TheShell->TheFs,tempPath,KEntryAttMatchExclude|KEntryAttDir); |
|
2802 |
if (result==KErrNone) // A valid filename |
|
2803 |
{ |
|
2804 |
file.Close(); |
|
2805 |
TBool recursive=((aSwitches&TShellCommand::ESSwitch)!=0); |
|
2806 |
TUint switches=(recursive) ? CFileMan::EOverWrite : 0; |
|
2807 |
r=CShell::TheFileMan->Rename(oldName.FullName(),newName,switches); |
|
2808 |
// r=TheShell->TheFs.Rename(oldName.FullName(),newName); |
|
2809 |
return(r); |
|
2810 |
} |
|
2811 |
else |
|
2812 |
{ |
|
2813 |
// May be a request to rename a directory |
|
2814 |
RDir dir; |
|
2815 |
result=dir.Open(TheShell->TheFs,tempPath,KEntryAttMatchMask); |
|
2816 |
if (result==KErrNone) // A valid directory name |
|
2817 |
{ |
|
2818 |
dir.Close(); |
|
2819 |
TBool recursive=((aSwitches&TShellCommand::ESSwitch)!=0); |
|
2820 |
TUint switches=(recursive) ? CFileMan::EOverWrite : 0; |
|
2821 |
r=CShell::TheFileMan->Rename(oldName.FullName(),newName,switches); |
|
2822 |
// r=TheShell->TheFs.Rename(oldName.FullName(),newName); |
|
2823 |
return(r); |
|
2824 |
} |
|
2825 |
else |
|
2826 |
// Not a valid file or directory name - move one word along the command line |
|
2827 |
r=word.FindNextWord(word.iRightString); |
|
2828 |
} |
|
2829 |
} |
|
2830 |
||
2831 |
if (r<0) // Error in filename or destination |
|
2832 |
return (r); |
|
2833 |
else // End of command line, user typed invalid line |
|
2834 |
return (KErrNotFound); |
|
2835 |
||
2836 |
} |
|
2837 |
||
2838 |
TInt ShellFunction::Rd(TDes& aPath,TUint /*aSwitches*/) |
|
2839 |
{ |
|
2840 |
if (aPath.Length()==0) |
|
2841 |
return(KErrBadName); |
|
2842 |
if (aPath[aPath.Length()-1]!=KPathDelimiter) |
|
2843 |
aPath.Append(KPathDelimiter); |
|
2844 |
TParse dirPath; |
|
2845 |
TInt r = GetFullPath(aPath,dirPath); |
|
2846 |
if(r!=KErrNone) |
|
2847 |
return r; |
|
2848 |
||
2849 |
// Check whether the directory actually exists. |
|
2850 |
RDir directory; |
|
2851 |
r=directory.Open(TheShell->TheFs,dirPath.FullName(),KEntryAttMatchExclusive|KEntryAttDir); |
|
2852 |
if (r!=KErrNone) |
|
2853 |
{ |
|
2854 |
CShell::TheConsole->Printf(_L("Directory %S was not found\n"),&dirPath.FullName()); |
|
2855 |
return (KErrNone); |
|
2856 |
} |
|
2857 |
directory.Close(); |
|
2858 |
||
2859 |
TInt ret=TheShell->TheFs.RmDir(dirPath.FullName()); |
|
2860 |
||
2861 |
if (ret==KErrNone) |
|
2862 |
CShell::TheConsole->Printf(_L("Directory %S was removed\n"),&dirPath.FullName()); |
|
2863 |
else if(ret==KErrInUse) |
|
2864 |
{ |
|
2865 |
CShell::TheConsole->Printf(_L("Directory %S is in use and cannot be deleted\n"),&dirPath.FullName()); |
|
2866 |
return KErrNone; |
|
2867 |
} |
|
2868 |
||
2869 |
return(ret); |
|
2870 |
} |
|
2871 |
||
2872 |
TInt ShellFunction::Start(TDes& aProg,TUint /*aSwitches*/) |
|
2873 |
// |
|
2874 |
// Runs a program without waiting for completion |
|
2875 |
// |
|
2876 |
{ |
|
2877 |
||
2878 |
TInt bat=aProg.FindF(_L(".BAT")); |
|
2879 |
TInt space=aProg.Locate(' '); |
|
2880 |
TInt r=KErrArgument; |
|
2881 |
if (bat>=0 && (space<0 || space>bat)) |
|
2882 |
r=CShell::RunBatch(aProg); |
|
2883 |
else if (aProg.Length()!=0) |
|
2884 |
r=CShell::RunExecutable(aProg,EFalse); |
|
2885 |
return(r); |
|
2886 |
} |
|
2887 |
||
2888 |
TInt ShellFunction::Time(TDes&,TUint /*aSwitches*/) |
|
2889 |
{ |
|
2890 |
TTime time; |
|
2891 |
time.HomeTime(); |
|
2892 |
TDateTime dateTime(time.DateTime()); |
|
2893 |
CShell::TheConsole->Printf(_L(" %+02d/%+02d/%+04d %+02d:%+02d:%+02d.%+06d\n"),dateTime.Day()+1,dateTime.Month()+1,dateTime.Year(),dateTime.Hour(),dateTime.Minute(),dateTime.Second(),dateTime.MicroSecond()); |
|
2894 |
return(KErrNone); |
|
2895 |
} |
|
2896 |
||
2897 |
TInt ShellFunction::Trace(TDes& aState,TUint aSwitches) |
|
2898 |
// |
|
2899 |
// Turn on trace information |
|
2900 |
// |
|
2901 |
{ |
|
2902 |
TInt debugVal=0; |
|
2903 |
if (aSwitches&TShellCommand::ESSwitch) |
|
2904 |
debugVal|=KFSERV; |
|
2905 |
if (aSwitches&TShellCommand::ELSwitch) |
|
2906 |
debugVal|=KFLDR; |
|
2907 |
if (aSwitches&TShellCommand::EFSwitch) |
|
2908 |
debugVal|=KFSYS; |
|
2909 |
if (aSwitches&TShellCommand::ETSwitch) |
|
2910 |
debugVal|=KLFFS; |
|
2911 |
if (aSwitches&TShellCommand::EISwitch) |
|
2912 |
debugVal|=KISO9660; |
|
2913 |
if (aSwitches&TShellCommand::ENSwitch) |
|
2914 |
debugVal|=KNTFS; |
|
2915 |
if (aSwitches&TShellCommand::EMSwitch) |
|
2916 |
debugVal|=KTHRD; |
|
2917 |
if (aSwitches&TShellCommand::EOSwitch) |
|
2918 |
debugVal|=KROFS; |
|
2919 |
if (aSwitches&TShellCommand::ECSwitch) |
|
2920 |
debugVal|=KCOMPFS; |
|
2921 |
if (aSwitches&TShellCommand::EHSwitch) |
|
2922 |
debugVal|=KCACHE; |
|
2923 |
TheShell->TheFs.SetDebugRegister(debugVal); |
|
2924 |
||
2925 |
aSwitches=0; |
|
2926 |
||
2927 |
if (aState.Length()) |
|
2928 |
{ |
|
2929 |
TBuf<KShellMaxCommandLine> indexArg; |
|
2930 |
TWord word(aState); |
|
2931 |
||
2932 |
TLex lex=aState; |
|
2933 |
TUint val; |
|
2934 |
TInt r2=lex.Val(val,EHex); |
|
2935 |
||
2936 |
TInt r=word.FindNextWord(aState); |
|
2937 |
TUint index; |
|
2938 |
if (r>0) |
|
2939 |
{ |
|
2940 |
indexArg = aState.Right(aState.Length()-r); |
|
2941 |
lex=indexArg; |
|
2942 |
lex.Val(index,EDecimal); |
|
2943 |
} |
|
2944 |
else |
|
2945 |
index = 0; |
|
2946 |
||
2947 |
if (r2 != KErrNone) |
|
2948 |
{ |
|
2949 |
TInt shift = index % 32; |
|
2950 |
index /= 32; |
|
2951 |
val = UserSvr::DebugMask(index); |
|
2952 |
if (aState.Left(2)==_L("on")) |
|
2953 |
val |= 1<<shift; |
|
2954 |
else if (aState.Left(3)==_L("off")) |
|
2955 |
val &= ~(1<<shift); |
|
2956 |
} |
|
2957 |
||
2958 |
if (index < 256) |
|
2959 |
{ |
|
2960 |
User::SetDebugMask(val, index); |
|
2961 |
CShell::TheConsole->Printf(_L("SetDebugMask(0x%x, %d)\n"), val, index); |
|
2962 |
} |
|
2963 |
} |
|
2964 |
else |
|
2965 |
{ |
|
2966 |
for (TInt j=0; j<8; j++) |
|
2967 |
CShell::TheConsole->Printf(_L("DebugMask(%d) = 0x%08X\n"), j, UserSvr::DebugMask(j)); |
|
2968 |
} |
|
2969 |
||
2970 |
return(KErrNone); |
|
2971 |
} |
|
2972 |
||
2973 |
TInt ShellFunction::Tree(TDes& aPath,TUint aSwitches) |
|
2974 |
{ |
|
2975 |
ParsePath(aPath); |
|
2976 |
CShell::TheConsole->Printf(_L("\n %S\n"),&aPath); |
|
2977 |
if (aPath.Right(1)==_L("\\")) |
|
2978 |
aPath.Append('*'); |
|
2979 |
else |
|
2980 |
aPath.Append(_L("\\*")); |
|
2981 |
TBuf<256> buf=_L(" "); |
|
2982 |
TInt dirCount=ShowDirectoryTree(aPath,aSwitches,buf); |
|
2983 |
buf.Format(_L("\n Found %d subdirector"),dirCount); |
|
2984 |
if (dirCount==1) |
|
2985 |
buf.AppendFormat(_L("y\n")); |
|
2986 |
else |
|
2987 |
buf.AppendFormat(_L("ies\n")); |
|
2988 |
||
2989 |
CShell::OutputStringToConsole(((aSwitches&TShellCommand::EPSwitch)!=0),buf); |
|
2990 |
||
2991 |
return(KErrNone); |
|
2992 |
} |
|
2993 |
||
2994 |
TInt ShellFunction::ShowDirectoryTree(TDes& aPath,TUint aSwitches,TDes& aTreeGraph) |
|
2995 |
// |
|
2996 |
// Recursive fn. to draw tree of dir aPath (needs to be suffixed with '*') |
|
2997 |
// |
|
2998 |
{ |
|
2999 |
TInt dirCount=0; |
|
3000 |
RDir dir; |
|
3001 |
TInt r=dir.Open(TheShell->TheFs,aPath,KEntryAttDir); |
|
3002 |
if (r==KErrNone) |
|
3003 |
{ |
|
3004 |
TEntry next,entry; |
|
3005 |
while ((r=dir.Read(next))==KErrNone && !next.IsDir()) |
|
3006 |
{ |
|
3007 |
} |
|
3008 |
// lint info 722: Suspicious use of ; in previous line... |
|
3009 |
if (aSwitches&TShellCommand::EFSwitch) |
|
3010 |
{ |
|
3011 |
RDir dirFile; |
|
3012 |
if (dirFile.Open(TheShell->TheFs,aPath,0)==KErrNone) |
|
3013 |
{ |
|
3014 |
while (dirFile.Read(entry)==KErrNone) |
|
3015 |
CShell::OutputStringToConsole((aSwitches&TShellCommand::EPSwitch)!=0,(r==KErrNone)?_L("%S\x00B3 %S\n"):_L("%S %S\n"),&aTreeGraph,&entry.iName); |
|
3016 |
||
3017 |
dirFile.Close(); |
|
3018 |
} |
|
3019 |
} |
|
3020 |
if (r==KErrNone) |
|
3021 |
do |
|
3022 |
{ |
|
3023 |
entry=next; |
|
3024 |
while ((r=dir.Read(next))==KErrNone && !next.IsDir()) |
|
3025 |
; |
|
3026 |
||
3027 |
CShell::OutputStringToConsole((aSwitches&TShellCommand::EPSwitch)!=0,aTreeGraph); |
|
3028 |
if (r==KErrNone) |
|
3029 |
{ |
|
3030 |
CShell::OutputStringToConsole((aSwitches&TShellCommand::EPSwitch)!=0,_L("\x00C0\x00C4\x00C4%S\n"),&entry.iName); |
|
3031 |
aTreeGraph.Append(_L("\x00B3 ")); |
|
3032 |
} |
|
3033 |
else |
|
3034 |
{ |
|
3035 |
CShell::OutputStringToConsole((aSwitches&TShellCommand::EPSwitch)!=0,_L("\x00C0\x00C4\x00C4%S\n"),&entry.iName); |
|
3036 |
aTreeGraph.Append(_L(" ")); |
|
3037 |
} |
|
3038 |
aPath.Insert(aPath.Length()-1,entry.iName); |
|
3039 |
aPath.Insert(aPath.Length()-1,_L("\\")); |
|
3040 |
dirCount+=1+ShowDirectoryTree(aPath,aSwitches,aTreeGraph); |
|
3041 |
aPath.Delete(aPath.Length()-2-entry.iName.Length(),entry.iName.Length()+1); |
|
3042 |
aTreeGraph.SetLength(aTreeGraph.Length()-3); |
|
3043 |
} |
|
3044 |
while (r==KErrNone); |
|
3045 |
dir.Close(); |
|
3046 |
if (r!=KErrEof) |
|
3047 |
CShell::OutputStringToConsole((aSwitches&TShellCommand::EPSwitch)!=0,_L("Error EOF %d\n"),r); |
|
3048 |
||
3049 |
} |
|
3050 |
else |
|
3051 |
CShell::OutputStringToConsole((aSwitches&TShellCommand::EPSwitch)!=0,_L("Error in Open %d\n"),r); |
|
3052 |
return(dirCount); |
|
3053 |
} |
|
3054 |
||
3055 |
void ByteSwap(TDes16& aDes) |
|
3056 |
{ |
|
3057 |
TUint8* p=(TUint8*)aDes.Ptr(); |
|
3058 |
TUint8* pE=p+aDes.Size(); |
|
3059 |
TUint8 c; |
|
3060 |
for (; p<pE; p+=2) |
|
3061 |
c=*p, *p=p[1], p[1]=c; |
|
3062 |
} |
|
3063 |
||
3064 |
_LIT(KLitPercentS, "%S"); |
|
3065 |
TInt ShellFunction::Type(TDes& aPath,TUint aSwitches) |
|
3066 |
{ |
|
3067 |
ParsePath(aPath); |
|
3068 |
RFile file; |
|
3069 |
TInt r=file.Open(TheShell->TheFs,aPath,EFileStreamText|EFileShareReadersOnly); |
|
3070 |
if (r!=KErrNone) |
|
3071 |
return r; |
|
3072 |
TBuf8<0x200> tmpbuf; |
|
3073 |
TBuf<0x200> ubuf; |
|
3074 |
TInt state=0; // 0=start of file, 1=ASCII, 2=UNICODE little-endian, 3=UNICODE big-endian |
|
3075 |
TKeyCode key=EKeyNull; |
|
3076 |
||
3077 |
TInt nchars=0; |
|
3078 |
TInt l; |
|
3079 |
||
3080 |
do |
|
3081 |
{ |
|
3082 |
r=file.Read(tmpbuf); |
|
3083 |
if (r!=KErrNone) |
|
3084 |
{ |
|
3085 |
file.Close(); |
|
3086 |
return r; |
|
3087 |
} |
|
3088 |
||
3089 |
l=tmpbuf.Length(); |
|
3090 |
if (state==0) |
|
3091 |
{ |
|
3092 |
if (l>=2) |
|
3093 |
{ |
|
3094 |
TUint c=(tmpbuf[1]<<8)|tmpbuf[0]; |
|
3095 |
if (c==0xfeff) |
|
3096 |
state=2; |
|
3097 |
else if (c==0xfffe) |
|
3098 |
state=3; |
|
3099 |
else |
|
3100 |
state=1; |
|
3101 |
} |
|
3102 |
else |
|
3103 |
state=1; |
|
3104 |
} |
|
3105 |
TPtrC buf; |
|
3106 |
if (state>1) |
|
3107 |
{ |
|
3108 |
if (l&1) |
|
3109 |
--l, tmpbuf.SetLength(l); |
|
3110 |
buf.Set((TText*)tmpbuf.Ptr(),l/sizeof(TText)); |
|
3111 |
if (state==3) |
|
3112 |
{ |
|
3113 |
TPtr wbuf( (TText*)buf.Ptr(), buf.Length(), buf.Length() ); |
|
3114 |
ByteSwap(wbuf); |
|
3115 |
} |
|
3116 |
} |
|
3117 |
else |
|
3118 |
{ |
|
3119 |
ubuf.Copy(tmpbuf); |
|
3120 |
buf.Set(ubuf); |
|
3121 |
} |
|
3122 |
while ((r=buf.Locate('\n'))!=KErrNotFound) |
|
3123 |
{ |
|
3124 |
nchars=0; |
|
3125 |
TPtrC bufLeft=buf.Left(r+1); |
|
3126 |
key = CShell::OutputStringToConsole((aSwitches&TShellCommand::EPSwitch)!=0,KLitPercentS(), &bufLeft); |
|
3127 |
buf.Set(buf.Mid(r+1)); |
|
3128 |
||
3129 |
if(key == EKeyEscape) |
|
3130 |
goto exit; |
|
3131 |
} |
|
3132 |
||
3133 |
nchars=buf.Length(); |
|
3134 |
if (nchars) |
|
3135 |
{ |
|
3136 |
key = CShell::OutputStringToConsole((aSwitches&TShellCommand::EPSwitch)!=0,KLitPercentS(), &buf); |
|
3137 |
if(key == EKeyEscape) |
|
3138 |
goto exit; |
|
3139 |
||
3140 |
} |
|
3141 |
||
3142 |
} while(l==tmpbuf.MaxLength()); |
|
3143 |
||
3144 |
exit: |
|
3145 |
||
3146 |
file.Close(); |
|
3147 |
CShell::NewLine(); |
|
3148 |
return KErrNone; |
|
3149 |
} |
|
3150 |
||
3151 |
void ShellFunction::ParsePath(TDes& aPath) |
|
3152 |
{ |
|
3153 |
if (aPath.Length()>0 && aPath[0]==KPathDelimiter) |
|
3154 |
return; |
|
3155 |
TParse pathParse; |
|
3156 |
if (aPath.Length()<2 || aPath[1]!=':') |
|
3157 |
pathParse.SetNoWild(TheShell->currentPath,NULL,NULL); |
|
3158 |
else |
|
3159 |
{ |
|
3160 |
if (aPath.Length()>=3 && aPath[2]==KPathDelimiter) |
|
3161 |
return; |
|
3162 |
pathParse.SetNoWild(TheShell->drivePaths[User::UpperCase(aPath[0])-'A'],NULL,NULL); |
|
3163 |
aPath.Delete(0,2); |
|
3164 |
} |
|
3165 |
if (aPath.Length()>=2 && aPath.Left(2).Compare(_L(".."))==0) |
|
3166 |
{ |
|
3167 |
aPath.Delete(0,2); |
|
3168 |
pathParse.PopDir(); |
|
3169 |
while (aPath.Length()>=3 && aPath.Left(3).Compare(_L("\\.."))==0) |
|
3170 |
{ |
|
3171 |
aPath.Delete(0,3); |
|
3172 |
pathParse.PopDir(); |
|
3173 |
} |
|
3174 |
if (aPath.Length()!=0 && aPath[0]==KPathDelimiter) |
|
3175 |
aPath.Delete(0,1); |
|
3176 |
} |
|
3177 |
aPath.Insert(0,pathParse.FullName()); |
|
3178 |
} |
|
3179 |
||
3180 |
TBool ShellFunction::Certain() |
|
3181 |
{ |
|
3182 |
CShell::TheConsole->Printf(_L("Are you sure? Y/N...")); |
|
3183 |
TInt r=User::UpperCase(CShell::TheConsole->Getch()); |
|
3184 |
while ((!(r=='Y'))&&(!(r=='N'))) |
|
3185 |
{ |
|
3186 |
CShell::TheConsole->Printf(_L("%c is invalid\n"),r); |
|
3187 |
CShell::TheConsole->Printf(_L("Are you sure? Y/N...")); |
|
3188 |
r=User::UpperCase(CShell::TheConsole->Getch()); |
|
3189 |
} |
|
3190 |
CShell::TheConsole->Printf(_L("%c\n"),r); |
|
3191 |
return(r=='Y'); |
|
3192 |
} |
|
3193 |
||
3194 |
TInt ShellFunction::GetFullPath(TDes& aPath,TParse& aParse) |
|
3195 |
// |
|
3196 |
// Parse a path of the form "[C:][\\]AAA\\..\\.\\BBB\\xxx.yyy" where: |
|
3197 |
// . indicates the current directory |
|
3198 |
// .. indicates move to the parent directory |
|
3199 |
// An optional "\\" at the start of the path indicates the path is not relative to the current path |
|
3200 |
// |
|
3201 |
{ |
|
3202 |
||
3203 |
TInt r; |
|
3204 |
if (aPath.Length()>0 && aPath[aPath.Length()-1]=='.') |
|
3205 |
aPath.Append(KPathDelimiter); |
|
3206 |
if (aPath.Length()==0) |
|
3207 |
r=aParse.Set(TheShell->currentPath,NULL,NULL); |
|
3208 |
else if (aPath[0]==KPathDelimiter) |
|
3209 |
r=aParse.Set(aPath,&TheShell->currentPath,NULL); |
|
3210 |
else if (aPath.Length()>=2 && aPath[1]==KDriveDelimiter) |
|
3211 |
{ |
|
3212 |
TInt drvNum; |
|
3213 |
r=RFs::CharToDrive(aPath[0],drvNum); |
|
3214 |
if (r==KErrNone) |
|
3215 |
r=aParse.Set(aPath,&TheShell->drivePaths[drvNum],NULL); |
|
3216 |
} |
|
3217 |
else |
|
3218 |
{ |
|
3219 |
if (aPath.LocateReverse(KPathDelimiter)>=0) |
|
3220 |
{ |
|
3221 |
if (aPath.Length()+TheShell->currentPath.Length()>aPath.MaxLength()) |
|
3222 |
return(KErrBadName); |
|
3223 |
aPath.Insert(0,TheShell->currentPath); |
|
3224 |
} |
|
3225 |
r=aParse.Set(aPath,&TheShell->currentPath,NULL); |
|
3226 |
} |
|
3227 |
if (r!=KErrNone) |
|
3228 |
return(r); |
|
3229 |
if (aParse.Path().Find(_L(".\\"))==KErrNotFound) |
|
3230 |
return(KErrNone); |
|
3231 |
if (aParse.Path().Find(_L("...\\"))!=KErrNotFound) |
|
3232 |
return(KErrBadName); |
|
3233 |
TParse dirParse; |
|
3234 |
TPtrC path(aParse.DriveAndPath()); |
|
3235 |
TInt pos=path.Find(_L(".\\")); |
|
3236 |
if (path[pos-1]!='.' && path[pos-1]!='\\') |
|
3237 |
return(KErrNone); // FileName ending in . |
|
3238 |
TInt isParent=(path[pos-1]=='.') ? 1 : 0; |
|
3239 |
r=dirParse.Set(path.Left(pos-isParent),NULL,NULL); |
|
3240 |
while(r==KErrNone) |
|
3241 |
{ |
|
3242 |
if (isParent) |
|
3243 |
dirParse.PopDir(); |
|
3244 |
path.Set(path.Right(path.Length()-pos-2)); |
|
3245 |
pos=path.Find(_L(".\\")); |
|
3246 |
if (pos==0) |
|
3247 |
{ |
|
3248 |
isParent=0; |
|
3249 |
continue; |
|
3250 |
} |
|
3251 |
else if (pos!=KErrNotFound) |
|
3252 |
isParent=(path[pos-1]=='.') ? 1 : 0; |
|
3253 |
TInt len=(pos==KErrNotFound) ? path.Length() : pos-isParent; |
|
3254 |
r=AddRelativePath(dirParse,path.Left(len)); |
|
3255 |
if (r!=KErrNone || pos==KErrNotFound) |
|
3256 |
break; |
|
3257 |
} |
|
3258 |
if (r!=KErrNone) |
|
3259 |
return(r); |
|
3260 |
// lint -e50 |
|
3261 |
TBuf<KMaxFileName> nameAndExt=aParse.NameAndExt(); |
|
3262 |
aParse.Set(dirParse.FullName(),&nameAndExt,NULL); |
|
3263 |
return(KErrNone); |
|
3264 |
} |
|
3265 |
||
3266 |
void ShellFunction::StripQuotes(TDes& aVal) |
|
3267 |
{ |
|
3268 |
for(TInt idx=0;idx<aVal.Length();idx++) |
|
3269 |
{ |
|
3270 |
while((idx < aVal.Length()) && (aVal[idx] == '"')) |
|
3271 |
{ |
|
3272 |
aVal.Delete(idx, 1); |
|
3273 |
} |
|
3274 |
} |
|
3275 |
} |
|
3276 |
||
3277 |
TInt ShellFunction::ValidName(TDes& aPath,TUint /*aSwitches*/) |
|
3278 |
// |
|
3279 |
// Check whether the name has any invalid characters |
|
3280 |
// |
|
3281 |
{ |
|
3282 |
TBool tooShort=EFalse; |
|
3283 |
||
3284 |
TText badChar; |
|
3285 |
TPtr ptr(&badChar,sizeof(TText),sizeof(TText)); |
|
3286 |
||
3287 |
TBool validName=TheShell->TheFs.IsValidName(aPath,badChar); |
|
3288 |
if (validName) |
|
3289 |
CShell::TheConsole->Printf(_L("'%S' is a valid name\n"),&aPath); |
|
3290 |
else |
|
3291 |
{ |
|
3292 |
if (!tooShort) |
|
3293 |
CShell::TheConsole->Printf(_L("'%S' is not a valid name.\n"),&aPath); |
|
3294 |
||
3295 |
CShell::TheConsole->Printf(_L("The '%S' character is not allowed\n"),&ptr); |
|
3296 |
} |
|
3297 |
return (KErrNone); |
|
3298 |
} |
|
3299 |
||
3300 |
LOCAL_C TInt pswd_DrvNbr(TDes &aPath, TInt &aDN) |
|
3301 |
// |
|
3302 |
// password utility function to extract drive number from cmd string. |
|
3303 |
// |
|
3304 |
{ |
|
3305 |
TLex l(aPath); |
|
3306 |
return l.Val(aDN); |
|
3307 |
} |
|
3308 |
||
3309 |
LOCAL_C TInt pswd_Password(TDes &aPath, TInt aPWNbr, TMediaPassword &aPW) |
|
3310 |
// |
|
3311 |
// utility function to extract indexed password from command string. A |
|
3312 |
// dash is interpreted as the null password. |
|
3313 |
// |
|
3314 |
{ |
|
3315 |
__ASSERT_DEBUG(aPWNbr >= 1, User::Panic(_L("Invalid pswd nbr"), 0)); |
|
3316 |
||
3317 |
TLex l(aPath); |
|
3318 |
||
3319 |
TPtrC ptScan; |
|
3320 |
for (TInt i = 0; i <= aPWNbr; ++i) |
|
3321 |
{ |
|
3322 |
if (l.Eos()) |
|
3323 |
return KErrNotFound; |
|
3324 |
else |
|
3325 |
ptScan.Set(l.NextToken()); |
|
3326 |
} |
|
3327 |
||
3328 |
// take remainder of command line and terminate after password |
|
3329 |
TBuf<256> pswd; |
|
3330 |
for (TInt j = 0; j < ptScan.Length() && ! TChar(ptScan[j]).IsSpace(); ++j) |
|
3331 |
{ |
|
3332 |
pswd.Append(ptScan[j]); |
|
3333 |
} |
|
3334 |
||
3335 |
aPW.Zero(); |
|
3336 |
if (pswd[0] == '-') |
|
3337 |
return KErrNone; |
|
3338 |
||
3339 |
// fill aPW with contents of pswd, not converting to ASCII |
|
3340 |
const TInt byteLen = pswd.Length() * 2; |
|
3341 |
if (byteLen > KMaxMediaPassword) |
|
3342 |
return KErrArgument; |
|
3343 |
||
3344 |
aPW.Copy(reinterpret_cast<const TUint8 *>(pswd.Ptr()), byteLen); |
|
3345 |
||
3346 |
return KErrNone; |
|
3347 |
} |
|
3348 |
||
3349 |
TInt ShellFunction::Lock(TDes &aPath, TUint aSwitches) |
|
3350 |
// |
|
3351 |
// Locks a password-enabled media. |
|
3352 |
// |
|
3353 |
{ |
|
3354 |
TInt r; |
|
3355 |
TInt dn; |
|
3356 |
TMediaPassword curPswd; |
|
3357 |
TMediaPassword newPswd; |
|
3358 |
TBool store = aSwitches & TShellCommand::ESSwitch; |
|
3359 |
||
3360 |
if ((r = pswd_DrvNbr(aPath, dn)) < 0) |
|
3361 |
return r; |
|
3362 |
||
3363 |
if ((r = pswd_Password(aPath, 1, curPswd)) < 0) |
|
3364 |
return r; |
|
3365 |
||
3366 |
if ((r = pswd_Password(aPath, 2, newPswd)) < 0) |
|
3367 |
return r; |
|
3368 |
||
3369 |
return TheShell->TheFs.LockDrive(dn, curPswd, newPswd, store); |
|
3370 |
} |
|
3371 |
||
3372 |
TInt ShellFunction::Unlock(TDes &aPath, TUint aSwitches) |
|
3373 |
// |
|
3374 |
// Unlocks a password-enabled media. |
|
3375 |
// |
|
3376 |
{ |
|
3377 |
TInt r; |
|
3378 |
TInt dn; |
|
3379 |
TMediaPassword curPswd; |
|
3380 |
TBool store = aSwitches & TShellCommand::ESSwitch; |
|
3381 |
||
3382 |
if ((r = pswd_DrvNbr(aPath, dn)) < 0) |
|
3383 |
return r; |
|
3384 |
||
3385 |
if ((r = pswd_Password(aPath, 1, curPswd)) < 0) |
|
3386 |
return r; |
|
3387 |
||
3388 |
return TheShell->TheFs.UnlockDrive(dn, curPswd, store); |
|
3389 |
} |
|
3390 |
||
3391 |
TInt ShellFunction::Clear(TDes &aPath, TUint /* aSwitches */) |
|
3392 |
// |
|
3393 |
// Clears a password from a password-enabled media. |
|
3394 |
// |
|
3395 |
{ |
|
3396 |
TInt r; |
|
3397 |
TInt dn; |
|
3398 |
TMediaPassword curPswd; |
|
3399 |
||
3400 |
if ((r = pswd_DrvNbr(aPath, dn)) < 0) |
|
3401 |
return r; |
|
3402 |
||
3403 |
if ((r = pswd_Password(aPath, 1, curPswd)) < 0) |
|
3404 |
return r; |
|
3405 |
||
3406 |
return TheShell->TheFs.ClearPassword(dn, curPswd); |
|
3407 |
} |
|
3408 |
||
3409 |
TInt ShellFunction::SetSize(TDes& aPath,TUint /*aSwitches*/) |
|
3410 |
// |
|
3411 |
// Set size of a file, create this if it does not exist |
|
3412 |
// |
|
3413 |
{ |
|
3414 |
TInt fileNameLen=aPath.LocateReverse(' '); |
|
3415 |
if (fileNameLen==KErrNotFound) // No spaces implies no filelength specified |
|
3416 |
{ |
|
3417 |
CShell::TheConsole->Printf(_L("Please specify a file name and a file length\n")); |
|
3418 |
return (KErrNone); |
|
3419 |
} |
|
3420 |
||
3421 |
||
3422 |
TInt fileLength=(aPath.Length()-fileNameLen); |
|
3423 |
if (fileLength>16) |
|
3424 |
return (KErrTooBig); // Too many digits - too large! |
|
3425 |
TBuf<16> rightString=aPath.Right(fileLength); |
|
3426 |
aPath.SetLength(fileNameLen); |
|
3427 |
||
3428 |
TLex size(rightString); |
|
3429 |
size.SkipSpace(); |
|
3430 |
||
3431 |
TRadix radix=ParseHexaPrefixIfAny(size); |
|
3432 |
TUint32 fileSize; |
|
3433 |
TInt r=size.Val(fileSize,radix); |
|
3434 |
if (r!=KErrNone || ! size.Eos()) |
|
3435 |
{ |
|
3436 |
CShell::TheConsole->Printf(_L("Please specify a file length\n")); |
|
3437 |
return KErrNone; |
|
3438 |
} |
|
3439 |
||
3440 |
TParse fileName; |
|
3441 |
GetFullPath(aPath,fileName); |
|
3442 |
RFile64 file; |
|
3443 |
r=file.Open(CShell::TheFs,fileName.FullName(),EFileRead|EFileWrite); |
|
3444 |
if(r==KErrNotFound) |
|
3445 |
r=file.Create(CShell::TheFs,fileName.FullName(),EFileRead|EFileWrite); |
|
3446 |
if (r==KErrNone) |
|
3447 |
{ |
|
3448 |
r=file.SetSize(fileSize); |
|
3449 |
file.Close(); |
|
3450 |
if(r!=KErrNone) |
|
3451 |
CShell::TheConsole->Printf(_L("Error (%d) - could not set size of file\n"),r); |
|
3452 |
} |
|
3453 |
else |
|
3454 |
{ |
|
3455 |
CShell::TheConsole->Printf(_L("Error (%d) - could not create or open file\n"),r); |
|
3456 |
CShell::TheFs.Delete(fileName.FullName()); |
|
3457 |
} |
|
3458 |
return(r); |
|
3459 |
} |
|
3460 |
||
3461 |
TInt ShellFunction::DebugPort(TDes& aArgs, TUint /*aSwitches*/) |
|
3462 |
// |
|
3463 |
// Set or get the debug port from the command line (debugport) |
|
3464 |
// |
|
3465 |
{ |
|
3466 |
_LIT(KGetPortLit, "Debug port is %d (0x%x)\n"); |
|
3467 |
_LIT(KSetPortLit, "Debug port set to %d (0x%x)\n"); |
|
3468 |
||
3469 |
TLex s(aArgs); |
|
3470 |
s.SkipSpace(); |
|
3471 |
if (s.Eos()) |
|
3472 |
{ |
|
3473 |
TInt port; |
|
3474 |
TInt r = HAL::Get(HALData::EDebugPort, port); |
|
3475 |
if (r != KErrNone) |
|
3476 |
return r; |
|
3477 |
CShell::TheConsole->Printf(KGetPortLit, (TUint32)port, (TUint32)port); |
|
3478 |
} |
|
3479 |
else |
|
3480 |
{ |
|
3481 |
TRadix radix=EDecimal; |
|
3482 |
if (s.Remainder().Length()>2) |
|
3483 |
{ |
|
3484 |
s.Mark(); |
|
3485 |
s.Inc(2); |
|
3486 |
if (s.MarkedToken().MatchF(_L("0x"))!=KErrNotFound) |
|
3487 |
radix=EHex; |
|
3488 |
else |
|
3489 |
s.UnGetToMark(); |
|
3490 |
} |
|
3491 |
||
3492 |
union Port |
|
3493 |
{ |
|
3494 |
TUint32 u; |
|
3495 |
TInt32 s; |
|
3496 |
}; |
|
3497 |
||
3498 |
Port port; |
|
3499 |
TInt r; |
|
3500 |
if (radix == EHex) |
|
3501 |
r = s.Val(port.u, radix); |
|
3502 |
else |
|
3503 |
r = s.Val(port.s); |
|
3504 |
if (r != KErrNone || ! s.Eos()) |
|
3505 |
return KErrBadName; |
|
3506 |
r = HAL::Set(HALData::EDebugPort, port.s); |
|
3507 |
if (r != KErrNone) |
|
3508 |
return r; |
|
3509 |
CShell::TheConsole->Printf(KSetPortLit, port.s, port.u); |
|
3510 |
} |
|
3511 |
||
3512 |
return KErrNone; |
|
3513 |
} |
|
3514 |
||
3515 |
TInt ShellFunction::Plugin(TDes& aName,TUint aSwitches) |
|
3516 |
{ |
|
3517 |
TInt err = KErrNone; |
|
3518 |
switch(aSwitches) |
|
3519 |
{ |
|
3520 |
case TShellCommand::EASwitch: |
|
3521 |
{ |
|
3522 |
err = CShell::TheFs.AddPlugin(aName); |
|
3523 |
CShell::TheConsole->Printf(_L("Add Plugin: %S [r:%d]\n"), &aName, err); |
|
3524 |
break; |
|
3525 |
} |
|
3526 |
case TShellCommand::ERSwitch: |
|
3527 |
{ |
|
3528 |
err = CShell::TheFs.RemovePlugin(aName); |
|
3529 |
CShell::TheConsole->Printf(_L("Remove Plugin: %S [r:%d]\n"), &aName, err); |
|
3530 |
break; |
|
3531 |
} |
|
3532 |
case TShellCommand::EMSwitch: |
|
3533 |
{ |
|
3534 |
err = CShell::TheFs.MountPlugin(aName); |
|
3535 |
CShell::TheConsole->Printf(_L("Mount Plugin: %S [r:%d]\n"), &aName, err); |
|
3536 |
break; |
|
3537 |
} |
|
3538 |
case TShellCommand::EDSwitch: |
|
3539 |
{ |
|
3540 |
err = CShell::TheFs.DismountPlugin(aName); |
|
3541 |
CShell::TheConsole->Printf(_L("Dismount Plugin: %S [r:%d]\n"), &aName, err); |
|
3542 |
break; |
|
3543 |
} |
|
3544 |
default: |
|
3545 |
{ |
|
3546 |
break; |
|
3547 |
} |
|
3548 |
} |
|
3549 |
return err; |
|
3550 |
} |
|
3551 |
||
3552 |
_LIT(KCrNl, "\r\n"); |
|
3553 |
||
3554 |
void SIPrintf(TRefByValue<const TDesC16> aFmt, ...) |
|
3555 |
{ |
|
3556 |
TBuf<256> buf; |
|
3557 |
VA_LIST list; |
|
3558 |
VA_START(list, aFmt); |
|
3559 |
// coverity[uninit_use_in_call] |
|
3560 |
buf.FormatList(aFmt, list); |
|
3561 |
buf.Append(KCrNl); |
|
3562 |
RDebug::RawPrint(buf); |
|
3563 |
CShell::TheConsole->Printf(buf); |
|
3564 |
} |
|
3565 |
||
3566 |
/** |
|
3567 |
Run a specified executable in a loop. |
|
3568 |
||
3569 |
RUNEXEC <count> <command [args]> [/E] [/S] [/R] |
|
3570 |
||
3571 |
count - loop count; zero (0) means: forever |
|
3572 |
command - the executable to run. Arguments can be supplied. |
|
3573 |
Limitations: |
|
3574 |
command arguments cannot contain /? switches as the shell strips these out. |
|
3575 |
command cannot contain spaces. |
|
3576 |
||
3577 |
/E terminates the loop if the program exits with an error |
|
3578 |
||
3579 |
/S makes the shell interpret "count" as a number of seconds |
|
3580 |
The shell will not attempt to terminate "command" early if it is still running after |
|
3581 |
"count" seconds. It will terminate the loop only after "command" has exited. |
|
3582 |
||
3583 |
/R will make the shell reset debug registers / trace flags after each iteration. |
|
3584 |
This is to be used if the program modifies tracing flags for its own purposes but exits |
|
3585 |
abnormally; if /R is used, later iterations will run the program from the same initial |
|
3586 |
tracing state each time. |
|
3587 |
Limitation: This flag does not yet affect BTrace / UTrace state. |
|
3588 |
||
3589 |
Switches can be combined; "RUNEXEC 2000 testprg /E/S/R" keeps running "testprg" till an error |
|
3590 |
occurs, or more than 2000 seconds have passed, and resets the debug state after each iteration. |
|
3591 |
*/ |
|
3592 |
TInt ShellFunction::RunExec(TDes& aProg, TUint aSwitches) |
|
3593 |
{ |
|
3594 |
_LIT(KRunExecFailedProcessCreate, "Failed to spawn command %S: error %d\n"); |
|
3595 |
_LIT(KRunExecReportStatusAndTime, "Total elapsed time: %d msecs, Iteration %d: Exit type %d,%d,%S\n"); |
|
3596 |
aProg.TrimAll(); |
|
3597 |
TBuf<KShellMaxCommandLine> parameters(0); |
|
3598 |
TInt r; |
|
3599 |
TInt count = 0; |
|
3600 |
TTime timeStart, timeCurrent; |
|
3601 |
TTimeIntervalMicroSeconds timeTaken; |
|
3602 |
||
3603 |
// The first parameter must be a valid decimal integer. |
|
3604 |
for (r=0; r < aProg.Length() && TChar(aProg[r]).IsDigit(); r++) |
|
3605 |
count = count * 10 + (aProg[r] - '0'); |
|
3606 |
if (r == 0 || r == aProg.Length() || TChar(aProg[r]).IsSpace() == EFalse) |
|
3607 |
return (KErrArgument); |
|
3608 |
aProg = aProg.Mid(r+1); |
|
3609 |
||
3610 |
TBool exitOnErr = (aSwitches & TShellCommand::EESwitch); |
|
3611 |
TBool resetDebugRegs = (aSwitches & TShellCommand::ERSwitch); |
|
3612 |
TBool countIsSecs = (aSwitches & TShellCommand::ESSwitch); |
|
3613 |
TBool forever = (count == 0); |
|
3614 |
||
3615 |
timeStart.HomeTime(); |
|
3616 |
||
3617 |
// copy out the parameters - if any |
|
3618 |
r = aProg.Locate(' '); |
|
3619 |
if(r != KErrNotFound) |
|
3620 |
{ |
|
3621 |
parameters = aProg.Mid(r+1); |
|
3622 |
aProg.SetLength(r); |
|
3623 |
} |
|
3624 |
||
3625 |
// Make sure the executable name qualifies as a pathname. |
|
3626 |
aProg.UpperCase(); |
|
3627 |
if (aProg.FindF(_L(".EXE")) == KErrNotFound && (aProg.Length()+4) <= KShellMaxCommandLine) |
|
3628 |
aProg.Append(_L(".EXE")); |
|
3629 |
||
3630 |
#ifdef _DEBUG |
|
3631 |
SIPrintf(_L("RUNEXEC: command %S, parameters %S, count %d, forever %d, issecs %d, exiterr %d"), |
|
3632 |
&aProg, ¶meters, count, forever, countIsSecs, exitOnErr); |
|
3633 |
#endif |
|
3634 |
TInt i=0; |
|
3635 |
FOREVER |
|
3636 |
{ |
|
3637 |
TInt retcode; |
|
3638 |
RProcess newProcess; |
|
3639 |
TRequestStatus status = KRequestPending; |
|
3640 |
TExitType exitType; |
|
3641 |
TBuf<KMaxExitCategoryName> exitCat(0); |
|
3642 |
||
3643 |
r = newProcess.Create(aProg, parameters); |
|
3644 |
if (r != KErrNone) |
|
3645 |
{ |
|
3646 |
SIPrintf(KRunExecFailedProcessCreate, &aProg, r); |
|
3647 |
return (r); // this is systematic - must return |
|
3648 |
} |
|
3649 |
newProcess.Logon(status); |
|
3650 |
newProcess.Resume(); |
|
3651 |
User::WaitForRequest(status); |
|
3652 |
exitType = newProcess.ExitType(); |
|
3653 |
exitCat = newProcess.ExitCategory(); |
|
3654 |
retcode = newProcess.ExitReason(); |
|
3655 |
newProcess.Close(); |
|
3656 |
||
3657 |
timeCurrent.HomeTime(); |
|
3658 |
timeTaken = timeCurrent.MicroSecondsFrom(timeStart); |
|
3659 |
TInt msecs = I64LOW(timeTaken.Int64() / 1000); |
|
3660 |
SIPrintf(KRunExecReportStatusAndTime, msecs, i+1, exitType, retcode, &exitCat); |
|
3661 |
||
3662 |
if (resetDebugRegs) |
|
3663 |
{ |
|
3664 |
TheShell->TheFs.SetDebugRegister(0); |
|
3665 |
User::SetDebugMask(0); |
|
3666 |
} |
|
3667 |
||
3668 |
i++; |
|
3669 |
||
3670 |
if ((exitOnErr && (exitType != EExitKill || status != KErrNone)) || // err occurred, leave requested ? |
|
3671 |
(countIsSecs && count != 0 && timeTaken.Int64() > (TInt64)1000000 * (TInt64)count) || // time elapsed ? |
|
3672 |
(!forever && i >= count)) // loop done ? |
|
3673 |
break; |
|
3674 |
} |
|
3675 |
return(KErrNone); |
|
3676 |
} |
|
3677 |
||
3678 |
// |
|
3679 |
// System information command |
|
3680 |
// |
|
3681 |
||
3682 |
TBool DebugNum(TInt aBitNum) |
|
3683 |
{ |
|
3684 |
__ASSERT_ALWAYS(aBitNum >= 0 && aBitNum <= KMAXTRACE, User::Panic(_L("Bad bit num"), 0)); |
|
3685 |
TInt index = aBitNum >> 5; |
|
3686 |
TInt m = UserSvr::DebugMask(index) & (1 << (aBitNum & 31)); |
|
3687 |
return m != 0; |
|
3688 |
} |
|
3689 |
||
3690 |
void SIHeading(TRefByValue<const TDesC16> aFmt, ...) |
|
3691 |
{ |
|
3692 |
TBuf<256> buf; |
|
3693 |
VA_LIST list; |
|
3694 |
VA_START(list, aFmt); |
|
3695 |
buf.Append(KCrNl); |
|
3696 |
buf.AppendFormatList(aFmt, list); |
|
3697 |
buf.Append(KCrNl); |
|
3698 |
RDebug::RawPrint(buf); |
|
3699 |
CShell::TheConsole->Printf(buf); |
|
3700 |
buf.Fill('=', buf.Length()-4); |
|
3701 |
buf.Append(KCrNl); |
|
3702 |
RDebug::RawPrint(buf); |
|
3703 |
CShell::TheConsole->Printf(buf); |
|
3704 |
} |
|
3705 |
||
3706 |
void SIBoolean(const TDesC& aFmt, TBool aVal) |
|
3707 |
{ |
|
3708 |
_LIT(KEnabled, "enabled"); |
|
3709 |
_LIT(KDisabled, "disabled"); |
|
3710 |
SIPrintf(aFmt, aVal ? &KEnabled : &KDisabled); |
|
3711 |
} |
|
3712 |
||
3713 |
TInt ShellFunction::SysInfo(TDes& /*aArgs*/, TUint /*aSwitches*/) |
|
3714 |
{ |
|
3715 |
SIHeading(_L("Kernel Features")); |
|
3716 |
SIBoolean(_L("Crazy scheduler delays are %S."), DebugNum(KCRAZYSCHEDDELAY)); |
|
3717 |
SIBoolean(_L("Crazy scheduler priorities and timeslicing are %S."), |
|
3718 |
UserSvr::HalFunction(EHalGroupKernel, EKernelHalConfigFlags, 0, 0) & EKernelConfigCrazyScheduling); |
|
3719 |
||
3720 |
return KErrNone; |
|
3721 |
} |
|
3722 |
||
3723 |
||
3724 |
//------------------------------------------------------------------------- |
|
3725 |
/** |
|
3726 |
Print out the command line to the console and standard debug port. |
|
3727 |
*/ |
|
3728 |
TInt ShellFunction::ConsoleEcho(TDes& aArgs, TUint /*aSwitches*/) |
|
3729 |
{ |
|
3730 |
SIPrintf(aArgs); |
|
3731 |
return KErrNone; |
|
3732 |
} |