Ejemplo n.º 1
0
void TestQuickFormat()
    {
    test.Start(_L("Test EQuickFormat"));
    TInt counter;
    RFormat format;

    TInt err = format.Open(fsSession, msDrive->GetSessionPath(), EQuickFormat, counter);
    test(err == KErrNone);
    while(counter)
        {
        err = format.Next(counter);
        test(err == KErrNone);
        }
    format.Close();
    DisplayVolumeInfo();
    test.End();
    }
Ejemplo n.º 2
0
GLDEF_C void Format(TInt aDrive)
//
// Format current drive
//
	{
	test.Next(_L("Format"));
	TBuf<4> driveBuf=_L("?:\\");
	driveBuf[0]=(TText)(aDrive+'A');
	RFormat format;
	TInt count;
	TInt r=format.Open(TheFs,driveBuf,EQuickFormat,count);
	test_KErrNone(r);
	while(count)
		{
		TInt r=format.Next(count);
		test_KErrNone(r);
		}
	format.Close();
	}
Ejemplo n.º 3
0
void TestFullFormat()
    {
    test.Start(_L("Test EFullFormat"));
    TInt counter;
    RFormat format;

    TInt err = format.Open(fsSession, msDrive->GetSessionPath(), EFullFormat, counter);
    test(err == KErrNone);
    while(counter)
        {
        test.Printf(_L("."));
        err = format.Next(counter);
        test(err == KErrNone);
        }
    test.Printf(_L("\n\r"));

    format.Close();
    DisplayVolumeInfo();
    test.End();
    }
Ejemplo n.º 4
0
LOCAL_C void DoFormat()
//
// Format the ramdisk
//
	{

	TInt count;
	RFormat format;
#if defined(__WINS__)
	TInt r=format.Open(TheFs,_L("Y:\\"),EHighDensity,count);
#else
	TInt r=format.Open(TheFs,_L("C:\\"),EHighDensity,count);
#endif
	test_KErrNone(r);
	while(count)
		{
		r=format.Next(count);
		test_KErrNone(r);
		}
	format.Close();
	}
Ejemplo n.º 5
0
/** Formats the drive 

	@param aDrive 	Drive to be formatted
*/
void Format(TInt aDrive)
	{

	test.Next(_L("Format"));
	TBuf<4> driveBuf = _L("?:\\");
	driveBuf[0] = (TText)(aDrive+'A');
	RFormat format;
	TInt count, prevcount = 0;
	TInt r = format.Open(TheFs, driveBuf, EQuickFormat, count);
	TESTERROR(r);
	
	while(count)
		{
		TInt r = format.Next(count);
        if(count != prevcount)
	        {
			test.Printf(_L("."));
			prevcount = count;
			}
		TESTERROR(r);
		}

	format.Close();
	}
