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