sl@0
|
1 |
// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// e32test\misc\drvdump.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include <e32test.h>
|
sl@0
|
19 |
#include <e32svr.h>
|
sl@0
|
20 |
#include <d32locd.h>
|
sl@0
|
21 |
|
sl@0
|
22 |
RTest test(_L("DriveDump"));
|
sl@0
|
23 |
CConsoleBase* C;
|
sl@0
|
24 |
TBool Changed;
|
sl@0
|
25 |
TBusLocalDrive D;
|
sl@0
|
26 |
TInt Drive;
|
sl@0
|
27 |
TBool SerialOut=ETrue;
|
sl@0
|
28 |
|
sl@0
|
29 |
void OpenDrive()
|
sl@0
|
30 |
{
|
sl@0
|
31 |
D.Close();
|
sl@0
|
32 |
TInt r=D.Connect(Drive, Changed);
|
sl@0
|
33 |
test(r==KErrNone);
|
sl@0
|
34 |
}
|
sl@0
|
35 |
|
sl@0
|
36 |
TInt Getch()
|
sl@0
|
37 |
{
|
sl@0
|
38 |
return (TInt)C->Getch();
|
sl@0
|
39 |
}
|
sl@0
|
40 |
|
sl@0
|
41 |
void Print(const TDesC& aDes)
|
sl@0
|
42 |
{
|
sl@0
|
43 |
C->Write(aDes);
|
sl@0
|
44 |
if (SerialOut)
|
sl@0
|
45 |
RDebug::RawPrint(aDes);
|
sl@0
|
46 |
}
|
sl@0
|
47 |
|
sl@0
|
48 |
void putc(TUint aChar)
|
sl@0
|
49 |
{
|
sl@0
|
50 |
TBuf<1> b;
|
sl@0
|
51 |
b.SetLength(1);
|
sl@0
|
52 |
b[0]=(TText)aChar;
|
sl@0
|
53 |
Print(b);
|
sl@0
|
54 |
}
|
sl@0
|
55 |
|
sl@0
|
56 |
void NewLine()
|
sl@0
|
57 |
{
|
sl@0
|
58 |
Print(_L("\r\n"));
|
sl@0
|
59 |
}
|
sl@0
|
60 |
|
sl@0
|
61 |
void PrintLine(const TDesC& aDes)
|
sl@0
|
62 |
{
|
sl@0
|
63 |
Print(aDes);
|
sl@0
|
64 |
NewLine();
|
sl@0
|
65 |
}
|
sl@0
|
66 |
|
sl@0
|
67 |
void Dump(const TAny* aStart, TInt aLength, const TInt64& aAddr)
|
sl@0
|
68 |
{
|
sl@0
|
69 |
TBuf<80> out;
|
sl@0
|
70 |
TBuf<20> ascii;
|
sl@0
|
71 |
TUint a=(TUint)aStart;
|
sl@0
|
72 |
TInt64 da=aAddr;
|
sl@0
|
73 |
do
|
sl@0
|
74 |
{
|
sl@0
|
75 |
out.Zero();
|
sl@0
|
76 |
ascii.Zero();
|
sl@0
|
77 |
out.AppendNum(I64HIGH(da),EHex);
|
sl@0
|
78 |
out.AppendNumFixedWidth(I64LOW(da), EHex,8);
|
sl@0
|
79 |
out.Append(_L(": "));
|
sl@0
|
80 |
TUint b;
|
sl@0
|
81 |
for (b=0; b<16; b++)
|
sl@0
|
82 |
{
|
sl@0
|
83 |
TUint8 c=*(TUint8*)(a+b);
|
sl@0
|
84 |
out.AppendNumFixedWidth(c,EHex,2);
|
sl@0
|
85 |
out.Append(' ');
|
sl@0
|
86 |
if (b==7)
|
sl@0
|
87 |
out.Append(_L("| "));
|
sl@0
|
88 |
if (c<0x20 || c>=0x7f)
|
sl@0
|
89 |
c=0x2e;
|
sl@0
|
90 |
ascii.Append(TChar(c));
|
sl@0
|
91 |
}
|
sl@0
|
92 |
out.Append(ascii);
|
sl@0
|
93 |
PrintLine(out);
|
sl@0
|
94 |
a+=16;
|
sl@0
|
95 |
aLength-=16;
|
sl@0
|
96 |
da+=16;
|
sl@0
|
97 |
} while(aLength>0);
|
sl@0
|
98 |
}
|
sl@0
|
99 |
|
sl@0
|
100 |
void ReadDrive(TAny* aDest, const TInt64& aPos, TInt aSize)
|
sl@0
|
101 |
{
|
sl@0
|
102 |
TInt64 pos=aPos;
|
sl@0
|
103 |
TPtr8 p((TUint8*)aDest, 0, aSize);
|
sl@0
|
104 |
TInt r=D.Read(pos, aSize, p);
|
sl@0
|
105 |
if (r!=KErrNone)
|
sl@0
|
106 |
{
|
sl@0
|
107 |
test.Printf(_L("r=%d\n"), r);
|
sl@0
|
108 |
test(r==KErrNone);
|
sl@0
|
109 |
}
|
sl@0
|
110 |
}
|
sl@0
|
111 |
|
sl@0
|
112 |
TInt E32Main()
|
sl@0
|
113 |
{
|
sl@0
|
114 |
test.Title();
|
sl@0
|
115 |
C=test.Console();
|
sl@0
|
116 |
|
sl@0
|
117 |
TInt64 pos;
|
sl@0
|
118 |
TUint size;
|
sl@0
|
119 |
TBuf<256> cmdBuf;
|
sl@0
|
120 |
User::CommandLine(cmdBuf);
|
sl@0
|
121 |
TLex cmd(cmdBuf);
|
sl@0
|
122 |
cmd.SkipSpace();
|
sl@0
|
123 |
test(cmd.Val(Drive)==KErrNone);
|
sl@0
|
124 |
cmd.SkipSpace();
|
sl@0
|
125 |
test(cmd.Val(pos,EHex)==KErrNone);
|
sl@0
|
126 |
cmd.SkipSpace();
|
sl@0
|
127 |
test(cmd.Val(size,EHex)==KErrNone);
|
sl@0
|
128 |
|
sl@0
|
129 |
TUint8* buf=(TUint8*)User::Alloc(size);
|
sl@0
|
130 |
|
sl@0
|
131 |
OpenDrive();
|
sl@0
|
132 |
|
sl@0
|
133 |
TBuf<80> out;
|
sl@0
|
134 |
out.Format(_L("Drive %d"),Drive);
|
sl@0
|
135 |
PrintLine(out);
|
sl@0
|
136 |
|
sl@0
|
137 |
ReadDrive(buf, pos, size);
|
sl@0
|
138 |
Dump(buf, size, pos);
|
sl@0
|
139 |
|
sl@0
|
140 |
User::Free(buf);
|
sl@0
|
141 |
D.Close();
|
sl@0
|
142 |
|
sl@0
|
143 |
return 0;
|
sl@0
|
144 |
}
|
sl@0
|
145 |
|
sl@0
|
146 |
|