sl@0: // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // f32test\server\t_chlffs.cpp sl@0: // sl@0: // sl@0: sl@0: #define __E32TEST_EXTENSION__ sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: // Now non-t_main programs need to chk if they are running on lffs, sl@0: #include "t_server.h" sl@0: #include "t_chlffs.h" sl@0: sl@0: sl@0: const TInt KInvalidDriveLetter=-1; sl@0: sl@0: LOCAL_D TInt LFFSdriveNumber=KInvalidDriveLetter; sl@0: LOCAL_D TBool LFFSTesting=EFalse; sl@0: _LIT(KLFFSName,"Lffs"); sl@0: sl@0: sl@0: LOCAL_C void FormatLFFS(RFs &anFsSession,TDes &aDrive) sl@0: // sl@0: // Format the LFFS drive sl@0: // sl@0: { sl@0: RFormat format; sl@0: TInt count; sl@0: TInt r; sl@0: sl@0: test.Printf(_L("Format LFFS drive %S\r\n"), &aDrive); sl@0: r=format.Open(anFsSession,aDrive,EHighDensity,count); sl@0: test.Printf(_L("Format open done. Count = %d\r\n"), count); sl@0: test(r==KErrNone); sl@0: sl@0: while (count) sl@0: { sl@0: TInt r=format.Next(count); sl@0: test.Printf(_L("Format next done. Count = %d\r\n"), count); sl@0: test(r==KErrNone); sl@0: } sl@0: sl@0: format.Close(); sl@0: } sl@0: sl@0: GLDEF_C TBool IsFileSystemLFFS(RFs &aFsSession,TInt aDrive) sl@0: // sl@0: // return true if lffs on aDrive sl@0: // sl@0: { sl@0: TFileName f; sl@0: TInt r=aFsSession.FileSystemName(f,aDrive); sl@0: test(r==KErrNone || r==KErrNotFound); sl@0: return (f.CompareF(KLFFSName)==0); sl@0: } sl@0: sl@0: GLDEF_C TInt CheckLFFSDriveForPlatform() sl@0: // sl@0: // Check the LFFS drive number for the current platform sl@0: // sl@0: { sl@0: TInt lffsDrvNum; sl@0: sl@0: TInt uid; sl@0: TInt r=HAL::Get(HAL::EMachineUid,uid); sl@0: test(r==KErrNone); sl@0: sl@0: if (uid==HAL::EMachineUid_Brutus) sl@0: { sl@0: lffsDrvNum=EDriveK; sl@0: test.Printf(_L("Test is running on BRUTUS\r\n")); sl@0: } sl@0: else if (uid==HAL::EMachineUid_Win32Emulator) sl@0: { sl@0: lffsDrvNum=EDriveW; sl@0: test.Printf(_L("Test is running on WINS Pc\r\n")); sl@0: } sl@0: else if (uid == HAL::EMachineUid_Integrator) sl@0: { sl@0: lffsDrvNum=EDriveK; sl@0: test.Printf(_L("Test is running on INTEGRATOR\r\n")); sl@0: } sl@0: else if (uid == HAL::EMachineUid_Assabet) sl@0: { sl@0: lffsDrvNum=EDriveK; sl@0: test.Printf(_L("Test is running on Assabet\r\n")); sl@0: } sl@0: else sl@0: lffsDrvNum=KInvalidDriveLetter; sl@0: return(lffsDrvNum); sl@0: } sl@0: sl@0: GLDEF_C TBool CheckMountLFFS(RFs &anFsSession,TChar aDriveLetter) sl@0: // sl@0: // Check if test to be performed on LFFS drive. Mount the ELFFS.FSY if sl@0: // necessary sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Check if LFFS drive (Mount LFFS if required)")); sl@0: sl@0: TInt r,drvNum; sl@0: TBuf<4> lffsDriveLetter=_L("?:\\"); sl@0: sl@0: // first check if the lffs is mounted on the drive sl@0: r=anFsSession.CharToDrive(aDriveLetter,drvNum); sl@0: test(r==KErrNone); sl@0: if (IsFileSystemLFFS(anFsSession,drvNum)) sl@0: { sl@0: lffsDriveLetter[0]=(TText)aDriveLetter; sl@0: test.Printf(_L("Testing an LFFS drive (%S)"), &lffsDriveLetter); sl@0: test.Printf(_L("LFFS already mounted on drive %S\r\n"), &lffsDriveLetter); sl@0: LFFSdriveNumber=drvNum; sl@0: LFFSTesting=ETrue; sl@0: return(ETrue); sl@0: } sl@0: sl@0: // check if platform expects lffs to be mounted on specified drive sl@0: TInt lffsDrvNum=CheckLFFSDriveForPlatform(); sl@0: if (drvNum!=lffsDrvNum) sl@0: { sl@0: test.Printf(_L("Not testing an LFFS drive\n")); sl@0: return(EFalse); sl@0: } sl@0: sl@0: lffsDriveLetter[0]=(TText)aDriveLetter; sl@0: test.Printf(_L("Testing an LFFS drive (%S)"), &lffsDriveLetter); sl@0: LFFSdriveNumber=lffsDrvNum; sl@0: LFFSTesting=ETrue; sl@0: sl@0: test.Next(_L("Load device driver: MEDLFS")); sl@0: r=User::LoadPhysicalDevice(_L("MEDLFS")); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: sl@0: test.Next(_L("Add file system: ELFFS")); sl@0: r=anFsSession.AddFileSystem(_L("ELFFS")); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: sl@0: TFullName name; sl@0: r=anFsSession.FileSystemName(name,LFFSdriveNumber); sl@0: test(r==KErrNone || r==KErrNotFound); sl@0: sl@0: if (name.MatchF(_L("Lffs")) != 0) sl@0: { sl@0: // Some other file system is at the "Lffs" drive. sl@0: if (name.Length() != 0) sl@0: { sl@0: // Not allowed to dismount the file system from the drive associated sl@0: // with the default path - so temporarily change the default path. sl@0: test.Printf(_L("Dismounting %S on drive %S\r\n"), &name, &lffsDriveLetter); sl@0: r=anFsSession.DismountFileSystem(name,LFFSdriveNumber); sl@0: test(r==KErrNone); sl@0: sl@0: } sl@0: sl@0: test.Printf(_L("Mount LFFS on drive %S\r\n"),&lffsDriveLetter); sl@0: r=anFsSession.MountFileSystem(_L("Lffs"), LFFSdriveNumber); sl@0: test.Printf(_L(" Mount result %d\r\n"), r); sl@0: test(r==KErrNone || r==KErrCorrupt || r==KErrNotReady); sl@0: sl@0: if (r==KErrCorrupt) sl@0: { sl@0: test.Printf(_L("The volume was corrupt. Formatting...\r\n")); sl@0: FormatLFFS(anFsSession,lffsDriveLetter); sl@0: } sl@0: else if(r==KErrNotReady) sl@0: { sl@0: test.Printf(_L("The mount was not ready. Formatting...\r\n")); sl@0: FormatLFFS(anFsSession,lffsDriveLetter); sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("The volume was mounted OK. Formatting...\r\n")); sl@0: FormatLFFS(anFsSession,lffsDriveLetter); // ??? sl@0: } sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("LFFS already mounted on drive %S\r\n"), &lffsDriveLetter); sl@0: } sl@0: sl@0: return(ETrue); sl@0: } sl@0: sl@0: GLDEF_C TBool IsTestingLFFS() sl@0: // sl@0: // Return ETrue if testing LFFS sl@0: // sl@0: { sl@0: return(LFFSTesting); sl@0: } sl@0: sl@0: GLDEF_C void TestingLFFS(TBool aSetting) sl@0: // sl@0: // Set whether testing LFFS or not sl@0: // sl@0: { sl@0: LFFSTesting=aSetting; sl@0: } sl@0: sl@0: GLDEF_C TInt GetDriveLFFS() sl@0: // sl@0: // Return the LFFS drive number sl@0: // sl@0: { sl@0: return(LFFSdriveNumber); sl@0: } sl@0: sl@0: GLDEF_C TBool IsSessionDriveLFFS(RFs& aFs,TChar& aDriveLetter) sl@0: { sl@0: // sl@0: // Quick method of testing if session drive is LFFS sl@0: // sl@0: TBool isLffs; sl@0: TFileName path; sl@0: TInt r=aFs.SessionPath(path); sl@0: test(r==KErrNone); sl@0: TInt drv; sl@0: r=RFs::CharToDrive(path[0],drv); sl@0: test(r==KErrNone); sl@0: sl@0: aDriveLetter=path[0]; sl@0: isLffs=IsFileSystemLFFS(aFs,drv); sl@0: if(isLffs) sl@0: return(ETrue); sl@0: sl@0: // check if platform expects lffs to be mounted on default drive sl@0: TInt lffsDrv = CheckLFFSDriveForPlatform(); sl@0: if (lffsDrv == KInvalidDriveLetter) sl@0: { sl@0: test.Printf(_L("IsSessionDriveLFFS: platform does not support lffs.\r\n")); sl@0: isLffs = EFalse; sl@0: } sl@0: else sl@0: { sl@0: TChar curCh=path[0]; sl@0: curCh.LowerCase(); sl@0: sl@0: TChar lffsCh; // lffs drv ltr sl@0: test((r = RFs::DriveToChar(lffsDrv, lffsCh)) == KErrNone); sl@0: lffsCh.LowerCase(); sl@0: sl@0: test.Printf(_L("IsSessionDriveLFFS: cur drv = \'%c\', lffs drv = \'%c\'.\n"), (TText) curCh, (TText) lffsCh); sl@0: isLffs = ((TText) curCh) == ((TText) lffsCh); sl@0: } sl@0: sl@0: return(isLffs); sl@0: } sl@0: sl@0: GLDEF_C TBool IsDefaultDriveLFFS() sl@0: // sl@0: // Quick method of testing if running on LFFS for non t_main based tests. sl@0: // sl@0: { sl@0: // check if lffs mounted on default drive sl@0: TBool isLffs; sl@0: RFs fs; sl@0: TInt r=fs.Connect(); sl@0: test(r==KErrNone); sl@0: TFileName path; sl@0: r=fs.SessionPath(path); sl@0: test(r==KErrNone); sl@0: TInt drv; sl@0: r=TheFs.CharToDrive(path[0],drv); sl@0: test(r==KErrNone); sl@0: sl@0: isLffs=IsFileSystemLFFS(fs,drv); sl@0: fs.Close(); sl@0: if(isLffs) sl@0: return(ETrue); sl@0: sl@0: // check if platform expects lffs to be mounted on default drive sl@0: TInt lffsDrv = CheckLFFSDriveForPlatform(); sl@0: if (lffsDrv == KInvalidDriveLetter) sl@0: { sl@0: test.Printf(_L("IsCurrentDriveLFFS: platform does not support lffs.\r\n")); sl@0: isLffs = EFalse; sl@0: } sl@0: else sl@0: { sl@0: TChar curCh=path[0]; sl@0: curCh.LowerCase(); sl@0: sl@0: TChar lffsCh; // lffs drv ltr sl@0: test((r = RFs::DriveToChar(lffsDrv, lffsCh)) == KErrNone); sl@0: lffsCh.LowerCase(); sl@0: sl@0: test.Printf(_L("IsCurrentDriveLFFS: cur drv = \'%c\', lffs drv = \'%c\'.\n"), (TText) curCh, (TText) lffsCh); sl@0: isLffs = ((TText) curCh) == ((TText) lffsCh); sl@0: } sl@0: sl@0: return(isLffs); sl@0: } sl@0: sl@0: GLDEF_C TBool IsNamedDriveLFFS(RFs &aFsSession,TText aDrv) sl@0: // sl@0: // Quick method of testing if running on LFFS for non t_main based tests. sl@0: // sl@0: { sl@0: TInt d; sl@0: TInt r=RFs::CharToDrive(aDrv,d); sl@0: test(r==KErrNone); sl@0: return(IsFileSystemLFFS(aFsSession,d)); sl@0: } sl@0: sl@0: GLDEF_C TInt GetLFFSControlModeSize() sl@0: // sl@0: // For LFFS, the media may not exhibit a contiguous data region. This is the case if the sl@0: // Control Mode Size is non-zero. sl@0: // sl@0: { sl@0: TLocalDriveCapsV7 caps; // V7 to allow for devices exhibiting Control Mode sl@0: TPckg capsPckg(caps); sl@0: TBusLocalDrive localDrive; sl@0: TBool lffsMediaFound = EFalse; sl@0: TBool dumBool = EFalse; // Arbitrary if LFFS is mounted on non-removable media sl@0: // Loop to find the local drive for LFFS - this is always of type EMediaFlash sl@0: for(TInt drvNum=0; drvNum