// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
void CIpsPlgMessagePartStorerOperation::StoreTextHtmlPartL(
		CFSMailMessagePart* aPart)
	{
	User::LeaveIfNull(aPart);
	
	// Text buffer for html text content
	HBufC* data16 = aPart->GetLocalTextContentLC();

	// Convert from 16 to 8 bit data - data must exist until request is completed
	iDataBuffer = HBufC8::NewL((data16->Length() * 2) + 1);
	TPtr8 ptr8(iDataBuffer->Des());
	CnvUtfConverter::ConvertFromUnicodeToUtf8(ptr8, *data16);

	// Get text/html part file for write
	RFile file = aPart->GetContentFileL(ETrue);
	CleanupClosePushL(file);

    // if we don't do SetSize(0) characters from the original mail are left in the end of the mail
	// if the modified mail contains less characters.
	User::LeaveIfError( file.SetSize( 0 ) );

	// Write new content to text/html part file - async function
	file.Write( 0, *iDataBuffer, iDataBuffer->Length(), iStatus );
	
	CleanupStack::PopAndDestroy(2, data16);
	SetActive();
	}
// -----------------------------------------------------------------------
// CPreviouslyInstalledAppsCache::FlushToDiskL
// -----------------------------------------------------------------------
//  
void CPreviouslyInstalledAppsCache::FlushToDiskL()
	{
	// Write to disk
	RFile cacheFile;
	TInt err = cacheFile.Open(iFs, KPreInstalledApps, EFileStream|EFileWrite);
	if(err != KErrNone)
		{
			User::LeaveIfError(cacheFile.Create(iFs, KPreInstalledApps, EFileStream|EFileWrite));
		}
	CleanupClosePushL(cacheFile);

	// Truncate file.
	User::LeaveIfError(cacheFile.SetSize(0));
	
	// Now write the cache
	RFileWriteStream cacheWriteStream(cacheFile);
	cacheWriteStream.PushL();

	TInt32 count(iPrevPkgUids.Count());
	cacheWriteStream.WriteInt32L(count);

	for (TInt i = 0; i < count; i++)
		{
		cacheWriteStream.WriteInt32L(iPrevPkgUids[i].iUid);
		}	
	
	cacheWriteStream.CommitL();
	CleanupStack::PopAndDestroy(&cacheWriteStream);
	CleanupStack::PopAndDestroy(&cacheFile);
	}
예제 #3
0
void CWmDrmDataStore::InitializeDummyDbFileL( const TDesC& aFileName,
    RFile& aDummyDb, TBool& aConfiguredDrive )
    {
    TInt r( KErrNone );

    LOGFN( "CWmDrmDataStore::InitializeDummyDbFileL" );

    r = aDummyDb.Create( iServer->Fs(), aFileName, EFileWrite );
    if ( r == KErrAlreadyExists )
        {
        User::LeaveIfError(
            aDummyDb.Open( iServer->Fs(), aFileName, EFileWrite ) );
        }
    else if( !r )
        {
        TInt dataStoreSize( DataStoreSizeL( aConfiguredDrive ) );
        if ( aConfiguredDrive )
            {
            if ( dataStoreSize <= iDummyDbInitialSize2 )
                {
                User::LeaveIfError(
                    aDummyDb.SetSize( iDummyDbInitialSize2 - dataStoreSize ) );
                }
            else
                {
                User::LeaveIfError( aDummyDb.SetSize( 0 ) );
                }
            }
        else
            {
            if ( dataStoreSize <= iDummyDbInitialSize )
                {
                User::LeaveIfError(
                    aDummyDb.SetSize( iDummyDbInitialSize - dataStoreSize ) );
                }
            else
                {
                User::LeaveIfError( aDummyDb.SetSize( 0 ) );
                }
            }
        }
    else
        {
        User::Leave( r );
        }
    }
예제 #4
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
//
void CPixelMetricsMapperViewContainer::ShowL( const TDesC& aString, TBool& aLast, const TBool& aFileOutput )
    {
    MDesCArray* itemList = iListbox->Model()->ItemTextArray();
    CDesCArray* itemArray = ( CDesCArray* ) itemList;

    itemArray->AppendL( aString );

    iListbox->HandleItemAdditionL();
    iListbox->SetCurrentItemIndex( iCount );
    iCount++;
    if ( aLast )
        {
        if (aFileOutput)
            {
            RFile file;
            RFs& fs = CEikonEnv::Static()->FsSession();
            TFileName fileName =_L("Layout_");

            TRect screenRect;
            AknLayoutUtils::LayoutMetricsRect(
                AknLayoutUtils::EApplicationWindow,
                screenRect );

            // Add screen dimensions
            TInt height = screenRect.Height();
            TInt width = screenRect.Width();
            fileName.AppendNum(height);
            fileName.Append('_');
            fileName.AppendNum(width);

            fileName.Append(_L(".txt"));

            TInt err=file.Open(fs,fileName,EFileStreamText|EFileWrite|EFileShareAny);
            if (err==KErrNotFound) // file does not exist - create it
                err=file.Create(fs,fileName,EFileStreamText|EFileWrite|EFileShareAny);
            else
                file.SetSize(0); //sweep the file
            TFileText textFile;
            textFile.Set(file);
            err = textFile.Seek(ESeekStart);
            if (err) User::InfoPrint(_L("File corrupted"));

            // Finally loop through all the entries:
            TInt idx = 0;
            for(;idx!=itemList->MdcaCount();idx++)
                {
                err = textFile.Write(itemList->MdcaPoint(idx));
                if (err) User::InfoPrint(_L("File corrupted"));
                }
            file.Close();
            }
        DrawNow();
        }
    }
예제 #5
0
//Creates one or more large files with the total size near to the size of the available disk space.
//The idea is to cause  an "out of disk space" condition.
static void FillLargeDataFileL(RFile& aFile, TInt aSize)
	{
    TInt err = KErrDiskFull;
    while(err == KErrDiskFull)
        {
        err = aFile.SetSize(aSize);
        aSize -= 100;
        if(aSize <= 0)
            {
            break;
            }
        }
    TEST(err == KErrNone || err == KErrDiskFull);
	}
void CFileOperator::DoResizeL()
	{
	RFile file;
	TInt count = iFirstFile;

	while (count < iFirstFile + iNumFiles)
		{
		TFileName nextFile;
		FileNameGen(nextFile, count);
		file.Open(iFs, nextFile, EFileWrite);
		TInt size;
		file.Size(size);
		file.SetSize(size+10);
		file.Close();	
		count++;
		}
	}
예제 #7
0
LOCAL_C TInt CreateFileX(const TDesC& aBaseName,TInt aX, RFs iFs)
//
// Create a large file. Return KErrEof or KErrNone
//
	{

	TBuf<128> fileName=aBaseName;
	fileName.AppendNum(aX);
	RFile file;
	TInt r=file.Replace(iFs,fileName,EFileWrite);
	if (r==KErrDiskFull)
		return(r);
	if (r!=KErrNone)
		{
		test.Printf(_L("ERROR:: Replace returned %d\n"),r);
		return(KErrDiskFull);
		}
	r=file.SetSize(65536);
	if (r==KErrDiskFull)
		{
		file.Close();
		return(r);
		}
	if (r!=KErrNone)
		{
		test.Printf(_L("ERROR:: SetSize returned %d\n"),r);
		file.Close();
		return(KErrDiskFull);
		}
	file.Close();
//	r=iFs.CheckDisk(fileName);
//	if (r!=KErrNone && r!=KErrNotSupported)
//		{
//		test.Printf(_L("ERROR:: CheckDisk returned %d\n"),r);
//		test.Getch();
//		return(KErrDiskFull);
//		}
	test.Printf(_L("Created file %d size 64k\n"),aX);
	return(KErrNone);
	}
예제 #8
0
bool QFSFileEngine::setSize(qint64 size)
{
    Q_D(QFSFileEngine);
    bool ret = false;
    TInt err = KErrNone;
    if (d->symbianFile.SubSessionHandle()) {
        TInt err = d->symbianFile.SetSize(size);
        ret = (err == KErrNone);
        if (ret && d->symbianFilePos > size)
            d->symbianFilePos = size;
    }
    else if (d->fd != -1)
        ret = QT_FTRUNCATE(d->fd, size) == 0;
    else if (d->fh)
        ret = QT_FTRUNCATE(QT_FILENO(d->fh), size) == 0;
    else {
        RFile tmp;
        QString symbianFilename(d->fileEntry.nativeFilePath());
        err = tmp.Open(qt_s60GetRFs(), qt_QString2TPtrC(symbianFilename), EFileWrite);
        if (err == KErrNone)
        {
            err = tmp.SetSize(size);
            tmp.Close();
        }
        ret = (err == KErrNone);
    }
    if (!ret) {
        QSystemError error;
        if (err)
            error = QSystemError(err, QSystemError::NativeError);
        else
            error = QSystemError(errno, QSystemError::StandardLibraryError);
        setError(QFile::ResizeError, error.toString());
    }
    return ret;
}
예제 #9
0
파일: pm_mapperapp.cpp 프로젝트: mpvader/qt
void CPixelMetricsMapperAppUi::CreateHeaderFileL() const
    {
    // Open/create resulting file.
    RFile file;
    HBufC* layoutFile = HBufC::NewLC( KMaxFileName );
    *layoutFile = KLayoutSourceFileAndPath;
    TFileName fileName = *layoutFile;
    CleanupStack::PopAndDestroy(layoutFile);
    RFs& fs = CEikonEnv::Static()->FsSession();
    TInt error = file.Open(fs,fileName, EFileWrite|EFileShareAny|EFileStreamText );
    if (error==KErrNotFound)
        {
       file.Create(fs,fileName, EFileWrite|EFileShareAny|EFileStreamText);
        }
    CleanupClosePushL( file );
    file.SetSize( 0 );

    // Make all writes as from textfile.
    TFileText textFile;
    textFile.Set( file );
    textFile.Seek( ESeekStart );

    // Take all layout files from private folder.
    CDir* dirList;
    User::LeaveIfError(fs.GetDir(
        KPixelMetricsDataFiles,
        KEntryAttMaskSupported,
        ESortByName,
        dirList));

    TMySmallBuffer bufferLayoutHdr;
    TMyBigBuffer bufferPMData;
    TInt fileCount = dirList->Count();
    for (TInt i=0;i<fileCount;i++)
        {
        // open sourcefile
        RFile sourceFile;
        TFileName layoutFile = (*dirList)[i].iName;
        User::LeaveIfError( sourceFile.Open(
            fs,layoutFile, EFileRead|EFileShareAny|EFileStreamText ));
        CleanupClosePushL( sourceFile );

        // Make all reads as from textfile.
        TFileText textSourceFile;
        textSourceFile.Set( sourceFile );
        TFileName layoutName = CreateLayoutNameL( textSourceFile );

        // rewind - just in case.
        textSourceFile.Seek( ESeekStart );
        TFileName oneline;
        bufferLayoutHdr.Append(KOpenBrace);
        bufferPMData.Append(KOpenBrace);
        TInt loop = 0;
        FOREVER
            {
            if( textSourceFile.Read(oneline) != KErrNone )
                {
                break;
                }
            // Add commas for all but first line
            if (loop != 0)
                {
                if ( loop <= KHeaderValues-1)
                    {
                    bufferLayoutHdr.Append(KComma);
                    }
                else
                    {
                    if (loop != KHeaderValues)
                        {
                        bufferPMData.Append(KComma);
                        }
                    }
                if (loop==KHeaderValues)
                    {
                    bufferLayoutHdr.Append(_L(",QLatin1String(\""));
                    bufferLayoutHdr.Append(layoutName);
                    bufferLayoutHdr.Append(_L("\")"));
                    }
                }
            // Remove pixel metrics name and ":"
            oneline = oneline.Mid(oneline.Find(KColon)+1);
            // Remove tab
            oneline = oneline.Mid(oneline.Find(KTab)+1);
            // remove crap from the end of line
            TLex lex(oneline);
            TInt nextValue = -666;
            User::LeaveIfError( lex.Val(nextValue) );
            if ( loop <= KHeaderValues-1)
                {
                bufferLayoutHdr.AppendNum(nextValue);
                }
            else
                {
                if (nextValue == -909)
                    bufferPMData.Append(_L("ECommonStyleValue"));
                else
                    bufferPMData.AppendNum(nextValue);
                }
            oneline.Zero();
            loop++;
            }
        file.Flush();
        bufferLayoutHdr.Append(KEndBraceWithCommaAndCRLF);
        bufferPMData.Append(KEndBraceWithCommaAndCRLF);
        CleanupStack::PopAndDestroy(); //sourceFile
        }

    if (fileCount > 0)
        {
        bufferLayoutHdr = bufferLayoutHdr.Left(bufferLayoutHdr.Length()-2);
        bufferPMData = bufferPMData.Left(bufferPMData.Length()-2);
        textFile.Write(bufferLayoutHdr);
        textFile.Write(KCRLF);
        textFile.Write(bufferPMData);
        }
    delete dirList;

    CleanupStack::PopAndDestroy(); //file
    }
예제 #10
0
LOCAL_C void Test4()
//
// Test uid's can be read when the file is open
//
//	EFileShareExclusive,EFileShareReadersOnly,EFileShareAny,
//	EFileStream=0,EFileStreamText=0x100,
//	EFileRead=0,EFileWrite=0x200
//
	{

	test.Next(_L("Uids can be read if the file is open"));
	RFile f;
	TEntry entry;
	TInt r=f.Open(TheFs,_L("UIDCHK.DAT"),EFileShareExclusive|EFileRead);
	test_KErrNone(r);
	r=TheFs.Entry(_L("UIDCHK.DAT"),entry);
	test_KErrNone(r);
	test(entry.iName==_L("UIDCHK.DAT"));
	test(entry.IsTypeValid());
	test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T'));
	f.Close();

	r=f.Open(TheFs,_L("UIDCHK.DAT"),EFileShareExclusive|EFileWrite);
	test_KErrNone(r);
	r=TheFs.Entry(_L("UIDCHK.DAT"),entry);
	test_KErrNone(r);
	test(entry.iName==_L("UIDCHK.DAT"));
	test(entry.IsTypeValid());
	test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T'));

	r=f.SetSize(256);
	test_KErrNone(r);
	TBuf8<16> des;
	r=TheFs.ReadFileSection(_L("UIDCHK.DAT"),0,des,16);
	test_KErrNone(r);

	f.Close();

	r=f.Open(TheFs,_L("UIDCHK.DAT"),EFileShareReadersOnly|EFileRead);
	test_KErrNone(r);
	r=TheFs.Entry(_L("UIDCHK.DAT"),entry);
	test_KErrNone(r);
	test(entry.iName==_L("UIDCHK.DAT"));
	test(entry.IsTypeValid());
	test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T'));
	f.Close();

//	EFileShareReadersOnly|EFileWrite is illegal

	r=f.Open(TheFs,_L("UIDCHK.DAT"),EFileShareAny|EFileRead);
	test_KErrNone(r);
	r=TheFs.Entry(_L("UIDCHK.DAT"),entry);
	test_KErrNone(r);
	test(entry.iName==_L("UIDCHK.DAT"));
	test(entry.IsTypeValid());
	test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T'));
	f.Close();

	r=f.Open(TheFs,_L("UIDCHK.DAT"),EFileShareAny|EFileWrite);
	test_KErrNone(r);

	RFile secondFile;
	r=secondFile.Open(TheFs,_L("UIDCHK.DAT"),EFileShareAny|EFileWrite);
	test_KErrNone(r);

	RFile thirdFile;
	r=thirdFile.Open(TheFs,_L("UIDCHK.DAT"),EFileShareAny|EFileRead);
	test_KErrNone(r);

	r=TheFs.Entry(_L("UIDCHK.DAT"),entry);
	test_KErrNone(r);
	test(entry.iName==_L("UIDCHK.DAT"));
	test(entry.IsTypeValid());
	test(entry.iType[0]==TUid::Uid('D') && entry.iType[1]==TUid::Uid('A') && entry.iType[2]==TUid::Uid('T'));
	f.Close();
	secondFile.Close();
	thirdFile.Close();

	r=f.Open(TheFs,_L("UIDWINS.PE"),EFileShareAny|EFileWrite);
	test_KErrNone(r);

	r=TheFs.Entry(_L("UIDWINS.PE"),entry);
	test_KErrNone(r);
	test(entry.iName==_L("UIDWINS.PE"));
#if defined(__WINS__)
	TFileName sessionPath;
	TheFs.SessionPath(sessionPath);
	if (sessionPath[0]!='C')
		test(entry.IsTypeValid()==EFalse);
	else
		{
		test(entry.IsTypeValid());
		test(entry.iType[0]==TUid::Uid(0x1000007a) && entry.iType[1]==TUid::Uid(2) && entry.iType[2]==TUid::Uid(3));
		}
#else
	test(entry.IsTypeValid()==EFalse);
#endif
	f.Close();
	}
예제 #11
0
LOCAL_C void CreateTestFiles()
//
// Create files with uids for testing
//
	{

	test.Next(_L("Create test files"));
	TInt r=TheFs.MkDir(_L("\\F32-TST\\"));
	test_Value(r, r == KErrNone || r==KErrAlreadyExists);

	RFile file;

//	Create \\gSessionPath\\UIDCHK.BLG - with uid no data
	r=file.Replace(TheFs,_L("\\F32-TST\\UIDCHK.BLG"),EFileRead|EFileWrite);
	test_KErrNone(r);
	TUidType uidType(TUid::Uid('U'),TUid::Uid('I'),TUid::Uid('D'));
	TCheckedUid checkedUid(uidType);
	TPtrC8 buf((TUint8*)&checkedUid,sizeof(TCheckedUid));
	r=file.Write(buf);
	test_KErrNone(r);
	file.Close();

//	Create \\gSessionPath\\UIDCHK.MSG - with uid and data
	r=file.Replace(TheFs,_L("\\F32-TST\\UIDCHK.MSG"),EFileRead|EFileWrite);
	test_KErrNone(r);
	TUidType uidType2(TUid::Uid('X'),TUid::Uid('Y'),TUid::Uid('Z'));
	checkedUid.Set(uidType2);
	buf.Set((TUint8*)&checkedUid,sizeof(TCheckedUid));
	r=file.Write(buf);
	test_KErrNone(r);
	r=file.Write(_L8("More file data"));
	test_KErrNone(r);
	file.Close();
	
//	Create \\gSessionPath\\UIDCHK.DAT - uid stored only in the file
	r=file.Replace(TheFs,_L("\\F32-TST\\UIDCHK.DAT"),EFileRead|EFileWrite);
	test_KErrNone(r);
	TUidType uidType3(TUid::Uid('D'),TUid::Uid('A'),TUid::Uid('T'));
	checkedUid.Set(uidType3);
	buf.Set((TUint8*)&checkedUid,sizeof(TCheckedUid));
	r=file.Write(buf);
	test_KErrNone(r);
	r=file.Write(_L8("More file data"));
	test_KErrNone(r);
	file.Close();

//	Make a few random files - these will be deleted before the test begins
//	but are necessary to try to split file ReadFileSection into non-contiguous clusters
	
	r=file.Replace(TheFs,_L("\\F32-TST\\Temp1.txt"),EFileRead|EFileWrite);
	test_KErrNone(r);
	file.SetSize(550);
	file.Close();

	r=file.Replace(TheFs,_L("\\F32-TST\\Temp2.txt"),EFileRead|EFileWrite);
	test_KErrNone(r);
	file.SetSize(256);
	file.Close();

	r=file.Replace(TheFs,_L("\\F32-TST\\Temp3.txt"),EFileRead|EFileWrite);
	test_KErrNone(r);
	file.SetSize(256);
	file.Close();
	
	r=file.Replace(TheFs,_L("\\F32-TST\\Temp4.txt"),EFileRead|EFileWrite);
	test_KErrNone(r);
	file.SetSize(550);
	file.Close();
	
	r=file.Replace(TheFs,_L("\\F32-TST\\Temp5.txt"),EFileRead|EFileWrite);
	test_KErrNone(r);
	file.SetSize(256);
	file.Close();

	r=file.Replace(TheFs,_L("\\F32-TST\\Temp6.txt"),EFileRead|EFileWrite);
	test_KErrNone(r);
	file.SetSize(256);
	file.Close();

	r=file.Replace(TheFs,_L("\\F32-TST\\Temp7.txt"),EFileRead|EFileWrite);
	test_KErrNone(r);
	file.SetSize(256);
	file.Close();

	r=file.Replace(TheFs,_L("\\F32-TST\\Temp8.txt"),EFileRead|EFileWrite);
	test_KErrNone(r);
	file.SetSize(256);
	file.Close();

	r=file.Replace(TheFs,_L("\\F32-TST\\Temp9.txt"),EFileRead|EFileWrite);
	test_KErrNone(r);
	file.SetSize(256);
	file.Close();

	r=file.Replace(TheFs,_L("\\F32-TST\\Temp10.txt"),EFileRead|EFileWrite);
	test_KErrNone(r);
	file.SetSize(256);
	file.Close();

	TheFs.Delete(_L("\\F32-TST\\Temp2.txt"));
	TheFs.Delete(_L("\\F32-TST\\Temp4.txt"));
	TheFs.Delete(_L("\\F32-TST\\Temp6.txt"));
	TheFs.Delete(_L("\\F32-TST\\Temp8.txt"));
	TheFs.Delete(_L("\\F32-TST\\Temp10.txt"));
	
	r=file.Replace(TheFs,_L("\\F32-TST\\ReadFileSection1.txt"),EFileRead|EFileWrite);
	test_KErrNone(r);

//	Write 5000 bytes of nonsense
	
	TInt i=0;
	for ( ; i<100; i++)
		{
		r=file.Write(alphaPtr);
		test_KErrNone(r);
		r=file.Write(numberPtr);
		test_KErrNone(r);
		r=file.Write(humptyPtr);
		test_KErrNone(r);
		}
	
	file.Close();

	TheFs.Delete(_L("\\F32-TST\\Temp1.txt"));
	TheFs.Delete(_L("\\F32-TST\\Temp3.txt"));
	TheFs.Delete(_L("\\F32-TST\\Temp5.txt"));
	TheFs.Delete(_L("\\F32-TST\\Temp7.txt"));
	TheFs.Delete(_L("\\F32-TST\\Temp9.txt"));
	}
예제 #12
0
void CCmdYmodem::DoRunL()
	{
	PrepareConsoleToTransferL();

	if (iMode == EReceive)
		{
		TPtrC receiveDir;
		if (iFileNames.Count() > 1)
			{
			PrintError(KErrArgument, _L("Too many arguments - only the receive directory may be specified in receive mode."));
			User::Leave(KErrArgument);
			}
		else if (iFileNames.Count() == 1)
			{
			TFileName2 fileName(iFileNames[0]);
			receiveDir.Set(iFileNames[0]);

			if ((fileName.Exists(FsL()) && !fileName.IsDirL(FsL())) || (!fileName.Exists(FsL()) && !iOverwrite))
				{
				LeaveIfErr(KErrArgument, _L("\"%S\" is not a directory"), &fileName);
				}
			}
		else
			{
			receiveDir.Set(Env().Pwd());
			}

		Progress(_L("YMODEM receive to \"%S\"\r\n"), &receiveDir);
		RArray<TFileName2> receivedFiles;
		CleanupClosePushL(receivedFiles);
		TFailedFile failedFile;
		TBool finished(EFalse);
		while (!finished)
			{
			TSyncResult syncResult = SendSyncL();
			if (syncResult == EEot)
				{
				finished = ETrue;
				}
			else
				{
				iPacketNumber = 0;
				TBool isFinalBlock(EFalse);
				TPtrC block(ReceiveBlockL(ETrue, isFinalBlock));
				TPtrC fileName(block.Ptr()); // filename is the first null terminated string in the block.
				if (fileName.Length() > 0)
					{
					TFileName2 fileName2(fileName);
					fileName2.MakeAbsoluteL(receiveDir);
					TLex lex(block.Mid(fileName.Length() + 1));
					TInt size;
					User::LeaveIfError(lex.Val(size));
					TInt err = KErrNone;
					if (!iOverwrite && fileName2.Exists(FsL()))
						{
						err = KErrAlreadyExists;
						}
					RFile file;
					if (err == KErrNone)
						{
						if (size == 0)
							{
							if (iOverwrite)
								{
								err = file.Replace(FsL(), fileName2, EFileWrite);
								}
							else
								{
								err = file.Create(FsL(), fileName2, EFileWrite);
								}
							}
						else
							{
							Progress(_L("Starting receive of \"%S\" (%d bytes)\r\n"), &fileName, size);
							SendSyncL();
							TRAP(err, ReceiveToFileL(fileName2));
							if (err == KErrNone)
								{
								err = file.Open(FsL(), fileName2, EFileWrite);
								if (err == KErrNone)
									{
									err = file.SetSize(size);
									}
								}
							else
								{
								Fs().Delete(fileName2);
								}
							}
						}
					else
						{
						TRAP_IGNORE(ReceiveToNullL());
						}
					file.Close();
					if (err)
						{
						failedFile.iError = err;
						failedFile.iFileName = fileName2;
						finished = ETrue;
						}
					else
						{
						receivedFiles.Append(fileName2); // Ignore error.
						}
					}
				else
					{
					finished = ETrue;
					}
				}
			}

		CleanupClonsoleAfterTransferL();

		const TInt numFilesReceived = receivedFiles.Count();
		if (numFilesReceived == 0)
			{
			if (failedFile.iError == KErrNone)
				{
				Printf(_L("No files to receive.\r\n"));
				}
			}
		else if (numFilesReceived == 1)
			{
			const TFileName2& fileName = receivedFiles[0];
			Printf(_L("Successfully received \"%S\".\r\n"), &fileName);
			}
		else
			{
			Printf(_L("Successfully received:\r\n"));
			for (TInt i = 0; i < numFilesReceived; ++i)
				{
				const TFileName2& fileName = receivedFiles[i];
				Printf(_L("\t\"%S\"\r\n"), &fileName);
				}
			}

		if (failedFile.iError)
			{
			PrintError(failedFile.iError, _L("Failed to receive \"%S\""), &failedFile.iFileName);
			}
		CleanupStack::PopAndDestroy(&receivedFiles);
		}
	else if (iMode == ESend)
		{
		const TInt numFiles = iFileNames.Count();
		if (numFiles == 0)
			{
			PrintError(KErrArgument, _L("No files to send specified"));
			User::Leave(KErrArgument);
			}
		for (TInt i = 0; i < numFiles; ++i)
			{
			const TFileName2& fileName = iFileNames[i];
			if (fileName.Exists(FsL()))
				{
				if (fileName.IsDirL(FsL()))
					{
					LeaveIfErr(KErrArgument, _L("\"%S\" is not a file"), &fileName);
					}
				}
			else
				{
				LeaveIfErr(KErrArgument, _L("\"%S\" does not exist"), &fileName);
				}
			}
		WaitForSyncL();
		HBufC* buf = HBufC::NewLC(iBlockSize);
		TPtr bufPtr(buf->Des());
		for (TInt i = 0; i < numFiles; ++i)
			{
			const TFileName2& fileName = iFileNames[i];
			LeaveIfFileNotFound(fileName);
			TEntry entry;
			User::LeaveIfError(FsL().Entry(fileName, entry));
			bufPtr.SetLength(bufPtr.MaxLength());
			bufPtr.FillZ();
			bufPtr.Copy(fileName.NameAndExt());
			bufPtr.SetLength(buf->Length() + 1); // To leave a terminating null after the file name.
			bufPtr.AppendNum(entry.iSize);
			if (bufPtr.Length() < iBlockSize)
				{
				// There's not enough data to fill this block, so pad with NULL.
				bufPtr.AppendFill(0, iBlockSize - bufPtr.Length());
				}
			iPacketNumber = 0;
			SendBlockL(*buf);
			WaitForSyncL();
			SendFileL(fileName);
			}
		iPacketNumber = 0;
		bufPtr.SetLength(bufPtr.MaxLength());
		bufPtr.FillZ();
		SendBlockL(*buf);
		CleanupStack::PopAndDestroy(buf);
		CleanupClonsoleAfterTransferL();

		if (numFiles == 1)
			{
			Printf(_L("Successfully sent \"%S\".\r\n"), &iFileNames[0]);
			}
		else
			{
			Printf(_L("Successfully sent:\r\n"));
			for (TInt i = 0; i < numFiles; ++i)
				{
				const TFileName2& fileName = iFileNames[i];
				Printf(_L("\t\"%S\"\r\n"), &fileName);
				}
			}
		}
	User::LeaveIfError(Stdin().CancelCaptureAllKeys());
	}
예제 #13
0
static void DoTestFileWrite(TInt aBlockSize, TInt aFileSize = KMaxFileSize, TBool aUpdate = EFalse)
//
// Do Write benchmark
//
{
    DataBuf.SetLength(aBlockSize);
    const TInt maxWriteCount = aFileSize / aBlockSize;

    TFileName testDir(_L("?:\\F32-TST\\"));
    testDir[0] = (TText) gDriveToTest;
    TInt r = TheFs.MkDir(testDir);
    test_Value(r, r == KErrNone || r == KErrAlreadyExists);

    TFileName fileName;
    r = File.Temp(TheFs, testDir, fileName, EFileWrite | (gFileSequentialModeOn ? EFileSequential : 0)
                  | (gWriteCachingOn ? EFileWriteBuffered : EFileWriteDirectIO));
    test_KErrNone(r);

    if (aUpdate)
    {
        TInt r = File.SetSize(aFileSize);
        test_KErrNone(r);
    }

    TUint functionCalls = 0;

    TTime startTime;
    TTime endTime;
    TUint initTicks = 0;
    TUint finalTicks = 0;


    // we stop after the entire file has been written or after 10 seconds, whichever happens sooner
    RTimer timer;
    timer.CreateLocal();
    TRequestStatus reqStat;

    TInt pos = 0;
    File.Seek(ESeekStart, pos);

    timer.After(reqStat, 10000000); // After 10 secs

    startTime.HomeTime();
    initTicks = User::FastCounter();

    for (TInt i = 0 ; i<maxWriteCount && reqStat==KRequestPending; i++)
    {
        File.Write(pos, DataBuf, aBlockSize);

        pos += aBlockSize;
        if (pos > KMaxFileSize-aBlockSize)
            pos = 0;

        functionCalls++;
    }

    if (gFlushAfterWrite)
    {
        r = File.Flush();
        test_KErrNone(r)
    }

    // write file once only
    finalTicks = User::FastCounter();
    endTime.HomeTime();
//	TTimeIntervalMicroSeconds duration = endTime.MicroSecondsFrom(startTime);
    TTimeIntervalMicroSeconds duration = TInt64(finalTicks - initTicks) * TInt64(1000000) / TInt64(gFastCounterFreq) ;

    TInt dataTransferred = functionCalls * aBlockSize;
    TReal transferRate =
        TReal32(dataTransferred) /
        TReal(duration.Int64()) * TReal(1000000) / TReal(K1K); // KB/s
    test.Printf(_L("Write %7d bytes in %7d byte blocks:\t%11.3f KBytes/s (%d microsecs)\n"),
                dataTransferred, aBlockSize, transferRate, endTime.MicroSecondsFrom(startTime).Int64());

    timer.Close();

    File.Close();
    r = TheFs.Delete(fileName);
    test_KErrNone(r)

    return;
}
예제 #14
0
// -----------------------------------------------------------------------------
// CSdDisk::FillDisk()
// Fills the diskspace 
// 
// -----------------------------------------------------------------------------
void CSdDisk::FillDisk(RFs& aFs, TInt& aFreeDiskSpaceToLeave)
    {
	RFile iEaterFile;
	TInt fileSize(0);	
	TInt err(KErrNone);
	
	TReal64 diskFree = CheckDiskSpace(aFs);
	// RDebug::Print(_L("Shareddatatest ## Eat disk space") );
	
	// For loop to create eaterfiles
	for ( TInt i = 0 ; diskFree != 0 ; i++ )
	    {	
		TBuf16<30> str;
		str.Copy(KFileName);
		str.AppendNum(i,EDecimal);
			
		// RDebug::Print(_L("Shareddatatest ## Open file %s"), &str);
	
		err = iEaterFile.Open( aFs, str, EFileShareAny | EFileWrite );

		if ( err == KErrNotFound )	// file does not exist - create it
		    {
			err = iEaterFile.Create( aFs, str, EFileShareAny | EFileWrite );
		    }

		if ( err == KErrNone )
		    {
			// Create maximum size eaterfile if there is more disk space available than the maximum file size
			if ( diskFree > TReal64(KMaxTInt) )
			    {
				// RDebug::Print( _L("Shareddatatest ## Creating %d. EaterFile"), i+1);
				err = iEaterFile.SetSize( KMaxTInt );
				
				diskFree = diskFree - TReal64(KMaxTInt);
			    }
			
			// ... And if available disk space is less than maximum file size
			else
			    {
				// If aFreeDiskSpaceToLeave parameter says we have to leave some free disk
				if ( aFreeDiskSpaceToLeave != 0 )
				    {
					// RDebug::Print( _L("Shareddatatest ## Creating %d. EaterFile"), i+1);
					TInt sizeToSet = STATIC_CAST(TInt, I64INT(diskFree));
					err = iEaterFile.SetSize( sizeToSet - aFreeDiskSpaceToLeave * 1024 );
					iEaterFile.Size( fileSize );
					// RDebug::Print( _L("Shareddatatest ## Last EaterFileSize: %d"), fileSize);
					diskFree = 0;	
				    }
				
				// Otherwise try to eat all the disk space
				else
				    {
					// RDebug::Print( _L("Shareddatatest ## Creating %d. EaterFile"), i+1);
					TInt sizeToSet = STATIC_CAST(TInt, I64INT(diskFree));
					// RDebug::Print( _L("Shareddatatest ## Filesize in the end should be around %d bytes"), sizeToSet);
					
					for ( TInt j = 64 ; err != KErrDiskFull ; j-- )
					    {	
						err = iEaterFile.SetSize( sizeToSet - j * 1024 );
					    }
					iEaterFile.Size( fileSize );
					// RDebug::Print( _L("Shareddatatest ## Last EaterFileSize: %d bytes"), fileSize);
					// RDebug::Print( _L("Shareddatatest ## There should be %d bytes of free disk"),sizeToSet - fileSize);
					diskFree = 0;
				    }
			    }
		    }
		
		else
		    {
			RDebug::Print(_L("Shareddatatest ## Error = %d"), err);
			diskFree = 0;
		    }

		// RDebug::Print(_L("Shareddatatest ## Close file"));
		iEaterFile.Close();
	    }
    }
