Update contrib.
1 // Copyright (c) 2001-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Simple app to dump out the contents of a drive
19 #include <e32std_private.h>
22 #include "user_config.h"
24 RTest test( _L("TF_DUMP") );
27 const TInt KBytesPerLine = 32;
30 class CDumper : public CBase
39 void Add3Bytes( const TUint8* aBytes );
42 TBusLocalDrive iDrive;
46 TBuf<KBytesPerLine> iLineBuf;
60 void CDumper::CreateL()
63 // Load the device driver
67 test( KErrNone == fs.Connect() );
70 test( KErrNone == fs.SetDefaultPath( _L("Z:\\") ) );
73 fs.FileSystemName( name, KLffsLogicalDriveNumber );
74 if( name.Length() > 0 )
76 test.Printf( _L("Unmounting drive") );
77 test( KErrNone == fs.DismountFileSystem( _L("Lffs"), KLffsLogicalDriveNumber) );
78 User::After( 2000000 );
79 test.Printf( _L("Drive unmounted") );
85 // Open a TBusLogicalDevice to it
87 test.Printf( _L("Opening media channel") );
88 TBool changedFlag = EFalse;
89 User::LeaveIfError( iDrive.Connect( KDriveNumber, changedFlag ) );
93 // Get size of Flash drive
95 TLocalDriveCapsV2Buf info;
97 iDriveSize = I64LOW(info().iSize);
101 test.Printf( _L("Drive size is 0x%x bytes"), iDriveSize );
105 void CDumper::Add3Bytes( const TUint8* aBytes )
107 TUint8 buf[4]; // produces four output bytes
109 buf[0] = 0x30 + (aBytes[0] >> 2); // first 6 bits
110 buf[1] = 0x30 + ( ((aBytes[0] << 4)&0x30) | (aBytes[1] >> 4));
111 buf[2] = 0x30 + ( ((aBytes[1] << 2)&0x3C) | (aBytes[2] >> 6));
112 buf[3] = 0x30 + (aBytes[2] & 0x3F); // last 6 bits
114 TInt avail = iLineBuf.MaxLength() - iLineBuf.Length();
121 for( TInt i = 0; i < avail; i++ )
123 iLineBuf.Append( *p++ );
127 test.Printf( iLineBuf );
129 for( TInt i = 4 - avail; i > 0; i-- )
131 iLineBuf.Append( *p++ );
138 void CDumper::DoDump()
142 TInt remain = iDriveSize;
146 TInt readLen = Min( remain, 300 );
147 TInt r = iDrive.Read( offset, readLen, buf );
150 RDebug::Print( _L("Error: drive read failed %d"), r );
153 TUint8* p = (TUint8*)buf.Ptr();
154 TInt remainder = readLen % 3;
157 // leftover bytes, must be end of media, pad buffer
158 buf.AppendFill( 0x0, 3 - remainder );
159 readLen += 3 - remainder; // round up
161 for( TInt i = readLen / 3; i > 0; i-- )
169 test.Printf( iLineBuf ); // remaining bit
176 test.Start(_L("Dumping Flash contents...."));
179 TRAPD( ret, dumper.CreateL() );
180 if( KErrNone == ret )