Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32test\server\t_chlffs.cpp
18 #define __E32TEST_EXTENSION__
24 // Now non-t_main programs need to chk if they are running on lffs,
29 const TInt KInvalidDriveLetter=-1;
31 LOCAL_D TInt LFFSdriveNumber=KInvalidDriveLetter;
32 LOCAL_D TBool LFFSTesting=EFalse;
33 _LIT(KLFFSName,"Lffs");
36 LOCAL_C void FormatLFFS(RFs &anFsSession,TDes &aDrive)
38 // Format the LFFS drive
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);
52 TInt r=format.Next(count);
53 test.Printf(_L("Format next done. Count = %d\r\n"), count);
60 GLDEF_C TBool IsFileSystemLFFS(RFs &aFsSession,TInt aDrive)
62 // return true if lffs on aDrive
66 TInt r=aFsSession.FileSystemName(f,aDrive);
67 test(r==KErrNone || r==KErrNotFound);
68 return (f.CompareF(KLFFSName)==0);
71 GLDEF_C TInt CheckLFFSDriveForPlatform()
73 // Check the LFFS drive number for the current platform
79 TInt r=HAL::Get(HAL::EMachineUid,uid);
82 if (uid==HAL::EMachineUid_Brutus)
85 test.Printf(_L("Test is running on BRUTUS\r\n"));
87 else if (uid==HAL::EMachineUid_Win32Emulator)
90 test.Printf(_L("Test is running on WINS Pc\r\n"));
92 else if (uid == HAL::EMachineUid_Integrator)
95 test.Printf(_L("Test is running on INTEGRATOR\r\n"));
97 else if (uid == HAL::EMachineUid_Assabet)
100 test.Printf(_L("Test is running on Assabet\r\n"));
103 lffsDrvNum=KInvalidDriveLetter;
107 GLDEF_C TBool CheckMountLFFS(RFs &anFsSession,TChar aDriveLetter)
109 // Check if test to be performed on LFFS drive. Mount the ELFFS.FSY if
114 test.Next(_L("Check if LFFS drive (Mount LFFS if required)"));
117 TBuf<4> lffsDriveLetter=_L("?:\\");
119 // first check if the lffs is mounted on the drive
120 r=anFsSession.CharToDrive(aDriveLetter,drvNum);
122 if (IsFileSystemLFFS(anFsSession,drvNum))
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;
132 // check if platform expects lffs to be mounted on specified drive
133 TInt lffsDrvNum=CheckLFFSDriveForPlatform();
134 if (drvNum!=lffsDrvNum)
136 test.Printf(_L("Not testing an LFFS drive\n"));
140 lffsDriveLetter[0]=(TText)aDriveLetter;
141 test.Printf(_L("Testing an LFFS drive (%S)"), &lffsDriveLetter);
142 LFFSdriveNumber=lffsDrvNum;
145 test.Next(_L("Load device driver: MEDLFS"));
146 r=User::LoadPhysicalDevice(_L("MEDLFS"));
147 test(r==KErrNone || r==KErrAlreadyExists);
149 test.Next(_L("Add file system: ELFFS"));
150 r=anFsSession.AddFileSystem(_L("ELFFS"));
151 test(r==KErrNone || r==KErrAlreadyExists);
154 r=anFsSession.FileSystemName(name,LFFSdriveNumber);
155 test(r==KErrNone || r==KErrNotFound);
157 if (name.MatchF(_L("Lffs")) != 0)
159 // Some other file system is at the "Lffs" drive.
160 if (name.Length() != 0)
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);
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);
177 test.Printf(_L("The volume was corrupt. Formatting...\r\n"));
178 FormatLFFS(anFsSession,lffsDriveLetter);
180 else if(r==KErrNotReady)
182 test.Printf(_L("The mount was not ready. Formatting...\r\n"));
183 FormatLFFS(anFsSession,lffsDriveLetter);
187 test.Printf(_L("The volume was mounted OK. Formatting...\r\n"));
188 FormatLFFS(anFsSession,lffsDriveLetter); // ???
193 test.Printf(_L("LFFS already mounted on drive %S\r\n"), &lffsDriveLetter);
199 GLDEF_C TBool IsTestingLFFS()
201 // Return ETrue if testing LFFS
207 GLDEF_C void TestingLFFS(TBool aSetting)
209 // Set whether testing LFFS or not
212 LFFSTesting=aSetting;
215 GLDEF_C TInt GetDriveLFFS()
217 // Return the LFFS drive number
220 return(LFFSdriveNumber);
223 GLDEF_C TBool IsSessionDriveLFFS(RFs& aFs,TChar& aDriveLetter)
226 // Quick method of testing if session drive is LFFS
230 TInt r=aFs.SessionPath(path);
233 r=RFs::CharToDrive(path[0],drv);
236 aDriveLetter=path[0];
237 isLffs=IsFileSystemLFFS(aFs,drv);
241 // check if platform expects lffs to be mounted on default drive
242 TInt lffsDrv = CheckLFFSDriveForPlatform();
243 if (lffsDrv == KInvalidDriveLetter)
245 test.Printf(_L("IsSessionDriveLFFS: platform does not support lffs.\r\n"));
253 TChar lffsCh; // lffs drv ltr
254 test((r = RFs::DriveToChar(lffsDrv, lffsCh)) == KErrNone);
257 test.Printf(_L("IsSessionDriveLFFS: cur drv = \'%c\', lffs drv = \'%c\'.\n"), (TText) curCh, (TText) lffsCh);
258 isLffs = ((TText) curCh) == ((TText) lffsCh);
264 GLDEF_C TBool IsDefaultDriveLFFS()
266 // Quick method of testing if running on LFFS for non t_main based tests.
269 // check if lffs mounted on default drive
275 r=fs.SessionPath(path);
278 r=TheFs.CharToDrive(path[0],drv);
281 isLffs=IsFileSystemLFFS(fs,drv);
286 // check if platform expects lffs to be mounted on default drive
287 TInt lffsDrv = CheckLFFSDriveForPlatform();
288 if (lffsDrv == KInvalidDriveLetter)
290 test.Printf(_L("IsCurrentDriveLFFS: platform does not support lffs.\r\n"));
298 TChar lffsCh; // lffs drv ltr
299 test((r = RFs::DriveToChar(lffsDrv, lffsCh)) == KErrNone);
302 test.Printf(_L("IsCurrentDriveLFFS: cur drv = \'%c\', lffs drv = \'%c\'.\n"), (TText) curCh, (TText) lffsCh);
303 isLffs = ((TText) curCh) == ((TText) lffsCh);
309 GLDEF_C TBool IsNamedDriveLFFS(RFs &aFsSession,TText aDrv)
311 // Quick method of testing if running on LFFS for non t_main based tests.
315 TInt r=RFs::CharToDrive(aDrv,d);
317 return(IsFileSystemLFFS(aFsSession,d));
320 GLDEF_C TInt GetLFFSControlModeSize()
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.
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++)
334 TInt r=localDrive.Connect(drvNum,dumBool);
335 if(r==KErrNotSupported)
336 continue; // Local drive not present
338 r=localDrive.Caps(capsPckg);
339 localDrive.Disconnect();
340 if(r==KErrNotSupported||r==KErrNotReady)
341 continue; // Local drive not available
343 if(capsPckg().iType==EMediaFlash)
345 lffsMediaFound=ETrue;
351 test.Printf(_L("GetLFFSControlModeSize: LFFS media not found !\n"));
354 return (capsPckg().iControlModeSize);