os/kernelhwsrv/kerneltest/f32test/server/t_dcnone.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #include <f32file.h>
    17 #include <e32test.h>
    18 #include <e32std.h>
    19 #include <e32std_private.h>
    20 #include <e32def.h>
    21 #include <e32def_private.h>
    22 #include <e32svr.h>
    23 #include "t_server.h"
    24 
    25 GLDEF_D RTest test(_L("t_dcnone"));
    26 GLDEF_D TTime gTimeNow;
    27 LOCAL_D TInt gTheDriveNum;
    28 
    29 //_LIT(KDefPath, "\\Default\\");
    30 
    31 const TInt KPathPosition = 2;
    32 _LIT(KExpectedPrivatePath, "\\Private\\00000001\\");
    33 
    34 
    35 _LIT(KResourcePath, "?:\\Resource\\");
    36 _LIT(KSystemPath,	"?:\\Sys\\");
    37 _LIT(KPrivatePath,	"?:\\Private\\");
    38 _LIT(KPrivateFalseID,	"?:\\Private\\FFFFFFFF\\");
    39 _LIT(KDriveName,	"Billy");
    40 //_LIT(KVolLable,		"Benny");
    41 
    42 _LIT(KFileSys,	"systemfile.txt");
    43 //_LIT(KFileSys2,	"systemfile.tmp");
    44 _LIT(KFileSys3, "sysfile.rna");
    45 
    46 _LIT(KFilePri,	"privatefile.txt");
    47 _LIT(KFilePri2,	"privatefile.tmp");
    48 _LIT(KFilePri3,	"prifile.rna");
    49 
    50 _LIT(KFileRes,	"resourcefile.txt");
    51 //_LIT(KFileRes2,	"resourcefile.tmp");
    52 _LIT(KFileRes3,	"resfile.rna");
    53 
    54 _LIT(KMkDirSub,"Subdir\\");
    55 _LIT(KOldFile,"?:\\Anyold.txt");
    56 //_LIT(KNullPath, "");
    57 //_LIT(KLFFSName, "Lffs");
    58 
    59 _LIT(KWildPath, "Z:\\SYS\\");
    60 _LIT(KWildFile, "*");
    61 
    62 _LIT(KPrivatePathTest1,	"\\Private\\00000001");
    63 _LIT(KPrivatePathTest2, "\\Private\\FFFFFFFF");
    64 _LIT(KPrivatePathTest3, "\\Private\\FFFFFFFF\\");
    65 TInt theDrive=0;
    66 TCapability TheCaps;
    67 TBuf<4> driveBuf=_L("?:\\");
    68 RFormat format;
    69 TInt count;
    70 RRawDisk rawdisk;
    71 RFile file1;
    72 RFile file2;
    73 RDir	dir;
    74 CDir*	dirEntries;
    75 TInt r;
    76 TBuf<40> fsname;
    77 TBuf<40> systestname;
    78 TBuf<40> pritestname;
    79 TBuf<40> restestname;
    80 TBuf<40> theprivatepath;
    81 TBuf<40> pritestfalseidname;
    82 TBuf<40> mkdirname;
    83 TFileName fromTemp;
    84 
    85 
    86 TBuf<25> prifilename;
    87 TBuf<25> sysfilename;
    88 TBuf<30> realName;
    89 TBuf<40> shortfilename;
    90 TBuf<40> longfilename;
    91 
    92 TRequestStatus aStat1;
    93 TRequestStatus aStat2;
    94 TRequestStatus aStat3;
    95 TRequestStatus aStat4;
    96 
    97 TVolumeInfo aVolInfo;
    98 //	TDriveInfo adriveInfo;
    99 
   100 TBuf<40> systestfile;
   101 TBuf<40> pritestfile;
   102 TBuf<40> restestfile;
   103 TBuf<40> systestfile1;
   104 TBuf<40> pritestfile1;
   105 TBuf<40> restestfile1;
   106 
   107 TTime testtime;
   108 TBuf<20> oldName;
   109 TBuf<25> temp;
   110 TEntry entry;
   111 
   112 
   113 
   114 
   115 LOCAL_C void TestPathCheck()
   116 //
   117 // This test case is brought in by INC054580
   118 // (NTT Renaming sys ¨Cfolder on C -drive on H2 allows user to access sys -files)
   119 //
   120     {
   121     TInt r = TheFs.Rename(_L("\\sys"), _L("\\sysbad"));
   122     test(r == KErrPermissionDenied);
   123     r = TheFs.Rename(_L("\\resource"), _L("\\resourcebad"));
   124     test(r == KErrPermissionDenied);
   125     r = TheFs.Rename(_L("\\private"), _L("\\privatebad"));
   126     test(r == KErrPermissionDenied);
   127     }
   128 
   129 LOCAL_C void systemRFstest()
   130 //
   131 //
   132 //
   133 	{
   134 	systestname=KSystemPath;
   135 	systestname[0]=(TText)('A' + gTheDriveNum);
   136 	
   137 	mkdirname.Zero();
   138 	mkdirname.Append(systestname);
   139 	mkdirname.Append(KMkDirSub);
   140 	r=TheFs.MkDirAll(mkdirname);	
   141 	test(r==KErrPermissionDenied);
   142 
   143 	r=TheFs.RmDir(mkdirname);	
   144 	test(r==KErrPermissionDenied);
   145 
   146 	r=TheFs.SetSubst(systestname,EDriveP);
   147 	test(r==KErrPermissionDenied);
   148 	
   149 	r=TheFs.SetSessionPath(systestname);
   150 	test(r==KErrPermissionDenied);
   151 
   152 	TheFs.NotifyChange(ENotifyAll,aStat1,systestname);
   153 	test(aStat1==KErrPermissionDenied);
   154 
   155 	systestfile=KSystemPath;
   156 	systestfile[0]=(TText)('A' + gTheDriveNum);
   157 	systestfile1=systestfile;
   158 	systestfile.Append(KFileSys);
   159 	systestfile1.Append(KFileSys3);
   160 	
   161 	oldName=KOldFile;
   162 	oldName[0]=(TText)gDriveToTest;
   163 
   164 	r=TheFs.GetShortName(systestfile, shortfilename);
   165 	test(r==KErrPermissionDenied);
   166 
   167 	r=TheFs.GetLongName(systestfile1, longfilename);
   168 	test(r==KErrPermissionDenied);
   169 
   170 	r=file1.Create(TheFs,oldName,EFileWrite);
   171 	test(r==KErrNone || r==KErrAlreadyExists);
   172 	file1.Close();
   173 
   174 	r=TheFs.Replace(oldName,systestfile);
   175 	test(r==KErrPermissionDenied);
   176 	
   177 	r=TheFs.Rename(systestfile,systestfile1);
   178 	test(r==KErrPermissionDenied);
   179 	
   180 	// check that the entry for the system directory itself can be retrieved with no error
   181 	// - with or without a slash
   182 	TPtrC restrictedDir(systestname.Ptr(), systestname.Length());
   183 	r=TheFs.Entry(restrictedDir, entry);
   184 	test.Printf(_L("RFs::Entry(%S) returned %d"), &restrictedDir, r);
   185 	test(r==KErrNone);
   186 	test (entry.iAtt & KEntryAttDir);
   187 
   188 	TPtrC restrictedDirWithNoBackSlash(restrictedDir.Ptr(), restrictedDir.Length()-1);
   189 	r=TheFs.Entry(restrictedDirWithNoBackSlash,entry);
   190 	test.Printf(_L("RFs::Entry(%S) returned %d"), &restrictedDirWithNoBackSlash, r);
   191 	test(r==KErrNone);
   192 
   193 	r=TheFs.Entry(systestfile1,entry);
   194 	test(r==KErrPermissionDenied);
   195 	
   196 	r=TheFs.SetEntry(systestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
   197 	test(r==KErrPermissionDenied);
   198 
   199 	r=TheFs.Delete(systestfile1);
   200 	test(r==KErrPermissionDenied);
   201 
   202 	}
   203 
   204 
   205 LOCAL_C void resourceRFstest()
   206 //
   207 //
   208 //
   209 	{
   210 
   211 	restestname=KResourcePath;
   212 	restestname[0]=(TText)('A' + gTheDriveNum);
   213 	
   214 	mkdirname.Zero();
   215 	mkdirname.Append(restestname);
   216 	mkdirname.Append(KMkDirSub);
   217 	r=TheFs.MkDirAll(mkdirname);	
   218 	test(r==KErrPermissionDenied);
   219 
   220 	TheFs.RmDir(mkdirname);
   221 	test(r==KErrPermissionDenied);
   222 
   223 	r=TheFs.SetSubst(restestname,EDriveP);
   224 	test(r==KErrPermissionDenied);
   225 	
   226 	r=TheFs.RealName(_L("P:\\File.XXX"),realName);
   227 	test(r==KErrNone);
   228 
   229 	r=TheFs.SetSessionPath(restestname);
   230 	test(r==KErrNone);
   231 	
   232 	TheFs.NotifyChange(ENotifyAll,aStat4,restestname);
   233 	test(aStat4==KRequestPending);
   234 
   235 
   236 	restestfile=KResourcePath;
   237 	restestfile[0]=(TText)('A' + gTheDriveNum);
   238 	restestfile1=restestfile;
   239 	restestfile.Append(KFileRes);
   240 	restestfile1.Append(KFileRes3);
   241 	
   242 	oldName=KOldFile;
   243 	oldName[0]=(TText)gDriveToTest;
   244 
   245 	r=TheFs.GetShortName(restestfile, shortfilename);
   246 	test(r==KErrNone || KErrPathNotFound);
   247 
   248 	r=TheFs.GetLongName(restestfile1, longfilename);
   249 	test(r==KErrNone || KErrPathNotFound);
   250 
   251 	r=file1.Create(TheFs,oldName,EFileWrite);
   252 	test(r==KErrNone || r==KErrAlreadyExists);
   253 	file1.Close();
   254 
   255 	r=TheFs.Replace(oldName,restestfile);
   256 	test(r==KErrPermissionDenied);
   257 	
   258 	r=TheFs.Rename(restestfile,restestfile1);
   259 	test(r==KErrPermissionDenied);
   260 	
   261 	// check that the entry for the resource directory itself can be retrieved with no error
   262 	// - with or without a slash
   263 	TPtrC restrictedDir(restestname.Ptr(), restestname.Length());
   264 	r=TheFs.Entry(restrictedDir, entry);
   265 	test.Printf(_L("RFs::Entry(%S) returned %d"), &restrictedDir, r);
   266 	test(r==KErrNone);
   267 	test (entry.iAtt & KEntryAttDir);
   268 
   269 	TPtrC restrictedDirWithNoBackSlash(restrictedDir.Ptr(), restrictedDir.Length()-1);
   270 	r=TheFs.Entry(restrictedDirWithNoBackSlash,entry);
   271 	test.Printf(_L("RFs::Entry(%S) returned %d"), &restrictedDirWithNoBackSlash, r);
   272 	test(r==KErrNone);
   273 
   274 	r=TheFs.Entry(restestfile1,entry);
   275 	test(r==KErrNone || r==KErrNotFound);
   276 
   277 	r=TheFs.SetEntry(restestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
   278 	test(r==KErrPermissionDenied);
   279 
   280 	r=TheFs.Delete(restestfile1);
   281 	test(r==KErrPermissionDenied);
   282 
   283 	}
   284 
   285 
   286 LOCAL_C void privatefalseIDRFstest()
   287 //
   288 //
   289 //
   290 	{
   291 	pritestfalseidname=KPrivateFalseID;
   292 	pritestfalseidname[0]=(TText)('A' + gTheDriveNum);
   293 
   294 	mkdirname.Zero();
   295 	mkdirname.Append(pritestfalseidname);
   296 	mkdirname.Append(KMkDirSub);
   297 
   298 	r=TheFs.MkDirAll(mkdirname);	
   299 	test(r==KErrPermissionDenied);
   300 
   301 	r=TheFs.RmDir(mkdirname);	
   302 	test(r==KErrPermissionDenied);
   303 
   304 	r=TheFs.SetSubst(pritestfalseidname,EDriveP);
   305 	test(r==KErrPermissionDenied); 
   306 
   307 	TheFs.NotifyChange(ENotifyAll,aStat2,pritestfalseidname);
   308 	test(aStat2==KErrPermissionDenied);
   309 
   310 
   311 	pritestfile=KPrivateFalseID;
   312 	pritestfile[0]=(TText)('A' + gTheDriveNum);
   313 	pritestfile1=pritestfile;
   314 	pritestfile.Append(KFilePri2);
   315 	pritestfile1.Append(KFilePri3);
   316 	
   317 	oldName=KOldFile;
   318 	oldName[0]=(TText)gDriveToTest;
   319 
   320 	r=TheFs.GetShortName(pritestfile, shortfilename);
   321 	test(r==KErrPermissionDenied);
   322 
   323 	r=TheFs.GetLongName(pritestfile1, longfilename);
   324 	test(r==KErrPermissionDenied);
   325 
   326 	r=file1.Create(TheFs,oldName,EFileWrite);
   327 	test(r==KErrNone || r==KErrAlreadyExists);
   328 	file1.Close();
   329 
   330 	r=TheFs.Replace(oldName,pritestfile);
   331 	test(r==KErrPermissionDenied);
   332 	
   333 	r=TheFs.Rename(pritestfile,pritestfile1);
   334 	test(r==KErrPermissionDenied);
   335 	
   336 	r=TheFs.Entry(pritestfile1,entry);
   337 	test(r==KErrPermissionDenied);
   338 
   339 	r=TheFs.SetEntry(pritestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
   340 	test(r==KErrPermissionDenied);
   341 
   342 	r=TheFs.Delete(pritestfile1);
   343 	test(r==KErrPermissionDenied);
   344 
   345 	}
   346 
   347 
   348 
   349 LOCAL_C void privateRFstest()
   350 //
   351 //
   352 //
   353 	{
   354 	pritestname=KPrivatePath;
   355 	pritestname[0]=(TText)('A' + gTheDriveNum);
   356 
   357 	mkdirname.Zero();
   358 	mkdirname.Append(pritestname);
   359 	mkdirname.Append(KMkDirSub);
   360 
   361 	r=TheFs.MkDirAll(mkdirname);	
   362 	test(r==KErrPermissionDenied);
   363 
   364 	r=TheFs.RmDir(mkdirname);	
   365 	test(r==KErrPermissionDenied);
   366 
   367 	r=TheFs.SetSubst(pritestname,EDriveP);
   368 	test(r==KErrPermissionDenied); 
   369 
   370 	TheFs.NotifyChange(ENotifyAll,aStat2,pritestname);
   371 	test(aStat2==KErrPermissionDenied);
   372 
   373 
   374 	pritestfile=KPrivatePath;
   375 	pritestfile[0]=(TText)('A' + gTheDriveNum);
   376 	pritestfile1=pritestfile;
   377 	pritestfile.Append(KFilePri2);
   378 	pritestfile1.Append(KFilePri3);
   379 	
   380 	oldName=KOldFile;
   381 	oldName[0]=(TText)gDriveToTest;
   382 
   383 	r=TheFs.GetShortName(pritestfile, shortfilename);
   384 	test(r==KErrPermissionDenied);
   385 
   386 	r=TheFs.GetLongName(pritestfile1, longfilename);
   387 	test(r==KErrPermissionDenied);
   388 
   389 	r=file1.Create(TheFs,oldName,EFileWrite);
   390 	test(r==KErrNone || r==KErrAlreadyExists);
   391 	file1.Close();
   392 
   393 	r=TheFs.Replace(oldName,pritestfile);
   394 	test(r==KErrPermissionDenied);
   395 	
   396 	r=TheFs.Rename(pritestfile,pritestfile1);
   397 	test(r==KErrPermissionDenied);
   398 	
   399 	r=TheFs.Entry(pritestfile1,entry);
   400 	test(r==KErrPermissionDenied);
   401 
   402 	// check that the entry for the private directory itself can be retrieved with no error
   403 	// - with or without a slash
   404 	TPtrC restrictedDir(pritestname.Ptr(), pritestname.Length());
   405 	r=TheFs.Entry(restrictedDir, entry);
   406 	test.Printf(_L("RFs::Entry(%S) returned %d"), &restrictedDir, r);
   407 	test(r==KErrNone);
   408 	test (entry.iAtt & KEntryAttDir);
   409 
   410 	TPtrC restrictedDirWithNoBackSlash(restrictedDir.Ptr(), restrictedDir.Length()-1);
   411 	r=TheFs.Entry(restrictedDirWithNoBackSlash,entry);
   412 	test.Printf(_L("RFs::Entry(%S) returned %d"), &restrictedDirWithNoBackSlash, r);
   413 	test(r==KErrNone);
   414 
   415 	r=TheFs.SetEntry(pritestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
   416 	test(r==KErrPermissionDenied);
   417 
   418 	r=TheFs.Delete(pritestfile1);
   419 	test(r==KErrPermissionDenied);
   420 
   421 	}
   422 
   423 
   424 LOCAL_C void privateSIDRFstest()
   425 //
   426 //
   427 //
   428 	{
   429 	theprivatepath[0]=(TText)gDriveToTest;	
   430 	test.Printf(_L("the Private Path = %S"),&theprivatepath);
   431 
   432 	mkdirname.Zero();
   433 	mkdirname.Append(theprivatepath);
   434 	mkdirname.Append(KMkDirSub);
   435 	r=TheFs.MkDirAll(mkdirname);	
   436 	test(r==KErrNone);
   437 
   438 	r=TheFs.RmDir(mkdirname);	
   439 	test(r==KErrNone);
   440 
   441 	r=TheFs.SetSubst(theprivatepath,EDriveP);	
   442 	test(r==KErrPermissionDenied);
   443 
   444 	r=TheFs.RealName(_L("P:\\File.XXX"),realName);
   445 	test(r==KErrNone);
   446 	
   447 	r=TheFs.SetSessionPath(theprivatepath);
   448 	test(r==KErrNone);
   449 
   450 	TheFs.NotifyChange(ENotifyAll,aStat3,theprivatepath);
   451 	test(aStat3==KRequestPending);
   452 
   453 
   454 	pritestfile=theprivatepath;
   455 	pritestfile[0]=(TText)('A' + gTheDriveNum);
   456 	pritestfile1=pritestfile;
   457 	pritestfile.Append(KFilePri2);
   458 	pritestfile1.Append(KFilePri3);
   459 	
   460 	oldName=KOldFile;
   461 	oldName[0]=(TText)gDriveToTest;
   462 
   463 	r=TheFs.GetShortName(pritestfile, shortfilename);
   464 	test(r==KErrNone || KErrPathNotFound);
   465 
   466 	r=TheFs.GetLongName(pritestfile1, longfilename);
   467 	test(r==KErrNone || KErrPathNotFound);
   468 
   469 	r=file1.Create(TheFs,oldName,EFileWrite);
   470 	test(r==KErrNone || r==KErrAlreadyExists);
   471 	file1.Close();
   472 
   473 	r=TheFs.Replace(oldName,pritestfile);
   474 	test(r==KErrNone);
   475 	
   476 	r=TheFs.Rename(pritestfile,pritestfile1);
   477 	test(r==KErrNone || r==KErrAlreadyExists);
   478 	
   479 	r=TheFs.Entry(pritestfile1,entry);
   480 	test(r==KErrNone);
   481 
   482 	//Test Entry with correct SID
   483 	r=TheFs.Entry(theprivatepath,entry);
   484 	test(r==KErrNone);
   485 	
   486 	//Test Entry with correct SID and without "//" appended
   487 	r=TheFs.Entry(KPrivatePathTest1,entry);
   488 	test(r==KErrNone);
   489 	
   490 	//Test Entry with invalid SID, without // appended
   491 	r=TheFs.Entry(KPrivatePathTest2,entry);
   492 	test(r==KErrPermissionDenied);
   493 	
   494 	//Test Entry with invalid SID
   495 	r=TheFs.Entry(KPrivatePathTest3,entry);
   496 	test(r==KErrPermissionDenied);
   497 
   498 	r=TheFs.SetEntry(pritestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
   499 	test(r==KErrNone);
   500 
   501 	r=TheFs.Delete(pritestfile1);
   502 	test(r==KErrNone);
   503 
   504 	}
   505 
   506 
   507 LOCAL_C void systemRFiletest()
   508 //
   509 //
   510 //
   511 	{
   512 	r=TheFs.SetSessionPath(systestname);
   513 	test(r==KErrPermissionDenied);
   514 
   515 	r=file1.Temp(TheFs,systestname,fromTemp,EFileWrite);
   516 	test(r==KErrPermissionDenied);
   517 
   518 
   519 	TBuf<25> sysfilename;
   520 	sysfilename.Append(systestname);
   521 	sysfilename.Append(KFileSys);
   522 
   523 	r=file1.Create(TheFs,sysfilename,EFileWrite);
   524 	test(r==KErrPermissionDenied);
   525 
   526 	r=file1.Open(TheFs,sysfilename,EFileWrite);
   527 	test(r==KErrPermissionDenied);
   528 	
   529 	r=file1.Open(TheFs,sysfilename,EFileRead);
   530 	test(r==KErrPermissionDenied);
   531 	
   532 	r=file1.Replace(TheFs,sysfilename,EFileWrite);
   533 	test(r==KErrPermissionDenied);
   534 
   535 	TFindFile finder(TheFs);
   536 	CDir* dir = NULL;
   537 	r=finder.FindWildByDir(KWildFile, KWildPath, dir);
   538 	if (!(r==KErrPermissionDenied))
   539 		test.Printf(_L("T_DCNONE: test find wildcards r = %d (expected KErrPermissionDenied)\n"), r);
   540 	test(r==KErrPermissionDenied);
   541 	delete dir;
   542 	}
   543 
   544 LOCAL_C void resourceRFiletest()
   545 //
   546 //
   547 //
   548 	{
   549 	r=TheFs.SetSessionPath(restestname);
   550 	test(r==KErrNone);
   551 
   552 	r=file1.Temp(TheFs,restestname,fromTemp,EFileWrite);
   553 	test(r==KErrPermissionDenied);
   554 	file1.Close();
   555 
   556 	r=file1.Create(TheFs,KFileRes,EFileWrite);
   557 	test(r==KErrPermissionDenied);
   558 	file1.Close();
   559 
   560 	r=file1.Open(TheFs,KFileRes,EFileWrite);
   561 	test(r==KErrPermissionDenied);
   562 	file1.Close();
   563 
   564 	r=file1.Open(TheFs,KFileRes,EFileRead|EFileShareReadersOnly);
   565 	test(r==KErrNone || r==KErrPathNotFound);
   566 	file1.Close();
   567 
   568 	r=file1.Open(TheFs,KFileRes,EFileShareReadersOrWriters|EFileRead);
   569 	test(r==KErrNone || r==KErrPathNotFound);
   570 	file1.Close();
   571 
   572 	r=file1.Open(TheFs,KFileRes,EFileShareReadersOrWriters|EFileWrite);
   573 	test(r==KErrPermissionDenied);
   574 	file1.Close();
   575 
   576 	r=file1.Open(TheFs,KFileRes,EFileShareReadersOnly);
   577 	test(r==KErrNone || r==KErrPathNotFound);
   578 
   579 	r=file1.ChangeMode(EFileShareExclusive);	//this is not illegal though will prevent shared access to resource which is nit my fault but may be desirable to prevent
   580 	test(r==KErrNone || r==KErrPathNotFound);
   581 
   582 	//this operation is prevented as you can not open a file for write access in the resource directory
   583 	r=file1.Rename(KFileRes3);
   584 	test(r==KErrPermissionDenied || r==KErrAccessDenied);
   585 
   586 	file1.Close();
   587 
   588 	r=file1.Replace(TheFs,KFileRes,EFileWrite);
   589 	test(r==KErrPermissionDenied);
   590 	file1.Close();
   591 
   592 	}
   593 
   594 
   595 LOCAL_C void privatefalseIDRFiletest()
   596 //
   597 //
   598 //
   599 	{
   600 
   601 	r=TheFs.SetSessionPath(pritestfalseidname);
   602 	test(r==KErrPermissionDenied);
   603 
   604 	r=file1.Temp(TheFs,pritestfalseidname,fromTemp,EFileWrite);
   605 	test(r==KErrPermissionDenied);
   606 
   607 	TBuf<25> prifilename;
   608 	prifilename.Append(pritestname);
   609 	prifilename.Append(KFileSys);
   610 
   611 	r=file1.Create(TheFs,prifilename,EFileWrite);
   612 	test(r==KErrPermissionDenied);
   613 
   614 
   615 	r=file1.Open(TheFs,prifilename,EFileWrite);
   616 	test(r==KErrPermissionDenied);
   617 
   618 	r=file1.Open(TheFs,prifilename,EFileRead);
   619 	test(r==KErrPermissionDenied);
   620 
   621 	
   622 	r=file1.Replace(TheFs,prifilename,EFileWrite);
   623 	test(r==KErrPermissionDenied);
   624 
   625 	}
   626 
   627 
   628 
   629 LOCAL_C void privateRFiletest()
   630 //
   631 //
   632 //
   633 	{
   634 
   635 	r=TheFs.SetSessionPath(pritestname);
   636 	test(r==KErrPermissionDenied);
   637 
   638 	r=file1.Temp(TheFs,pritestname,fromTemp,EFileWrite);
   639 	test(r==KErrPermissionDenied);
   640 
   641 	TBuf<25> prifilename;
   642 	prifilename.Append(pritestname);
   643 	prifilename.Append(KFileSys);
   644 
   645 	r=file1.Create(TheFs,prifilename,EFileWrite);
   646 	test(r==KErrPermissionDenied);
   647 
   648 
   649 	r=file1.Open(TheFs,prifilename,EFileWrite);
   650 	test(r==KErrPermissionDenied);
   651 
   652 	
   653 	r=file1.Open(TheFs,prifilename,EFileRead);
   654 	test(r==KErrPermissionDenied);
   655 
   656 
   657 	r=file1.Replace(TheFs,prifilename,EFileWrite);
   658 	test(r==KErrPermissionDenied);
   659 
   660 	}
   661 
   662 LOCAL_C void privateSIDRFiletest()
   663 //
   664 //
   665 //
   666 	{
   667 
   668 	r=TheFs.SetSessionToPrivate(gTheDriveNum);
   669 	test(r==KErrNone);
   670 		
   671 	r=file1.Temp(TheFs,theprivatepath,fromTemp,EFileWrite);
   672 	test(r==KErrNone);
   673 	file1.Close();
   674 	r=file1.Create(TheFs,KFilePri,EFileWrite);
   675 	test(r==KErrNone || r==KErrAlreadyExists);
   676 	file1.Close();
   677 	r=file1.Open(TheFs,KFilePri,EFileWrite);
   678 	test(r==KErrNone);
   679 	file1.Close();
   680 	r=file1.Open(TheFs,KFilePri,EFileRead);
   681 	test(r==KErrNone);
   682 	file1.Close();
   683 	r=file1.Replace(TheFs,KFilePri,EFileWrite);
   684 	test(r==KErrNone);
   685 	r=file1.Rename(KFilePri3);
   686 	test(r==KErrNone || r==KErrAlreadyExists);
   687 	file1.Close();
   688 
   689 	}
   690 
   691 
   692 LOCAL_C void RDirtest()
   693 //
   694 //
   695 //
   696 	{
   697 	//system
   698 
   699 	TBuf<30> dirNameBuf(KSystemPath);
   700 	dirNameBuf[0]=(TText)gDriveToTest;
   701 	r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
   702 	test(r==KErrPermissionDenied);
   703 	dir.Close();
   704 	r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
   705 	test(r==KErrPermissionDenied);
   706 	dirNameBuf.Zero();
   707 	delete dirEntries;
   708 	
   709 	dirNameBuf=KPrivateFalseID;
   710 	dirNameBuf[0]=(TText)gDriveToTest;
   711 	r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
   712 	test(r==KErrPermissionDenied);
   713 	dir.Close();
   714 	r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
   715 	test(r==KErrPermissionDenied);
   716 	dirNameBuf.Zero();
   717 	delete dirEntries;
   718 
   719 	//Private
   720 	dirNameBuf=KPrivatePath;
   721 	dirNameBuf[0]=(TText)gDriveToTest;
   722 	r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
   723 	test(r==KErrPermissionDenied);
   724 	dir.Close();
   725 	r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
   726 	test(r==KErrPermissionDenied);
   727 	dirNameBuf.Zero();
   728 	delete dirEntries;
   729 	//Private/uid
   730 	TheFs.PrivatePath(dirNameBuf);
   731 	dirNameBuf.Insert(0,_L("?:"));
   732 	dirNameBuf[0]=(TText)gDriveToTest;
   733 	r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
   734 	test(r==KErrNone);
   735 	dir.Close();
   736 	r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
   737 	test(r==KErrNone);
   738 	dirNameBuf.Zero();
   739 	delete dirEntries;
   740 	//Resource
   741 	dirNameBuf=KResourcePath;
   742 	dirNameBuf[0]=(TText)gDriveToTest;
   743 	r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
   744 	test(r==KErrNone);
   745 	r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
   746 	test(r==KErrNone);
   747 	dir.Close();
   748 	delete dirEntries;
   749 	}
   750 
   751 
   752 LOCAL_C void TestNoCaps()
   753 //
   754 //	test APIs with no capabilities
   755 //
   756 	{
   757 	r=TheFs.FileSystemName(fsname,gTheDriveNum);
   758 	test(r==KErrNone);
   759 	r = DismountFileSystem(TheFs, fsname, gTheDriveNum);
   760 	test(r==KErrPermissionDenied);
   761 //	r=TheFs.RemoveFileSystem(fsname);	//can not test due to bug elsewhere fix exists
   762 //	test(r==KErrPermissionDenied);
   763 //	r=TheFs.AddFileSystem(fsname);
   764 //	test(r==KErrPermissionDenied);
   765 	r = MountFileSystem(TheFs, fsname, gTheDriveNum);
   766 	test(r==KErrPermissionDenied);
   767 	r=TheFs.SetDriveName(gTheDriveNum,KDriveName);
   768 	test(r==KErrPermissionDenied);
   769 //	r=TheFs.SetVolumeLabel(KVolLable, gTheDriveNum);	//broken on wins C:
   770 //	test(r==KErrPermissionDenied);
   771 
   772 	systemRFstest();
   773 	resourceRFstest();
   774 	privateRFstest();
   775 	privateSIDRFstest();
   776 	privatefalseIDRFstest();
   777 
   778 	systemRFiletest();
   779 	resourceRFiletest();
   780 	privateRFiletest();
   781 	privateSIDRFiletest();
   782 	privatefalseIDRFiletest();
   783 	//disk changes to sys and pri paths should have completed these
   784 	test(aStat4 == KRequestPending);
   785 	TheFs.NotifyChangeCancel(aStat4);
   786 	test(aStat4==KErrCancel);
   787 
   788 
   789 	User::WaitForRequest(aStat3);
   790 	test(aStat1==KErrPermissionDenied);
   791 	test(aStat2==KErrPermissionDenied);
   792 	test(aStat3==KErrNone);
   793 	
   794 	r=TheFs.SetSessionPath(systestname);
   795 	test(r==KErrPermissionDenied);
   796 	
   797 	
   798 //Test RRawDisk class
   799 	r=rawdisk.Open(TheFs,gTheDriveNum);
   800 	test(r==KErrPermissionDenied);
   801 //	rawdisk.Close();
   802 
   803 	r=format.Open(TheFs,driveBuf,EHighDensity,count);
   804 	test(r==KErrPermissionDenied);
   805 
   806 	RDirtest();
   807 
   808 	driveBuf[0]=(TText)gDriveToTest;
   809 	r=TheFs.ScanDrive(driveBuf);
   810 	test(r==KErrPermissionDenied);
   811 	r=TheFs.CheckDisk(driveBuf);
   812 	test(r==KErrPermissionDenied);
   813 	}
   814 
   815 LOCAL_C void TestCaps()
   816 //
   817 //	test format etc that require certain capabilities
   818 //
   819 	{
   820 #ifndef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
   821 	const char myDiagMsg[]="Capability Check Failure";
   822 #endif //!__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
   823 	r=RProcess().HasCapability(ECapabilityAllFiles, __PLATSEC_DIAGNOSTIC_STRING(myDiagMsg));
   824 	test(!r);
   825 	r=RProcess().HasCapability(ECapabilityTCB, __PLATSEC_DIAGNOSTIC_STRING(myDiagMsg));
   826 	test(!r);
   827 	r=RProcess().HasCapability(ECapabilityDiskAdmin, __PLATSEC_DIAGNOSTIC_STRING(myDiagMsg));
   828 	test(!r);
   829 	r=RProcess().HasCapability(ECapability_None, __PLATSEC_DIAGNOSTIC_STRING(myDiagMsg));
   830 	test(r);
   831 
   832 	driveBuf[0]=(TText)gDriveToTest;
   833 	r=TheFs.SessionPath(temp);
   834 	test(r==KErrNone);
   835 
   836 	r=TheFs.CreatePrivatePath(gTheDriveNum);
   837 	test(r==KErrNone || r== KErrAlreadyExists);
   838 
   839 	TBuf<18> tempPri;
   840 	r=TheFs.PrivatePath(tempPri);
   841 	test(r==KErrNone);
   842 	theprivatepath = _L("?:");
   843 	theprivatepath.Append(tempPri);
   844 
   845 	TestNoCaps();
   846 
   847 	TFileName thesessionpath;
   848 	r=TheFs.SetSessionToPrivate(gTheDriveNum);
   849 	test(r==KErrNone);
   850 	r=TheFs.SessionPath(thesessionpath);
   851 	test(r==KErrNone);
   852 	
   853 	test(thesessionpath == theprivatepath);
   854 
   855 	}
   856 
   857 
   858 LOCAL_C void MakeDirs()
   859 //
   860 // Create system and private directories for scan with and without DC
   861 //
   862 	{
   863 	TInt r;
   864 	r = TheFs.MkDir(_L("\\normal\\"));
   865 	test(r == KErrNone || r == KErrAlreadyExists);
   866 	r = TheFs.MkDir(_L("\\normal\\one\\"));
   867 	test(r == KErrNone || r == KErrAlreadyExists);
   868 	r = TheFs.MkDir(_L("\\normal\\two\\"));
   869 	test(r == KErrNone || r == KErrAlreadyExists);
   870 	r = TheFs.MkDir(_L("\\sys\\"));
   871 	test(r == KErrPermissionDenied);
   872 	r = TheFs.MkDir(_L("\\sys\\one\\"));
   873 	test(r == KErrPermissionDenied);
   874 	r = TheFs.MkDir(_L("\\sys\\two\\"));
   875 	test(r == KErrPermissionDenied);
   876 	r = TheFs.MkDir(_L("\\private\\"));
   877 	test(r == KErrPermissionDenied);
   878 	r = TheFs.MkDir(_L("\\private\\one\\"));
   879 	test(r == KErrPermissionDenied);
   880 	r = TheFs.MkDir(_L("\\private\\two\\"));
   881 	test(r == KErrPermissionDenied);
   882 	r = TheFs.MkDir(_L("\\ZZZZZZ\\"));
   883 	test(r == KErrNone || r == KErrAlreadyExists);
   884 	}
   885 
   886 TFileName dirName;
   887 
   888 LOCAL_C void ScanDir(const TDesC& aName, CDirScan::TScanDirection aDirection, TInt aError)
   889 	{
   890 	CDirScan* scanner = NULL;
   891 	TRAP(r, scanner = CDirScan::NewL(TheFs));
   892 	test(r == KErrNone && scanner);
   893 
   894 	TRAP(r, scanner->SetScanDataL(aName,KEntryAttDir,ESortByName|EAscending,aDirection));
   895 	test(r == KErrNone);
   896 	
   897 	CDir *entryList=NULL;
   898 	for (;;)
   899 		{
   900 		TRAP(r, scanner->NextL(entryList));
   901 		test(r == aError);
   902 		if (entryList==NULL)
   903 			break;
   904 		TInt count=entryList->Count();
   905 		while (count--)
   906 			{
   907 			TEntry data=(*entryList)[count];
   908 			TBuf<KMaxFileName> path=scanner->AbbreviatedPath();
   909 			dirName = path;
   910 			dirName.Append(data.iName);
   911 			test.Printf(_L("    %S\n"),&dirName);
   912 			
   913 			}
   914 		delete entryList;
   915 		entryList=NULL;
   916 		}
   917 	delete scanner;
   918 
   919 	}
   920 
   921 /**
   922 The following test, tests CFileMan and CDirScan API on folders private and sys
   923 to confirm that any operation on these folders for any app with incorrect capability
   924 returns KErrPermissionDenied. This test step was added as a result of DEF051428
   925 ("PlatSec: Incorrect errors returned by f32")
   926 */
   927 LOCAL_C void TestCaging()
   928 	{
   929 	CFileMan* fMan=CFileMan::NewL(TheFs);
   930 	TInt r;
   931 	if(fMan!=NULL)
   932 		{		
   933 		
   934 		// Checking the private path
   935 		TBuf<30> privatepath;
   936 		r=TheFs.PrivatePath(privatepath);
   937 		test.Printf(_L("Private Path is=%S"),&privatepath);
   938 		
   939 		r = TheFs.MkDir(_L("\\Caged\\"));
   940 		test(r==KErrNone || r==KErrAlreadyExists);
   941 		
   942 		CDir* entryCount=NULL;
   943 		r=TheFs.GetDir(_L("\\*.*"),KEntryAttNormal,ESortNone,entryCount);
   944 		test(r==KErrNone);
   945 		TInt rootCount= entryCount->Count();
   946 		
   947 		delete entryCount;
   948 		entryCount=NULL;
   949 
   950 
   951 		//Testing Copy
   952 		CDir* entryCount2=NULL;
   953 		r=fMan->Copy(_L("\\sys\\"),_L("\\Caged\\"));
   954 		test(r == KErrPermissionDenied);
   955 		r=fMan->Copy(_L("\\*"),_L("\\Caged\\"));
   956 		test(r == KErrNone);
   957 		
   958 		r=TheFs.GetDir(_L("\\Caged\\*.*"),KEntryAttNormal,ESortNone,entryCount2);
   959 		test(r==KErrNone);
   960 		TInt cagedCount= entryCount2->Count();
   961 		
   962 		test(cagedCount==rootCount);
   963 		
   964 		delete entryCount2;
   965 		entryCount2=NULL;
   966 		
   967 		// Check if both copied sys and private are empty (no information is exposed)
   968 		CDir* entryCount3=NULL;
   969 		r=TheFs.GetDir(_L("\\Caged\\private\\*.*"),KEntryAttNormal|KEntryAttDir,ESortNone,entryCount3);
   970 		test(r==KErrPathNotFound);
   971 		delete entryCount3;
   972 		entryCount3=NULL;
   973 		
   974 		CDir* entryCount4=NULL;
   975 		r=TheFs.GetDir(_L("\\Caged\\sys\\*.*"),KEntryAttNormal|KEntryAttDir,ESortNone,entryCount4);
   976 		test(r==KErrPathNotFound);
   977 		delete entryCount4;
   978 		entryCount4=NULL;
   979 
   980 	
   981 		r=fMan->Copy(_L("\\private\\two\\moo"),_L("\\private\\two\\mew")); 
   982 		test(r == KErrPermissionDenied);
   983 	
   984 		// Create a test file
   985 		RFile testFile;
   986 		r = testFile.Replace(TheFs, _L("\\capTest"),EFileWrite);
   987 		test(r==KErrNone || r==KErrAlreadyExists);
   988 		testFile.Close();
   989 		
   990 		TFileName name;
   991 		name = privatepath;
   992 		name.Append(_L("privateFile.tst"));
   993 		RFile privateFile;
   994 		r = privateFile.Replace(TheFs, name,EFileWrite);
   995 		test(r==KErrNone || r==KErrAlreadyExists);
   996 		privateFile.Close();
   997 
   998 	
   999 		r=fMan->Copy(_L("\\capTest"),_L("\\private\\two\\moo")); 
  1000 		test(r == KErrPermissionDenied);
  1001 		r=fMan->Copy(_L("\\capTest"),_L("\\sys\\bin\\moo")); 
  1002 		test(r == KErrPermissionDenied);
  1003 		r=fMan->Copy(_L("\\sys\\bin\\capTest"),_L("\\sys\\bin\\moo"));
  1004 		test(r == KErrPermissionDenied);
  1005 		r=fMan->Copy(_L("\\sys\\*"),_L("\\"));
  1006 		test (r==KErrPermissionDenied);
  1007 		r=fMan->Copy(name,_L("\\sys\\"));
  1008 		test(r==KErrPermissionDenied);
  1009 
  1010 		// Testing Move
  1011 		r=fMan->Move(_L("\\private\\two\\moo"),_L("\\private\\one\\moo"));
  1012 		test(r == KErrPermissionDenied);
  1013 		r=fMan->Move(_L("\\private\\two\\moo.."),_L("\\private\\one\\moo"));
  1014 		test(r == KErrPermissionDenied);
  1015 		r=fMan->Move(_L("\\private\\two\\moo"),_L("\\private\\one\\moo.."));
  1016 		test(r == KErrPermissionDenied);
  1017 		r=fMan->Move(name,_L("\\privateFile.tst"));
  1018 		test(r == KErrNone);
  1019 		r=fMan->Move(_L("\\privateFile.tst"),name);
  1020 		test(r == KErrNone);
  1021 		r=fMan->Move(_L("\\capTest"),_L("\\private\\two\\moo")); 
  1022 		test(r == KErrPermissionDenied);
  1023 		r=fMan->Move(_L("\\capTest"),_L("\\sys\\bin\\moo")); 
  1024 		test(r == KErrPermissionDenied);
  1025 		r=fMan->Move(_L("\\sys\\bin\\capTest"),_L("\\sys\\bin\\moo"));
  1026 		test(r == KErrPermissionDenied);
  1027 		r=fMan->Move(_L("\\sys\\*"),_L("\\"));
  1028 		test (r==KErrPermissionDenied);
  1029 		r=fMan->Move(name,_L("\\sys\\"));
  1030 		test(r==KErrPermissionDenied);
  1031 
  1032 
  1033 		// Testing Attribs
  1034 		r=fMan->Attribs(_L("\\private\\two\\moo"),KEntryAttReadOnly,0,TTime(0)); 
  1035 		test(r == KErrPermissionDenied);
  1036 		r=fMan->Attribs(_L("\\private\\moo"),KEntryAttReadOnly,0,TTime(0)); 
  1037 		test(r == KErrPermissionDenied);
  1038 		r=fMan->Attribs(name,KEntryAttReadOnly,0,TTime(0));
  1039 		test(r == KErrNone);
  1040 		r=fMan->Attribs(name,0,KEntryAttReadOnly,TTime(0));
  1041 		test(r == KErrNone);
  1042 
  1043 
  1044 		// Testing RmDir
  1045 		r=fMan->RmDir(_L("\\private\\"));
  1046 		test(r == KErrPermissionDenied);
  1047 		r=fMan->RmDir(_L("\\private\\two\\"));
  1048 		test(r == KErrPermissionDenied);
  1049 		r=fMan->RmDir(_L("\\private\\tw?\\"));
  1050 		test(r == KErrPermissionDenied);
  1051 		r=fMan->RmDir(_L("\\sys\\"));
  1052 		test(r == KErrPermissionDenied);
  1053 		
  1054 		
  1055 		// Testing Rename
  1056 		r=fMan->Rename(_L("\\private\\two\\moo"),_L("\\private\\two\\mew")); 
  1057 		test(r == KErrPermissionDenied);
  1058 		
  1059 		// Testing Delete
  1060 		r=fMan->Delete(_L("\\private\\two\\test")); 
  1061 		test(r == KErrPermissionDenied);
  1062 		r=fMan->Delete(_L("\\private\\moo")); 
  1063 		test(r == KErrPermissionDenied);
  1064 		r=fMan->Delete(_L("\\sys\\moo")); 
  1065 		test(r == KErrPermissionDenied);
  1066 		
  1067 
  1068 		//Something that actually exists in Private
  1069 		r=fMan->Rename(name,_L("\\private\\00000001\\moo")); 
  1070 		test(r == KErrNone);
  1071 		r=fMan->Rename(_L("\\private\\00000001\\moo"),name); 
  1072 		test(r == KErrNone);
  1073 		r=fMan->Copy(name,_L("\\private\\00000001\\moo")); 
  1074 		test(r == KErrNone);
  1075 		r=fMan->Delete(_L("\\private\\00000001\\moo")); 
  1076 		test(r == KErrNone);
  1077 
  1078 		// Clean up the test data
  1079 		r=fMan->RmDir(_L("\\Caged\\")); 
  1080 		test(r == KErrNone);
  1081 		r=fMan->Delete(_L("\\capTest")); 
  1082 		test(r == KErrNone);
  1083 		r=fMan->Delete(name); 
  1084 		test(r == KErrNone);
  1085 		delete(fMan);
  1086 		}
  1087 	
  1088 	// CDirScan tests
  1089 	ScanDir(_L("\\"), CDirScan::EScanUpTree, KErrNone);
  1090 	ScanDir(_L("\\"), CDirScan::EScanDownTree, KErrNone);
  1091 	ScanDir(_L("\\private\\"), CDirScan::EScanDownTree, KErrPermissionDenied);
  1092 	ScanDir(_L("\\private\\"), CDirScan::EScanUpTree, KErrPermissionDenied);
  1093 	}
  1094 LOCAL_C void CleanDirs()
  1095 //
  1096 // Remove system and private directories for scan with and without DC
  1097 // (note that the \Private directory may not be able to be removed at this
  1098 // point if it contains other directories, so failing with "in use" is
  1099 // permitted in this case).
  1100 //
  1101 	{
  1102 	TInt r;
  1103 	r = TheFs.RmDir(_L("\\normal\\one\\"));
  1104 	test(r == KErrNone);
  1105 	r = TheFs.RmDir(_L("\\normal\\two\\"));
  1106 	test(r == KErrNone);
  1107 	r = TheFs.RmDir(_L("\\normal\\"));
  1108 	test(r == KErrNone);
  1109 	r = TheFs.RmDir(_L("\\sys\\one\\"));
  1110 	test(r == KErrPermissionDenied);
  1111 	r = TheFs.RmDir(_L("\\sys\\two\\"));
  1112 	test(r == KErrPermissionDenied);
  1113 	r = TheFs.RmDir(_L("\\sys\\"));
  1114 	test(r == KErrPermissionDenied);
  1115 	r = TheFs.RmDir(_L("\\private\\one\\"));
  1116 	test(r == KErrPermissionDenied);
  1117 	r = TheFs.RmDir(_L("\\private\\two\\"));
  1118 	test(r == KErrPermissionDenied);
  1119 	r = TheFs.RmDir(_L("\\private\\"));
  1120 	test(r == KErrPermissionDenied);
  1121 	r = TheFs.RmDir(_L("\\ZZZZZZ\\"));
  1122 	test(r == KErrNone);
  1123 	}
  1124 
  1125 TFileName gDirList[100];
  1126 TInt      gDirNum = 0;
  1127 
  1128 LOCAL_C void ListDirs()
  1129 //
  1130 // List the directories and files on the disk, without DC (so we
  1131 // find all of them), saving them in gDirList[] apart from
  1132 // members of the System and Private ones.
  1133 //
  1134 	{
  1135 	CDirScan* scanner = NULL;
  1136 	TInt r;
  1137 	TRAP(r, scanner = CDirScan::NewL(TheFs));
  1138 	test(r == KErrNone && scanner);
  1139 	TParse dirName;
  1140 	TheFs.Parse(_L("\\"),dirName);
  1141 	TRAP(r, scanner->SetScanDataL(dirName.FullName(),KEntryAttDir,ESortByName|EAscending));
  1142 	test(r == KErrNone);
  1143 	CDir *entryList;
  1144 	test.Printf(_L("------ ALL DIRECTORIES ------\n"));
  1145 	for (;;)
  1146 		{
  1147 		scanner->NextL(entryList);
  1148 		if (entryList==NULL)
  1149 			break;
  1150 		TInt count=entryList->Count();
  1151 		while (count--)
  1152 			{
  1153 			TEntry data=(*entryList)[count];
  1154 			TBuf<KMaxFileName> path=scanner->AbbreviatedPath();
  1155 			gDirList[gDirNum] = path;
  1156 			gDirList[gDirNum].Append(data.iName);
  1157 			test.Printf(_L("    %S\n"),&gDirList[gDirNum]);
  1158 			gDirNum++;
  1159 			}
  1160 		delete entryList;
  1161 		entryList=NULL;
  1162 		}
  1163 	delete scanner;
  1164 	}
  1165 
  1166 LOCAL_C void TestDirs()
  1167 //
  1168 // Scan directories and files with DC on, so only the root \Private
  1169 // and \System directories should be found (no contents).
  1170 //
  1171 	{
  1172 
  1173 	MakeDirs();
  1174 	ListDirs();
  1175 
  1176 	CDirScan* scanner = NULL;
  1177 	TInt r;
  1178 	TRAP(r, scanner = CDirScan::NewL(TheFs));
  1179 	test(r == KErrNone && scanner);
  1180 	TParse dirName;
  1181 	TheFs.Parse(_L("\\"),dirName);
  1182 	TRAP(r, scanner->SetScanDataL(dirName.FullName(),KEntryAttDir,ESortByName|EAscending));
  1183 	test(r == KErrNone);
  1184 	CDir *entryList = NULL;
  1185 	TInt  num = 0;
  1186 	test.Printf(_L("------ ACCESSIBLE DIRECTORIES ------\n"));
  1187 	for (;;)
  1188 		{
  1189 		TRAP(r, scanner->NextL(entryList));
  1190 		if (r != KErrNone)
  1191 			{
  1192 			test.Printf(_L("*** ERROR %d doing NextL()\n"), r);
  1193 			break;
  1194 			}
  1195 		if (entryList==NULL)
  1196 			break;
  1197 		TInt count=entryList->Count();
  1198 		while (count--)
  1199 			{
  1200 			TEntry data=(*entryList)[count];
  1201 			TBuf<KMaxFileName> path=scanner->AbbreviatedPath();
  1202 			path.Append(data.iName);
  1203 			if (path == gDirList[num])
  1204 				{
  1205 				test.Printf(_L("%S\n"),&path);
  1206 				num++;
  1207 				}
  1208 			else
  1209 				{
  1210 				test.Printf(_L("%S *** NOT FOUND ***\n"),&path);
  1211 				}
  1212 			}
  1213 		delete entryList;
  1214 		entryList=NULL;
  1215 		}
  1216 	delete scanner;
  1217 	CleanDirs();
  1218 	test(r == KErrNone);
  1219 	if (num < gDirNum)
  1220 		{
  1221 		test.Printf(_L("Directory not as expected (%d found < %d expected\n"), num, gDirNum);
  1222 		test(0);
  1223 		}
  1224 	test.Printf(_L("------------------------------------\n"));
  1225 
  1226 	}
  1227 
  1228 void TestSystemDrive()
  1229 	{
  1230 	test.Next(_L("TestSystemDrive"));
  1231 	TDriveNumber drive = RFs::GetSystemDrive();
  1232 	test.Printf(_L("System Drive is %c:\n"), 'A'+drive);
  1233 	for(TInt i=EDriveA; i<=EDriveZ; i++)
  1234 		{
  1235 		test(TheFs.SetSystemDrive((TDriveNumber)i) == KErrPermissionDenied);
  1236 		}
  1237 	TChar drvchar = RFs::GetSystemDriveChar();
  1238 	test(drvchar == (TChar)('A' + drive)); 
  1239 	}
  1240 	
  1241 LOCAL_C void CleanupL()
  1242 //
  1243 // Clean up tests
  1244 //
  1245 	{
  1246 	test.Next(_L("Delete test directory"));
  1247 	CFileMan* fMan=CFileMan::NewL(TheFs);
  1248 	TInt r=fMan->RmDir(gSessionPath);
  1249 	test(r==KErrNone);
  1250 	delete fMan;
  1251 	}
  1252 
  1253 GLDEF_C void CallTestsL(/*TChar aDriveLetter*/)
  1254 //
  1255 // Do all tests
  1256 //
  1257 	{
  1258 	if( !PlatSec::IsCapabilityEnforced(ECapabilityTCB) || 
  1259 		!PlatSec::IsCapabilityEnforced(ECapabilityAllFiles) ||
  1260 		!PlatSec::IsCapabilityEnforced(ECapabilityDiskAdmin))
  1261 		{
  1262 		test.Printf(_L("Insufficient capabilities enabled - leaving t_dcnone"));
  1263 		test.Printf(_L("\n")); // Prevent overwrite by next print
  1264 		return;
  1265 		}
  1266 	TurnAllocFailureOff();
  1267 	TheFs.CharToDrive(gDriveToTest,gTheDriveNum);
  1268 	
  1269 	TBuf<30> sesspath;
  1270 	sesspath=_L("?:\\");
  1271 	sesspath[0] = (TText)gDriveToTest;
  1272 
  1273 	TInt r= TheFs.SetSessionPath(sesspath);
  1274 	test(r==KErrNone);
  1275 
  1276 	TBuf<2> cmd;
  1277 	cmd.SetLength(1);
  1278 	cmd[0] = (TText)gDriveToTest;
  1279 	RProcess tp;
  1280 	r=tp.Create(_L("clean_prepdc.exe"),sesspath);
  1281 	test(r==KErrNone);
  1282 	{
  1283 	TRequestStatus ps;
  1284 	tp.Logon(ps);
  1285 	tp.Resume();
  1286 	tp.Close();
  1287 	User::WaitForRequest(ps);
  1288 	}
  1289 
  1290 	//check double mode ie that Defpath still works	
  1291 	RFs fs1;
  1292 	RFs fs2;
  1293 	
  1294 	r=fs1.Connect();
  1295 	test(r==KErrNone);
  1296 	r=fs1.SessionPath(sesspath);
  1297 	test(r==KErrNone);
  1298 	test.Printf(_L("session1 Path=%S"),&sesspath);
  1299 
  1300 	TBuf<30> privatepath;
  1301 	r=fs1.SetSessionToPrivate(gTheDriveNum);
  1302 	test(r==KErrNone);
  1303 	r=fs1.PrivatePath(privatepath);
  1304 	test(r==KErrNone);
  1305 	r=privatepath.Compare(KExpectedPrivatePath());
  1306 	test(r==0);
  1307 	r=fs1.SessionPath(sesspath);
  1308 	test(r==KErrNone);
  1309 	r=privatepath.Compare(sesspath.Mid(KPathPosition));
  1310 	test(r==0);
  1311 	r=fs1.CreatePrivatePath(gTheDriveNum);
  1312 	test(r==KErrNone);
  1313 	fs1.Close();
  1314 
  1315 	r=fs2.Connect();
  1316 	test(r==KErrNone);
  1317 	r=fs2.SessionPath(sesspath);
  1318 	test(r==KErrNone);
  1319 	test.Printf(_L("session2 Path=%S"),&sesspath);
  1320 	fs2.Close();
  1321 
  1322 	TestCaps();
  1323 	TestCaging();
  1324 	TestDirs();
  1325 	TestPathCheck();
  1326 	TestSystemDrive();
  1327 
  1328 	test.Printf(_L("No of files open=%d"), TheFs.ResourceCount());
  1329 	
  1330 	CleanupL();
  1331 	}