0
|
1 |
// Copyright (c) 1997-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_format.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
#define __E32TEST_EXTENSION__
|
|
19 |
|
|
20 |
#include <f32file.h>
|
|
21 |
#include <e32test.h>
|
|
22 |
#include <e32svr.h>
|
|
23 |
#include "t_server.h"
|
|
24 |
#include "t_chlffs.h"
|
|
25 |
|
|
26 |
#include "f32_test_utils.h"
|
|
27 |
|
|
28 |
using namespace F32_Test_Utils;
|
|
29 |
|
|
30 |
|
|
31 |
GLREF_D TFileName gSessionPath;
|
|
32 |
|
|
33 |
|
|
34 |
void GenerateMediaChange()
|
|
35 |
{
|
|
36 |
TBuf<2> b;
|
|
37 |
b.SetLength(2);
|
|
38 |
b[0]=gSessionPath[0];
|
|
39 |
b[1]=':';
|
|
40 |
RFormat format;
|
|
41 |
TInt count;
|
|
42 |
TInt r=format.Open(TheFs,b,EHighDensity,count);
|
|
43 |
test(r==KErrNone);
|
|
44 |
format.Close();
|
|
45 |
}
|
|
46 |
|
|
47 |
RTest test(_L("T_FORMAT"));
|
|
48 |
RSemaphore gSleepThread;
|
|
49 |
TRequestStatus gThreadLogon;
|
|
50 |
|
|
51 |
static TInt gDrive=-1;
|
|
52 |
static const TInt KSectorSize=512;
|
|
53 |
static const TInt KHeapSize=0x200;
|
|
54 |
|
|
55 |
enum TTestCode{ETest3,ETest5};
|
|
56 |
|
|
57 |
|
|
58 |
//-------------------------------------------------------------------
|
|
59 |
TInt DoFormatSteps(RFormat& aFormat, TInt& aFmtCnt)
|
|
60 |
{
|
|
61 |
TInt nRes = KErrNone;
|
|
62 |
|
|
63 |
while(aFmtCnt)
|
|
64 |
{
|
|
65 |
nRes = aFormat.Next(aFmtCnt);
|
|
66 |
if(nRes != KErrNone)
|
|
67 |
{
|
|
68 |
test.Printf(_L("RFormat::Next() failed! code:%d\n"), nRes);
|
|
69 |
break;
|
|
70 |
}
|
|
71 |
}
|
|
72 |
|
|
73 |
return nRes;
|
|
74 |
}
|
|
75 |
|
|
76 |
static void WaitForMedia()
|
|
77 |
//
|
|
78 |
// Wait until the media change is serviced
|
|
79 |
//
|
|
80 |
{
|
|
81 |
|
|
82 |
FOREVER
|
|
83 |
{
|
|
84 |
TInt r=TheFs.MkDir(_L("\\"));
|
|
85 |
if (r!=KErrNotReady)
|
|
86 |
break;
|
|
87 |
User::After(100000);
|
|
88 |
}
|
|
89 |
}
|
|
90 |
|
|
91 |
static TInt ThreadEntryPoint(TAny* aTestCode)
|
|
92 |
//
|
|
93 |
// Thread entry point
|
|
94 |
//
|
|
95 |
{
|
|
96 |
|
|
97 |
RFs fs;
|
|
98 |
TInt ret=fs.Connect();
|
|
99 |
test(ret==KErrNone);
|
|
100 |
ret=fs.SetSessionPath(gSessionPath);
|
|
101 |
test(ret==KErrNone);
|
|
102 |
TTestCode testCode=*(TTestCode*)&aTestCode;
|
|
103 |
TInt count;
|
|
104 |
RFormat format;
|
|
105 |
switch (testCode)
|
|
106 |
{
|
|
107 |
case ETest3:
|
|
108 |
{
|
|
109 |
ret=format.Open(fs,gSessionPath,EQuickFormat,count);
|
|
110 |
test(ret==KErrNone);
|
|
111 |
|
|
112 |
ret = DoFormatSteps(format, count);
|
|
113 |
test(ret==KErrNone);
|
|
114 |
|
|
115 |
format.Close();
|
|
116 |
break;
|
|
117 |
}
|
|
118 |
case ETest5:
|
|
119 |
{
|
|
120 |
ret=format.Open(fs,gSessionPath,EFullFormat,count);
|
|
121 |
test(ret==KErrNone);
|
|
122 |
gSleepThread.Signal();
|
|
123 |
User::After(100000000);
|
|
124 |
break;
|
|
125 |
}
|
|
126 |
default:
|
|
127 |
break;
|
|
128 |
}
|
|
129 |
return(KErrNone);
|
|
130 |
}
|
|
131 |
|
|
132 |
//-------------------------------------------------------------------
|
|
133 |
static void CorruptCurrentDrive()
|
|
134 |
//
|
|
135 |
// Corrupt the current drive
|
|
136 |
//
|
|
137 |
{
|
|
138 |
test.Printf(_L("CorruptCurrentDrive() %c:"), 'A'+CurrentDrive());
|
|
139 |
|
|
140 |
RRawDisk raw;
|
|
141 |
TInt r=raw.Open(TheFs,CurrentDrive());
|
|
142 |
test(r==KErrNone);
|
|
143 |
if (!Is_Lffs(TheFs, gDrive))
|
|
144 |
{
|
|
145 |
TBuf8<KSectorSize> zeroBuf(KSectorSize);
|
|
146 |
Mem::FillZ((TAny*)zeroBuf.Ptr(),zeroBuf.MaxSize());
|
|
147 |
|
|
148 |
//-- for FAT32 we need to corrupt a backup BOOT sector as well,
|
|
149 |
//-- otherwise it can be used and some tests will fail..
|
|
150 |
const TInt KMaxSectors = 25; //-- how many sectors to corrupt
|
|
151 |
for(TInt i=0; i<KMaxSectors; ++i)
|
|
152 |
{
|
|
153 |
r=raw.Write(i*KSectorSize, zeroBuf);
|
|
154 |
test(r==KErrNone);
|
|
155 |
}
|
|
156 |
}
|
|
157 |
else
|
|
158 |
{
|
|
159 |
TBuf8<32> zeroBuf(32);
|
|
160 |
for (TInt j=0;j<32;++j)
|
|
161 |
zeroBuf[j]=(TUint8)j; //Not actuall zero buf for lffs
|
|
162 |
// For LFFS, the media may not exhibit a contiguous region of sufficient length
|
|
163 |
// to support a continuous sequence of writes. This is the case if the
|
|
164 |
// Control Mode Size is non-zero
|
|
165 |
TInt cntlModeSize=GetLFFSControlModeSize();
|
|
166 |
if(cntlModeSize==0)
|
|
167 |
{
|
|
168 |
//test.Printf(_L("CorruptCurrentDrive() - Control mode size is zero\n"),r);
|
|
169 |
for (TInt writePos=0;writePos<0x20200;writePos+=32)
|
|
170 |
{
|
|
171 |
r=raw.Write(writePos,zeroBuf);
|
|
172 |
// The device driver most likely fails when writing a random
|
|
173 |
// buffer due to read back checks. Since we're writing
|
|
174 |
// aligned 32-byte blocks, we don't need to bother that much.
|
|
175 |
// The device driver writes the block but fails when reading
|
|
176 |
// it back.
|
|
177 |
// test(r==KErrNone);
|
|
178 |
}
|
|
179 |
}
|
|
180 |
else if(cntlModeSize>0)
|
|
181 |
{
|
|
182 |
//test.Printf(_L("CorruptCurrentDrive() - Control mode = 0x%x\n"),r);
|
|
183 |
// For devices which have a non-zero control mode size, the writes may
|
|
184 |
// require segmentation.
|
|
185 |
TInt cmBase=0;
|
|
186 |
TInt cmOffset=0;
|
|
187 |
TInt bufOffset=0;
|
|
188 |
TInt bytesWritten=0;
|
|
189 |
TPtrC8 writeBuf;
|
|
190 |
while(bytesWritten < 0x20200)
|
|
191 |
{
|
|
192 |
TInt bufLeft = 32 - bufOffset; // 32 from size of zeroBuf
|
|
193 |
TInt spaceLeft = cntlModeSize - cmOffset;
|
|
194 |
TInt writeLen=(bufLeft>spaceLeft)? spaceLeft : bufLeft;
|
|
195 |
writeBuf.Set(&(zeroBuf[bufOffset]),writeLen);
|
|
196 |
TInt writePos = cmBase + cmOffset;
|
|
197 |
r=raw.Write(writePos,writeBuf);
|
|
198 |
bytesWritten += writeLen;
|
|
199 |
if(bufLeft < spaceLeft)
|
|
200 |
{
|
|
201 |
bufOffset = 0;
|
|
202 |
cmOffset += bufLeft;
|
|
203 |
}
|
|
204 |
else if(bufLeft == spaceLeft)
|
|
205 |
{
|
|
206 |
bufOffset = 0;
|
|
207 |
cmOffset = 0;
|
|
208 |
cmBase += (2*cntlModeSize);
|
|
209 |
}
|
|
210 |
else
|
|
211 |
{ // bufRemaining>spaceRemaining
|
|
212 |
bufOffset += spaceLeft;
|
|
213 |
cmOffset = 0;
|
|
214 |
cmBase += (2*cntlModeSize);
|
|
215 |
}
|
|
216 |
}
|
|
217 |
}
|
|
218 |
else
|
|
219 |
{
|
|
220 |
// Negative value (error code) returned from GetLFFSControlModeSize()
|
|
221 |
test.Printf(_L("CorruptCurrentDrive() - Control mode = %d (ERROR!) \n"),cntlModeSize);
|
|
222 |
test(0);
|
|
223 |
}
|
|
224 |
}
|
|
225 |
raw.Close();
|
|
226 |
}
|
|
227 |
|
|
228 |
|
|
229 |
//-------------------------------------------------------------------
|
|
230 |
static void Test1()
|
|
231 |
//
|
|
232 |
// Format disk
|
|
233 |
//
|
|
234 |
{
|
|
235 |
|
|
236 |
test.Next(_L("Test EFullFormat"));
|
|
237 |
TInt count;
|
|
238 |
RFormat format;
|
|
239 |
|
|
240 |
TInt r=format.Open(TheFs,gSessionPath,EFullFormat,count);
|
|
241 |
test(r==KErrNone);
|
|
242 |
|
|
243 |
r = DoFormatSteps(format, count);
|
|
244 |
test(r==KErrNone);
|
|
245 |
|
|
246 |
format.Close();
|
|
247 |
|
|
248 |
TVolumeInfo volInfo;
|
|
249 |
r=TheFs.Volume(volInfo);
|
|
250 |
test(r==KErrNone);
|
|
251 |
|
|
252 |
if (volInfo.iSize-volInfo.iFree!=0)
|
|
253 |
{
|
|
254 |
test.Printf(_L("Memory 'in use' after a full format = %ld\n"),(volInfo.iSize-volInfo.iFree));
|
|
255 |
test.Printf(_L("volInfo.iSize = %ld\n"),volInfo.iSize);
|
|
256 |
test.Printf(_L("volInfo.iFree = %ld\n"),volInfo.iFree);
|
|
257 |
}
|
|
258 |
|
|
259 |
test.Next(_L("Test EQuickFormat"));
|
|
260 |
r=format.Open(TheFs,gSessionPath,EQuickFormat,count);
|
|
261 |
test(r==KErrNone);
|
|
262 |
|
|
263 |
r = DoFormatSteps(format, count);
|
|
264 |
test(r==KErrNone);
|
|
265 |
|
|
266 |
format.Close();
|
|
267 |
|
|
268 |
r=TheFs.Volume(volInfo);
|
|
269 |
test(r==KErrNone);
|
|
270 |
|
|
271 |
if (volInfo.iSize-volInfo.iFree!=0)
|
|
272 |
{
|
|
273 |
test.Printf(_L("Memory 'in use' after a quick format = %ld\n"),(volInfo.iSize-volInfo.iFree));
|
|
274 |
test.Printf(_L("volInfo.iSize = %ld\n"),volInfo.iSize);
|
|
275 |
test.Printf(_L("volInfo.iFree = %ld\n"),volInfo.iFree);
|
|
276 |
return;
|
|
277 |
}
|
|
278 |
|
|
279 |
}
|
|
280 |
|
|
281 |
//-------------------------------------------------------------------
|
|
282 |
static void Test2()
|
|
283 |
//
|
|
284 |
// Test access controls
|
|
285 |
//
|
|
286 |
{
|
|
287 |
|
|
288 |
test.Next(_L("Test disk cannot be formatted while a file is open"));
|
|
289 |
RFile f;
|
|
290 |
TInt r=f.Replace(TheFs,_L("BLARGME.BLARG"),EFileStream);
|
|
291 |
test(r==KErrNone);
|
|
292 |
|
|
293 |
TInt count;
|
|
294 |
RFormat format;
|
|
295 |
r=format.Open(TheFs,gSessionPath,EFullFormat,count);
|
|
296 |
test(r==KErrInUse);
|
|
297 |
|
|
298 |
f.Close();
|
|
299 |
r=format.Open(TheFs,gSessionPath,EFullFormat,count);
|
|
300 |
test(r==KErrNone);
|
|
301 |
format.Close();
|
|
302 |
|
|
303 |
CheckFileExists(_L("BLARGME.BLARG"),KErrNone);
|
|
304 |
}
|
|
305 |
|
|
306 |
//-------------------------------------------------------------------
|
|
307 |
static void Test3()
|
|
308 |
//
|
|
309 |
// Test notification
|
|
310 |
//
|
|
311 |
{
|
|
312 |
|
|
313 |
test.Next(_L("Test successful format triggers notifier"));
|
|
314 |
MakeFile(_L("\\BLARG_BLARG_BLARG.BLG"));
|
|
315 |
TRequestStatus reqStat;
|
|
316 |
TheFs.NotifyChange(ENotifyEntry,reqStat);
|
|
317 |
|
|
318 |
RThread clientThread;
|
|
319 |
TInt r=clientThread.Create(_L("ClientThread"),ThreadEntryPoint,0x4000,KHeapSize,KHeapSize,(TAny*)ETest3);
|
|
320 |
test.Printf(_L("Created helper thread #1, res=%d\n"),r);
|
|
321 |
test(r==KErrNone);
|
|
322 |
|
|
323 |
clientThread.Logon(gThreadLogon);
|
|
324 |
clientThread.Resume();
|
|
325 |
clientThread.Close();
|
|
326 |
|
|
327 |
User::WaitForRequest(reqStat);
|
|
328 |
test.Printf(_L("Notifier triggered #1, res=%d\n"),reqStat.Int());
|
|
329 |
|
|
330 |
User::WaitForRequest(gThreadLogon);
|
|
331 |
test.Printf(_L("Helper thread exited #1, res=%d\n"),gThreadLogon.Int());
|
|
332 |
|
|
333 |
CheckFileExists(_L("BLARG_BLARG_BLARG.BLG"),KErrNotFound);
|
|
334 |
MakeFile(_L("\\BLARG_BLARG_BLARG.BLG"));
|
|
335 |
|
|
336 |
TheFs.NotifyChange(ENotifyAll,reqStat);
|
|
337 |
r=clientThread.Create(_L("ClientThread"),ThreadEntryPoint,0x4000,KHeapSize,KHeapSize,(TAny*)ETest3);
|
|
338 |
test.Printf(_L("Created helper thread #2, res=%d\n"),r);
|
|
339 |
test(r==KErrNone);
|
|
340 |
|
|
341 |
|
|
342 |
clientThread.Logon(gThreadLogon);
|
|
343 |
clientThread.Resume();
|
|
344 |
clientThread.Close();
|
|
345 |
|
|
346 |
User::WaitForRequest(reqStat);
|
|
347 |
test.Printf(_L("Notifier triggered #2, res=%d\n"),reqStat.Int());
|
|
348 |
|
|
349 |
User::WaitForRequest(gThreadLogon);
|
|
350 |
test.Printf(_L("Helper thread exited #2, res=%d\n"),gThreadLogon.Int());
|
|
351 |
|
|
352 |
CheckFileExists(_L("BLARG_BLARG_BLARG.BLG"),KErrNotFound);
|
|
353 |
}
|
|
354 |
|
|
355 |
//-------------------------------------------------------------------
|
|
356 |
static void Test4()
|
|
357 |
//
|
|
358 |
// Test partially completed formats
|
|
359 |
//
|
|
360 |
{
|
|
361 |
test.Next(_L("Test partially completed formats"));
|
|
362 |
|
|
363 |
if(Is_Automounter(TheFs, gDrive))
|
|
364 |
{//-- if we have automounter FS installed, formatting of the corrupted media is not straightforward
|
|
365 |
//-- The automounter might not be able to decide which of the child file systems shall be used; This issue is covered in a specific test.
|
|
366 |
test.Printf(_L("This step is skipped for Automounter File System\n"));
|
|
367 |
return;
|
|
368 |
}
|
|
369 |
|
|
370 |
MakeFile(_L("\\FORMAT\\DIR1\\BLARG_BLARG_BLARG.BLG"));
|
|
371 |
TInt count;
|
|
372 |
CorruptCurrentDrive();
|
|
373 |
|
|
374 |
test.Printf(_L("Formatting the drive...\n"));
|
|
375 |
|
|
376 |
RFormat format;
|
|
377 |
TInt r=format.Open(TheFs,gSessionPath,EFullFormat,count);
|
|
378 |
test(r==KErrNone);
|
|
379 |
|
|
380 |
while(count)
|
|
381 |
{
|
|
382 |
RDir dir;
|
|
383 |
r=dir.Open(TheFs,_L("\\*.*"),KEntryAttNormal);
|
|
384 |
test(r==KErrInUse);
|
|
385 |
r=format.Next(count);
|
|
386 |
test(r==KErrNone);
|
|
387 |
}
|
|
388 |
format.Close();
|
|
389 |
|
|
390 |
CheckFileExists(_L("\\FORMAT\\DIR1\\BLARG_BLARG_BLARG.BLG"),KErrPathNotFound);
|
|
391 |
}
|
|
392 |
|
|
393 |
//-------------------------------------------------------------------
|
|
394 |
static void Test5()
|
|
395 |
//
|
|
396 |
// Test panic formatting thread
|
|
397 |
//
|
|
398 |
{
|
|
399 |
|
|
400 |
test.Next(_L("Test panic formatting thread"));
|
|
401 |
|
|
402 |
if(Is_Automounter(TheFs, gDrive))
|
|
403 |
{//-- if we have automounter FS installed, formatting of the corrupted media is not straightforward
|
|
404 |
//-- The automounter might not be able to decide which of the child file systems shall be used; This issue is covered in a specific test.
|
|
405 |
test.Printf(_L("This step is skipped for Automounter File System\n"));
|
|
406 |
return;
|
|
407 |
}
|
|
408 |
|
|
409 |
CorruptCurrentDrive();
|
|
410 |
if (!(IsTestingLFFS() && GetDriveLFFS()==EDriveC)) // ??? Remove after ER5U
|
|
411 |
{
|
|
412 |
// UserSvr::ForceRemountMedia(ERemovableMedia0); // Generate media change
|
|
413 |
GenerateMediaChange();
|
|
414 |
WaitForMedia();
|
|
415 |
}
|
|
416 |
|
|
417 |
gSleepThread.CreateLocal(0);
|
|
418 |
RThread clientThread;
|
|
419 |
TInt r=clientThread.Create(_L("ClientThread"),ThreadEntryPoint,0x4000,KHeapSize,KHeapSize,(TAny*)ETest5);
|
|
420 |
test.Printf(_L("Created helper thread #1, res=%d\n"),r);
|
|
421 |
test(r==KErrNone);
|
|
422 |
|
|
423 |
test.Printf(_L("Panicing formatting thread #1\n"));
|
|
424 |
clientThread.Resume();
|
|
425 |
gSleepThread.Wait();
|
|
426 |
test.Printf(_L("Panicing formatting thread #2\n"));
|
|
427 |
User::SetJustInTime(EFalse);
|
|
428 |
clientThread.Panic(_L("Panic formatting thread"),KErrGeneral);
|
|
429 |
User::SetJustInTime(ETrue);
|
|
430 |
User::After(200000); // to let panic take effect
|
|
431 |
test.Printf(_L("Panicing formatting thread #3\n"));
|
|
432 |
|
|
433 |
RDir dir;
|
|
434 |
r=dir.Open(TheFs,_L("\\*.*"),KEntryAttNormal);
|
|
435 |
// if(IsTestingLFFS() && (r==KErrNone))
|
|
436 |
// {
|
|
437 |
// dir.Close();
|
|
438 |
// }
|
|
439 |
// else
|
|
440 |
// {
|
|
441 |
test(r==KErrCorrupt);
|
|
442 |
// }
|
|
443 |
|
|
444 |
test.Printf(_L("Formatting the drive...\n"));
|
|
445 |
|
|
446 |
TInt count;
|
|
447 |
RFormat format;
|
|
448 |
r=format.Open(TheFs,gSessionPath,EQuickFormat,count);
|
|
449 |
test(r==KErrNone);
|
|
450 |
|
|
451 |
r = DoFormatSteps(format, count);
|
|
452 |
test(r==KErrNone);
|
|
453 |
|
|
454 |
format.Close();
|
|
455 |
|
|
456 |
MakeFile(_L("BLARGOID.BLARG"));
|
|
457 |
CheckFileExists(_L("BLARGOID.BLARG"),KErrNone);
|
|
458 |
clientThread.Close();
|
|
459 |
gSleepThread.Close();
|
|
460 |
}
|
|
461 |
|
|
462 |
//-------------------------------------------------------------------
|
|
463 |
static void Test6()
|
|
464 |
//
|
|
465 |
// Test ramdrive is shrunk after formatting
|
|
466 |
//
|
|
467 |
{
|
|
468 |
|
|
469 |
test.Next(_L("Test ramdrive shrinks after formatting"));
|
|
470 |
TVolumeInfo volInfo;
|
|
471 |
TInt r=TheFs.Volume(volInfo);
|
|
472 |
test(r==KErrNone);
|
|
473 |
if ((volInfo.iDrive.iMediaAtt&KMediaAttVariableSize)==0)
|
|
474 |
return;
|
|
475 |
|
|
476 |
TInt64 used=volInfo.iSize-volInfo.iFree;
|
|
477 |
RFile f;
|
|
478 |
r=f.Replace(TheFs,_L("BIGFILE.SIZE"),EFileRead|EFileWrite);
|
|
479 |
test(r==KErrNone);
|
|
480 |
f.SetSize(0x100000); // 1MB
|
|
481 |
f.Close();
|
|
482 |
|
|
483 |
r=TheFs.Volume(volInfo);
|
|
484 |
test(r==KErrNone);
|
|
485 |
TInt64 used2=volInfo.iSize-volInfo.iFree;
|
|
486 |
test(used<used2);
|
|
487 |
|
|
488 |
r=TheFs.Delete(_L("BIGFILE.SIZE"));
|
|
489 |
test(r==KErrNone);
|
|
490 |
r=TheFs.Volume(volInfo);
|
|
491 |
test(r==KErrNone);
|
|
492 |
used2=volInfo.iSize-volInfo.iFree;
|
|
493 |
test(used==used2);
|
|
494 |
|
|
495 |
r=f.Replace(TheFs,_L("BIGFILE.SIZE"),EFileRead|EFileWrite);
|
|
496 |
test(r==KErrNone);
|
|
497 |
f.SetSize(0x100000); // 1MB
|
|
498 |
f.Close();
|
|
499 |
|
|
500 |
r=TheFs.Volume(volInfo);
|
|
501 |
test(r==KErrNone);
|
|
502 |
used2=volInfo.iSize-volInfo.iFree;
|
|
503 |
test(used<used2);
|
|
504 |
|
|
505 |
TInt count;
|
|
506 |
RFormat format;
|
|
507 |
r=format.Open(TheFs,gSessionPath,EQuickFormat,count);
|
|
508 |
test(r==KErrNone);
|
|
509 |
|
|
510 |
r = DoFormatSteps(format, count);
|
|
511 |
test(r==KErrNone);
|
|
512 |
|
|
513 |
format.Close();
|
|
514 |
|
|
515 |
r=TheFs.Volume(volInfo);
|
|
516 |
test(r==KErrNone);
|
|
517 |
used2=volInfo.iSize-volInfo.iFree;
|
|
518 |
test(used>=used2);
|
|
519 |
}
|
|
520 |
|
|
521 |
static void Test7()
|
|
522 |
//
|
|
523 |
// Generate media change before formatting.
|
|
524 |
//
|
|
525 |
{
|
|
526 |
|
|
527 |
test.Next(_L("Generate Media change before formatting"));
|
|
528 |
|
|
529 |
if(Is_Automounter(TheFs, gDrive))
|
|
530 |
{//-- if we have automounter FS installed, formatting of the corrupted media is not straightforward
|
|
531 |
//-- The automounter might not be able to decide which of the child file systems shall be used; This issue is covered in a specific test.
|
|
532 |
test.Printf(_L("This step is skipped for Automounter File System\n"));
|
|
533 |
return;
|
|
534 |
}
|
|
535 |
|
|
536 |
TVolumeInfo volInfo;
|
|
537 |
TInt r=TheFs.Volume(volInfo);
|
|
538 |
test(r==KErrNone);
|
|
539 |
|
|
540 |
if (volInfo.iDrive.iMediaAtt&KMediaAttVariableSize)
|
|
541 |
return; // Don't bother on internal disk
|
|
542 |
|
|
543 |
if (Is_Lffs(TheFs, gDrive))
|
|
544 |
return; // Don't bother on LFFS
|
|
545 |
|
|
546 |
CorruptCurrentDrive();
|
|
547 |
// UserSvr::ForceRemountMedia(ERemovableMedia0); // Generate media change
|
|
548 |
GenerateMediaChange();
|
|
549 |
WaitForMedia();
|
|
550 |
TInt count;
|
|
551 |
RFormat format;
|
|
552 |
r=format.Open(TheFs,gSessionPath,EQuickFormat,count);
|
|
553 |
test(r==KErrNone);
|
|
554 |
|
|
555 |
r = DoFormatSteps(format, count);
|
|
556 |
test(r==KErrNone);
|
|
557 |
|
|
558 |
format.Close();
|
|
559 |
}
|
|
560 |
|
|
561 |
//-------------------------------------------------------------------
|
|
562 |
static void Test8()
|
|
563 |
//
|
|
564 |
// Test incomplete format
|
|
565 |
//
|
|
566 |
{
|
|
567 |
|
|
568 |
test.Next(_L("Test incomplete format"));
|
|
569 |
|
|
570 |
if(Is_Automounter(TheFs, gDrive))
|
|
571 |
{//-- if we have automounter FS installed, formatting of the corrupted media is not straightforward
|
|
572 |
//-- The automounter might not be able to decide which of the child file systems shall be used; This issue is covered in a specific test.
|
|
573 |
test.Printf(_L("This step is skipped for Automounter File System\n"));
|
|
574 |
return;
|
|
575 |
}
|
|
576 |
|
|
577 |
CorruptCurrentDrive();
|
|
578 |
|
|
579 |
if (!(IsTestingLFFS() && GetDriveLFFS()==EDriveC)) // ??? Remove after ER5U
|
|
580 |
{
|
|
581 |
// UserSvr::ForceRemountMedia(ERemovableMedia0); // Generate media change
|
|
582 |
GenerateMediaChange();
|
|
583 |
WaitForMedia();
|
|
584 |
}
|
|
585 |
|
|
586 |
TVolumeInfo volInfo;
|
|
587 |
TInt r=TheFs.Volume(volInfo);
|
|
588 |
// test(r==KErrCorrupt);
|
|
589 |
TInt count;
|
|
590 |
RFormat format;
|
|
591 |
r=format.Open(TheFs,gSessionPath,EQuickFormat,count);
|
|
592 |
r=TheFs.Volume(volInfo);
|
|
593 |
test(r==KErrInUse);
|
|
594 |
r=format.Next(count);
|
|
595 |
test(r==KErrNone);
|
|
596 |
TDriveList driveList;
|
|
597 |
r=TheFs.DriveList(driveList);
|
|
598 |
test(r==KErrNone);
|
|
599 |
|
|
600 |
if(gDrive == EDriveC)
|
|
601 |
{
|
|
602 |
r=TheFs.Volume(volInfo, gDrive);
|
|
603 |
test(r==KErrInUse);
|
|
604 |
}
|
|
605 |
else
|
|
606 |
{
|
|
607 |
r=TheFs.Volume(volInfo,EDriveC);
|
|
608 |
test(r==KErrNone);
|
|
609 |
|
|
610 |
r=TheFs.Volume(volInfo,gDrive);
|
|
611 |
test(r==KErrInUse);
|
|
612 |
|
|
613 |
r=TheFs.Volume(volInfo,gDrive);
|
|
614 |
test(r==KErrInUse);
|
|
615 |
}
|
|
616 |
|
|
617 |
|
|
618 |
format.Close();
|
|
619 |
Format(CurrentDrive());
|
|
620 |
}
|
|
621 |
|
|
622 |
|
|
623 |
//-------------------------------------------------------------------
|
|
624 |
/**
|
|
625 |
Test an API that allows force media formatting with the files or other objects opened on the volume
|
|
626 |
*/
|
|
627 |
void TestFormat_ForceDismount()
|
|
628 |
{
|
|
629 |
test.Next(_L("Test format with forced media dismounting"));
|
|
630 |
|
|
631 |
if(Is_Lffs(TheFs, gDrive))
|
|
632 |
{//-- forced FS dismounting with files/directories opened damages LFFS structure for unknown reason.
|
|
633 |
//-- this is a problem of LFFS, anyway, it is not supported.
|
|
634 |
test.Next(_L("This test can't be performed on LFFS, Skipping."));
|
|
635 |
return;
|
|
636 |
}
|
|
637 |
|
|
638 |
TInt nRes;
|
|
639 |
RFormat format;
|
|
640 |
TUint fmtMode = EQuickFormat;
|
|
641 |
TInt fmtCnt;
|
|
642 |
TBuf<10> drivePath;
|
|
643 |
drivePath.Format(_L("%C:\\"), gDrive+'A');
|
|
644 |
|
|
645 |
|
|
646 |
RBuf8 buf8;
|
|
647 |
RFile file1;
|
|
648 |
RDir dir;
|
|
649 |
|
|
650 |
const TInt KBufLen = 128*K1KiloByte;
|
|
651 |
nRes = buf8.CreateMax(KBufLen);
|
|
652 |
test_KErrNone(nRes);
|
|
653 |
|
|
654 |
_LIT(KFname, "\\file1");
|
|
655 |
|
|
656 |
|
|
657 |
|
|
658 |
//---------------------------------------------------------------------------------
|
|
659 |
//-- 1.1 open a file, try to format in normal mode; this shall fail with KErrInUse
|
|
660 |
test.Printf(_L("Test normal format with normal opened objects\n"));
|
|
661 |
nRes = file1.Replace(TheFs, KFname, EFileWrite);
|
|
662 |
test_KErrNone(nRes);
|
|
663 |
|
|
664 |
fmtMode = EQuickFormat;
|
|
665 |
|
|
666 |
nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt);
|
|
667 |
test(nRes == KErrInUse);
|
|
668 |
format.Close();
|
|
669 |
|
|
670 |
buf8.SetLength(22);
|
|
671 |
nRes = file1.Write(buf8);
|
|
672 |
test_KErrNone(nRes);
|
|
673 |
|
|
674 |
file1.Close();
|
|
675 |
|
|
676 |
//-- 1.2 open a directory, try to format in normal mode; this shall fail with KErrInUse
|
|
677 |
nRes = dir.Open(TheFs,_L("\\*.*"),KEntryAttNormal);
|
|
678 |
test_KErrNone(nRes);
|
|
679 |
|
|
680 |
fmtMode = EQuickFormat;
|
|
681 |
nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt);
|
|
682 |
test(nRes == KErrInUse);
|
|
683 |
format.Close();
|
|
684 |
|
|
685 |
dir.Close();
|
|
686 |
|
|
687 |
|
|
688 |
//---------------------------------------------------------------------------------
|
|
689 |
//-- 2.1 forced quick formatting
|
|
690 |
test.Printf(_L("Test forced quick formatting\n"));
|
|
691 |
nRes = file1.Replace(TheFs, KFname, EFileWrite); //-- open a file
|
|
692 |
test_KErrNone(nRes);
|
|
693 |
|
|
694 |
nRes = dir.Open(TheFs,_L("\\*.*"),KEntryAttNormal); //-- open a directory
|
|
695 |
test_KErrNone(nRes);
|
|
696 |
|
|
697 |
//-- this will mark the current Mount as "Dismounted" and will instantiate another CMountCB for formatting
|
|
698 |
fmtMode = EQuickFormat | EForceFormat;
|
|
699 |
|
|
700 |
nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt);
|
|
701 |
test_KErrNone(nRes);
|
|
702 |
|
|
703 |
nRes = DoFormatSteps(format, fmtCnt);
|
|
704 |
test_KErrNone(nRes);
|
|
705 |
|
|
706 |
format.Close();
|
|
707 |
|
|
708 |
|
|
709 |
nRes=TheFs.CheckDisk(gSessionPath);
|
|
710 |
test(nRes==KErrNone||nRes==KErrNotSupported);
|
|
711 |
|
|
712 |
buf8.SetLength(22);
|
|
713 |
nRes = file1.Write(buf8);
|
|
714 |
test(nRes == KErrDisMounted);
|
|
715 |
file1.Close(); //-- this will make the previously "Dismounted" mount die.
|
|
716 |
dir.Close();
|
|
717 |
|
|
718 |
|
|
719 |
//---------------------------------------------------------------------------------
|
|
720 |
//-- 2.2 forced full formatting
|
|
721 |
test.Printf(_L("Test forced full formatting\n"));
|
|
722 |
nRes = file1.Replace(TheFs, KFname, EFileWrite);
|
|
723 |
test_KErrNone(nRes);
|
|
724 |
|
|
725 |
//-- this will mark the current Mount as "Dismounted" and will instantiate another CMountCB for formatting
|
|
726 |
fmtMode = EFullFormat | EForceFormat;
|
|
727 |
|
|
728 |
nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt);
|
|
729 |
test_KErrNone(nRes);
|
|
730 |
|
|
731 |
nRes = DoFormatSteps(format, fmtCnt);
|
|
732 |
test_KErrNone(nRes);
|
|
733 |
|
|
734 |
format.Close();
|
|
735 |
|
|
736 |
nRes=TheFs.CheckDisk(gSessionPath);
|
|
737 |
test(nRes==KErrNone||nRes==KErrNotSupported);
|
|
738 |
|
|
739 |
buf8.SetLength(22);
|
|
740 |
nRes = file1.Write(buf8);
|
|
741 |
test(nRes == KErrDisMounted);
|
|
742 |
file1.Close(); //-- this will make the previously "Dismounted" mount die.
|
|
743 |
|
|
744 |
//---------------------------------------------------------------------------------
|
|
745 |
//-- 3. check that forced formatting will complete NotifyDismount
|
|
746 |
test.Printf(_L("Test forced formatting completes NotifyDismount\n"));
|
|
747 |
TRequestStatus stat1;
|
|
748 |
|
|
749 |
nRes = file1.Replace(TheFs, KFname, EFileWrite);
|
|
750 |
test_KErrNone(nRes);
|
|
751 |
|
|
752 |
TheFs.NotifyDismount(gDrive, stat1, EFsDismountRegisterClient);
|
|
753 |
test(stat1.Int() == KRequestPending);
|
|
754 |
|
|
755 |
fmtMode = EQuickFormat;
|
|
756 |
nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt);
|
|
757 |
test(nRes == KErrInUse);
|
|
758 |
format.Close();
|
|
759 |
|
|
760 |
test(stat1.Int() == KRequestPending);
|
|
761 |
|
|
762 |
fmtMode = EQuickFormat | EForceFormat;
|
|
763 |
nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt);
|
|
764 |
test_KErrNone(nRes);
|
|
765 |
format.Close();
|
|
766 |
|
|
767 |
User::WaitForRequest(stat1);
|
|
768 |
test(stat1.Int() == KErrNone);
|
|
769 |
|
|
770 |
buf8.SetLength(22);
|
|
771 |
nRes = file1.Write(buf8);
|
|
772 |
test(nRes == KErrDisMounted);
|
|
773 |
file1.Close();
|
|
774 |
|
|
775 |
//---------------------------------------------------------------------------------
|
|
776 |
//-- 4.1 check that forced formatting will succeed with dirty file cache
|
|
777 |
test.Printf(_L("Test forced formatting will succeed with dirty file cache\n"));
|
|
778 |
|
|
779 |
nRes = file1.Replace(TheFs, KFname, EFileWrite | EFileWriteBuffered); //-- enable write caching
|
|
780 |
test_KErrNone(nRes);
|
|
781 |
|
|
782 |
buf8.SetLength(KBufLen);
|
|
783 |
nRes = file1.Write(buf8); //-- this will hopefully get via file write cache
|
|
784 |
test_KErrNone(nRes);
|
|
785 |
|
|
786 |
fmtMode = EQuickFormat | EForceFormat;
|
|
787 |
nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt);
|
|
788 |
test_KErrNone(nRes);
|
|
789 |
format.Close();
|
|
790 |
|
|
791 |
nRes = file1.Write(buf8);
|
|
792 |
test(nRes == KErrDisMounted);
|
|
793 |
file1.Close();
|
|
794 |
|
|
795 |
|
|
796 |
//---------------------------------------------------------------------------------
|
|
797 |
|
|
798 |
test.Printf(_L("Test forced formatting with disk access objects opened\n"));
|
|
799 |
|
|
800 |
//-- 5.1 check that forced formatting will fail when there are "disk access" objects opened RFormat
|
|
801 |
RFormat format1;
|
|
802 |
|
|
803 |
nRes = format1.Open(TheFs, drivePath, fmtMode, fmtCnt);
|
|
804 |
test(nRes == KErrNone);
|
|
805 |
|
|
806 |
fmtMode = EQuickFormat | EForceFormat;
|
|
807 |
nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt);
|
|
808 |
test(nRes == KErrInUse);
|
|
809 |
format.Close();
|
|
810 |
|
|
811 |
format1.Close();
|
|
812 |
|
|
813 |
//-- 5.1 check that forced formatting will fail when there are "disk access" objects opened RRawDisk
|
|
814 |
RRawDisk rawDisk;
|
|
815 |
nRes = rawDisk.Open(TheFs, gDrive);
|
|
816 |
test(nRes == KErrNone);
|
|
817 |
|
|
818 |
fmtMode = EQuickFormat | EForceFormat;
|
|
819 |
nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt);
|
|
820 |
test(nRes == KErrInUse);
|
|
821 |
format.Close();
|
|
822 |
|
|
823 |
rawDisk.Close();
|
|
824 |
|
|
825 |
|
|
826 |
//---------------------------------------------------------------------------------
|
|
827 |
//-- 6. Try forced formatting with clamped files, this shall fail with KErrInuse
|
|
828 |
test.Printf(_L("Test forced formatting and clamps on the volume\n"));
|
|
829 |
|
|
830 |
nRes = file1.Replace(TheFs, KFname, EFileWrite);
|
|
831 |
test_KErrNone(nRes);
|
|
832 |
|
|
833 |
buf8.SetLength(KBufLen);
|
|
834 |
nRes = file1.Write(buf8); //-- this will hopefully get via file write cache
|
|
835 |
test_KErrNone(nRes);
|
|
836 |
file1.Flush();
|
|
837 |
|
|
838 |
//-- Clamp file
|
|
839 |
RFileClamp handle;
|
|
840 |
|
|
841 |
nRes=handle.Clamp(file1);
|
|
842 |
if(nRes != KErrNone)
|
|
843 |
{
|
|
844 |
test.Printf(_L("file clamps on this drive are not supported\n"));
|
|
845 |
}
|
|
846 |
else
|
|
847 |
{
|
|
848 |
fmtMode = EQuickFormat | EForceFormat;
|
|
849 |
nRes = format.Open(TheFs, drivePath, fmtMode, fmtCnt);
|
|
850 |
test(nRes == KErrInUse);
|
|
851 |
format.Close();
|
|
852 |
}
|
|
853 |
|
|
854 |
handle.Close(TheFs);
|
|
855 |
|
|
856 |
file1.Close();
|
|
857 |
|
|
858 |
buf8.Close();
|
|
859 |
}
|
|
860 |
|
|
861 |
|
|
862 |
void CallTestsL()
|
|
863 |
//
|
|
864 |
// Call tests that may leave
|
|
865 |
//
|
|
866 |
{
|
|
867 |
|
|
868 |
TInt r;
|
|
869 |
r = TheFs.CharToDrive(gDriveToTest, gDrive);
|
|
870 |
test(r == KErrNone);
|
|
871 |
|
|
872 |
//-- set up console output
|
|
873 |
F32_Test_Utils::SetConsole(test.Console());
|
|
874 |
|
|
875 |
TInt nRes=TheFs.CharToDrive(gDriveToTest, gDrive);
|
|
876 |
test(nRes==KErrNone);
|
|
877 |
|
|
878 |
PrintDrvInfo(TheFs, gDrive);
|
|
879 |
|
|
880 |
if(Is_Win32(TheFs, gDrive))
|
|
881 |
return; //-- emulator drive c:
|
|
882 |
|
|
883 |
|
|
884 |
SetSessionPath(_L("\\"));
|
|
885 |
|
|
886 |
Test1();
|
|
887 |
Test2();
|
|
888 |
Test3();
|
|
889 |
Test4();
|
|
890 |
Test5();
|
|
891 |
Test6();
|
|
892 |
Test7();
|
|
893 |
Test8();
|
|
894 |
TestFormat_ForceDismount();
|
|
895 |
|
|
896 |
r=TheFs.CheckDisk(gSessionPath);
|
|
897 |
test(r==KErrNone||r==KErrNotSupported);
|
|
898 |
}
|
|
899 |
|
|
900 |
|