kerneltest/e32test/misc/drvdump.cpp
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 1997-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 // e32test\misc\drvdump.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32test.h>
       
    19 #include <e32svr.h>
       
    20 #include <d32locd.h>
       
    21 
       
    22 RTest test(_L("DriveDump"));
       
    23 CConsoleBase* C;
       
    24 TBool Changed;
       
    25 TBusLocalDrive D;
       
    26 TInt Drive;
       
    27 TBool SerialOut=ETrue;
       
    28 
       
    29 void OpenDrive()
       
    30 	{
       
    31 	D.Close();
       
    32 	TInt r=D.Connect(Drive, Changed);
       
    33 	test(r==KErrNone);
       
    34 	}
       
    35 
       
    36 TInt Getch()
       
    37 	{
       
    38 	return (TInt)C->Getch();
       
    39 	}
       
    40 
       
    41 void Print(const TDesC& aDes)
       
    42 	{
       
    43 	C->Write(aDes);
       
    44 	if (SerialOut)
       
    45 		RDebug::RawPrint(aDes);
       
    46 	}
       
    47 
       
    48 void putc(TUint aChar)
       
    49 	{
       
    50 	TBuf<1> b;
       
    51 	b.SetLength(1);
       
    52 	b[0]=(TText)aChar;
       
    53 	Print(b);
       
    54 	}
       
    55 
       
    56 void NewLine()
       
    57 	{
       
    58 	Print(_L("\r\n"));
       
    59 	}
       
    60 
       
    61 void PrintLine(const TDesC& aDes)
       
    62 	{
       
    63 	Print(aDes);
       
    64 	NewLine();
       
    65 	}
       
    66 
       
    67 void Dump(const TAny* aStart, TInt aLength, const TInt64& aAddr)
       
    68 	{
       
    69 	TBuf<80> out;
       
    70 	TBuf<20> ascii;
       
    71 	TUint a=(TUint)aStart;
       
    72 	TInt64 da=aAddr;
       
    73 	do
       
    74 		{
       
    75 		out.Zero();
       
    76 		ascii.Zero();
       
    77 		out.AppendNum(I64HIGH(da),EHex);
       
    78 		out.AppendNumFixedWidth(I64LOW(da), EHex,8);
       
    79 		out.Append(_L(": "));
       
    80 		TUint b;
       
    81 		for (b=0; b<16; b++)
       
    82 			{
       
    83 			TUint8 c=*(TUint8*)(a+b);
       
    84 			out.AppendNumFixedWidth(c,EHex,2);
       
    85 			out.Append(' ');
       
    86 			if (b==7)
       
    87 				out.Append(_L("| "));
       
    88 			if (c<0x20 || c>=0x7f)
       
    89 				c=0x2e;
       
    90 			ascii.Append(TChar(c));
       
    91 			}
       
    92 		out.Append(ascii);
       
    93 		PrintLine(out);
       
    94 		a+=16;
       
    95 		aLength-=16;
       
    96 		da+=16;
       
    97 		} while(aLength>0);
       
    98 	}
       
    99 
       
   100 void ReadDrive(TAny* aDest, const TInt64& aPos, TInt aSize)
       
   101 	{
       
   102 	TInt64 pos=aPos;
       
   103 	TPtr8 p((TUint8*)aDest, 0, aSize);
       
   104 	TInt r=D.Read(pos, aSize, p);
       
   105 	if (r!=KErrNone)
       
   106 		{
       
   107 		test.Printf(_L("r=%d\n"), r);
       
   108 		test(r==KErrNone);
       
   109 		}
       
   110 	}
       
   111 
       
   112 TInt E32Main()
       
   113 	{
       
   114 	test.Title();
       
   115 	C=test.Console();
       
   116 
       
   117 	TInt64 pos;
       
   118 	TUint size;
       
   119 	TBuf<256> cmdBuf;
       
   120 	User::CommandLine(cmdBuf);
       
   121 	TLex cmd(cmdBuf);
       
   122 	cmd.SkipSpace();
       
   123 	test(cmd.Val(Drive)==KErrNone);
       
   124 	cmd.SkipSpace();
       
   125 	test(cmd.Val(pos,EHex)==KErrNone);
       
   126 	cmd.SkipSpace();
       
   127 	test(cmd.Val(size,EHex)==KErrNone);
       
   128 
       
   129 	TUint8* buf=(TUint8*)User::Alloc(size);
       
   130 
       
   131 	OpenDrive();
       
   132 
       
   133 	TBuf<80> out;
       
   134 	out.Format(_L("Drive %d"),Drive);
       
   135 	PrintLine(out);
       
   136 
       
   137 	ReadDrive(buf, pos, size);
       
   138 	Dump(buf, size, pos);
       
   139 
       
   140 	User::Free(buf);
       
   141 	D.Close();
       
   142 
       
   143 	return 0;
       
   144 	}
       
   145 
       
   146