void CTestUtilSessionSwi::ServiceL(const RMessage2& aMessage)
	{
	switch (aMessage.Function())
		{
		case ECopy:
			{
			HBufC* source = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,0);
			HBufC* destination = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,1);

			TInt err = Server().FileMan().Copy(*source, *destination, CFileMan::ERecurse | CFileMan::EOverWrite);
			if (err == KErrNone)
				{
				// Turn off the read only attributes
				TTime time(0); // must specify 0, or a valid time, otherwise sets time to a random value and causes -6/-21 errors
				err = Server().FileMan().Attribs(*destination, 0, KEntryAttReadOnly, time, CFileMan::ERecurse);
				}
			
			CleanupStack::PopAndDestroy(destination);
			CleanupStack::PopAndDestroy(source);

			aMessage.Complete(err);
			break;
			}
		case EMove:
			{
			HBufC* source = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,0);
			HBufC* destination = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,1);

			TInt err = Server().FS().Rename(*source,*destination);
			if (err == KErrNone)
				{
				// Turn off the read only attributes
				TTime time(0); // must specify 0, or a valid time, otherwise sets time to a random value and causes -6/-21 errors
				err = Server().FileMan().Attribs(*destination, 0, KEntryAttReadOnly, time, CFileMan::ERecurse);
				}
			
			CleanupStack::PopAndDestroy(destination);
			CleanupStack::PopAndDestroy(source);
			
			aMessage.Complete(err);
			break;
			}
		case EDelete:
			{
			HBufC* fileName = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,0);
			TEntry entry;
			TInt err = Server().FS().Entry(*fileName, entry);
			if (err == KErrNone)
				{
				if (entry.IsDir())
					{
					TPath pathName(*fileName);
					if (pathName[pathName.Length() - 1] != KPathDelimiter)
						{
						pathName.Append(KPathDelimiter);
						}
					err = Server().FileMan().RmDir(pathName);
					}
				else
					{
					err = Server().FS().Delete(*fileName);
					}
				}
			CleanupStack::PopAndDestroy(fileName);
			
			aMessage.Complete(err);
			break;
			}
		case ERmDir:
			{
			HBufC* fileName = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,0);
			TParsePtrC parsePtr(*fileName);
			if(parsePtr.IsRoot())
				{
				User::Leave(KErrAccessDenied);
				}
			TInt err = Server().FileMan().RmDir(*fileName);
			CleanupStack::PopAndDestroy(fileName);
			
			aMessage.Complete(err);
			break;
			}
		case EMkDirAll:
			{
			HBufC* fileName = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,0);
			TInt err = Server().FS().MkDirAll(*fileName);
			CleanupStack::PopAndDestroy(fileName);
			
			aMessage.Complete(err);
			break;
			}
		case EFileExists:
			{			
			delete iDetector;
			iDetector=CTestFileDetector::NewL(aMessage,
												Server().FS());			
			iDetector->DetectFile();
			break;
			}
		case ELock:
			{
			HBufC* fileName = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,0);
			RFile lockFile;
			TInt err = lockFile.Open(Server().FS(), *fileName, EFileWrite);
			if (err == KErrNone)
				iLockedFileHandles.Append(lockFile);

			CleanupStack::PopAndDestroy(fileName);			
			aMessage.Complete(err);
			break;
			}			
		case EUnlock:
			{
			HBufC* fileName = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,0);
			TInt err = KErrNotFound;
			TFileName lockedFileName;
			for (TInt i = 0; i < iLockedFileHandles.Count() && err;i++)
				{
				TInt err2 = iLockedFileHandles[i].FullName(lockedFileName);
				User::LeaveIfError(err2);
				if (lockedFileName.MatchF(*fileName) != KErrNotFound)
					{
					iLockedFileHandles[i].Close();
					iLockedFileHandles.Remove(i);
					err = KErrNone;
					}
				}
			CleanupStack::PopAndDestroy(fileName);			
			aMessage.Complete(err);
			break;
			}
			case EFormat:
			{
			TInt drive = aMessage.Int0();
			TBool formatFatOnly = aMessage.Int1();
			TChar aDriveChar;
			User::LeaveIfError(Server().FS().DriveToChar(drive, aDriveChar));
			TBuf<3> bfDrv;
			bfDrv.Append(aDriveChar);
			bfDrv.Append(KBP);
	
			RFormat format;
			TInt count;
			User::LeaveIfError(format.Open(Server().FS(), bfDrv, EHighDensity, count));
			CleanupClosePushL(format);
			
			if (formatFatOnly)
   				{
   				User::LeaveIfError(format.Next(count));
   				}
			else
				{
				while (count > 0)
					{
					User::LeaveIfError(format.Next(count));
					}
				}
				
			CleanupStack::PopAndDestroy(&format);
			aMessage.Complete(KErrNone);
			break;
			}
		case EMount:
			{
			TInt drive = aMessage.Int0();
			User::LeaveIfError(Server().FS().Connect());
			//Mount the drive synchronizely to make sure the drive is ready for the next operation
			User::LeaveIfError(Server().FS().MountFileSystem(KFAT, drive, ETrue));
			aMessage.Complete(KErrNone);
			break;
			}
		case EUnMount:
			{
			TInt drive = aMessage.Int0();
			TFileName fsName;
			User::LeaveIfError(Server().FS().FileSystemName(fsName, drive));
			User::LeaveIfError(Server().FS().DismountFileSystem(fsName, drive));
			aMessage.Complete(KErrNone);
			break;
			}
		case ESetReadOnly:
			{
			HBufC* fileName = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,0);
			TInt setReadOnly = aMessage.Int1();
			TUint setmask;
			TUint clearmask;
			if (setReadOnly)
				{
				// Setting read only attribute
				setmask = KEntryAttReadOnly;
				clearmask = 0;
				}
			else
				{
				// Clearing read only attribute
				setmask = 0;
				clearmask = KEntryAttReadOnly;				
				}
			
			// Turn off the read only attributes
			TTime time(0);
			TInt err = Server().FileMan().Attribs(*fileName, setmask, clearmask, time);
			CleanupStack::PopAndDestroy(fileName);			
			aMessage.Complete(err);
			break;
			}
		case EGetFileHandle:
			{
			HBufC* fileName = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,0); 
			RFile file;
			CleanupClosePushL(file);
			User::LeaveIfError(file.Open(Server().FS(), *fileName, EFileRead | EFileShareReadersOnly));
			User::LeaveIfError(file.TransferToClient(aMessage, 1));
			CleanupStack::PopAndDestroy(2, fileName); // file
			break;
			}
		case EWatchFile:
			{
			if (iFileWatcher)
				{
				if (iFileWatcher->IsActive())
					{
					aMessage.Complete(KErrServerBusy);
					break;
					}
				else
					{
					delete iFileWatcher;
					iFileWatcher = NULL;
					}
				}
			// Create a new file watcher for this session
			iFileWatcher = CFileWatcher::NewL(Server().FS(), aMessage);
			break;
			}
		case EWatchFileCancel:
			{
			if (iFileWatcher)
				{
				iFileWatcher->Cancel();
				aMessage.Complete(KErrNone);
				}
			else
				{
				// No file watch request to cancel!
				aMessage.Complete(KErrNotReady);
				}
			break;
			}
		case EGetNumFiles:
			{
			HBufC* dirPath = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,0);
			CDir* dirContents = NULL;
			
			User::LeaveIfError(Server().FS().GetDir(*dirPath, KEntryAttNormal, ESortNone, dirContents));
			TPckg<TInt> numFiles(dirContents->Count());
			
			delete dirContents;
			aMessage.WriteL(1, numFiles);
			aMessage.Complete(KErrNone);
			CleanupStack::PopAndDestroy(dirPath);
			break;
			}

	case ERegenerateCache:
			{
		#ifndef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
			Swi::RSisRegistryWritableSession session;
			User::LeaveIfError(session.Connect());
			CleanupClosePushL(session);
			session.RegenerateCacheL();
			CleanupStack::PopAndDestroy(&session);
			aMessage.Complete(KErrNone);
		#else
			aMessage.Complete(KErrNotSupported);
		#endif
			break;
			}
	    case EGetFileHash:
			{
			HBufC* fileNameA = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,0);
			CMessageDigest* digest = CalculateFileHashLC(*fileNameA);
			aMessage.WriteL(1, digest->Final());
			aMessage.Complete(KErrNone);
			CleanupStack::PopAndDestroy(2, fileNameA);
			break;
			}
		default:
			{
			PanicClient(aMessage,EPanicIllegalFunction);
			break;
			}
		}
	}
