/**
    Testing the case of passing a directory name longer than KMaxFileName to the file server.
    KErrBadName shall be the result
*/
LOCAL_C void DoTestLongDirName2(void)
{
    RFs         rfs;
    TBool       bDirExisted=EFalse;

    CleanupClosePushL(rfs);    
    test(rfs.Connect() == KErrNone);
    
    //-- create a dir c:\a
    _LIT(dirName, "C:\\a\\");
    TInt err = rfs.MkDir(dirName);
    test_Value(err, err == KErrNone || err == KErrAlreadyExists);
    
    if(err == KErrAlreadyExists)
        bDirExisted = ETrue;
    
    //-- dir name longer than KMaxFileName
    _LIT(longDirName, "C:\\a\\longnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongnamelongname\\");
    //TInt nLen = dirName().Length();
    
    //-- try to create a directory with a very long name, checking that it doesn't get truncated to the "c:\a"
    err = rfs.MkDir(longDirName);
    test_Value(err, err == KErrBadName);

    //-- clean up, remove created directory, otherwise some ill-designed tests can fail
    if(!bDirExisted)
        rfs.RmDir(dirName);
    
    CleanupStack::PopAndDestroy(1); // rfs
}
void CMtfTestActionDeleteMessageStore::ExecuteActionL()
	{
	TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionDeleteMessageStore);
	HBufC* paramStorePath = ObtainParameterReferenceL<HBufC>(TestCase(),ActionParameters().Parameter(0));

	TPtrC Store = paramStorePath->Des();
	RFs fs;
	fs.Connect();
	CDictionaryFileStore* store = CDictionaryFileStore::SystemLC(fs);
	const TUid KUidMsvMessageDriveStream = {0x1000163E};
	if (store->IsPresentL(KUidMsvMessageDriveStream))
		{
		store->RemoveL(KUidMsvMessageDriveStream); 
		store->CommitL();
		}
	CleanupStack::PopAndDestroy(store); 

	CFileMan* fileMan = CFileMan::NewL(fs); 
	CleanupStack::PushL(fileMan);
	TInt error;
	error = fileMan->RmDir(Store); 
	error = fs.RmDir(Store); 
	if (!(error==KErrNotFound||error==KErrNone))
		{
		User::Leave(KErrAccessDenied);
		}
	CleanupStack::PopAndDestroy(fileMan);
	fs.Close();
	TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionDeleteMessageStore);
	TestCase().ActionCompletedL(*this);
	}
// ----------------------------------------------------------------------------------------
// CTerminalControlServer::DeleteFileL
// ----------------------------------------------------------------------------------------
void CTerminalControlServer::DeleteFileL( const TDesC8 &aFileName )
{
    RDEBUG("CTerminalControlServer::DeleteFileL");

    RFs fs;
    User::LeaveIfError(fs.Connect());
    CleanupClosePushL( fs );

    HBufC *fileName = HBufC::NewLC( aFileName.Length()+1 );
    TPtr fnptr( fileName->Des() );

    fnptr.Copy(aFileName);
    TEntry entry;

    User::LeaveIfError( fs.Entry( fnptr, entry ) );

    if( entry.IsDir() )
    {
        if(fnptr.Right(1) != _L("\\"))
        {
            fnptr.Append(_L("\\"));
        }
        User::LeaveIfError(fs.RmDir( fnptr ) );
    }
    else
    {
        User::LeaveIfError(fs.Delete( fnptr ) );
    }

    CleanupStack::PopAndDestroy( fileName );

    CleanupStack::PopAndDestroy( &fs );
}
//sqlite3SymbianLibInit() - 'File I/O error simulation' test
void sqlite3SymbianLibInitFsErrTest()
	{
	sqlite3SymbianLibFinalize();
	
	TInt sysDrive = static_cast<TInt>(RFs::GetSystemDrive());
	TDriveUnit drvUnit(sysDrive);
	TDriveName drvName = drvUnit.Name();
	
	TFileName path;
	TInt err = TheFs.PrivatePath(path);
	TEST2(err, KErrNone);
	
	TParse privDataCage;
	err = privDataCage.Set(drvName, &path, 0);
	TEST2(err, KErrNone);
	
	err = KErrNotFound;
	TInt cnt = 1;
	for(;err<KErrNone;++cnt)
		{
		for (TInt fsError=KErrNotFound;fsError>=KErrDied;--fsError)
			{
			(void)TheFs.RmDir(privDataCage.FullName());
	
			TInt processHandleCnt = 0;
			TInt threadHandleCnt = 0;
			RThread().HandleCount(processHandleCnt, threadHandleCnt);
			TInt allocCellsCnt = User::CountAllocCells();
			
			(void)TheFs.SetErrorCondition(fsError, cnt);
			err = sqlite3SymbianLibInit();
			(void)TheFs.SetErrorCondition(KErrNone);
			
			if(err != KErrNone)
				{
				TInt processHandleCnt2 = 0;
				TInt threadHandleCnt2 = 0;
				RThread().HandleCount(processHandleCnt2, threadHandleCnt2);
				TEST2(processHandleCnt2, processHandleCnt);
				TEST2(threadHandleCnt2, threadHandleCnt);
				TInt allocCellsCnt2 = User::CountAllocCells();
				TEST2(allocCellsCnt2, allocCellsCnt);
				}
			else
				{
				sqlite3SymbianLibFinalize();
				}
			}
		}
	sqlite3SymbianLibFinalize();
	TheTest.Printf(_L("=== sqlite3SymbianLibInit() 'File I/O error simulation' test succeeded at iteration %d\r\n"), cnt);
	}
