Esempio n. 1
0
LOCAL_C void Test2()
//
// Reproduce old bugs
//
	{

	test.Next(_L("Regression Protection"));
	RFile f1,f2;
//
	TInt r=f1.Replace(TheFs,_L("BIGFILE1.TST"),EFileWrite);
	test_KErrNone(r);
	r=f2.Replace(TheFs,_L("BIGFILE2.TST"),EFileWrite);
	test_KErrNone(r);
//
	WriteCluster(f1,0);
	WriteCluster(f1,1);
	WriteCluster(f1,2);
	WriteCluster(f1,3);
	WriteCluster(f1,4);
	WriteCluster(f1,5);
	WriteCluster(f2,0);
	WriteCluster(f1,6);
//
	SeekToCluster(f1,6);
	SeekToCluster(f1,4);
//
	f1.Close();
	f2.Close();
	r=TheFs.Delete(_L("BIGFile1.tst"));
	test_KErrNone(r);
	r=TheFs.Delete(_L("BIGFile2.tst"));
	test_KErrNone(r);
	CheckDisk();
	}
Esempio n. 2
0
GLDEF_C void CallTestsL(void)
//
// Test formatting
//
    {

	test.Title();
	test.Start(_L("Testing filesystem on default drive"));

	TChar driveLetter;
	if (IsSessionDriveLFFS(TheFs,driveLetter))
		{
		test.Printf(_L("CallTestsL: Skipped: test does not run on LFFS.\n"));
		return;
		}	

	DoTestsL();
	CheckDisk();

	test.End();
	test.Close();
	return;
    }
Esempio n. 3
0
LOCAL_C void Test1()
//
// Test openning a large file
//
	{

	test.Next(_L("Create interleaved files"));
	RFile f1,f2;
//
	TInt r=f1.Replace(TheFs,_L("BIGFILE1.TST"),EFileWrite);
	test_KErrNone(r);
	r=f2.Replace(TheFs,_L("BIGFILE2.TST"),EFileWrite);
	test_KErrNone(r);
//
	TInt maxListLength=4;
	TInt i=0,k=0;
	TInt countf1=0;
	TInt countf2=0;
	for (k=0;k<maxListLength;k++)
		{
		for (i=0;i<maxListLength;i++)
			{
			TInt j;
			for (j=0;j<=i;j++)
				WriteCluster(f1,countf1++);
			for (j=0;j<=k;j++)
				WriteCluster(f2,countf2++);
			test.Printf(_L("Written %d to file1 %d to file2\n"),i+1,k+1);
			}
		}

	ExhaustiveTest(f1,countf1);
	ExhaustiveTest(f2,countf2);

	SeekToCluster(f1,1,10);
	SeekToCluster(f1,6,3);
	SeekToCluster(f1,8,4);
	SeekToCluster(f1,12,3);
	SeekToCluster(f1,23,32);
	SeekToCluster(f1,5,8);
	SeekToCluster(f1,7,9);
	SeekToCluster(f1,12,1);
	SeekToCluster(f1,2,32);
	SeekToCluster(f1,16,8);
	SeekToCluster(f1,9,5);
	SeekToCluster(f1,33,6);
	SeekToCluster(f1,13,7);
	SeekToCluster(f1,9,17);
	SeekToCluster(f1,4,5);
	SeekToCluster(f1,5,31);
	SeekToCluster(f1,11,10);
	SeekToCluster(f1,1,2);
	SeekToCluster(f1,5,5);

	f1.Close();
	f2.Close();
	r=TheFs.Delete(_L("BIGFile1.tst"));
	test_KErrNone(r);
	r=TheFs.Delete(_L("BIGFile2.tst"));
	test_KErrNone(r);
	CheckDisk();
	}
