sl@0
|
1 |
// Copyright (c) 2001-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 |
// Simple app to dump out the contents of a drive
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include <e32std.h>
|
sl@0
|
19 |
#include <e32std_private.h>
|
sl@0
|
20 |
#include <e32svr.h>
|
sl@0
|
21 |
#include <e32test.h>
|
sl@0
|
22 |
#include "user_config.h"
|
sl@0
|
23 |
|
sl@0
|
24 |
RTest test( _L("TF_DUMP") );
|
sl@0
|
25 |
|
sl@0
|
26 |
|
sl@0
|
27 |
const TInt KBytesPerLine = 32;
|
sl@0
|
28 |
|
sl@0
|
29 |
|
sl@0
|
30 |
class CDumper : public CBase
|
sl@0
|
31 |
{
|
sl@0
|
32 |
public:
|
sl@0
|
33 |
~CDumper();
|
sl@0
|
34 |
|
sl@0
|
35 |
void CreateL();
|
sl@0
|
36 |
void DoDump();
|
sl@0
|
37 |
|
sl@0
|
38 |
private:
|
sl@0
|
39 |
void Add3Bytes( const TUint8* aBytes );
|
sl@0
|
40 |
|
sl@0
|
41 |
private:
|
sl@0
|
42 |
TBusLocalDrive iDrive;
|
sl@0
|
43 |
TBool iDriveOpened;
|
sl@0
|
44 |
TBool iDriveSize;
|
sl@0
|
45 |
|
sl@0
|
46 |
TBuf<KBytesPerLine> iLineBuf;
|
sl@0
|
47 |
};
|
sl@0
|
48 |
|
sl@0
|
49 |
|
sl@0
|
50 |
CDumper::~CDumper()
|
sl@0
|
51 |
{
|
sl@0
|
52 |
if( iDriveOpened )
|
sl@0
|
53 |
{
|
sl@0
|
54 |
iDrive.Disconnect();
|
sl@0
|
55 |
}
|
sl@0
|
56 |
}
|
sl@0
|
57 |
|
sl@0
|
58 |
|
sl@0
|
59 |
|
sl@0
|
60 |
void CDumper::CreateL()
|
sl@0
|
61 |
{
|
sl@0
|
62 |
//
|
sl@0
|
63 |
// Load the device driver
|
sl@0
|
64 |
//
|
sl@0
|
65 |
#ifdef UNMOUNT_DRIVE
|
sl@0
|
66 |
RFs fs;
|
sl@0
|
67 |
test( KErrNone == fs.Connect() );
|
sl@0
|
68 |
#if 0
|
sl@0
|
69 |
// XXX not EKA2
|
sl@0
|
70 |
test( KErrNone == fs.SetDefaultPath( _L("Z:\\") ) );
|
sl@0
|
71 |
#endif
|
sl@0
|
72 |
TFullName name;
|
sl@0
|
73 |
fs.FileSystemName( name, KLffsLogicalDriveNumber );
|
sl@0
|
74 |
if( name.Length() > 0 )
|
sl@0
|
75 |
{
|
sl@0
|
76 |
test.Printf( _L("Unmounting drive") );
|
sl@0
|
77 |
test( KErrNone == fs.DismountFileSystem( _L("Lffs"), KLffsLogicalDriveNumber) );
|
sl@0
|
78 |
User::After( 2000000 );
|
sl@0
|
79 |
test.Printf( _L("Drive unmounted") );
|
sl@0
|
80 |
}
|
sl@0
|
81 |
fs.Close();
|
sl@0
|
82 |
#endif
|
sl@0
|
83 |
|
sl@0
|
84 |
//
|
sl@0
|
85 |
// Open a TBusLogicalDevice to it
|
sl@0
|
86 |
//
|
sl@0
|
87 |
test.Printf( _L("Opening media channel") );
|
sl@0
|
88 |
TBool changedFlag = EFalse;
|
sl@0
|
89 |
User::LeaveIfError( iDrive.Connect( KDriveNumber, changedFlag ) );
|
sl@0
|
90 |
iDriveOpened = ETrue;
|
sl@0
|
91 |
|
sl@0
|
92 |
//
|
sl@0
|
93 |
// Get size of Flash drive
|
sl@0
|
94 |
//
|
sl@0
|
95 |
TLocalDriveCapsV2Buf info;
|
sl@0
|
96 |
iDrive.Caps(info);
|
sl@0
|
97 |
iDriveSize = I64LOW(info().iSize);
|
sl@0
|
98 |
|
sl@0
|
99 |
|
sl@0
|
100 |
iLineBuf.Zero();
|
sl@0
|
101 |
test.Printf( _L("Drive size is 0x%x bytes"), iDriveSize );
|
sl@0
|
102 |
}
|
sl@0
|
103 |
|
sl@0
|
104 |
|
sl@0
|
105 |
void CDumper::Add3Bytes( const TUint8* aBytes )
|
sl@0
|
106 |
{
|
sl@0
|
107 |
TUint8 buf[4]; // produces four output bytes
|
sl@0
|
108 |
|
sl@0
|
109 |
buf[0] = 0x30 + (aBytes[0] >> 2); // first 6 bits
|
sl@0
|
110 |
buf[1] = 0x30 + ( ((aBytes[0] << 4)&0x30) | (aBytes[1] >> 4));
|
sl@0
|
111 |
buf[2] = 0x30 + ( ((aBytes[1] << 2)&0x3C) | (aBytes[2] >> 6));
|
sl@0
|
112 |
buf[3] = 0x30 + (aBytes[2] & 0x3F); // last 6 bits
|
sl@0
|
113 |
|
sl@0
|
114 |
TInt avail = iLineBuf.MaxLength() - iLineBuf.Length();
|
sl@0
|
115 |
if( avail > 4 )
|
sl@0
|
116 |
{
|
sl@0
|
117 |
avail = 4;
|
sl@0
|
118 |
}
|
sl@0
|
119 |
|
sl@0
|
120 |
TUint8* p = &buf[0];
|
sl@0
|
121 |
for( TInt i = 0; i < avail; i++ )
|
sl@0
|
122 |
{
|
sl@0
|
123 |
iLineBuf.Append( *p++ );
|
sl@0
|
124 |
}
|
sl@0
|
125 |
if( avail < 4 )
|
sl@0
|
126 |
{
|
sl@0
|
127 |
test.Printf( iLineBuf );
|
sl@0
|
128 |
iLineBuf.Zero();
|
sl@0
|
129 |
for( TInt i = 4 - avail; i > 0; i-- )
|
sl@0
|
130 |
{
|
sl@0
|
131 |
iLineBuf.Append( *p++ );
|
sl@0
|
132 |
}
|
sl@0
|
133 |
}
|
sl@0
|
134 |
}
|
sl@0
|
135 |
|
sl@0
|
136 |
|
sl@0
|
137 |
|
sl@0
|
138 |
void CDumper::DoDump()
|
sl@0
|
139 |
{
|
sl@0
|
140 |
TBuf8<300> buf;
|
sl@0
|
141 |
|
sl@0
|
142 |
TInt remain = iDriveSize;
|
sl@0
|
143 |
TInt64 offset = 0;
|
sl@0
|
144 |
while( remain > 0 )
|
sl@0
|
145 |
{
|
sl@0
|
146 |
TInt readLen = Min( remain, 300 );
|
sl@0
|
147 |
TInt r = iDrive.Read( offset, readLen, buf );
|
sl@0
|
148 |
if( KErrNone != r )
|
sl@0
|
149 |
{
|
sl@0
|
150 |
RDebug::Print( _L("Error: drive read failed %d"), r );
|
sl@0
|
151 |
return;
|
sl@0
|
152 |
}
|
sl@0
|
153 |
TUint8* p = (TUint8*)buf.Ptr();
|
sl@0
|
154 |
TInt remainder = readLen % 3;
|
sl@0
|
155 |
if( remainder != 0 )
|
sl@0
|
156 |
{
|
sl@0
|
157 |
// leftover bytes, must be end of media, pad buffer
|
sl@0
|
158 |
buf.AppendFill( 0x0, 3 - remainder );
|
sl@0
|
159 |
readLen += 3 - remainder; // round up
|
sl@0
|
160 |
}
|
sl@0
|
161 |
for( TInt i = readLen / 3; i > 0; i-- )
|
sl@0
|
162 |
{
|
sl@0
|
163 |
Add3Bytes( p );
|
sl@0
|
164 |
p += 3;
|
sl@0
|
165 |
}
|
sl@0
|
166 |
offset += readLen;
|
sl@0
|
167 |
remain -= readLen;
|
sl@0
|
168 |
}
|
sl@0
|
169 |
test.Printf( iLineBuf ); // remaining bit
|
sl@0
|
170 |
}
|
sl@0
|
171 |
|
sl@0
|
172 |
|
sl@0
|
173 |
TInt E32Main()
|
sl@0
|
174 |
{
|
sl@0
|
175 |
test.Title();
|
sl@0
|
176 |
test.Start(_L("Dumping Flash contents...."));
|
sl@0
|
177 |
|
sl@0
|
178 |
CDumper dumper;
|
sl@0
|
179 |
TRAPD( ret, dumper.CreateL() );
|
sl@0
|
180 |
if( KErrNone == ret )
|
sl@0
|
181 |
{
|
sl@0
|
182 |
dumper.DoDump();
|
sl@0
|
183 |
}
|
sl@0
|
184 |
return KErrNone;
|
sl@0
|
185 |
}
|