Ejemplo n.º 7
0
LOCAL_C void doComponentTest()
    //
    // Do the component test
    //
	{
#ifndef __NO_HEAP_CHECK
	__UHEAP_MARK;
#endif	

    TInt ret;
    test.Printf(_L("Start MountStart test. Be sure MMC card is inserted.\n"));
    // Parse the CommandLine argument: removal drive
    ParseCommandArguments();

    // Connect to the server
    LOG_AND_TEST(KErrNone,  fs.Connect());
	CleanupClosePushL(fs); 
	   
    // Convert drive letter to its numerical equivalent
	ret = fs.CharToDrive(driveLetter,removalDrvNo);
	LOG_AND_TEST(ret,  KErrNone);	

	// Load the logical device
	_LIT(KDriverFileName,"TESTUSBC.LDD");
	ret = User::LoadLogicalDevice(KDriverFileName);
	LOG_AND_TEST(KErrNone, ret);

    // Add MS file system
	_LIT(KMsFsFsy, "MSFS.FSY");
	LOG_AND_TEST(KErrNone, fs.AddFileSystem(KMsFsFsy));
	
    // Start Ms file system
    RUsbMassStorage usbMs;
    CleanupClosePushL(usbMs);

    TMassStorageConfig config;
    
    config.iVendorId.Copy(_L("vendorId"));
    config.iProductId.Copy(_L("productId"));
    config.iProductRev.Copy(_L("rev"));

	ret = usbMs.Connect();
    LOG_AND_TEST(KErrNone, ret);
  
    // Start usb mass storage device
    LOG_AND_TEST(KErrNone , usbMs.Start(config));

    // Format removable drive using FAT FS
    RFormat format;
    TBuf<2> removalDrive;
    removalDrive.Append(driveLetter);
    removalDrive.Append(':');
    TInt tracksRemaining;
    test.Printf(_L("Start MMC card formatting\n"));
    LOG_AND_TEST(KErrNone, format.Open(fs, removalDrive, EHighDensity|EQuickFormat, tracksRemaining));
    while (tracksRemaining)
        {
        test.Printf(_L("."));
        LOG_AND_TEST(KErrNone,  format.Next(tracksRemaining));
        }
    format.Close();
  	test.Printf(_L("\nDone!\n"));

    // Open a session to LDD
    test.Printf(_L("Open LDD\n"));
    LOG_AND_TEST(KErrNone, usbcClient.Open(0));

	test.Printf(_L("Creating CActiveScheduler\n"));
	CActiveScheduler* sched = new(ELeave) CActiveScheduler;
	CleanupStack::PushL(sched);
	CActiveScheduler::Install(sched);
  	
	// Create a state machine
	CStateMachine* sm = CStateMachine::NewL();
	CleanupStack::PushL(sm);
    sm->AddState(EUsbMsDriveState_Disconnected);
    sm->AddState(EUsbMsDriveState_Connecting);
    sm->AddState(EUsbMsDriveState_Connected);
    sm->AddState(EUsbMsDriveState_Disconnecting);
    sm->AddState(EUsbMsDriveState_Active);
    sm->AddState(EUsbMsDriveState_Locked);
    sm->AddState(EUsbMsState_Written);
    sm->AddState(EUsbMsState_Read);
    
    sm->SetInitState(EUsbMsDriveState_Disconnected);

  	CPropertyHandler* driveStatusHandler 	= CMsDriveStatusHandler::NewLC(removalDrvNo, *sm);
  	CPropertyHandler* readStatusHandler 	= CMsReadStatusHandler::NewLC(removalDrvNo, *sm);
  	CPropertyHandler* writtenStatusHandler 	= CMsWrittenStatusHandler::NewLC(removalDrvNo, *sm);
  	
 	CPropertyWatch::NewLC(EUsbMsDriveState_DriveStatus, *driveStatusHandler);
 	CPropertyWatch::NewLC(EUsbMsDriveState_KBytesRead, *readStatusHandler);
 	CPropertyWatch::NewLC(EUsbMsDriveState_KBytesWritten, *writtenStatusHandler);
 	
	CActiveScheduler::Start();

	ret = usbMs.Stop();
	test.Printf(_L("usbMs.Stop returned %d\n"), ret);
	test(ret == KErrNone);
	usbMs.Close();
	// 1 sec delay for MSFS to stop
	User::After(1000000);
	ret = fs.RemoveFileSystem(KMsFs);
	test(ret == KErrNone || ret == KErrNotFound);
	test.Printf(_L("RemoveFileSystem returned %d\n"), ret);

	usbcClient.Close();
	ret = User::FreeLogicalDevice(_L("USBC"));
	test.Printf(_L("FreeLogicalDevice returned %d\n"), ret);
	test(ret == KErrNone);			

	CleanupStack::PopAndDestroy(3);	// 3 CPropertyWatches 
	CleanupStack::PopAndDestroy(3);	// 3 property status change handlers
	CleanupStack::PopAndDestroy(sm);
	CleanupStack::PopAndDestroy(sched);
	CleanupStack::PopAndDestroy(&usbMs);
	CleanupStack::PopAndDestroy(&fs);

#ifndef __NO_HEAP_CHECK
	__UHEAP_MARKEND;
#endif
	}