void RemoveDirectoryTreeL(RFs& aFs, const TDesC& aFileName)
	{
	TParse directory;
	User::LeaveIfError(directory.SetNoWild(aFileName, NULL, NULL));
	while(!directory.IsRoot())
		{
		// try to remove this directory
		TInt err = aFs.RmDir(directory.DriveAndPath());
		if(err == KErrInUse || err == KErrAccessDenied)
			{
			break;
			}
		VerifyDeletionErrorL(err);		
		// move to deleted directory's parent
		User::LeaveIfError(directory.PopDir());
		}	
	}
void DoRun()
	{
    RFs fs;
	TInt err = fs.Connect();
	TEST2(err, KErrNone);

	TheTest.Start(_L("  @SYMTestCaseID:SYSLIB-SQL-LEGACY-T_SQLENVDESTROY-0001 Delete secure databases from C: "));

	DoDeleteFile(fs, KDbCFileName1);
	DoDeleteFile(fs, KDbCFileName2);
	DoDeleteFile(fs, KDbCFileName3);
	DoDeleteFile(fs, KDbCFileName4);
	DoDeleteFile(fs, KDbCFileName5);

	DoDeleteFile(fs, KDb1);
	DoDeleteFile(fs, KDb2);
	DoDeleteFile(fs, KDb3);
	DoDeleteFile(fs, KDb4);
	DoDeleteFile(fs, KDb5);
	DoDeleteFile(fs, KDb6);
	DoDeleteFile(fs, KDb7);
	DoDeleteFile(fs, KDb8);

	TheTest.Printf(_L("====================================================\r\n"));
	PrintDiskUsage(fs, _L("c:\\"));
	TheTest.Printf(_L("====================================================\r\n"));
	
	//Remove the created subdir in the private datacage. 
	err = fs.RmDir(KPrivateSubDir);
	if(err != KErrNone && err != KErrNotFound)
		{
		TheTest.Printf(_L("Error %d deleting \"%S\" directory.\n"), err, &KPrivateSubDir);
		}
	
	fs.Close();
	}
Exemple #7
0
int PosixFilesystem::rmdir (RFs& aFs, const wchar_t* aPath, int& anErrno)
{
    TParse name;
    TInt err=GetFullPath(name,(const TText16 *)aPath,aFs,NULL);
    if (!err)
    {
        TPtrC path=name.DriveAndPath();
        TUint att=0;
        if (path.Length()==3)
            err=EPERM;	// no, you may not remove the root directory
        else
            err=aFs.Att(path, att);
        if (!err)
            if (att&KEntryAttDir)
            {
                err=aFs.RmDir(path);
                if (err==KErrInUse)
                    err=EEXIST;	// i.e. directory not empty
            }
            else
                err=ENOTDIR;
    }
    return MapError(err,anErrno);
}
static void TestWithCaps(TUint32 aCaps, TInt aExpectedError, const TDesC& aFileName)
/**
	Helper function for TestWithCaps(TUint32, TInt).  This function invokes
	a helper executable with the supplied capabilities and tells it to delete
	the supplied filename.
	
 	@param	aCapMask		Capabilities of process which calls RLoader::Delete.
	@param	aExpectedError	Expected error reason.  The launched executable is expected
							to panic with category KTldPanicCat and this reason, which
							is the expected return code from RLoader::Delete.
	@param	aFileName		The helper executable is told to delete this file.
*/
	{
	test.Printf(
		_L("TestWithCaps,aCaps=0x%x,aExpectedError=%d,aFileName=\"%S\"\n"),
		aCaps, aExpectedError, &aFileName);

	TInt r;

	// create the file to delete
	RFs fs;
	r = fs.Connect();
	test(r == KErrNone);

	// if this file is expected to exist then create it
	TPtrC dirName;
	TBool shouldExist = (aFileName == KTldTcbFile || aFileName == KTldAllFilesFile);
	if (shouldExist)
		{
		TParsePtrC pp(aFileName);
		dirName.Set(pp.DriveAndPath());
		r = fs.MkDirAll(dirName);
		test(r == KErrNone || r == KErrAlreadyExists);
		CreateTestFile(fs, aFileName);
		}

	SetHelperCaps(aCaps);
	RunHelper(aFileName, aExpectedError);

	if (shouldExist)
		{
		// if the file could not be deleted then delete it now
		TEntry e;
		// a C++ bool for the following equality operator
		bool exists = (fs.Entry(aFileName, e) == KErrNone);
		test(exists == (aExpectedError != KErrNone));
		
		if (exists)
			{
			r = fs.Delete(aFileName);
			test(r == KErrNone);
			}

		// delete the immediate containing directory.  The error code is not
		// used because the directory may be used for something else.
		fs.RmDir(dirName);
		}

	// delete the generated different-caps file
	r = fs.Delete(_L("c:\\sys\\bin\\tld_helper_caps.exe"));
	test(r == KErrNone);
	r = fs.Delete(_L("c:\\sys\\hash\\tld_helper_caps.exe"));
	test(r == KErrNone || r == KErrNotFound || r == KErrPathNotFound);

	fs.Close();
	}