/**
  Function		: ExecuteActionL
  Description	: Entry point for the this test action in the test framework
  @internalTechnology
  @param		: none
  @return		: void
  @pre none 
  @post none
*/
void CMtfTestActionSetDiskSpace::ExecuteActionL()
	{
	TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionSetDiskSpace );
	
	RFs fs;
	User::LeaveIfError(fs.Connect());

	TInt newFreeValue = ObtainValueParameterL<TInt>(TestCase(),ActionParameters().Parameter(0));

	TestCase().INFO_PRINTF2(_L("Setting Drive C free disk space to %ld bytes."), newFreeValue);

	//
	// Check the current disk space available level...
	//
	TVolumeInfo  volumeInfo;
	
	User::LeaveIfError(fs.Volume(volumeInfo, EDriveC));
	TestCase().INFO_PRINTF2(_L("  Drive C currently has %ld bytes free."), volumeInfo.iFree);

	//
	// Check that this is possible...
	//	
	if (volumeInfo.iFree < newFreeValue)
		{
		TestCase().INFO_PRINTF1(_L("  Drive C already has too little free space!"));
		User::Leave(KErrArgument);
		}

	//
	// Ensure the temporary directory exists...
	//
	TInt ret;
	
	ret = fs.MkDir(KTempDiskSpaceDirName);
	if (ret != KErrNone  &&  ret != KErrAlreadyExists)
		{
		User::Leave(ret);
		}

	//
	// Work out how many files to create and their sizes. A full temp file is
	// 1GB in size, the last temp file will handle the remainder. Then loop
	// through and create them all...
	//
	TInt64  maxSizeOfTempFile  = (1024*1024*1024); 
	TInt64  diskSpaceToReserve = volumeInfo.iFree - newFreeValue;
	TInt64  numOfFullTempFiles = (diskSpaceToReserve / maxSizeOfTempFile);
	TInt64  lastTempFileSize   = (diskSpaceToReserve % maxSizeOfTempFile);
	TBuf<32>  tempFileName;
	RFile  file;

	for(TInt fileNum = 1;  fileNum <= numOfFullTempFiles;  fileNum++)
		{
		tempFileName.Copy(KTempDiskSpaceDirName);
		tempFileName.AppendFormat(_L("reserved.%d"), fileNum);

		TestCase().INFO_PRINTF3(_L("  Creating %S of %ld bytes."), &tempFileName, maxSizeOfTempFile);

		User::LeaveIfError(file.Replace(fs, tempFileName, EFileWrite));
		User::LeaveIfError(file.SetSize(maxSizeOfTempFile));	
		file.Close();
		}

	if (lastTempFileSize > 0)
		{
		User::LeaveIfError(fs.Volume(volumeInfo, EDriveC));
		TestCase().INFO_PRINTF2(_L("  Drive C now has %ld bytes free."), volumeInfo.iFree);
		
		if( lastTempFileSize > volumeInfo.iFree )
			{	
			lastTempFileSize = volumeInfo.iFree;
			}
		
		
		tempFileName.Copy(KTempDiskSpaceDirName);
		tempFileName.AppendFormat(_L("reserved.%d"), numOfFullTempFiles+1);

		TestCase().INFO_PRINTF3(_L("  Creating %S of %ld bytes."), &tempFileName, lastTempFileSize);

		User::LeaveIfError(file.Replace(fs, tempFileName, EFileWrite));
		User::LeaveIfError(file.SetSize(lastTempFileSize));	
		file.Close();
		}

	//
	// Recheck the free space now...
	//	
	User::LeaveIfError(fs.Volume(volumeInfo, EDriveC));
	TestCase().INFO_PRINTF2(_L("  Drive C now has %ld bytes free."), volumeInfo.iFree);


	fs.Close();

	TestCase().INFO_PRINTF2( _L("Test Action %S completed."), &KTestActionSetDiskSpace );
	TestCase().ActionCompletedL( *this );	
	}