int CDiskRepartition::CreatePrimaryPartition()
{
	DWORD ReadedBytes;
	LARGE_INTEGER oldunpart = _unpartitioned_space;
	PARTITION_INFORMATION_EX* tmppartition;
	CheckDisk();	
	//OpenDisk();
	_unpartitioned_space = oldunpart;
	_partitioned_space.QuadPart = _drive_space.QuadPart - _unpartitioned_space.QuadPart;
	_partitioned_space.QuadPart -= (5 * 1024 * 1024); // leave 5 mb gap 

	int _open_part_kb = _partitioned_space.QuadPart / 1024;
	WriteLog("CDiskRepartition: Part0 %d kb. Total %d kb", _open_part_kb, _drive_space.QuadPart / 1024);
	

	if ( _open_part_kb <=10 )
	{
		_partitioned_space.QuadPart = 32 * 1024; // Rohos Logon Key takes 25Kb
		_open_part_kb = _partitioned_space.QuadPart / 1024;
		WriteLog("CDiskRepartition: Part0 fix %d kb", _open_part_kb);
	}

	if (hDevice == INVALID_HANDLE_VALUE)
	{
		return false;
	}
	if (!DiskName)
	{
		return false;	
	}
	tmppartition = new PARTITION_INFORMATION_EX[4];
	LARGE_INTEGER maxoffset;
	maxoffset.QuadPart = 0;


	SetFilePointer(hDevice, 0, NULL, FILE_BEGIN);
	char buffer[512] = {'0'}; 
	DWORD bytewritten; 
	WriteFile(hDevice, buffer, 512, &bytewritten, NULL);

	DeviceIoControl((HANDLE) hDevice, IOCTL_DISK_GET_DRIVE_LAYOUT_EX, 
                          NULL, 0, (LPVOID) &driveinfo, (DWORD) 4096*16, (LPDWORD) &ReadedBytes, NULL); 
		for (int i = 0; i < 4; i++)
		{
			tmppartition[i].PartitionNumber = 0; 
			tmppartition[i].RewritePartition = 1; 
			tmppartition[i].StartingOffset.QuadPart = 0;
			tmppartition[i].PartitionLength.QuadPart = 0; 
			tmppartition[i].Mbr.BootIndicator = 0; 
			tmppartition[i].Mbr.RecognizedPartition = 0; 
			tmppartition[i].Mbr.HiddenSectors = 0; 
			tmppartition[i].Mbr.PartitionType = 0;
			tmppartition[i].PartitionStyle = (PARTITION_STYLE)0;		
		}
		driveinfo.PartitionStyle = PARTITION_STYLE_MBR;
		driveinfo.PartitionCount = 4;
		driveinfo.Mbr.Signature = 0xA4B57300;


	CopyMemory(&driveinfo.PartitionEntry[0],tmppartition,sizeof(PARTITION_INFORMATION_EX)*4);
	if (!DeviceIoControl(hDevice,IOCTL_DISK_SET_DRIVE_LAYOUT_EX, &driveinfo,sizeof(DRIVE_LAYOUT_INFORMATION_EX)+driveinfo.PartitionCount * sizeof(PARTITION_INFORMATION_EX), 
                        NULL,0,&ReadedBytes, (LPOVERLAPPED) NULL))
	{
		//log[0]<<"IOCTL_DISK_SET_DRIVE_LAYOUT_EX "<<GetLastError()<<endl<<flush;
		WriteLog(L"IOCTL_DISK_SET_DRIVE_LAYOUT_EX %d \n",GetLastError());
		return false;
	}
	if (!DeviceIoControl(hDevice,IOCTL_DISK_UPDATE_PROPERTIES, 0,0, 
                        NULL,0,&ReadedBytes, (LPOVERLAPPED) NULL))
	{
		WriteLog(L"IOCTL_DISK_UPDATE_PROPERTIES %d \n",GetLastError());
		//log[0]<<"IOCTL_DISK_UPDATE_PROPERTIES "<<GetLastError()<<endl<<flush;
		return false;
	}

	//////////CREATE NEW PARTITION
	DeviceIoControl((HANDLE) hDevice, IOCTL_DISK_GET_DRIVE_LAYOUT_EX, 
                          NULL, 0, (LPVOID) &driveinfo, (DWORD) 4096*16, (LPDWORD) &ReadedBytes, NULL); 
		tmppartition[0].PartitionNumber = 0; 
        tmppartition[0].RewritePartition = 1; 
		tmppartition[0].StartingOffset.QuadPart = 32256;
        tmppartition[0].PartitionLength.QuadPart = _partitioned_space.QuadPart; 
        tmppartition[0].Mbr.BootIndicator = 0; 
        tmppartition[0].Mbr.RecognizedPartition = 1; 
        tmppartition[0].Mbr.HiddenSectors = (DWORD)tmppartition[0].StartingOffset.QuadPart / 512; 
        tmppartition[0].Mbr.PartitionType = 7;
        tmppartition[0].PartitionStyle = (PARTITION_STYLE)0;
		for (int i = 1; i < 4; i++)
		{
			tmppartition[i].PartitionNumber = 0; 
			tmppartition[i].RewritePartition = 1; 
			tmppartition[i].StartingOffset.QuadPart = 0;
			tmppartition[i].PartitionLength.QuadPart = 0; 
			tmppartition[i].Mbr.BootIndicator = 0; 
			tmppartition[i].Mbr.RecognizedPartition = 0; 
			tmppartition[i].Mbr.HiddenSectors = 0; 
			tmppartition[i].Mbr.PartitionType = 0;
			tmppartition[i].PartitionStyle = (PARTITION_STYLE)0;		
		}
		driveinfo.PartitionStyle = PARTITION_STYLE_MBR;
		driveinfo.PartitionCount = 4;
		driveinfo.Mbr.Signature = 0xA4B57300;


	CopyMemory(&driveinfo.PartitionEntry[0],tmppartition,sizeof(PARTITION_INFORMATION_EX)*4);
	if (!DeviceIoControl(hDevice,IOCTL_DISK_SET_DRIVE_LAYOUT_EX, &driveinfo,sizeof(DRIVE_LAYOUT_INFORMATION_EX)+driveinfo.PartitionCount * sizeof(PARTITION_INFORMATION_EX), 
                        NULL,0,&ReadedBytes, (LPOVERLAPPED) NULL))
	{
		//log[0]<<"IOCTL_DISK_SET_DRIVE_LAYOUT_EX "<<GetLastError()<<endl<<flush;
		WriteLog(L"IOCTL_DISK_SET_DRIVE_LAYOUT_EX %d \n",GetLastError());
		return false;
	}
	if (!DeviceIoControl(hDevice,IOCTL_DISK_UPDATE_PROPERTIES, 0,0, 
                        NULL,0,&ReadedBytes, (LPOVERLAPPED) NULL))
	{
		WriteLog(L"IOCTL_DISK_UPDATE_PROPERTIES %d \n",GetLastError());
//		log[0]<<"IOCTL_DISK_UPDATE_PROPERTIES "<<GetLastError()<<endl<<flush;
		return false;
	}
	delete tmppartition;
	//CloseHandle(hDevice);

	return true;
}