1 // Copyright (c) 2006-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 // Performs various different disk calculations |
|
15 // |
|
16 // |
|
17 |
|
18 #include "basetestfat32calculate.h" |
|
19 #include "sl_bpb1.h" |
|
20 |
|
21 static RRawDisk TheDisk; |
|
22 |
|
23 /** |
|
24 Class Constructor |
|
25 */ |
|
26 CBaseTestFat32Calculate::CBaseTestFat32Calculate() |
|
27 { |
|
28 SetTestStepName(KTestStepCalculate); |
|
29 } |
|
30 |
|
31 /** |
|
32 Class Destructor |
|
33 */ |
|
34 CBaseTestFat32Calculate::~CBaseTestFat32Calculate() |
|
35 { |
|
36 } |
|
37 |
|
38 |
|
39 /** |
|
40 Get the calculation to be performed from the ini file and carry out that |
|
41 particular calculation |
|
42 1. If SetGreater is specified in the ini file then the function SetToGreater |
|
43 is called the set the cluster count to a value greater than it actually is |
|
44 2. If ComputeFatSize is specified in the ini file then the function |
|
45 ComputeFatSize is called to computer the size of each FAT |
|
46 3. If ClusterCount is specified in the ini file, then the function |
|
47 ClusterCount is called to return the clutser count of the volume |
|
48 |
|
49 @return EPass if test passes and EFail if test fails |
|
50 */ |
|
51 TVerdict CBaseTestFat32Calculate::doTestStepL() |
|
52 { |
|
53 SetTestStepResult(EFail); |
|
54 _LIT(KCalculation,"Calculation"); |
|
55 TBufC<6> calculationType; |
|
56 TPtrC16 calculation = calculationType; |
|
57 TBool alright = GetStringFromConfig(ConfigSection(), KCalculation, calculation); |
|
58 if(alright) |
|
59 { |
|
60 if (calculation == _L("SetGreater")) |
|
61 { |
|
62 TInt r = SetToGreater(iClusterCount, 1000); |
|
63 if (r != KErrNone) |
|
64 { |
|
65 _LIT(KFailClusterCount, "Failed to Set to a greater cluster count - r=%d"); |
|
66 INFO_PRINTF2(KFailClusterCount, r); |
|
67 return TestStepResult(); |
|
68 } |
|
69 } |
|
70 if (calculation == _L("ComputeFatSize")) |
|
71 { |
|
72 TInt r = ComputeFatSize(); |
|
73 if (r != KErrNone) |
|
74 { |
|
75 _LIT(KFailComputeFatSz, "Failed to compute FatSz - r=%d"); |
|
76 INFO_PRINTF2(KFailComputeFatSz, r); |
|
77 return TestStepResult(); |
|
78 } |
|
79 } |
|
80 if (calculation == _L("ClusterCount")) |
|
81 { |
|
82 TInt r = CheckClusterCount(iClusterCount); |
|
83 if (r != KErrNone) |
|
84 { |
|
85 _LIT(KFailComputeClusCnt, "Failed to compute ClusterCount - r=%d"); |
|
86 INFO_PRINTF2(KFailComputeClusCnt, r); |
|
87 return TestStepResult(); |
|
88 } |
|
89 } |
|
90 if (calculation == _L("CheckFSInfo")) |
|
91 { |
|
92 TInt r = CheckFSInfo(0x3E8); |
|
93 if (r != KErrNone) |
|
94 { |
|
95 _LIT(KFailCheckFSInfo, "Failed FSInfo check - r=%d"); |
|
96 INFO_PRINTF2(KFailCheckFSInfo, r); |
|
97 return TestStepResult(); |
|
98 } |
|
99 } |
|
100 } |
|
101 else |
|
102 { |
|
103 _LIT(KIniFileError, "Failed to read calculation type from ini file"); |
|
104 INFO_PRINTF1(KIniFileError); |
|
105 return TestStepResult(); |
|
106 } |
|
107 |
|
108 SetTestStepResult(EPass); |
|
109 _LIT(KWritePass, "Calculation Pass"); |
|
110 INFO_PRINTF1(KWritePass); |
|
111 return TestStepResult(); |
|
112 } |
|
113 |
|
114 /** |
|
115 Set the cluster count to a value greater than it should be |
|
116 The bad cluster count is caluclated as 10000 added to the actual |
|
117 cluster count value. The bad cluster count is then written to the disk |
|
118 in place of the actual cluster count. |
|
119 |
|
120 @param aClusterCount The cluster count of the volume |
|
121 @param aPos The position at which to start writing to the raw disk |
|
122 |
|
123 @return KErrNone if successful |
|
124 */ |
|
125 TInt CBaseTestFat32Calculate::SetToGreater(TUint32 aClusterCount, TInt aPos) |
|
126 { |
|
127 TUint32 badClusterCount; |
|
128 badClusterCount = aClusterCount+10000; |
|
129 TUint8 num[4]; |
|
130 TInt i; |
|
131 TInt r; |
|
132 |
|
133 r = TheDisk.Open(iTheFs, CurrentDrive()); |
|
134 for (i=0; i<4; i++) |
|
135 { |
|
136 |
|
137 num[i] = 0; |
|
138 num[i] = num[i] + badClusterCount; |
|
139 badClusterCount = badClusterCount >> 8; |
|
140 } |
|
141 |
|
142 TUint8 data[1]; |
|
143 TPtr8 buffer((TUint8*)&data[0],1); |
|
144 |
|
145 for (i=0; i<4; i++) |
|
146 { |
|
147 aPos = aPos + 1; |
|
148 r=TheDisk.Read(aPos,buffer); |
|
149 data[0]=num[i]; |
|
150 r=TheDisk.Write(aPos,buffer); |
|
151 } |
|
152 TheDisk.Close(); |
|
153 return r; |
|
154 } |
|
155 |
|
156 /** |
|
157 Calculate the size of each FAT and verify that it is equal the |
|
158 value in BPB_FATSz32. The 'BPB_..' values are read directly from the disk |
|
159 and the calculation is taken from the Microsoft FAT32 speification document |
|
160 |
|
161 @return KErrNone if successful |
|
162 */ |
|
163 TInt CBaseTestFat32Calculate::ComputeFatSize() |
|
164 { |
|
165 TInt TmpVal1 = (iDriveSize/512) - iBPB_ResvdSecCnt; |
|
166 TInt TmpVal2 = (256 * iBPB_SecPerClus) + iBPB_NumFATs; |
|
167 TmpVal2 = TmpVal2 / 2; |
|
168 TInt FatSz32 = (TmpVal1 + (TmpVal2 - 1)) / TmpVal2; |
|
169 INFO_PRINTF2(_L("FatSz32 = %d"), FatSz32); |
|
170 if (iBPB_FATSz32 == FatSz32) |
|
171 { |
|
172 _LIT(KFatSzPass, "BPB_FATSz32 = %d is equal to calculated value = %d"); |
|
173 INFO_PRINTF3(KFatSzPass,iBPB_FATSz32, FatSz32 ); |
|
174 return KErrNone; |
|
175 } |
|
176 else |
|
177 { |
|
178 _LIT(KFatSzFail, "BPB_FATSz32 = %d is not equal to the calculated value = %d"); |
|
179 INFO_PRINTF3(KFatSzFail, iBPB_FATSz32,FatSz32); |
|
180 return -1; |
|
181 } |
|
182 } |
|
183 |
|
184 /** |
|
185 Verify that the cluster count is greater than 65525. |
|
186 If the volume is FAT32 then it should have a cluster count greater than |
|
187 65525. Otherwise the volume should be FAT16. |
|
188 |
|
189 @param aClusterCount The cluster count of the volume |
|
190 |
|
191 @return KErrNone if successful |
|
192 */ |
|
193 TInt CBaseTestFat32Calculate::CheckClusterCount(TUint32 aClusterCount) |
|
194 { |
|
195 if (aClusterCount > 65525) |
|
196 { |
|
197 _LIT(KClusCntPass, "Cluster count is greater than 65525"); |
|
198 INFO_PRINTF1(KClusCntPass); |
|
199 return KErrNone; |
|
200 } |
|
201 else |
|
202 { |
|
203 _LIT(KClusCntFail, "Cluster count is not greater than 65525"); |
|
204 INFO_PRINTF1(KClusCntFail); |
|
205 return -1; |
|
206 } |
|
207 } |
|
208 |
|
209 |
|
210 /** |
|
211 Read the FSInfo sector at the FSI_Free_Count field. |
|
212 Following this check that the last known cluster count is less than |
|
213 the actual cluster count of the volume. |
|
214 |
|
215 Note: This function should be called after files have been written |
|
216 to the disk to ensure that clusters have been occupied |
|
217 |
|
218 @param aPos The position at which to start reading from the raw disk |
|
219 |
|
220 @return KErrNone if successful |
|
221 */ |
|
222 TInt CBaseTestFat32Calculate::CheckFSInfo(TInt aPos) |
|
223 { |
|
224 TUint32 fsInfo; |
|
225 |
|
226 TUint32 data; |
|
227 TPtr8 buffer((TUint8*)&data,4); |
|
228 |
|
229 TInt r = TheDisk.Open(iTheFs, CurrentDrive()); |
|
230 r = TheDisk.Read(aPos,buffer); |
|
231 |
|
232 fsInfo = data; |
|
233 |
|
234 TheDisk.Close(); |
|
235 |
|
236 if (fsInfo < iClusterCount) |
|
237 { |
|
238 _LIT(KFSInfoPass, "FSInfo Correct, iClusterCount = %08x fsInfo = %08x fsInfo = %08x"); |
|
239 INFO_PRINTF4(KFSInfoPass, iClusterCount, data, fsInfo); |
|
240 return KErrNone; |
|
241 } |
|
242 else |
|
243 { |
|
244 _LIT(KFSInfoFail, "FSInfo incorrect, iClusterCount = %08x fsInfo = %08x"); |
|
245 INFO_PRINTF3(KFSInfoFail, iClusterCount, fsInfo); |
|
246 return -1; |
|
247 } |
|
248 } |
|