Ejemplo n.º 8
0
LOCAL_C void DiskAdminTest()
//
//	test diskadministration capabilitiy
//
	{
	r=TheFs.FileSystemName(fsname,gTheDriveNum);
	test_KErrNone(r);
	r = DismountFileSystem(TheFs, fsname, gTheDriveNum);
	test_KErrNone(r);
//	r=TheFs.RemoveFileSystem(fsname);	//can not test due to bug else where fix exists
//	test_Value(r, r == KErrPermissionDenied);
//	r=TheFs.AddFileSystem(fsname);
//	test_Value(r, r == KErrPermissionDenied);
	r = MountFileSystem(TheFs, fsname, gTheDriveNum);
	test_KErrNone(r);
	r=TheFs.SetDriveName(gTheDriveNum,KDriveName);
	test_KErrNone(r);
	r=TheFs.SetVolumeLabel(KVolLable, gTheDriveNum);
	test_Value(r, r == KErrNone || r==KErrNotSupported);

	systemRFstest();
	resourceRFstest();
	privateRFstest();
	privateSIDRFstest();
	privateFalseIDRFstest();

	systemRFiletest();
	resourceRFiletest();
	privateRFiletest();
	privateSIDRFiletest();
	privatefalseIDRFiletest();

//disk changes to sys and pri paths should have completed these
	test(aStat4 == KRequestPending);
	TheFs.NotifyChangeCancel(aStat4);
	test(aStat4==KErrCancel);
	
	User::WaitForRequest(aStat3);
	test(aStat1==KErrPermissionDenied);
	test(aStat2==KErrPermissionDenied);
	test(aStat3==KErrNone);
	
	r=TheFs.SetSessionPath(systestname);
	test_Value(r, r == KErrPermissionDenied);
	
//Test RRawDisk class
	r=rawdisk.Open(TheFs,gTheDriveNum);
	test_Value(r, r == KErrPermissionDenied);
	rawdisk.Close();

	RDirtest();

#ifdef __WINS__
	if (User::UpperCase(driveBuf[0]) != 'C')
#endif
		{
		//Test RFormat class
		r=format.Open(TheFs,driveBuf,EHighDensity,count);
		test_KErrNone(r);

		while(count)
			{
			TInt r=format.Next(count);
			test_KErrNone(r);
			}
		format.Close();
		}

	driveBuf[0]=(TText)gDriveToTest;
	r=TheFs.ScanDrive(driveBuf);
	test_Value(r, r == KErrNone || r==KErrNotSupported);
	r=TheFs.CheckDisk(driveBuf);
	test_Value(r, r == KErrNone || r==KErrNotSupported);
	}