sl@0: // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32test\misc\drvdump.cpp sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: RTest test(_L("DriveDump")); sl@0: CConsoleBase* C; sl@0: TBool Changed; sl@0: TBusLocalDrive D; sl@0: TInt Drive; sl@0: TBool SerialOut=ETrue; sl@0: sl@0: void OpenDrive() sl@0: { sl@0: D.Close(); sl@0: TInt r=D.Connect(Drive, Changed); sl@0: test(r==KErrNone); sl@0: } sl@0: sl@0: TInt Getch() sl@0: { sl@0: return (TInt)C->Getch(); sl@0: } sl@0: sl@0: void Print(const TDesC& aDes) sl@0: { sl@0: C->Write(aDes); sl@0: if (SerialOut) sl@0: RDebug::RawPrint(aDes); sl@0: } sl@0: sl@0: void putc(TUint aChar) sl@0: { sl@0: TBuf<1> b; sl@0: b.SetLength(1); sl@0: b[0]=(TText)aChar; sl@0: Print(b); sl@0: } sl@0: sl@0: void NewLine() sl@0: { sl@0: Print(_L("\r\n")); sl@0: } sl@0: sl@0: void PrintLine(const TDesC& aDes) sl@0: { sl@0: Print(aDes); sl@0: NewLine(); sl@0: } sl@0: sl@0: void Dump(const TAny* aStart, TInt aLength, const TInt64& aAddr) sl@0: { sl@0: TBuf<80> out; sl@0: TBuf<20> ascii; sl@0: TUint a=(TUint)aStart; sl@0: TInt64 da=aAddr; sl@0: do sl@0: { sl@0: out.Zero(); sl@0: ascii.Zero(); sl@0: out.AppendNum(I64HIGH(da),EHex); sl@0: out.AppendNumFixedWidth(I64LOW(da), EHex,8); sl@0: out.Append(_L(": ")); sl@0: TUint b; sl@0: for (b=0; b<16; b++) sl@0: { sl@0: TUint8 c=*(TUint8*)(a+b); sl@0: out.AppendNumFixedWidth(c,EHex,2); sl@0: out.Append(' '); sl@0: if (b==7) sl@0: out.Append(_L("| ")); sl@0: if (c<0x20 || c>=0x7f) sl@0: c=0x2e; sl@0: ascii.Append(TChar(c)); sl@0: } sl@0: out.Append(ascii); sl@0: PrintLine(out); sl@0: a+=16; sl@0: aLength-=16; sl@0: da+=16; sl@0: } while(aLength>0); sl@0: } sl@0: sl@0: void ReadDrive(TAny* aDest, const TInt64& aPos, TInt aSize) sl@0: { sl@0: TInt64 pos=aPos; sl@0: TPtr8 p((TUint8*)aDest, 0, aSize); sl@0: TInt r=D.Read(pos, aSize, p); sl@0: if (r!=KErrNone) sl@0: { sl@0: test.Printf(_L("r=%d\n"), r); sl@0: test(r==KErrNone); sl@0: } sl@0: } sl@0: sl@0: TInt E32Main() sl@0: { sl@0: test.Title(); sl@0: C=test.Console(); sl@0: sl@0: TInt64 pos; sl@0: TUint size; sl@0: TBuf<256> cmdBuf; sl@0: User::CommandLine(cmdBuf); sl@0: TLex cmd(cmdBuf); sl@0: cmd.SkipSpace(); sl@0: test(cmd.Val(Drive)==KErrNone); sl@0: cmd.SkipSpace(); sl@0: test(cmd.Val(pos,EHex)==KErrNone); sl@0: cmd.SkipSpace(); sl@0: test(cmd.Val(size,EHex)==KErrNone); sl@0: sl@0: TUint8* buf=(TUint8*)User::Alloc(size); sl@0: sl@0: OpenDrive(); sl@0: sl@0: TBuf<80> out; sl@0: out.Format(_L("Drive %d"),Drive); sl@0: PrintLine(out); sl@0: sl@0: ReadDrive(buf, pos, size); sl@0: Dump(buf, size, pos); sl@0: sl@0: User::Free(buf); sl@0: D.Close(); sl@0: sl@0: return 0; sl@0: } sl@0: sl@0: