void CPreModifierPlugin::FsReadFileSectionL(TFsPluginRequest& aRequest)
	{
	TInt err = KErrNone;
	TInt length = 0;
	TInt64 pos = 0;
	TFileName filename;
	TParse parse;
	TBuf<256> testfilename1;

	//setting up test files
	testfilename1.Append(iDriveToTest);
	testfilename1.Append(_L(":\\Data\\test.txt"));

	filename = aRequest.Src().FullName();

	err = aRequest.Read(TFsPluginRequest::ELength, length);
	iLastError = err;
	iLineNumber = __LINE__;
	if(err!=KErrNone)
		User::Leave(err); //trapped in DoRequestL
	
	err = aRequest.Read(TFsPluginRequest::EPosition, pos);
	iLastError = err;
	iLineNumber = __LINE__;
	if(err!=KErrNone)
		User::Leave(err); //trapped in DoRequestL

    parse.Set(filename, NULL, NULL);

	_LOG2(_L("CPreModifierPlugin::FsReadFileSectionL, file: %S"), &filename);
	
	if (aRequest.IsPostOperation())
		{
		_LOG(_L("CPreModifierPlugin::FsReadFileSectionL, post intercept - enter"));
		RFilePlugin fileplugin2(aRequest,ETrue);
		//open a second file
		err = fileplugin2.Open(testfilename1, EFileWrite);
		_LOG3(_L("CPreModifierPlugin::FsReadFileSectionL - RFilePlugin::Open for %S returned %d"), &testfilename1, err);
		iLastError = err;
		iLineNumber = __LINE__;
		if(err!=KErrNone)
			User::Leave(err); //trapped in DoRequestL
								
		TInt64 size=0;
		err = fileplugin2.Size(size);
		_LOG3(_L("CPreModifierPlugin::FsReadFileSectionL - RFilePlugin::Size for %S returned %d"), &testfilename1, err);
		iLastError = err;
		iLineNumber = __LINE__;
		if(err!=KErrNone)
			User::Leave(err); //trapped in DoRequestL

		//close the second file
		fileplugin2.Close();
		_LOG(_L("CPreModifierPlugin::FsReadFileSectionL - post intercept - exit"));
		}
	else
		{
			User::Invariant();
		}
	}
void CPreModifierPlugin::FsRenameL(TFsPluginRequest& aRequest)
	{
	TInt err = KErrNone;
	TFileName oldfilename;
	TFileName newfilename;

	oldfilename = aRequest.Src().FullName();
	newfilename = aRequest.Dest().FullName();

	TBuf<256> testfilename1;

	//setting up test files
	testfilename1.Append(iDriveToTest);
	testfilename1.Append(_L(":\\Data\\test.txt"));

	if (aRequest.IsPostOperation())
		{
		_LOG(_L("CPreModifierPlugin::FsRenameL, post intercept"));
		RFilePlugin fileplugin2(aRequest);
		//open a second file
		err = fileplugin2.Open(testfilename1, EFileWrite);
		_LOG3(_L("CPreModifierPlugin::FsRenameL, RFilePlugin::Open for %S returned %d"), &testfilename1, err);
		iLastError = err;
		iLineNumber = __LINE__;
		if(err!=KErrNone)
			User::Leave(err); //trapped in DoRequestL
								
		TInt64 size=0;
		err = fileplugin2.Size(size);
		iLastError = err;
		iLineNumber = __LINE__;
		if(err!=KErrNone)
			User::Leave(err); //trapped in DoRequestL		

		//close the second file
		fileplugin2.Close();
		_LOG2(_L("CPreModifierPlugin::FsRenameL, RFilePlugin::Close to the second file returned %d"), err);
		}
	else
		{
		User::Invariant();
		}
	}
/**
@internalComponent
*/
void CPreModifierPlugin::FsFileRenameL(TFsPluginRequest& aRequest)
	{
	TFileName oldfilename, newfilename;
	TParse parse;

	oldfilename = aRequest.Src().FullName();
	newfilename = aRequest.Dest().FullName();
	
    parse.Set(oldfilename, NULL, NULL);
	TPtrC extension(parse.Ext());

	_LOG3(_L("CPreModifierPlugin::FsFileRenameL, old name: %S, new name: %S"), &oldfilename, &newfilename);
	
	if (aRequest.IsPostOperation())
		{
		_LOG(_L("CPreModifierPlugin::FsFileRenameL, post intercept"));

		if (extension.CompareF(_L(".tst")) == 0)
			{
			TBuf8<32> tempBuf = (_L8("Rename Post Intercept"));
			RFilePlugin fileplugin(aRequest);
			TInt err = fileplugin.AdoptFromClient();
			iLastError = err;
			iLineNumber = __LINE__;
			if(err!=KErrNone)
				User::Leave(err); //trapped in DoRequestL

			err = fileplugin.Write(20, tempBuf);
			_LOG2(_L("CPreModifierPlugin::FsFileRenameL, FileWrite returned %d"), err);
			iLastError = err;
			iLineNumber = __LINE__;
			if(err!=KErrNone)
				User::Leave(err); //trapped in DoRequestL
			fileplugin.Close();
			}
		}
	else
		{
			User::Invariant();
		}
	}
Example #4
0
/*Test to ensure that when a file has been opened for exclusive access,
 * i.e. readonly, that from a plugin we can still write to it regardless
 */
TInt CExclusiveAccessPlugin::FsFileWriteL(TFsPluginRequest& aRequest)
	{
	if(!aRequest.IsPostOperation()) // pre-operation
		{
		//Make sure that the file is read only.

		RFilePlugin file(aRequest);
		TInt err = file.AdoptFromClient();
		iLastError = err;
		iLineNumber = __LINE__;
		if(err!=KErrNone)
			return err;
		
		RFsPlugin rfsplugin(aRequest);
		err = rfsplugin.Connect();
		iLastError = err;
		iLineNumber = __LINE__;
		if(err!=KErrNone)
			return err;
		
		TEntry entry;
		err = rfsplugin.Entry(aRequest.Src().FullName(), entry);
		iLastError = err;
		iLineNumber = __LINE__;
		if(err!=KErrNone)
			return err;
		
//		if(!entry.IsReadOnly())
//			{
//			//this test should only being being used for read only files.
//			User::Invariant();
//			}
		
		TInt64 pos;
		err = aRequest.Read(TFsPluginRequest::EPosition, pos); //get pos
		iLastError = err;
		iLineNumber = __LINE__;
		if(err!=KErrNone)
			return err;
		
		TInt length;
		err = aRequest.Read(TFsPluginRequest::ELength, length); //get length
		iLastError = err;
		iLineNumber = __LINE__;
		if(err!=KErrNone)
			return err;
		
		TBuf8<1024> data;
		err = aRequest.Read(TFsPluginRequest::EData, data); //get data to write
		iLastError = err;
		iLineNumber = __LINE__;
		if(err!=KErrNone)
			return err;
		
		//Now test that we can actually write to this read-only file
		//Should pass, kerrnone.
		err = file.Write(pos,data,length);
		iLastError = err;
		iLineNumber = __LINE__;
		if(err!=KErrNone)
			return err;
		
		file.Close();

		//We've performed the efsfilewrite, so return kerrcompletion.
		return KErrCompletion;		
		}

	return KErrNone;
	}
void CPreModifierPlugin::FsReplaceL(TFsPluginRequest& aRequest)
	{
	TFileName oldfilename;
	TFileName newfilename;

	oldfilename = aRequest.Src().FullName();
	newfilename = aRequest.Dest().FullName();

	TBuf<256> testfilename1;

	//setting up test files
	testfilename1.Append(iDriveToTest);
	testfilename1.Append(_L(":\\Data\\test.txt"));

    	
	if (aRequest.IsPostOperation())
		{
		//STF: Is this code going to get called - the pre-operation completes early?

		_LOG(_L("CPreModifierPlugin::FsReplaceL, post intercept"));
		//We should check that the name has changed here.
		RFilePlugin file(aRequest);
		TInt err = file.AdoptFromClient();
		iLastError = err;
		iLineNumber = __LINE__;
		if(err!=KErrNone)
			User::Leave(err); //trapped in DoRequestL

		TInt compare = oldfilename.Compare(newfilename);
		if(compare != 0) //is equal
			{
			//User::Leave(compare);
			//It wont be equal as the name is coming from the request aint it.
			//Pointless comparison then eh?
			}

		file.Close();

		RFilePlugin fileplugin2(aRequest);
		//open a second file
		err = fileplugin2.Open(testfilename1, EFileWrite);
		_LOG3(_L("CPreModifierPlugin::FsReplaceL, RFilePlugin::Open for %S returned %d"), &testfilename1, err);
		iLastError = err;
		iLineNumber = __LINE__;
		if(err!=KErrNone)
			User::Leave(err); //trapped in DoRequestL
								
		TInt64 size=0;
		err =fileplugin2.Size(size);
		iLastError = err;
		iLineNumber = __LINE__;
		if(err!=KErrNone)
			User::Leave(err); //trapped in DoRequestL

		//close the second file
		fileplugin2.Close();
		_LOG2(_L("CPreModifierPlugin::FsReplaceL, RFilePlugin::Close to the second file returned %d"), err);
		}
	else
		{
		User::Invariant();
		}
	}
void CPreModifierPlugin::FsFileReplaceL(TFsPluginRequest& aRequest)
	{
	TFileName filename;
	TParse parse;
	
	filename = aRequest.Src().FullName();

	TUint mode;
	TInt err = aRequest.Read(TFsPluginRequest::EMode, mode);
	iLastError = err;
	iLineNumber = __LINE__;
	if(err!=KErrNone)
		User::Leave(err); //trapped in DoRequestL

	parse.Set(filename, NULL, NULL);
	TPtrC extension(parse.Ext());

	_LOG2(_L("CPreModifierPlugin::FsFileReplaceL, file: %S"), &filename);
	
	if (aRequest.IsPostOperation())
		{
		_LOG(_L("CPreModifierPlugin::FsFileReplaceL, post intercept"));
		if ((extension.CompareF(_L(".tst")) == 0) && (aRequest.Message().Int1() != 0))
			{
			//write to the newly replaced file
			TBuf8<64> wbuffer;
			wbuffer.Copy(_L8("TestTestTest"));

			RFilePlugin fileplugin(aRequest);
			TInt err = fileplugin.AdoptFromClient();
			iLastError = err;
			iLineNumber = __LINE__;
			if(err!=KErrNone)
				User::Leave(err); //trapped in DoRequestL

    		err = fileplugin.Write(0, wbuffer);
			_LOG2(_L("CPreModifierPlugin::FsFileReplaceL, RFilePlugin::Write to the newly created file returned %d"), err);
			iLastError = err;
			iLineNumber = __LINE__;
			if(err!=KErrNone)
				User::Leave(err); //trapped in DoRequestL

			TInt length = wbuffer.Length();
			HBufC8* tempBuf = HBufC8::NewMaxLC(length);
			TPtr8 tempBufPtr((TUint8 *)tempBuf->Des().Ptr(), length, length);
			err = fileplugin.Read(0, tempBufPtr);
			_LOG2(_L("CPreModifierPlugin::FsFileReplaceL, RFilePlugin::Read returned %d"), err);
			iLastError = err;
			iLineNumber = __LINE__;
			if(err!=KErrNone)
				User::Leave(err); //trapped in DoRe

			//testing the correct thing has been written to the drive
			err = wbuffer.Compare(tempBufPtr);
			iLastError = err;
			iLineNumber = __LINE__;
			if(err!=KErrNone)
				User::Leave(err); //trapped in DoRequestL
			
			fileplugin.Close();
			CleanupStack::PopAndDestroy();
			}
		}
	else
		{
		User::Invariant();
		}
	}