sl@0: // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // f32test\server\t_misc.cpp sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include "t_server.h" sl@0: sl@0: #ifdef __VC32__ sl@0: // Solve compilation problem caused by non-English locale sl@0: #pragma setlocale("english") sl@0: #endif sl@0: sl@0: GLDEF_D RTest test(_L("T_MISC")); sl@0: sl@0: LOCAL_C void Test1() sl@0: // sl@0: // Open, write to and read from a file sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Open, write to and read from a file")); sl@0: TInt r=TheFs.SetSessionPath(gSessionPath); sl@0: test(r==KErrNone); sl@0: RFile file; sl@0: r=file.Create(TheFs,_L("Hello.Wld"),EFileWrite); sl@0: test(r==KErrNone); sl@0: r=file.Write(_L8("Hello World"),11); sl@0: test(r==KErrNone); sl@0: file.Close(); sl@0: sl@0: r=file.Open(TheFs,_L("Hello.Wld"),EFileRead); sl@0: test(r==KErrNone); sl@0: TBuf8<256> buf; sl@0: r=file.Read(buf); sl@0: test(r==KErrNone); sl@0: test(buf==_L8("Hello World")); sl@0: file.Close(); sl@0: } sl@0: sl@0: LOCAL_C void Test2() sl@0: // sl@0: // Open and read from a file sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Open and read from a file")); sl@0: TInt r=TheFs.SetSessionPath(gSessionPath); sl@0: test(r==KErrNone); sl@0: RFile file; sl@0: r=file.Open(TheFs,_L("Hello.Wld"),EFileRead); sl@0: test(r==KErrNone); sl@0: TBuf8<256> buf; sl@0: r=file.Read(buf); sl@0: test(r==KErrNone); sl@0: test(buf==_L8("Hello World")); sl@0: file.Close(); sl@0: r=TheFs.Delete(_L("HELLO.WLD")); sl@0: test(r==KErrNone); sl@0: } sl@0: sl@0: LOCAL_C void Test3() sl@0: // sl@0: // Create nested directories sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Create nested directories")); sl@0: TInt r=TheFs.SetSessionPath(gSessionPath); sl@0: test(r==KErrNone); sl@0: TheFs.ResourceCountMarkStart(); sl@0: // sl@0: r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\A.B")); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: r=TheFs.MkDir(_L("\\F32-TST\\RIGHT\\")); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: // sl@0: r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\ONE\\")); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\TWO\\")); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\THREE\\")); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\TWO\\BOTTOM\\")); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: // sl@0: r=TheFs.MkDirAll(_L("\\F32-TST\\RIGHT\\TOP\\MID\\BOT\\")); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: } sl@0: sl@0: LOCAL_C void Test4() sl@0: // sl@0: // Test returned error values sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Test returned error values")); sl@0: TInt r=TheFs.SetSessionPath(gSessionPath); sl@0: test(r==KErrNone); sl@0: TheFs.ResourceCountMarkStart(); sl@0: // sl@0: r=TheFs.MkDir(_L("\\")); sl@0: test(r==KErrAlreadyExists); sl@0: r=TheFs.MkDir(_L("\\LEFT")); sl@0: test(r==KErrAlreadyExists); sl@0: r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\")); sl@0: test(r==KErrAlreadyExists); sl@0: r=TheFs.MkDir(_L("\\F32-TST\\LEFT\\..\\NEWDIR\\")); sl@0: test(r==KErrBadName); sl@0: r=TheFs.MkDir(_L("\\F32-TST\\NEWDIR\\SUBDIR\\")); sl@0: test(r==KErrPathNotFound); sl@0: // sl@0: r=TheFs.RmDir(_L("\\")); sl@0: test(r==KErrInUse); sl@0: r=TheFs.RmDir(_L("\\PROG")); sl@0: test(r==KErrInUse); sl@0: r=TheFs.RmDir(_L("\\F32-TST\\")); sl@0: test(r==KErrInUse); sl@0: sl@0: sl@0: RDir dir; sl@0: r=dir.Open(TheFs,_L("V:\\asdf"),KEntryAttNormal); sl@0: test(r==KErrNone || r==KErrNotReady || r==KErrNotFound); sl@0: if (r==KErrNone) sl@0: dir.Close(); sl@0: r=dir.Open(TheFs,_L("L:\\asdf"),KEntryAttNormal); sl@0: test(r==KErrNone || r==KErrNotReady || r==KErrNotFound); sl@0: dir.Close(); sl@0: // sl@0: TEntry entry; sl@0: r=TheFs.Entry(_L("z:\\NOTEXiSTS\\file.txt"),entry); sl@0: test(r==KErrPathNotFound); sl@0: r=TheFs.Entry(_L("z:\\NOTEXiSTS\\"),entry); sl@0: test(r==KErrNotFound); sl@0: r=TheFs.Entry(_L("z:\\SYSTEM\\"),entry); sl@0: test(r==KErrNone); sl@0: r=TheFs.Entry(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin)?_L("z:\\SYS\\BIN\\ESHELL.EXE"):_L("z:\\SYSTEM\\BIN\\ESHELL.EXE"),entry); sl@0: test(r==KErrNone); sl@0: sl@0: r=dir.Open(TheFs,_L("\\*"),NULL); sl@0: test(r==KErrNone); sl@0: TEntry dirEntry; sl@0: r=dir.Read(dirEntry); sl@0: test(r==KErrNone || r==KErrEof); sl@0: if (r==KErrNone) sl@0: test.Printf(_L("%S\n"),&dirEntry.iName); sl@0: dir.Close(); sl@0: sl@0: r=dir.Open(TheFs,_L("A:\\*"),NULL); sl@0: test(r==KErrNotReady || r==KErrNone); sl@0: dir.Close(); sl@0: } sl@0: sl@0: LOCAL_C void Test5() sl@0: // sl@0: // Read files directly from the rom sl@0: // sl@0: sl@0: { sl@0: test.Next(_L("Read Files directly from the rom")); sl@0: sl@0: TInt pos=0; sl@0: TInt r; sl@0: _LIT(KTFileCpp, "Z:\\test\\T_FILE.CPP"); sl@0: _LIT(KTFsrvCpp, "Z:\\test\\T_FSRV.CPP"); sl@0: sl@0: if ( TheFs.IsFileInRom(KTFileCpp) != NULL && TheFs.IsFileInRom(KTFsrvCpp) != NULL ) sl@0: { sl@0: RFile f; sl@0: r=f.Open(TheFs,KTFileCpp,EFileRead); sl@0: test(r==KErrNone); sl@0: r=f.Seek(ESeekAddress,pos); sl@0: TText8* ptrPos=*(TText8**)&pos; sl@0: test(r==KErrNone); sl@0: TBuf8<1024> readBuf; sl@0: r=f.Read(readBuf); sl@0: test(r==KErrNone); sl@0: test(readBuf.Length()==readBuf.MaxLength()); sl@0: TPtrC8 memBuf(ptrPos,readBuf.Length()); sl@0: test(memBuf==readBuf); sl@0: sl@0: ptrPos+=9913; sl@0: pos=9913; sl@0: r=f.Seek(ESeekStart,pos); sl@0: test(r==KErrNone); sl@0: readBuf.SetLength(0); sl@0: r=f.Read(readBuf); sl@0: test(r==KErrNone); sl@0: test(readBuf.Length()==readBuf.MaxLength()); sl@0: memBuf.Set(ptrPos,readBuf.Length()); sl@0: test(memBuf==readBuf); sl@0: sl@0: RFile f2; sl@0: pos=10; sl@0: r=f2.Open(TheFs,KTFsrvCpp,EFileRead); sl@0: sl@0: test(r==KErrNone); sl@0: r=f2.Seek(ESeekAddress,pos); sl@0: ptrPos=*(TText8**)&pos; sl@0: test(r==KErrNone); sl@0: readBuf.SetLength(0); sl@0: pos=10; sl@0: r=f2.Seek(ESeekStart,pos); sl@0: test(r==KErrNone); sl@0: r=f2.Read(readBuf); sl@0: test(r==KErrNone); sl@0: test(readBuf.Length()==readBuf.MaxLength()); sl@0: memBuf.Set(ptrPos,readBuf.Length()); sl@0: test(memBuf==readBuf); sl@0: sl@0: ptrPos+=2445; sl@0: pos=10+2445; sl@0: r=f2.Seek(ESeekStart,pos); sl@0: test(r==KErrNone); sl@0: readBuf.SetLength(0); sl@0: r=f2.Read(readBuf); sl@0: test(r==KErrNone); sl@0: test(readBuf.Length()==readBuf.MaxLength()); sl@0: memBuf.Set(ptrPos,readBuf.Length()); sl@0: test(memBuf==readBuf); sl@0: sl@0: pos=0; sl@0: r=f.Seek(ESeekAddress,pos); sl@0: ptrPos=*(TText8**)&pos; sl@0: test(r==KErrNone); sl@0: readBuf.SetLength(0); sl@0: pos=0; sl@0: r=f.Seek(ESeekStart,pos); sl@0: test(r==KErrNone); sl@0: r=f.Read(readBuf); sl@0: test(r==KErrNone); sl@0: test(readBuf.Length()==readBuf.MaxLength()); sl@0: memBuf.Set(ptrPos,readBuf.Length()); sl@0: test(memBuf==readBuf); sl@0: sl@0: ptrPos+=5245; sl@0: pos=5245; sl@0: r=f.Seek(ESeekStart,pos); sl@0: test(r==KErrNone); sl@0: readBuf.SetLength(0); sl@0: r=f.Read(readBuf); sl@0: test(r==KErrNone); sl@0: test(readBuf.Length()==readBuf.MaxLength()); sl@0: memBuf.Set(ptrPos,readBuf.Length()); sl@0: test(memBuf==readBuf); sl@0: sl@0: f.Close(); sl@0: f2.Close(); sl@0: } sl@0: } sl@0: sl@0: LOCAL_C void Test6() sl@0: // sl@0: // Test rom return values sl@0: // sl@0: { sl@0: test.Next(_L("Test rom return values")); sl@0: sl@0: RFile f; sl@0: TInt r=f.Replace(TheFs,_L("Z:\\Test\\T_Fsrv.Cpp"),EFileRead); sl@0: test(r==KErrAccessDenied); sl@0: r=f.Create(TheFs,_L("Z:\\Test\\newT_Fsrv.Cpp"),EFileRead); sl@0: test(r==KErrAccessDenied); sl@0: r=f.Open(TheFs,_L("Z:\\Test\\T_Fsrv.Cpp"),EFileRead); sl@0: test(r==KErrNone); sl@0: f.Close(); sl@0: r=f.Open(TheFs,_L("Z:\\Test\\T_Fsrv.Cpp"),EFileRead|EFileWrite); sl@0: test(r==KErrAccessDenied); sl@0: } sl@0: sl@0: LOCAL_C void Test7() sl@0: // sl@0: // Test cache sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Test cache updated when writing to a file")); sl@0: TUidType uid1(TUid::Uid(1),TUid::Uid(2),TUid::Uid(3)); sl@0: TBuf8<32> contents1=_L8("asdf asdf asdf"); sl@0: TBuf<32> file1=_L("\\TMISC\\CACHE.FILE"); sl@0: MakeFile(file1,uid1,contents1); sl@0: sl@0: TEntry entry; sl@0: TInt r=TheFs.Entry(file1,entry); sl@0: test(r==KErrNone); sl@0: test(entry.iType==uid1); sl@0: sl@0: TUidType uid2(TUid::Uid(4),TUid::Uid(5),TUid::Uid(6)); sl@0: TCheckedUid checkedUid(uid2); sl@0: TPtrC8 uidData((TUint8*)&checkedUid,sizeof(TCheckedUid)); sl@0: RFile f; sl@0: r=f.Open(TheFs,file1,EFileRead|EFileWrite); sl@0: test(r==KErrNone); sl@0: r=f.Write(uidData); sl@0: test(r==KErrNone); sl@0: r = f.Flush(); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.Entry(file1,entry); sl@0: test(r==KErrNone); sl@0: test(entry.iType==uid2); sl@0: sl@0: f.Close(); sl@0: r=TheFs.Entry(file1,entry); sl@0: test(r==KErrNone); sl@0: test(entry.iType==uid2); sl@0: } sl@0: sl@0: LOCAL_C void Test8() sl@0: // sl@0: // Test IsValidName sl@0: // sl@0: { sl@0: test.Next(_L("Test RFs::IsValidName(TDesC)")); sl@0: sl@0: // tests calling IsValidName() with invalid name as first call to session sl@0: // see defect EXT-57KH9K sl@0: _LIT(KInvalidName, "test\\i1.jpg"); sl@0: RFs fs; sl@0: test(KErrNone==fs.Connect()); sl@0: test(fs.IsValidName(KInvalidName)==EFalse); sl@0: fs.Close(); sl@0: sl@0: test(TheFs.IsValidName(_L("*"))==EFalse); sl@0: test(TheFs.IsValidName(_L("?"))==EFalse); sl@0: test(TheFs.IsValidName(_L(">"))==EFalse); sl@0: test(TheFs.IsValidName(_L("<"))==EFalse); sl@0: test(TheFs.IsValidName(_L(":"))==EFalse); sl@0: test(TheFs.IsValidName(_L("\""))==EFalse); sl@0: test(TheFs.IsValidName(_L("/"))==EFalse); sl@0: test(TheFs.IsValidName(_L("|"))==EFalse); sl@0: test(TheFs.IsValidName(_L("\\"))==EFalse); sl@0: sl@0: test(TheFs.IsValidName(_L("xx*yy"))==EFalse); sl@0: test(TheFs.IsValidName(_L("xx?yy"))==EFalse); sl@0: test(TheFs.IsValidName(_L("xx>yy"))==EFalse); sl@0: test(TheFs.IsValidName(_L("xx\\group\\release.txt"))==EFalse); sl@0: test(TheFs.IsValidName(_L("C:\\<\\group\\release.txt"))==EFalse); sl@0: test(TheFs.IsValidName(_L("C:\\:\\group\\release.txt"))==EFalse); sl@0: test(TheFs.IsValidName(_L("C:\\\"\\group\\release.txt"))==EFalse); sl@0: test(TheFs.IsValidName(_L("C:\\/\\group\\release.txt"))==EFalse); sl@0: test(TheFs.IsValidName(_L("C:\\|\\group\\release.txt"))==EFalse); sl@0: sl@0: test(TheFs.IsValidName(_L(""))==EFalse); // must be a name or extension present sl@0: test(TheFs.IsValidName(_L(".ext"))); sl@0: test(TheFs.IsValidName(_L("C:\\asdf.blarg\\"))==EFalse); sl@0: test(TheFs.IsValidName(_L("\\"))==EFalse); sl@0: sl@0: test(TheFs.IsValidName(_L("as(){}@~#;!\xA3$%^&()df.blarg"))); // Valid names sl@0: test(TheFs.IsValidName(_L("C:\\asdf.blarg\\asdf.blarg"))); // Valid names sl@0: test(TheFs.IsValidName(_L("\'"))); // Valid names sl@0: sl@0: test.Next(_L("Test RFs::IsValidName(TDesC, TDes) overload")); sl@0: sl@0: TText testChar; sl@0: test(TheFs.IsValidName(_L("*"),testChar)==EFalse); sl@0: test(testChar=='*'); sl@0: test(TheFs.IsValidName(_L("?"),testChar)==EFalse); sl@0: test(testChar=='?'); sl@0: test(TheFs.IsValidName(_L(">"),testChar)==EFalse); sl@0: test(testChar=='>'); sl@0: test(TheFs.IsValidName(_L("<"),testChar)==EFalse); sl@0: test(testChar=='<'); sl@0: test(TheFs.IsValidName(_L(":"),testChar)==EFalse); sl@0: test(testChar==':'); sl@0: test(TheFs.IsValidName(_L("\""),testChar)==EFalse); sl@0: test(testChar=='\"'); // Tests that " is illegal sl@0: test(TheFs.IsValidName(_L("/"),testChar)==EFalse); sl@0: test(testChar=='/'); sl@0: test(TheFs.IsValidName(_L("|"),testChar)==EFalse); sl@0: test(testChar=='|'); sl@0: test(TheFs.IsValidName(_L("\\"),testChar)==EFalse); sl@0: test(testChar==' '); sl@0: sl@0: test(TheFs.IsValidName(_L("xx*yy"),testChar)==EFalse); sl@0: test(testChar=='*'); sl@0: test(TheFs.IsValidName(_L("xx?yy"),testChar)==EFalse); sl@0: test(testChar=='?'); sl@0: test(TheFs.IsValidName(_L("xx>yy"),testChar)==EFalse); sl@0: test(testChar=='>'); sl@0: test(TheFs.IsValidName(_L("xx\\group\\release.txt"),testChar)==EFalse); sl@0: test(testChar=='>'); sl@0: test(TheFs.IsValidName(_L("C:\\<\\group\\release.txt"),testChar)==EFalse); sl@0: test(testChar=='<'); sl@0: test(TheFs.IsValidName(_L("C:\\HelloWorld\\:\\group\\release.txt"),testChar)==EFalse); sl@0: test(testChar==':'); sl@0: sl@0: sl@0: test(TheFs.IsValidName(_L("C::\\group\\release.txt"),testChar)==EFalse); sl@0: test(testChar==':'); sl@0: test(TheFs.IsValidName(_L(">\\group\\release.txt"),testChar)==EFalse); sl@0: test(testChar=='>'); sl@0: test(TheFs.IsValidName(_L("C|group\\release.txt"),testChar)==EFalse); sl@0: test(testChar=='|'); sl@0: test(TheFs.IsValidName(_L("C\\|\\group\\release.txt"),testChar)==EFalse); sl@0: test(testChar=='|'); sl@0: sl@0: test(TheFs.IsValidName(_L("\\>"),testChar)==EFalse); sl@0: test(testChar=='>'); sl@0: test(TheFs.IsValidName(_L("C:\\|group\\release.txt"),testChar)==EFalse); sl@0: test(testChar=='|'); sl@0: sl@0: test(TheFs.IsValidName(_L("C:\\\"\\group\\release.txt"),testChar)==EFalse); sl@0: test(testChar=='\"'); sl@0: test(TheFs.IsValidName(_L("C:\\/\\group\\release.txt"),testChar)==EFalse); sl@0: test(testChar=='/'); sl@0: test(TheFs.IsValidName(_L("C:\\|\\group\\release.txt"),testChar)==EFalse); sl@0: test(testChar=='|'); sl@0: test(TheFs.IsValidName(_L("C:\\ \\group\\release.txt"),testChar)==EFalse); // must be a name or extension present sl@0: test(testChar==' '); sl@0: sl@0: // Test that \ is not allowed in filenames sl@0: TFileName filename; sl@0: filename=_L("C:\\HelloWorld\\\\\\group\\release.txt"); sl@0: TPtr pChar(&testChar,sizeof(TText),sizeof(TText)); sl@0: test(TheFs.IsValidName(filename,testChar)==EFalse); sl@0: test(pChar.Find(_L("\\"))!=KErrNotFound); sl@0: filename=_L("C:\\\\\\group\\release.txt"); sl@0: test(TheFs.IsValidName(filename,testChar)==EFalse); sl@0: test(pChar.Find(_L("\\"))!=KErrNotFound); sl@0: filename=_L("C:\\Hello World\\group\\release.txt"); sl@0: filename[8]=KPathDelimiter; // Makes C:\\Hello World\\group\\release.txt sl@0: test(TheFs.IsValidName(filename,testChar)); sl@0: filename=_L("C:\\HelloWorld\\::\\group\\release.txt"); sl@0: test(TheFs.IsValidName(filename,testChar)==EFalse); sl@0: test(pChar.Find(_L(":"))!=KErrNotFound); sl@0: sl@0: filename=_L("C:\\>>\\group\\release.txt"); sl@0: test(TheFs.IsValidName(filename,testChar)==EFalse); sl@0: test(pChar.Find(_L(">"))!=KErrNotFound); sl@0: sl@0: test(TheFs.IsValidName(_L(""),testChar)==EFalse); // Must be a name sl@0: test(testChar==' '); sl@0: test(TheFs.IsValidName(_L(".ext"),testChar)); sl@0: test(TheFs.IsValidName(_L("C:\\asdf.blarg\\"),testChar)==EFalse); sl@0: test(testChar==' '); // Must be a name else testChar is set to blank sl@0: test(TheFs.IsValidName(_L("C:\\asdf.blarg"),testChar)); sl@0: sl@0: test(TheFs.IsValidName(_L("C:\\asdf..blarg\\"),testChar)==EFalse); sl@0: test(testChar==' '); // Must be a name else testChar is set to blank sl@0: test(TheFs.IsValidName(_L("C:\\asdf..blarg"),testChar)); sl@0: sl@0: test(TheFs.IsValidName(_L("\\"),testChar)==EFalse); sl@0: test(testChar==' '); sl@0: sl@0: // Test multiple evil characters - parsing occurs from right to left sl@0: // except that wildcarded characters take priority and are picked out first sl@0: test(TheFs.IsValidName(_L("abc>def|ghi?jkl:mnodef|ghidef|ghidef|ghidef|ghi"),testChar)==EFalse); sl@0: test(testChar=='|'); sl@0: test(TheFs.IsValidName(_L("abc>def"),testChar)==EFalse); sl@0: test(testChar=='>'); sl@0: sl@0: test(!TheFs.IsValidName(_L("C:\\v123456.."),testChar)); // Valid name sl@0: test(TheFs.IsValidName(_L("abc"),testChar)); // Valid name sl@0: test(TheFs.IsValidName(_L("as(){}@~#;!\xA3$%^&()df.blarg"),testChar)); // Valid name sl@0: test(TheFs.IsValidName(_L("C:\\asdf.blarg\\asdf.blarg"),testChar)); // Valid name sl@0: test(TheFs.IsValidName(_L("\'"),testChar)); // Valid name sl@0: sl@0: //PDEF133084: The wild character in the extension was not being detected. sl@0: _LIT( KTestString, "E:\\My Videos\\Downloads\\1\\1\\Name.3gp?" ); sl@0: TBuf<50> path; sl@0: path = KTestString; sl@0: TBool validName( EFalse ); sl@0: TText badChar; sl@0: TInt badCharLoc( KErrNotFound ); sl@0: sl@0: while ( ! validName ) sl@0: { sl@0: validName = TheFs.IsValidName( path, badChar ); sl@0: sl@0: if ( ! validName ) sl@0: { sl@0: badCharLoc = path.LocateReverse( badChar ); sl@0: sl@0: if ( KErrNotFound != badCharLoc ) sl@0: { sl@0: path[badCharLoc] = '_'; sl@0: } sl@0: } sl@0: } sl@0: } sl@0: sl@0: LOCAL_C void Test9() sl@0: // sl@0: // Test IsFileInRom sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Test RFs::IsFileInRom")); sl@0: sl@0: CFileMan* fMan=CFileMan::NewL(TheFs); sl@0: TInt r=fMan->Copy(_L("Z:\\TEST\\T_FILE.CPP"),_L("C:\\T_FILE.CPP")); sl@0: test(r==KErrNone || r==KErrAccessDenied); sl@0: delete fMan; sl@0: TUint8* addr=TheFs.IsFileInRom(_L("C:\\ESHELL.EXE")); sl@0: test(addr==NULL); sl@0: addr=TheFs.IsFileInRom(_L("Z:\\TEST\\T_FILE.CPP")); sl@0: if (addr!=NULL) sl@0: { sl@0: test(addr!=NULL); sl@0: TPtrC8 startOfFile(addr,12); sl@0: test(startOfFile==_L8("// Copyright")); sl@0: } sl@0: else sl@0: { sl@0: test (addr==NULL); sl@0: } sl@0: } sl@0: sl@0: LOCAL_C void Test10() sl@0: // sl@0: // Test drive names sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Test Drive Names")); sl@0: TFileName driveName; sl@0: TInt i; sl@0: for(i=0;i drive0=_L("Dilbert"); sl@0: TBuf<64> drive4=_L("Dogbert"); sl@0: TBuf<64> drive17=_L("Flibble"); sl@0: TBuf<64> drive25=_L("RAMDRIVE"); sl@0: TInt r=TheFs.SetDriveName(0,drive0); sl@0: test(r==KErrNone); sl@0: r=TheFs.SetDriveName(4,drive4); sl@0: test(r==KErrNone); sl@0: r=TheFs.SetDriveName(17,drive17); sl@0: test(r==KErrNone); sl@0: r=TheFs.SetDriveName(25,drive25); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.GetDriveName(0,driveName); sl@0: test(r==KErrNone); sl@0: test(driveName==drive0); sl@0: r=TheFs.GetDriveName(4,driveName); sl@0: test(r==KErrNone); sl@0: test(driveName==drive4); sl@0: r=TheFs.GetDriveName(17,driveName); sl@0: test(r==KErrNone); sl@0: test(driveName==drive17); sl@0: r=TheFs.GetDriveName(25,driveName); sl@0: test(r==KErrNone); sl@0: test(driveName==drive25); sl@0: sl@0: drive0=_L("askdjflsdfourewoqiuroiuaksjdvx,cvsdhwjhjhalsjhfshfkjhslj"); sl@0: r=TheFs.SetDriveName(0,drive0); sl@0: test(r==KErrNone); sl@0: r=TheFs.GetDriveName(0,driveName); sl@0: test(r==KErrNone); sl@0: test(driveName==drive0); sl@0: sl@0: // Test with illegal characters in drive name sl@0: drive0=_L("Dil>bert"); sl@0: drive4=_L("Dog?bert"); sl@0: drive17=_L("Fli*bble"); sl@0: drive25=_L("RAMD//RIVE"); sl@0: sl@0: r=TheFs.SetDriveName(0,drive0); sl@0: test(r==KErrBadName); sl@0: r=TheFs.SetDriveName(4,drive4); sl@0: test(r==KErrBadName); sl@0: r=TheFs.SetDriveName(17,drive17); sl@0: test(r==KErrBadName); sl@0: r=TheFs.SetDriveName(25,drive25); sl@0: test(r==KErrBadName); sl@0: sl@0: // Test that it is OK to set the name to no characters sl@0: sl@0: drive0=_L(""); sl@0: drive4=_L(""); sl@0: drive17=_L(""); sl@0: drive25=_L(""); sl@0: sl@0: r=TheFs.SetDriveName(0,drive0); sl@0: test(r==KErrNone); sl@0: r=TheFs.SetDriveName(4,drive4); sl@0: test(r==KErrNone); sl@0: r=TheFs.SetDriveName(17,drive17); sl@0: test(r==KErrNone); sl@0: r=TheFs.SetDriveName(25,drive25); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.GetDriveName(0,driveName); sl@0: test(r==KErrNone); sl@0: test(driveName==drive0); sl@0: r=TheFs.GetDriveName(4,driveName); sl@0: test(r==KErrNone); sl@0: test(driveName==drive4); sl@0: r=TheFs.GetDriveName(17,driveName); sl@0: test(r==KErrNone); sl@0: test(driveName==drive17); sl@0: r=TheFs.GetDriveName(25,driveName); sl@0: test(r==KErrNone); sl@0: test(driveName==drive25); sl@0: sl@0: sl@0: } sl@0: sl@0: LOCAL_C void Test11() sl@0: // sl@0: // Miscellaneous tests sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Miscellaneous tests")); sl@0: TVolumeInfo vol; sl@0: TInt r=TheFs.Volume(vol); sl@0: test.Printf(_L("VolumeName = %S\n"),&vol.iName); sl@0: test(r==KErrNone); sl@0: r=TheFs.RmDir(_L("\\asdfasdf.\\")); sl@0: test(r==KErrBadName); sl@0: r=TheFs.MkDir(_L("\\asdfasdf.\\")); sl@0: test(r==KErrBadName); sl@0: } sl@0: sl@0: LOCAL_C void Test12() sl@0: // sl@0: // Test SetNotifyUser and GetNotifyUser sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Test Set and GetNotifyUser")); sl@0: TBool notifyState=TheFs.GetNotifyUser(); sl@0: test(notifyState); sl@0: notifyState=EFalse; sl@0: TheFs.SetNotifyUser(notifyState); sl@0: notifyState=TheFs.GetNotifyUser(); sl@0: test(notifyState==EFalse); sl@0: notifyState=ETrue; sl@0: TheFs.SetNotifyUser(notifyState); sl@0: notifyState=TheFs.GetNotifyUser(); sl@0: test(notifyState); sl@0: } sl@0: sl@0: LOCAL_C void Test13() sl@0: // sl@0: // Test return values from RFs::Volume on cf-cards sl@0: // sl@0: { sl@0: sl@0: test.Next(_L("Test RFs::Volume")); sl@0: TVolumeInfo vol; sl@0: TInt r=TheFs.Volume(vol,EDriveB); sl@0: test(r==KErrNotReady || r==KErrNone || KErrPathNotFound); sl@0: test.Printf(_L("RFs::Volume EDriveB returned %d\n"),r); sl@0: sl@0: r=TheFs.Volume(vol,EDriveC); sl@0: test(r==KErrNotReady || r==KErrNone || KErrPathNotFound); sl@0: test.Printf(_L("RFs::Volume EDriveC returned %d\n"),r); sl@0: sl@0: r=TheFs.Volume(vol,EDriveD); sl@0: test(r==KErrNotReady || r==KErrNone || KErrPathNotFound); sl@0: test.Printf(_L("RFs::Volume EDriveD returned %d\n"),r); sl@0: sl@0: r=TheFs.Volume(vol,EDriveE); sl@0: test(r==KErrNotReady || r==KErrNone || KErrPathNotFound); sl@0: test.Printf(_L("RFs::Volume EDriveE returned %d\n"),r); sl@0: sl@0: r=TheFs.Volume(vol,EDriveF); sl@0: test(r==KErrNotReady || r==KErrNone || KErrPathNotFound); sl@0: test.Printf(_L("RFs::Volume EDriveF returned %d\n"),r); sl@0: } sl@0: sl@0: sl@0: void DoTest14(TInt aDrvNum); sl@0: TInt CreateStuffedFile(RFs& aFs, const TDesC& aFileName, TUint aFileSize); sl@0: TInt CreateEmptyFile(RFs& aFs, const TDesC& aFileName, TUint aFileSize); sl@0: TBool CheckFileContents(RFs& aFs, const TDesC& aFileName); sl@0: TBool CheckBufferContents(const TDesC8& aBuffer, TUint aPrintBaseAddr=0); sl@0: sl@0: /** sl@0: Testing unallocated data initialization vulnerability in RFile sl@0: This test is performed on RAM drives and non-removable media that supports DeleteNotify (KMediaAttDeleteNotify flag) sl@0: e.g. XSR NAND sl@0: */ sl@0: LOCAL_C void Test14() sl@0: { sl@0: TInt nRes; sl@0: sl@0: test.Next(_L("Testing unallocated data initialization vulnerability in RFile")); sl@0: sl@0: TDriveList driveList; sl@0: TDriveInfo driveInfo; sl@0: sl@0: //-- 1. get drives list sl@0: nRes=TheFs.DriveList(driveList); sl@0: test(nRes == KErrNone); sl@0: sl@0: //-- 2. walk through all drives, performing the test only on suitable ones sl@0: for (TInt drvNum=0; drvNum"),param)==EFalse); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); sl@0: test(param.InvalidCharPos() == 1); sl@0: sl@0: test(TheFs.IsValidName(_L("<"),param)==EFalse); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); sl@0: test(param.InvalidCharPos() == 1); sl@0: sl@0: test(TheFs.IsValidName(_L(":"),param)==EFalse); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); sl@0: test(param.InvalidCharPos() == 1); sl@0: sl@0: test(TheFs.IsValidName(_L("\""),param)==EFalse); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); sl@0: test(param.InvalidCharPos() == 1); sl@0: sl@0: test(TheFs.IsValidName(_L("/"),param)==EFalse); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); sl@0: test(param.InvalidCharPos() == 1); sl@0: sl@0: test(TheFs.IsValidName(_L("|"),param)==EFalse); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); sl@0: test(param.InvalidCharPos() == 1); sl@0: sl@0: test(TheFs.IsValidName(_L("xx*yy"),param)==EFalse); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); sl@0: test(param.InvalidCharPos() == 3); sl@0: sl@0: test(TheFs.IsValidName(_L("xx?yy"),param)==EFalse); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); sl@0: test(param.InvalidCharPos() == 3); sl@0: sl@0: test(TheFs.IsValidName(_L("xx>yy"),param)==EFalse); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); sl@0: test(param.InvalidCharPos() == 3); sl@0: sl@0: test(TheFs.IsValidName(_L("xx\\group\\release.txt"),param)==EFalse); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); sl@0: test(param.InvalidCharPos() == 4); sl@0: sl@0: test(TheFs.IsValidName(_L("C:\\<\\group\\release.txt"),param)==EFalse); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); sl@0: test(param.InvalidCharPos() == 4); sl@0: sl@0: test(TheFs.IsValidName(_L("C:\\HelloWorld\\:\\group\\release.txt"),param)==EFalse); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); sl@0: test(param.InvalidCharPos() == 15); sl@0: sl@0: test(TheFs.IsValidName(_L("C::\\group\\release.txt"),param)==EFalse); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); sl@0: test(param.InvalidCharPos() == 3); sl@0: sl@0: test(TheFs.IsValidName(_L(">\\group\\release.txt"),param)==EFalse); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); sl@0: test(param.InvalidCharPos() == 1); sl@0: sl@0: test(TheFs.IsValidName(_L("C|group\\release.txt"),param)==EFalse); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); sl@0: test(param.InvalidCharPos() == 2); sl@0: sl@0: test(TheFs.IsValidName(_L("C\\|\\group\\release.txt"),param)==EFalse); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); sl@0: test(param.InvalidCharPos() == 3); sl@0: sl@0: test(TheFs.IsValidName(_L("\\>"),param)==EFalse); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); sl@0: test(param.InvalidCharPos() == 2); sl@0: sl@0: test(TheFs.IsValidName(_L("C:\\|group\\release.txt"),param)==EFalse); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); sl@0: test(param.InvalidCharPos() == 4); sl@0: sl@0: test(TheFs.IsValidName(_L("C:\\\"\\group\\release.txt"),param)==EFalse); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); sl@0: test(param.InvalidCharPos() == 4); sl@0: sl@0: test(TheFs.IsValidName(_L("C:\\/\\group\\release.txt"),param)==EFalse); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); sl@0: test(param.InvalidCharPos() == 4); sl@0: sl@0: test(TheFs.IsValidName(_L("C:\\|\\group\\release.txt"),param)==EFalse); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); sl@0: test(param.InvalidCharPos() == 4); sl@0: sl@0: test(TheFs.IsValidName(_L("C:\\ \\group\\release.txt"),param)==EFalse);//intermediate directory names cannot be blank sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrBadName); sl@0: sl@0: // Test that \ is not allowed in filenames sl@0: TFileName filename; sl@0: filename=_L("C:\\HelloWorld\\\\\\group\\release.txt"); sl@0: sl@0: test(TheFs.IsValidName(filename,param)==EFalse); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); sl@0: test(param.InvalidCharPos() == 22); sl@0: sl@0: filename=_L("C:\\\\\\group\\release.txt"); sl@0: test(TheFs.IsValidName(filename,param)==EFalse); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); sl@0: test(param.InvalidCharPos() == 11); sl@0: sl@0: filename=_L("C:\\Hello World\\group\\release.txt"); sl@0: filename[8]=KPathDelimiter; sl@0: test(TheFs.IsValidName(filename,param)); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrNone); sl@0: sl@0: filename=_L("C:\\HelloWorld\\::\\group\\release.txt"); sl@0: test(TheFs.IsValidName(filename,param)==EFalse); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); sl@0: test(param.InvalidCharPos() == 16); sl@0: sl@0: filename=_L("C:\\>>\\group\\release.txt"); sl@0: test(TheFs.IsValidName(filename,param)==EFalse); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); sl@0: test(param.InvalidCharPos() == 5); sl@0: sl@0: test(TheFs.IsValidName(_L(""),param)==EFalse); // Must be a name sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrBadName); sl@0: sl@0: test(TheFs.IsValidName(_L(".ext"),param)); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrNone); sl@0: sl@0: test(TheFs.IsValidName(_L("C:\\asdf.blarg"),param)); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrNone); sl@0: sl@0: test(TheFs.IsValidName(_L("C:\\asdf..blarg"),param)); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrNone); sl@0: sl@0: // Test multiple evil characters - parsing occurs from right to left sl@0: // except that wildcarded characters take priority and are picked out first sl@0: sl@0: test(TheFs.IsValidName(_L("abc>def|ghi?jkl:mnodef|ghidef|ghidef|ghidef|ghidef|ghidef|ghi"),param)==EFalse); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); sl@0: test(param.InvalidCharPos() == 8); sl@0: sl@0: test(TheFs.IsValidName(_L("abc>def|ghi"),param)==EFalse); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); sl@0: test(param.InvalidCharPos() == 8); sl@0: sl@0: test(TheFs.IsValidName(_L("abc>def"),param)==EFalse); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); sl@0: test(param.InvalidCharPos() == 4); sl@0: sl@0: test(TheFs.IsValidName(_L("abc>def"),param)==EFalse); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); sl@0: test(param.InvalidCharPos() == 4); sl@0: sl@0: test(!TheFs.IsValidName(_L("C:\\v123456.."),param)); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); sl@0: test(param.InvalidCharPos() == 11); sl@0: sl@0: test(!TheFs.IsValidName(_L("C:\\v123456.."),param)); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrBadCharacter); sl@0: test(param.InvalidCharPos() == 11); sl@0: sl@0: test(TheFs.IsValidName(_L("abc"),param)); // Valid name sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrNone); sl@0: sl@0: test(TheFs.IsValidName(_L("abc"),param)); // Valid name sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrNone); sl@0: sl@0: test(TheFs.IsValidName(_L("as(){}@~#;!\xA3$%^&()df.blarg"),param)); // Valid name sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrNone); sl@0: sl@0: test(TheFs.IsValidName(_L("as(){}@~#;!\xA3$%^&()df.blarg"),param)); // Valid name sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrNone); sl@0: sl@0: test(TheFs.IsValidName(_L("C:\\asdf.blarg\\asdf.blarg"),param)); // Valid name sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrNone); sl@0: sl@0: test(TheFs.IsValidName(_L("C:\\asdf.blarg\\asdf.blarg"),param)); // Valid name sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrNone); sl@0: sl@0: test(TheFs.IsValidName(_L("\'"),param)); // Valid name sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrNone); sl@0: sl@0: test(TheFs.IsValidName(_L("\'"),param)); // Valid name sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrNone); sl@0: sl@0: //testing directory names sl@0: test(TheFs.IsValidName(_L("\\"),param)); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrNone); // Valid Name sl@0: sl@0: test(TheFs.IsValidName(_L("C:\\asdf.blarg\\"),param)); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrNone); // Valid Name sl@0: sl@0: sl@0: test(TheFs.IsValidName(_L("C:\\asdf..blarg\\"),param)); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrNone); // Valid Name sl@0: sl@0: test(TheFs.IsValidName(_L("file1.txt\\\\"),param) == EFalse); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrBadName); sl@0: sl@0: // test name which exceeds KMaxFileName only on prepending the session path sl@0: _LIT(KNameLength250, "AAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAA"); sl@0: if(useDefaultSessionPath) sl@0: { sl@0: test(TheFs.IsValidName(KNameLength250, param)==EFalse); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrNameTooLong); sl@0: break; sl@0: } sl@0: else sl@0: { sl@0: test(TheFs.IsValidName(KNameLength250, param)); sl@0: test(param.ErrorCode() == RFs::TNameValidParam::ErrNone); sl@0: } sl@0: useDefaultSessionPath = ETrue; sl@0: } sl@0: } sl@0: sl@0: sl@0: sl@0: void TestGetMediaSerialNumber() sl@0: { sl@0: test.Next(_L("Test RFs::GetMediaSerialNumber")); sl@0: TInt theDrive; sl@0: TInt r = TheFs.CharToDrive(gDriveToTest,theDrive); sl@0: test(r == KErrNone); sl@0: TMediaSerialNumber serNum; sl@0: r = TheFs.GetMediaSerialNumber(serNum, theDrive); sl@0: if (r) test.Printf(_L("RFs::GetMediaSerialNumber returned error %d"), r); sl@0: test(r == KErrNotSupported || r == KErrNotReady || r == KErrNone); sl@0: if (r == KErrNotSupported) sl@0: { sl@0: test.Printf(_L("MediaSerialNumber: Not Supported\n")); sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("MediaSerialNumber: length=%d\n"), serNum.Length()); sl@0: TBuf<20> str; sl@0: _LIT(KNumberString, "%02X"); sl@0: _LIT(KNewLine, "\n"); sl@0: TInt i; sl@0: for (i = 0; i < serNum.Length(); i++) sl@0: { sl@0: str.AppendFormat(KNumberString, serNum[i]); sl@0: if (i%8 == 7) sl@0: { sl@0: str.Append(KNewLine); sl@0: test.Printf(_L("%S"), &str); sl@0: str.SetLength(0); sl@0: } sl@0: } sl@0: if (i%8 != 7) sl@0: { sl@0: test.Printf(KNewLine); sl@0: } sl@0: } sl@0: } sl@0: sl@0: sl@0: //-------------------------------------------------------- sl@0: sl@0: /** sl@0: Create an empty file of specified size. sl@0: @param aFs ref. to the FS sl@0: @param aFileName name of the file sl@0: @param aFileSize size of the file to be created sl@0: @return KErrNone on success, system-wide error code otherwise sl@0: */ sl@0: TInt CreateEmptyFile(RFs& aFs, const TDesC& aFileName, TUint aFileSize) sl@0: { sl@0: RFile file; sl@0: TInt nRes; sl@0: sl@0: nRes = file.Create(aFs, aFileName, EFileRead|EFileWrite); sl@0: if(nRes != KErrNone) sl@0: return nRes; sl@0: sl@0: nRes = file.SetSize(aFileSize); sl@0: if(nRes != KErrNone) sl@0: return nRes; sl@0: sl@0: file.Close(); sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: //-------------------------------------------------------- sl@0: sl@0: /** sl@0: Create a file of specified size filled with some data pattern. sl@0: @param aFs ref. to the FS sl@0: @param aFileName name of the file sl@0: @param aFileSize size of the file to be created sl@0: @return KErrNone on success, system-wide error code otherwise sl@0: */ sl@0: TInt CreateStuffedFile(RFs& aFs, const TDesC& aFileName, TUint aFileSize) sl@0: { sl@0: TInt nRes; sl@0: RFile file; sl@0: sl@0: //-- create a buffer with some data sl@0: const TUint KBufLength = 0x100; sl@0: TBuf8 buffer; sl@0: buffer.SetLength(KBufLength); sl@0: sl@0: TUint i; sl@0: sl@0: for(i = 0; i < KBufLength; i++) sl@0: buffer[i] = static_cast (i) ; sl@0: sl@0: //-- create a file sl@0: nRes = file.Create(aFs, aFileName, EFileRead|EFileWrite); sl@0: if(nRes != KErrNone) sl@0: return nRes; sl@0: sl@0: const TUint n1 = aFileSize / KBufLength; sl@0: const TUint n2 = aFileSize % KBufLength; sl@0: sl@0: //-- fill the file with the data from buffer sl@0: for(i=0; i buffer; sl@0: buffer.SetLength(0); sl@0: sl@0: //-- open the file sl@0: nRes = file.Open(aFs, aFileName, EFileRead); sl@0: test(nRes == KErrNone); sl@0: sl@0: //-- check file contents sl@0: TUint nFilePos=0; sl@0: for(;;) sl@0: { sl@0: //-- read data from the file into the buffer sl@0: nRes = file.Read(buffer); sl@0: test(nRes == KErrNone); sl@0: sl@0: if(buffer.Length() == 0) sl@0: { sl@0: nRes = KErrNone; //-- read all the file, no illegitimate information found sl@0: break; //EOF sl@0: } sl@0: sl@0: //-- check if the buffer contains only allowed data (RAM page initialisation data, etc. e.g. 0x00, 0xff, 0x03, 0xcc) sl@0: if(!CheckBufferContents(buffer, nFilePos)) sl@0: { sl@0: test.Printf(_L("\nCheckFileContents failed ! The file contains illegitimate information!\n")); sl@0: nRes = KErrCorrupt; //-- indicate that the read buffer contains illegitimate information sl@0: break; //-- comment this out if you need a full dump of the file sl@0: } sl@0: sl@0: nFilePos+=buffer.Length(); sl@0: } sl@0: sl@0: file.Close(); sl@0: return nRes; sl@0: } sl@0: sl@0: //-------------------------------------------------------- sl@0: sl@0: /** sl@0: Check if the buffer contains illegitimate information i.e. something different from 0x00, 0xff, 0x03, 0xcc sl@0: sl@0: @param aBuffer buffer descriptor to check sl@0: @param aPrintBaseAddr dump base address, used for dumping buffer only sl@0: @return ETrue on success sl@0: */ sl@0: TBool CheckBufferContents(const TDesC8& aBuffer, TUint aPrintBaseAddr/*=0*/) sl@0: { sl@0: TBool bRes = ETrue; sl@0: sl@0: //-- check if the buffer filled with allowable data (RAM page initialisation data or something similar) sl@0: //-- but not something meaningful. sl@0: //-- allowable bytes: 0x00, 0x03, 0xff, 0xcc sl@0: for(TInt i=0; i byteBuffer; sl@0: TBuf16<256> lineBuffer; sl@0: lineBuffer.Format(_L("%08X: "), aPrintBaseAddr+n); sl@0: for (TInt m=0; m<16 && n