author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 31 Aug 2010 16:34:26 +0300 | |
branch | RCL_3 |
changeset 43 | c1f20ce4abcf |
parent 0 | a41df078684a |
child 44 | 3e88ff8f41d5 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1996-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 |
// @file |
|
15 |
// various FAT utilities |
|
16 |
// |
|
17 |
// |
|
18 |
||
19 |
#include "f32_test_utils.h" |
|
20 |
using namespace F32_Test_Utils; |
|
21 |
||
22 |
#include "filesystem_fat.h" |
|
23 |
||
24 |
//------------------------------------------------------------------------------------------------------------------- |
|
25 |
||
26 |
//-- define this macro if it is necessarily to exclude all stuff that uses RFs, consoles etc. |
|
27 |
//-- may be useful if this code is used for file server extensions. mmp file is a good place to define this macro. |
|
28 |
#ifndef FAT_UTILS_LEAN_AND_MEAN |
|
29 |
||
30 |
#include <e32cons.h> |
|
31 |
#include <e32math.h> |
|
32 |
||
33 |
//-- Note that the writable static data are not allowed in DLLs i.e. plugins or somethig else. |
|
34 |
//-- Thus it needs to be thrown away by preprocessing in such a case. |
|
35 |
||
36 |
static CConsoleBase* pConsole = NULL; //-- pointer to the text console for printing out data |
|
37 |
static TBool bPrintOutEnabled = ETrue; //-- global flag, if EFalse, all printing out is disabled |
|
38 |
||
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
39 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
40 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
41 |
//------------------------------------------------------------------------------------------------------------------- |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
42 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
43 |
/** |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
44 |
Prints out a hex dump of a descriptor contents |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
45 |
@param aBuf data descriptor to dump |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
46 |
*/ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
47 |
void F32_Test_Utils::HexDump(const TDesC8& aBuf) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
48 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
49 |
HexDump(aBuf.Ptr(), aBuf.Size()); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
50 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
51 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
52 |
//------------------------------------------------------------------------------------------------------------------- |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
53 |
/** |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
54 |
Prints out a hex dump of a buffer |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
55 |
@param apBuf pointer to the data to dump |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
56 |
@param aBufLen buffer length |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
57 |
*/ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
58 |
void F32_Test_Utils::HexDump(const TAny* apBuf, TUint aBufLen) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
59 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
60 |
DoPrintf(_L("~ F32_Test_Utils::HexDump() size:%u\n"), aBufLen); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
61 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
62 |
ASSERT(apBuf); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
63 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
64 |
if(!aBufLen) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
65 |
return; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
66 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
67 |
const TUint colDmpWidth = 16; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
68 |
const TUint8* pBuf = (const TUint8*)apBuf; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
69 |
TBuf<256> buf1; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
70 |
TBuf<64> buf2; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
71 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
72 |
TUint dumpPos; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
73 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
74 |
for(dumpPos=0; dumpPos < aBufLen-1; ) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
75 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
76 |
buf1.Format(_L("%06X: "), dumpPos); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
77 |
buf2.Zero(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
78 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
79 |
for(TUint i=0; i<colDmpWidth; ++i) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
80 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
81 |
buf1.AppendFormat(_L("%02x "), pBuf[dumpPos+i]); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
82 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
83 |
const TChar ch = pBuf[dumpPos+i]; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
84 |
if(ch.IsPrint()) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
85 |
buf2.Append(ch); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
86 |
else |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
87 |
buf2.Append(_L(".")); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
88 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
89 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
90 |
if(++dumpPos >= aBufLen) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
91 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
92 |
while(++i < colDmpWidth) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
93 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
94 |
buf1.Append(_L(" ")); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
95 |
buf2.Append(_L(" ")); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
96 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
97 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
98 |
break; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
99 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
100 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
101 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
102 |
buf1.Append(buf2); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
103 |
DoPrintf(buf1); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
104 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
105 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
106 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
107 |
DoPrintf(_L("\n")); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
108 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
109 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
110 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
111 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
112 |
//------------------------------------------------------------------------------------------------------------------- |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
113 |
/** |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
114 |
Compare 2 buffers and print out the difference if there is any. |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
115 |
Buffer sizes must be the same and non-0 |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
116 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
117 |
@param aBuf1 buffer 1 descriptor |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
118 |
@param aBuf2 buffer 2 descriptor |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
119 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
120 |
@return ETrue if buffers are the same, EFalse otherwise |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
121 |
*/ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
122 |
TBool F32_Test_Utils::CompareBuffers(const TDesC8& aBuf1, const TDesC8& aBuf2) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
123 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
124 |
return CompareBuffers(aBuf1.Ptr(), aBuf1.Size(), aBuf2.Ptr(), aBuf2.Size()); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
125 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
126 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
127 |
//------------------------------------------------------------------------------------------------------------------- |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
128 |
/** |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
129 |
Compare 2 buffers and print out the difference if there is any. |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
130 |
Buffer sizes must be the same and non-0 |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
131 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
132 |
@param apBuf1 pointer to the buffer 1 |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
133 |
@param aBuf1Len buffer1 length |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
134 |
@param apBuf2 pointer to the buffer 2 |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
135 |
@param aBuf2Len buffer2 length |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
136 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
137 |
@return ETrue if buffers are the same, EFalse otherwise |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
138 |
*/ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
139 |
TBool F32_Test_Utils::CompareBuffers(const TAny* apBuf1, TUint aBuf1Len, const TAny* apBuf2, TUint aBuf2Len) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
140 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
141 |
ASSERT(apBuf1 && apBuf2); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
142 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
143 |
if(aBuf1Len != aBuf2Len) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
144 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
145 |
DoPrintf(_L("~ F32_Test_Utils::CompareBuffers() different sizes! %u:%u\n"), aBuf1Len, aBuf2Len); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
146 |
ASSERT(0); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
147 |
return EFalse; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
148 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
149 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
150 |
if(!aBuf1Len) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
151 |
{//-- empty buffers to compare |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
152 |
return ETrue; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
153 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
154 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
155 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
156 |
const TUint8* pBuf1 = (const TUint8*)apBuf1; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
157 |
const TUint8* pBuf2 = (const TUint8*)apBuf2; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
158 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
159 |
if(!Mem::Compare(pBuf1, aBuf1Len, pBuf2, aBuf2Len)) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
160 |
return ETrue; //-- buffers are the same. |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
161 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
162 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
163 |
//-- the buffers' contents are different |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
164 |
TUint diffpos; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
165 |
TBuf<256> buf1; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
166 |
TBuf<100> buf2; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
167 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
168 |
const TUint colDmpWidth = 16; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
169 |
TBool bBannerPrinted = EFalse; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
170 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
171 |
//-- dump chunks of the buffer with differences only |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
172 |
for(diffpos=0; diffpos<aBuf1Len-1; ) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
173 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
174 |
if(pBuf1[diffpos] == pBuf2[diffpos]) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
175 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
176 |
++diffpos; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
177 |
continue; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
178 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
179 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
180 |
if(!bBannerPrinted) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
181 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
182 |
bBannerPrinted = ETrue; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
183 |
DoPrintf(_L("~ F32_Test_Utils::CompareBuffers() buffers' contents are different starting at pos:%u (0x%x). Hexdump:\n"), diffpos, diffpos); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
184 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
185 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
186 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
187 |
//-- difference found, dump chunks of the buffer with differences only |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
188 |
TUint dumpPos = (diffpos >> 4) << 4; //-- round down to 16 |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
189 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
190 |
buf1.Format(_L("%06X: "), dumpPos); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
191 |
buf2.Format(_L("|")); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
192 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
193 |
for(TUint i=0; i<colDmpWidth; ++i) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
194 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
195 |
buf1.AppendFormat(_L("%02x"), pBuf1[dumpPos+i]); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
196 |
buf2.AppendFormat(_L("%02x"), pBuf2[dumpPos+i]); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
197 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
198 |
if(i < colDmpWidth-1) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
199 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
200 |
buf1.Append(_L(" ")); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
201 |
buf2.Append(_L(" ")); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
202 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
203 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
204 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
205 |
if(++diffpos >= aBuf1Len) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
206 |
{//-- pad the dump with spaces |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
207 |
while(++i < colDmpWidth) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
208 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
209 |
buf1.Append(_L(" ")); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
210 |
buf2.Append(_L(" ")); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
211 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
212 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
213 |
break; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
214 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
215 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
216 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
217 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
218 |
buf1.Append(buf2); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
219 |
DoPrintf(buf1); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
220 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
221 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
222 |
DoPrintf(_L("\n")); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
223 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
224 |
return EFalse; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
225 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
226 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
227 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
228 |
//------------------------------------------------------------------------------------------------------------------- |
0 | 229 |
/** |
230 |
Set the console where the ouput will go. |
|
231 |
@param apConsole pointer to the console. if NULL, the print out will be debug port only. |
|
232 |
*/ |
|
233 |
void F32_Test_Utils::SetConsole(CConsoleBase* apConsole) |
|
234 |
{ |
|
235 |
pConsole = apConsole; |
|
236 |
} |
|
237 |
||
238 |
/** |
|
239 |
Enable or disable printing out. See DoPrintf() |
|
240 |
@param bEnable If ETrue, print out is enabled |
|
241 |
@return previous value of the global bPrintOutEnabled flag |
|
242 |
*/ |
|
243 |
TBool F32_Test_Utils::EnablePrintOutput(TBool bEnable) |
|
244 |
{ |
|
245 |
TBool bPrevVal = bPrintOutEnabled; |
|
246 |
bPrintOutEnabled = bEnable; |
|
247 |
||
248 |
return bPrevVal; |
|
249 |
} |
|
250 |
||
251 |
/** |
|
252 |
Print out the drive information. |
|
253 |
||
254 |
@param aFs reference to the FS session |
|
255 |
@param aDrive drive number |
|
256 |
@return system-wide error codes. |
|
257 |
*/ |
|
258 |
TInt F32_Test_Utils::PrintDrvInfo(RFs &aFs, TInt aDrive) |
|
259 |
{ |
|
260 |
TInt nRes; |
|
261 |
TDriveInfo driveInfo; |
|
262 |
TVolumeInfo volInfo; |
|
263 |
TBuf<256> Buf; |
|
264 |
||
265 |
//-- get drive info |
|
266 |
nRes = aFs.Drive(driveInfo, aDrive); |
|
267 |
if(nRes != KErrNone) |
|
268 |
return nRes; |
|
269 |
||
270 |
nRes = aFs.Volume(volInfo, aDrive); |
|
271 |
if(nRes != KErrNone) |
|
272 |
return nRes; |
|
273 |
||
274 |
DoPrintf(_L("Drive %c: #%d\n"), 'A'+aDrive, aDrive); |
|
275 |
||
276 |
//-- print the FS name |
|
277 |
nRes = aFs.FileSystemName(Buf, aDrive); |
|
278 |
if(nRes != KErrNone) |
|
279 |
return nRes; |
|
280 |
||
281 |
//-- to find out FS sub type |
|
282 |
TFSName fsName; |
|
283 |
nRes = aFs.FileSystemSubType(aDrive, fsName); |
|
284 |
if(nRes == KErrNone && Buf.CompareF(fsName) !=KErrNone) |
|
285 |
{ |
|
286 |
Buf.AppendFormat(_L(" (%S)"), &fsName); |
|
287 |
} |
|
288 |
||
289 |
||
290 |
DoPrintf(_L("FS name: %S\n"), &Buf); |
|
291 |
||
292 |
//-- print drive and media attributes |
|
293 |
DoPrintf(_L("MediaType: 0x%x\n"), driveInfo.iType); |
|
294 |
DoPrintf(_L("DriveAtt:0x%x\n"),driveInfo.iDriveAtt); |
|
295 |
DoPrintf(_L("MediaAtt:0x%x\n"),driveInfo.iMediaAtt); |
|
296 |
||
297 |
//-- volume information |
|
298 |
DoPrintf(_L("VolId:0x%x\n"),volInfo.iUniqueID); |
|
299 |
DoPrintf(_L("VolSz:%ld (%ldK)\n"),volInfo.iSize, volInfo.iSize/1024); |
|
300 |
DoPrintf(_L("Free:%ld (%ldK)\n"),volInfo.iFree, volInfo.iFree/1024); |
|
301 |
||
302 |
return KErrNone; |
|
303 |
} |
|
304 |
||
305 |
//------------------------------------------------------------------------------------------------------------------- |
|
306 |
||
307 |
||
308 |
/** |
|
309 |
Fill a media region with a given byte pattern |
|
310 |
||
311 |
@param aFs reference to the FS session |
|
312 |
@param aDrive drive number |
|
313 |
@param aMediaStartPos media region start position |
|
314 |
@param aMediaEndPos media region end position |
|
315 |
@param aBytePattern byte to fill the media region with |
|
316 |
||
317 |
@return system-wide error codes. |
|
318 |
*/ |
|
319 |
TInt F32_Test_Utils::FillMedia(RFs &aFs, TInt aDrive, TInt64 aMediaStartPos, TInt64 aMediaEndPos, TUint8 aBytePattern/*=0*/) |
|
320 |
{ |
|
321 |
DoPrintf(_L("~ F32_Test_Utils::FillMedia() drv:%d, from:%u to:%u\n"),aDrive, (TUint32)aMediaStartPos, (TUint32)aMediaEndPos); |
|
322 |
||
323 |
ASSERT(aMediaStartPos<=aMediaEndPos && aMediaStartPos >=0 && aMediaEndPos >=0); |
|
324 |
||
325 |
TInt nRes = KErrNone; |
|
326 |
RBuf8 buf; |
|
327 |
const TUint32 KBufSz=65536; //-- zero-buffer size, bytes |
|
328 |
||
329 |
//-- create a buffer, filled with given pattern |
|
330 |
nRes = buf.CreateMax(KBufSz); |
|
331 |
ASSERT(nRes == KErrNone); |
|
332 |
buf.Fill(aBytePattern); |
|
333 |
||
334 |
TUint32 rem = (TUint32)(aMediaEndPos - aMediaStartPos); |
|
335 |
while(rem) |
|
336 |
{ |
|
337 |
const TUint32 bytesToWrite=Min(rem, KBufSz); |
|
338 |
TPtrC8 ptrData(buf.Ptr(), bytesToWrite); |
|
339 |
||
340 |
nRes = MediaRawWrite(aFs, aDrive, aMediaStartPos, ptrData); |
|
341 |
if(nRes != KErrNone && nRes != KErrDiskFull) |
|
342 |
break; |
|
343 |
||
344 |
aMediaStartPos+=bytesToWrite; |
|
345 |
rem-=bytesToWrite; |
|
346 |
} |
|
347 |
||
348 |
buf.Close(); |
|
349 |
||
350 |
return nRes; |
|
351 |
} |
|
352 |
||
353 |
||
354 |
//------------------------------------------------------------------------------------------------------------------- |
|
355 |
||
356 |
/** |
|
357 |
Raw read from the media. |
|
358 |
||
359 |
@param aFs reference to the FS session |
|
360 |
@param aDrive drive number |
|
361 |
@param aMediaPos media position |
|
362 |
@param aLen how many bytes to read |
|
363 |
@param aData descriptor for the data |
|
364 |
||
365 |
@return system-wide error code. |
|
366 |
*/ |
|
367 |
TInt F32_Test_Utils::MediaRawRead(RFs &aFs, TInt aDrive, TInt64 aMediaPos, TUint32 aLen, TDes8& aData) |
|
368 |
{ |
|
369 |
TInt nRes=KErrNone; |
|
370 |
TRAP(nRes, DoMediaRawReadL(aFs, aDrive, aMediaPos, aLen, aData)); |
|
371 |
return nRes; |
|
372 |
} |
|
373 |
||
374 |
//------------------------------------------------------------------------------------------------------------------- |
|
375 |
||
376 |
/** |
|
377 |
Raw write to the media. |
|
378 |
||
379 |
@param aFs reference to the FS session |
|
380 |
@param aDrive drive number |
|
381 |
@param aMediaPos media position |
|
382 |
@param aData descriptor with the data to write |
|
383 |
||
384 |
@return system-wide error code. |
|
385 |
*/ |
|
386 |
TInt F32_Test_Utils::MediaRawWrite(RFs &aFs, TInt aDrive, TInt64 aMediaPos, const TDesC8& aData) |
|
387 |
{ |
|
388 |
TInt nRes=KErrNone; |
|
389 |
TRAP(nRes, DoMediaRawWriteL(aFs, aDrive, aMediaPos, aData)); |
|
390 |
return nRes; |
|
391 |
} |
|
392 |
||
393 |
||
394 |
//------------------------------------------------------------------------------------------------------------------- |
|
395 |
void F32_Test_Utils::DoMediaRawReadL(RFs &aFs, TInt aDrive, TInt64 aMediaPos, TUint32 aLen, TDes8& aData) |
|
396 |
{ |
|
397 |
ASSERT(aMediaPos>=0); |
|
398 |
ASSERT(aDrive >= EDriveA && aDrive <= EDriveZ); |
|
399 |
||
400 |
if((TUint32)aData.MaxSize() < aLen) |
|
401 |
User::Leave(KErrArgument); |
|
402 |
||
403 |
if(aLen == 0) |
|
404 |
return; |
|
405 |
||
406 |
aData.SetLength(aLen); |
|
407 |
||
408 |
RRawDisk rawDisk; |
|
409 |
CleanupClosePushL(rawDisk); |
|
410 |
||
411 |
User::LeaveIfError(rawDisk.Open(aFs, aDrive)); |
|
412 |
User::LeaveIfError(rawDisk.Read(aMediaPos, aData)); |
|
413 |
||
414 |
CleanupStack::PopAndDestroy(&rawDisk); |
|
415 |
} |
|
416 |
||
417 |
//------------------------------------------------------------------------------------------------------------------- |
|
418 |
void F32_Test_Utils::DoMediaRawWriteL(RFs &aFs, TInt aDrive, TInt64 aMediaPos, const TDesC8& aData) |
|
419 |
{ |
|
420 |
ASSERT(aMediaPos>=0); |
|
421 |
ASSERT(aDrive >= EDriveA && aDrive <= EDriveZ); |
|
422 |
||
423 |
if(aData.Size() == 0) |
|
424 |
return; |
|
425 |
||
426 |
RRawDisk rawDisk; |
|
427 |
CleanupClosePushL(rawDisk); |
|
428 |
||
429 |
User::LeaveIfError(rawDisk.Open(aFs, aDrive)); |
|
430 |
User::LeaveIfError(rawDisk.Write(aMediaPos, (TDesC8&)aData)); |
|
431 |
||
432 |
CleanupStack::PopAndDestroy(&rawDisk); |
|
433 |
} |
|
434 |
||
435 |
//------------------------------------------------------------------------------------------------------------------- |
|
436 |
||
437 |
_LIT(KFsName_LFFS, "lffs"); |
|
438 |
_LIT(KFsName_Win32, "Win32"); |
|
439 |
_LIT(KFsName_ExFAT, "ExFat"); |
|
440 |
_LIT(KFsName_AutoMonuter, "automounter"); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
441 |
_LIT(KFsName_HVFS, "HVFS"); |
0 | 442 |
|
443 |
/** @return ETrue if "Automounter" FS is mounted on this drive */ |
|
444 |
TBool F32_Test_Utils::Is_Automounter(RFs &aFs, TInt aDrive) |
|
445 |
{ |
|
446 |
ASSERT(aDrive >= EDriveA && aDrive <= EDriveZ); |
|
447 |
TFSName f; |
|
448 |
TInt r = aFs.FileSystemName(f, aDrive); |
|
449 |
__ASSERT_ALWAYS((r==KErrNone) && (f.Length()>0), User::Invariant()); |
|
450 |
||
451 |
return (f.CompareF(KFsName_AutoMonuter) == 0 ); |
|
452 |
||
453 |
} |
|
454 |
||
455 |
/** @return ETrue if "lffs" FS is mounted on this drive */ |
|
456 |
TBool F32_Test_Utils::Is_Lffs(RFs &aFs, TInt aDrive) |
|
457 |
{ |
|
458 |
ASSERT(aDrive >= EDriveA && aDrive <= EDriveZ); |
|
459 |
TFSName f; |
|
460 |
TInt r = aFs.FileSystemName(f, aDrive); |
|
461 |
__ASSERT_ALWAYS((r==KErrNone) && (f.Length()>0), User::Invariant()); |
|
462 |
||
463 |
return (f.CompareF(KFsName_LFFS) == 0 ); |
|
464 |
||
465 |
} |
|
466 |
||
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
467 |
/** @return ETrue if "Win32" FS is mounted on this drive (i.e this is emulator's drive C:) */ |
0 | 468 |
TBool F32_Test_Utils::Is_Win32(RFs &aFs, TInt aDrive) |
469 |
{ |
|
470 |
ASSERT(aDrive >= EDriveA && aDrive <= EDriveZ); |
|
471 |
TFSName f; |
|
472 |
TInt r = aFs.FileSystemName(f, aDrive); |
|
473 |
__ASSERT_ALWAYS((r==KErrNone) && (f.Length()>0), User::Invariant()); |
|
474 |
||
475 |
return (f.CompareF(KFsName_Win32) == 0 ); |
|
476 |
} |
|
477 |
||
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
478 |
/** @return ETrue if "HVFS" is mounted on this drive (i.e PlatSim's drive C:) */ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
479 |
TBool F32_Test_Utils::Is_HVFS(RFs &aFs, TInt aDrive) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
480 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
481 |
ASSERT(aDrive >= EDriveA && aDrive <= EDriveZ); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
482 |
TFSName f; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
483 |
TInt r = aFs.FileSystemName(f, aDrive); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
484 |
__ASSERT_ALWAYS((r==KErrNone) && (f.Length()>0), User::Invariant()); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
485 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
486 |
return (f.CompareF(KFsName_HVFS) == 0); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
487 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
488 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
489 |
/** @return ETrue if "HVFS" or "Win32" FS is mounted on this drive |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
490 |
* (i.e drive C: of PlatSim or the emulator) */ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
491 |
TBool F32_Test_Utils::Is_SimulatedSystemDrive(RFs &aFs, TInt aDrive) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
492 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
493 |
ASSERT(aDrive >= EDriveA && aDrive <= EDriveZ); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
494 |
TFSName f; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
495 |
TInt r = aFs.FileSystemName(f, aDrive); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
496 |
__ASSERT_ALWAYS((r==KErrNone) && (f.Length()>0), User::Invariant()); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
497 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
498 |
return (f.CompareF(KFsName_HVFS) == 0 || f.CompareF(KFsName_Win32) == 0); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
499 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
500 |
|
0 | 501 |
/** @return ETrue if the filesystem if FAT (fat12/16/32) */ |
502 |
TBool F32_Test_Utils::Is_Fat(RFs &aFs, TInt aDrive) |
|
503 |
{ |
|
504 |
ASSERT(aDrive >= EDriveA && aDrive <= EDriveZ); |
|
505 |
TFSName fsName; |
|
506 |
TInt nRes = aFs.FileSystemName(fsName, aDrive); |
|
507 |
__ASSERT_ALWAYS((nRes==KErrNone) && (fsName.Length()>0), User::Invariant()); |
|
508 |
||
509 |
if(fsName.CompareF(KFileSystemName_FAT) == 0) |
|
510 |
return ETrue; //-- "FAT" FS is explicitly mounted on this drive |
|
511 |
||
512 |
//-- try analyse file system subtype for the case of automounter FS |
|
513 |
nRes = aFs.FileSystemSubType(aDrive,fsName); |
|
514 |
if(nRes !=KErrNone) |
|
515 |
return EFalse; |
|
516 |
||
517 |
return (fsName.CompareF(KFSSubType_FAT16) == 0 || fsName.CompareF(KFSSubType_FAT32) == 0 || fsName.CompareF(KFSSubType_FAT12) == 0); |
|
518 |
} |
|
519 |
||
520 |
/** returns ETrue if "exFAT" FS is mounted on this drive */ |
|
521 |
TBool F32_Test_Utils::Is_ExFat(RFs &aFs, TInt aDrive) |
|
522 |
{ |
|
523 |
ASSERT(aDrive >= EDriveA && aDrive <= EDriveZ); |
|
524 |
TFSName fsName; |
|
525 |
TInt nRes = aFs.FileSystemName(fsName, aDrive); |
|
526 |
__ASSERT_ALWAYS((nRes==KErrNone) && (fsName.Length()>0), User::Invariant()); |
|
527 |
||
528 |
if(fsName.CompareF(KFsName_ExFAT) == 0 ) |
|
529 |
return ETrue; //-- "exFAT" FS is explicitly mounted on this drive |
|
530 |
||
531 |
//-- try analyse file system subtype for the case of automounter FS |
|
532 |
nRes = aFs.FileSystemSubType(aDrive,fsName); |
|
533 |
if(nRes !=KErrNone) |
|
534 |
return EFalse; |
|
535 |
||
536 |
return (fsName.CompareF(KFsName_ExFAT) == 0); |
|
537 |
} |
|
538 |
||
539 |
/** @return ETrue if the filesystem if FAT32 */ |
|
540 |
TBool F32_Test_Utils::Is_Fat32(RFs &aFs, TInt aDrive) |
|
541 |
{ |
|
542 |
if(!Is_Fat(aFs, aDrive)) |
|
543 |
return EFalse; |
|
544 |
||
545 |
TFSName fsName; |
|
546 |
TInt nRes = aFs.FileSystemSubType(aDrive,fsName); |
|
547 |
||
548 |
if(nRes !=KErrNone) |
|
549 |
return EFalse; |
|
550 |
||
551 |
return (fsName.CompareF(KFSSubType_FAT32) == 0); |
|
552 |
||
553 |
} |
|
554 |
||
555 |
/** @return ETrue if the filesystem if FAT16 */ |
|
556 |
TBool F32_Test_Utils::Is_Fat16(RFs &aFs, TInt aDrive) |
|
557 |
{ |
|
558 |
if(!Is_Fat(aFs, aDrive)) |
|
559 |
return EFalse; |
|
560 |
||
561 |
TFSName fsName; |
|
562 |
TInt nRes = aFs.FileSystemSubType(aDrive,fsName); |
|
563 |
||
564 |
if(nRes !=KErrNone) |
|
565 |
return EFalse; |
|
566 |
||
567 |
return (fsName.CompareF(KFSSubType_FAT16) == 0); |
|
568 |
||
569 |
} |
|
570 |
||
571 |
/** @return ETrue if the filesystem if FAT12 */ |
|
572 |
TBool F32_Test_Utils::Is_Fat12(RFs &aFs, TInt aDrive) |
|
573 |
{ |
|
574 |
if(!Is_Fat(aFs, aDrive)) |
|
575 |
return EFalse; |
|
576 |
||
577 |
TFSName fsName; |
|
578 |
TInt nRes = aFs.FileSystemSubType(aDrive,fsName); |
|
579 |
||
580 |
if(nRes !=KErrNone) |
|
581 |
return EFalse; |
|
582 |
||
583 |
return (fsName.CompareF(KFSSubType_FAT12) == 0); |
|
584 |
||
585 |
} |
|
586 |
||
587 |
||
588 |
static void DoCreateCheckableFileL(RFile64& aFile, TUint64 aSize) |
|
589 |
{ |
|
590 |
||
591 |
ASSERT(aSize >= TMD5::HashSize); |
|
592 |
||
593 |
//-- 1. set file size |
|
594 |
User::LeaveIfError(aFile.SetSize((TInt)aSize)); |
|
595 |
||
596 |
//-- 2. leave place for the 16-bytes MD5 hash in the file beginning |
|
597 |
TInt64 filePos = TMD5::HashSize; |
|
598 |
User::LeaveIfError(aFile.Seek(ESeekStart,filePos)); |
|
599 |
aSize-=TMD5::HashSize; |
|
600 |
||
601 |
TMD5 md5Hash; |
|
602 |
||
603 |
//-- 3. fill the file with random bytes |
|
604 |
const TInt KBufSize=65536; //-- buffer size for writing data |
|
605 |
TInt64 rndSeed = aSize % 43283; |
|
606 |
if(!rndSeed) |
|
607 |
rndSeed = 33521; |
|
608 |
||
609 |
RBuf8 buf; |
|
610 |
buf.CreateMaxL(KBufSize); |
|
611 |
||
612 |
TUint64 prevSz = aSize; |
|
613 |
while(aSize) |
|
614 |
{ |
|
615 |
//-- initialize buffer with random rubbish |
|
616 |
for(TInt i=0; i<KBufSize; ++i) |
|
617 |
{ |
|
618 |
buf[i] = (TUint8)Math::Rand(rndSeed); |
|
619 |
} |
|
620 |
||
621 |
const TUint32 nBytes = (TUint32)Min((TUint64)KBufSize, aSize); |
|
622 |
TPtrC8 ptrData(buf.Ptr(), nBytes); |
|
623 |
User::LeaveIfError(aFile.Write(ptrData)); //-- write data to the file |
|
624 |
md5Hash.Update(ptrData); //-- update MD5 hash |
|
625 |
||
626 |
aSize-=nBytes; |
|
627 |
||
628 |
if((prevSz - aSize) >= K1MegaByte) |
|
629 |
{ |
|
630 |
prevSz = aSize; |
|
631 |
DoPrintf(_L(".")); |
|
632 |
} |
|
633 |
} |
|
634 |
||
635 |
||
636 |
buf.Close(); |
|
637 |
DoPrintf(_L("\n")); |
|
638 |
||
639 |
//-- 4. write MD5 hash to the beginning of the file |
|
640 |
filePos = 0; |
|
641 |
User::LeaveIfError(aFile.Seek(ESeekStart,filePos)); |
|
642 |
User::LeaveIfError(aFile.Write(md5Hash.Final())); |
|
643 |
||
644 |
} |
|
645 |
||
646 |
||
647 |
static void DoVerifyCheckableFileL(RFile64& aFile) |
|
648 |
{ |
|
649 |
TInt64 fileSize; |
|
650 |
User::LeaveIfError(aFile.Size(fileSize)); |
|
651 |
||
652 |
if(fileSize < TMD5::HashSize) |
|
653 |
User::Leave(KErrCorrupt); //-- MD5 hash is 16 bytes, it's the minimal file size |
|
654 |
||
655 |
//-- 1. read MD5 header from the file |
|
656 |
TBuf8<TMD5::HashSize> md5Header(TMD5::HashSize); |
|
657 |
User::LeaveIfError(aFile.Read(md5Header)); |
|
658 |
fileSize -= TMD5::HashSize; |
|
659 |
||
660 |
//-- 2. read the rest of the data and calculate the checksum |
|
661 |
TMD5 md5Hash; |
|
662 |
RBuf8 buf; |
|
663 |
||
664 |
const TInt KBufSize=65536; //-- buffer size for writing data |
|
665 |
buf.CreateMaxL(KBufSize); |
|
666 |
||
667 |
TUint64 prevSz = fileSize; |
|
668 |
while(fileSize) |
|
669 |
{ |
|
670 |
User::LeaveIfError(aFile.Read(buf)); //-- read data from the file |
|
671 |
if (buf.Length() == 0) |
|
672 |
User::Leave(KErrEof); |
|
673 |
md5Hash.Update(buf); //-- update MD5 hash |
|
674 |
||
675 |
fileSize-=buf.Length(); |
|
676 |
||
677 |
if((prevSz - fileSize) >= K1MegaByte) |
|
678 |
{ |
|
679 |
prevSz = fileSize; |
|
680 |
DoPrintf(_L(".")); |
|
681 |
} |
|
682 |
} |
|
683 |
||
684 |
buf.Close(); |
|
685 |
DoPrintf(_L("\n")); |
|
686 |
||
687 |
if(md5Hash.Final() != md5Header) |
|
688 |
User::Leave(KErrCorrupt); //-- the file is corrupt |
|
689 |
} |
|
690 |
||
691 |
//------------------------------------------------------------------------------------------------------------------- |
|
692 |
||
693 |
/** |
|
694 |
Creates a file filled with random data. The file has a 16-byte MD5 header at the start, so it is possible to |
|
695 |
verify the data validity later. Thus the minimal file size is 16 bytes. The file with the iven name may already |
|
696 |
exist; in this case it will be replaced. |
|
697 |
||
698 |
@param aFs reference to the FS session |
|
699 |
@param aFileName name of the file to be created / replaced |
|
700 |
@param aSize size of the file; 16 bytes min. |
|
701 |
||
702 |
@return Standard error code |
|
703 |
*/ |
|
704 |
TInt F32_Test_Utils::CreateCheckableStuffedFile(RFs& aFs, const TDesC& aFileName, TUint64 aSize) |
|
705 |
{ |
|
706 |
||
707 |
DoPrintf(_L("~ F32_Test_Utils::CreateCheckableStuffedFile() file:%S, Size:%LU\n"), &aFileName, aSize); |
|
708 |
||
709 |
if(aSize < TMD5::HashSize) |
|
710 |
return KErrArgument; //-- MD5 hash is 16 bytes, it's the minimal file size |
|
711 |
||
712 |
RFile64 file; |
|
713 |
||
714 |
//-- 1. create a file |
|
715 |
TInt nRes = file.Replace(aFs, aFileName, EFileWrite); |
|
716 |
if(nRes != KErrNone) |
|
717 |
return nRes; |
|
718 |
||
719 |
TRAP(nRes, DoCreateCheckableFileL(file, aSize)); |
|
720 |
||
721 |
file.Close(); |
|
722 |
return nRes; |
|
723 |
} |
|
724 |
||
725 |
||
726 |
/** |
|
727 |
Verify previously created file that has MD5 header at the beginning. See CreateCheckableStuffedFile(...) |
|
728 |
||
729 |
@param aFs reference to the FS session |
|
730 |
@param aFileName name of the file to be verified |
|
731 |
||
732 |
@return Standard error code. KErrNone if the file contents matches the MD5 header. |
|
733 |
*/ |
|
734 |
TInt F32_Test_Utils::VerifyCheckableFile(RFs& aFs, const TDesC& aFileName) |
|
735 |
{ |
|
736 |
DoPrintf(_L("~ F32_Test_Utils::VerifyCheckableFile() file:%S\n"), &aFileName); |
|
737 |
||
738 |
RFile64 file; |
|
739 |
||
740 |
//-- 1. create a file |
|
741 |
TInt nRes = file.Open(aFs, aFileName, EFileRead); |
|
742 |
if(nRes != KErrNone) |
|
743 |
return nRes; |
|
744 |
||
745 |
TRAP(nRes, DoVerifyCheckableFileL(file)); |
|
746 |
||
747 |
file.Close(); |
|
748 |
return nRes; |
|
749 |
||
750 |
} |
|
751 |
||
752 |
||
753 |
/** |
|
754 |
Create an empty file (not filled with anything). The size of the file is set by using RFile::SetSize(). |
|
755 |
For FAT this will result in allocating a cluster chain in FAT fable, for the file systems that support sparse files (like LFFS) |
|
756 |
this might not work as expected. |
|
757 |
||
758 |
@param aFs reference to the FS session |
|
759 |
@param aFileName name of the file to be created / replaced |
|
760 |
@param aSize size of the file |
|
761 |
||
762 |
@return Standard error code |
|
763 |
*/ |
|
764 |
TInt F32_Test_Utils::CreateEmptyFile(RFs& aFs, const TDesC& aFileName, TUint64 aSize) |
|
765 |
{ |
|
766 |
DoPrintf(_L("~ F32_Test_Utils::CreateEmptyFile() file:%S, sz:%LU\n"), &aFileName, aSize); |
|
767 |
||
768 |
RFile64 file; |
|
769 |
||
770 |
//-- 1. create a file |
|
771 |
TInt nRes = file.Replace(aFs, aFileName, EFileWrite); |
|
772 |
if(nRes != KErrNone) |
|
773 |
return nRes; |
|
774 |
||
775 |
//-- 2. set file size |
|
776 |
nRes = file.SetSize(aSize); |
|
777 |
||
778 |
file.Close(); |
|
779 |
||
780 |
return nRes; |
|
781 |
} |
|
782 |
||
783 |
//------------------------------------------------------------------------------------------------------------------- |
|
784 |
||
785 |
/** |
|
786 |
Dismount and mount the filesystem again, optionally taking time when the mount starts. |
|
787 |
The FS can have extensions added into it; this function will handle only the primary extension (if it is present) and |
|
788 |
will mont the FS with it. Non-primary extensions are not supported yet. |
|
789 |
||
790 |
||
791 |
@param aFs reference to the FS session |
|
792 |
@param aDrive drive number |
|
793 |
@param apTimeMountStart pointer to the TTime object, that can be called TTime::UniversalTime() on mount start (this can be |
|
794 |
used for measuring time taken to mount the FS). |
|
795 |
if NULL, no action will be taken. |
|
796 |
||
797 |
@return error code from the RFs::MountFileSystem() |
|
798 |
||
799 |
*/ |
|
800 |
TInt F32_Test_Utils::RemountFS(RFs& aFs, TInt aDrive, TTime* apTimeMountStart/*=NULL*/) |
|
801 |
{ |
|
802 |
TInt nRes; |
|
803 |
DoPrintf(_L("~ F32_Test_Utils::RemountingFS at drive:%d\n"), aDrive); |
|
804 |
||
805 |
TFSDescriptor fsDescriptor; |
|
806 |
||
807 |
//-- 1. get current FS information |
|
808 |
nRes = GetFileSystemDescriptor(aFs, aDrive, fsDescriptor); |
|
809 |
if(nRes != KErrNone) |
|
810 |
return nRes; |
|
811 |
||
812 |
//-- 2. dismount the file system |
|
813 |
if(fsDescriptor.iPExtName.Length() > 0) |
|
814 |
{ |
|
815 |
DoPrintf(_L("~ Dismounting FS:%S with ext:%S\n"), &fsDescriptor.iFsName, &fsDescriptor.iPExtName); |
|
816 |
} |
|
817 |
else |
|
818 |
{ |
|
819 |
DoPrintf(_L("~ Dismounting FS:%S\n"), &fsDescriptor.iFsName); |
|
820 |
} |
|
821 |
||
822 |
nRes = aFs.DismountFileSystem(fsDescriptor.iFsName, aDrive); |
|
823 |
if(nRes != KErrNone) |
|
824 |
{ |
|
825 |
ASSERT(0); |
|
826 |
return nRes; |
|
827 |
} |
|
828 |
||
829 |
//-- 3. mount it again |
|
830 |
if(apTimeMountStart) |
|
831 |
apTimeMountStart->UniversalTime(); //-- take Mount start time |
|
832 |
||
833 |
||
834 |
nRes = MountFileSystem(aFs, aDrive, fsDescriptor); |
|
835 |
return nRes; |
|
836 |
} |
|
837 |
||
838 |
//------------------------------------------------------------------------------------------------------------------- |
|
839 |
||
840 |
TFSDescriptor::TFSDescriptor() |
|
841 |
{ |
|
842 |
Init(); |
|
843 |
} |
|
844 |
||
845 |
void TFSDescriptor::Init() |
|
846 |
{ |
|
847 |
iFsName.SetLength(0); |
|
848 |
iPExtName.SetLength(0); |
|
849 |
iDriveSynch = EFalse; |
|
850 |
} |
|
851 |
||
852 |
TBool TFSDescriptor::operator==(const TFSDescriptor& aRhs) const |
|
853 |
{ |
|
854 |
ASSERT(this != &aRhs); |
|
855 |
return (iFsName.CompareF(aRhs.iFsName) == 0 && iPExtName.CompareF(aRhs.iPExtName) == 0 && iDriveSynch == aRhs.iDriveSynch); |
|
856 |
} |
|
857 |
||
858 |
||
859 |
//------------------------------------------------------------------------------------------------------------------- |
|
860 |
/** |
|
861 |
Gets the information about file system mounted on a drive. This information can be later used for mounting this FS back if it is going to be dismounted |
|
862 |
||
863 |
@param aFs reference to the FS session |
|
864 |
@param aDrive drive number |
|
865 |
@param aFsDesc file system descriptor |
|
866 |
||
867 |
@return standard error code |
|
868 |
*/ |
|
869 |
TInt F32_Test_Utils::GetFileSystemDescriptor(RFs &aFs, TInt aDrive, TFSDescriptor& aFsDesc) |
|
870 |
{ |
|
871 |
TInt nRes; |
|
872 |
||
873 |
//-- 1. get file system name |
|
874 |
nRes = aFs.FileSystemName(aFsDesc.iFsName, aDrive); |
|
875 |
if(nRes != KErrNone) |
|
876 |
{ |
|
877 |
ASSERT(0); |
|
878 |
return nRes; |
|
879 |
} |
|
880 |
||
881 |
//-- 2. find out if the drive sync/async |
|
882 |
TPckgBuf<TBool> drvSyncBuf; |
|
883 |
nRes = aFs.QueryVolumeInfoExt(aDrive, EIsDriveSync, drvSyncBuf); |
|
884 |
if(nRes != KErrNone) |
|
885 |
{//-- pretend that the drive is asynch. in the case of file system being corrupted. this is 99.9% true |
|
886 |
aFsDesc.iDriveSynch = EFalse; |
|
887 |
} |
|
888 |
else |
|
889 |
{ |
|
890 |
aFsDesc.iDriveSynch = drvSyncBuf(); |
|
891 |
} |
|
892 |
||
893 |
//-- 3. find out primary extension name if it is present; we will need to add it again when mounting the FS |
|
894 |
//-- other extensions (non-primary) are not supported yet |
|
895 |
nRes = aFs.ExtensionName(aFsDesc.iPExtName, aDrive, 0); |
|
896 |
if(nRes != KErrNone) |
|
897 |
{ |
|
898 |
aFsDesc.iPExtName.SetLength(0); |
|
899 |
} |
|
900 |
||
901 |
//-- 3.1 check if the drive has non-primary extensions, fail in this case |
|
902 |
TBuf<40> extName; |
|
903 |
nRes = aFs.ExtensionName(extName, aDrive, 1); |
|
904 |
if(nRes == KErrNone) |
|
905 |
{ |
|
906 |
DoPrintf(_L("~ F32_Test_Utils::GetFileSystemDescriptor: Non-primary extensions are not supported!\n")); |
|
907 |
return KErrNotSupported; |
|
908 |
} |
|
909 |
||
910 |
||
911 |
return KErrNone; |
|
912 |
} |
|
913 |
||
914 |
//------------------------------------------------------------------------------------------------------------------- |
|
915 |
/** |
|
916 |
Mount the file system by the information provided in the FS descriptor |
|
917 |
||
918 |
@param aFs reference to the FS session |
|
919 |
@param aDrive drive number |
|
920 |
@param aFsDesc file system descriptor containing all necessary information to mount the FS. |
|
921 |
||
922 |
@return standard error code |
|
923 |
*/ |
|
924 |
TInt F32_Test_Utils::MountFileSystem(RFs &aFs, TInt aDrive, const TFSDescriptor& aFsDesc) |
|
925 |
{ |
|
926 |
DoPrintf(_L("~ F32_Test_Utils::MountFileSystem() drive:%d Name:%S\n"), aDrive, &aFsDesc.iFsName); |
|
927 |
||
928 |
TInt nRes; |
|
929 |
if(aFsDesc.iFsName.Length() <=0 ) |
|
930 |
{ |
|
931 |
ASSERT(0); |
|
932 |
return KErrArgument; |
|
933 |
} |
|
934 |
||
935 |
||
936 |
//-- mount File system |
|
937 |
const TBool bPrimaryExt = (aFsDesc.iPExtName.Length() > 0); |
|
938 |
||
939 |
if(bPrimaryExt) |
|
940 |
{//-- we need to mount FS with the primary extension |
|
941 |
nRes = aFs.AddExtension(aFsDesc.iPExtName); |
|
942 |
if(nRes != KErrNone && nRes != KErrAlreadyExists) |
|
943 |
{ |
|
944 |
ASSERT(0); |
|
945 |
return nRes; |
|
946 |
} |
|
947 |
||
948 |
nRes = aFs.MountFileSystem(aFsDesc.iFsName, aFsDesc.iPExtName, aDrive, aFsDesc.iDriveSynch); |
|
949 |
} |
|
950 |
else |
|
951 |
{//-- the FS did not have primary extension |
|
952 |
nRes = aFs.MountFileSystem(aFsDesc.iFsName, aDrive, aFsDesc.iDriveSynch); |
|
953 |
} |
|
954 |
||
955 |
||
956 |
return nRes; |
|
957 |
} |
|
958 |
||
959 |
//------------------------------------------------------------------------------------------------------------------- |
|
960 |
/** |
|
961 |
Format volume, regardless the file system installed. |
|
962 |
||
963 |
@param aFs reference to the FS session |
|
964 |
@param aDrive drive number |
|
965 |
@param aQuickFormat if True, a quick format will be performed. otherwise - full |
|
966 |
@return system-wide error codes. |
|
967 |
*/ |
|
968 |
TInt F32_Test_Utils::FormatDrive(RFs &aFs, TInt aDrive, TBool aQuickFormat) |
|
969 |
{ |
|
970 |
TPtrC fmtTypeName = (aQuickFormat ? _L("Quick") : _L("Full")); |
|
971 |
DoPrintf(_L("~ F32_Test_Utils::FormatDrive() drv:%d, type:%S\n"),aDrive, &fmtTypeName); |
|
972 |
||
973 |
ASSERT(aDrive >= EDriveA && aDrive <= EDriveZ); |
|
974 |
||
975 |
RFormat format; |
|
976 |
TUint fmtMode=0; |
|
977 |
TInt fmtCnt=0; |
|
978 |
TInt prevCnt; |
|
979 |
TInt nRes; |
|
980 |
||
981 |
if(aQuickFormat) |
|
982 |
fmtMode |= EQuickFormat; |
|
983 |
||
984 |
//if(aForceErase) |
|
985 |
// fmtMode |= EForceErase; |
|
986 |
||
987 |
TBuf<10> drvName; |
|
988 |
drvName.Format(_L("%C:"),'A'+aDrive); |
|
989 |
||
990 |
nRes = format.Open(aFs, drvName, fmtMode, fmtCnt); |
|
991 |
if(nRes!=KErrNone) |
|
992 |
goto Fail; |
|
993 |
||
994 |
//-- do format steps |
|
995 |
prevCnt=fmtCnt; |
|
996 |
while(fmtCnt) |
|
997 |
{ |
|
998 |
nRes = format.Next(fmtCnt); |
|
999 |
if(nRes!=KErrNone) |
|
1000 |
goto Fail; |
|
1001 |
||
1002 |
if(fmtCnt != prevCnt) |
|
1003 |
{ |
|
1004 |
DoPrintf(_L(".")); |
|
1005 |
prevCnt = fmtCnt; |
|
1006 |
} |
|
1007 |
} |
|
1008 |
||
1009 |
//-- formatting has finished |
|
1010 |
DoPrintf(_L("\n")); |
|
1011 |
format.Close(); |
|
1012 |
return KErrNone; |
|
1013 |
||
1014 |
Fail: |
|
1015 |
format.Close(); |
|
1016 |
DoPrintf(_L("~ F32_Test_Utils::FormatFatDrive() failed! code:%d\n"), nRes); |
|
1017 |
||
1018 |
return nRes; |
|
1019 |
} |
|
1020 |
||
1021 |
||
1022 |
#endif //FAT_UTILS_LEAN_AND_MEAN |
|
1023 |
||
1024 |
||
1025 |
//------------------------------------------------------------------------------------------------------------------- |
|
1026 |
/** |
|
1027 |
printing interface. Prints out to the console (if is set) and to the debug interface |
|
1028 |
if pConsole is NULL will print to the debug port only. |
|
1029 |
*/ |
|
1030 |
void F32_Test_Utils::DoPrintf(TRefByValue<const TDesC> aFmt,...) |
|
1031 |
{ |
|
1032 |
#ifndef FAT_UTILS_LEAN_AND_MEAN |
|
1033 |
if(!bPrintOutEnabled) |
|
1034 |
return; //-- disabled by global flag |
|
1035 |
#endif //FAT_UTILS_LEAN_AND_MEAN |
|
1036 |
||
1037 |
VA_LIST list; |
|
1038 |
VA_START(list, aFmt); |
|
1039 |
||
1040 |
TBuf<0x100> buf; |
|
1041 |
buf.FormatList(aFmt, list); //-- ignore overflows |
|
1042 |
||
1043 |
#ifndef FAT_UTILS_LEAN_AND_MEAN |
|
1044 |
if(pConsole) |
|
1045 |
{ |
|
1046 |
pConsole->Write(buf); |
|
1047 |
} |
|
1048 |
#endif //FAT_UTILS_LEAN_AND_MEAN |
|
1049 |
||
1050 |
const TInt bufLen = buf.Length(); |
|
1051 |
if(bufLen >0 && buf[bufLen-1] == '\n') |
|
1052 |
{ |
|
1053 |
buf.Insert(bufLen-1, _L("\r")); |
|
1054 |
} |
|
1055 |
||
1056 |
RDebug::RawPrint(buf); |
|
1057 |
} |
|
1058 |
||
1059 |
//------------------------------------------------------------------------------------------------------------------- |
|
1060 |
||
1061 |
TBool F32_Test_Utils::IsPowerOf2(TUint32 aVal) |
|
1062 |
{ |
|
1063 |
if (aVal==0) |
|
1064 |
return EFalse; |
|
1065 |
||
1066 |
return !(aVal & (aVal-1)); |
|
1067 |
} |
|
1068 |
||
1069 |
||
1070 |
//------------------------------------------------------------------------------------------------------------------- |
|
1071 |
TUint32 F32_Test_Utils::Log2(TUint32 aVal) |
|
1072 |
{ |
|
1073 |
__ASSERT_COMPILE(sizeof(TUint32) == 4); |
|
1074 |
ASSERT(aVal); |
|
1075 |
||
1076 |
TUint32 bitPos=31; |
|
1077 |
||
1078 |
if(!(aVal >> 16)) {bitPos-=16; aVal<<=16;} |
|
1079 |
if(!(aVal >> 24)) {bitPos-=8; aVal<<=8 ;} |
|
1080 |
if(!(aVal >> 28)) {bitPos-=4; aVal<<=4 ;} |
|
1081 |
if(!(aVal >> 30)) {bitPos-=2; aVal<<=2 ;} |
|
1082 |
if(!(aVal >> 31)) {bitPos-=1;} |
|
1083 |
||
1084 |
return bitPos; |
|
1085 |
} |
|
1086 |
||
1087 |
||
1088 |
//------------------------------------------------------------------------------------------------------------------- |
|
1089 |
||
1090 |
//################################################################################################################### |
|
1091 |
//# TMD5 class implementation |
|
1092 |
//################################################################################################################### |
|
1093 |
||
1094 |
||
1095 |
#define T_MASK ((TUint32)~0) |
|
1096 |
#define T1 /* 0xd76aa478 */ (T_MASK ^ 0x28955b87) |
|
1097 |
#define T2 /* 0xe8c7b756 */ (T_MASK ^ 0x173848a9) |
|
1098 |
#define T3 0x242070db |
|
1099 |
#define T4 /* 0xc1bdceee */ (T_MASK ^ 0x3e423111) |
|
1100 |
#define T5 /* 0xf57c0faf */ (T_MASK ^ 0x0a83f050) |
|
1101 |
#define T6 0x4787c62a |
|
1102 |
#define T7 /* 0xa8304613 */ (T_MASK ^ 0x57cfb9ec) |
|
1103 |
#define T8 /* 0xfd469501 */ (T_MASK ^ 0x02b96afe) |
|
1104 |
#define T9 0x698098d8 |
|
1105 |
#define T10 /* 0x8b44f7af */ (T_MASK ^ 0x74bb0850) |
|
1106 |
#define T11 /* 0xffff5bb1 */ (T_MASK ^ 0x0000a44e) |
|
1107 |
#define T12 /* 0x895cd7be */ (T_MASK ^ 0x76a32841) |
|
1108 |
#define T13 0x6b901122 |
|
1109 |
#define T14 /* 0xfd987193 */ (T_MASK ^ 0x02678e6c) |
|
1110 |
#define T15 /* 0xa679438e */ (T_MASK ^ 0x5986bc71) |
|
1111 |
#define T16 0x49b40821 |
|
1112 |
#define T17 /* 0xf61e2562 */ (T_MASK ^ 0x09e1da9d) |
|
1113 |
#define T18 /* 0xc040b340 */ (T_MASK ^ 0x3fbf4cbf) |
|
1114 |
#define T19 0x265e5a51 |
|
1115 |
#define T20 /* 0xe9b6c7aa */ (T_MASK ^ 0x16493855) |
|
1116 |
#define T21 /* 0xd62f105d */ (T_MASK ^ 0x29d0efa2) |
|
1117 |
#define T22 0x02441453 |
|
1118 |
#define T23 /* 0xd8a1e681 */ (T_MASK ^ 0x275e197e) |
|
1119 |
#define T24 /* 0xe7d3fbc8 */ (T_MASK ^ 0x182c0437) |
|
1120 |
#define T25 0x21e1cde6 |
|
1121 |
#define T26 /* 0xc33707d6 */ (T_MASK ^ 0x3cc8f829) |
|
1122 |
#define T27 /* 0xf4d50d87 */ (T_MASK ^ 0x0b2af278) |
|
1123 |
#define T28 0x455a14ed |
|
1124 |
#define T29 /* 0xa9e3e905 */ (T_MASK ^ 0x561c16fa) |
|
1125 |
#define T30 /* 0xfcefa3f8 */ (T_MASK ^ 0x03105c07) |
|
1126 |
#define T31 0x676f02d9 |
|
1127 |
#define T32 /* 0x8d2a4c8a */ (T_MASK ^ 0x72d5b375) |
|
1128 |
#define T33 /* 0xfffa3942 */ (T_MASK ^ 0x0005c6bd) |
|
1129 |
#define T34 /* 0x8771f681 */ (T_MASK ^ 0x788e097e) |
|
1130 |
#define T35 0x6d9d6122 |
|
1131 |
#define T36 /* 0xfde5380c */ (T_MASK ^ 0x021ac7f3) |
|
1132 |
#define T37 /* 0xa4beea44 */ (T_MASK ^ 0x5b4115bb) |
|
1133 |
#define T38 0x4bdecfa9 |
|
1134 |
#define T39 /* 0xf6bb4b60 */ (T_MASK ^ 0x0944b49f) |
|
1135 |
#define T40 /* 0xbebfbc70 */ (T_MASK ^ 0x4140438f) |
|
1136 |
#define T41 0x289b7ec6 |
|
1137 |
#define T42 /* 0xeaa127fa */ (T_MASK ^ 0x155ed805) |
|
1138 |
#define T43 /* 0xd4ef3085 */ (T_MASK ^ 0x2b10cf7a) |
|
1139 |
#define T44 0x04881d05 |
|
1140 |
#define T45 /* 0xd9d4d039 */ (T_MASK ^ 0x262b2fc6) |
|
1141 |
#define T46 /* 0xe6db99e5 */ (T_MASK ^ 0x1924661a) |
|
1142 |
#define T47 0x1fa27cf8 |
|
1143 |
#define T48 /* 0xc4ac5665 */ (T_MASK ^ 0x3b53a99a) |
|
1144 |
#define T49 /* 0xf4292244 */ (T_MASK ^ 0x0bd6ddbb) |
|
1145 |
#define T50 0x432aff97 |
|
1146 |
#define T51 /* 0xab9423a7 */ (T_MASK ^ 0x546bdc58) |
|
1147 |
#define T52 /* 0xfc93a039 */ (T_MASK ^ 0x036c5fc6) |
|
1148 |
#define T53 0x655b59c3 |
|
1149 |
#define T54 /* 0x8f0ccc92 */ (T_MASK ^ 0x70f3336d) |
|
1150 |
#define T55 /* 0xffeff47d */ (T_MASK ^ 0x00100b82) |
|
1151 |
#define T56 /* 0x85845dd1 */ (T_MASK ^ 0x7a7ba22e) |
|
1152 |
#define T57 0x6fa87e4f |
|
1153 |
#define T58 /* 0xfe2ce6e0 */ (T_MASK ^ 0x01d3191f) |
|
1154 |
#define T59 /* 0xa3014314 */ (T_MASK ^ 0x5cfebceb) |
|
1155 |
#define T60 0x4e0811a1 |
|
1156 |
#define T61 /* 0xf7537e82 */ (T_MASK ^ 0x08ac817d) |
|
1157 |
#define T62 /* 0xbd3af235 */ (T_MASK ^ 0x42c50dca) |
|
1158 |
#define T63 0x2ad7d2bb |
|
1159 |
#define T64 /* 0xeb86d391 */ (T_MASK ^ 0x14792c6e) |
|
1160 |
||
1161 |
||
1162 |
TMD5::TMD5() |
|
1163 |
{ |
|
1164 |
Reset(); |
|
1165 |
} |
|
1166 |
||
1167 |
//------------------------------------------------------------------------------------------------------------------- |
|
1168 |
||
1169 |
void TMD5::Md5_process(const TUint8 *data /*[64]*/) |
|
1170 |
{ |
|
1171 |
TUint32 |
|
1172 |
a = iState.abcd[0], b = iState.abcd[1], |
|
1173 |
c = iState.abcd[2], d = iState.abcd[3]; |
|
1174 |
TUint32 t; |
|
1175 |
TUint32 xbuf[16]; |
|
1176 |
const TUint32 *X; |
|
1177 |
||
1178 |
{ |
|
1179 |
static const TInt w = 1; |
|
1180 |
if (*((const TUint8 *)&w)) |
|
1181 |
{ |
|
1182 |
if (!((data - (const TUint8 *)0) & 3)) { |
|
1183 |
X = (const TUint32 *)data; |
|
1184 |
} else { |
|
1185 |
memcpy(xbuf, data, 64); |
|
1186 |
X = xbuf; |
|
1187 |
} |
|
1188 |
} |
|
1189 |
else |
|
1190 |
{ |
|
1191 |
const TUint8 *xp = data; |
|
1192 |
TInt i; |
|
1193 |
||
1194 |
X = xbuf; /* (dynamic only) */ |
|
1195 |
for (i = 0; i < 16; ++i, xp += 4) |
|
1196 |
xbuf[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24); |
|
1197 |
} |
|
1198 |
} |
|
1199 |
||
1200 |
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) |
|
1201 |
||
1202 |
#define F(x, y, z) (((x) & (y)) | (~(x) & (z))) |
|
1203 |
#define SET(a, b, c, d, k, s, Ti)\ |
|
1204 |
t = a + F(b,c,d) + X[k] + Ti;\ |
|
1205 |
a = ROTATE_LEFT(t, s) + b |
|
1206 |
SET(a, b, c, d, 0, 7, T1); |
|
1207 |
SET(d, a, b, c, 1, 12, T2); |
|
1208 |
SET(c, d, a, b, 2, 17, T3); |
|
1209 |
SET(b, c, d, a, 3, 22, T4); |
|
1210 |
SET(a, b, c, d, 4, 7, T5); |
|
1211 |
SET(d, a, b, c, 5, 12, T6); |
|
1212 |
SET(c, d, a, b, 6, 17, T7); |
|
1213 |
SET(b, c, d, a, 7, 22, T8); |
|
1214 |
SET(a, b, c, d, 8, 7, T9); |
|
1215 |
SET(d, a, b, c, 9, 12, T10); |
|
1216 |
SET(c, d, a, b, 10, 17, T11); |
|
1217 |
SET(b, c, d, a, 11, 22, T12); |
|
1218 |
SET(a, b, c, d, 12, 7, T13); |
|
1219 |
SET(d, a, b, c, 13, 12, T14); |
|
1220 |
SET(c, d, a, b, 14, 17, T15); |
|
1221 |
SET(b, c, d, a, 15, 22, T16); |
|
1222 |
#undef SET |
|
1223 |
||
1224 |
#define G(x, y, z) (((x) & (z)) | ((y) & ~(z))) |
|
1225 |
#define SET(a, b, c, d, k, s, Ti)\ |
|
1226 |
t = a + G(b,c,d) + X[k] + Ti;\ |
|
1227 |
a = ROTATE_LEFT(t, s) + b |
|
1228 |
SET(a, b, c, d, 1, 5, T17); |
|
1229 |
SET(d, a, b, c, 6, 9, T18); |
|
1230 |
SET(c, d, a, b, 11, 14, T19); |
|
1231 |
SET(b, c, d, a, 0, 20, T20); |
|
1232 |
SET(a, b, c, d, 5, 5, T21); |
|
1233 |
SET(d, a, b, c, 10, 9, T22); |
|
1234 |
SET(c, d, a, b, 15, 14, T23); |
|
1235 |
SET(b, c, d, a, 4, 20, T24); |
|
1236 |
SET(a, b, c, d, 9, 5, T25); |
|
1237 |
SET(d, a, b, c, 14, 9, T26); |
|
1238 |
SET(c, d, a, b, 3, 14, T27); |
|
1239 |
SET(b, c, d, a, 8, 20, T28); |
|
1240 |
SET(a, b, c, d, 13, 5, T29); |
|
1241 |
SET(d, a, b, c, 2, 9, T30); |
|
1242 |
SET(c, d, a, b, 7, 14, T31); |
|
1243 |
SET(b, c, d, a, 12, 20, T32); |
|
1244 |
#undef SET |
|
1245 |
||
1246 |
#define H(x, y, z) ((x) ^ (y) ^ (z)) |
|
1247 |
#define SET(a, b, c, d, k, s, Ti)\ |
|
1248 |
t = a + H(b,c,d) + X[k] + Ti;\ |
|
1249 |
a = ROTATE_LEFT(t, s) + b |
|
1250 |
SET(a, b, c, d, 5, 4, T33); |
|
1251 |
SET(d, a, b, c, 8, 11, T34); |
|
1252 |
SET(c, d, a, b, 11, 16, T35); |
|
1253 |
SET(b, c, d, a, 14, 23, T36); |
|
1254 |
SET(a, b, c, d, 1, 4, T37); |
|
1255 |
SET(d, a, b, c, 4, 11, T38); |
|
1256 |
SET(c, d, a, b, 7, 16, T39); |
|
1257 |
SET(b, c, d, a, 10, 23, T40); |
|
1258 |
SET(a, b, c, d, 13, 4, T41); |
|
1259 |
SET(d, a, b, c, 0, 11, T42); |
|
1260 |
SET(c, d, a, b, 3, 16, T43); |
|
1261 |
SET(b, c, d, a, 6, 23, T44); |
|
1262 |
SET(a, b, c, d, 9, 4, T45); |
|
1263 |
SET(d, a, b, c, 12, 11, T46); |
|
1264 |
SET(c, d, a, b, 15, 16, T47); |
|
1265 |
SET(b, c, d, a, 2, 23, T48); |
|
1266 |
#undef SET |
|
1267 |
||
1268 |
#define I(x, y, z) ((y) ^ ((x) | ~(z))) |
|
1269 |
#define SET(a, b, c, d, k, s, Ti)\ |
|
1270 |
t = a + I(b,c,d) + X[k] + Ti;\ |
|
1271 |
a = ROTATE_LEFT(t, s) + b |
|
1272 |
SET(a, b, c, d, 0, 6, T49); |
|
1273 |
SET(d, a, b, c, 7, 10, T50); |
|
1274 |
SET(c, d, a, b, 14, 15, T51); |
|
1275 |
SET(b, c, d, a, 5, 21, T52); |
|
1276 |
SET(a, b, c, d, 12, 6, T53); |
|
1277 |
SET(d, a, b, c, 3, 10, T54); |
|
1278 |
SET(c, d, a, b, 10, 15, T55); |
|
1279 |
SET(b, c, d, a, 1, 21, T56); |
|
1280 |
SET(a, b, c, d, 8, 6, T57); |
|
1281 |
SET(d, a, b, c, 15, 10, T58); |
|
1282 |
SET(c, d, a, b, 6, 15, T59); |
|
1283 |
SET(b, c, d, a, 13, 21, T60); |
|
1284 |
SET(a, b, c, d, 4, 6, T61); |
|
1285 |
SET(d, a, b, c, 11, 10, T62); |
|
1286 |
SET(c, d, a, b, 2, 15, T63); |
|
1287 |
SET(b, c, d, a, 9, 21, T64); |
|
1288 |
#undef SET |
|
1289 |
||
1290 |
iState.abcd[0] += a; |
|
1291 |
iState.abcd[1] += b; |
|
1292 |
iState.abcd[2] += c; |
|
1293 |
iState.abcd[3] += d; |
|
1294 |
||
1295 |
} |
|
1296 |
||
1297 |
//------------------------------------------------------------------------------------------------------------------- |
|
1298 |
void TMD5::Md5_append(const TUint8 *data, TInt nbytes) |
|
1299 |
{ |
|
1300 |
const TUint8 *p = data; |
|
1301 |
||
1302 |
TInt left = nbytes; |
|
1303 |
||
1304 |
TInt offset = (iState.count[0] >> 3) & 63; |
|
1305 |
TUint32 nbits = (TUint32)(nbytes << 3); |
|
1306 |
||
1307 |
if (nbytes <= 0) |
|
1308 |
return; |
|
1309 |
||
1310 |
iState.count[1] += nbytes >> 29; |
|
1311 |
iState.count[0] += nbits; |
|
1312 |
if (iState.count[0] < nbits) |
|
1313 |
iState.count[1]++; |
|
1314 |
||
1315 |
if (offset) |
|
1316 |
{ |
|
1317 |
TInt copy = (offset + nbytes > 64 ? 64 - offset : nbytes); |
|
1318 |
||
1319 |
memcpy(iState.buf + offset, p, copy); |
|
1320 |
if (offset + copy < 64) |
|
1321 |
return; |
|
1322 |
p += copy; |
|
1323 |
left -= copy; |
|
1324 |
Md5_process(iState.buf); |
|
1325 |
} |
|
1326 |
||
1327 |
for (; left >= 64; p += 64, left -= 64) |
|
1328 |
Md5_process(p); |
|
1329 |
||
1330 |
if (left) |
|
1331 |
memcpy(iState.buf, p, left); |
|
1332 |
||
1333 |
} |
|
1334 |
||
1335 |
||
1336 |
void TMD5::Md5_finish() |
|
1337 |
{ |
|
1338 |
static const TUint8 pad[64] = { |
|
1339 |
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|
1340 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|
1341 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|
1342 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
|
1343 |
}; |
|
1344 |
TUint8 data[8]; |
|
1345 |
TInt i; |
|
1346 |
||
1347 |
for (i = 0; i < 8; ++i) |
|
1348 |
data[i] = (TUint8)(iState.count[i >> 2] >> ((i & 3) << 3)); |
|
1349 |
Md5_append(pad, ((55 - (iState.count[0] >> 3)) & 63) + 1); |
|
1350 |
Md5_append(data, 8); |
|
1351 |
for (i = 0; i < 16; ++i) |
|
1352 |
iDigest[i] = (TUint8)(iState.abcd[i >> 2] >> ((i & 3) << 3)); |
|
1353 |
||
1354 |
} |
|
1355 |
||
1356 |
//------------------------------------------------------------------------------------------------------------------- |
|
1357 |
||
1358 |
/** reset MD5 to initial state */ |
|
1359 |
void TMD5::Reset() |
|
1360 |
{ |
|
1361 |
iState.count[0] = iState.count[1] = 0; |
|
1362 |
iState.abcd[0] = 0x67452301; |
|
1363 |
iState.abcd[1] = /*0xefcdab89*/ T_MASK ^ 0x10325476; |
|
1364 |
iState.abcd[2] = /*0x98badcfe*/ T_MASK ^ 0x67452301; |
|
1365 |
iState.abcd[3] = 0x10325476; |
|
1366 |
} |
|
1367 |
||
1368 |
||
1369 |
/** |
|
1370 |
Update MD5 with some data |
|
1371 |
@param aMessage descriptor with data |
|
1372 |
*/ |
|
1373 |
void TMD5::Update(const TDesC8& aMessage) |
|
1374 |
{ |
|
1375 |
Md5_append((const TUint8*)aMessage.Ptr(), aMessage.Length()); |
|
1376 |
} |
|
1377 |
||
1378 |
/** |
|
1379 |
Finalise MD5 calculation |
|
1380 |
@param aMessage descriptor with data |
|
1381 |
@return pointer to 16-byte array with MD5 hash |
|
1382 |
*/ |
|
1383 |
TPtrC8 TMD5::Final(const TDesC8& aMessage) |
|
1384 |
{ |
|
1385 |
Update(aMessage); |
|
1386 |
Md5_finish(); |
|
1387 |
return TPtrC8(iDigest, HashSize); |
|
1388 |
} |
|
1389 |
||
1390 |
||
1391 |
/** |
|
1392 |
Finalise MD5 calculation |
|
1393 |
@return pointer to 16-byte array with MD5 hash |
|
1394 |
*/ |
|
1395 |
TPtrC8 TMD5::Final() |
|
1396 |
{ |
|
1397 |
Md5_finish(); |
|
1398 |
return TPtrC8(iDigest, HashSize); |
|
1399 |
} |
|
1400 |
||
1401 |
||
1402 |
||
1403 |
||
1404 |
||
1405 |
||
1406 |
||
1407 |
||
1408 |
||
1409 |
||
1410 |
||
1411 |
||
1412 |
||
1413 |
||
1414 |
||
1415 |
||
1416 |
||
1417 |
||
1418 |
||
1419 |
||
1420 |
||
1421 |