0
|
1 |
/*
|
|
2 |
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
#include "t_fat32readraw.h"
|
|
21 |
|
|
22 |
static RRawDisk TheDisk;
|
|
23 |
|
|
24 |
/**
|
|
25 |
Class Constructor
|
|
26 |
*/
|
|
27 |
CBaseTestFat32ReadRaw::CBaseTestFat32ReadRaw()
|
|
28 |
{
|
|
29 |
SetTestStepName(KTestStepReadRaw);
|
|
30 |
}
|
|
31 |
|
|
32 |
/**
|
|
33 |
Class Destructor
|
|
34 |
*/
|
|
35 |
CBaseTestFat32ReadRaw::~CBaseTestFat32ReadRaw()
|
|
36 |
{
|
|
37 |
}
|
|
38 |
|
|
39 |
|
|
40 |
/**
|
|
41 |
This function performs the following actions:
|
|
42 |
1. Gets the position to read on the raw disk from the ini file
|
|
43 |
-> if a cluster is specified then get the position from GetCluster().
|
|
44 |
2. Get the number of bytes to read starting from the obtained position
|
|
45 |
3. Read the disk byte by byte and place into an array.
|
|
46 |
-> If a mask is specified then compare the mask with the read value.
|
|
47 |
-> If the correct results are specified in the ini file then compare
|
|
48 |
the array contain the read values with the array containing the
|
|
49 |
correct results.
|
|
50 |
|
|
51 |
@return EPass if test passes and EFail if test fails
|
|
52 |
*/
|
|
53 |
TVerdict CBaseTestFat32ReadRaw::doTestStepL()
|
|
54 |
{
|
|
55 |
SetTestStepResult(EFail);
|
|
56 |
|
|
57 |
TInt ascivalue[20];
|
|
58 |
TInt correctresults[20];
|
|
59 |
TInt r;
|
|
60 |
|
|
61 |
_LIT(KPosition,"ReadPosition");
|
|
62 |
TInt position;
|
|
63 |
TBool alright = GetHexFromConfig(ConfigSection(), KPosition, position);
|
|
64 |
if(alright)
|
|
65 |
{
|
|
66 |
if (iMedia == 1 && position >= 16384)
|
|
67 |
{
|
|
68 |
INFO_PRINTF2(_L("Position = %d"), position);
|
|
69 |
INFO_PRINTF2(_L("iBPB_ResvdSecCnt = %d"), iBPB_ResvdSecCnt);
|
|
70 |
position = (iBPB_ResvdSecCnt * 512) + (position - 0x4000);
|
|
71 |
INFO_PRINTF2(_L("New Position = %d"), position);
|
|
72 |
}
|
|
73 |
_LIT(KCluster,"ClusterNumber");
|
|
74 |
TInt64 clusterPosition;
|
|
75 |
TInt cluster;
|
|
76 |
TBool alright2 = GetIntFromConfig(ConfigSection(), KCluster, cluster);
|
|
77 |
if (alright2)
|
|
78 |
{
|
|
79 |
r = GetCluster(cluster, clusterPosition);
|
|
80 |
if (r != KErrNone)
|
|
81 |
{
|
|
82 |
SetTestStepResult(EFail);
|
|
83 |
INFO_PRINTF1(_L("Could not get disk position"));
|
|
84 |
return TestStepResult();
|
|
85 |
}
|
|
86 |
else
|
|
87 |
{
|
|
88 |
position = clusterPosition;
|
|
89 |
}
|
|
90 |
}
|
|
91 |
|
|
92 |
_LIT(KFATEntryReadPosition,"FATEntryReadPosition");
|
|
93 |
_LIT(KFATEntry0,"FATEntry0");
|
|
94 |
_LIT(KFATEntry1,"FATEntry1");
|
|
95 |
_LIT(KFATEntry3,"FATEntry3");
|
|
96 |
_LIT(KFATEntry4,"FATEntry4");
|
|
97 |
TPtrC fat_entry_str;
|
|
98 |
if(GetStringFromConfig(ConfigSection(), KFATEntryReadPosition, fat_entry_str))
|
|
99 |
{
|
|
100 |
if(!fat_entry_str.Compare(KFATEntry0))
|
|
101 |
{
|
|
102 |
position = iBPB_ResvdSecCnt * iBPB_BytsPerSec;
|
|
103 |
}
|
|
104 |
else if(!fat_entry_str.Compare(KFATEntry1))
|
|
105 |
{
|
|
106 |
position = iBPB_ResvdSecCnt * iBPB_BytsPerSec + 4;
|
|
107 |
}
|
|
108 |
else if(!fat_entry_str.Compare(KFATEntry3))
|
|
109 |
{
|
|
110 |
position = iBPB_ResvdSecCnt * iBPB_BytsPerSec + 4*3;
|
|
111 |
}
|
|
112 |
else if(!fat_entry_str.Compare(KFATEntry4))
|
|
113 |
{
|
|
114 |
position = iBPB_ResvdSecCnt * iBPB_BytsPerSec + 4*4;
|
|
115 |
}
|
|
116 |
}
|
|
117 |
_LIT(KReadPosition, "The position on the disk being read is %d");
|
|
118 |
INFO_PRINTF2(KReadPosition,position);
|
|
119 |
|
|
120 |
_LIT(KNumOfBytes,"NumberOfBytes");
|
|
121 |
TInt numbyte;
|
|
122 |
TBool alright3 = GetHexFromConfig(ConfigSection(), KNumOfBytes, numbyte);
|
|
123 |
if (alright3)
|
|
124 |
{
|
|
125 |
r = ReadRaw(position, numbyte, ascivalue);
|
|
126 |
if(r != KErrNone)
|
|
127 |
{
|
|
128 |
_LIT(KErrorRead, "Cannot read the raw disk at position %d and length %d - error = %d");
|
|
129 |
INFO_PRINTF4(KErrorRead,position, numbyte, r);
|
|
130 |
SetTestStepResult(EFail);
|
|
131 |
return TestStepResult();
|
|
132 |
}
|
|
133 |
_LIT(KMask,"Mask");
|
|
134 |
TInt mask;
|
|
135 |
TBool alright4 = GetHexFromConfig(ConfigSection(), KMask, mask);
|
|
136 |
if (alright4)
|
|
137 |
{
|
|
138 |
r = CheckMask(mask,numbyte, ascivalue, position);
|
|
139 |
if (r == KErrNone)
|
|
140 |
{
|
|
141 |
_LIT(KValueCorrect, "Result Correct");
|
|
142 |
INFO_PRINTF1(KValueCorrect);
|
|
143 |
SetTestStepResult(EPass);
|
|
144 |
_LIT(KReadPass, "Read Passed");
|
|
145 |
INFO_PRINTF1(KReadPass);
|
|
146 |
return TestStepResult();
|
|
147 |
}
|
|
148 |
else
|
|
149 |
{
|
|
150 |
_LIT(KValueWrong, "Result Incorrect, value is %X but should be %X");
|
|
151 |
INFO_PRINTF3(KValueWrong, ascivalue[0], mask);
|
|
152 |
SetTestStepResult(EFail);
|
|
153 |
_LIT(KReadFail, "Read Failed");
|
|
154 |
INFO_PRINTF1(KReadFail);
|
|
155 |
return TestStepResult();
|
|
156 |
}
|
|
157 |
}
|
|
158 |
else
|
|
159 |
{
|
|
160 |
r = GetCorrectResult(numbyte,correctresults);
|
|
161 |
TInt i;
|
|
162 |
for (i = 0; i < numbyte; i++)
|
|
163 |
{
|
|
164 |
if (ascivalue[i] != correctresults[i])
|
|
165 |
{
|
|
166 |
if ((ascivalue[i] == 0xFF) && (correctresults[i] == 0x00))
|
|
167 |
{
|
|
168 |
_LIT(KValueCorrect, "Result Correct");
|
|
169 |
INFO_PRINTF1(KValueCorrect);
|
|
170 |
SetTestStepResult(EPass);
|
|
171 |
_LIT(KReadPass, "Read Passed");
|
|
172 |
INFO_PRINTF1(KReadPass);
|
|
173 |
return TestStepResult();
|
|
174 |
}
|
|
175 |
else
|
|
176 |
{
|
|
177 |
_LIT(KValueWrong, "Result Incorrect, value is %X but should be %X");
|
|
178 |
INFO_PRINTF3(KValueWrong, ascivalue[i], correctresults[i]);
|
|
179 |
SetTestStepResult(EFail);
|
|
180 |
_LIT(KReadFail, "Read Failed");
|
|
181 |
INFO_PRINTF1(KReadFail);
|
|
182 |
return TestStepResult();
|
|
183 |
}
|
|
184 |
}
|
|
185 |
else
|
|
186 |
{
|
|
187 |
_LIT(KValueCorrect, "Result Correct");
|
|
188 |
INFO_PRINTF1(KValueCorrect);
|
|
189 |
SetTestStepResult(EPass);
|
|
190 |
_LIT(KReadPass, "Read Passed");
|
|
191 |
INFO_PRINTF1(KReadPass);
|
|
192 |
return TestStepResult();
|
|
193 |
}
|
|
194 |
}
|
|
195 |
}
|
|
196 |
}
|
|
197 |
else
|
|
198 |
{
|
|
199 |
_LIT(KErrorRead, "Cannot read the ini file Number of Bytes ");
|
|
200 |
INFO_PRINTF3(KErrorRead,position, numbyte);
|
|
201 |
SetTestStepResult(EFail);
|
|
202 |
return TestStepResult();
|
|
203 |
}
|
|
204 |
}
|
|
205 |
else
|
|
206 |
{
|
|
207 |
_LIT(KErrorRead, "Cannot read the ini file Read Position ");
|
|
208 |
INFO_PRINTF1(KErrorRead);
|
|
209 |
SetTestStepResult(EFail);
|
|
210 |
return TestStepResult();
|
|
211 |
}
|
|
212 |
return TestStepResult();
|
|
213 |
}
|
|
214 |
|
|
215 |
|
|
216 |
/**
|
|
217 |
Read from the raw disk byte by byte and place the results into an array
|
|
218 |
|
|
219 |
@param aPos The position from which to start reading the raw disk
|
|
220 |
@param aNumberOfBytes The number of bytes to read from the raw disk
|
|
221 |
@param aAsciiValue Array containing the values that are read from the raw disk
|
|
222 |
|
|
223 |
@return KErrNone if successfull
|
|
224 |
*/
|
|
225 |
TInt CBaseTestFat32ReadRaw::ReadRaw(TInt64 aPos,TInt aNumberOfBytes,TInt *aAsciiValue)
|
|
226 |
{
|
|
227 |
TInt r;
|
|
228 |
r = TheDisk.Open(iTheFs, CurrentDrive());
|
|
229 |
if (r != KErrNone)
|
|
230 |
{
|
|
231 |
_LIT(KErrorRead, "Cannot open the raw disk - r=%d");
|
|
232 |
INFO_PRINTF2(KErrorRead, r);
|
|
233 |
return r;
|
|
234 |
}
|
|
235 |
|
|
236 |
TUint8 data[20];
|
|
237 |
TPtr8 buf(&data[0], 20);
|
|
238 |
r = TheDisk.Read(aPos, buf);
|
|
239 |
if (r != KErrNone)
|
|
240 |
{
|
|
241 |
_LIT(KErrorRead, "Cannot read the raw disk - r=%d");
|
|
242 |
INFO_PRINTF2(KErrorRead, r);
|
|
243 |
return r;
|
|
244 |
}
|
|
245 |
TInt i;
|
|
246 |
for (i = 0; i < aNumberOfBytes; i++)
|
|
247 |
{
|
|
248 |
aAsciiValue[i] = data[i];
|
|
249 |
}
|
|
250 |
TheDisk.Close();
|
|
251 |
return r;
|
|
252 |
}
|
|
253 |
|
|
254 |
/**
|
|
255 |
Get the correct result value byte by byte and place into an array
|
|
256 |
|
|
257 |
@param aNumberOfBytes The number of bytes to read from the raw disk
|
|
258 |
@param aCorrectResultArray Array containing the values that are expected
|
|
259 |
|
|
260 |
@return KErrNone if successful
|
|
261 |
*/
|
|
262 |
|
|
263 |
TInt CBaseTestFat32ReadRaw::GetCorrectResult(TInt aNumOfBytes,TInt* aCorrectResultArray)
|
|
264 |
{
|
|
265 |
TInt result;
|
|
266 |
TInt i;
|
|
267 |
_LIT(KCorrectResult,"CorrectResult%d");
|
|
268 |
for (i=1; i<aNumOfBytes+1; i++)
|
|
269 |
{
|
|
270 |
TBuf<20> a;
|
|
271 |
a.Format(KCorrectResult, i);
|
|
272 |
TBool alright3 = GetHexFromConfig(ConfigSection(), a, result);
|
|
273 |
if (alright3)
|
|
274 |
{
|
|
275 |
aCorrectResultArray[i-1] = result;
|
|
276 |
}
|
|
277 |
else
|
|
278 |
{
|
|
279 |
INFO_PRINTF1(_L("Could not get correct result from ini file"));
|
|
280 |
return KErrGeneral;
|
|
281 |
}
|
|
282 |
}
|
|
283 |
return KErrNone;
|
|
284 |
}
|
|
285 |
|
|
286 |
/**
|
|
287 |
Get the position by calulating from the entry and position in the entry
|
|
288 |
specified in the ini file
|
|
289 |
|
|
290 |
|
|
291 |
@param aClusterNumber The cluster number on the raw disk
|
|
292 |
@param aPosition The position from which to start reading the raw disk
|
|
293 |
|
|
294 |
@return KErrNone if successful
|
|
295 |
*/
|
|
296 |
TInt CBaseTestFat32ReadRaw::GetCluster(TInt aClusterNumber,TInt64 &aPosition)
|
|
297 |
{
|
|
298 |
TInt entry;
|
|
299 |
_LIT(KEntry,"Entry");
|
|
300 |
TInt entryposition;
|
|
301 |
_LIT(KPositionInEntry,"PositionInEntry");
|
|
302 |
TBool alright = GetIntFromConfig(ConfigSection(), KEntry, entry);
|
|
303 |
if (alright)
|
|
304 |
{
|
|
305 |
TBool alright2 = GetIntFromConfig(ConfigSection(), KPositionInEntry, entryposition);
|
|
306 |
if (alright2)
|
|
307 |
{
|
|
308 |
// Calculating the byte number on the disk when given the
|
|
309 |
// cluster number, the entry number and the position in the entry
|
|
310 |
TInt sizeOfEntry = 96;
|
|
311 |
aPosition = (iBPB_ResvdSecCnt + (iBPB_FATSz32 * 2) + (iBPB_SecPerClus * (aClusterNumber - 2))) * 512;
|
|
312 |
aPosition = aPosition + ((entry - 1) * sizeOfEntry) + entryposition;
|
|
313 |
return KErrNone;
|
|
314 |
}
|
|
315 |
else
|
|
316 |
{
|
|
317 |
INFO_PRINTF1(_L("Could not read position in entry from ini file"));
|
|
318 |
return KErrGeneral;
|
|
319 |
}
|
|
320 |
}
|
|
321 |
else
|
|
322 |
{
|
|
323 |
INFO_PRINTF1(_L("Could not read entry number from ini file"));
|
|
324 |
return KErrGeneral;
|
|
325 |
}
|
|
326 |
}
|
|
327 |
|
|
328 |
/**
|
|
329 |
Check if the mask value is correct with the mask obtained from the ini file
|
|
330 |
|
|
331 |
@param aMask Value of the mask
|
|
332 |
@param aNumberOfBytes The number of bytes to read from the raw disk
|
|
333 |
@param aAsciiValue Array containing the values that are read from the raw disk
|
|
334 |
@param aPos The position on the raw disk
|
|
335 |
|
|
336 |
@reutrn KErrNone is successfull
|
|
337 |
*/
|
|
338 |
TInt CBaseTestFat32ReadRaw::CheckMask(TInt aMask, TInt aNumOfBytes, TInt *aAsciiValue, TInt64 aPos)
|
|
339 |
{
|
|
340 |
TUint32 readValue;
|
|
341 |
TInt maskreturn;
|
|
342 |
_LIT(KMaskReturn,"MaskReturn");
|
|
343 |
TInt i;
|
|
344 |
|
|
345 |
readValue = 0;
|
|
346 |
for (i=aNumOfBytes-1; i>=0; i--)
|
|
347 |
{
|
|
348 |
|
|
349 |
readValue = readValue << 8;
|
|
350 |
readValue = readValue + aAsciiValue[i];
|
|
351 |
}
|
|
352 |
// Special case for the extension flag field. Checks whether mirroring is
|
|
353 |
// enabled or disabled and whether is contains the correct value. Position
|
|
354 |
// on the disk for this fiels is 0x29
|
|
355 |
if ((aPos == 0x29) && (aMask == 0))
|
|
356 |
{
|
|
357 |
if(readValue != 0)
|
|
358 |
{
|
|
359 |
aMask = 0x80;
|
|
360 |
if ((readValue&aMask) == (TUint32)aMask)
|
|
361 |
{
|
|
362 |
aMask = 0x0D;
|
|
363 |
if ((aMask&readValue) == 0)
|
|
364 |
{
|
|
365 |
INFO_PRINTF1(_L("Mirroring is DISABLED and the active FAT is correct"));
|
|
366 |
return KErrNone;
|
|
367 |
}
|
|
368 |
else
|
|
369 |
{
|
|
370 |
INFO_PRINTF1(_L("Mirroring is DISABLED and the active FAT is incorrect"));
|
|
371 |
return KErrGeneral;
|
|
372 |
}
|
|
373 |
}
|
|
374 |
}
|
|
375 |
else
|
|
376 |
{
|
|
377 |
INFO_PRINTF1(_L("Mirroring is ENABLED and the field is 0"));
|
|
378 |
return KErrNone;
|
|
379 |
}
|
|
380 |
}
|
|
381 |
else
|
|
382 |
{
|
|
383 |
TBool alright = GetIntFromConfig(ConfigSection(), KMaskReturn, maskreturn);
|
|
384 |
if (alright)
|
|
385 |
{
|
|
386 |
if (maskreturn == 0)
|
|
387 |
{
|
|
388 |
if ((readValue&aMask) == 0)
|
|
389 |
{
|
|
390 |
return KErrNone;
|
|
391 |
}
|
|
392 |
else
|
|
393 |
{
|
|
394 |
return KErrGeneral;
|
|
395 |
}
|
|
396 |
}
|
|
397 |
else
|
|
398 |
{
|
|
399 |
if ((readValue&aMask) == (TUint32)aMask)
|
|
400 |
{
|
|
401 |
return KErrNone;
|
|
402 |
}
|
|
403 |
else
|
|
404 |
{
|
|
405 |
return KErrGeneral;
|
|
406 |
}
|
|
407 |
}
|
|
408 |
}
|
|
409 |
}
|
|
410 |
return KErrNone;
|
|
411 |
}
|