void CFileOperator::DoMixedOperationsL()
	{
	// will perform 18*iNumFiles operations
	RFile file;
	TInt firstFile = iFirstFile;
	TInt lastFile = iFirstFile + (2 * iNumFiles);
	TInt firstDir = iFirstFile;
	TInt lastDir = iFirstFile + iNumFiles;
	
	_LIT8(KData, "Some text.");

	TInt i;
	// Create Files - 2*iNumFiles Ops
	// we create 2*iNumFiles files here so that we can ensure that at least iNumfiles ops are performed after the replace step
	for (i = firstFile; i < lastFile; i++)
		{
		TFileName nextFile;
		FileNameGen(nextFile, i);
		file.Create(iFs, nextFile, EFileRead);
		file.Close();	
		}

	// Create Directories - iNumFiles Ops
	for (i = firstDir; i < lastDir; i++)
		{
		TFileName nextFile;
		FileNameGen(nextFile, i, EFalse);
		iFs.MkDir(nextFile);
		}
	
	// Write - 2*iNumFiles Ops
	for (i = firstFile; i < lastFile; i++)
		{
		TFileName nextFile;
		FileNameGen(nextFile, i);
		file.Open(iFs, nextFile, EFileWrite);
		file.Write(KData);
		file.Flush();
		file.Close();
		}

	// Resize - 2*iNumFiles Ops
	for (i = firstFile; i < lastFile; i++)
		{
		TFileName nextFile;
		FileNameGen(nextFile, i);
		file.Open(iFs, nextFile, EFileWrite);
		TInt size;
		file.Size(size);
		file.SetSize(size+10);
		file.Close();
		}
	
	// Replace Files - iNumFiles Ops
	for (i = firstFile; i < firstFile + iNumFiles; i++)
		{
		TFileName newFile;
		TFileName oldFile;
		FileNameGen(oldFile, i);
		FileNameGen(newFile, i + iNumFiles);
		iFs.Replace(oldFile, newFile);
		}
	firstFile += iNumFiles;
	
	// Rename Files - iNumFiles Ops
	for (i = firstFile; i < lastFile; i++)
		{
		TFileName newFile;
		TFileName oldFile;
		FileNameGen(newFile, i - iNumFiles);
		FileNameGen(oldFile, i);	
		iFs.Rename(oldFile, newFile);
		}
	firstFile -= iNumFiles;
	lastFile -= iNumFiles;
	
	// Delete Dirs - iNumFiles Ops
	for (i = firstDir; i < lastDir; i++)
		{
		TFileName nextFile;
		FileNameGen(nextFile, i, EFalse);
		iFs.RmDir(nextFile);
		}
	
	// Delete File - iNumFiles Ops
	for (i = firstFile; i < lastFile; i++)
		{
		TFileName nextFile;
		FileNameGen(nextFile, i);
		iFs.Delete(nextFile);
		}

	// All-in-one - 7*iNumFiles Ops
	for (i = firstFile; i < lastFile; i++)
		{
		TFileName nextFile;
		FileNameGen(nextFile, i);
		TFileName nextDir;
		FileNameGen(nextDir, i, EFalse);
		
		iFs.MkDir(nextDir);
		
		file.Create(iFs, nextFile, EFileWrite);
		file.Write(KData);
		file.Flush();
		TInt size;
		file.Size(size);
		file.SetSize(size+10);
		file.Close();
		
		TFileName newName;
		FileNameGen(newName, i + iNumFiles);
		iFs.Rename(nextFile, newName);
		
		iFs.Delete(newName);
		iFs.RmDir(nextDir);
		}
	}