os/kernelhwsrv/kerneltest/f32test/server/t_dcdiskadmin.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/server/t_dcdiskadmin.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,945 @@
     1.4 +// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// f32test\server\t_dcdiskadmin.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <f32file.h>
    1.22 +#include <e32test.h>
    1.23 +#include <e32std.h>
    1.24 +#include <e32std_private.h>
    1.25 +#include <e32svr.h>
    1.26 +#include "t_server.h"
    1.27 +
    1.28 +GLDEF_D RTest test(_L("T_DCDiskadmin"));
    1.29 +GLDEF_D TTime gTimeNow;
    1.30 +LOCAL_D TInt gTheDriveNum;
    1.31 +
    1.32 +const TInt KPathPosition = 2;
    1.33 +_LIT(KExpectedPrivatePath, "\\Private\\00000001\\");
    1.34 +_LIT(KResourcePath, "?:\\Resource\\");
    1.35 +_LIT(KSystemPath,	"?:\\Sys\\");
    1.36 +_LIT(KPrivatePath,	"?:\\Private\\");
    1.37 +_LIT(KPrivateFalseID,	"?:\\Private\\FFFFFFFF\\");
    1.38 +_LIT(KDriveName,	"Billy");
    1.39 +_LIT(KVolLable,		"Benny");
    1.40 +_LIT(KFileSys,	"systemfile.txt");
    1.41 +_LIT(KFileSys3, "sysfile.rna");
    1.42 +_LIT(KFilePri,	"privatefile.txt");
    1.43 +_LIT(KFilePri2,	"privatefile.tmp");
    1.44 +_LIT(KFilePri3,	"prifile.rna");
    1.45 +_LIT(KFileRes,	"resourcefile.txt");
    1.46 +_LIT(KFileRes3,	"resfile.rna");
    1.47 +_LIT(KMkDirSub,"Subdir\\");
    1.48 +_LIT(KOldFile,"?:\\Anyold.txt");
    1.49 +_LIT(KWildPath, "Z:\\SYS\\");
    1.50 +_LIT(KWildFile, "*");
    1.51 +
    1.52 +TInt theDrive=0;
    1.53 +TCapability TheCaps;
    1.54 +TBuf<4> driveBuf=_L("?:\\");
    1.55 +RFormat format;
    1.56 +TInt count;
    1.57 +RRawDisk rawdisk;
    1.58 +RFile file1;
    1.59 +RFile file2;
    1.60 +RDir	dir;
    1.61 +CDir*	dirEntries;
    1.62 +TInt r;
    1.63 +TBuf<40> fsname;
    1.64 +TBuf<40> systestname;
    1.65 +TBuf<40> pritestname;
    1.66 +TBuf<40> restestname;
    1.67 +TBuf<40> theprivatepath;
    1.68 +TBuf<40> pritestfalseidname;
    1.69 +TBuf<40> mkdirname;
    1.70 +TFileName fromTemp;
    1.71 +
    1.72 +TBuf<40> shortfilename;
    1.73 +TBuf<40> longfilename;
    1.74 +
    1.75 +TBuf<30> dirNameBuf;
    1.76 +TRequestStatus aStat1;
    1.77 +TRequestStatus aStat2;
    1.78 +TRequestStatus aStat3;
    1.79 +TRequestStatus aStat4;
    1.80 +
    1.81 +TVolumeInfo aVolInfo;
    1.82 +//	TDriveInfo adriveInfo;
    1.83 +
    1.84 +TBuf<40> systestfile;
    1.85 +TBuf<40> pritestfile;
    1.86 +TBuf<40> restestfile;
    1.87 +TBuf<40> systestfile1;
    1.88 +TBuf<40> pritestfile1;
    1.89 +TBuf<40> restestfile1;
    1.90 +TBuf<30> realName;
    1.91 +TTime testtime;
    1.92 +TBuf<20> oldName;
    1.93 +
    1.94 +TBuf<25> temp;
    1.95 +
    1.96 +TEntry entry;
    1.97 +
    1.98 +
    1.99 +
   1.100 +LOCAL_C void systemRFstest()
   1.101 +//
   1.102 +//
   1.103 +//
   1.104 +	{
   1.105 +
   1.106 +	//system		
   1.107 +	systestname=KSystemPath;
   1.108 +	systestname[0]=(TText)('A' + gTheDriveNum);
   1.109 +
   1.110 +	mkdirname.Zero();
   1.111 +	mkdirname.Append(systestname);
   1.112 +	mkdirname.Append(KMkDirSub);
   1.113 +	r=TheFs.MkDirAll(mkdirname);	
   1.114 +	test(r==KErrPermissionDenied);
   1.115 +
   1.116 +	r=TheFs.RmDir(mkdirname);	
   1.117 +	test(r==KErrPermissionDenied);
   1.118 +
   1.119 +	r=TheFs.SetSubst(systestname,EDriveS);
   1.120 +	test(r==KErrPermissionDenied);
   1.121 +	
   1.122 +	r=TheFs.SetSessionPath(systestname);
   1.123 +	test(r==KErrPermissionDenied);
   1.124 +
   1.125 +	TheFs.NotifyChange(ENotifyAll,aStat1,systestname);
   1.126 +	test(aStat1==KErrPermissionDenied);
   1.127 +
   1.128 +	systestfile=KSystemPath;
   1.129 +	systestfile[0]=(TText)('A' + gTheDriveNum);
   1.130 +	systestfile1=systestfile;
   1.131 +	systestfile.Append(KFileSys);
   1.132 +	systestfile1.Append(KFileSys3);
   1.133 +	
   1.134 +	oldName=KOldFile;
   1.135 +	oldName[0]=(TText)gDriveToTest;
   1.136 +
   1.137 +	r=TheFs.GetShortName(systestfile, shortfilename);
   1.138 +	test(r==KErrPermissionDenied);
   1.139 +
   1.140 +	r=TheFs.GetLongName(systestfile1, longfilename);
   1.141 +	test(r==KErrPermissionDenied);
   1.142 +
   1.143 +	r=file1.Create(TheFs,oldName,EFileWrite);
   1.144 +	test(r==KErrNone || r==KErrAlreadyExists);
   1.145 +	file1.Close();
   1.146 +
   1.147 +	r=TheFs.Replace(oldName,systestfile);
   1.148 +	test(r==KErrPermissionDenied);
   1.149 +	
   1.150 +	r=TheFs.Rename(systestfile,systestfile1);
   1.151 +	test(r==KErrPermissionDenied);
   1.152 +	
   1.153 +	r=TheFs.Entry(systestfile1,entry);
   1.154 +	test(r==KErrPermissionDenied);
   1.155 +
   1.156 +	r=TheFs.SetEntry(systestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
   1.157 +	test(r==KErrPermissionDenied);
   1.158 +
   1.159 +	r=TheFs.Delete(systestfile1);
   1.160 +	test(r==KErrPermissionDenied);
   1.161 +
   1.162 +
   1.163 +	// DEF141257: Security Issue in File Server 
   1.164 +	// Test that we can't access the system drive by preceding it with a dot character
   1.165 +	_LIT(KSystemPathDot, "?:\\.Sys\\");
   1.166 +
   1.167 +	// try creating a file in "\.SYS"...
   1.168 +	TBuf<40> SysTestFileDot;
   1.169 +	SysTestFileDot=KSystemPathDot;
   1.170 +	SysTestFileDot[0]=(TText)('A' + gTheDriveNum);
   1.171 +	SysTestFileDot.Append(KFileSys);
   1.172 +	RFile file;
   1.173 +	r = file.Replace(TheFs, SysTestFileDot, EFileWrite);
   1.174 +	test(r==KErrPathNotFound);
   1.175 +
   1.176 +	// try creating a subst drive for "\.SYS"...
   1.177 +	TBuf<40> SysTestNameDot;
   1.178 +	SysTestNameDot=KSystemPathDot;
   1.179 +	SysTestNameDot[0]=(TText)('A' + gTheDriveNum);
   1.180 +	r=TheFs.SetSubst(SysTestNameDot,EDriveA);
   1.181 +	test(r==KErrNone);
   1.182 +
   1.183 +	// try creating a file using substituted drive...
   1.184 +	TBuf<40> SubstTestFile = _L("A:\\");
   1.185 +	SubstTestFile.Append(KFileSys);
   1.186 +
   1.187 +	r = file.Replace(TheFs, SubstTestFile, EFileWrite);
   1.188 +	test(r==KErrPathNotFound);
   1.189 +
   1.190 +	r = TheFs.SetSubst(_L(""),EDriveA);
   1.191 +	test(r==KErrNone);
   1.192 +
   1.193 +
   1.194 +
   1.195 +	// try listing files in "\.SYS"
   1.196 +	_LIT(KWildPathDot, "Z:\\.SYS\\");
   1.197 +	TFindFile finder(TheFs);
   1.198 +	CDir* dir = NULL;
   1.199 +	r=finder.FindWildByDir(KWildFile, KWildPathDot, dir);
   1.200 +	test(r==KErrNotFound);
   1.201 +	delete dir;
   1.202 +
   1.203 +	// Deliberately create a directory called "\.SYS"
   1.204 +	// and verify shortname is NOT the same as "SYS"
   1.205 +	mkdirname.Zero();
   1.206 +	mkdirname.Append(KSystemPathDot);
   1.207 +	mkdirname[0]=(TText)('A' + gTheDriveNum);
   1.208 +	r=TheFs.MkDirAll(mkdirname);	
   1.209 +	test(r==KErrNone);
   1.210 +
   1.211 +	r=TheFs.GetShortName(mkdirname, shortfilename);
   1.212 +	test(r==KErrNone || r==KErrNotSupported);	// short names not supported on LFFS
   1.213 +//	r = shortfilename.Compare(_L("SYS~1"));
   1.214 +//	test(r==KErrNone);
   1.215 +	r = shortfilename.Compare(_L("SYS"));
   1.216 +	test (r != 0);
   1.217 +
   1.218 +	r = TheFs.RmDir(mkdirname);
   1.219 +	test(r==KErrNone);
   1.220 +
   1.221 +	// Deliberately create a directory called "\..SYS"
   1.222 +	// and verify shortname is NOT the same as "SYS"
   1.223 +	_LIT(KSystemPathDotDot, "?:\\..Sys\\");
   1.224 +	mkdirname.Zero();
   1.225 +	mkdirname.Append(KSystemPathDotDot);
   1.226 +	mkdirname[0]=(TText)('A' + gTheDriveNum);
   1.227 +	r=TheFs.MkDirAll(mkdirname);	
   1.228 +	test(r==KErrNone);
   1.229 +
   1.230 +	r=TheFs.GetShortName(mkdirname, shortfilename);
   1.231 +	test(r==KErrNone || r==KErrNotSupported);	// short names not supported on LFFS
   1.232 +//	r = shortfilename.Compare(_L("_.SYS"));
   1.233 +//	test(r==KErrNone);
   1.234 +	r = shortfilename.Compare(_L("SYS"));
   1.235 +	test (r != 0);
   1.236 +
   1.237 +	r = TheFs.RmDir(mkdirname);
   1.238 +	test(r==KErrNone);
   1.239 +	}
   1.240 +
   1.241 +
   1.242 +LOCAL_C void resourceRFstest()
   1.243 +//
   1.244 +//
   1.245 +//
   1.246 +	{
   1.247 +//resource		
   1.248 +	restestname=KResourcePath;
   1.249 +	restestname[0]=(TText)('A' + gTheDriveNum);
   1.250 +	
   1.251 +	mkdirname.Zero();
   1.252 +	mkdirname.Append(restestname);
   1.253 +	mkdirname.Append(KMkDirSub);
   1.254 +	r=TheFs.MkDirAll(mkdirname);	
   1.255 +	test(r==KErrPermissionDenied);
   1.256 +
   1.257 +	TheFs.RmDir(mkdirname);
   1.258 +	test(r==KErrPermissionDenied);
   1.259 +	
   1.260 +	// Change due to defect DEF099546 fix
   1.261 +	// TCB capability is required for following operation.
   1.262 +	r=TheFs.SetSubst(restestname,EDriveS);
   1.263 +	//test(r==KErrNone);
   1.264 +	test(r==KErrPermissionDenied);
   1.265 +	
   1.266 +	// SetSubst will fail.
   1.267 +	//r=TheFs.RealName(_L("S:\\File.XXX"),realName);
   1.268 +	//test(r==KErrNone);
   1.269 +
   1.270 +	//r=TheFs.SetSubst(_L(""),EDriveS); 
   1.271 +	//test(r==KErrNone);
   1.272 +
   1.273 +	r=TheFs.SetSessionPath(restestname);
   1.274 +	test(r==KErrNone);
   1.275 +	
   1.276 +	TheFs.NotifyChange(ENotifyAll,aStat4,restestname);
   1.277 +	test(aStat4==KRequestPending);
   1.278 +
   1.279 +
   1.280 +	restestfile=KResourcePath;
   1.281 +	restestfile[0]=(TText)('A' + gTheDriveNum);
   1.282 +	restestfile1=restestfile;
   1.283 +	restestfile.Append(KFileRes);
   1.284 +	restestfile1.Append(KFileRes3);
   1.285 +	
   1.286 +	oldName=KOldFile;
   1.287 +	oldName[0]=(TText)gDriveToTest;
   1.288 +
   1.289 +	r=TheFs.GetShortName(restestfile, shortfilename);
   1.290 +	test(r==KErrNone || KErrPathNotFound);
   1.291 +
   1.292 +	r=TheFs.GetLongName(restestfile1, longfilename);
   1.293 +	test(r==KErrNone || KErrPathNotFound);
   1.294 +
   1.295 +	r=file1.Create(TheFs,oldName,EFileWrite);
   1.296 +	test(r==KErrNone || r==KErrAlreadyExists);
   1.297 +	file1.Close();
   1.298 +
   1.299 +	r=TheFs.Replace(oldName,restestfile);
   1.300 +	test(r==KErrPermissionDenied);
   1.301 +	
   1.302 +	r=TheFs.Rename(restestfile,restestfile1);
   1.303 +	test(r==KErrPermissionDenied);
   1.304 +	
   1.305 +	r=TheFs.Entry(restestfile1,entry);
   1.306 +	test(r==KErrNone || KErrPathNotFound);
   1.307 +
   1.308 +	r=TheFs.SetEntry(restestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
   1.309 +	test(r==KErrPermissionDenied);
   1.310 +
   1.311 +	r=TheFs.Delete(restestfile1);
   1.312 +	test(r==KErrPermissionDenied);
   1.313 +	}
   1.314 +
   1.315 +
   1.316 +LOCAL_C void privateFalseIDRFstest()
   1.317 +//
   1.318 +//
   1.319 +//
   1.320 +	{
   1.321 +	pritestfalseidname=KPrivateFalseID;
   1.322 +	pritestfalseidname[0]=(TText)('A' + gTheDriveNum);
   1.323 +
   1.324 +	mkdirname.Zero();
   1.325 +	mkdirname.Append(pritestfalseidname);
   1.326 +	mkdirname.Append(KMkDirSub);
   1.327 +
   1.328 +	r=TheFs.MkDirAll(mkdirname);	
   1.329 +	test(r==KErrPermissionDenied);
   1.330 +
   1.331 +	r=TheFs.RmDir(mkdirname);	
   1.332 +	test(r==KErrPermissionDenied);
   1.333 +
   1.334 +	r=TheFs.SetSubst(pritestfalseidname,EDriveS);
   1.335 +	test(r==KErrPermissionDenied); 
   1.336 +	
   1.337 +	r=TheFs.SetSessionPath(pritestfalseidname);
   1.338 +	test(r==KErrPermissionDenied);
   1.339 +
   1.340 +	TheFs.NotifyChange(ENotifyAll,aStat2,pritestfalseidname);
   1.341 +	test(aStat2==KErrPermissionDenied);
   1.342 +
   1.343 +	pritestfile=KPrivateFalseID;
   1.344 +	pritestfile[0]=(TText)('A' + gTheDriveNum);
   1.345 +	pritestfile1=pritestfile;
   1.346 +	pritestfile.Append(KFilePri2);
   1.347 +	pritestfile1.Append(KFilePri3);
   1.348 +	
   1.349 +	oldName=KOldFile;
   1.350 +	oldName[0]=(TText)gDriveToTest;
   1.351 +
   1.352 +	r=TheFs.GetShortName(pritestfile, shortfilename);
   1.353 +	test(r==KErrPermissionDenied);
   1.354 +
   1.355 +	r=TheFs.GetLongName(pritestfile1, longfilename);
   1.356 +	test(r==KErrPermissionDenied);
   1.357 +
   1.358 +	r=file1.Create(TheFs,oldName,EFileWrite);
   1.359 +	test(r==KErrNone || r==KErrAlreadyExists);
   1.360 +	file1.Close();
   1.361 +
   1.362 +	r=TheFs.Replace(oldName,pritestfile);
   1.363 +	test(r==KErrPermissionDenied);
   1.364 +	
   1.365 +	r=TheFs.Rename(pritestfile,pritestfile1);
   1.366 +	test(r==KErrPermissionDenied);
   1.367 +	
   1.368 +	r=TheFs.Entry(pritestfile1,entry);
   1.369 +	test(r==KErrPermissionDenied);
   1.370 +
   1.371 +	r=TheFs.SetEntry(pritestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
   1.372 +	test(r==KErrPermissionDenied);
   1.373 +
   1.374 +	r=TheFs.Delete(pritestfile1);
   1.375 +	test(r==KErrPermissionDenied);
   1.376 +
   1.377 +	}
   1.378 +
   1.379 +
   1.380 +
   1.381 +LOCAL_C void privateRFstest()
   1.382 +//
   1.383 +//
   1.384 +//
   1.385 +	{
   1.386 +//private
   1.387 +	pritestname=KPrivatePath;
   1.388 +	pritestname[0]=(TText)('A' + gTheDriveNum);
   1.389 +
   1.390 +	mkdirname.Zero();
   1.391 +	mkdirname.Append(pritestname);
   1.392 +	mkdirname.Append(KMkDirSub);
   1.393 +
   1.394 +	r=TheFs.MkDirAll(mkdirname);	
   1.395 +	test(r==KErrPermissionDenied);
   1.396 +
   1.397 +	r=TheFs.RmDir(mkdirname);	
   1.398 +	test(r==KErrPermissionDenied);
   1.399 +
   1.400 +	r=TheFs.SetSubst(pritestname,EDriveS);
   1.401 +	test(r==KErrPermissionDenied); 
   1.402 +	
   1.403 +	r=TheFs.SetSessionPath(pritestname);
   1.404 +	test(r==KErrPermissionDenied);
   1.405 +
   1.406 +	TheFs.NotifyChange(ENotifyAll,aStat2,pritestname);
   1.407 +	test(aStat2==KErrPermissionDenied);
   1.408 +
   1.409 +	pritestfile=KPrivatePath;
   1.410 +	pritestfile[0]=(TText)('A' + gTheDriveNum);
   1.411 +	pritestfile1=pritestfile;
   1.412 +	pritestfile.Append(KFilePri2);
   1.413 +	pritestfile1.Append(KFilePri3);
   1.414 +	
   1.415 +	oldName=KOldFile;
   1.416 +	oldName[0]=(TText)gDriveToTest;
   1.417 +
   1.418 +	r=TheFs.GetShortName(pritestfile, shortfilename);
   1.419 +	test(r==KErrPermissionDenied);
   1.420 +
   1.421 +	r=TheFs.GetLongName(pritestfile1, longfilename);
   1.422 +	test(r==KErrPermissionDenied);
   1.423 +
   1.424 +	r=file1.Create(TheFs,oldName,EFileWrite);
   1.425 +	test(r==KErrNone || r==KErrAlreadyExists);
   1.426 +	file1.Close();
   1.427 +
   1.428 +	r=TheFs.Replace(oldName,pritestfile);
   1.429 +	test(r==KErrPermissionDenied);
   1.430 +	
   1.431 +	r=TheFs.Rename(pritestfile,pritestfile1);
   1.432 +	test(r==KErrPermissionDenied);
   1.433 +	
   1.434 +	r=TheFs.Entry(pritestfile1,entry);
   1.435 +	test(r==KErrPermissionDenied);
   1.436 +
   1.437 +	r=TheFs.SetEntry(pritestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
   1.438 +	test(r==KErrPermissionDenied);
   1.439 +
   1.440 +	r=TheFs.Delete(pritestfile1);
   1.441 +	test(r==KErrPermissionDenied);
   1.442 +
   1.443 +	}
   1.444 +
   1.445 +
   1.446 +LOCAL_C void privateSIDRFstest()
   1.447 +//
   1.448 +//
   1.449 +//
   1.450 +	{
   1.451 +//private/UID
   1.452 +	theprivatepath[0]=(TText)gDriveToTest;	
   1.453 +	test.Printf(_L("the Private Path = %S"),&theprivatepath);
   1.454 +
   1.455 +	mkdirname.Zero();
   1.456 +	mkdirname.Append(theprivatepath);
   1.457 +	mkdirname.Append(KMkDirSub);
   1.458 +	r=TheFs.MkDirAll(mkdirname);	
   1.459 +	test(r==KErrNone);
   1.460 +
   1.461 +	r=TheFs.RmDir(mkdirname);	
   1.462 +	test(r==KErrNone);
   1.463 +
   1.464 +	r=TheFs.SetSubst(theprivatepath,EDriveS);	
   1.465 +	test(r==KErrNone);
   1.466 +
   1.467 +	r=TheFs.RealName(_L("S:\\File.XXX"),realName);
   1.468 +	test(r==KErrNone);
   1.469 +
   1.470 +	r=TheFs.SetSubst(_L(""),EDriveS);	
   1.471 +	test(r==KErrNone);
   1.472 +	
   1.473 +	r=TheFs.SetSessionPath(theprivatepath);
   1.474 +	test(r==KErrNone);
   1.475 +
   1.476 +	TheFs.NotifyChange(ENotifyAll,aStat3,theprivatepath);
   1.477 +	test(aStat3==KRequestPending);
   1.478 +
   1.479 +		pritestfile=theprivatepath;
   1.480 +	pritestfile[0]=(TText)('A' + gTheDriveNum);
   1.481 +	pritestfile1=pritestfile;
   1.482 +	pritestfile.Append(KFilePri2);
   1.483 +	pritestfile1.Append(KFilePri3);
   1.484 +	
   1.485 +	oldName=KOldFile;
   1.486 +	oldName[0]=(TText)gDriveToTest;
   1.487 +
   1.488 +	r=TheFs.GetShortName(pritestfile, shortfilename);
   1.489 +	test(r==KErrNone || KErrPathNotFound);
   1.490 +
   1.491 +	r=TheFs.GetLongName(pritestfile1, longfilename);
   1.492 +	test(r==KErrNone || KErrPathNotFound);
   1.493 +
   1.494 +	r=file1.Create(TheFs,oldName,EFileWrite);
   1.495 +	test(r==KErrNone || r==KErrAlreadyExists);
   1.496 +	file1.Close();
   1.497 +
   1.498 +	r=TheFs.Replace(oldName,pritestfile);
   1.499 +	test(r==KErrNone);
   1.500 +	
   1.501 +	r=TheFs.Rename(pritestfile,pritestfile1);
   1.502 +	test(r==KErrNone || r==KErrAlreadyExists);
   1.503 +	
   1.504 +	r=TheFs.Entry(pritestfile1,entry);
   1.505 +	test(r==KErrNone);
   1.506 +
   1.507 +	r=TheFs.SetEntry(pritestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
   1.508 +	test(r==KErrNone);
   1.509 +
   1.510 +	r=TheFs.Delete(pritestfile1);
   1.511 +	test(r==KErrNone);
   1.512 +	}
   1.513 +
   1.514 +LOCAL_C void systemRFiletest()
   1.515 +//
   1.516 +//
   1.517 +//
   1.518 +	{
   1.519 +//RFile testing with session path set to //system//
   1.520 +
   1.521 +	r=TheFs.SetSessionPath(systestname);
   1.522 +	test(r==KErrPermissionDenied);
   1.523 +
   1.524 +	r=file1.Temp(TheFs,systestname,fromTemp,EFileWrite);
   1.525 +	test(r==KErrPermissionDenied);
   1.526 +
   1.527 +	TBuf<25> sysfilename;
   1.528 +	sysfilename.Append(systestname);
   1.529 +	sysfilename.Append(KFileSys);
   1.530 +	r=file1.Create(TheFs,sysfilename,EFileWrite);
   1.531 +	test(r==KErrPermissionDenied);
   1.532 +
   1.533 +	r=file1.Open(TheFs,sysfilename,EFileWrite);
   1.534 +	test(r==KErrPermissionDenied);
   1.535 +
   1.536 +	r=file1.Open(TheFs,sysfilename,EFileRead);
   1.537 +	test(r==KErrPermissionDenied);
   1.538 +
   1.539 +	r=file1.Replace(TheFs,sysfilename,EFileWrite);
   1.540 +	test(r==KErrPermissionDenied);
   1.541 +
   1.542 +    TFindFile finder(TheFs);
   1.543 +    CDir* dir = NULL;
   1.544 +    r=finder.FindWildByDir(KWildFile, KWildPath, dir);
   1.545 +	if (!(r==KErrPermissionDenied))
   1.546 +        test.Printf(_L("T_DCDISKADMIN: test find wildcards r = %d (expected KErrPermissionDenied)\n"), r);
   1.547 +	test(r==KErrPermissionDenied);
   1.548 +	delete dir;
   1.549 +	}
   1.550 +
   1.551 +LOCAL_C void resourceRFiletest()
   1.552 +//
   1.553 +//
   1.554 +//
   1.555 +	{
   1.556 +//RFile testing with session path set to //resource//
   1.557 +	r=TheFs.SetSessionPath(restestname);
   1.558 +	test(r==KErrNone);
   1.559 +
   1.560 +	r=file1.Temp(TheFs,restestname,fromTemp,EFileWrite);
   1.561 +	test(r==KErrPermissionDenied);
   1.562 +	file1.Close();
   1.563 +
   1.564 +	r=file1.Create(TheFs,KFileRes,EFileWrite);
   1.565 +	test(r==KErrPermissionDenied);
   1.566 +	file1.Close();
   1.567 +
   1.568 +	r=file1.Open(TheFs,KFileRes,EFileWrite);
   1.569 +	test(r==KErrPermissionDenied);
   1.570 +	file1.Close();
   1.571 +
   1.572 +	r=file1.Open(TheFs,KFileRes,EFileRead|EFileShareReadersOnly);
   1.573 +	test(r==KErrNone || r==KErrPathNotFound);
   1.574 +	file1.Close();
   1.575 +
   1.576 +	r=file1.Open(TheFs,KFileRes,EFileShareReadersOrWriters|EFileRead);
   1.577 +	test(r==KErrNone || r==KErrPathNotFound);
   1.578 +	file1.Close();
   1.579 +
   1.580 +	r=file1.Open(TheFs,KFileRes,EFileShareReadersOrWriters|EFileWrite);
   1.581 +	test(r==KErrPermissionDenied);
   1.582 +	file1.Close();
   1.583 +
   1.584 +	r=file1.Open(TheFs,KFileRes,EFileShareReadersOnly);
   1.585 +	test(r==KErrNone);
   1.586 +
   1.587 +	r=file1.ChangeMode(EFileShareExclusive);	
   1.588 +	test(r==KErrNone);
   1.589 +
   1.590 +	//this operation is prevented as you can not open a file for write access in the resource directory
   1.591 +	r=file1.Rename(KFileRes3);
   1.592 +	test(r==KErrPermissionDenied || r==KErrAccessDenied);
   1.593 +	file1.Close();
   1.594 +
   1.595 +	r=file1.Replace(TheFs,KFileRes,EFileWrite);
   1.596 +	test(r==KErrPermissionDenied);
   1.597 +	file1.Close();
   1.598 +
   1.599 +	}
   1.600 +
   1.601 +
   1.602 +LOCAL_C void privatefalseIDRFiletest()
   1.603 +//
   1.604 +//RFile testing with session path set to //Private//falseID
   1.605 +//
   1.606 +	{
   1.607 +	r=TheFs.SetSessionPath(pritestfalseidname);
   1.608 +	test(r==KErrPermissionDenied);
   1.609 +
   1.610 +	r=file1.Temp(TheFs,pritestfalseidname,fromTemp,EFileWrite);
   1.611 +	test(r==KErrPermissionDenied);
   1.612 +
   1.613 +	TBuf<25> prifilename;
   1.614 +	prifilename.Append(pritestname);
   1.615 +	prifilename.Append(KFileSys);
   1.616 +
   1.617 +	r=file1.Create(TheFs,prifilename,EFileWrite);
   1.618 +	test(r==KErrPermissionDenied);
   1.619 +
   1.620 +	r=file1.Open(TheFs,prifilename,EFileWrite);
   1.621 +	test(r==KErrPermissionDenied);
   1.622 +
   1.623 +	r=file1.Open(TheFs,prifilename,EFileRead);
   1.624 +	test(r==KErrPermissionDenied);
   1.625 +
   1.626 +	r=file1.Replace(TheFs,prifilename,EFileWrite);
   1.627 +	test(r==KErrPermissionDenied);
   1.628 +	}
   1.629 +
   1.630 +
   1.631 +LOCAL_C void privateRFiletest()
   1.632 +//
   1.633 +//RFile testing with session path set to //Private//
   1.634 +//
   1.635 +	{
   1.636 +	r=TheFs.SetSessionPath(pritestname);
   1.637 +	test(r==KErrPermissionDenied);
   1.638 +
   1.639 +	r=file1.Temp(TheFs,pritestname,fromTemp,EFileWrite);
   1.640 +	test(r==KErrPermissionDenied);
   1.641 +
   1.642 +	TBuf<25> prifilename;
   1.643 +	prifilename.Append(pritestname);
   1.644 +	prifilename.Append(KFileSys);
   1.645 +
   1.646 +	r=file1.Create(TheFs,prifilename,EFileWrite);
   1.647 +	test(r==KErrPermissionDenied);
   1.648 +
   1.649 +	r=file1.Open(TheFs,prifilename,EFileWrite);
   1.650 +	test(r==KErrPermissionDenied);
   1.651 +	
   1.652 +	r=file1.Open(TheFs,prifilename,EFileRead);
   1.653 +	test(r==KErrPermissionDenied);
   1.654 +
   1.655 +	r=file1.Replace(TheFs,prifilename,EFileWrite);
   1.656 +	test(r==KErrPermissionDenied);
   1.657 +	}
   1.658 +
   1.659 +
   1.660 +LOCAL_C void privateSIDRFiletest()
   1.661 +//
   1.662 +//Rfile Testing with session path set to //Private//UID//
   1.663 +//
   1.664 +	{
   1.665 +	r=TheFs.SetSessionToPrivate(gTheDriveNum);
   1.666 +	test(r==KErrNone);
   1.667 +		
   1.668 +	r=file1.Temp(TheFs,theprivatepath,fromTemp,EFileWrite);
   1.669 +	test(r==KErrNone);
   1.670 +	file1.Close();
   1.671 +
   1.672 +	r=file1.Create(TheFs,KFilePri,EFileWrite);
   1.673 +	test(r==KErrNone || r==KErrAlreadyExists);
   1.674 +	file1.Close();
   1.675 +
   1.676 +	r=file1.Open(TheFs,KFilePri,EFileWrite);
   1.677 +	test(r==KErrNone);
   1.678 +	file1.Close();
   1.679 +	
   1.680 +	r=file1.Open(TheFs,KFilePri,EFileRead);
   1.681 +	test(r==KErrNone);
   1.682 +	file1.Close();
   1.683 +	
   1.684 +	r=file1.Replace(TheFs,KFilePri,EFileWrite);
   1.685 +	test(r==KErrNone);
   1.686 +	
   1.687 +	r=file1.Rename(KFilePri3);
   1.688 +	test(r==KErrNone || r==KErrAlreadyExists);
   1.689 +	file1.Close();
   1.690 +	}
   1.691 +
   1.692 +
   1.693 +LOCAL_C void RDirtest()
   1.694 +//
   1.695 +//
   1.696 +//
   1.697 +	{
   1.698 +	//system
   1.699 +	dirNameBuf.Zero();
   1.700 +	dirNameBuf = KSystemPath;
   1.701 +	dirNameBuf[0]=(TText)gDriveToTest;
   1.702 +	r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
   1.703 +	test(r==KErrPermissionDenied);
   1.704 +	dir.Close();
   1.705 +	r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
   1.706 +	test(r==KErrPermissionDenied);
   1.707 +	dirNameBuf.Zero();
   1.708 +	delete dirEntries;
   1.709 +	//Private//falseid
   1.710 +	dirNameBuf=KPrivateFalseID;
   1.711 +	dirNameBuf[0]=(TText)gDriveToTest;
   1.712 +	r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
   1.713 +	test(r==KErrPermissionDenied);
   1.714 +	dir.Close();
   1.715 +	r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
   1.716 +	test(r==KErrPermissionDenied);
   1.717 +	dirNameBuf.Zero();
   1.718 +	delete dirEntries;
   1.719 +	//Private
   1.720 +	dirNameBuf=KPrivatePath;
   1.721 +	dirNameBuf[0]=(TText)gDriveToTest;
   1.722 +	r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
   1.723 +	test(r==KErrPermissionDenied);
   1.724 +	dir.Close();
   1.725 +	r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
   1.726 +	test(r==KErrPermissionDenied);
   1.727 +	dirNameBuf.Zero();
   1.728 +	delete dirEntries;
   1.729 +	//Private/uid
   1.730 +	TheFs.PrivatePath(dirNameBuf);
   1.731 +	dirNameBuf.Insert(0,_L("?:"));
   1.732 +	dirNameBuf[0]=(TText)gDriveToTest;
   1.733 +	r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
   1.734 +	test(r==KErrNone);
   1.735 +	dir.Close();
   1.736 +	r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
   1.737 +	test(r==KErrNone);
   1.738 +	dirNameBuf.Zero();
   1.739 +	delete dirEntries;
   1.740 +	//Resource
   1.741 +	dirNameBuf=KResourcePath;
   1.742 +	dirNameBuf[0]=(TText)gDriveToTest;
   1.743 +	r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
   1.744 +	test(r==KErrNone || r==KErrPathNotFound || r==KErrNotFound);
   1.745 +	r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
   1.746 +	test(r==KErrNone || r==KErrPathNotFound || r==KErrNotFound);
   1.747 +	dir.Close();
   1.748 +	delete dirEntries;
   1.749 +	}
   1.750 +
   1.751 +
   1.752 +LOCAL_C void DiskAdminTest()
   1.753 +//
   1.754 +//	test diskadministration capabilitiy
   1.755 +//
   1.756 +	{
   1.757 +	r=TheFs.FileSystemName(fsname,gTheDriveNum);
   1.758 +	test(r==KErrNone);
   1.759 +	r = DismountFileSystem(TheFs, fsname, gTheDriveNum);
   1.760 +	test(r==KErrNone);
   1.761 +//	r=TheFs.RemoveFileSystem(fsname);	//can not test due to bug else where fix exists
   1.762 +//	test(r==KErrPermissionDenied);
   1.763 +//	r=TheFs.AddFileSystem(fsname);
   1.764 +//	test(r==KErrPermissionDenied);
   1.765 +	r = MountFileSystem(TheFs, fsname, gTheDriveNum);
   1.766 +	test(r==KErrNone);
   1.767 +	r=TheFs.SetDriveName(gTheDriveNum,KDriveName);
   1.768 +	test(r==KErrNone);
   1.769 +	r=TheFs.SetVolumeLabel(KVolLable, gTheDriveNum);
   1.770 +	test(r==KErrNone || r==KErrNotSupported);
   1.771 +
   1.772 +	systemRFstest();
   1.773 +	resourceRFstest();
   1.774 +	privateRFstest();
   1.775 +	privateSIDRFstest();
   1.776 +	privateFalseIDRFstest();
   1.777 +
   1.778 +	systemRFiletest();
   1.779 +	resourceRFiletest();
   1.780 +	privateRFiletest();
   1.781 +	privateSIDRFiletest();
   1.782 +	privatefalseIDRFiletest();
   1.783 +
   1.784 +//disk changes to sys and pri paths should have completed these
   1.785 +	test(aStat4 == KRequestPending);
   1.786 +	TheFs.NotifyChangeCancel(aStat4);
   1.787 +	test(aStat4==KErrCancel);
   1.788 +	
   1.789 +	User::WaitForRequest(aStat3);
   1.790 +	test(aStat1==KErrPermissionDenied);
   1.791 +	test(aStat2==KErrPermissionDenied);
   1.792 +	test(aStat3==KErrNone);
   1.793 +	
   1.794 +	r=TheFs.SetSessionPath(systestname);
   1.795 +	test(r==KErrPermissionDenied);
   1.796 +	
   1.797 +//Test RRawDisk class
   1.798 +	r=rawdisk.Open(TheFs,gTheDriveNum);
   1.799 +	test(r==KErrPermissionDenied);
   1.800 +	rawdisk.Close();
   1.801 +
   1.802 +	RDirtest();
   1.803 +
   1.804 +#ifdef __WINS__
   1.805 +	if (User::UpperCase(driveBuf[0]) != 'C')
   1.806 +#endif
   1.807 +		{
   1.808 +		//Test RFormat class
   1.809 +		r=format.Open(TheFs,driveBuf,EHighDensity,count);
   1.810 +		test(r==KErrNone);
   1.811 +
   1.812 +		while(count)
   1.813 +			{
   1.814 +			TInt r=format.Next(count);
   1.815 +			test(r==KErrNone);
   1.816 +			}
   1.817 +		format.Close();
   1.818 +		}
   1.819 +
   1.820 +	driveBuf[0]=(TText)gDriveToTest;
   1.821 +	r=TheFs.ScanDrive(driveBuf);
   1.822 +	test(r==KErrNone || r==KErrNotSupported);
   1.823 +	r=TheFs.CheckDisk(driveBuf);
   1.824 +	test(r==KErrNone || r==KErrNotSupported);
   1.825 +	}
   1.826 +
   1.827 +
   1.828 +
   1.829 +LOCAL_C void TestCaps()
   1.830 +//
   1.831 +//	test format etc that require certain capabilities
   1.832 +//
   1.833 +	{
   1.834 +	driveBuf[0]=(TText)gDriveToTest;
   1.835 +	r=TheFs.SessionPath(temp);
   1.836 +	test(r==KErrNone);
   1.837 +
   1.838 +	test.Printf(_L("Session path: %S"),&temp);
   1.839 +
   1.840 +	r=TheFs.CreatePrivatePath(gTheDriveNum);
   1.841 +	test(r==KErrNone || r== KErrAlreadyExists);
   1.842 +
   1.843 +	TBuf<18> tempPri;
   1.844 +	r=TheFs.PrivatePath(tempPri);
   1.845 +	test(r==KErrNone);
   1.846 +	theprivatepath = _L("?:");
   1.847 +	theprivatepath.Append(tempPri);
   1.848 +	
   1.849 +	DiskAdminTest();
   1.850 +
   1.851 +	TFileName thesessionpath;
   1.852 +
   1.853 +	r=TheFs.SetSessionToPrivate(gTheDriveNum);
   1.854 +	test(r==KErrNone);
   1.855 +	r=TheFs.SessionPath(thesessionpath);
   1.856 +	test(r==KErrNone);
   1.857 +
   1.858 +	test(thesessionpath == theprivatepath);
   1.859 +	}
   1.860 +
   1.861 +
   1.862 +LOCAL_C void CleanupL()
   1.863 +//
   1.864 +// Clean up tests
   1.865 +//
   1.866 +	{
   1.867 +	test.Next(_L("Delete test directory"));
   1.868 +	CFileMan* fMan=CFileMan::NewL(TheFs);
   1.869 +	TInt r=fMan->RmDir(gSessionPath);
   1.870 +	test(r==KErrNone || KErrPathNotFound);
   1.871 +	delete fMan;
   1.872 +	}
   1.873 +
   1.874 +GLDEF_C void CallTestsL(/*TChar aDriveLetter*/)
   1.875 +//
   1.876 +// Do all tests
   1.877 +//
   1.878 +	{
   1.879 +	if( !PlatSec::IsCapabilityEnforced(ECapabilityDiskAdmin))
   1.880 +		{
   1.881 +		test.Printf(_L("Capability ECapabilityDiskAdmin not enabled - leaving t_dcdiskadmin"));
   1.882 +		test.Printf(_L("\n")); // Prevent overwrite by next print
   1.883 +		return;
   1.884 +		}
   1.885 +
   1.886 +	TurnAllocFailureOff();
   1.887 +	TheFs.CharToDrive(gDriveToTest,gTheDriveNum);
   1.888 +	
   1.889 +	TBuf<30> sesspath;
   1.890 +	sesspath=_L("?:\\");
   1.891 +	sesspath[0] = (TText)gDriveToTest;
   1.892 +
   1.893 +	TInt r= TheFs.SetSessionPath(sesspath);
   1.894 +	test(r==KErrNone);
   1.895 +
   1.896 +	//cleanup from previous run of this test
   1.897 +	TBuf<2> cmd;
   1.898 +	cmd.SetLength(1);
   1.899 +	cmd[0] = (TText)gDriveToTest;
   1.900 +	RProcess tp;
   1.901 +	r=tp.Create(_L("clean_prepdc.exe"),sesspath);
   1.902 +	test(r==KErrNone);
   1.903 +	{
   1.904 +	TRequestStatus ps;
   1.905 +	tp.Logon(ps);
   1.906 +	tp.Resume();
   1.907 +	tp.Close();
   1.908 +	User::WaitForRequest(ps);
   1.909 +	}
   1.910 +
   1.911 +	//check double mode ie that Defpath still works	
   1.912 +	RFs fs1;
   1.913 +	RFs fs2;
   1.914 +	
   1.915 +	r=fs1.Connect();
   1.916 +	test(r==KErrNone);
   1.917 +	r=fs1.SessionPath(sesspath);
   1.918 +	test(r==KErrNone);
   1.919 +	test.Printf(_L("session1 Path=%S"),&sesspath);
   1.920 +
   1.921 +	TBuf<30> privatepath;
   1.922 +	r=fs1.SetSessionToPrivate(gTheDriveNum);
   1.923 +	test(r==KErrNone);
   1.924 +	r=fs1.PrivatePath(privatepath);
   1.925 +	test(r==KErrNone);
   1.926 +	r=privatepath.Compare(KExpectedPrivatePath());
   1.927 +	test(r==0);
   1.928 +	r=fs1.SessionPath(sesspath);
   1.929 +	test(r==KErrNone);
   1.930 +	r=privatepath.Compare(sesspath.Mid(KPathPosition));
   1.931 +	test(r==0);
   1.932 +	r=fs1.CreatePrivatePath(gTheDriveNum);
   1.933 +	test(r==KErrNone);
   1.934 +	fs1.Close();
   1.935 +
   1.936 +	r=fs2.Connect();
   1.937 +	test(r==KErrNone);
   1.938 +	r=fs2.SessionPath(sesspath);
   1.939 +	test(r==KErrNone);
   1.940 +	test.Printf(_L("session2 Path=%S"),&sesspath);
   1.941 +	fs2.Close();
   1.942 +
   1.943 +	TestCaps();
   1.944 +
   1.945 +	test.Printf(_L("No of files open=%d"), TheFs.ResourceCount());
   1.946 +
   1.947 +	CleanupL();
   1.948 +	}