os/kernelhwsrv/kerneltest/f32test/server/t_dctcbdiskadmin.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_dctcbdiskadmin"));
    26 GLDEF_D TTime gTimeNow;
    27 LOCAL_D TInt gTheDriveNum;
    28 
    29 const TInt KPathPosition = 2;
    30 _LIT(KExpectedPrivatePath, "\\Private\\00000001\\");
    31 _LIT(KResourcePath, "?:\\Resource\\");
    32 _LIT(KSystemPath,	"?:\\Sys\\");
    33 _LIT(KPrivatePath,	"?:\\Private\\");
    34 _LIT(KPrivateFalseID,	"?:\\Private\\FFFFFFFF\\");
    35 _LIT(KDriveName,	"Billy");
    36 _LIT(KVolLable,		"Benny");
    37 _LIT(KFileSys,	"systemfile.txt");
    38 _LIT(KFileSys3, "sysfile.rna");
    39 _LIT(KFilePri,	"privatefile.txt");
    40 _LIT(KFilePri2,	"privatefile.tmp");
    41 _LIT(KFilePri3,	"prifile.rna");
    42 _LIT(KFileRes,	"resourcefile.txt");
    43 _LIT(KFileRes3,	"resfile.rna");
    44 _LIT(KMkDirSub,"Subdir\\");
    45 _LIT(KOldFile,"?:\\Anyold.txt");
    46 _LIT(KWildPath, "Z:\\SYS\\");
    47 _LIT(KWildFile, "*");
    48 
    49 TCapability TheCaps;
    50 TBuf<4> driveBuf=_L("?:\\");
    51 RFormat format;
    52 TInt count;
    53 RRawDisk rawdisk;
    54 RFile file1;
    55 RFile file2;
    56 RDir	dir;
    57 
    58 TInt r;
    59 TBuf<40> fsname;
    60 TBuf<40> systestname;
    61 TBuf<40> pritestname;
    62 TBuf<40> restestname;
    63 TBuf<40> theprivatepath;
    64 TBuf<40> pritestfalseidname;
    65 TBuf<40> mkdirname;
    66 TFileName fromTemp;
    67 
    68 TBuf<25> sysfilename;
    69 TBuf<30> realName;
    70 TBuf<40> shortfilename;
    71 TBuf<40> longfilename;
    72 
    73 TRequestStatus aStat1;
    74 TRequestStatus aStat2;
    75 TRequestStatus aStat3;
    76 TRequestStatus aStat4;
    77 
    78 TVolumeInfo aVolInfo;
    79 //	TDriveInfo adriveInfo;
    80 
    81 TBuf<40> systestfile;
    82 TBuf<40> pritestfile;
    83 TBuf<40> restestfile;
    84 TBuf<40> systestfile1;
    85 TBuf<40> pritestfile1;
    86 TBuf<40> restestfile1;
    87 
    88 TTime testtime;
    89 TBuf<20> oldName;
    90 
    91 TBuf<25> temp;
    92 
    93 TEntry entry;
    94 
    95 
    96 LOCAL_C void privateFalseIDRFsTest()
    97 //
    98 //
    99 //
   100 	{
   101 	__UHEAP_MARK;
   102 
   103 	//private and wrong UID
   104 	pritestfalseidname=KPrivateFalseID;
   105 	pritestfalseidname[0]=(TText)('A' + gTheDriveNum);
   106 	
   107 	mkdirname.Zero();
   108 	mkdirname.Append(pritestfalseidname);
   109 	mkdirname.Append(KMkDirSub);
   110 
   111 	r=TheFs.MkDirAll(mkdirname);	
   112 	test(r==KErrPermissionDenied);
   113 
   114 	r=TheFs.RmDir(mkdirname);	
   115 	test(r==KErrPermissionDenied);
   116 
   117 	r=TheFs.SetSubst(pritestfalseidname,EDriveO);
   118 	test(r==KErrPermissionDenied);
   119 
   120 	r=TheFs.RealName(_L("O:\\File.XXX"),realName);
   121 	test(r==KErrNone);
   122 
   123 	r=TheFs.SetSessionPath(pritestfalseidname);
   124 	test(r==KErrPermissionDenied);
   125 
   126 	TheFs.NotifyChange(ENotifyAll,aStat2,pritestfalseidname);
   127 	test(aStat2==KErrPermissionDenied);
   128 
   129 
   130 	pritestfile=KPrivateFalseID;
   131 	pritestfile[0]=(TText)('A' + gTheDriveNum);
   132 	pritestfile1=pritestfile;
   133 	pritestfile.Append(KFilePri2);
   134 	pritestfile1.Append(KFilePri3);
   135 	
   136 	oldName=KOldFile;
   137 	oldName[0]=(TText)gDriveToTest;
   138 
   139 	r=TheFs.GetShortName(pritestfile, shortfilename);
   140 	test(r==KErrPermissionDenied || r==KErrNotSupported);
   141 
   142 	r=TheFs.GetLongName(pritestfile1, longfilename);
   143 	test(r==KErrPermissionDenied || r==KErrNotSupported);
   144 
   145 	r=file1.Create(TheFs,oldName,EFileWrite);
   146 	test(r==KErrNone || r==KErrAlreadyExists);
   147 	file1.Close();
   148 
   149 	r=TheFs.Replace(oldName,pritestfile);
   150 	test(r==KErrPermissionDenied);
   151 	
   152 	r=TheFs.Rename(pritestfile,pritestfile1);
   153 	test(r==KErrPermissionDenied);
   154 	
   155 	r=TheFs.Entry(pritestfile1,entry);
   156 	test(r==KErrPermissionDenied);
   157 
   158 	r=TheFs.SetEntry(pritestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
   159 	test(r==KErrPermissionDenied);
   160 
   161 	r=TheFs.Delete(pritestfile1);
   162 	test(r==KErrPermissionDenied);
   163 
   164 	r=TheFs.Delete(oldName);
   165 	test(r==KErrNone);
   166 
   167 	__UHEAP_MARKEND;
   168 	}
   169 LOCAL_C void systemRFsTest()
   170 //
   171 //	RFs test on system Directory
   172 //
   173 	{
   174 	__UHEAP_MARK;
   175 
   176 	systestname=KSystemPath;
   177 	systestname[0]=(TText)('A' + gTheDriveNum);
   178 	
   179 	mkdirname.Zero();
   180 	mkdirname.Append(systestname);
   181 	mkdirname.Append(KMkDirSub);
   182 	r=TheFs.MkDirAll(mkdirname);	
   183 	test(r==KErrNone);
   184 
   185 	TheFs.RmDir(mkdirname);
   186 	test(r==KErrNone);
   187 
   188 	r=TheFs.SetSubst(systestname,EDriveO);
   189 	test(r==KErrNone);
   190 	
   191 	r=TheFs.RealName(_L("O:\\File.XXX"),realName);
   192 	test(r==KErrPermissionDenied);
   193 
   194 	r=TheFs.SetSubst(_L(""),EDriveO); //to unsubst
   195 	test(r==KErrNone);
   196 
   197 	r=TheFs.SetSessionPath(systestname);
   198 	test(r==KErrPermissionDenied);
   199 	
   200 	TheFs.NotifyChange(ENotifyAll,aStat1,systestname);
   201 	test(aStat1==KErrPermissionDenied);
   202 
   203 	systestfile=KSystemPath;
   204 	systestfile[0]=(TText)('A' + gTheDriveNum);
   205 	systestfile1=systestfile;
   206 	systestfile.Append(KFileSys);
   207 	systestfile1.Append(KFileSys3);
   208 	
   209 	oldName=KOldFile;
   210 	oldName[0]=(TText)gDriveToTest;
   211 
   212 	r=TheFs.GetShortName(systestfile, shortfilename);
   213 	test(r==KErrPermissionDenied || r==KErrNotSupported);
   214 
   215 	r=TheFs.GetLongName(systestfile1, longfilename);
   216 	test(r==KErrPermissionDenied || r==KErrNotSupported);
   217 
   218 	r=file1.Create(TheFs,oldName,EFileWrite);
   219 	test(r==KErrNone || r==KErrAlreadyExists);
   220 	file1.Close();
   221 
   222 	r=TheFs.Replace(oldName,systestfile);
   223 	test(r==KErrNone);
   224 	
   225 	r=TheFs.Delete(systestfile1);
   226 	test(r==KErrNone || r==KErrNotFound);
   227 
   228 	r=TheFs.Rename(systestfile,systestfile1);
   229 	test(r==KErrNone);
   230 	
   231 	r=TheFs.Entry(systestfile1,entry);
   232 	test(r==KErrPermissionDenied);
   233 
   234 	r=TheFs.SetEntry(systestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
   235 	test(r==KErrNone);
   236 
   237 	r=TheFs.Delete(systestfile1);
   238 	test(r==KErrNone);
   239 
   240 	__UHEAP_MARKEND;
   241 	}
   242 
   243 LOCAL_C void ResourceRFsTest()
   244 //
   245 //
   246 //
   247 	{
   248 	__UHEAP_MARK;
   249 
   250 	restestname=KResourcePath;
   251 	restestname[0]=(TText)('A' + gTheDriveNum);
   252 	
   253 	mkdirname.Zero();
   254 	mkdirname.Append(restestname);
   255 	mkdirname.Append(KMkDirSub);
   256 	r=TheFs.MkDirAll(mkdirname);	
   257 	test(r==KErrNone);
   258 
   259 	TheFs.RmDir(mkdirname);
   260 	test(r==KErrNone);
   261 
   262 	r=TheFs.SetSubst(restestname,EDriveO);
   263 	test(r==KErrNone);
   264 	
   265 	r=TheFs.RealName(_L("O:\\File.XXX"),realName);
   266 	test(r==KErrNone);
   267 
   268 	r=TheFs.SetSubst(_L(""),EDriveO); //to unsubst
   269 	test(r==KErrNone);
   270 
   271 	r=TheFs.SetSessionPath(restestname);
   272 	test(r==KErrNone);
   273 	
   274 	TheFs.NotifyChange(ENotifyAll,aStat4,restestname);
   275 	test(aStat4==KRequestPending);
   276 
   277 	restestfile=KResourcePath;
   278 	restestfile[0]=(TText)('A' + gTheDriveNum);
   279 	restestfile1=restestfile;
   280 	restestfile.Append(KFileRes);
   281 	restestfile1.Append(KFileRes3);
   282 	
   283 	oldName=KOldFile;
   284 	oldName[0]=(TText)gDriveToTest;
   285 
   286 	r=TheFs.GetShortName(restestfile, shortfilename);
   287 	test(r==KErrNone || KErrNotFound || r==KErrNotSupported);
   288 
   289 	r=TheFs.GetLongName(restestfile1, longfilename);
   290 	test(r==KErrNone || KErrNotFound || r==KErrNotSupported);
   291 
   292 	r=file1.Create(TheFs,oldName,EFileWrite);
   293 	test(r==KErrNone || r==KErrAlreadyExists);
   294 	file1.Close();
   295 
   296 	r=TheFs.Replace(oldName,restestfile);
   297 	test(r==KErrNone);
   298 	
   299 	r=TheFs.Delete(restestfile1);
   300 	test(r==KErrNone || r==KErrNotFound);
   301 
   302 	r=TheFs.Rename(restestfile,restestfile1);
   303 	test(r==KErrNone);
   304 	
   305 	r=TheFs.Entry(restestfile1,entry);
   306 	test(r==KErrNone);
   307 
   308 	r=TheFs.SetEntry(restestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
   309 	test(r==KErrNone);
   310 
   311 	r=TheFs.Delete(restestfile1);
   312 	test(r==KErrNone);
   313 
   314 
   315 	__UHEAP_MARKEND;
   316 	}
   317 
   318 LOCAL_C void privateRFsTest()
   319 //
   320 //
   321 //
   322 	{
   323 	__UHEAP_MARK;
   324 
   325 	//private
   326 	pritestname=KPrivatePath;
   327 	pritestname[0]=(TText)('A' + gTheDriveNum);
   328 	
   329 	mkdirname.Zero();
   330 	mkdirname.Append(pritestname);
   331 	mkdirname.Append(KMkDirSub);
   332 
   333 	r=TheFs.MkDirAll(mkdirname);	
   334 	test(r==KErrPermissionDenied);
   335 
   336 	r=TheFs.RmDir(mkdirname);	
   337 	test(r==KErrPermissionDenied);
   338 
   339 	r=TheFs.SetSubst(pritestname,EDriveO);
   340 	test(r==KErrPermissionDenied);
   341 
   342 	r=TheFs.RealName(_L("O:\\File.XXX"),realName);
   343 	test(r==KErrNone);
   344 
   345 	r=TheFs.SetSessionPath(pritestname);
   346 	test(r==KErrPermissionDenied);
   347 
   348 	TheFs.NotifyChange(ENotifyAll,aStat2,pritestname);
   349 	test(aStat2==KErrPermissionDenied);
   350 
   351 
   352 	pritestfile=KPrivatePath;
   353 	pritestfile[0]=(TText)('A' + gTheDriveNum);
   354 	pritestfile1=pritestfile;
   355 	pritestfile.Append(KFilePri2);
   356 	pritestfile1.Append(KFilePri3);
   357 	
   358 	oldName=KOldFile;
   359 	oldName[0]=(TText)gDriveToTest;
   360 
   361 	r=TheFs.GetShortName(pritestfile, shortfilename);
   362 	test(r==KErrPermissionDenied || r==KErrNotSupported);
   363 
   364 	r=TheFs.GetLongName(pritestfile1, longfilename);
   365 	test(r==KErrPermissionDenied || r==KErrNotSupported);
   366 
   367 	r=file1.Create(TheFs,oldName,EFileWrite);
   368 	test(r==KErrNone || r==KErrAlreadyExists);
   369 	file1.Close();
   370 
   371 	r=TheFs.Replace(oldName,pritestfile);
   372 	test(r==KErrPermissionDenied);
   373 	
   374 	r=TheFs.Rename(pritestfile,pritestfile1);
   375 	test(r==KErrPermissionDenied);
   376 	
   377 	r=TheFs.Entry(pritestfile1,entry);
   378 	test(r==KErrPermissionDenied);
   379 
   380 	r=TheFs.SetEntry(pritestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
   381 	test(r==KErrPermissionDenied);
   382 
   383 	r=TheFs.Delete(pritestfile1);
   384 	test(r==KErrPermissionDenied);
   385 
   386 
   387 	__UHEAP_MARKEND;
   388 	}
   389 
   390 
   391 LOCAL_C void privateSIDRFstest()
   392 	{
   393 	__UHEAP_MARK;
   394 
   395 	theprivatepath[0]=(TText)gDriveToTest;	
   396 	test.Printf(_L("the Private Path = %S"),&theprivatepath);
   397 
   398 	mkdirname.Zero();
   399 	mkdirname.Append(theprivatepath);
   400 	mkdirname.Append(KMkDirSub);
   401 	r=TheFs.MkDirAll(mkdirname);	
   402 	test(r==KErrNone);
   403 
   404 	r=TheFs.RmDir(mkdirname);	
   405 	test(r==KErrNone);
   406 
   407 	r=TheFs.SetSubst(theprivatepath,EDriveO);	
   408 	test(r==KErrNone); 
   409 
   410 	r=TheFs.RealName(_L("O:\\File.XXX"),realName);
   411 	test(r==KErrNone);
   412 
   413 	r=TheFs.SetSubst(_L(""),EDriveO);	 //to unsubst
   414 	test(r==KErrNone);
   415 
   416 	r=TheFs.SetSessionPath(theprivatepath);
   417 	test(r==KErrNone);
   418 
   419 	TheFs.NotifyChange(ENotifyAll,aStat3,theprivatepath);
   420 	test(aStat3==KRequestPending);
   421 
   422 	pritestfile=theprivatepath;
   423 	pritestfile[0]=(TText)('A' + gTheDriveNum);
   424 	pritestfile1=pritestfile;
   425 	pritestfile.Append(KFilePri2);
   426 	pritestfile1.Append(KFilePri3);
   427 	
   428 	oldName=KOldFile;
   429 	oldName[0]=(TText)gDriveToTest;
   430 
   431 	r=TheFs.GetShortName(pritestfile, shortfilename);
   432 	test(r==KErrNone || r==KErrNotFound || r==KErrNotSupported);
   433 
   434 	r=TheFs.GetLongName(pritestfile1, longfilename);
   435 	test(r==KErrNone || r==KErrNotFound || r==KErrNotSupported);
   436 
   437 	r=file1.Create(TheFs,oldName,EFileWrite);
   438 	test(r==KErrNone || r==KErrAlreadyExists);
   439 	file1.Close();
   440 
   441 	r=TheFs.Replace(oldName,pritestfile);
   442 	test(r==KErrNone);
   443 	
   444 	r=TheFs.Rename(pritestfile,pritestfile1);
   445 	test(r==KErrNone || r==KErrAlreadyExists);
   446 	
   447 	r=TheFs.Entry(pritestfile1,entry);
   448 	test(r==KErrNone);
   449 
   450 	r=TheFs.SetEntry(pritestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
   451 	test(r==KErrNone);
   452 
   453 	r=TheFs.Delete(pritestfile1);
   454 	test(r==KErrNone);
   455 
   456 	__UHEAP_MARKEND;
   457 	}
   458 
   459 
   460 LOCAL_C void systemRFiletest()
   461 //
   462 //RFile testing with session path set to //system//
   463 //
   464 	{
   465 	__UHEAP_MARK;
   466 
   467 	r=TheFs.SetSessionPath(systestname);
   468 	test(r==KErrPermissionDenied);
   469 
   470 	r=file1.Temp(TheFs,systestname,fromTemp,EFileWrite);
   471 	test(r==KErrNone);
   472 	file1.Close();
   473 
   474 	systestfile=KSystemPath;
   475 	systestfile[0]=(TText)('A' + gTheDriveNum);
   476 	systestfile1=systestfile;
   477 	systestfile.Append(KFileSys);
   478 	systestfile1.Append(KFileSys3);
   479 
   480 	r=file1.Create(TheFs,systestfile,EFileWrite);
   481 	test(r==KErrNone);
   482 	file1.Close();
   483 
   484 	r=file1.Open(TheFs,systestfile,EFileWrite);
   485 	test(r==KErrNone);
   486 	file1.Close();
   487 	
   488 	r=file1.Open(TheFs,systestfile,EFileRead);
   489 	test(r==KErrPermissionDenied);
   490 	file1.Close();
   491 
   492 	r=file1.Replace(TheFs,systestfile,EFileWrite);
   493 	test(r==KErrNone);
   494 	
   495 	r=file1.Rename(systestfile1);
   496 	test(r==KErrNone);
   497 	file1.Close();
   498 
   499     TFindFile finder(TheFs);
   500     CDir* dir = NULL;
   501     r=finder.FindWildByDir(KWildFile, KWildPath, dir);
   502 	if (!(r==KErrPermissionDenied))
   503         test.Printf(_L("T_DCTCBDISKADMIN: test find wildcards r = %d (expected KErrPermissionDenied)\n"), r);
   504 	test(r==KErrPermissionDenied);
   505 //	delete dir;
   506 
   507 	r=TheFs.Delete(fromTemp);
   508 	test(r==KErrNone);
   509 
   510 	r=TheFs.Delete(systestfile1);
   511 	test(r==KErrNone);
   512 	
   513 
   514 	__UHEAP_MARKEND;
   515 	}
   516 
   517 LOCAL_C void resourceRFiletest()
   518 //
   519 //RFile testing with session path set to //resource//
   520 //
   521 	{
   522 	__UHEAP_MARK;
   523 
   524 	r=TheFs.SetSessionPath(restestname);
   525 	test(r==KErrNone);
   526 
   527 	r=file1.Temp(TheFs,restestname,fromTemp,EFileWrite);
   528 	test(r==KErrNone);
   529 	file1.Close();
   530 
   531 	r=file1.Create(TheFs,KFileRes,EFileWrite);
   532 	test(r==KErrNone);
   533 	file1.Close();
   534 
   535 	r=file1.Open(TheFs,KFileRes,EFileWrite|EFileShareExclusive );
   536 	test(r==KErrNone);
   537 	
   538 	r=file1.Rename(KFileRes3);
   539 	test(r==KErrNone);
   540 	file1.Close();
   541 
   542 	r=file1.Open(TheFs,KFileRes3,EFileShareReadersOrWriters|EFileRead);
   543 	test(r==KErrNone);
   544 	file1.Close();
   545 
   546 	r=file1.Open(TheFs,KFileRes3,EFileShareReadersOrWriters|EFileWrite);
   547 	test(r==KErrNone);
   548 	file1.Close();
   549 
   550 	r=file1.Open(TheFs,KFileRes3,EFileShareReadersOnly);
   551 	test(r==KErrNone);
   552 
   553 	r=file1.ChangeMode(EFileShareExclusive);
   554 	test(r==KErrNone);
   555 	file1.Close();
   556 
   557 	r=file1.Replace(TheFs,KFileRes,EFileWrite);
   558 	test(r==KErrNone);
   559 	file1.Close();	
   560 
   561 	r=TheFs.Delete(KFileRes);
   562 	test(r==KErrNone);
   563 
   564 	r=TheFs.Delete(KFileRes3);
   565 	test(r==KErrNone);
   566 
   567 	r=TheFs.Delete(fromTemp);
   568 	test(r==KErrNone);
   569 
   570 	__UHEAP_MARKEND;
   571 	}
   572 
   573 
   574 LOCAL_C void privatefalseIDRFiletest()
   575 //
   576 //RFile testing with session path set to //Private//<false ID>//
   577 //
   578 	{
   579 	__UHEAP_MARK;
   580 
   581 	r=TheFs.SetSessionPath(pritestfalseidname);
   582 	test(r==KErrPermissionDenied);
   583 
   584 	// Since can't set the session path to what is required, so use
   585 	// an explicit path
   586 	pritestfile=pritestfalseidname;
   587 	pritestfile[0]=(TText)('A' + gTheDriveNum);
   588 	pritestfile.Append(KFilePri);
   589 
   590 	r=file1.Temp(TheFs,pritestfalseidname,fromTemp,EFileWrite);
   591 	test(r==KErrPermissionDenied);
   592 	file1.Close();
   593 
   594 	r=file1.Create(TheFs,pritestfile,EFileWrite);
   595 	test(r==KErrPermissionDenied);
   596 	file1.Close();
   597 
   598 	r=file1.Open(TheFs,pritestfile,EFileWrite);
   599 	test(r==KErrPermissionDenied);
   600 	file1.Close();
   601 	
   602 	r=file1.Replace(TheFs,pritestfile,EFileWrite);
   603 	test(r==KErrPermissionDenied);
   604 
   605 	// Can't perform this operation since file1 has not been created
   606 /*	r=file1.Rename(KFilePri3);
   607 	test(r==KErrPermissionDenied);
   608 	file1.Close();
   609 */
   610 	__UHEAP_MARKEND;
   611 	}
   612 
   613 
   614 
   615 LOCAL_C void privateRFiletest()
   616 //
   617 //RFile testing with session path set to //Private//
   618 //
   619 	{
   620 	__UHEAP_MARK;
   621 
   622 	r=TheFs.SetSessionPath(pritestname);
   623 	test(r==KErrPermissionDenied);
   624 
   625 	r=file1.Temp(TheFs,pritestname,fromTemp,EFileWrite);
   626 	test(r==KErrPermissionDenied);
   627 	file1.Close();
   628 
   629 	// Since can't set session path create explicit path
   630 	pritestfile=KPrivatePath;
   631 	pritestfile[0]=(TText)('A' + gTheDriveNum);
   632 	pritestfile.Append(KFilePri);
   633 
   634 	r=file1.Create(TheFs,pritestfile,EFileWrite);
   635 	test(r==KErrPermissionDenied);
   636 	file1.Close();
   637 
   638 	r=file1.Open(TheFs,pritestfile,EFileWrite);
   639 	test(r==KErrPermissionDenied);
   640 	file1.Close();
   641 	
   642 	r=file1.Open(TheFs,pritestfile,EFileRead);
   643 	test(r==KErrPermissionDenied);
   644 	file1.Close();
   645 	
   646 	r=file1.Replace(TheFs,pritestfile,EFileWrite);
   647 	test(r==KErrPermissionDenied);
   648 
   649 	// Can't rename nor delete since file1 not created
   650 /*
   651 	r=file1.Rename(KFilePri3);
   652 	test(r==KErrPermissionDenied);
   653 	file1.Close();
   654 
   655 	r=TheFs.Delete(fromTemp);
   656 	test(r==KErrNone);
   657 */
   658 
   659 	__UHEAP_MARKEND;
   660 	}
   661 
   662 
   663 
   664 LOCAL_C void privateSIDRFiletest()
   665 //
   666 //Rfile Testing with session path set to //Private//UID//
   667 //
   668 	{
   669 	__UHEAP_MARK;
   670 
   671 	r=TheFs.SetSessionToPrivate(gTheDriveNum);
   672 	test(r==KErrNone);
   673 	
   674 	r=file1.Temp(TheFs,theprivatepath,fromTemp,EFileWrite);
   675 	test(r==KErrNone);
   676 	file1.Close();
   677 
   678 	r=file1.Create(TheFs,KFilePri,EFileWrite);
   679 	test(r==KErrNone || r==KErrAlreadyExists);
   680 	file1.Close();
   681 
   682 	r=file1.Open(TheFs,KFilePri,EFileWrite);
   683 	test(r==KErrNone);
   684 	file1.Close();
   685 	
   686 	r=file1.Open(TheFs,KFilePri,EFileRead);
   687 	test(r==KErrNone);
   688 	file1.Close();
   689 	
   690 	r=file1.Replace(TheFs,KFilePri,EFileWrite);
   691 	test(r==KErrNone);
   692 	
   693 	r=file1.Rename(KFilePri3);
   694 	test(r==KErrNone);
   695 	file1.Close();
   696 
   697 	r=TheFs.Delete(KFilePri3);
   698 	test(r==KErrNone);
   699 
   700 	r=TheFs.Delete(fromTemp);
   701 	test(r==KErrNone);
   702 
   703 	__UHEAP_MARKEND;
   704 	}
   705 
   706 LOCAL_C void RDirtest()
   707 //
   708 //
   709 //
   710 	{
   711 	__UHEAP_MARK;
   712 
   713 
   714 	//system
   715 	CDir*	dirEntries;
   716 	TBuf<30> dirNameBuf(KSystemPath);
   717 	dirNameBuf[0]=(TText)gDriveToTest;
   718 	r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
   719 	test(r==KErrPermissionDenied);
   720 	dir.Close();
   721 	r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
   722 	test(r==KErrPermissionDenied);
   723 	dirNameBuf.Zero();
   724 	delete dirEntries;
   725 
   726 	//Private
   727 	dirNameBuf=KPrivatePath;
   728 	dirNameBuf[0]=(TText)gDriveToTest;
   729 	r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
   730 	test(r==KErrPermissionDenied);
   731 	dir.Close();
   732 	r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
   733 	test(r==KErrPermissionDenied);
   734 	dirNameBuf.Zero();
   735 	delete dirEntries;
   736 
   737 	//Private//<wrong ID>//
   738 	dirNameBuf=KPrivateFalseID;
   739 	dirNameBuf[0]=(TText)gDriveToTest;
   740 	r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
   741 	test(r==KErrPermissionDenied);
   742 	dir.Close();
   743 	r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
   744 	test(r==KErrPermissionDenied);
   745 	dirNameBuf.Zero();
   746 	delete dirEntries;
   747 
   748 	//Private/uid
   749 	TheFs.PrivatePath(dirNameBuf);
   750 	dirNameBuf.Insert(0,_L("?:"));
   751 	dirNameBuf[0]=(TText)gDriveToTest;
   752 	r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
   753 	test(r==KErrNone);
   754 	dir.Close();
   755 	r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
   756 	test(r==KErrNone);
   757 	dirNameBuf.Zero();
   758 	delete dirEntries;
   759 	//Resource
   760 	
   761 	dirNameBuf=KResourcePath;
   762 	dirNameBuf[0]=(TText)gDriveToTest;
   763 	r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
   764 	test(r==KErrNone);
   765 	r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
   766 	test(r==KErrNone);
   767 	dir.Close();
   768 	delete dirEntries;
   769 
   770 	__UHEAP_MARKEND;
   771 	}
   772 
   773 
   774 LOCAL_C void TestTcbDiskAdmin()
   775 //
   776 //	Test with tcb capabilities
   777 //
   778 	{
   779 	__UHEAP_MARK;
   780 
   781 	r=TheFs.FileSystemName(fsname,gTheDriveNum);
   782 	test(r==KErrNone);
   783 	r = DismountFileSystem(TheFs, fsname, gTheDriveNum);
   784 	test(r==KErrNone || r==KErrNotFound);
   785 //	r=TheFs.RemoveFileSystem(fsname);	//can not test due to bug else where fix exists
   786 //	test(r==KErrNone);
   787 //	r=TheFs.AddFileSystem(fsname);
   788 //	test(r==KErrNone);
   789 	r = MountFileSystem(TheFs, fsname, gTheDriveNum);
   790 	test(r==KErrNone);
   791 	r=TheFs.SetDriveName(gTheDriveNum,KDriveName);
   792 	test(r==KErrNone);
   793 #ifndef __WINS__
   794  	r=TheFs.SetVolumeLabel(KVolLable, gTheDriveNum);
   795 	test(r==KErrNone);
   796 #endif
   797 
   798 	systemRFsTest();
   799 	ResourceRFsTest();
   800 	privateRFsTest();	
   801 	privateSIDRFstest();
   802 	privateFalseIDRFsTest();
   803 
   804 	systemRFiletest();
   805 	resourceRFiletest();
   806 	privateRFiletest();
   807 	privateSIDRFiletest();
   808 	privatefalseIDRFiletest();
   809 
   810 	//check notifier return values set in rfs testing
   811 	User::WaitForRequest(aStat1);
   812 	User::WaitForRequest(aStat2);
   813 	User::WaitForRequest(aStat3);
   814 	User::WaitForRequest(aStat4);
   815 	test(aStat1==KErrPermissionDenied);
   816 	test(aStat2==KErrPermissionDenied);
   817 	test(aStat3==KErrNone);
   818 	test(aStat4==KErrNone);
   819 
   820 	r=TheFs.SetSessionPath(systestname);
   821 	test(r==KErrPermissionDenied);
   822 	
   823 //Test RRawDisk class
   824 	r=rawdisk.Open(TheFs,gTheDriveNum);
   825 	test(r==KErrNone);
   826 	rawdisk.Close();
   827 
   828 	RDirtest();
   829 
   830 #ifdef __WINS__
   831 	if (User::UpperCase(driveBuf[0]) != 'C')
   832 #endif
   833 		{
   834 		//Test RFormat class
   835 		r=format.Open(TheFs,driveBuf,EHighDensity,count);
   836 		test(r==KErrNone);
   837 
   838 		while(count)	
   839 			{
   840 			TInt r=format.Next(count);
   841 			test(r==KErrNone);
   842 			}
   843 		format.Close();
   844 		}
   845 
   846 	driveBuf[0]=(TText)gDriveToTest;
   847 	r=TheFs.ScanDrive(driveBuf);
   848 	test(r==KErrNone || r==KErrNotSupported);
   849 	r=TheFs.CheckDisk(driveBuf);
   850 	test(r==KErrNone || r==KErrNotSupported);
   851 
   852 	__UHEAP_MARKEND;
   853 	}
   854 
   855 LOCAL_C void TestCaps()
   856 //
   857 //	test format etc that require certain capabilities
   858 //
   859 	{
   860 
   861 	__UHEAP_MARK;
   862 #ifndef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
   863 	const char myDiagMsg[] = "Capability Check Failure";
   864 #endif //!__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
   865 	r=RProcess().HasCapability(ECapabilityTCB,ECapabilityDiskAdmin, __PLATSEC_DIAGNOSTIC_STRING(myDiagMsg));
   866 	test(r);
   867 
   868 	driveBuf[0]=(TText)gDriveToTest;
   869 	r=TheFs.SessionPath(temp);
   870 	test(r==KErrNone);
   871 
   872 	test.Printf(_L("Session path: %S"),&temp);
   873 
   874 	r=TheFs.CreatePrivatePath(gTheDriveNum);
   875 	test(r==KErrNone || r== KErrAlreadyExists);
   876 
   877 	TBuf<18> tempPri;
   878 	r=TheFs.PrivatePath(tempPri);
   879 	test(r==KErrNone);
   880 	theprivatepath = _L("?:");
   881 	theprivatepath.Append(tempPri);
   882 
   883 	TestTcbDiskAdmin();
   884 
   885 	TFileName thesessionpath;
   886 
   887 	r=TheFs.SetSessionToPrivate(gTheDriveNum);
   888 	test(r==KErrNone);
   889 	r=TheFs.SessionPath(thesessionpath);
   890 	test(r==KErrNone);
   891 	
   892 	test(thesessionpath == theprivatepath);
   893 
   894 	__UHEAP_MARKEND;
   895 	}
   896 
   897 LOCAL_C void CleanupL()
   898 //
   899 // Clean up tests
   900 //
   901 	{
   902 	test.Next(_L("Delete test directory"));
   903 	CFileMan* fMan=CFileMan::NewL(TheFs);
   904 	TInt r=fMan->RmDir(gSessionPath);
   905 	test(r==KErrNone || r==KErrPathNotFound);
   906 
   907 	TBuf<20> delDir;
   908 	delDir=KResourcePath;
   909 	delDir[0]=(TText)gDriveToTest;
   910 	r=fMan->RmDir(delDir);
   911 	test(r==KErrNone || r==KErrPathNotFound);
   912 	delete fMan;
   913 
   914 	delDir=KSystemPath;
   915 	delDir[0]=(TText)gDriveToTest;
   916 	r=TheFs.RmDir(delDir);
   917 	test(r==KErrNone || r==KErrPathNotFound || r==KErrNotFound);
   918 	}
   919 
   920 GLDEF_C void CallTestsL(/*TChar aDriveLetter*/)
   921 //
   922 // Do all tests
   923 //
   924 	{
   925 	if( !PlatSec::IsCapabilityEnforced(ECapabilityTCB) || 
   926 		!PlatSec::IsCapabilityEnforced(ECapabilityDiskAdmin))
   927 		{
   928 		test.Printf(_L("Insufficient capabilities enabled - leaving t_dctcbdiskadmin"));
   929 		test.Printf(_L("\n")); // Prevent overwrite by next print
   930 		return;
   931 		}
   932 
   933 	__UHEAP_MARK;
   934 
   935 	TurnAllocFailureOff();
   936 
   937 	TheFs.CharToDrive(gDriveToTest,gTheDriveNum);
   938 	
   939 	TBuf<30> sesspath;
   940 	sesspath=_L("?:\\");
   941 	sesspath[0] = (TText)gDriveToTest;
   942 
   943 	TInt r= TheFs.SetSessionPath(sesspath);
   944 	test(r==KErrNone);
   945 
   946 	//cleanup from previous run of this test
   947 	RProcess tp;
   948 	r=tp.Create(_L("clean_prepdc.exe"),sesspath);
   949 	test(r==KErrNone);
   950 	{
   951 	TRequestStatus ps;
   952 	tp.Logon(ps);
   953 	tp.Resume();
   954 	tp.Close();
   955 	User::WaitForRequest(ps);
   956 	}
   957 
   958 	//check double mode ie that Defpath still works	
   959 	RFs fs1;
   960 	RFs fs2;
   961 	
   962 	r=fs1.Connect();
   963 	test(r==KErrNone);
   964 	r=fs1.SessionPath(sesspath);
   965 	test(r==KErrNone);
   966 	test.Printf(_L("session1 Path=%S"),&sesspath);
   967 
   968 	TBuf<30> privatepath;
   969 	r=fs1.SetSessionToPrivate(gTheDriveNum);
   970 	test(r==KErrNone);
   971 	r=fs1.PrivatePath(privatepath);
   972 	test(r==KErrNone);
   973 	r=privatepath.Compare(KExpectedPrivatePath());
   974 	test(r==0);
   975 	r=fs1.SessionPath(sesspath);
   976 	test(r==KErrNone);
   977 	r=privatepath.Compare(sesspath.Mid(KPathPosition));
   978 	test(r==0);
   979 	r=fs1.CreatePrivatePath(gTheDriveNum);
   980 	test(r==KErrNone);
   981 	fs1.Close();
   982 
   983 	r=fs2.Connect();
   984 	test(r==KErrNone);
   985 	r=fs2.SessionPath(sesspath);
   986 	test(r==KErrNone);
   987 	test.Printf(_L("session2 Path=%S"),&sesspath);
   988 	fs2.Close();
   989 
   990 	__UHEAP_MARK;
   991 	TestCaps();
   992 	__UHEAP_MARKEND;
   993 
   994 	test.Printf(_L("No of files open=%d"), TheFs.ResourceCount());
   995 
   996 	CleanupL();
   997 	__UHEAP_MARKEND;
   998 
   999 	}