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