First public contribution.
1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32test\server\t_dcdiskadminallfiles.cpp
21 #include <e32std_private.h>
23 #include <e32def_private.h>
27 GLDEF_D RTest test(_L("T_DCDISKADMINALLFILES"));
28 GLDEF_D TTime gTimeNow;
29 LOCAL_D TInt gTheDriveNum;
32 const TInt KPathPosition = 2;
33 _LIT(KExpectedPrivatePath, "\\Private\\00000001\\");
34 _LIT(KResourcePath, "?:\\Resource\\");
35 _LIT(KSystemPath, "?:\\Sys\\");
36 _LIT(KPrivatePath, "?:\\Private\\");
37 _LIT(KPrivateFalseID, "?:\\Private\\FFFFFFFF\\");
38 _LIT(KDriveName, "Billy");
39 _LIT(KVolLable, "Benny");
40 _LIT(KFileSys, "systemfile.txt");
41 _LIT(KFileSys3, "sysfile.rna");
42 _LIT(KFilePri, "privatefile.txt");
43 _LIT(KFilePri2, "privatefile.tmp");
44 _LIT(KFilePri3, "prifile.rna");
45 _LIT(KFileRes, "resourcefile.txt");
46 _LIT(KFileRes3, "resfile.rna");
47 _LIT(KMkDirSub,"Subdir\\");
48 _LIT(KOldFile,"?:\\Anyold.txt");
51 _LIT(KWildPath, "Z:\\SYSTEM\\"); // Until Loader is modified to use /Sys/
53 _LIT(KWildPath, "Z:\\SYS\\");
58 TBuf<4> driveBuf=_L("?:\\");
71 TBuf<40> theprivatepath;
72 TBuf<40> pritestfalseidname;
78 TBuf<40> shortfilename;
79 TBuf<40> longfilename;
81 TRequestStatus aStat1;
82 TRequestStatus aStat2;
83 TRequestStatus aStat3;
84 TRequestStatus aStat4;
87 // TDriveInfo adriveInfo;
92 TBuf<40> systestfile1;
93 TBuf<40> pritestfile1;
94 TBuf<40> restestfile1;
104 LOCAL_C void systemRFsTest()
106 // RFs test on system Directory
109 systestname=KSystemPath;
110 systestname[0]=(TText)('A' + gTheDriveNum);
113 mkdirname.Append(systestname);
114 mkdirname.Append(KMkDirSub);
115 r=TheFs.MkDirAll(mkdirname);
116 test(r==KErrPermissionDenied);
118 TheFs.RmDir(mkdirname);
119 test(r==KErrPermissionDenied);
121 r=TheFs.SetSubst(systestname,EDriveO);
122 test(r==KErrPermissionDenied);
124 r=TheFs.SetSessionPath(systestname);
127 TheFs.NotifyChange(ENotifyAll,aStat1,systestname);
128 test(aStat1==KRequestPending);
130 systestfile=KSystemPath;
131 systestfile[0]=(TText)('A' + gTheDriveNum);
132 systestfile1=systestfile;
133 systestfile.Append(KFileSys);
134 systestfile1.Append(KFileSys3);
137 oldName[0]=(TText)gDriveToTest;
139 r=TheFs.GetShortName(systestfile, shortfilename);
140 test(r==KErrNone || r==KErrNotFound || r==KErrNotSupported);
142 r=TheFs.GetLongName(systestfile1, longfilename);
143 test(r==KErrNone || r==KErrNotFound || r==KErrNotSupported);
145 r=file1.Create(TheFs,oldName,EFileWrite);
146 test(r==KErrNone || r==KErrAlreadyExists);
149 r=TheFs.Replace(oldName,systestfile);
150 test(r==KErrPermissionDenied);
152 r=TheFs.Rename(systestfile,systestfile1);
153 test(r==KErrPermissionDenied);
155 r=TheFs.Entry(systestfile1,entry);
156 test(r==KErrNone || KErrNotFound);
158 r=TheFs.SetEntry(systestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
159 test(r==KErrPermissionDenied);
161 r=TheFs.Delete(systestfile1);
162 test(r==KErrPermissionDenied);
165 LOCAL_C void ResourceRFsTest()
170 restestname=KResourcePath;
171 restestname[0]=(TText)('A' + gTheDriveNum);
174 mkdirname.Append(restestname);
175 mkdirname.Append(KMkDirSub);
176 r=TheFs.MkDirAll(mkdirname);
177 test(r==KErrPermissionDenied);
179 TheFs.RmDir(mkdirname);
180 test(r==KErrPermissionDenied);
182 // Change due to defect DEF099546 fix
183 // TCB capability is required for following operation.
184 r=TheFs.SetSubst(restestname,EDriveO);
186 test(r==KErrPermissionDenied);
188 // SetSubst will fail.
189 //r=TheFs.RealName(_L("O:\\File.XXX"),realName);
192 //r=TheFs.SetSubst(_L(""),EDriveO);
195 r=TheFs.SetSessionPath(restestname);
198 TheFs.NotifyChange(ENotifyAll,aStat4,restestname);
199 test(aStat4==KRequestPending);
201 restestfile=KResourcePath;
202 restestfile[0]=(TText)('A' + gTheDriveNum);
203 restestfile1=restestfile;
204 restestfile.Append(KFileRes);
205 restestfile1.Append(KFileRes3);
208 oldName[0]=(TText)gDriveToTest;
210 r=TheFs.GetShortName(restestfile, shortfilename);
211 test(r==KErrNone || r==KErrNotFound || r==KErrNotSupported);
213 r=TheFs.GetLongName(restestfile1, longfilename);
214 test(r==KErrNone || r==KErrNotFound || r==KErrNotSupported);
216 r=file1.Create(TheFs,oldName,EFileWrite);
217 test(r==KErrNone || r==KErrAlreadyExists);
220 r=TheFs.Replace(oldName,restestfile);
221 test(r==KErrPermissionDenied);
223 r=TheFs.Rename(restestfile,restestfile1);
224 test(r==KErrPermissionDenied);
226 r=TheFs.Entry(restestfile1,entry);
227 test(r==KErrNone || r==KErrPathNotFound || r==KErrNotFound);
229 r=TheFs.SetEntry(restestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
230 test(r==KErrPermissionDenied);
232 r=TheFs.Delete(restestfile1);
233 test(r==KErrPermissionDenied);
238 LOCAL_C void privatefalseIDRFsTest()
243 pritestfalseidname=KPrivateFalseID;
244 pritestfalseidname[0]=(TText)('A' + gTheDriveNum);
247 mkdirname.Append(pritestfalseidname);
248 mkdirname.Append(KMkDirSub);
250 r=TheFs.MkDirAll(mkdirname);
253 r=TheFs.RmDir(mkdirname);
256 r=TheFs.SetSubst(pritestfalseidname,EDriveO);
259 r=TheFs.RealName(_L("O:\\File.XXX"),realName);
262 r=TheFs.SetSubst(_L(""),EDriveO);
265 r=TheFs.SetSessionPath(pritestfalseidname);
268 TheFs.NotifyChange(ENotifyAll,aStat2,pritestfalseidname);
269 test(aStat2==KRequestPending);
272 pritestfile=KPrivateFalseID;
273 pritestfile[0]=(TText)('A' + gTheDriveNum);
274 pritestfile1=pritestfile;
275 pritestfile.Append(KFilePri2);
276 pritestfile1.Append(KFilePri3);
279 oldName[0]=(TText)gDriveToTest;
281 r=TheFs.GetShortName(pritestfile, shortfilename);
282 test(r==KErrNone || r==KErrNotFound || r==KErrNotSupported);
284 r=TheFs.GetLongName(pritestfile1, longfilename);
285 test(r==KErrNone || r==KErrNotFound || r==KErrNotSupported);
287 r=file1.Create(TheFs,oldName,EFileWrite);
288 test(r==KErrNone || r==KErrAlreadyExists);
291 r=TheFs.Replace(oldName,pritestfile);
294 r=TheFs.Rename(pritestfile,pritestfile1);
297 r=TheFs.Entry(pritestfile1,entry);
300 r=TheFs.SetEntry(pritestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
303 r=TheFs.Delete(pritestfile1);
309 LOCAL_C void privateRFsTest()
315 pritestname=KPrivatePath;
316 pritestname[0]=(TText)('A' + gTheDriveNum);
319 mkdirname.Append(pritestname);
320 mkdirname.Append(KMkDirSub);
322 r=TheFs.MkDirAll(mkdirname);
325 r=TheFs.RmDir(mkdirname);
328 r=TheFs.SetSubst(pritestname,EDriveO);
331 r=TheFs.RealName(_L("O:\\File.XXX"),realName);
334 r=TheFs.SetSubst(_L(""),EDriveO);
337 r=TheFs.SetSessionPath(pritestname);
340 TheFs.NotifyChange(ENotifyAll,aStat2,pritestname);
341 test(aStat2==KRequestPending);
344 pritestfile=KPrivatePath;
345 pritestfile[0]=(TText)('A' + gTheDriveNum);
346 pritestfile1=pritestfile;
347 pritestfile.Append(KFilePri2);
348 pritestfile1.Append(KFilePri3);
351 oldName[0]=(TText)gDriveToTest;
353 r=TheFs.GetShortName(pritestfile, shortfilename);
354 test(r==KErrNone || r==KErrNotFound || r==KErrNotSupported);
356 r=TheFs.GetLongName(pritestfile1, longfilename);
357 test(r==KErrNone || r==KErrNotFound || r==KErrNotSupported);
359 r=file1.Create(TheFs,oldName,EFileWrite);
360 test(r==KErrNone || r==KErrAlreadyExists);
363 r=TheFs.Replace(oldName,pritestfile);
364 test(r==KErrNone || r==KErrNotFound);
366 r=TheFs.Rename(pritestfile,pritestfile1);
369 r=TheFs.Entry(pritestfile1,entry);
372 r=TheFs.SetEntry(pritestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
375 r=TheFs.Delete(pritestfile1);
381 LOCAL_C void privateSIDRFstest()
383 theprivatepath[0]=(TText)gDriveToTest;
384 test.Printf(_L("the Private Path = %S"),&theprivatepath);
387 mkdirname.Append(theprivatepath);
388 mkdirname.Append(KMkDirSub);
389 r=TheFs.MkDirAll(mkdirname);
392 r=TheFs.RmDir(mkdirname);
395 r=TheFs.SetSubst(theprivatepath,EDriveO);
398 r=TheFs.RealName(_L("O:\\File.XXX"),realName);
401 r=TheFs.SetSubst(_L(""),EDriveO);
404 r=TheFs.SetSessionPath(theprivatepath);
407 TheFs.NotifyChange(ENotifyAll,aStat3,theprivatepath);
408 test(aStat3==KRequestPending);
410 pritestfile=theprivatepath;
411 pritestfile[0]=(TText)('A' + gTheDriveNum);
412 pritestfile1=pritestfile;
413 pritestfile.Append(KFilePri2);
414 pritestfile1.Append(KFilePri3);
417 oldName[0]=(TText)gDriveToTest;
419 r=TheFs.GetShortName(pritestfile, shortfilename);
420 test(r==KErrNone || r==KErrNotFound || r==KErrNotSupported);
422 r=TheFs.GetLongName(pritestfile1, longfilename);
423 test(r==KErrNone || r==KErrNotFound || r==KErrNotSupported);
425 r=file1.Create(TheFs,oldName,EFileWrite);
426 test(r==KErrNone || r==KErrAlreadyExists);
429 r=TheFs.Replace(oldName,pritestfile);
432 r=TheFs.Rename(pritestfile,pritestfile1);
433 test(r==KErrNone || r==KErrAlreadyExists);
435 r=TheFs.Entry(pritestfile1,entry);
438 r=TheFs.SetEntry(pritestfile1,testtime,KEntryAttNormal,KEntryAttReadOnly);
441 r=TheFs.Delete(pritestfile1);
446 LOCAL_C void systemRFiletest()
448 //RFile testing with session path set to //system//
452 r=TheFs.SetSessionPath(systestname);
455 r=file1.Temp(TheFs,systestname,fromTemp,EFileWrite);
456 test(r==KErrPermissionDenied);
459 systestfile=systestname;
460 systestfile.Append(KFileSys);
461 r=file1.Create(TheFs,systestfile,EFileWrite);
462 test(r==KErrPermissionDenied);
465 r=file1.Open(TheFs,systestfile,EFileWrite);
466 test(r==KErrPermissionDenied);
468 r=file1.Open(TheFs,systestfile,EFileRead);
469 test(r==KErrNone|| r==KErrNotFound);
471 r=file1.Replace(TheFs,systestfile,EFileWrite);
472 test(r==KErrPermissionDenied);
474 TFindFile finder(TheFs);
476 r=finder.FindWildByDir(KWildFile, KWildPath, dir);
478 test.Printf(_L("T_DCDISKADMINALLFILES: test find wildcards r = %d (expected KErrNone)\n"), r);
483 LOCAL_C void resourceRFiletest()
485 //RFile testing with session path set to //resource//
488 r=TheFs.SetSessionPath(restestname);
491 r=file1.Temp(TheFs,restestname,fromTemp,EFileWrite);
492 test(r==KErrPermissionDenied);
495 r=file1.Create(TheFs,KFileRes,EFileWrite);
496 test(r==KErrPermissionDenied);
499 r=file1.Open(TheFs,KFileRes,EFileWrite|EFileShareExclusive );
500 test(r==KErrPermissionDenied);
502 r=file1.Open(TheFs,KFileRes,EFileShareReadersOnly);
503 test(r==KErrNone || KErrPathNotFound || KErrNotFound);
506 r=file1.Open(TheFs,KFileRes,EFileShareReadersOrWriters|EFileRead);
507 test(r==KErrNone || KErrPathNotFound || KErrNotFound);
510 r=file1.Open(TheFs,KFileRes,EFileShareReadersOrWriters|EFileWrite);
511 test(r==KErrPermissionDenied);
514 r=file1.Replace(TheFs,KFileRes3,EFileWrite);
515 test(r==KErrPermissionDenied);
520 LOCAL_C void privatefalseIDRFiletest()
522 //RFile testing with session path set to //Private//false ID
525 r=TheFs.SetSessionPath(pritestfalseidname);
528 r=file1.Temp(TheFs,pritestfalseidname,fromTemp,EFileWrite);
532 r=file1.Create(TheFs,KFilePri,EFileWrite);
536 r=file1.Open(TheFs,KFilePri,EFileWrite);
540 r=file1.Open(TheFs,KFilePri,EFileRead);
544 r=file1.Replace(TheFs,KFilePri,EFileWrite);
547 r=file1.Rename(KFilePri3);
553 LOCAL_C void privateRFiletest()
555 //RFile testing with session path set to //Private//
558 r=TheFs.SetSessionPath(pritestname);
561 r=file1.Temp(TheFs,pritestname,fromTemp,EFileWrite);
565 r=file1.Create(TheFs,KFilePri,EFileWrite);
569 r=file1.Open(TheFs,KFilePri,EFileWrite);
573 r=file1.Open(TheFs,KFilePri,EFileRead);
577 r=file1.Replace(TheFs,KFilePri,EFileWrite);
580 r=file1.Rename(KFilePri3);
586 LOCAL_C void privateSIDRFiletest()
588 //Rfile Testing with session path set to //Private//UID//
591 r=TheFs.SetSessionToPrivate(gTheDriveNum);
594 r=file1.Temp(TheFs,theprivatepath,fromTemp,EFileWrite);
598 r=file1.Create(TheFs,KFilePri,EFileWrite);
602 r=file1.Open(TheFs,KFilePri,EFileWrite);
606 r=file1.Open(TheFs,KFilePri,EFileRead);
611 r=file1.Replace(TheFs,KFilePri,EFileWrite);
614 r=file1.Rename(KFilePri3);
619 LOCAL_C void RDirtest()
627 TBuf<30> dirNameBuf(KSystemPath);
628 dirNameBuf[0]=(TText)gDriveToTest;
629 r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
630 test(r==KErrNone || r==KErrPathNotFound || r==KErrNotFound);
634 r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
640 dirNameBuf=KPrivateFalseID;
641 dirNameBuf[0]=(TText)gDriveToTest;
642 r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
645 r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
650 dirNameBuf=KPrivatePath;
651 dirNameBuf[0]=(TText)gDriveToTest;
652 r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
655 r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
660 TheFs.PrivatePath(dirNameBuf);
661 dirNameBuf.Insert(0,_L("?:"));
662 dirNameBuf[0]=(TText)gDriveToTest;
663 r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
666 r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
671 dirNameBuf=KResourcePath;
672 dirNameBuf[0]=(TText)gDriveToTest;
673 r=dir.Open(TheFs,dirNameBuf,KEntryAttNormal);
674 test(r==KErrNone || r==KErrPathNotFound);
677 r=TheFs.GetDir(dirNameBuf,KEntryAttMatchMask,ESortByName,dirEntries);
685 LOCAL_C void TestDiskAdminAllfiles()
687 // Test with root capabilities
690 r=TheFs.FileSystemName(fsname,gTheDriveNum);
692 r = DismountFileSystem(TheFs, fsname, gTheDriveNum);
694 // r=TheFs.RemoveFileSystem(fsname); //can not test due to bug else where fix exists
695 // test(r==KErrNone);
696 // r=TheFs.AddFileSystem(fsname);
697 // test(r==KErrNone);
698 r = MountFileSystem(TheFs, fsname, gTheDriveNum);
700 r=TheFs.SetDriveName(gTheDriveNum,KDriveName);
703 r=TheFs.SetVolumeLabel(KVolLable, gTheDriveNum);
711 privatefalseIDRFsTest();
716 privateSIDRFiletest();
717 privatefalseIDRFiletest();
719 //check notifier return values set in rfs testing
720 //User::WaitForRequest(aStat1);
721 User::WaitForRequest(aStat2);
722 User::WaitForRequest(aStat3);
723 //User::WaitForRequest(aStat4);
724 test(aStat2==KErrNone);
725 test(aStat3==KErrNone);
727 test(aStat1 == KRequestPending);
728 TheFs.NotifyChangeCancel(aStat1);
729 test(aStat1==KErrCancel);
731 test(aStat4 == KRequestPending);
732 TheFs.NotifyChangeCancel(aStat4);
733 test(aStat4==KErrCancel);
735 r=TheFs.SetSessionPath(systestname);
738 //Test RRawDisk class
739 r=rawdisk.Open(TheFs,gTheDriveNum);
740 test(r==KErrPermissionDenied);
746 if (User::UpperCase(driveBuf[0]) != 'C')
750 r=format.Open(TheFs,driveBuf,EHighDensity,count);
754 TInt r=format.Next(count);
760 driveBuf[0]=(TText)gDriveToTest;
761 r=TheFs.ScanDrive(driveBuf);
762 test(r==KErrNone || r==KErrNotSupported || KErrInUse);
763 r=TheFs.CheckDisk(driveBuf);
764 test(r==KErrNone || r==KErrNotSupported || KErrInUse);
767 LOCAL_C void TestCaps()
769 // test format etc that require certain capabilities
772 #ifndef __REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
773 const char myDiagMsg[] = "Capability Check Failure";
774 #endif //__REMOVE_PLATSEC_DIAGNOSTIC_STRINGS__
775 r=RProcess().HasCapability(ECapabilityAllFiles, __PLATSEC_DIAGNOSTIC_STRING(myDiagMsg));
777 r=RProcess().HasCapability(ECapabilityDiskAdmin, __PLATSEC_DIAGNOSTIC_STRING(myDiagMsg));
780 driveBuf[0]=(TText)gDriveToTest;
781 r=TheFs.SessionPath(temp);
784 test.Printf(_L("Session path: %S"),&temp);
786 r=TheFs.CreatePrivatePath(gTheDriveNum);
787 test(r==KErrNone || r== KErrAlreadyExists);
790 r=TheFs.PrivatePath(tempPri);
792 theprivatepath = _L("?:");
793 theprivatepath.Append(tempPri);
795 TestDiskAdminAllfiles();
797 TFileName thesessionpath;
798 r=TheFs.SetSessionToPrivate(gTheDriveNum);
800 r=TheFs.SessionPath(thesessionpath);
802 test(thesessionpath == theprivatepath);
806 LOCAL_C void CleanupL()
811 test.Next(_L("Delete test directory"));
812 CFileMan* fMan=CFileMan::NewL(TheFs);
813 TInt r=fMan->RmDir(gSessionPath);
814 test(r==KErrNone || KErrPathNotFound);
818 GLDEF_C void CallTestsL(/*TChar aDriveLetter*/)
823 if( !PlatSec::IsCapabilityEnforced(ECapabilityAllFiles) ||
824 !PlatSec::IsCapabilityEnforced(ECapabilityDiskAdmin))
826 test.Printf(_L("Capabilities insufficient - leaving t_dcdiskadminallfiles"));
827 test.Printf(_L("\n")); // Prevent overwrite by next print
830 TurnAllocFailureOff();
831 TheFs.CharToDrive(gDriveToTest,gTheDriveNum);
835 sesspath[0] = (TText)gDriveToTest;
837 TInt r= TheFs.SetSessionPath(sesspath);
842 cmd[0] = (TText)gDriveToTest;
844 r=tp.Create(_L("clean_prepdc.exe"),sesspath);
851 User::WaitForRequest(ps);
854 //check double mode ie that Defpath still works
860 r=fs1.SessionPath(sesspath);
862 test.Printf(_L("session1 Path=%S"),&sesspath);
864 TBuf<30> privatepath;
865 r=fs1.SetSessionToPrivate(gTheDriveNum);
867 r=fs1.PrivatePath(privatepath);
869 r=privatepath.Compare(KExpectedPrivatePath());
871 r=fs1.SessionPath(sesspath);
873 r=privatepath.Compare(sesspath.Mid(KPathPosition));
875 r=fs1.CreatePrivatePath(gTheDriveNum);
881 r=fs2.SessionPath(sesspath);
883 test.Printf(_L("session2 Path=%S"),&sesspath);
888 test.Printf(_L("No of files open=%d"), TheFs.ResourceCount());