|
1 // Copyright (c) 1998-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 // f32test\server\t_chlffs.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #define __E32TEST_EXTENSION__ |
|
19 #include <f32file.h> |
|
20 #include <e32test.h> |
|
21 #include <e32hal.h> |
|
22 #include <hal.h> |
|
23 |
|
24 // Now non-t_main programs need to chk if they are running on lffs, |
|
25 #include "t_server.h" |
|
26 #include "t_chlffs.h" |
|
27 |
|
28 |
|
29 const TInt KInvalidDriveLetter=-1; |
|
30 |
|
31 LOCAL_D TInt LFFSdriveNumber=KInvalidDriveLetter; |
|
32 LOCAL_D TBool LFFSTesting=EFalse; |
|
33 _LIT(KLFFSName,"Lffs"); |
|
34 |
|
35 |
|
36 LOCAL_C void FormatLFFS(RFs &anFsSession,TDes &aDrive) |
|
37 // |
|
38 // Format the LFFS drive |
|
39 // |
|
40 { |
|
41 RFormat format; |
|
42 TInt count; |
|
43 TInt r; |
|
44 |
|
45 test.Printf(_L("Format LFFS drive %S\r\n"), &aDrive); |
|
46 r=format.Open(anFsSession,aDrive,EHighDensity,count); |
|
47 test.Printf(_L("Format open done. Count = %d\r\n"), count); |
|
48 test(r==KErrNone); |
|
49 |
|
50 while (count) |
|
51 { |
|
52 TInt r=format.Next(count); |
|
53 test.Printf(_L("Format next done. Count = %d\r\n"), count); |
|
54 test(r==KErrNone); |
|
55 } |
|
56 |
|
57 format.Close(); |
|
58 } |
|
59 |
|
60 GLDEF_C TBool IsFileSystemLFFS(RFs &aFsSession,TInt aDrive) |
|
61 // |
|
62 // return true if lffs on aDrive |
|
63 // |
|
64 { |
|
65 TFileName f; |
|
66 TInt r=aFsSession.FileSystemName(f,aDrive); |
|
67 test(r==KErrNone || r==KErrNotFound); |
|
68 return (f.CompareF(KLFFSName)==0); |
|
69 } |
|
70 |
|
71 GLDEF_C TInt CheckLFFSDriveForPlatform() |
|
72 // |
|
73 // Check the LFFS drive number for the current platform |
|
74 // |
|
75 { |
|
76 TInt lffsDrvNum; |
|
77 |
|
78 TInt uid; |
|
79 TInt r=HAL::Get(HAL::EMachineUid,uid); |
|
80 test(r==KErrNone); |
|
81 |
|
82 if (uid==HAL::EMachineUid_Brutus) |
|
83 { |
|
84 lffsDrvNum=EDriveK; |
|
85 test.Printf(_L("Test is running on BRUTUS\r\n")); |
|
86 } |
|
87 else if (uid==HAL::EMachineUid_Win32Emulator) |
|
88 { |
|
89 lffsDrvNum=EDriveW; |
|
90 test.Printf(_L("Test is running on WINS Pc\r\n")); |
|
91 } |
|
92 else if (uid == HAL::EMachineUid_Integrator) |
|
93 { |
|
94 lffsDrvNum=EDriveK; |
|
95 test.Printf(_L("Test is running on INTEGRATOR\r\n")); |
|
96 } |
|
97 else if (uid == HAL::EMachineUid_Assabet) |
|
98 { |
|
99 lffsDrvNum=EDriveK; |
|
100 test.Printf(_L("Test is running on Assabet\r\n")); |
|
101 } |
|
102 else |
|
103 lffsDrvNum=KInvalidDriveLetter; |
|
104 return(lffsDrvNum); |
|
105 } |
|
106 |
|
107 GLDEF_C TBool CheckMountLFFS(RFs &anFsSession,TChar aDriveLetter) |
|
108 // |
|
109 // Check if test to be performed on LFFS drive. Mount the ELFFS.FSY if |
|
110 // necessary |
|
111 // |
|
112 { |
|
113 |
|
114 test.Next(_L("Check if LFFS drive (Mount LFFS if required)")); |
|
115 |
|
116 TInt r,drvNum; |
|
117 TBuf<4> lffsDriveLetter=_L("?:\\"); |
|
118 |
|
119 // first check if the lffs is mounted on the drive |
|
120 r=anFsSession.CharToDrive(aDriveLetter,drvNum); |
|
121 test(r==KErrNone); |
|
122 if (IsFileSystemLFFS(anFsSession,drvNum)) |
|
123 { |
|
124 lffsDriveLetter[0]=(TText)aDriveLetter; |
|
125 test.Printf(_L("Testing an LFFS drive (%S)"), &lffsDriveLetter); |
|
126 test.Printf(_L("LFFS already mounted on drive %S\r\n"), &lffsDriveLetter); |
|
127 LFFSdriveNumber=drvNum; |
|
128 LFFSTesting=ETrue; |
|
129 return(ETrue); |
|
130 } |
|
131 |
|
132 // check if platform expects lffs to be mounted on specified drive |
|
133 TInt lffsDrvNum=CheckLFFSDriveForPlatform(); |
|
134 if (drvNum!=lffsDrvNum) |
|
135 { |
|
136 test.Printf(_L("Not testing an LFFS drive\n")); |
|
137 return(EFalse); |
|
138 } |
|
139 |
|
140 lffsDriveLetter[0]=(TText)aDriveLetter; |
|
141 test.Printf(_L("Testing an LFFS drive (%S)"), &lffsDriveLetter); |
|
142 LFFSdriveNumber=lffsDrvNum; |
|
143 LFFSTesting=ETrue; |
|
144 |
|
145 test.Next(_L("Load device driver: MEDLFS")); |
|
146 r=User::LoadPhysicalDevice(_L("MEDLFS")); |
|
147 test(r==KErrNone || r==KErrAlreadyExists); |
|
148 |
|
149 test.Next(_L("Add file system: ELFFS")); |
|
150 r=anFsSession.AddFileSystem(_L("ELFFS")); |
|
151 test(r==KErrNone || r==KErrAlreadyExists); |
|
152 |
|
153 TFullName name; |
|
154 r=anFsSession.FileSystemName(name,LFFSdriveNumber); |
|
155 test(r==KErrNone || r==KErrNotFound); |
|
156 |
|
157 if (name.MatchF(_L("Lffs")) != 0) |
|
158 { |
|
159 // Some other file system is at the "Lffs" drive. |
|
160 if (name.Length() != 0) |
|
161 { |
|
162 // Not allowed to dismount the file system from the drive associated |
|
163 // with the default path - so temporarily change the default path. |
|
164 test.Printf(_L("Dismounting %S on drive %S\r\n"), &name, &lffsDriveLetter); |
|
165 r=anFsSession.DismountFileSystem(name,LFFSdriveNumber); |
|
166 test(r==KErrNone); |
|
167 |
|
168 } |
|
169 |
|
170 test.Printf(_L("Mount LFFS on drive %S\r\n"),&lffsDriveLetter); |
|
171 r=anFsSession.MountFileSystem(_L("Lffs"), LFFSdriveNumber); |
|
172 test.Printf(_L(" Mount result %d\r\n"), r); |
|
173 test(r==KErrNone || r==KErrCorrupt || r==KErrNotReady); |
|
174 |
|
175 if (r==KErrCorrupt) |
|
176 { |
|
177 test.Printf(_L("The volume was corrupt. Formatting...\r\n")); |
|
178 FormatLFFS(anFsSession,lffsDriveLetter); |
|
179 } |
|
180 else if(r==KErrNotReady) |
|
181 { |
|
182 test.Printf(_L("The mount was not ready. Formatting...\r\n")); |
|
183 FormatLFFS(anFsSession,lffsDriveLetter); |
|
184 } |
|
185 else |
|
186 { |
|
187 test.Printf(_L("The volume was mounted OK. Formatting...\r\n")); |
|
188 FormatLFFS(anFsSession,lffsDriveLetter); // ??? |
|
189 } |
|
190 } |
|
191 else |
|
192 { |
|
193 test.Printf(_L("LFFS already mounted on drive %S\r\n"), &lffsDriveLetter); |
|
194 } |
|
195 |
|
196 return(ETrue); |
|
197 } |
|
198 |
|
199 GLDEF_C TBool IsTestingLFFS() |
|
200 // |
|
201 // Return ETrue if testing LFFS |
|
202 // |
|
203 { |
|
204 return(LFFSTesting); |
|
205 } |
|
206 |
|
207 GLDEF_C void TestingLFFS(TBool aSetting) |
|
208 // |
|
209 // Set whether testing LFFS or not |
|
210 // |
|
211 { |
|
212 LFFSTesting=aSetting; |
|
213 } |
|
214 |
|
215 GLDEF_C TInt GetDriveLFFS() |
|
216 // |
|
217 // Return the LFFS drive number |
|
218 // |
|
219 { |
|
220 return(LFFSdriveNumber); |
|
221 } |
|
222 |
|
223 GLDEF_C TBool IsSessionDriveLFFS(RFs& aFs,TChar& aDriveLetter) |
|
224 { |
|
225 // |
|
226 // Quick method of testing if session drive is LFFS |
|
227 // |
|
228 TBool isLffs; |
|
229 TFileName path; |
|
230 TInt r=aFs.SessionPath(path); |
|
231 test(r==KErrNone); |
|
232 TInt drv; |
|
233 r=RFs::CharToDrive(path[0],drv); |
|
234 test(r==KErrNone); |
|
235 |
|
236 aDriveLetter=path[0]; |
|
237 isLffs=IsFileSystemLFFS(aFs,drv); |
|
238 if(isLffs) |
|
239 return(ETrue); |
|
240 |
|
241 // check if platform expects lffs to be mounted on default drive |
|
242 TInt lffsDrv = CheckLFFSDriveForPlatform(); |
|
243 if (lffsDrv == KInvalidDriveLetter) |
|
244 { |
|
245 test.Printf(_L("IsSessionDriveLFFS: platform does not support lffs.\r\n")); |
|
246 isLffs = EFalse; |
|
247 } |
|
248 else |
|
249 { |
|
250 TChar curCh=path[0]; |
|
251 curCh.LowerCase(); |
|
252 |
|
253 TChar lffsCh; // lffs drv ltr |
|
254 test((r = RFs::DriveToChar(lffsDrv, lffsCh)) == KErrNone); |
|
255 lffsCh.LowerCase(); |
|
256 |
|
257 test.Printf(_L("IsSessionDriveLFFS: cur drv = \'%c\', lffs drv = \'%c\'.\n"), (TText) curCh, (TText) lffsCh); |
|
258 isLffs = ((TText) curCh) == ((TText) lffsCh); |
|
259 } |
|
260 |
|
261 return(isLffs); |
|
262 } |
|
263 |
|
264 GLDEF_C TBool IsDefaultDriveLFFS() |
|
265 // |
|
266 // Quick method of testing if running on LFFS for non t_main based tests. |
|
267 // |
|
268 { |
|
269 // check if lffs mounted on default drive |
|
270 TBool isLffs; |
|
271 RFs fs; |
|
272 TInt r=fs.Connect(); |
|
273 test(r==KErrNone); |
|
274 TFileName path; |
|
275 r=fs.SessionPath(path); |
|
276 test(r==KErrNone); |
|
277 TInt drv; |
|
278 r=TheFs.CharToDrive(path[0],drv); |
|
279 test(r==KErrNone); |
|
280 |
|
281 isLffs=IsFileSystemLFFS(fs,drv); |
|
282 fs.Close(); |
|
283 if(isLffs) |
|
284 return(ETrue); |
|
285 |
|
286 // check if platform expects lffs to be mounted on default drive |
|
287 TInt lffsDrv = CheckLFFSDriveForPlatform(); |
|
288 if (lffsDrv == KInvalidDriveLetter) |
|
289 { |
|
290 test.Printf(_L("IsCurrentDriveLFFS: platform does not support lffs.\r\n")); |
|
291 isLffs = EFalse; |
|
292 } |
|
293 else |
|
294 { |
|
295 TChar curCh=path[0]; |
|
296 curCh.LowerCase(); |
|
297 |
|
298 TChar lffsCh; // lffs drv ltr |
|
299 test((r = RFs::DriveToChar(lffsDrv, lffsCh)) == KErrNone); |
|
300 lffsCh.LowerCase(); |
|
301 |
|
302 test.Printf(_L("IsCurrentDriveLFFS: cur drv = \'%c\', lffs drv = \'%c\'.\n"), (TText) curCh, (TText) lffsCh); |
|
303 isLffs = ((TText) curCh) == ((TText) lffsCh); |
|
304 } |
|
305 |
|
306 return(isLffs); |
|
307 } |
|
308 |
|
309 GLDEF_C TBool IsNamedDriveLFFS(RFs &aFsSession,TText aDrv) |
|
310 // |
|
311 // Quick method of testing if running on LFFS for non t_main based tests. |
|
312 // |
|
313 { |
|
314 TInt d; |
|
315 TInt r=RFs::CharToDrive(aDrv,d); |
|
316 test(r==KErrNone); |
|
317 return(IsFileSystemLFFS(aFsSession,d)); |
|
318 } |
|
319 |
|
320 GLDEF_C TInt GetLFFSControlModeSize() |
|
321 // |
|
322 // For LFFS, the media may not exhibit a contiguous data region. This is the case if the |
|
323 // Control Mode Size is non-zero. |
|
324 // |
|
325 { |
|
326 TLocalDriveCapsV7 caps; // V7 to allow for devices exhibiting Control Mode |
|
327 TPckg<TLocalDriveCapsV7> capsPckg(caps); |
|
328 TBusLocalDrive localDrive; |
|
329 TBool lffsMediaFound = EFalse; |
|
330 TBool dumBool = EFalse; // Arbitrary if LFFS is mounted on non-removable media |
|
331 // Loop to find the local drive for LFFS - this is always of type EMediaFlash |
|
332 for(TInt drvNum=0; drvNum<KMaxLocalDrives; drvNum++) |
|
333 { |
|
334 TInt r=localDrive.Connect(drvNum,dumBool); |
|
335 if(r==KErrNotSupported) |
|
336 continue; // Local drive not present |
|
337 test_KErrNone(r); |
|
338 r=localDrive.Caps(capsPckg); |
|
339 localDrive.Disconnect(); |
|
340 if(r==KErrNotSupported||r==KErrNotReady) |
|
341 continue; // Local drive not available |
|
342 test_KErrNone(r); |
|
343 if(capsPckg().iType==EMediaFlash) |
|
344 { |
|
345 lffsMediaFound=ETrue; |
|
346 break; |
|
347 } |
|
348 } |
|
349 if(!lffsMediaFound) |
|
350 { |
|
351 test.Printf(_L("GetLFFSControlModeSize: LFFS media not found !\n")); |
|
352 return KErrGeneral; |
|
353 } |
|
354 return (capsPckg().iControlModeSize); |
|
355 } |