TInt E32Main()
	{
	TInt r;
	test.Title();
	test.Start(_L("Starting T_DENYCLAMP ..."));
	test(TheFs.Connect()==KErrNone);

	GetDriveLetters();
	TBuf<256> pathName;	

	//************************************************************************
	//
	// Test on FAT (writable file system)
	//
	//************************************************************************
	if(NandFatDrv!='?')
		{
		pathName=_L("?:\\CLAMP-TST\\");	// FAT on NAND
		pathName[0]=(TText)NandFatDrv;
		r=TheFs.MkDirAll(pathName);
		test(r==KErrNone || r== KErrAlreadyExists);
		TheFs.SetSessionPath(pathName);
		test.Printf( _L("T_DENYCLAMP: testing FAT drive on %C\n"),(TText)NandFatDrv);

		Test1();		// Basic clamp operation
		Test2();		// Invalid clamp requests
//		Test3(pathName);// Denied FS requests when files are clamped - invalid for T_DENYCLAMP

		r=TheFs.RmDir(pathName);
		test(r==KErrNone);
		}
	else
		test.Printf( _L("T_DENYCLAMP: FAT drive not tested\n"));

	//************************************************************************
	//
	// Test on ROFS (non-writable file system) 
	//
	//************************************************************************
	if(RofsDrv!='?')
		{
		pathName=_L("?:\\");
		pathName[0]=(TText)RofsDrv;
		TheFs.SetSessionPath(pathName);
		test.Printf( _L("T_DENYCLAMP: testing ROFS drive on %C\n"),(TText)RofsDrv);

		Test4(pathName);	// Clamp tests for non-writable file system
		}
	else
		test.Printf( _L("T_DENYCLAMP: ROFS drive not tested\n"));

	//************************************************************************
	//
	// Test on Z: - Composite File System, or ROMFS (non-writable file system)
	//
	//************************************************************************
	if(CompDrv!='?')
		{
		pathName=_L("?:\\TEST\\");
		pathName[0]=(TText)CompDrv;
		TheFs.SetSessionPath(pathName);
		test.Printf( _L("T_DENYCLAMP: testing Z drive (on %C)\n"),(TText)CompDrv);

		Test4(pathName);	// Clamp tests for non-writable file system
		}
	else
		test.Printf( _L("T_DENYCLAMP: Z drive not tested\n"));

	//************************************************************************
	//
	// Test on LFFS (non-clampable file system)
	//
	//************************************************************************
	if(LffsDrv!='?')
		{
		TBuf<256> unsuppPath;	
		unsuppPath=_L("?:\\CLAMP-TST\\");
		unsuppPath[0]=(TText)LffsDrv;
		r=TheFs.MkDirAll(unsuppPath);
		test(r==KErrNone || r== KErrAlreadyExists);
		TheFs.SetSessionPath(unsuppPath);
		test.Printf( _L("T_DENYCLAMP: testing LFFS drive on %C\n"),(TText)LffsDrv);

		Test5();		// Clamp requests on non-clamping file systems
		}
	else
		test.Printf( _L("T_DENYCLAMP: LFFS drive not tested\n"));

	test.End();
	return 0;
	}