|
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 #include "t_fat32writeraw.h" |
|
20 |
|
21 static RRawDisk TheDisk; |
|
22 |
|
23 /** |
|
24 Class Constructor |
|
25 */ |
|
26 CBaseTestFat32WriteRaw::CBaseTestFat32WriteRaw() |
|
27 { |
|
28 SetTestStepName(KTestStepWriteRaw); |
|
29 } |
|
30 |
|
31 /** |
|
32 Class Destructor |
|
33 */ |
|
34 CBaseTestFat32WriteRaw::~CBaseTestFat32WriteRaw() |
|
35 { |
|
36 } |
|
37 |
|
38 /** |
|
39 This function performs the following actions: |
|
40 1. Get the position at which to write on the raw disk from the ini file |
|
41 -> if a cluster is specified, get the position from the GetCluster function |
|
42 2. Get the number of bytes to write from the ini file |
|
43 3. Obtain the values to be written to the disk from the ini file. |
|
44 4. Write the values to the disk byte by byte. |
|
45 |
|
46 @return EPass if test passes and EFail if test fails |
|
47 */ |
|
48 TVerdict CBaseTestFat32WriteRaw::doTestStepL() |
|
49 { |
|
50 SetTestStepResult(EFail); |
|
51 _LIT(KPosition,"WritePosition"); |
|
52 _LIT(KNumOfBytes,"NumberOfBytes"); |
|
53 _LIT(KCluster,"ClusterNumber"); |
|
54 TInt writevalues[12]; |
|
55 TInt position; |
|
56 TInt64 clusterPosition; |
|
57 TInt cluster; |
|
58 TInt numbyte; |
|
59 TInt r; |
|
60 TBool alright = GetHexFromConfig(ConfigSection(), KPosition, position); |
|
61 if(alright) |
|
62 { |
|
63 if (iMedia == 1 && position >= 16384) |
|
64 { |
|
65 INFO_PRINTF2(_L("Position = %d"), position); |
|
66 INFO_PRINTF2(_L("iBPB_ResvdSecCnt = %d"), iBPB_ResvdSecCnt); |
|
67 position = (iBPB_ResvdSecCnt * 512) + (position - 0x4000); |
|
68 INFO_PRINTF2(_L("New Position = %d"), position); |
|
69 } |
|
70 TBool alright2 = GetHexFromConfig(ConfigSection(), KNumOfBytes, numbyte); |
|
71 if (alright2) |
|
72 { |
|
73 TBool alright2 = GetIntFromConfig(ConfigSection(), KCluster, cluster); |
|
74 if (alright2) |
|
75 { |
|
76 r = GetCluster(cluster, clusterPosition); |
|
77 position = clusterPosition; |
|
78 } |
|
79 else |
|
80 { |
|
81 position = position; |
|
82 } |
|
83 _LIT(KFATEntryWritePosition,"FATEntryWritePosition"); |
|
84 _LIT(KFATEntry0,"FATEntry0"); |
|
85 _LIT(KFATEntry1,"FATEntry1"); |
|
86 _LIT(KFATEntry2,"FATEntry2"); |
|
87 _LIT(KFATEntry3,"FATEntry3"); |
|
88 _LIT(KFATEntry4,"FATEntry4"); |
|
89 _LIT(KFATEntry6,"FATEntry6"); |
|
90 _LIT(KFATEntry18,"FATEntry18"); |
|
91 _LIT(KFATEntry52,"FATEntry52"); |
|
92 _LIT(KFATEntry78,"FATEntry78"); |
|
93 |
|
94 |
|
95 TPtrC fat_entry_str; |
|
96 if(GetStringFromConfig(ConfigSection(), KFATEntryWritePosition, fat_entry_str)) |
|
97 { |
|
98 if(!fat_entry_str.Compare(KFATEntry0)) |
|
99 { |
|
100 position = iBPB_ResvdSecCnt * iBPB_BytsPerSec; |
|
101 } |
|
102 else if(!fat_entry_str.Compare(KFATEntry1)) |
|
103 { |
|
104 position = iBPB_ResvdSecCnt * iBPB_BytsPerSec + 4; |
|
105 } |
|
106 else if(!fat_entry_str.Compare(KFATEntry2)) |
|
107 { |
|
108 position = iBPB_ResvdSecCnt * iBPB_BytsPerSec + 4*2; |
|
109 } |
|
110 else if(!fat_entry_str.Compare(KFATEntry3)) |
|
111 { |
|
112 position = iBPB_ResvdSecCnt * iBPB_BytsPerSec + 4*3; |
|
113 } |
|
114 else if(!fat_entry_str.Compare(KFATEntry4)) |
|
115 { |
|
116 position = iBPB_ResvdSecCnt * iBPB_BytsPerSec + 4*4; |
|
117 } |
|
118 else if(!fat_entry_str.Compare(KFATEntry6)) |
|
119 { |
|
120 position = iBPB_ResvdSecCnt * iBPB_BytsPerSec + 4*6; |
|
121 } |
|
122 else if(!fat_entry_str.Compare(KFATEntry18)) |
|
123 { |
|
124 position = iBPB_ResvdSecCnt * iBPB_BytsPerSec + 4*18; |
|
125 } |
|
126 else if(!fat_entry_str.Compare(KFATEntry52)) |
|
127 { |
|
128 position = iBPB_ResvdSecCnt * iBPB_BytsPerSec + 4*52; |
|
129 } |
|
130 else if(!fat_entry_str.Compare(KFATEntry78)) |
|
131 { |
|
132 position = iBPB_ResvdSecCnt * iBPB_BytsPerSec + 4*78; |
|
133 } |
|
134 |
|
135 } |
|
136 _LIT(KWritePosition, "The position on the disk being written to is %d"); |
|
137 INFO_PRINTF2(KWritePosition,position); |
|
138 r = GetWriteValue(numbyte,writevalues); |
|
139 TInt i; |
|
140 r = TheDisk.Open(iTheFs, CurrentDrive()); |
|
141 if (r!=KErrNone) |
|
142 { |
|
143 _LIT(KErrorOpen, "Cannot open the raw disk - r=%d"); |
|
144 INFO_PRINTF2(KErrorOpen, r); |
|
145 } |
|
146 for (i=0;i<numbyte;i++) |
|
147 { |
|
148 r = WriteRaw(position+i, writevalues[i]); |
|
149 if(r != KErrNone) |
|
150 { |
|
151 _LIT(KErrorRead, "Cannot write to the raw disk at position %d with value %d"); |
|
152 INFO_PRINTF3(KErrorRead,position, writevalues[i]); |
|
153 SetTestStepResult(EFail); |
|
154 return TestStepResult(); |
|
155 } |
|
156 } |
|
157 TheDisk.Close(); |
|
158 } |
|
159 else |
|
160 { |
|
161 _LIT(KNoIniNumByte, "Cannot read the number of bytes from the ini file"); |
|
162 INFO_PRINTF1(KNoIniNumByte); |
|
163 SetTestStepResult(EFail); |
|
164 return TestStepResult(); |
|
165 } |
|
166 } |
|
167 else |
|
168 { |
|
169 _LIT(KNoIniPos, "Cannot read the position from the ini file"); |
|
170 INFO_PRINTF1(KNoIniPos); |
|
171 SetTestStepResult(EFail); |
|
172 return TestStepResult(); |
|
173 } |
|
174 |
|
175 |
|
176 SetTestStepResult(EPass); |
|
177 _LIT(KWritePass, "Write Passed"); |
|
178 INFO_PRINTF1(KWritePass); |
|
179 return TestStepResult(); |
|
180 } |
|
181 |
|
182 /** |
|
183 Writing a value to the raw disk |
|
184 |
|
185 @param aPos The position from which to start writing to the raw disk |
|
186 @param aValue The value to write to the raw disk |
|
187 |
|
188 @return KErrNone if successfull |
|
189 */ |
|
190 TInt CBaseTestFat32WriteRaw::WriteRaw(TInt64 aPos,TInt aValue) |
|
191 { |
|
192 // int val = 0; |
|
193 TInt r; |
|
194 TUint8 data[1]; |
|
195 TPtr8 buffer((TUint8*)&data[0],1); |
|
196 r = TheDisk.Read(aPos,buffer); |
|
197 data[0] = aValue; |
|
198 r = TheDisk.Write(aPos,buffer); |
|
199 if (r != KErrNone) |
|
200 { |
|
201 _LIT(KErrorWrite, "Cannot write to the raw disk - r=%d"); |
|
202 INFO_PRINTF2(KErrorWrite,r); |
|
203 } |
|
204 return r; |
|
205 } |
|
206 |
|
207 /** |
|
208 Get the values that are to be written to the disk byte by byte |
|
209 and place into an array |
|
210 |
|
211 @param aNumberOfBytes the nummber of bytes to write to the raw disk |
|
212 @param aValueArray Array containing the values to write to the raw disk |
|
213 |
|
214 @return KErrNone if successfull |
|
215 */ |
|
216 TInt CBaseTestFat32WriteRaw::GetWriteValue(TInt aNumOfBytes,TInt* aValueArray) |
|
217 { |
|
218 TInt value; |
|
219 TInt i; |
|
220 _LIT(KWriteValues,"WriteValue%d"); |
|
221 for (i = 1; i < aNumOfBytes + 1; i++) |
|
222 { |
|
223 TBuf<20> writeValue; |
|
224 writeValue.Format(KWriteValues, i); |
|
225 TBool alright3 = GetHexFromConfig(ConfigSection(), writeValue, value); |
|
226 if (alright3) |
|
227 { |
|
228 aValueArray[i-1] = value; |
|
229 } |
|
230 else |
|
231 { |
|
232 INFO_PRINTF1(_L("Cannot read WriteValue from ini file")); |
|
233 return KErrGeneral; |
|
234 } |
|
235 } |
|
236 return KErrNone; |
|
237 } |
|
238 |
|
239 /** |
|
240 Get the position by calulating from the entry and position in the entry |
|
241 specified in the ini file |
|
242 |
|
243 @param aClusterNumber The cluster on the disk to write to |
|
244 @param aPosition the position within an entry |
|
245 |
|
246 @return KErrNone if successfull |
|
247 */ |
|
248 TInt CBaseTestFat32WriteRaw::GetCluster(TInt aClusterNumber,TInt64 &aPosition) |
|
249 { |
|
250 TInt entry; |
|
251 _LIT(KEntry,"Entry"); |
|
252 TInt entryposition; |
|
253 _LIT(KPositionInEntry,"PositionInEntry"); |
|
254 TBool alright = GetIntFromConfig(ConfigSection(), KEntry, entry); |
|
255 if (alright) |
|
256 { |
|
257 TBool alright2 = GetIntFromConfig(ConfigSection(), KPositionInEntry, entryposition); |
|
258 if (alright2) |
|
259 { |
|
260 aPosition = (iBPB_ResvdSecCnt + (iBPB_FATSz32*2) + (iBPB_SecPerClus * (aClusterNumber - 2))) * 512; |
|
261 aPosition = aPosition + ((entry - 1)*96)+ entryposition;//(32 * (entry - 1)); |
|
262 } |
|
263 } |
|
264 return KErrNone; |
|
265 } |
|
266 |