sl@0: // Copyright (c) 1995-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_dcdiskadmin.cpp sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "t_server.h" sl@0: sl@0: GLDEF_D RTest test(_L("T_DCDiskadmin")); sl@0: GLDEF_D TTime gTimeNow; sl@0: LOCAL_D TInt gTheDriveNum; sl@0: sl@0: const TInt KPathPosition = 2; sl@0: _LIT(KExpectedPrivatePath, "\\Private\\00000001\\"); sl@0: _LIT(KResourcePath, "?:\\Resource\\"); sl@0: _LIT(KSystemPath, "?:\\Sys\\"); sl@0: _LIT(KPrivatePath, "?:\\Private\\"); sl@0: _LIT(KPrivateFalseID, "?:\\Private\\FFFFFFFF\\"); sl@0: _LIT(KDriveName, "Billy"); sl@0: _LIT(KVolLable, "Benny"); sl@0: _LIT(KFileSys, "systemfile.txt"); sl@0: _LIT(KFileSys3, "sysfile.rna"); sl@0: _LIT(KFilePri, "privatefile.txt"); sl@0: _LIT(KFilePri2, "privatefile.tmp"); sl@0: _LIT(KFilePri3, "prifile.rna"); sl@0: _LIT(KFileRes, "resourcefile.txt"); sl@0: _LIT(KFileRes3, "resfile.rna"); sl@0: _LIT(KMkDirSub,"Subdir\\"); sl@0: _LIT(KOldFile,"?:\\Anyold.txt"); sl@0: _LIT(KWildPath, "Z:\\SYS\\"); sl@0: _LIT(KWildFile, "*"); sl@0: sl@0: TInt theDrive=0; sl@0: TCapability TheCaps; sl@0: TBuf<4> driveBuf=_L("?:\\"); sl@0: RFormat format; sl@0: TInt count; sl@0: RRawDisk rawdisk; sl@0: RFile file1; sl@0: RFile file2; sl@0: RDir dir; sl@0: CDir* dirEntries; sl@0: TInt r; sl@0: TBuf<40> fsname; sl@0: TBuf<40> systestname; sl@0: TBuf<40> pritestname; sl@0: TBuf<40> restestname; sl@0: TBuf<40> theprivatepath; sl@0: TBuf<40> pritestfalseidname; sl@0: TBuf<40> mkdirname; sl@0: TFileName fromTemp; sl@0: sl@0: TBuf<40> shortfilename; sl@0: TBuf<40> longfilename; sl@0: sl@0: TBuf<30> dirNameBuf; sl@0: TRequestStatus aStat1; sl@0: TRequestStatus aStat2; sl@0: TRequestStatus aStat3; sl@0: TRequestStatus aStat4; sl@0: sl@0: TVolumeInfo aVolInfo; sl@0: // TDriveInfo adriveInfo; sl@0: sl@0: TBuf<40> systestfile; sl@0: TBuf<40> pritestfile; sl@0: TBuf<40> restestfile; sl@0: TBuf<40> systestfile1; sl@0: TBuf<40> pritestfile1; sl@0: TBuf<40> restestfile1; sl@0: TBuf<30> realName; sl@0: TTime testtime; sl@0: TBuf<20> oldName; sl@0: sl@0: TBuf<25> temp; sl@0: sl@0: TEntry entry; sl@0: sl@0: sl@0: sl@0: LOCAL_C void systemRFstest() sl@0: // sl@0: // sl@0: // sl@0: { sl@0: sl@0: //system sl@0: systestname=KSystemPath; sl@0: systestname[0]=(TText)('A' + gTheDriveNum); sl@0: sl@0: mkdirname.Zero(); sl@0: mkdirname.Append(systestname); sl@0: mkdirname.Append(KMkDirSub); sl@0: r=TheFs.MkDirAll(mkdirname); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=TheFs.RmDir(mkdirname); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=TheFs.SetSubst(systestname,EDriveS); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=TheFs.SetSessionPath(systestname); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: TheFs.NotifyChange(ENotifyAll,aStat1,systestname); sl@0: test(aStat1==KErrPermissionDenied); sl@0: sl@0: systestfile=KSystemPath; sl@0: systestfile[0]=(TText)('A' + gTheDriveNum); sl@0: systestfile1=systestfile; sl@0: systestfile.Append(KFileSys); sl@0: systestfile1.Append(KFileSys3); sl@0: sl@0: oldName=KOldFile; sl@0: oldName[0]=(TText)gDriveToTest; sl@0: sl@0: r=TheFs.GetShortName(systestfile, shortfilename); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=TheFs.GetLongName(systestfile1, longfilename); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=file1.Create(TheFs,oldName,EFileWrite); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: file1.Close(); sl@0: sl@0: r=TheFs.Replace(oldName,systestfile); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=TheFs.Rename(systestfile,systestfile1); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=TheFs.Entry(systestfile1,entry); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=TheFs.SetEntry(systestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=TheFs.Delete(systestfile1); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: sl@0: // DEF141257: Security Issue in File Server sl@0: // Test that we can't access the system drive by preceding it with a dot character sl@0: _LIT(KSystemPathDot, "?:\\.Sys\\"); sl@0: sl@0: // try creating a file in "\.SYS"... sl@0: TBuf<40> SysTestFileDot; sl@0: SysTestFileDot=KSystemPathDot; sl@0: SysTestFileDot[0]=(TText)('A' + gTheDriveNum); sl@0: SysTestFileDot.Append(KFileSys); sl@0: RFile file; sl@0: r = file.Replace(TheFs, SysTestFileDot, EFileWrite); sl@0: test(r==KErrPathNotFound); sl@0: sl@0: // try creating a subst drive for "\.SYS"... sl@0: TBuf<40> SysTestNameDot; sl@0: SysTestNameDot=KSystemPathDot; sl@0: SysTestNameDot[0]=(TText)('A' + gTheDriveNum); sl@0: r=TheFs.SetSubst(SysTestNameDot,EDriveA); sl@0: test(r==KErrNone); sl@0: sl@0: // try creating a file using substituted drive... sl@0: TBuf<40> SubstTestFile = _L("A:\\"); sl@0: SubstTestFile.Append(KFileSys); sl@0: sl@0: r = file.Replace(TheFs, SubstTestFile, EFileWrite); sl@0: test(r==KErrPathNotFound); sl@0: sl@0: r = TheFs.SetSubst(_L(""),EDriveA); sl@0: test(r==KErrNone); sl@0: sl@0: sl@0: sl@0: // try listing files in "\.SYS" sl@0: _LIT(KWildPathDot, "Z:\\.SYS\\"); sl@0: TFindFile finder(TheFs); sl@0: CDir* dir = NULL; sl@0: r=finder.FindWildByDir(KWildFile, KWildPathDot, dir); sl@0: test(r==KErrNotFound); sl@0: delete dir; sl@0: sl@0: // Deliberately create a directory called "\.SYS" sl@0: // and verify shortname is NOT the same as "SYS" sl@0: mkdirname.Zero(); sl@0: mkdirname.Append(KSystemPathDot); sl@0: mkdirname[0]=(TText)('A' + gTheDriveNum); sl@0: r=TheFs.MkDirAll(mkdirname); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.GetShortName(mkdirname, shortfilename); sl@0: test(r==KErrNone || r==KErrNotSupported); // short names not supported on LFFS sl@0: // r = shortfilename.Compare(_L("SYS~1")); sl@0: // test(r==KErrNone); sl@0: r = shortfilename.Compare(_L("SYS")); sl@0: test (r != 0); sl@0: sl@0: r = TheFs.RmDir(mkdirname); sl@0: test(r==KErrNone); sl@0: sl@0: // Deliberately create a directory called "\..SYS" sl@0: // and verify shortname is NOT the same as "SYS" sl@0: _LIT(KSystemPathDotDot, "?:\\..Sys\\"); sl@0: mkdirname.Zero(); sl@0: mkdirname.Append(KSystemPathDotDot); sl@0: mkdirname[0]=(TText)('A' + gTheDriveNum); sl@0: r=TheFs.MkDirAll(mkdirname); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.GetShortName(mkdirname, shortfilename); sl@0: test(r==KErrNone || r==KErrNotSupported); // short names not supported on LFFS sl@0: // r = shortfilename.Compare(_L("_.SYS")); sl@0: // test(r==KErrNone); sl@0: r = shortfilename.Compare(_L("SYS")); sl@0: test (r != 0); sl@0: sl@0: r = TheFs.RmDir(mkdirname); sl@0: test(r==KErrNone); sl@0: } sl@0: sl@0: sl@0: LOCAL_C void resourceRFstest() sl@0: // sl@0: // sl@0: // sl@0: { sl@0: //resource sl@0: restestname=KResourcePath; sl@0: restestname[0]=(TText)('A' + gTheDriveNum); sl@0: sl@0: mkdirname.Zero(); sl@0: mkdirname.Append(restestname); sl@0: mkdirname.Append(KMkDirSub); sl@0: r=TheFs.MkDirAll(mkdirname); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: TheFs.RmDir(mkdirname); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: // Change due to defect DEF099546 fix sl@0: // TCB capability is required for following operation. sl@0: r=TheFs.SetSubst(restestname,EDriveS); sl@0: //test(r==KErrNone); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: // SetSubst will fail. sl@0: //r=TheFs.RealName(_L("S:\\File.XXX"),realName); sl@0: //test(r==KErrNone); sl@0: sl@0: //r=TheFs.SetSubst(_L(""),EDriveS); sl@0: //test(r==KErrNone); sl@0: sl@0: r=TheFs.SetSessionPath(restestname); sl@0: test(r==KErrNone); sl@0: sl@0: TheFs.NotifyChange(ENotifyAll,aStat4,restestname); sl@0: test(aStat4==KRequestPending); sl@0: sl@0: sl@0: restestfile=KResourcePath; sl@0: restestfile[0]=(TText)('A' + gTheDriveNum); sl@0: restestfile1=restestfile; sl@0: restestfile.Append(KFileRes); sl@0: restestfile1.Append(KFileRes3); sl@0: sl@0: oldName=KOldFile; sl@0: oldName[0]=(TText)gDriveToTest; sl@0: sl@0: r=TheFs.GetShortName(restestfile, shortfilename); sl@0: test(r==KErrNone || KErrPathNotFound); sl@0: sl@0: r=TheFs.GetLongName(restestfile1, longfilename); sl@0: test(r==KErrNone || KErrPathNotFound); sl@0: sl@0: r=file1.Create(TheFs,oldName,EFileWrite); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: file1.Close(); sl@0: sl@0: r=TheFs.Replace(oldName,restestfile); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=TheFs.Rename(restestfile,restestfile1); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=TheFs.Entry(restestfile1,entry); sl@0: test(r==KErrNone || KErrPathNotFound); sl@0: sl@0: r=TheFs.SetEntry(restestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=TheFs.Delete(restestfile1); sl@0: test(r==KErrPermissionDenied); sl@0: } sl@0: sl@0: sl@0: LOCAL_C void privateFalseIDRFstest() sl@0: // sl@0: // sl@0: // sl@0: { sl@0: pritestfalseidname=KPrivateFalseID; sl@0: pritestfalseidname[0]=(TText)('A' + gTheDriveNum); sl@0: sl@0: mkdirname.Zero(); sl@0: mkdirname.Append(pritestfalseidname); sl@0: mkdirname.Append(KMkDirSub); sl@0: sl@0: r=TheFs.MkDirAll(mkdirname); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=TheFs.RmDir(mkdirname); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=TheFs.SetSubst(pritestfalseidname,EDriveS); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=TheFs.SetSessionPath(pritestfalseidname); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: TheFs.NotifyChange(ENotifyAll,aStat2,pritestfalseidname); sl@0: test(aStat2==KErrPermissionDenied); sl@0: sl@0: pritestfile=KPrivateFalseID; sl@0: pritestfile[0]=(TText)('A' + gTheDriveNum); sl@0: pritestfile1=pritestfile; sl@0: pritestfile.Append(KFilePri2); sl@0: pritestfile1.Append(KFilePri3); sl@0: sl@0: oldName=KOldFile; sl@0: oldName[0]=(TText)gDriveToTest; sl@0: sl@0: r=TheFs.GetShortName(pritestfile, shortfilename); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=TheFs.GetLongName(pritestfile1, longfilename); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=file1.Create(TheFs,oldName,EFileWrite); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: file1.Close(); sl@0: sl@0: r=TheFs.Replace(oldName,pritestfile); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=TheFs.Rename(pritestfile,pritestfile1); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=TheFs.Entry(pritestfile1,entry); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=TheFs.SetEntry(pritestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=TheFs.Delete(pritestfile1); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: } sl@0: sl@0: sl@0: sl@0: LOCAL_C void privateRFstest() sl@0: // sl@0: // sl@0: // sl@0: { sl@0: //private sl@0: pritestname=KPrivatePath; sl@0: pritestname[0]=(TText)('A' + gTheDriveNum); sl@0: sl@0: mkdirname.Zero(); sl@0: mkdirname.Append(pritestname); sl@0: mkdirname.Append(KMkDirSub); sl@0: sl@0: r=TheFs.MkDirAll(mkdirname); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=TheFs.RmDir(mkdirname); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=TheFs.SetSubst(pritestname,EDriveS); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=TheFs.SetSessionPath(pritestname); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: TheFs.NotifyChange(ENotifyAll,aStat2,pritestname); sl@0: test(aStat2==KErrPermissionDenied); sl@0: sl@0: pritestfile=KPrivatePath; sl@0: pritestfile[0]=(TText)('A' + gTheDriveNum); sl@0: pritestfile1=pritestfile; sl@0: pritestfile.Append(KFilePri2); sl@0: pritestfile1.Append(KFilePri3); sl@0: sl@0: oldName=KOldFile; sl@0: oldName[0]=(TText)gDriveToTest; sl@0: sl@0: r=TheFs.GetShortName(pritestfile, shortfilename); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=TheFs.GetLongName(pritestfile1, longfilename); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=file1.Create(TheFs,oldName,EFileWrite); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: file1.Close(); sl@0: sl@0: r=TheFs.Replace(oldName,pritestfile); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=TheFs.Rename(pritestfile,pritestfile1); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=TheFs.Entry(pritestfile1,entry); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=TheFs.SetEntry(pritestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=TheFs.Delete(pritestfile1); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: } sl@0: sl@0: sl@0: LOCAL_C void privateSIDRFstest() sl@0: // sl@0: // sl@0: // sl@0: { sl@0: //private/UID sl@0: theprivatepath[0]=(TText)gDriveToTest; sl@0: test.Printf(_L("the Private Path = %S"),&theprivatepath); sl@0: sl@0: mkdirname.Zero(); sl@0: mkdirname.Append(theprivatepath); sl@0: mkdirname.Append(KMkDirSub); sl@0: r=TheFs.MkDirAll(mkdirname); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.RmDir(mkdirname); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.SetSubst(theprivatepath,EDriveS); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.RealName(_L("S:\\File.XXX"),realName); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.SetSubst(_L(""),EDriveS); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.SetSessionPath(theprivatepath); sl@0: test(r==KErrNone); sl@0: sl@0: TheFs.NotifyChange(ENotifyAll,aStat3,theprivatepath); sl@0: test(aStat3==KRequestPending); sl@0: sl@0: pritestfile=theprivatepath; sl@0: pritestfile[0]=(TText)('A' + gTheDriveNum); sl@0: pritestfile1=pritestfile; sl@0: pritestfile.Append(KFilePri2); sl@0: pritestfile1.Append(KFilePri3); sl@0: sl@0: oldName=KOldFile; sl@0: oldName[0]=(TText)gDriveToTest; sl@0: sl@0: r=TheFs.GetShortName(pritestfile, shortfilename); sl@0: test(r==KErrNone || KErrPathNotFound); sl@0: sl@0: r=TheFs.GetLongName(pritestfile1, longfilename); sl@0: test(r==KErrNone || KErrPathNotFound); sl@0: sl@0: r=file1.Create(TheFs,oldName,EFileWrite); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: file1.Close(); sl@0: sl@0: r=TheFs.Replace(oldName,pritestfile); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.Rename(pritestfile,pritestfile1); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: sl@0: r=TheFs.Entry(pritestfile1,entry); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.SetEntry(pritestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly); sl@0: test(r==KErrNone); sl@0: sl@0: r=TheFs.Delete(pritestfile1); sl@0: test(r==KErrNone); sl@0: } sl@0: sl@0: LOCAL_C void systemRFiletest() sl@0: // sl@0: // sl@0: // sl@0: { sl@0: //RFile testing with session path set to //system// sl@0: sl@0: r=TheFs.SetSessionPath(systestname); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=file1.Temp(TheFs,systestname,fromTemp,EFileWrite); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: TBuf<25> sysfilename; sl@0: sysfilename.Append(systestname); sl@0: sysfilename.Append(KFileSys); sl@0: r=file1.Create(TheFs,sysfilename,EFileWrite); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=file1.Open(TheFs,sysfilename,EFileWrite); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=file1.Open(TheFs,sysfilename,EFileRead); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=file1.Replace(TheFs,sysfilename,EFileWrite); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: TFindFile finder(TheFs); sl@0: CDir* dir = NULL; sl@0: r=finder.FindWildByDir(KWildFile, KWildPath, dir); sl@0: if (!(r==KErrPermissionDenied)) sl@0: test.Printf(_L("T_DCDISKADMIN: test find wildcards r = %d (expected KErrPermissionDenied)\n"), r); sl@0: test(r==KErrPermissionDenied); sl@0: delete dir; sl@0: } sl@0: sl@0: LOCAL_C void resourceRFiletest() sl@0: // sl@0: // sl@0: // sl@0: { sl@0: //RFile testing with session path set to //resource// sl@0: r=TheFs.SetSessionPath(restestname); sl@0: test(r==KErrNone); sl@0: sl@0: r=file1.Temp(TheFs,restestname,fromTemp,EFileWrite); sl@0: test(r==KErrPermissionDenied); sl@0: file1.Close(); sl@0: sl@0: r=file1.Create(TheFs,KFileRes,EFileWrite); sl@0: test(r==KErrPermissionDenied); sl@0: file1.Close(); sl@0: sl@0: r=file1.Open(TheFs,KFileRes,EFileWrite); sl@0: test(r==KErrPermissionDenied); sl@0: file1.Close(); sl@0: sl@0: r=file1.Open(TheFs,KFileRes,EFileRead|EFileShareReadersOnly); sl@0: test(r==KErrNone || r==KErrPathNotFound); sl@0: file1.Close(); sl@0: sl@0: r=file1.Open(TheFs,KFileRes,EFileShareReadersOrWriters|EFileRead); sl@0: test(r==KErrNone || r==KErrPathNotFound); sl@0: file1.Close(); sl@0: sl@0: r=file1.Open(TheFs,KFileRes,EFileShareReadersOrWriters|EFileWrite); sl@0: test(r==KErrPermissionDenied); sl@0: file1.Close(); sl@0: sl@0: r=file1.Open(TheFs,KFileRes,EFileShareReadersOnly); sl@0: test(r==KErrNone); sl@0: sl@0: r=file1.ChangeMode(EFileShareExclusive); sl@0: test(r==KErrNone); sl@0: sl@0: //this operation is prevented as you can not open a file for write access in the resource directory sl@0: r=file1.Rename(KFileRes3); sl@0: test(r==KErrPermissionDenied || r==KErrAccessDenied); sl@0: file1.Close(); sl@0: sl@0: r=file1.Replace(TheFs,KFileRes,EFileWrite); sl@0: test(r==KErrPermissionDenied); sl@0: file1.Close(); sl@0: sl@0: } sl@0: sl@0: sl@0: LOCAL_C void privatefalseIDRFiletest() sl@0: // sl@0: //RFile testing with session path set to //Private//falseID sl@0: // sl@0: { sl@0: r=TheFs.SetSessionPath(pritestfalseidname); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=file1.Temp(TheFs,pritestfalseidname,fromTemp,EFileWrite); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: TBuf<25> prifilename; sl@0: prifilename.Append(pritestname); sl@0: prifilename.Append(KFileSys); sl@0: sl@0: r=file1.Create(TheFs,prifilename,EFileWrite); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=file1.Open(TheFs,prifilename,EFileWrite); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=file1.Open(TheFs,prifilename,EFileRead); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=file1.Replace(TheFs,prifilename,EFileWrite); sl@0: test(r==KErrPermissionDenied); sl@0: } sl@0: sl@0: sl@0: LOCAL_C void privateRFiletest() sl@0: // sl@0: //RFile testing with session path set to //Private// sl@0: // sl@0: { sl@0: r=TheFs.SetSessionPath(pritestname); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=file1.Temp(TheFs,pritestname,fromTemp,EFileWrite); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: TBuf<25> prifilename; sl@0: prifilename.Append(pritestname); sl@0: prifilename.Append(KFileSys); sl@0: sl@0: r=file1.Create(TheFs,prifilename,EFileWrite); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=file1.Open(TheFs,prifilename,EFileWrite); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=file1.Open(TheFs,prifilename,EFileRead); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: r=file1.Replace(TheFs,prifilename,EFileWrite); sl@0: test(r==KErrPermissionDenied); sl@0: } sl@0: sl@0: sl@0: LOCAL_C void privateSIDRFiletest() sl@0: // sl@0: //Rfile Testing with session path set to //Private//UID// sl@0: // sl@0: { sl@0: r=TheFs.SetSessionToPrivate(gTheDriveNum); sl@0: test(r==KErrNone); sl@0: sl@0: r=file1.Temp(TheFs,theprivatepath,fromTemp,EFileWrite); sl@0: test(r==KErrNone); sl@0: file1.Close(); sl@0: sl@0: r=file1.Create(TheFs,KFilePri,EFileWrite); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: file1.Close(); sl@0: sl@0: r=file1.Open(TheFs,KFilePri,EFileWrite); sl@0: test(r==KErrNone); sl@0: file1.Close(); sl@0: sl@0: r=file1.Open(TheFs,KFilePri,EFileRead); sl@0: test(r==KErrNone); sl@0: file1.Close(); sl@0: sl@0: r=file1.Replace(TheFs,KFilePri,EFileWrite); sl@0: test(r==KErrNone); sl@0: sl@0: r=file1.Rename(KFilePri3); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: file1.Close(); sl@0: } sl@0: sl@0: sl@0: LOCAL_C void RDirtest() sl@0: // sl@0: // sl@0: // sl@0: { sl@0: //system sl@0: dirNameBuf.Zero(); sl@0: dirNameBuf = KSystemPath; sl@0: dirNameBuf[0]=(TText)gDriveToTest; sl@0: r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal); sl@0: test(r==KErrPermissionDenied); sl@0: dir.Close(); sl@0: r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries); sl@0: test(r==KErrPermissionDenied); sl@0: dirNameBuf.Zero(); sl@0: delete dirEntries; sl@0: //Private//falseid sl@0: dirNameBuf=KPrivateFalseID; sl@0: dirNameBuf[0]=(TText)gDriveToTest; sl@0: r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal); sl@0: test(r==KErrPermissionDenied); sl@0: dir.Close(); sl@0: r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries); sl@0: test(r==KErrPermissionDenied); sl@0: dirNameBuf.Zero(); sl@0: delete dirEntries; sl@0: //Private sl@0: dirNameBuf=KPrivatePath; sl@0: dirNameBuf[0]=(TText)gDriveToTest; sl@0: r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal); sl@0: test(r==KErrPermissionDenied); sl@0: dir.Close(); sl@0: r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries); sl@0: test(r==KErrPermissionDenied); sl@0: dirNameBuf.Zero(); sl@0: delete dirEntries; sl@0: //Private/uid sl@0: TheFs.PrivatePath(dirNameBuf); sl@0: dirNameBuf.Insert(0,_L("?:")); sl@0: dirNameBuf[0]=(TText)gDriveToTest; sl@0: r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal); sl@0: test(r==KErrNone); sl@0: dir.Close(); sl@0: r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries); sl@0: test(r==KErrNone); sl@0: dirNameBuf.Zero(); sl@0: delete dirEntries; sl@0: //Resource sl@0: dirNameBuf=KResourcePath; sl@0: dirNameBuf[0]=(TText)gDriveToTest; sl@0: r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal); sl@0: test(r==KErrNone || r==KErrPathNotFound || r==KErrNotFound); sl@0: r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries); sl@0: test(r==KErrNone || r==KErrPathNotFound || r==KErrNotFound); sl@0: dir.Close(); sl@0: delete dirEntries; sl@0: } sl@0: sl@0: sl@0: LOCAL_C void DiskAdminTest() sl@0: // sl@0: // test diskadministration capabilitiy sl@0: // sl@0: { sl@0: r=TheFs.FileSystemName(fsname,gTheDriveNum); sl@0: test(r==KErrNone); sl@0: r = DismountFileSystem(TheFs, fsname, gTheDriveNum); sl@0: test(r==KErrNone); sl@0: // r=TheFs.RemoveFileSystem(fsname); //can not test due to bug else where fix exists sl@0: // test(r==KErrPermissionDenied); sl@0: // r=TheFs.AddFileSystem(fsname); sl@0: // test(r==KErrPermissionDenied); sl@0: r = MountFileSystem(TheFs, fsname, gTheDriveNum); sl@0: test(r==KErrNone); sl@0: r=TheFs.SetDriveName(gTheDriveNum,KDriveName); sl@0: test(r==KErrNone); sl@0: r=TheFs.SetVolumeLabel(KVolLable, gTheDriveNum); sl@0: test(r==KErrNone || r==KErrNotSupported); sl@0: sl@0: systemRFstest(); sl@0: resourceRFstest(); sl@0: privateRFstest(); sl@0: privateSIDRFstest(); sl@0: privateFalseIDRFstest(); sl@0: sl@0: systemRFiletest(); sl@0: resourceRFiletest(); sl@0: privateRFiletest(); sl@0: privateSIDRFiletest(); sl@0: privatefalseIDRFiletest(); sl@0: sl@0: //disk changes to sys and pri paths should have completed these sl@0: test(aStat4 == KRequestPending); sl@0: TheFs.NotifyChangeCancel(aStat4); sl@0: test(aStat4==KErrCancel); sl@0: sl@0: User::WaitForRequest(aStat3); sl@0: test(aStat1==KErrPermissionDenied); sl@0: test(aStat2==KErrPermissionDenied); sl@0: test(aStat3==KErrNone); sl@0: sl@0: r=TheFs.SetSessionPath(systestname); sl@0: test(r==KErrPermissionDenied); sl@0: sl@0: //Test RRawDisk class sl@0: r=rawdisk.Open(TheFs,gTheDriveNum); sl@0: test(r==KErrPermissionDenied); sl@0: rawdisk.Close(); sl@0: sl@0: RDirtest(); sl@0: sl@0: #ifdef __WINS__ sl@0: if (User::UpperCase(driveBuf[0]) != 'C') sl@0: #endif sl@0: { sl@0: //Test RFormat class sl@0: r=format.Open(TheFs,driveBuf,EHighDensity,count); sl@0: test(r==KErrNone); sl@0: sl@0: while(count) sl@0: { sl@0: TInt r=format.Next(count); sl@0: test(r==KErrNone); sl@0: } sl@0: format.Close(); sl@0: } sl@0: sl@0: driveBuf[0]=(TText)gDriveToTest; sl@0: r=TheFs.ScanDrive(driveBuf); sl@0: test(r==KErrNone || r==KErrNotSupported); sl@0: r=TheFs.CheckDisk(driveBuf); sl@0: test(r==KErrNone || r==KErrNotSupported); sl@0: } sl@0: sl@0: sl@0: sl@0: LOCAL_C void TestCaps() sl@0: // sl@0: // test format etc that require certain capabilities sl@0: // sl@0: { sl@0: driveBuf[0]=(TText)gDriveToTest; sl@0: r=TheFs.SessionPath(temp); sl@0: test(r==KErrNone); sl@0: sl@0: test.Printf(_L("Session path: %S"),&temp); sl@0: sl@0: r=TheFs.CreatePrivatePath(gTheDriveNum); sl@0: test(r==KErrNone || r== KErrAlreadyExists); sl@0: sl@0: TBuf<18> tempPri; sl@0: r=TheFs.PrivatePath(tempPri); sl@0: test(r==KErrNone); sl@0: theprivatepath = _L("?:"); sl@0: theprivatepath.Append(tempPri); sl@0: sl@0: DiskAdminTest(); sl@0: sl@0: TFileName thesessionpath; sl@0: sl@0: r=TheFs.SetSessionToPrivate(gTheDriveNum); sl@0: test(r==KErrNone); sl@0: r=TheFs.SessionPath(thesessionpath); sl@0: test(r==KErrNone); sl@0: sl@0: test(thesessionpath == theprivatepath); sl@0: } sl@0: sl@0: sl@0: LOCAL_C void CleanupL() sl@0: // sl@0: // Clean up tests sl@0: // sl@0: { sl@0: test.Next(_L("Delete test directory")); sl@0: CFileMan* fMan=CFileMan::NewL(TheFs); sl@0: TInt r=fMan->RmDir(gSessionPath); sl@0: test(r==KErrNone || KErrPathNotFound); sl@0: delete fMan; sl@0: } sl@0: sl@0: GLDEF_C void CallTestsL(/*TChar aDriveLetter*/) sl@0: // sl@0: // Do all tests sl@0: // sl@0: { sl@0: if( !PlatSec::IsCapabilityEnforced(ECapabilityDiskAdmin)) sl@0: { sl@0: test.Printf(_L("Capability ECapabilityDiskAdmin not enabled - leaving t_dcdiskadmin")); sl@0: test.Printf(_L("\n")); // Prevent overwrite by next print sl@0: return; sl@0: } sl@0: sl@0: TurnAllocFailureOff(); sl@0: TheFs.CharToDrive(gDriveToTest,gTheDriveNum); sl@0: sl@0: TBuf<30> sesspath; sl@0: sesspath=_L("?:\\"); sl@0: sesspath[0] = (TText)gDriveToTest; sl@0: sl@0: TInt r= TheFs.SetSessionPath(sesspath); sl@0: test(r==KErrNone); sl@0: sl@0: //cleanup from previous run of this test sl@0: TBuf<2> cmd; sl@0: cmd.SetLength(1); sl@0: cmd[0] = (TText)gDriveToTest; sl@0: RProcess tp; sl@0: r=tp.Create(_L("clean_prepdc.exe"),sesspath); sl@0: test(r==KErrNone); sl@0: { sl@0: TRequestStatus ps; sl@0: tp.Logon(ps); sl@0: tp.Resume(); sl@0: tp.Close(); sl@0: User::WaitForRequest(ps); sl@0: } sl@0: sl@0: //check double mode ie that Defpath still works sl@0: RFs fs1; sl@0: RFs fs2; sl@0: sl@0: r=fs1.Connect(); sl@0: test(r==KErrNone); sl@0: r=fs1.SessionPath(sesspath); sl@0: test(r==KErrNone); sl@0: test.Printf(_L("session1 Path=%S"),&sesspath); sl@0: sl@0: TBuf<30> privatepath; sl@0: r=fs1.SetSessionToPrivate(gTheDriveNum); sl@0: test(r==KErrNone); sl@0: r=fs1.PrivatePath(privatepath); sl@0: test(r==KErrNone); sl@0: r=privatepath.Compare(KExpectedPrivatePath()); sl@0: test(r==0); sl@0: r=fs1.SessionPath(sesspath); sl@0: test(r==KErrNone); sl@0: r=privatepath.Compare(sesspath.Mid(KPathPosition)); sl@0: test(r==0); sl@0: r=fs1.CreatePrivatePath(gTheDriveNum); sl@0: test(r==KErrNone); sl@0: fs1.Close(); sl@0: sl@0: r=fs2.Connect(); sl@0: test(r==KErrNone); sl@0: r=fs2.SessionPath(sesspath); sl@0: test(r==KErrNone); sl@0: test.Printf(_L("session2 Path=%S"),&sesspath); sl@0: fs2.Close(); sl@0: sl@0: TestCaps(); sl@0: sl@0: test.Printf(_L("No of files open=%d"), TheFs.ResourceCount()); sl@0: sl@0: CleanupL(); sl@0: }