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