author | hgs |
Wed, 22 Sep 2010 10:53:45 +0100 | |
changeset 271 | dc268b18d709 |
parent 123 | fc55edbf3919 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1998-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: |
|
123 | 14 |
// f32test\filesystem\fat\t_scn32dr1.cpp |
15 |
// Tests that ScanDrive fixes known errors to a Rugged FAT drive |
|
0 | 16 |
// |
123 | 17 |
|
18 |
#define __E32TEST_EXTENSION__ |
|
0 | 19 |
|
20 |
#include <f32file.h> |
|
21 |
#include <e32test.h> |
|
22 |
||
23 |
#include "t_server.h" |
|
24 |
||
25 |
#include "fat_utils.h" |
|
26 |
using namespace Fat_Test_Utils; |
|
27 |
||
28 |
#ifdef __VC32__ |
|
29 |
// Solve compilation problem caused by non-English locale |
|
30 |
#pragma setlocale("english") |
|
31 |
#endif |
|
32 |
||
33 |
/* |
|
34 |
T_testscndrv tests the scandrive utility. Errors in this test will be |
|
35 |
introduced using the RRawdDisk class. The correct fixup is tested by rereading |
|
36 |
the disk. Drives tested are the default path(epoc) and X: (wins). This test |
|
37 |
returns immediately if used on the internal ram drive |
|
38 |
*/ |
|
39 |
||
40 |
/* |
|
41 |
The initial FAT12 directory structure (with cluster number in brackets) is as follows: |
|
42 |
||
43 |
| |
|
44 |
- scndrv (2) |
|
45 |
| |
|
46 |
- dir1 (3-4) |
|
47 |
| | |
|
48 |
| <a very long file name (19 entries)> (5) |
|
49 |
| |
|
50 |
- dir2 (6) |
|
51 |
| |
|
52 |
- full (7) |
|
53 |
| | |
|
54 |
| | |
|
55 |
| - <seven 2*32 bytes entries> (11-17) |
|
56 |
| |
|
57 |
- somedirwith3entries (8) |
|
58 |
| |
|
59 |
- somedir2with3entries (9) |
|
60 |
| |
|
61 |
- almostfull(10) |
|
62 |
| |
|
63 |
- <two lots of 6*32 bytes entries> (18+19) |
|
64 |
||
65 |
*/ |
|
66 |
||
67 |
/* |
|
68 |
The initial FAT32 directory structure (with cluster number in brackets is as follows): |
|
69 |
||
70 |
| |
|
71 |
- scndrv (3) |
|
72 |
| |
|
73 |
- dir1 (4) |
|
74 |
| | |
|
75 |
| <a very long file name (19 entries)> (5) |
|
76 |
| |
|
77 |
- dir2 (6) |
|
78 |
| |
|
79 |
- full (7) |
|
80 |
| | |
|
81 |
| | |
|
82 |
| - <seven 2*32 bytes entries> (11-17) |
|
83 |
| |
|
84 |
- somedirwith3entries (8) |
|
85 |
| |
|
86 |
- somedir2with3entries (9) |
|
87 |
| |
|
88 |
- almostfull(10) |
|
89 |
| |
|
90 |
- <two lots of 6*32 bytes entries> (18+19) |
|
91 |
||
92 |
*/ |
|
93 |
||
94 |
GLDEF_D RTest test(_L("T_SCN32DR1")); |
|
95 |
||
96 |
LOCAL_D const TInt KMaxFatEntries = 2048; |
|
97 |
LOCAL_D const TInt KMaxFatSize = KMaxFatEntries * 4; |
|
98 |
||
99 |
LOCAL_D const TInt KDirAttrReadOnly = 0x01; |
|
100 |
LOCAL_D const TInt KDirAttrHidden = 0x02; |
|
101 |
LOCAL_D const TInt KDirAttrSystem = 0x04; |
|
102 |
LOCAL_D const TInt KDirAttrVolumeId = 0x08; |
|
103 |
LOCAL_D const TInt KDirAttrDirectory = 0x10; |
|
104 |
LOCAL_D const TInt KDirAttrArchive = 0x20; |
|
105 |
LOCAL_D const TInt KDirAttrLongName = KDirAttrReadOnly | KDirAttrHidden | KDirAttrSystem | KDirAttrVolumeId; |
|
106 |
LOCAL_D const TInt KDirAttrLongMask = KDirAttrLongName | KDirAttrDirectory | KDirAttrArchive; |
|
107 |
LOCAL_D const TInt KDirLastLongEntry = 0x40; |
|
108 |
||
109 |
LOCAL_D RRawDisk TheRawDisk; |
|
110 |
LOCAL_D TFatBootSector BootSector; |
|
111 |
LOCAL_D TFileName TheDrive=_L("?:\\"); |
|
112 |
LOCAL_D HBufC8* FatBufPtr = NULL; |
|
113 |
LOCAL_D HBufC8* DirBufPtr = NULL; |
|
114 |
LOCAL_D HBufC8* ExtBufPtr = NULL; |
|
115 |
LOCAL_D TInt32 ExtBufAdd = 0; |
|
116 |
LOCAL_D TInt32 ExtBufLen = 0; |
|
117 |
LOCAL_D HBufC8* FatDiskPtr = NULL; |
|
118 |
LOCAL_D HBufC8* DirDiskPtr = NULL; |
|
119 |
||
120 |
static TFatType gDiskType = EInvalid; |
|
121 |
||
122 |
LOCAL_D TInt gDriveNumber; |
|
123 |
||
124 |
LOCAL_D TInt gBytesPerCluster; |
|
125 |
LOCAL_D TInt gEntriesPerCluster; |
|
126 |
LOCAL_D TInt gRootDirSectors; |
|
127 |
LOCAL_D TInt gRootDirEntries; |
|
128 |
LOCAL_D TInt gRootDirStart; // in bytes |
|
129 |
LOCAL_D TInt gRootSector; |
|
130 |
LOCAL_D TInt gFatStartBytes; |
|
131 |
LOCAL_D TInt gFatTestSize; // in bytes |
|
132 |
LOCAL_D TInt gFatTestEntries; |
|
133 |
LOCAL_D TInt gFatSizeSectors; |
|
134 |
LOCAL_D TInt gFirstDataSector; |
|
135 |
LOCAL_D TInt gMaxDataCluster; |
|
136 |
LOCAL_D TInt gDataStartBytes; |
|
137 |
LOCAL_D TInt gEndOfChain; // for FAT12/16/32 |
|
138 |
||
139 |
// cluster numbers in 1 and >1 sector per cluster modes |
|
140 |
LOCAL_D TInt gClusterRootDir; // 2 2 |
|
141 |
LOCAL_D TInt gClusterScnDrv; // 3 3 |
|
142 |
LOCAL_D TInt gClusterDir1; // 4 4 |
|
143 |
LOCAL_D TInt gClusterDir1ext; // 5 4 |
|
144 |
LOCAL_D TInt gClusterDir2; // 7 6 |
|
145 |
LOCAL_D TInt gClusterDir2_Full; // 8 7 |
|
146 |
LOCAL_D TInt gClusterDir2_SD3E; // 9 8 |
|
147 |
LOCAL_D TInt gClusterDir2_SD23E; // 10 9 |
|
148 |
LOCAL_D TInt gClusterDir2_AFull; // 11 10 |
|
149 |
LOCAL_D TInt gClusterEndMaxDepth; // 147 146 |
|
150 |
||
151 |
LOCAL_D TFileName LastInFull; |
|
152 |
||
153 |
class TEntryInfo |
|
154 |
{ |
|
155 |
public: |
|
156 |
TEntryInfo(TInt aBytePos,TInt aLength):iBytePos(aBytePos),iLength(aLength){} |
|
157 |
TEntryInfo(){} |
|
158 |
public: |
|
159 |
TInt iBytePos; |
|
160 |
TInt iLength; |
|
161 |
}; |
|
162 |
||
163 |
||
164 |
LOCAL_C TInt DirBufferSize() |
|
165 |
// |
|
166 |
// returns size in bytes nec for buffer to store relevant disk data |
|
167 |
// |
|
168 |
{ |
|
169 |
return(gMaxDataCluster*gBytesPerCluster); |
|
170 |
} |
|
171 |
||
172 |
LOCAL_C TInt PosInBytes(TInt aFatIndex) |
|
173 |
// |
|
174 |
// Return number of bytes into the FAT |
|
175 |
// |
|
176 |
{ |
|
177 |
TInt fatPosInBytes = -1; |
|
178 |
switch (gDiskType) |
|
179 |
{ |
|
180 |
case EFat32: |
|
181 |
fatPosInBytes=aFatIndex<<2; |
|
182 |
break; |
|
183 |
case EFat16: |
|
184 |
fatPosInBytes=aFatIndex<<1; |
|
185 |
break; |
|
186 |
case EFat12: |
|
187 |
fatPosInBytes=(aFatIndex*3>>1); |
|
188 |
break; |
|
189 |
default: |
|
190 |
test(0); |
|
191 |
} |
|
192 |
return(fatPosInBytes); |
|
193 |
} |
|
194 |
||
195 |
LOCAL_C TUint32 MaxClusters() |
|
196 |
// |
|
197 |
// Return the number of data clusters on the disk |
|
198 |
// |
|
199 |
{ |
|
200 |
TUint32 totSec = (BootSector.TotalSectors() ? BootSector.TotalSectors() : BootSector.HugeSectors()); |
|
201 |
TUint32 numSec = totSec - gFirstDataSector; |
|
202 |
return numSec / BootSector.SectorsPerCluster(); |
|
203 |
} |
|
204 |
||
205 |
LOCAL_C TInt ClusterToByte(TInt aCluster) |
|
206 |
// |
|
207 |
// converts cluster number to byte offset on disk |
|
208 |
// |
|
209 |
{ |
|
210 |
TInt pos; |
|
211 |
if (aCluster < 2) |
|
212 |
pos = gRootDirStart; |
|
213 |
else |
|
214 |
pos = (aCluster - 2) * gBytesPerCluster + gFirstDataSector * BootSector.BytesPerSector(); |
|
215 |
return pos; |
|
216 |
} |
|
217 |
||
218 |
LOCAL_C TInt ByteToCluster(TInt aBytePos) |
|
219 |
// |
|
220 |
// Converts byte offset from root dir buffer to cluster number |
|
221 |
// |
|
222 |
{ |
|
223 |
if (aBytePos < gRootDirStart) |
|
224 |
return -1; |
|
225 |
if (aBytePos < gDataStartBytes) |
|
226 |
return 0; |
|
227 |
return (aBytePos - gDataStartBytes) / gBytesPerCluster + 2; |
|
228 |
} |
|
229 |
||
230 |
LOCAL_C TInt ClusterEntryToBytes(TInt aCluster,TInt aEntry) |
|
231 |
// |
|
232 |
// converts position in cluster and entry number to byte pos from root directory |
|
233 |
// |
|
234 |
{ |
|
235 |
TInt pos; |
|
236 |
pos = ClusterToByte(aCluster) - gRootDirStart + aEntry*KSizeOfFatDirEntry; |
|
237 |
return pos; |
|
238 |
} |
|
239 |
||
240 |
LOCAL_C TInt FindUnMatch(const TUint8* aBuf, const TUint8* aCmp, TInt aLen, TInt aStart=0) |
|
241 |
// |
|
242 |
// Return position in buffers which doesn't match, or -1 if it matches |
|
243 |
// |
|
244 |
{ |
|
245 |
for (TInt i = aStart; i < aStart + aLen; i++) |
|
246 |
if (aBuf[i] != aCmp[i]) |
|
247 |
return i; |
|
248 |
return -1; |
|
249 |
} |
|
250 |
||
251 |
LOCAL_C TUint32 GetFatEntry(TUint32 aIndex, const TUint8* aFat=NULL) |
|
252 |
// |
|
253 |
// Read a single FAT entry from disk or FAT copy and return it |
|
254 |
// |
|
255 |
{ |
|
256 |
TInt pos = PosInBytes(aIndex); |
|
257 |
||
258 |
TUint8 data[4]; |
|
259 |
TUint8* ptr = data; |
|
260 |
||
261 |
if (aFat) |
|
262 |
ptr = (TUint8*)aFat + pos; |
|
263 |
else |
|
264 |
{ |
|
265 |
pos += BootSector.ReservedSectors() * BootSector.BytesPerSector(); |
|
266 |
TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A'); |
|
123 | 267 |
test_KErrNone(r); |
0 | 268 |
TPtr8 buf(&data[0], 4); |
269 |
r=TheRawDisk.Read(pos, buf); |
|
123 | 270 |
test_KErrNone(r); |
0 | 271 |
TheRawDisk.Close(); |
272 |
} |
|
273 |
||
274 |
TUint32 val = 0; |
|
275 |
switch (gDiskType) |
|
276 |
{ |
|
277 |
case EFat32: |
|
278 |
val = ptr[0] + (ptr[1] << 8) + (ptr[2] << 16) + (ptr[3] << 24); |
|
279 |
break; |
|
280 |
case EFat16: |
|
281 |
val = ptr[0] + (ptr[1] << 8); |
|
282 |
break; |
|
283 |
case EFat12: |
|
284 |
val = ptr[0] + (ptr[1] << 8); |
|
285 |
if (aIndex & 1) |
|
286 |
val >>= 4; |
|
287 |
val &= 0xFFF; |
|
288 |
break; |
|
289 |
default: |
|
290 |
test(0); |
|
291 |
} |
|
292 |
return val; |
|
293 |
} |
|
294 |
||
123 | 295 |
LOCAL_C void WriteToFatBuf(TInt aFatIndex,TInt aValue,const TUint8* aFat) |
0 | 296 |
// |
297 |
// Write a value to both fats starting at aFat |
|
298 |
// |
|
299 |
{ |
|
300 |
TUint8* p=(TUint8*)(aFat+PosInBytes(aFatIndex)); |
|
301 |
switch (gDiskType) |
|
302 |
{ |
|
303 |
case EFat32: |
|
304 |
p[0] = (TUint8) (aValue); |
|
305 |
p[1] = (TUint8) (aValue >> 8); |
|
306 |
p[2] = (TUint8) (aValue >> 16); |
|
307 |
p[3] = (TUint8) (aValue >> 24); |
|
308 |
break; |
|
309 |
case EFat16: |
|
310 |
p[0] = (TUint8) (aValue); |
|
311 |
p[1] = (TUint8) (aValue >> 8); |
|
312 |
break; |
|
313 |
case EFat12: |
|
314 |
{ |
|
315 |
TUint8 mask=0x0F; |
|
316 |
TBool odd=(aFatIndex)&1; |
|
317 |
TUint8 fatVal; |
|
318 |
TInt value=aValue; |
|
319 |
if(odd) |
|
320 |
{ |
|
321 |
mask<<=4; |
|
322 |
value<<=4; |
|
323 |
fatVal=p[0]; |
|
324 |
fatVal&=~mask; |
|
325 |
fatVal|=(TUint8)(value&0xFF); |
|
326 |
p[0]=fatVal; |
|
327 |
p[1]=(TUint8)(value>>8); |
|
328 |
} |
|
329 |
else |
|
330 |
{ |
|
331 |
p[0]=(TUint8)(value&0xFF); |
|
332 |
fatVal=p[1]; |
|
333 |
fatVal&=~mask; |
|
334 |
fatVal|=(TUint8)(value>>8); |
|
335 |
p[1]=fatVal; |
|
336 |
} |
|
337 |
} |
|
338 |
break; |
|
339 |
default: |
|
340 |
test(0); |
|
341 |
} |
|
342 |
return; |
|
343 |
} |
|
344 |
||
345 |
static void DoReadBootSector() |
|
346 |
{ |
|
347 |
||
348 |
TInt nRes = ReadBootSector(TheFs, CurrentDrive(), KBootSectorNum<<KDefaultSectorLog2, BootSector); |
|
123 | 349 |
test_KErrNone(nRes); |
0 | 350 |
|
351 |
if(!BootSector.IsValid()) |
|
352 |
{ |
|
353 |
test.Printf(_L("Wrong bootsector! Dump:\n")); |
|
354 |
BootSector.PrintDebugInfo(); |
|
355 |
test(0); |
|
356 |
} |
|
357 |
||
358 |
// Calculate derived variables (fixed for a particular disk format) |
|
359 |
if (BootSector.RootDirEntries() == 0) |
|
360 |
{ |
|
361 |
test.Printf(_L("Disk is FAT32\n")); |
|
362 |
gDiskType = EFat32; |
|
363 |
gEndOfChain = 0x0FFFFFFF; |
|
364 |
} |
|
365 |
else if (BootSector.FatType() == EFat16) |
|
366 |
{ |
|
367 |
test.Printf(_L("Disk is FAT16\n")); |
|
368 |
gDiskType = EFat16; |
|
369 |
gEndOfChain = 0xFFFF; |
|
370 |
} |
|
371 |
else |
|
372 |
{ |
|
373 |
test.Printf(_L("Disk is FAT12\n")); |
|
374 |
gDiskType = EFat12; |
|
375 |
gEndOfChain = 0x0FFF; |
|
376 |
} |
|
377 |
||
378 |
gBytesPerCluster = BootSector.BytesPerSector() * BootSector.SectorsPerCluster(); |
|
379 |
gFatStartBytes = BootSector.ReservedSectors() * BootSector.BytesPerSector(); |
|
380 |
gEntriesPerCluster = gBytesPerCluster / KSizeOfFatDirEntry; |
|
381 |
||
382 |
TBool big = (BootSector.SectorsPerCluster() > 1); |
|
383 |
switch (gDiskType) |
|
384 |
{ |
|
385 |
case EFat12: |
|
386 |
case EFat16: |
|
387 |
gRootDirEntries = BootSector.RootDirEntries(); |
|
388 |
gRootDirSectors = ((gRootDirEntries * KSizeOfFatDirEntry + BootSector.BytesPerSector() - 1) / BootSector.BytesPerSector()); |
|
389 |
gFatSizeSectors = BootSector.FatSectors(); |
|
390 |
gRootSector = BootSector.ReservedSectors() + BootSector.NumberOfFats() * gFatSizeSectors; |
|
391 |
gFirstDataSector = gRootSector + gRootDirSectors; |
|
392 |
gDataStartBytes = gFirstDataSector * BootSector.BytesPerSector(); |
|
393 |
gRootDirStart = gRootSector * BootSector.BytesPerSector(); |
|
394 |
gClusterRootDir = (big ? 0 : 0); |
|
395 |
gClusterScnDrv = (big ? 2 : 2); |
|
396 |
gClusterDir1 = (big ? 3 : 3); |
|
397 |
gClusterDir1ext = (big ? 3 : 4); |
|
398 |
gClusterDir2 = (big ? 5 : 6); |
|
399 |
gClusterDir2_Full = (big ? 6 : 7); |
|
400 |
gClusterDir2_SD3E = (big ? 7 : 8); |
|
401 |
gClusterDir2_SD23E = (big ? 8 : 9); |
|
402 |
gClusterDir2_AFull = (big ? 9 : 10); |
|
403 |
gClusterEndMaxDepth = (big ? 145 : 146); |
|
404 |
break; |
|
405 |
case EFat32: |
|
406 |
// |
|
407 |
// FAT32 will alway pre-allocate a single cluster for the root directory |
|
408 |
// |
|
409 |
// - The following calculations may look wierd (as the spec says that the FAT32 root dir |
|
410 |
// is not fixed) but for the purposes of this test we assume that root dir is only |
|
411 |
// one cluster in size, so we don't fill up the disk trying to fill up the root dir. |
|
412 |
// |
|
413 |
gRootDirEntries = gBytesPerCluster * 1 / KSizeOfFatDirEntry; // Maximum entries within default FAT32 root directory (before extension) |
|
414 |
gRootDirSectors = 0; // FAT32 has no fixed root directory sectors over which to skip |
|
415 |
gFatSizeSectors = BootSector.FatSectors32(); |
|
416 |
||
417 |
gRootSector = BootSector.ReservedSectors() + BootSector.NumberOfFats() * gFatSizeSectors; |
|
418 |
gFirstDataSector = gRootSector; |
|
419 |
||
420 |
gDataStartBytes = gFirstDataSector * BootSector.BytesPerSector(); |
|
421 |
gRootDirStart = (BootSector.RootClusterNum() - 2) * gBytesPerCluster + gDataStartBytes; |
|
422 |
||
423 |
gClusterRootDir = (big ? 2 : 2); |
|
424 |
gClusterScnDrv = (big ? 3 : 3); |
|
425 |
gClusterDir1 = (big ? 4 : 4); |
|
426 |
gClusterDir1ext = (big ? 4 : 5); |
|
427 |
gClusterDir2 = (big ? 6 : 7); |
|
428 |
gClusterDir2_Full = (big ? 7 : 8); |
|
429 |
gClusterDir2_SD3E = (big ? 8 : 9); |
|
430 |
gClusterDir2_SD23E = (big ? 9 : 10); |
|
431 |
gClusterDir2_AFull = (big ? 10 : 11); |
|
432 |
gClusterEndMaxDepth = (big ? 146 : 147); |
|
433 |
break; |
|
434 |
default: |
|
435 |
break; |
|
436 |
} |
|
437 |
||
438 |
gMaxDataCluster = gClusterDir2_AFull + 2 + (gFirstDataSector / BootSector.SectorsPerCluster() + 1); |
|
439 |
||
440 |
gFatTestEntries = MaxClusters(); |
|
441 |
if (gFatTestEntries > KMaxFatSize) |
|
442 |
gFatTestEntries = KMaxFatSize; |
|
443 |
} |
|
444 |
||
445 |
||
446 |
GLDEF_C void DumpBootSector() |
|
447 |
// |
|
448 |
// Display (in log) TFatBootSector structure |
|
449 |
// |
|
450 |
{ |
|
451 |
RDebug::Print(_L("iBytesPerSector = %8d"), BootSector.BytesPerSector()); |
|
452 |
RDebug::Print(_L("iSectorsPerCluster = %8d"), BootSector.SectorsPerCluster()); |
|
453 |
RDebug::Print(_L("iReservedSectors = %8d"), BootSector.ReservedSectors()); |
|
454 |
RDebug::Print(_L("iNumberOfFats = %8d"), BootSector.NumberOfFats()); |
|
455 |
RDebug::Print(_L("iRootDirEntries = %8d"), BootSector.RootDirEntries()); |
|
456 |
RDebug::Print(_L("iTotalSectors = %8d"), BootSector.TotalSectors()); |
|
457 |
RDebug::Print(_L("iMediaDescriptor = %8d"), BootSector.MediaDescriptor()); |
|
458 |
RDebug::Print(_L("iFatSectors = %8d"), BootSector.FatSectors()); |
|
459 |
RDebug::Print(_L("iSectorsPerTrack = %8d"), BootSector.SectorsPerTrack()); |
|
460 |
RDebug::Print(_L("iNumberOfHeads = %8d"), BootSector.NumberOfHeads()); |
|
461 |
RDebug::Print(_L("iHiddenSectors = %8d"), BootSector.HiddenSectors()); |
|
462 |
RDebug::Print(_L("iHugeSectors = %8d"), BootSector.HugeSectors()); |
|
463 |
||
464 |
if (gDiskType == EFat32) |
|
465 |
{ |
|
466 |
RDebug::Print(_L("iFatSectors32 = %8d"), BootSector.FatSectors32()); |
|
467 |
RDebug::Print(_L("iFATFlags = %8d"), BootSector.FATFlags()); |
|
468 |
RDebug::Print(_L("iVersionNumber = %8d"), BootSector.VersionNumber()); |
|
469 |
RDebug::Print(_L("iRootClusterNum = %8d (0x%08X)"), BootSector.RootClusterNum(), gRootDirStart); |
|
470 |
RDebug::Print(_L("iFSInfoSectorNum = %8d (0x%08X)"), BootSector.FSInfoSectorNum(), BootSector.FSInfoSectorNum() * BootSector.BytesPerSector()); |
|
471 |
RDebug::Print(_L("iBkBootRecSector = %8d (0x%08X)"), BootSector.BkBootRecSector(), BootSector.BkBootRecSector() * BootSector.BytesPerSector()); |
|
472 |
} |
|
473 |
} |
|
474 |
||
475 |
GLDEF_C void DumpFat(const TUint8* aFat=NULL) |
|
476 |
// |
|
477 |
// Dump to the log all those FAT entries which are non-zero |
|
478 |
// |
|
479 |
{ |
|
480 |
TInt32 max = MaxClusters(); |
|
481 |
if (max > KMaxFatEntries) |
|
482 |
max = KMaxFatEntries; |
|
483 |
RDebug::Print(_L("---------------- DUMP OF FAT ---------------")); |
|
484 |
for (TInt32 i = 0; i < max; i++) |
|
485 |
{ |
|
486 |
TInt32 val = GetFatEntry(i, aFat); |
|
487 |
TInt32 msk = 0x0FFFFFFF; |
|
488 |
switch (gDiskType) |
|
489 |
{ |
|
490 |
case EFat32: |
|
491 |
msk = 0x0FFFFFFF; |
|
492 |
break; |
|
493 |
case EFat16: |
|
494 |
msk = 0xFFFF; |
|
495 |
break; |
|
496 |
case EFat12: |
|
497 |
msk = 0x0FFF; |
|
498 |
break; |
|
499 |
default: |
|
500 |
test(0); |
|
501 |
} |
|
502 |
if ((val & msk) == (0x0FFFFFFF & msk)) |
|
503 |
RDebug::Print(_L(" %8d -> EOC"), i); |
|
504 |
else if ((val & msk) == (0x0FFFFFF8 & msk)) |
|
505 |
RDebug::Print(_L(" %8d -> Media"), i); |
|
506 |
else if ((val & msk) == (0x0FFFFFF7 & msk)) |
|
507 |
RDebug::Print(_L(" %8d -> BAD"), i); |
|
508 |
else if (val > max) |
|
509 |
RDebug::Print(_L(" %8d -> 0x%08X"), i, val); |
|
510 |
else if (val != 0) |
|
511 |
RDebug::Print(_L(" %8d -> %d"), i, val); |
|
512 |
} |
|
513 |
RDebug::Print(_L("--------------------------------------------")); |
|
514 |
} |
|
515 |
||
516 |
GLDEF_C TDes* DirAttributes(TInt aAttrib) |
|
517 |
// |
|
518 |
// Return a pointer to a local buffer containing the attribute letters. |
|
519 |
// |
|
520 |
{ |
|
521 |
LOCAL_D TBuf<6> str; |
|
522 |
LOCAL_D char* atr = "RHSVDA"; |
|
523 |
str.Fill(TText('-'), 6); |
|
524 |
for (TInt i = 0; i < 6; i++) |
|
525 |
if ((aAttrib >> i) & 1) |
|
526 |
str[i] = atr[i]; |
|
527 |
return &str; |
|
528 |
} |
|
529 |
||
530 |
GLDEF_C TBool IsValidDirEntry(TFatDirEntry* aDir) |
|
531 |
// |
|
532 |
// Test whether buffer is a valid normal directory entry |
|
533 |
// |
|
534 |
{ |
|
535 |
// first character must be 0x05 or greater than space |
|
536 |
if (aDir->iData[0] < 0x21 && aDir->iData[0] != 0x05) |
|
537 |
return EFalse; |
|
538 |
// other characters must be not less than space |
|
539 |
for (TInt i = 1; i < 11; i++) |
|
540 |
if (aDir->iData[i] < 0x20) |
|
541 |
return EFalse; |
|
542 |
return ETrue; |
|
543 |
} |
|
544 |
||
545 |
GLDEF_C void GetLongNamePart(TDes16& aName, const TUint8* aEntry, TInt aPos, TInt aOffset, TInt aLength) |
|
546 |
// |
|
547 |
// Extract part of a long name entry into the name buffer. |
|
548 |
// |
|
549 |
// @param aName buffer to put name |
|
550 |
// @param aEntry directory entry raw data |
|
551 |
// @param aPos character in buffer to start name segment |
|
552 |
// @param aOffset offset in directory entry of the segment |
|
553 |
// @param aLength number of characters in the segment |
|
554 |
// |
|
555 |
{ |
|
556 |
for (TInt i = 0; i < aLength; i++) |
|
557 |
{ |
|
558 |
TInt at = i * 2 + aOffset; |
|
559 |
TInt ch = aEntry[at] + aEntry[at+1] * 256; |
|
560 |
aName[aPos++] = TText(ch); |
|
561 |
} |
|
562 |
} |
|
563 |
||
564 |
GLDEF_C void ExtractNameString(TDes16& aName, const TUint8* aEntry) |
|
565 |
// |
|
566 |
// Extract a long name part from a directory entry, truncate it at the first |
|
567 |
// NUL (0) character and put quotes round it. |
|
568 |
// |
|
569 |
{ |
|
570 |
aName.SetLength(15); |
|
571 |
TInt len = aName.Length() - 1; |
|
572 |
TText qu = '\''; |
|
573 |
aName[0] = qu; |
|
574 |
GetLongNamePart(aName, aEntry, 1, 1, 5); |
|
575 |
GetLongNamePart(aName, aEntry, 6, 14, 6); |
|
576 |
GetLongNamePart(aName, aEntry, 12, 28, 2); |
|
577 |
TInt i; |
|
578 |
for (i = 0; i < len; i++) |
|
579 |
if (aName[i] == 0) |
|
580 |
break; |
|
581 |
aName[i++] = qu; |
|
582 |
aName.SetLength(i); |
|
583 |
} |
|
584 |
||
123 | 585 |
TDes& MakePrintable(TDes& aDes) |
586 |
{ |
|
587 |
TInt len = aDes.Length(); |
|
588 |
||
589 |
for (TInt i=0; i<len; i++) |
|
590 |
{ |
|
591 |
if ((TUint8) aDes[i] < 0x20) |
|
592 |
aDes[i] = '?'; |
|
593 |
} |
|
594 |
return aDes; |
|
595 |
} |
|
596 |
||
0 | 597 |
GLDEF_C TBool DumpDirEntry(TInt aNum, const TUint8* aEntry) |
598 |
// |
|
599 |
// Dump a single directory entry to the log. Return false if it was end of |
|
600 |
// directory or an invalid entry (and don't display it). |
|
601 |
// |
|
602 |
{ |
|
603 |
TFatDirEntry* d = (TFatDirEntry*)aEntry; |
|
604 |
if (d->IsErased()) |
|
605 |
{ |
|
606 |
//RDebug::Print(_L("%5d: ERASED"), aNum); |
|
607 |
} |
|
608 |
else if (d->IsEndOfDirectory()) |
|
609 |
{ |
|
610 |
if (aNum > 0) |
|
611 |
RDebug::Print(_L("%5d: ------------- end of directory"), aNum); |
|
612 |
return EFalse; |
|
613 |
} |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
614 |
else if (((TInt)d->Attributes() & KDirAttrLongMask) == KDirAttrLongName) |
0 | 615 |
{ |
616 |
TBuf16<15> name; |
|
617 |
ExtractNameString(name, aEntry); |
|
618 |
TInt ord = aEntry[0]; |
|
619 |
if (ord & KDirLastLongEntry) |
|
123 | 620 |
RDebug::Print(_L("%5d: %-15S #%-2d LAST"), aNum, &MakePrintable(name), ord & ~KDirLastLongEntry); |
0 | 621 |
else |
123 | 622 |
RDebug::Print(_L("%5d: %-15S #%-2d"), aNum, &MakePrintable(name), ord & ~KDirLastLongEntry); |
0 | 623 |
} |
624 |
else if (!IsValidDirEntry(d)) |
|
625 |
{ |
|
626 |
if (aNum > 0) |
|
627 |
RDebug::Print(_L("%5d: ============= INVALID ENTRY"), aNum); |
|
628 |
return EFalse; |
|
629 |
} |
|
630 |
else |
|
631 |
{ |
|
632 |
TBuf<11> name; |
|
633 |
name.Copy(d->Name()); |
|
634 |
RDebug::Print(_L("%5d: '%S' %S start %-5d size %d"), |
|
123 | 635 |
aNum, &MakePrintable(name), DirAttributes(d->Attributes()), d->StartCluster(), d->Size()); |
0 | 636 |
} |
637 |
return ETrue; |
|
638 |
} |
|
639 |
||
640 |
GLDEF_C void DumpDirCluster(const TUint8* aData, TInt aCluster=0) |
|
641 |
// |
|
642 |
// Dump directory entries until end of cluster or invalid/end entry found. |
|
643 |
// |
|
644 |
{ |
|
645 |
if (aCluster > 2) |
|
646 |
aData += (aCluster-2) * gBytesPerCluster; |
|
647 |
for (TInt i = 0; i < gBytesPerCluster; i += KSizeOfFatDirEntry) |
|
648 |
{ |
|
649 |
if (DumpDirEntry(i/KSizeOfFatDirEntry, aData)) |
|
650 |
aData += KSizeOfFatDirEntry; |
|
651 |
else |
|
652 |
break; |
|
653 |
} |
|
654 |
} |
|
655 |
||
656 |
GLDEF_C void DumpRootDir(const TUint8* aData) |
|
657 |
// |
|
658 |
// Dump the data area buffer, trying to interpret directory clusters (only look |
|
659 |
// at clusters which are marked as 'used' in the FAT). |
|
660 |
// |
|
661 |
{ |
|
662 |
RDebug::Print(_L("Root dir @ 0x%08X:"), gRootDirStart); |
|
663 |
for (TInt i = 0; i < BootSector.RootDirEntries(); i++) |
|
664 |
{ |
|
665 |
if (DumpDirEntry(i, aData)) |
|
666 |
aData += KSizeOfFatDirEntry; |
|
667 |
else |
|
668 |
break; |
|
669 |
} |
|
670 |
} |
|
671 |
||
672 |
GLDEF_C void DumpData(const TUint8* aFat, const TUint8* aDir) |
|
673 |
// |
|
674 |
// Dump the data area buffer, trying to interpret directory clusters (only look |
|
675 |
// at clusters which are marked as 'used' in the FAT). |
|
676 |
// |
|
677 |
{ |
|
678 |
RDebug::Print(_L("--------------- DATA AREA ------------------")); |
|
679 |
if (gDiskType != EFat32) |
|
680 |
{ |
|
681 |
DumpRootDir(aDir); |
|
682 |
} |
|
683 |
TInt max = (gFatTestEntries < gMaxDataCluster ? gFatTestEntries : gMaxDataCluster); |
|
684 |
for (TInt cluster = 2; cluster < max; cluster++) |
|
685 |
{ |
|
686 |
if (GetFatEntry(cluster, aFat) != 0) |
|
687 |
{ |
|
688 |
RDebug::Print(_L("Cluster %d @ 0x%08X:"), cluster, ClusterToByte(cluster)); |
|
689 |
DumpDirCluster(aDir+gDataStartBytes-gRootDirStart, cluster); |
|
690 |
} |
|
691 |
} |
|
692 |
RDebug::Print(_L("--------------------------------------------")); |
|
693 |
} |
|
694 |
||
695 |
GLDEF_C void DumpData(const TUint8* aFat, TInt aStart, TInt aEnd = -1) |
|
696 |
// |
|
697 |
// Dump clusters from disk (allows dumping of clusters not in our buffers). |
|
698 |
// Only look at clusters marked as 'used' in the FAT. Note that if aFat is |
|
699 |
// NULL the FAT entries will also be read from disk (slower but allows for ones |
|
700 |
// outside our copy in memory). |
|
701 |
// |
|
702 |
{ |
|
703 |
if (aStart > gFatTestEntries) |
|
704 |
return; |
|
705 |
RDebug::Print(_L("--------------- DATA AREA ------------------")); |
|
706 |
if (aEnd > gFatTestEntries) |
|
707 |
aEnd = gFatTestEntries; |
|
708 |
if (aEnd < 0) |
|
709 |
aEnd = aStart + 1; |
|
710 |
if (aStart < 2 && gDiskType != EFat32) |
|
711 |
{ |
|
712 |
HBufC8* buf=HBufC8::New(BootSector.RootDirEntries() * KSizeOfFatDirEntry); |
|
123 | 713 |
test_NotNull(buf); |
0 | 714 |
TPtr8 ptr=buf->Des(); |
715 |
TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A'); |
|
123 | 716 |
test_KErrNone(r); |
0 | 717 |
r=TheRawDisk.Read(gRootDirStart, ptr); |
123 | 718 |
test_KErrNone(r); |
0 | 719 |
TheRawDisk.Close(); |
720 |
DumpRootDir(buf->Ptr()); |
|
721 |
delete(buf); |
|
722 |
aStart = 2; |
|
723 |
} |
|
724 |
for (TInt cluster = aStart; cluster < aEnd; cluster++) |
|
725 |
{ |
|
726 |
if (GetFatEntry(cluster, aFat) != 0) |
|
727 |
{ |
|
728 |
HBufC8* buf=HBufC8::New(gBytesPerCluster); |
|
123 | 729 |
test_NotNull(buf); |
0 | 730 |
TPtr8 ptr=buf->Des(); |
731 |
TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A'); |
|
123 | 732 |
test_KErrNone(r); |
0 | 733 |
r=TheRawDisk.Read(ClusterToByte(cluster), ptr); |
123 | 734 |
test_KErrNone(r); |
0 | 735 |
TheRawDisk.Close(); |
736 |
RDebug::Print(_L("Cluster %d @ 0x%08X:"), cluster, ClusterToByte(cluster)); |
|
737 |
DumpDirCluster(ptr.Ptr()); |
|
738 |
delete buf; |
|
739 |
} |
|
740 |
} |
|
741 |
RDebug::Print(_L("--------------------------------------------")); |
|
742 |
} |
|
743 |
||
744 |
GLDEF_C void DumpHex(const TUint8* aData, TInt aLen, TInt aBase=0) |
|
745 |
// |
|
746 |
// Dump a block of memory to the log in hex. |
|
747 |
// |
|
748 |
{ |
|
749 |
for (TInt base = 0; base < aLen; base += 16) |
|
750 |
{ |
|
751 |
TBuf<16*3+3+16+1> buf; |
|
752 |
TInt off; |
|
753 |
for (off = base; off < aLen && off < base + 16; off++) |
|
754 |
{ |
|
755 |
buf.Append(TText(' ')); |
|
756 |
buf.AppendNumFixedWidth(aData[off], EHex, 2); |
|
757 |
} |
|
758 |
buf.Append(_L(" |")); |
|
759 |
for (off = base; off < aLen && off < base + 16; off++) |
|
760 |
{ |
|
761 |
TUint8 ch = aData[off]; |
|
762 |
buf.Append(ch < 0x20 || ch > 0x7E ? TText('_') : TText(ch)); |
|
763 |
} |
|
764 |
buf.Append(_L("|")); |
|
765 |
RDebug::Print(_L("%04X: %S"), base+aBase, &buf); |
|
766 |
} |
|
767 |
} |
|
768 |
||
769 |
GLDEF_C void DumpHex(const TPtrC8& aData, TInt aLen, TInt aBase=0) |
|
770 |
// |
|
771 |
// Dump a block of memory to the log in hex. |
|
772 |
// |
|
773 |
{ |
|
774 |
DumpHex(aData.Ptr(), aLen, aBase); |
|
775 |
} |
|
776 |
||
777 |
GLDEF_C void DumpHex(TInt aPos, TInt aLen, TInt aBase=0) |
|
778 |
// |
|
779 |
// Dump a block of memory to the log in hex. |
|
780 |
// |
|
781 |
{ |
|
782 |
TPtr8 dirBuf=DirBufPtr->Des(); |
|
783 |
DumpHex(dirBuf.Ptr()+aPos, aLen, aBase); |
|
784 |
} |
|
785 |
||
786 |
GLDEF_C void Dump(TEntryInfo& aEntry) |
|
787 |
// |
|
788 |
// Dump an entry description to the log in hex |
|
789 |
// |
|
790 |
{ |
|
791 |
RDebug::Print(_L("--- TEntryInfo 0x%08X, %d"), aEntry.iBytePos, aEntry.iLength); |
|
792 |
TInt len = aEntry.iLength*KSizeOfFatDirEntry; |
|
793 |
DumpHex(aEntry.iBytePos, len, aEntry.iBytePos); |
|
794 |
} |
|
795 |
||
796 |
LOCAL_C TInt GetStartCluster(TInt aCluster, TInt aEntry) |
|
797 |
// |
|
798 |
// Get the start cluster pertaining to a directory entry in a specific |
|
799 |
// directory cluster, return -1 if not available (invalid entry). |
|
800 |
// |
|
801 |
{ |
|
802 |
HBufC8* buf=HBufC8::New(gBytesPerCluster*2); |
|
123 | 803 |
test_NotNull(buf); |
0 | 804 |
TPtr8 ptr=buf->Des(); |
805 |
TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A'); |
|
123 | 806 |
test_KErrNone(r); |
0 | 807 |
r=TheRawDisk.Read(ClusterToByte(aCluster), ptr); |
123 | 808 |
test_KErrNone(r); |
0 | 809 |
TheRawDisk.Close(); |
810 |
RDebug::Print(_L("Cluster %d @ 0x%08X:"), aCluster, ClusterToByte(aCluster)); |
|
811 |
TFatDirEntry* d = (TFatDirEntry*)ptr.Ptr() + aEntry; |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
812 |
while (((TInt)d->Attributes() & KDirAttrLongMask) == KDirAttrLongName && aEntry < gEntriesPerCluster) |
0 | 813 |
{ |
814 |
if (d->IsErased() || d->IsEndOfDirectory()) |
|
815 |
break; |
|
816 |
++aEntry; |
|
817 |
d = (TFatDirEntry*)ptr.Ptr() + aEntry; |
|
818 |
} |
|
819 |
TInt start = d->StartCluster(); |
|
820 |
if (d->IsErased()) |
|
821 |
start = -1; |
|
822 |
else if (d->IsEndOfDirectory()) |
|
823 |
start = -1; |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
824 |
else if (((TInt)d->Attributes() & KDirAttrLongMask) == KDirAttrLongName) |
0 | 825 |
start = -1; |
826 |
else if (!IsValidDirEntry(d)) |
|
827 |
start = -1; |
|
828 |
delete buf; |
|
829 |
return start; |
|
830 |
} |
|
831 |
||
832 |
LOCAL_C void Format() |
|
833 |
{ |
|
834 |
TInt nRes; |
|
835 |
||
836 |
#if 0 |
|
837 |
TFatFormatParam fmt; |
|
838 |
fmt.iFatType = EFat32; |
|
839 |
fmt.iSecPerCluster = 1; |
|
840 |
||
841 |
nRes = FormatFatDrive(TheFs, CurrentDrive(), ETrue, &fmt); |
|
842 |
#else |
|
843 |
nRes = FormatFatDrive(TheFs, CurrentDrive(), ETrue); |
|
844 |
#endif |
|
845 |
||
123 | 846 |
test_KErrNone(nRes); |
0 | 847 |
|
848 |
} |
|
849 |
||
850 |
LOCAL_C void CreateDeepDir(TFileName& aDir,TInt aDepth) |
|
851 |
// |
|
852 |
// Increase directory strucutre by aDepth starting with aDir. |
|
853 |
// |
|
854 |
{ |
|
855 |
TFileName num; |
|
856 |
num.Num(1); |
|
857 |
num+=_L("\\"); |
|
858 |
TInt r; |
|
859 |
while(aDepth--) |
|
860 |
{ |
|
861 |
num[0] = TText(aDepth % 26 + 'A'); |
|
862 |
aDir+=num; |
|
863 |
r=TheFs.MkDir(aDir); |
|
123 | 864 |
test_KErrNone(r); |
0 | 865 |
} |
866 |
} |
|
867 |
||
868 |
LOCAL_C void DeleteDeepDir(TFileName& aDir,TInt aDepth) |
|
869 |
// |
|
870 |
// Delete dir structure. |
|
871 |
// |
|
872 |
{ |
|
873 |
TInt r; |
|
874 |
while(aDepth--) |
|
875 |
{ |
|
876 |
r=TheFs.RmDir(aDir); |
|
123 | 877 |
test_KErrNone(r); |
0 | 878 |
aDir.SetLength(aDir.Length()-2); |
879 |
} |
|
880 |
} |
|
881 |
||
882 |
LOCAL_C void CreateMaxDepthDir(TFileName& aDir1,TFileName& aDir2) |
|
883 |
// |
|
884 |
// Create directory structure with max possible depth-1. |
|
885 |
// Achieved by using dir names of one character. |
|
886 |
// |
|
887 |
{ |
|
888 |
//create dir structure with depth of 25 |
|
889 |
CreateDeepDir(aDir1,25); |
|
890 |
// split dir structure |
|
891 |
aDir2=aDir1; |
|
892 |
aDir2+=_L("a\\"); |
|
893 |
TInt r=TheFs.MkDir(aDir2); |
|
123 | 894 |
test_KErrNone(r); |
0 | 895 |
// create dir with depth of 126 directories - one short of max depth |
896 |
CreateDeepDir(aDir1,101); |
|
897 |
// create dir with depth of 90 |
|
898 |
CreateDeepDir(aDir2,64); |
|
899 |
} |
|
900 |
||
901 |
LOCAL_C void DeleteMaxDepthDir(TFileName&aDir1,TFileName&aDir2) |
|
902 |
// |
|
903 |
// Deletes max depth dir structure. |
|
904 |
// |
|
905 |
{ |
|
906 |
DeleteDeepDir(aDir2,64); |
|
907 |
TInt r=TheFs.RmDir(aDir2); |
|
123 | 908 |
test_KErrNone(r); |
0 | 909 |
aDir2.SetLength(aDir2.Length()-2); |
910 |
DeleteDeepDir(aDir1,102); |
|
911 |
DeleteDeepDir(aDir1,24); |
|
912 |
} |
|
913 |
||
914 |
LOCAL_C void MakeVeryLongName(TFileName& aLong) |
|
915 |
// |
|
916 |
// appends a very long file name to aLong |
|
917 |
// |
|
918 |
{ |
|
919 |
// create a name to take up 18 vfat entries - (1 sector + 2 entries) |
|
920 |
for(TInt i=0;i<234;++i) |
|
921 |
{ |
|
922 |
TInt c='a'+i%26; |
|
923 |
aLong.Append(c); |
|
924 |
} |
|
925 |
} |
|
926 |
||
927 |
GLDEF_C void CreateLongNames(TFileName& aLong, TInt aClusters) |
|
928 |
// |
|
929 |
// Creates entries to fill up the number of directory clusters |
|
930 |
// |
|
931 |
{ |
|
932 |
TInt len = aLong.Length(); // length of directory prefix |
|
933 |
MakeVeryLongName(aLong); |
|
934 |
TInt count = 0; |
|
935 |
RFile temp; |
|
936 |
for (TInt i = 0; i < aClusters * gEntriesPerCluster; i += 19) |
|
937 |
{ |
|
938 |
aLong[len+0] = TText(count/26 + 'A'); |
|
939 |
aLong[len+1] = TText(count%26 + 'A'); |
|
940 |
count++; |
|
941 |
TInt r=temp.Create(TheFs,aLong,EFileShareAny); |
|
123 | 942 |
test_KErrNone(r); |
0 | 943 |
temp.Close(); |
944 |
} |
|
945 |
} |
|
946 |
||
947 |
GLDEF_C void DeleteLongNames(TFileName& aLong, TInt aClusters) |
|
948 |
// |
|
949 |
// Deletes entries created by CreateLongNames() |
|
950 |
// |
|
951 |
{ |
|
952 |
TInt len = aLong.Length(); // length of directory prefix |
|
953 |
MakeVeryLongName(aLong); |
|
954 |
TInt count = 0; |
|
955 |
for (TInt i = 0; i < aClusters * gEntriesPerCluster; i += 19) |
|
956 |
{ |
|
957 |
aLong[len+0] = TText(count/26 + 'A'); |
|
958 |
aLong[len+1] = TText(count%26 + 'A'); |
|
959 |
count++; |
|
960 |
TInt r=TheFs.Delete(aLong); |
|
123 | 961 |
test_Value(r, r==KErrNone || r==KErrNotFound); |
0 | 962 |
} |
963 |
} |
|
964 |
||
965 |
LOCAL_C void DeleteRootDir(TInt aNum=0) |
|
966 |
// |
|
967 |
// Delete all entries in the root directory up to the last - aNum |
|
968 |
// |
|
969 |
{ |
|
970 |
test.Next(_L("Delete Root Directory Entries")); |
|
971 |
TInt maxRootEntries = gRootDirEntries; |
|
972 |
TFileName name=_L("\\???xxx"); |
|
973 |
TInt count=0; |
|
974 |
TInt entriesSoFar=2; |
|
975 |
TInt r; |
|
976 |
count = 0; |
|
977 |
for (entriesSoFar=0; entriesSoFar<maxRootEntries - aNum; entriesSoFar+=2) |
|
978 |
{ |
|
979 |
name[1]=(TUint16)(count/26/26+'a'); |
|
980 |
name[2]=(TUint16)(count/26%26+'a'); |
|
981 |
name[3]=(TUint16)(count%26+'a'); |
|
982 |
r=TheFs.Delete(name); |
|
123 | 983 |
test_Value(r, r==KErrNone || r==KErrNotFound); |
0 | 984 |
++count; |
985 |
} |
|
986 |
} |
|
987 |
||
988 |
LOCAL_C void CreateRootDir() |
|
989 |
// |
|
990 |
// fill up root directory to 1 clusters by creating entries and then deleting |
|
991 |
// them except the last. |
|
992 |
// |
|
993 |
{ |
|
994 |
test.Next(_L("Create Root Directory Entries")); |
|
995 |
TInt maxRootEntries = gRootDirEntries; |
|
996 |
TFileName name=_L("\\???xxx"); |
|
997 |
TInt count=0; |
|
998 |
TInt entriesSoFar=2; |
|
999 |
TInt r; |
|
1000 |
RFile f; |
|
1001 |
for (entriesSoFar=0; entriesSoFar<maxRootEntries; entriesSoFar+=2) |
|
1002 |
{ |
|
1003 |
name[1]=(TUint16)(count/26/26+'a'); |
|
1004 |
name[2]=(TUint16)(count/26%26+'a'); |
|
1005 |
name[3]=(TUint16)(count%26+'a'); |
|
1006 |
r=f.Create(TheFs, name, EFileWrite); |
|
123 | 1007 |
test_KErrNone(r); |
0 | 1008 |
f.Close(); |
1009 |
++count; |
|
1010 |
} |
|
1011 |
DeleteRootDir(1); |
|
1012 |
} |
|
1013 |
||
1014 |
LOCAL_C void FillUpRootDir(TInt aFree=0) |
|
1015 |
// |
|
1016 |
// fill up root directory |
|
1017 |
// |
|
1018 |
{ |
|
1019 |
TInt maxRootEntries = gRootDirEntries - aFree; |
|
1020 |
TFileName dir=_L("\\??\\"); |
|
1021 |
TInt count=0; |
|
1022 |
TInt entriesSoFar=2; |
|
1023 |
TInt r; |
|
1024 |
while(entriesSoFar<maxRootEntries) |
|
1025 |
{ |
|
1026 |
dir[1]=(TUint16)(count/26+'a'); |
|
1027 |
dir[2]=(TUint16)(count%26+'a'); |
|
1028 |
r=TheFs.MkDir(dir); |
|
123 | 1029 |
test_KErrNone(r); |
0 | 1030 |
entriesSoFar+=2; |
1031 |
++count; |
|
1032 |
} |
|
1033 |
} |
|
1034 |
||
1035 |
LOCAL_C void UnFillUpRootDir(TInt aFree=0) |
|
1036 |
// |
|
1037 |
// reverse changes from FillUpRootDir() |
|
1038 |
// |
|
1039 |
{ |
|
1040 |
TFileName dir=_L("\\??\\"); |
|
1041 |
TInt entriesSoFar=gRootDirEntries-aFree; |
|
1042 |
TInt count=0; |
|
1043 |
TInt r; |
|
1044 |
while(entriesSoFar>2) |
|
1045 |
{ |
|
1046 |
dir[1]=TUint16(count/26+'a'); |
|
1047 |
dir[2]=TUint16(count%26+'a'); |
|
1048 |
r=TheFs.RmDir(dir); |
|
123 | 1049 |
test_KErrNone(r); |
0 | 1050 |
entriesSoFar-=2; |
1051 |
++count; |
|
1052 |
} |
|
1053 |
} |
|
1054 |
||
1055 |
LOCAL_C void DeleteDirectoryStructure() |
|
1056 |
// |
|
1057 |
// deletes the directory structure |
|
1058 |
// |
|
1059 |
{ |
|
1060 |
test.Next(_L("Delete Directory Structure")); |
|
1061 |
TInt r=TheFs.RmDir(_L("\\scndrv\\dir2\\almostfull\\")); |
|
123 | 1062 |
test_KErrNone(r); |
0 | 1063 |
TInt entriesNeeded=(gEntriesPerCluster-2) / 2; //7*2entries + . + .. = full sector |
1064 |
for (TInt i = 0; i < entriesNeeded; i++) |
|
1065 |
{ |
|
1066 |
TFileName file=_L("\\scndrv\\dir2\\full\\__a"); |
|
1067 |
file.AppendNum(i); |
|
1068 |
r=TheFs.Delete(file); |
|
123 | 1069 |
test_Value(r, r==KErrNone||r==KErrNotFound); |
0 | 1070 |
} |
1071 |
r=TheFs.RmDir(_L("\\scndrv\\dir2\\full\\")); |
|
123 | 1072 |
test_KErrNone(r); |
0 | 1073 |
r=TheFs.RmDir(_L("\\scndrv\\dir2\\")); |
123 | 1074 |
test_KErrNone(r); |
0 | 1075 |
TFileName veryLongName=(_L("\\scndrv\\dir1\\")); |
1076 |
MakeVeryLongName(veryLongName); |
|
1077 |
r=TheFs.Delete(veryLongName); |
|
123 | 1078 |
test_KErrNone(r); |
0 | 1079 |
r=TheFs.RmDir(_L("\\scndrv\\dir1\\")); |
123 | 1080 |
test_KErrNone(r); |
0 | 1081 |
r=TheFs.RmDir(_L("\\scndrv\\")); |
123 | 1082 |
test_KErrNone(r); |
0 | 1083 |
} |
1084 |
||
1085 |
LOCAL_C void CreateDirectoryStructure() |
|
1086 |
// |
|
1087 |
// creates the directory structure |
|
1088 |
// |
|
1089 |
{ |
|
1090 |
test.Next(_L("Create Directory Structure")); |
|
1091 |
// cluster 3 (root dir is cluster 2) |
|
1092 |
TInt r=TheFs.MkDir(_L("\\scndrv\\")); |
|
123 | 1093 |
test_KErrNone(r); |
0 | 1094 |
// cluster 4 |
1095 |
r=TheFs.MkDir(_L("\\scndrv\\dir1\\")); |
|
123 | 1096 |
test_KErrNone(r); |
0 | 1097 |
TFileName veryLongName=(_L("\\scndrv\\dir1\\")); |
1098 |
MakeVeryLongName(veryLongName); |
|
1099 |
RFile f; |
|
1100 |
// cluster 5 |
|
1101 |
r=f.Create(TheFs,veryLongName,EFileShareAny); |
|
123 | 1102 |
test_KErrNone(r); |
0 | 1103 |
r=f.SetSize(512); |
123 | 1104 |
test_KErrNone(r); |
0 | 1105 |
f.Close(); |
1106 |
// cluster 6 |
|
1107 |
r=TheFs.MkDir(_L("\\scndrv\\dir2\\")); |
|
123 | 1108 |
test_KErrNone(r); |
0 | 1109 |
// cluster 7 |
1110 |
r=TheFs.MkDir(_L("\\scndrv\\dir2\\full\\")); |
|
123 | 1111 |
test_KErrNone(r); |
0 | 1112 |
// cluster 8 |
1113 |
r=TheFs.MkDir(_L("\\scndrv\\dir2\\somedirwith3entries\\")); |
|
123 | 1114 |
test_KErrNone(r); |
0 | 1115 |
// cluster 9 |
1116 |
r=TheFs.MkDir(_L("\\scndrv\\dir2\\somedir2with3entries\\")); |
|
123 | 1117 |
test_KErrNone(r); |
0 | 1118 |
// cluster 10 |
1119 |
r=TheFs.MkDir(_L("\\scndrv\\dir2\\almostfull\\")); |
|
123 | 1120 |
test_KErrNone(r); |
0 | 1121 |
// cluster 11-17 |
1122 |
TInt entriesNeeded=(gEntriesPerCluster-2) / 2; //7*2entries + . + .. = full sector |
|
1123 |
for (TInt i = 0; i < entriesNeeded; i++) |
|
1124 |
{ |
|
1125 |
TFileName file=_L("\\scndrv\\dir2\\full\\__a"); |
|
1126 |
file.AppendNum(i); |
|
1127 |
LastInFull = file; |
|
1128 |
r=f.Create(TheFs,file,EFileShareAny); |
|
123 | 1129 |
test_KErrNone(r); |
0 | 1130 |
if (i < 7) |
1131 |
{ |
|
1132 |
r=f.SetSize(512); |
|
123 | 1133 |
test_KErrNone(r); |
0 | 1134 |
} |
1135 |
f.Close(); |
|
1136 |
} |
|
1137 |
// cluster 18-19 |
|
1138 |
TInt charLength=13*4+1; // name to take up 6 entries |
|
1139 |
TFileName file1=_L("\\scndrv\\dir2\\almostfull\\"); |
|
1140 |
while(charLength--) |
|
1141 |
{ |
|
1142 |
TInt c='A'+charLength%26; |
|
1143 |
file1.Append(c); |
|
1144 |
} |
|
1145 |
TFileName file2=file1; |
|
1146 |
file1.AppendNum(1); |
|
1147 |
file2.AppendNum(2); |
|
1148 |
r=f.Create(TheFs,file1,EFileShareAny); |
|
123 | 1149 |
test_KErrNone(r); |
0 | 1150 |
r=f.SetSize(512); |
123 | 1151 |
test_KErrNone(r); |
0 | 1152 |
f.Close(); |
1153 |
r=f.Create(TheFs,file2,EFileShareAny); |
|
123 | 1154 |
test_KErrNone(r); |
0 | 1155 |
r=f.SetSize(512); |
123 | 1156 |
test_KErrNone(r); |
0 | 1157 |
f.Close(); |
1158 |
} |
|
1159 |
||
1160 |
LOCAL_C TUint8* DirPtr(TInt aOffset) |
|
1161 |
// |
|
1162 |
// Return a pointer to the offset in the dir buffer, or in the special |
|
1163 |
// extension buffer if the dir buffer isn't large enough. If the extension |
|
1164 |
// buffer is needed, it is read from disk when it is created (2 clusters, to |
|
1165 |
// allow for entries spanning cluster boundaries). Errors will occur if |
|
1166 |
// another cluster is needed before the extension has been released. |
|
1167 |
// |
|
1168 |
// Note that if an extension buffer is allocated then writing a dir buffer to |
|
1169 |
// disk will also write the extension buffer and any changes made in it. |
|
1170 |
// |
|
1171 |
{ |
|
1172 |
// if the offset is in store, return its byte address |
|
1173 |
if (aOffset < DirBufPtr->Des().MaxLength()) |
|
1174 |
return (TUint8*)DirBufPtr->Ptr() + aOffset; |
|
1175 |
// not in main buffer, see if extension is allocated already |
|
1176 |
if (!ExtBufPtr) |
|
1177 |
{ |
|
1178 |
// allocate buffer for 2 clusters, starting at the cluster which |
|
1179 |
// contains aOffset |
|
1180 |
ExtBufLen = 2 * gBytesPerCluster; |
|
1181 |
ExtBufPtr = HBufC8::New(ExtBufLen); |
|
123 | 1182 |
test_NotNull(ExtBufPtr); |
0 | 1183 |
// read the clusters in |
1184 |
ExtBufAdd = aOffset - aOffset % gBytesPerCluster; |
|
1185 |
TInt clust = (ExtBufAdd - (gDataStartBytes - gRootDirStart)) /gBytesPerCluster + 2; |
|
1186 |
RDebug::Print(_L("Extension buffer for cluster %d allocated"), clust); |
|
1187 |
TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A'); |
|
123 | 1188 |
test_KErrNone(r); |
0 | 1189 |
TPtr8 des(ExtBufPtr->Des()); |
1190 |
r=TheRawDisk.Read(gRootDirStart + ExtBufAdd, des); |
|
123 | 1191 |
test_KErrNone(r); |
0 | 1192 |
TheRawDisk.Close(); |
1193 |
} |
|
1194 |
// convert to offset in the extension buffer |
|
1195 |
aOffset -= ExtBufAdd; |
|
1196 |
if (aOffset >= ExtBufLen) |
|
1197 |
{ |
|
1198 |
test.Printf(_L("*** ERROR: tried to access cluster %d not in store\n"), |
|
1199 |
(aOffset + ExtBufAdd) / gBytesPerCluster + 2); |
|
1200 |
test(0); |
|
1201 |
} |
|
1202 |
return (TUint8*)ExtBufPtr->Ptr() + aOffset; |
|
1203 |
} |
|
1204 |
||
1205 |
LOCAL_C void DirPtrFree() |
|
1206 |
// |
|
1207 |
// Free the extension buffer and zero the references to it. |
|
1208 |
// |
|
1209 |
{ |
|
1210 |
if (ExtBufPtr) |
|
1211 |
{ |
|
1212 |
TInt clust = (ExtBufAdd - (gDataStartBytes - gRootDirStart)) /gBytesPerCluster + 2; |
|
1213 |
RDebug::Print(_L("Extension buffer for cluster %d deleted"), clust); |
|
1214 |
delete ExtBufPtr; |
|
1215 |
ExtBufPtr = NULL; |
|
1216 |
ExtBufAdd = 0; |
|
1217 |
ExtBufLen = 0; |
|
1218 |
} |
|
1219 |
} |
|
1220 |
||
1221 |
LOCAL_C void ReadDirDisk(TDes8& aDirBuf, TInt aCluster = -1) |
|
1222 |
// |
|
1223 |
// reads directory section of disk into buffer |
|
1224 |
// |
|
1225 |
{ |
|
123 | 1226 |
test_Value(aCluster, aCluster != 1); |
0 | 1227 |
|
1228 |
TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A'); |
|
123 | 1229 |
test_KErrNone(r); |
0 | 1230 |
|
1231 |
if (aCluster == -1) // all clusters ? |
|
1232 |
{ |
|
1233 |
r=TheRawDisk.Read(gRootDirStart, aDirBuf); |
|
1234 |
} |
|
1235 |
else if (aCluster == 0) // root directory cluster |
|
1236 |
{ |
|
1237 |
TPtr8 dirPtr = aDirBuf.MidTPtr(0, gBytesPerCluster); |
|
1238 |
r=TheRawDisk.Read(gRootDirStart, dirPtr); |
|
1239 |
} |
|
1240 |
else |
|
1241 |
{ |
|
1242 |
// directory buffer starts at root directory, so |
|
1243 |
// calculate offset from there. |
|
1244 |
TInt pos = ((aCluster - 2) * gBytesPerCluster) + |
|
1245 |
(gRootDirSectors * BootSector.BytesPerSector()); |
|
1246 |
TPtr8 dirPtr = aDirBuf.MidTPtr(pos, gBytesPerCluster); |
|
1247 |
r=TheRawDisk.Read(gRootDirStart + pos, dirPtr); |
|
1248 |
} |
|
1249 |
||
123 | 1250 |
test_KErrNone(r); |
0 | 1251 |
TheRawDisk.Close(); |
1252 |
} |
|
1253 |
||
1254 |
LOCAL_C void ReadFatDisk(TDes8& aFatBuf) |
|
1255 |
// |
|
1256 |
// reads fat section of disk info buffer |
|
1257 |
// |
|
1258 |
{ |
|
1259 |
TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A'); |
|
123 | 1260 |
test_KErrNone(r); |
0 | 1261 |
r=TheRawDisk.Read(gFatStartBytes, aFatBuf); |
123 | 1262 |
test_KErrNone(r); |
0 | 1263 |
TheRawDisk.Close(); |
1264 |
} |
|
1265 |
||
123 | 1266 |
LOCAL_C void WriteDirEntryToDisk(TDes8& aDirBuf, TInt aCluster = -1) |
0 | 1267 |
// |
123 | 1268 |
// writes dir entry buffer to disk |
0 | 1269 |
// |
1270 |
{ |
|
123 | 1271 |
test_Value(aCluster, aCluster != 1); |
0 | 1272 |
|
1273 |
TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A'); |
|
123 | 1274 |
test_KErrNone(r); |
0 | 1275 |
|
1276 |
if (aCluster == -1) |
|
1277 |
{ |
|
1278 |
r=TheRawDisk.Write(gRootDirStart, aDirBuf); |
|
1279 |
} |
|
1280 |
else if (aCluster == 0) // root directory cluster |
|
1281 |
{ |
|
1282 |
TPtr8 dirPtr = aDirBuf.MidTPtr(0, gBytesPerCluster); |
|
1283 |
r=TheRawDisk.Write(gRootDirStart, dirPtr); |
|
1284 |
} |
|
1285 |
else |
|
1286 |
{ |
|
1287 |
// directory buffer starts at root directory, so |
|
1288 |
// calculate offset from there. |
|
1289 |
TInt pos = ((aCluster - 2) * gBytesPerCluster) + |
|
1290 |
(gRootDirSectors * BootSector.BytesPerSector()); |
|
1291 |
TPtr8 dirPtr = aDirBuf.MidTPtr(pos, gBytesPerCluster); |
|
1292 |
r=TheRawDisk.Write(gRootDirStart + pos, dirPtr); |
|
1293 |
} |
|
1294 |
||
123 | 1295 |
test_KErrNone(r); |
0 | 1296 |
if (ExtBufPtr) |
1297 |
{ |
|
1298 |
TPtr8 des(ExtBufPtr->Des()); |
|
1299 |
r=TheRawDisk.Write(gRootDirStart + ExtBufAdd, des); |
|
123 | 1300 |
test_KErrNone(r); |
0 | 1301 |
} |
1302 |
TheRawDisk.Close(); |
|
1303 |
} |
|
1304 |
||
123 | 1305 |
LOCAL_C void WriteFatToDisk(TDes8& aFatBuf, TInt aStart=0) |
0 | 1306 |
// |
1307 |
// writes fat buffer to disk |
|
1308 |
// |
|
1309 |
{ |
|
1310 |
TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A'); |
|
123 | 1311 |
test_KErrNone(r); |
0 | 1312 |
TInt fatCount=BootSector.NumberOfFats() - aStart; |
1313 |
TInt pos = gFatStartBytes + aStart * gFatSizeSectors*BootSector.BytesPerSector(); |
|
1314 |
while(fatCount--) |
|
1315 |
{ |
|
1316 |
r=TheRawDisk.Write(pos, aFatBuf); |
|
123 | 1317 |
test_KErrNone(r); |
0 | 1318 |
pos += gFatSizeSectors*BootSector.BytesPerSector(); |
1319 |
} |
|
1320 |
TheRawDisk.Close(); |
|
1321 |
} |
|
1322 |
||
1323 |
LOCAL_C void WriteReservedId(TInt aBytePos) |
|
1324 |
// |
|
1325 |
// write reserved id to byte 19 of entry starting at aBytePos |
|
1326 |
// |
|
1327 |
{ |
|
1328 |
TUint8* pEntry=DirPtr(aBytePos); |
|
1329 |
pEntry[19]=1; |
|
1330 |
} |
|
1331 |
||
1332 |
LOCAL_C void WriteEndOfDir(TInt aBytePos) |
|
1333 |
// |
|
1334 |
// write end of directory marker to entry starting at aBytePos |
|
1335 |
// |
|
1336 |
{ |
|
1337 |
TUint8* pEntry=DirPtr(aBytePos); |
|
1338 |
Mem::FillZ(pEntry,KFatDirNameSize); |
|
1339 |
} |
|
1340 |
||
1341 |
LOCAL_C void WriteDelete(TInt aBytePos,TInt aNum) |
|
1342 |
// |
|
1343 |
// writes 0xe5 to entries starting at aBytePos |
|
1344 |
// |
|
1345 |
{ |
|
1346 |
TUint8* pEntry=DirPtr(aBytePos); |
|
1347 |
while(aNum--) |
|
1348 |
{ |
|
1349 |
pEntry[0]=0xE5; |
|
1350 |
pEntry+=KSizeOfFatDirEntry; |
|
1351 |
} |
|
1352 |
} |
|
1353 |
||
1354 |
LOCAL_C void WriteCopyDir(TInt aSrc, TInt aDst) |
|
1355 |
// |
|
1356 |
// Copy one directory entry over another |
|
1357 |
// |
|
1358 |
{ |
|
1359 |
TUint8* pSrc=DirPtr(aSrc); |
|
1360 |
TUint8* pDst=DirPtr(aDst); |
|
1361 |
Mem::Copy(pDst, pSrc, KSizeOfFatDirEntry); |
|
1362 |
} |
|
1363 |
||
1364 |
LOCAL_C void InitialiseBuffers() |
|
1365 |
// |
|
1366 |
// reads disk into buffers |
|
1367 |
// |
|
1368 |
{ |
|
1369 |
gFatTestEntries = MaxClusters(); |
|
1370 |
if (gFatTestEntries > KMaxFatSize) |
|
1371 |
gFatTestEntries = KMaxFatSize; |
|
1372 |
gFatTestSize = PosInBytes(gFatTestEntries); |
|
1373 |
FatBufPtr=HBufC8::New(gFatTestSize); |
|
123 | 1374 |
test_NotNull(FatBufPtr); |
0 | 1375 |
DirBufPtr=HBufC8::New(DirBufferSize()); |
123 | 1376 |
test_NotNull(DirBufPtr); |
0 | 1377 |
|
1378 |
// Buffers for reading from disk |
|
1379 |
FatDiskPtr=HBufC8::New(gFatTestSize); |
|
123 | 1380 |
test_NotNull(FatDiskPtr); |
0 | 1381 |
DirDiskPtr=HBufC8::New(DirBufferSize()); |
123 | 1382 |
test_NotNull(DirDiskPtr); |
0 | 1383 |
} |
1384 |
||
1385 |
LOCAL_C TBool IsSameAsDrive(const TDes8& aFatBuf,const TDes8& aDirBuf) |
|
1386 |
// |
|
1387 |
// compares the two bufs passed in with those on disk |
|
1388 |
// |
|
1389 |
{ |
|
1390 |
TPtr8 fatDisk=FatDiskPtr->Des(); |
|
1391 |
TPtr8 dirDisk=DirDiskPtr->Des(); |
|
1392 |
ReadDirDisk(dirDisk); |
|
1393 |
ReadFatDisk(fatDisk); |
|
1394 |
TBool fatOk = (aFatBuf.Compare(fatDisk)==0); |
|
1395 |
TBool dirOk = (aDirBuf.Compare(dirDisk)==0); |
|
1396 |
if (!fatOk) |
|
1397 |
{ |
|
1398 |
TInt i = FindUnMatch(aFatBuf.Ptr(), fatDisk.Ptr(), fatDisk.Length()); |
|
1399 |
switch (gDiskType) |
|
1400 |
{ |
|
1401 |
case EFat32: |
|
1402 |
i /= 4; |
|
1403 |
||
1404 |
if(i == 1) |
|
1405 |
{//-- mismatch in FAT[1] for FAT16/FAT32 it is OK because FAT[1] is used by volume finalisation |
|
1406 |
//-- to store Volume Clean Shutdown flag |
|
1407 |
fatOk = ETrue; |
|
1408 |
} |
|
1409 |
||
1410 |
break; |
|
1411 |
||
1412 |
case EFat16: |
|
1413 |
i /= 2; |
|
1414 |
||
1415 |
if(i == 1) |
|
1416 |
{//-- mismatch in FAT[1] for FAT16/FAT32 it is OK because FAT[1] is used by volume finalisation |
|
1417 |
//-- to store Volume Clean Shutdown flag |
|
1418 |
fatOk = ETrue; |
|
1419 |
} |
|
1420 |
||
1421 |
break; |
|
1422 |
||
1423 |
case EFat12: |
|
1424 |
i = i*2 / 3; |
|
1425 |
if (GetFatEntry(i, aFatBuf.Ptr()) == GetFatEntry(i, fatDisk.Ptr())) |
|
1426 |
++i; |
|
1427 |
break; |
|
1428 |
default: |
|
1429 |
test(0); |
|
1430 |
} |
|
1431 |
||
1432 |
if(fatOk && i==1) |
|
1433 |
{ |
|
1434 |
test.Printf(_L("Skipping FAT[1] entry for FAT16/32 \n"), i); |
|
1435 |
} |
|
1436 |
else |
|
1437 |
{ |
|
1438 |
test.Printf(_L("FAT entry %d different from expected\n"), i); |
|
1439 |
||
1440 |
RDebug::Print(_L("Expected:\n")); |
|
1441 |
DumpFat(aFatBuf.Ptr()); |
|
1442 |
RDebug::Print(_L("Actual:\n")); |
|
1443 |
DumpFat(fatDisk.Ptr()); |
|
1444 |
} |
|
1445 |
} |
|
1446 |
||
1447 |
if (!dirOk) |
|
1448 |
{ |
|
1449 |
TInt i = FindUnMatch(aDirBuf.Ptr(), dirDisk.Ptr(), dirDisk.Length()); |
|
1450 |
TInt clust = ByteToCluster(i); |
|
1451 |
TInt entry = i % gBytesPerCluster / KSizeOfFatDirEntry; |
|
1452 |
test.Printf(_L("DIR different from expected\n")); |
|
1453 |
test.Printf(_L(" at pos %d sector %d cluster %d entry %d:\n"), i, i / BootSector.BytesPerSector(), clust, entry); |
|
1454 |
||
1455 |
RDebug::Print(_L("Expected:\n")); |
|
1456 |
DumpHex(aDirBuf.Ptr() + i, 32); |
|
1457 |
RDebug::Print(_L("-------------")); |
|
1458 |
RDebug::Print(_L("Actual:\n")); |
|
1459 |
DumpHex(dirDisk.Ptr() + i, 32); |
|
1460 |
||
1461 |
RDebug::Print(_L("Expected:\n")); |
|
1462 |
DumpData(aFatBuf.Ptr(), aDirBuf.Ptr()); |
|
1463 |
RDebug::Print(_L("Actual:\n")); |
|
1464 |
DumpData(fatDisk.Ptr(), dirDisk.Ptr()); |
|
1465 |
} |
|
1466 |
else if (ExtBufPtr) |
|
1467 |
{ |
|
1468 |
HBufC8* extPtr = HBufC8::New(ExtBufLen); |
|
123 | 1469 |
test_NotNull(extPtr); |
0 | 1470 |
TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A'); |
123 | 1471 |
test_KErrNone(r); |
0 | 1472 |
TPtr8 des(extPtr->Des()); |
1473 |
r=TheRawDisk.Read(ExtBufAdd+gRootDirStart, des); |
|
123 | 1474 |
test_KErrNone(r); |
0 | 1475 |
TheRawDisk.Close(); |
1476 |
TInt i = FindUnMatch(ExtBufPtr->Ptr(), extPtr->Ptr(), ExtBufLen); |
|
1477 |
if (i >= 0) |
|
1478 |
{ |
|
1479 |
TInt extcl = (ExtBufAdd - (gDataStartBytes-gRootDirStart)) / gBytesPerCluster + 2; |
|
1480 |
TInt clust = i / gBytesPerCluster; |
|
1481 |
TInt entry = i % gBytesPerCluster / KSizeOfFatDirEntry; |
|
1482 |
test.Printf(_L("DIR different from expected\n")); |
|
1483 |
test.Printf(_L(" at cluster %d entry %d:\n"), extcl+clust, entry); |
|
1484 |
DumpHex(ExtBufPtr->Ptr() + clust * gBytesPerCluster + entry * KSizeOfFatDirEntry, 32); |
|
1485 |
RDebug::Print(_L("-------------")); |
|
1486 |
DumpHex(extPtr->Ptr() + clust * gBytesPerCluster + entry * KSizeOfFatDirEntry, 32); |
|
1487 |
// RDebug::Print(_L("Expected:\n")); |
|
1488 |
// DumpData(aFatBuf.Ptr(), aDirBuf.Ptr()); |
|
1489 |
// RDebug::Print(_L("Actual:\n")); |
|
1490 |
// DumpData(fatDisk.Ptr(), dirDisk.Ptr()); |
|
1491 |
dirOk = EFalse; |
|
1492 |
} |
|
1493 |
delete extPtr; |
|
1494 |
} |
|
1495 |
||
1496 |
return(fatOk && dirOk); |
|
1497 |
} |
|
1498 |
||
1499 |
LOCAL_C void WriteErased(TEntryInfo aTrg,TInt aToDelete) |
|
1500 |
// |
|
1501 |
// writes erased marker, starting at dos entry and working backwards |
|
1502 |
// used to simulate a part entry40*BootSector.BytesPerSector() |
|
1503 |
// |
|
1504 |
{ |
|
1505 |
TInt toStart=aTrg.iBytePos+(aTrg.iLength-1)*KSizeOfFatDirEntry; |
|
1506 |
TPtr8 dirBuf=DirBufPtr->Des(); |
|
1507 |
while(aToDelete--) |
|
1508 |
{ |
|
1509 |
dirBuf[toStart]=0xE5; |
|
1510 |
toStart-=KSizeOfFatDirEntry; |
|
1511 |
} |
|
1512 |
} |
|
1513 |
||
1514 |
LOCAL_C void CreatePartialEntry(TEntryInfo aTrg,TInt aToDelete,TBool aAddEOfDir) |
|
1515 |
// |
|
1516 |
// creates a partial entry |
|
1517 |
// |
|
1518 |
{ |
|
1519 |
WriteErased(aTrg,aToDelete); |
|
1520 |
if(aAddEOfDir) |
|
1521 |
WriteEndOfDir(aTrg.iBytePos+aTrg.iLength*KSizeOfFatDirEntry); |
|
1522 |
TPtr8 dirBuf=DirBufPtr->Des(); |
|
123 | 1523 |
WriteDirEntryToDisk(dirBuf); |
0 | 1524 |
} |
1525 |
||
1526 |
LOCAL_C TBool TestPartialEntry(TEntryInfo aEntry) |
|
1527 |
// |
|
1528 |
// tests that scandrive deals with a partial entry and returns the result |
|
1529 |
// |
|
1530 |
{ |
|
1531 |
test.Next(_L("TestPartialEntry")); |
|
1532 |
TInt r=TheFs.ScanDrive(gSessionPath); |
|
123 | 1533 |
test_KErrNone(r); |
0 | 1534 |
WriteDelete(aEntry.iBytePos,aEntry.iLength); |
1535 |
||
1536 |
TPtr8 fatBuf=FatBufPtr->Des(); |
|
1537 |
TPtr8 dirBuf=DirBufPtr->Des(); |
|
1538 |
||
1539 |
TBool res=IsSameAsDrive(fatBuf,dirBuf); |
|
1540 |
return(res); |
|
1541 |
} |
|
1542 |
||
1543 |
LOCAL_C void CreateMatchingEntry(TEntryInfo aTrg,TEntryInfo aSrc,TBool aAddEOfDir) |
|
1544 |
// |
|
1545 |
// creates matching entry |
|
1546 |
// |
|
1547 |
{ |
|
1548 |
test.Next(_L("Create entry with start cluster already used")); |
|
1549 |
TUint8* src = DirPtr(aSrc.iBytePos); |
|
1550 |
TUint8* dst = DirPtr(aTrg.iBytePos); |
|
1551 |
Mem::Copy(dst, src, aSrc.iLength*KSizeOfFatDirEntry); |
|
1552 |
WriteReservedId(aTrg.iBytePos+(aTrg.iLength-1)*KSizeOfFatDirEntry); |
|
1553 |
if(aAddEOfDir) |
|
1554 |
WriteEndOfDir(aTrg.iBytePos+aTrg.iLength*KSizeOfFatDirEntry); |
|
1555 |
TPtr8 dirBuf=DirBufPtr->Des(); |
|
123 | 1556 |
WriteDirEntryToDisk(dirBuf); |
0 | 1557 |
} |
1558 |
||
1559 |
LOCAL_C TBool TestMatchingEntry(TEntryInfo aToDelete) |
|
1560 |
// |
|
1561 |
// tests that scandrive deals with matching entries correctly |
|
1562 |
// |
|
1563 |
{ |
|
1564 |
test.Next(_L("TestMatchingEntries")); |
|
1565 |
WriteDelete(aToDelete.iBytePos,aToDelete.iLength); |
|
1566 |
TInt r=TheFs.ScanDrive(gSessionPath); |
|
123 | 1567 |
test_KErrNone(r); |
0 | 1568 |
|
1569 |
TPtr8 fatBuf=FatBufPtr->Des(); |
|
1570 |
TPtr8 dirBuf=DirBufPtr->Des(); |
|
1571 |
||
1572 |
TBool res=IsSameAsDrive(fatBuf,dirBuf); |
|
1573 |
DirPtrFree(); |
|
1574 |
return(res); |
|
1575 |
} |
|
1576 |
||
1577 |
||
1578 |
LOCAL_C void TestExtendedChars() |
|
1579 |
// |
|
1580 |
// tests that extended characters corresponding to ISO Latin 1 |
|
1581 |
// characters 128-255 are recognised as valid by scandrive |
|
1582 |
// |
|
1583 |
{ |
|
1584 |
test.Next(_L("TestExtendedChars()")); |
|
1585 |
Format(); |
|
1586 |
||
1587 |
_LIT(KRoot,"\\"); |
|
1588 |
CDir* dirs; |
|
1589 |
// check no entries in the root directory |
|
1590 |
TInt r=TheFs.GetDir(KRoot,KEntryAttMaskSupported,ESortNone,dirs); |
|
123 | 1591 |
test_KErrNone(r); |
1592 |
test_Equal(0,dirs->Count()); |
|
0 | 1593 |
delete(dirs); |
1594 |
dirs=NULL; |
|
1595 |
||
1596 |
// create file |
|
1597 |
_LIT(KOrigShortName,"P_SSI.TXT"); |
|
1598 |
||
1599 |
//_LIT(KTestFile,"\\p\xE4ssi.txt"); //-- this causes problems for VC6 and default locale different from English |
|
1600 |
TBuf<64> TestFileName(_L("\\p$ssi.txt")); |
|
1601 |
TestFileName[2] = 0xe4; //-- replace '$' with this code |
|
1602 |
||
1603 |
//_LIT(KExtShortName,"P\xC4SSI.TXT"); //-- this causes problems for VC6 and default locale different from English |
|
1604 |
TBuf<64> ExtShortName(_L("P$SSI.TXT")); |
|
1605 |
ExtShortName[1] = 0xC4; //-- replace '$' with this code |
|
1606 |
||
1607 |
||
1608 |
RFile file; |
|
1609 |
r=file.Replace(TheFs,TestFileName,EFileShareExclusive); |
|
123 | 1610 |
test_KErrNone(r); |
0 | 1611 |
file.Close(); |
1612 |
||
1613 |
// get short name |
|
1614 |
TFileName shortName; |
|
1615 |
r=TheFs.GetShortName(TestFileName,shortName); |
|
123 | 1616 |
test_KErrNone(r); |
0 | 1617 |
test(shortName==KOrigShortName); |
1618 |
||
1619 |
// must be first entry in root, modify to read like |
|
1620 |
// a windows-generated short name (ie. contains extended character) |
|
1621 |
DumpData(NULL, 0, 20); |
|
1622 |
TInt bytePos=ClusterEntryToBytes(0,1); |
|
1623 |
RRawDisk raw; |
|
1624 |
r=raw.Open(TheFs,gSessionPath[0]-'A'); |
|
123 | 1625 |
test_KErrNone(r); |
0 | 1626 |
TBuf8<1> buf(1); |
1627 |
||
1628 |
//-- change 2nd character in the short name (Fat DOS entry) |
|
1629 |
buf[0]=(TUint8)'\xC4'; |
|
1630 |
r=raw.Write(gRootDirStart+bytePos+1,buf); |
|
123 | 1631 |
test_KErrNone(r); |
0 | 1632 |
|
1633 |
//-- fix the fiddled short name checksum in the corresponding VFat entry |
|
1634 |
bytePos=ClusterEntryToBytes(0,0); |
|
1635 |
buf[0]=(TUint8)0x2f; |
|
1636 |
r=raw.Write(gRootDirStart+bytePos+13,buf); |
|
123 | 1637 |
test_KErrNone(r); |
0 | 1638 |
|
1639 |
// retrieve short name from media. |
|
1640 |
// Note: do not use RFs::GetShortName() as its behaviours are code page dependent. |
|
1641 |
bytePos=ClusterEntryToBytes(0,1); |
|
1642 |
TBuf8<11> shortNameBuf8; |
|
1643 |
r=raw.Read(gRootDirStart+bytePos,shortNameBuf8); |
|
123 | 1644 |
test_KErrNone(r); |
0 | 1645 |
shortNameBuf8 = DosNameFromStdFormat(shortNameBuf8); |
1646 |
shortName.Copy(shortNameBuf8); |
|
1647 |
raw.Close(); |
|
1648 |
||
1649 |
||
1650 |
test(shortName==ExtShortName); |
|
1651 |
DumpData(NULL, 0, 20); |
|
1652 |
//TheFs.SetDebugRegister(KFSYS); |
|
1653 |
r=TheFs.ScanDrive(gSessionPath); |
|
1654 |
TheFs.SetDebugRegister(0); |
|
123 | 1655 |
test_KErrNone(r); |
0 | 1656 |
DumpData(NULL, 0, 20); |
1657 |
||
1658 |
// retrieve short name from media. |
|
1659 |
r=raw.Open(TheFs,gSessionPath[0]-'A'); |
|
123 | 1660 |
test_KErrNone(r); |
0 | 1661 |
bytePos=ClusterEntryToBytes(0,1); |
1662 |
r=raw.Read(gRootDirStart+bytePos,shortNameBuf8); |
|
123 | 1663 |
test_KErrNone(r); |
0 | 1664 |
shortNameBuf8 = DosNameFromStdFormat(shortNameBuf8); |
1665 |
shortName.Copy(shortNameBuf8); |
|
1666 |
raw.Close(); |
|
1667 |
||
1668 |
test(shortName==ExtShortName); |
|
1669 |
||
1670 |
// delete file |
|
1671 |
r=TheFs.Delete(TestFileName); |
|
123 | 1672 |
test_KErrNone(r); |
0 | 1673 |
} |
1674 |
||
1675 |
LOCAL_C void TestMountAndScan() |
|
1676 |
// |
|
1677 |
// test MountFileSystemAndScan() |
|
1678 |
// |
|
1679 |
{ |
|
1680 |
TFullName extName; |
|
1681 |
TBool primaryExtensionExists = EFalse; |
|
1682 |
||
1683 |
test.Next(_L("TestMountAndScan")); |
|
1684 |
HBufC8* newFat=HBufC8::New(gFatTestSize); |
|
123 | 1685 |
test_NotNull(newFat); |
0 | 1686 |
TPtr8 fat=newFat->Des(); |
1687 |
TPtr8 origFat=FatBufPtr->Des(); |
|
1688 |
TPtr8 origDir=DirBufPtr->Des(); |
|
1689 |
||
1690 |
// set cluster of \scndrv\dir1\ to a hanging cluster |
|
1691 |
ReadFatDisk(fat); |
|
123 | 1692 |
WriteToFatBuf(gClusterDir1ext,35,fat.Ptr()); |
1693 |
WriteToFatBuf(35,36,fat.Ptr()); |
|
1694 |
WriteFatToDisk(fat); |
|
0 | 1695 |
// set the default path to something other than the current drive |
1696 |
TFileName fsName; |
|
1697 |
TInt r=TheFs.FileSystemName(fsName,gSessionPath[0]-'A'); |
|
123 | 1698 |
test_KErrNone(r); |
0 | 1699 |
TFileName origDefPath, newDefPath; |
1700 |
r=TheFs.SessionPath(origDefPath); |
|
123 | 1701 |
test_KErrNone(r); |
0 | 1702 |
newDefPath=origDefPath; |
1703 |
newDefPath[0]=(TText)'z'; |
|
1704 |
r=TheFs.SetSessionPath(newDefPath); |
|
123 | 1705 |
test_KErrNone(r); |
0 | 1706 |
r = TheFs.ExtensionName(extName,gSessionPath[0]-'A',0); |
1707 |
if (r == KErrNone) |
|
1708 |
{ |
|
1709 |
primaryExtensionExists = ETrue; |
|
1710 |
} |
|
1711 |
r=TheFs.DismountFileSystem(fsName,gSessionPath[0]-'A'); |
|
123 | 1712 |
test_KErrNone(r); |
0 | 1713 |
// mount file system and check scandrive corrects error |
1714 |
TBool isMount; |
|
1715 |
if (primaryExtensionExists) |
|
1716 |
r=TheFs.MountFileSystemAndScan(fsName,extName,gSessionPath[0]-'A',isMount); |
|
1717 |
else |
|
1718 |
r=TheFs.MountFileSystemAndScan(fsName,gSessionPath[0]-'A',isMount); |
|
123 | 1719 |
test(isMount); |
1720 |
test_KErrNone(r); |
|
0 | 1721 |
TBool res=IsSameAsDrive(origFat,origDir); |
1722 |
test(res); |
|
1723 |
||
1724 |
r=TheFs.SetSessionPath(origDefPath); |
|
123 | 1725 |
test_KErrNone(r); |
0 | 1726 |
delete newFat; |
1727 |
} |
|
1728 |
||
1729 |
||
1730 |
LOCAL_C void TestConsecutiveMountAndScans() |
|
1731 |
// |
|
1732 |
// test fix for DEF093072: [codebase]MountFileSystemAndScan returns err -21 but ok flag |
|
1733 |
// |
|
1734 |
{ |
|
1735 |
TFullName extName; |
|
1736 |
TBool primaryExtensionExists = EFalse; |
|
1737 |
TFileName fsName; |
|
1738 |
TInt r=TheFs.FileSystemName(fsName,gSessionPath[0]-'A'); |
|
123 | 1739 |
test_KErrNone(r); |
0 | 1740 |
r = TheFs.ExtensionName(extName,gSessionPath[0]-'A',0); |
1741 |
if (r == KErrNone) |
|
1742 |
{ |
|
1743 |
primaryExtensionExists = ETrue; |
|
1744 |
} |
|
1745 |
r=TheFs.DismountFileSystem(fsName,gSessionPath[0]-'A'); |
|
123 | 1746 |
test_KErrNone(r); |
0 | 1747 |
|
1748 |
// RFs::MountFileSystemAndScan twice consecutively |
|
1749 |
// first time |
|
1750 |
TBool isMount; |
|
1751 |
if (primaryExtensionExists) |
|
1752 |
r=TheFs.MountFileSystemAndScan(fsName,extName,gSessionPath[0]-'A',isMount); |
|
1753 |
else |
|
1754 |
r=TheFs.MountFileSystemAndScan(fsName,gSessionPath[0]-'A',isMount); |
|
123 | 1755 |
test(isMount); |
1756 |
test_KErrNone(r); |
|
0 | 1757 |
// and a second time |
1758 |
if (primaryExtensionExists) |
|
1759 |
r=TheFs.MountFileSystemAndScan(fsName,extName,gSessionPath[0]-'A',isMount); |
|
1760 |
else |
|
1761 |
r=TheFs.MountFileSystemAndScan(fsName,gSessionPath[0]-'A',isMount); |
|
123 | 1762 |
test(!isMount); |
1763 |
test_Equal(KErrAccessDenied,r); |
|
0 | 1764 |
} |
1765 |
||
123 | 1766 |
|
1767 |
static void CreateContiguousClusterChain(TUint32 aStartIndex, TUint32 aEndIndex, const TUint8* aFatPtr, TBool aMarkEoc) |
|
1768 |
/* |
|
1769 |
* Creates a contiguous cluster chain in the FAT buffer. |
|
1770 |
* |
|
1771 |
* @param aStartIndex The first cluster index of the chain |
|
1772 |
* aEndIndex The last cluster index of the chain |
|
1773 |
* aFatPtr FAT table buffer pointer |
|
1774 |
* aMarkEoc If ETrue, aEndIndex will be marked as EOC, else it will be a hanging cluster chain |
|
1775 |
*/ |
|
1776 |
{ |
|
1777 |
// Write cluster chain |
|
1778 |
for(TUint i=aStartIndex; i<aEndIndex; ++i) |
|
1779 |
WriteToFatBuf(i, i+1, aFatPtr); |
|
1780 |
// Mark EOC if needed |
|
1781 |
if (aMarkEoc) |
|
1782 |
WriteToFatBuf(aEndIndex, gEndOfChain, aFatPtr); |
|
1783 |
} |
|
1784 |
||
1785 |
||
0 | 1786 |
LOCAL_C void DoHangingClusters() |
1787 |
// |
|
1788 |
// Tests that scandrive removes hanging clusters |
|
1789 |
// |
|
1790 |
{ |
|
1791 |
test.Next(_L("Check Hanging clusters")); |
|
1792 |
HBufC8* newFat=HBufC8::New(gFatTestSize); |
|
123 | 1793 |
test_NotNull(newFat); |
0 | 1794 |
TPtr8 fat=newFat->Des(); |
1795 |
TPtr8 origFat=FatBufPtr->Des(); |
|
1796 |
TPtr8 origDir=DirBufPtr->Des(); |
|
1797 |
||
123 | 1798 |
// Set cluster of \scndrv\dir1\ to hanging cluster chain |
0 | 1799 |
test.Start(_L("Test hanging cluster in \\scndrv\\dir1\\")); |
1800 |
ReadFatDisk(fat); |
|
123 | 1801 |
WriteToFatBuf(gClusterDir1ext,35,fat.Ptr()); |
1802 |
WriteToFatBuf(35,36,fat.Ptr()); |
|
1803 |
WriteFatToDisk(fat); // gClusterDir1ext->35->36 |
|
0 | 1804 |
TInt r=TheFs.ScanDrive(gSessionPath); |
123 | 1805 |
test_KErrNone(r); |
0 | 1806 |
TBool res=IsSameAsDrive(origFat,origDir); |
1807 |
test(res); |
|
1808 |
||
123 | 1809 |
// Set cluster chain of first entry of \scndrv\dir1\ to |
0 | 1810 |
// larger size than file size |
1811 |
test.Next(_L("Test hanging cluster in first entry")); |
|
1812 |
ReadFatDisk(fat); |
|
123 | 1813 |
WriteToFatBuf(gClusterDir1ext,39,fat.Ptr()); |
1814 |
WriteToFatBuf(39,500,fat.Ptr()); |
|
1815 |
CreateContiguousClusterChain(500, 505, fat.Ptr(), ETrue); |
|
1816 |
WriteFatToDisk(fat); // gClusterDir1ext->39->500->501->502->503->504->505->EOC |
|
0 | 1817 |
r=TheFs.ScanDrive(gSessionPath); |
123 | 1818 |
test_KErrNone(r); |
0 | 1819 |
res=IsSameAsDrive(origFat,origDir); |
1820 |
test(res); |
|
1821 |
||
123 | 1822 |
// Set cluster of \scndrv\ to a hanging cluster |
0 | 1823 |
test.Next(_L("Test hanging cluster of \\scndrv\\")); |
1824 |
ReadFatDisk(fat); |
|
123 | 1825 |
WriteToFatBuf(gClusterScnDrv,511,fat.Ptr()); |
1826 |
WriteFatToDisk(fat); // gClusterScnDrv->511 |
|
0 | 1827 |
r=TheFs.ScanDrive(gSessionPath); |
123 | 1828 |
test_KErrNone(r); |
0 | 1829 |
res=IsSameAsDrive(origFat,origDir); |
1830 |
test(res); |
|
1831 |
||
1832 |
delete newFat; |
|
1833 |
test.End(); |
|
1834 |
} |
|
1835 |
||
1836 |
LOCAL_C void DoLostClusters() |
|
1837 |
// |
|
1838 |
// Tests that scandrive removes lost clusters |
|
1839 |
// |
|
1840 |
{ |
|
1841 |
test.Next(_L("Check lost clusters")); |
|
1842 |
HBufC8* newFat=HBufC8::New(gFatTestSize); |
|
123 | 1843 |
test_NotNull(newFat); |
0 | 1844 |
TPtr8 fat=newFat->Des(); |
1845 |
TPtr8 origFat=FatBufPtr->Des(); |
|
1846 |
TPtr8 origDir=DirBufPtr->Des(); |
|
1847 |
ReadFatDisk(origFat); |
|
1848 |
ReadDirDisk(origDir); |
|
1849 |
||
1850 |
// write cluster chain |
|
1851 |
test.Start(_L("Test removal of lost cluster chain")); |
|
1852 |
ReadFatDisk(fat); |
|
123 | 1853 |
CreateContiguousClusterChain(25, 35, fat.Ptr(), ETrue); |
1854 |
WriteFatToDisk(fat); // 25->26->27->28->29->30->31->32->33->34->35->EOC |
|
0 | 1855 |
TInt r=TheFs.ScanDrive(gSessionPath); |
123 | 1856 |
test_KErrNone(r); |
0 | 1857 |
TBool res=IsSameAsDrive(origFat,origDir); |
1858 |
test(res); |
|
1859 |
||
1860 |
// write semi-random changes to first fat |
|
1861 |
test.Next(_L("Test semi-random changes to first fat")); |
|
1862 |
for(TInt j=1;j<gFatTestSize/BootSector.BytesPerSector();++j) |
|
1863 |
{ |
|
1864 |
TInt off = j*BootSector.BytesPerSector()+j*7%512; |
|
1865 |
fat[off]=1; |
|
1866 |
} |
|
123 | 1867 |
WriteFatToDisk(fat); |
0 | 1868 |
r=TheFs.ScanDrive(gSessionPath); |
123 | 1869 |
test_KErrNone(r); |
0 | 1870 |
res=IsSameAsDrive(origFat,origDir); |
1871 |
test(res); |
|
1872 |
||
1873 |
// write semi-random changes to second fat |
|
1874 |
test.Next(_L("Test semi-random changes to second fat")); |
|
123 | 1875 |
WriteFatToDisk(fat, 1); |
0 | 1876 |
r=TheFs.ScanDrive(gSessionPath); |
123 | 1877 |
test_KErrNone(r); |
0 | 1878 |
res=IsSameAsDrive(origFat,origDir); |
1879 |
test(res); |
|
1880 |
||
1881 |
delete newFat; |
|
1882 |
test.End(); |
|
1883 |
} |
|
1884 |
||
123 | 1885 |
|
1886 |
static void DoHangingAndLostClusters() |
|
1887 |
/* |
|
1888 |
* Tests that ScanDrive fixes MULTIPLE hanging clusters and removes lost clusters. |
|
1889 |
* It creates multiple hanging and lost cluster chains in the FAT table and |
|
1890 |
* expects ScanDrive to fix them all. |
|
1891 |
*/ |
|
1892 |
{ |
|
1893 |
test.Start(_L("Check multiple hanging and lost cluster chains")); |
|
1894 |
HBufC8* newFat = HBufC8::New(gFatTestSize); |
|
1895 |
test_NotNull(newFat); |
|
1896 |
TPtr8 fat = newFat->Des(); |
|
1897 |
TPtr8 origFat = FatBufPtr->Des(); |
|
1898 |
TPtr8 origDir = DirBufPtr->Des(); |
|
1899 |
ReadFatDisk(origFat); |
|
1900 |
ReadDirDisk(origDir); |
|
1901 |
||
1902 |
test.Printf(_L("Create multiple hanging cluster chains\n")); |
|
1903 |
ReadFatDisk(fat); |
|
1904 |
// Set hanging cluster for the file in \scndrv\dir1 |
|
1905 |
// gClusterDir1ext+1->25->26->27->28->29->30->31->32->33->34->35 |
|
1906 |
WriteToFatBuf(gClusterDir1ext+1, 25, fat.Ptr()); |
|
1907 |
CreateContiguousClusterChain(25, 35, fat.Ptr(), EFalse); |
|
1908 |
// Set hanging cluster for the first file in \scndrv\dir2 |
|
1909 |
// gClusterDir2_AFull+1->249->250->53->54->55->EOC |
|
1910 |
WriteToFatBuf(gClusterDir2_AFull+1, 249, fat.Ptr()); |
|
1911 |
WriteToFatBuf(249, 250, fat.Ptr()); |
|
1912 |
WriteToFatBuf(250, 53, fat.Ptr()); |
|
1913 |
CreateContiguousClusterChain(53, 55, fat.Ptr(), ETrue); |
|
1914 |
// Set hanging cluster for the fourth file in \scndrv\dir2 |
|
1915 |
// gClusterDir2_AFull+4->59->60->61->62->63 |
|
1916 |
WriteToFatBuf(gClusterDir2_AFull+4, 59, fat.Ptr()); |
|
1917 |
CreateContiguousClusterChain(59, 63, fat.Ptr(), EFalse); |
|
1918 |
// Set hanging cluster for the second file in \scndrv\dir2 |
|
1919 |
// gClusterDir2_AFull+2->67->68->69->EOC |
|
1920 |
WriteToFatBuf(gClusterDir2_AFull+2, 67, fat.Ptr()); |
|
1921 |
CreateContiguousClusterChain(67, 69, fat.Ptr(), ETrue); |
|
1922 |
||
1923 |
test.Printf(_L("Create multiple lost clusters\n")); |
|
1924 |
// Create 1st lost cluster chain (clusters 36-45) |
|
1925 |
CreateContiguousClusterChain(36, 45, fat.Ptr(), ETrue); |
|
1926 |
// Create 2nd lost cluster chain (clusters 246-248,56-58) |
|
1927 |
CreateContiguousClusterChain(246, 248, fat.Ptr(), EFalse); |
|
1928 |
WriteToFatBuf(248, 56, fat.Ptr()); |
|
1929 |
CreateContiguousClusterChain(56, 58, fat.Ptr(), ETrue); |
|
1930 |
// Create 3rd lost cluster chain (clusters 251-253,564-566, with hanging end) |
|
1931 |
CreateContiguousClusterChain(251, 253, fat.Ptr(), EFalse); |
|
1932 |
WriteToFatBuf(253, 564, fat.Ptr()); |
|
1933 |
CreateContiguousClusterChain(564, 566, fat.Ptr(), EFalse); |
|
1934 |
||
1935 |
// Flush all FAT changes to the media |
|
1936 |
WriteFatToDisk(fat); |
|
1937 |
||
1938 |
test.Next(_L("Test ScanDrive fixes multiple hanging and lost cluster chains")); |
|
1939 |
TInt r = TheFs.CheckDisk(gSessionPath); // CheckDisk should detect an error |
|
1940 |
test_Value(r, r != KErrNone); |
|
1941 |
r = TheFs.ScanDrive(gSessionPath); // ScanDrive should find the errors and fix them |
|
1942 |
test_KErrNone(r); |
|
1943 |
r = TheFs.CheckDisk(gSessionPath); |
|
1944 |
test_KErrNone(r); |
|
1945 |
TBool res = IsSameAsDrive(origFat, origDir); |
|
1946 |
test(res); |
|
1947 |
||
1948 |
delete newFat; |
|
1949 |
test.End(); |
|
1950 |
} |
|
1951 |
||
1952 |
||
0 | 1953 |
LOCAL_C void DoPartEntries() |
1954 |
// |
|
1955 |
// Tests that scandrive detects/corrects partial entries |
|
1956 |
// |
|
1957 |
{ |
|
1958 |
RFile temp; |
|
1959 |
TInt last; |
|
1960 |
TBool res; |
|
1961 |
test.Start(_L("Check partial entries")); |
|
1962 |
TPtr8 fatBuf=FatBufPtr->Des(); |
|
1963 |
TPtr8 dirBuf=DirBufPtr->Des(); |
|
1964 |
||
1965 |
TInt r=TheFs.RmDir(_L("\\scndrv\\dir2\\somedirwith3entries\\")); |
|
123 | 1966 |
test_Value(r, r==KErrNone || r==KErrNotFound || r==KErrPathNotFound); |
0 | 1967 |
r=TheFs.RmDir(_L("\\scndrv\\dir2\\somedir2with3entries\\")); |
123 | 1968 |
test_Value(r, r==KErrNone || r==KErrNotFound || r==KErrPathNotFound); |
0 | 1969 |
|
1970 |
if (BootSector.RootDirEntries() != 0) |
|
1971 |
{ |
|
1972 |
// Can only do this on FAT12/16, FAT32 root directory is extensible |
|
1973 |
// partial entry that fills up the root dir |
|
1974 |
test.Next(_L("Partial entry at end of rootdir")); |
|
1975 |
FillUpRootDir(2); |
|
1976 |
r=temp.Create(TheFs,_L("\\temp"),EFileShareAny); |
|
123 | 1977 |
test_KErrNone(r); |
0 | 1978 |
temp.Close(); |
1979 |
ReadDirDisk(dirBuf); |
|
1980 |
ReadFatDisk(fatBuf); |
|
1981 |
TEntryInfo partial1(ClusterEntryToBytes(gClusterRootDir,BootSector.RootDirEntries()-2),2); |
|
1982 |
CreatePartialEntry(partial1,1,EFalse); |
|
1983 |
res=TestPartialEntry(partial1); |
|
1984 |
test(res); |
|
1985 |
UnFillUpRootDir(2); |
|
1986 |
ReadDirDisk(dirBuf); |
|
1987 |
ReadFatDisk(fatBuf); |
|
1988 |
} |
|
1989 |
||
271 | 1990 |
// use first entry \scndrv\dir2\almostfull |
0 | 1991 |
test.Next(_L("Partial entry in middle of subdir")); |
1992 |
last = GetStartCluster(gClusterDir2_AFull,7); |
|
1993 |
TEntryInfo partial2(ClusterEntryToBytes(gClusterDir2_AFull,2),6); |
|
1994 |
CreatePartialEntry(partial2,3,EFalse); |
|
1995 |
// entry has been allocated a cluster which scandrive should delete along with partial entry |
|
1996 |
if (last > 0) |
|
123 | 1997 |
WriteToFatBuf(last,0,fatBuf.Ptr()); |
0 | 1998 |
res=TestPartialEntry(partial2); |
1999 |
test(res); |
|
2000 |
||
271 | 2001 |
// reduce size of \scndrv\dir2\full |
0 | 2002 |
test.Next(_L("Test directory reclaim")); |
2003 |
last = GetStartCluster(gClusterDir2_Full,gEntriesPerCluster-2); |
|
2004 |
WriteEndOfDir(ClusterEntryToBytes(gClusterDir2_Full,gEntriesPerCluster-2)); |
|
123 | 2005 |
WriteDirEntryToDisk(dirBuf); |
0 | 2006 |
TInt entry = GetFatEntry(gClusterDir2_Full, fatBuf.Ptr()); |
123 | 2007 |
WriteToFatBuf(gClusterDir2_Full,gEndOfChain,fatBuf.Ptr()); |
0 | 2008 |
while (entry && (entry & gEndOfChain) != gEndOfChain) |
2009 |
{ |
|
2010 |
TInt next = GetFatEntry(entry, fatBuf.Ptr()); |
|
123 | 2011 |
WriteToFatBuf(entry,0,fatBuf.Ptr()); |
0 | 2012 |
entry = next; |
2013 |
} |
|
2014 |
if (last > 0) |
|
123 | 2015 |
WriteToFatBuf(last,0,fatBuf.Ptr()); |
0 | 2016 |
r=TheFs.ScanDrive(gSessionPath); |
123 | 2017 |
test_KErrNone(r); |
0 | 2018 |
res=IsSameAsDrive(fatBuf,dirBuf); |
2019 |
test(res); |
|
2020 |
||
271 | 2021 |
// use last entry of first cluster in \scndrv\dir2\full |
0 | 2022 |
test.Next(_L("Partial entry at end of subdir")); |
2023 |
r=temp.Create(TheFs,_L("\\scndrv\\dir2\\full\\temp"),EFileShareAny); |
|
123 | 2024 |
test_KErrNone(r); |
0 | 2025 |
temp.Close(); |
2026 |
ReadDirDisk(dirBuf); |
|
2027 |
ReadFatDisk(fatBuf); |
|
2028 |
TEntryInfo partial3(ClusterEntryToBytes(gClusterDir2_Full,gEntriesPerCluster-2),2); |
|
2029 |
CreatePartialEntry(partial3,1,EFalse); |
|
2030 |
res=TestPartialEntry(partial3); |
|
2031 |
test(res); |
|
2032 |
||
271 | 2033 |
// use entry in \scndrv\dir2\almostfull |
0 | 2034 |
test.Next(_L("Partial entry preceeding end-of-dir marker")); |
2035 |
last = GetStartCluster(gClusterDir2_AFull,14); |
|
2036 |
if (last > 0) |
|
123 | 2037 |
WriteToFatBuf(last,0,fatBuf.Ptr()); |
0 | 2038 |
last = GetStartCluster(gClusterDir2_AFull,8); |
2039 |
if (last > 0) |
|
123 | 2040 |
WriteToFatBuf(last,0,fatBuf.Ptr()); |
0 | 2041 |
WriteEndOfDir(ClusterEntryToBytes(gClusterDir2_AFull,14)); |
123 | 2042 |
WriteDirEntryToDisk(dirBuf); |
0 | 2043 |
TEntryInfo partial4(ClusterEntryToBytes(gClusterDir2_AFull,8),6); |
2044 |
CreatePartialEntry(partial4,4,EFalse); |
|
2045 |
res=TestPartialEntry(partial4); |
|
2046 |
test(res); |
|
2047 |
||
2048 |
// NOTE: |
|
2049 |
// Following test case is not valid anymore after fixing of |
|
2050 |
// PDEF128576: Unicode name file deleted after Scandrive |
|
2051 |
// In the fixes, we decided to discard file name checking in ScanDrive, |
|
2052 |
// as it is impossible for ScanDrive to judge if the illegal byte is part of a legal |
|
2053 |
// DBCS charater. |
|
2054 |
||
271 | 2055 |
// create entry in \scndrv\dir2\almostfull |
0 | 2056 |
// test.Next(_L("Partial entry with invalid dos name")); |
2057 |
// r=temp.Create(TheFs,_L("\\scndrv\\dir2\\almostfull\\Dodgy file name"),EFileShareAny); |
|
123 | 2058 |
// test_KErrNone(r); |
0 | 2059 |
// temp.Close(); |
2060 |
// ReadDirDisk(dirBuf); |
|
2061 |
// TInt dosStart=ClusterEntryToBytes(gClusterDir2_AFull,4); |
|
2062 |
// dirBuf[dosStart+4]=0x1; |
|
2063 |
// WriteDirDisk(dirBuf); |
|
2064 |
// r=TheFs.ScanDrive(gSessionPath); |
|
123 | 2065 |
// test_KErrNone(r); |
0 | 2066 |
// WriteDelete(dosStart-2*32,3); |
2067 |
// res=IsSameAsDrive(fatBuf,dirBuf); |
|
2068 |
// test(res); |
|
2069 |
||
2070 |
if (BootSector.SectorsPerCluster() == 1) |
|
2071 |
{ |
|
271 | 2072 |
// use entry created in \scndrv\dir2 |
0 | 2073 |
test.Next(_L("Partial entry spanning more than two clusters")); |
2074 |
last = GetStartCluster(gClusterDir2_Full,gEntriesPerCluster-1); |
|
2075 |
WriteEndOfDir(ClusterEntryToBytes(gClusterDir2_Full,gEntriesPerCluster-2)); |
|
2076 |
WriteEndOfDir(ClusterEntryToBytes(gClusterDir2_Full,gEntriesPerCluster-1)); |
|
123 | 2077 |
WriteDirEntryToDisk(dirBuf); |
0 | 2078 |
TFileName longFile=_L("\\scndrv\\dir2\\full\\"); |
2079 |
MakeVeryLongName(longFile); |
|
2080 |
r=temp.Create(TheFs,longFile,EFileShareAny); |
|
123 | 2081 |
test_KErrNone(r); |
0 | 2082 |
temp.Close(); |
2083 |
ReadDirDisk(dirBuf); |
|
123 | 2084 |
WriteToFatBuf(gClusterDir2_Full,gClusterDir2_SD3E,fatBuf.Ptr()); |
2085 |
WriteToFatBuf(gClusterDir2_SD3E,gClusterDir2_SD23E,fatBuf.Ptr()); |
|
2086 |
WriteToFatBuf(gClusterDir2_SD23E,gEndOfChain,fatBuf.Ptr()); |
|
0 | 2087 |
if (last > 0) |
123 | 2088 |
WriteToFatBuf(last,0,fatBuf.Ptr()); |
0 | 2089 |
TEntryInfo partial5(ClusterEntryToBytes(gClusterDir2_Full,gEntriesPerCluster-2),19); |
2090 |
CreatePartialEntry(partial5,7,EFalse); |
|
2091 |
res=TestPartialEntry(partial5); |
|
2092 |
test(res); |
|
2093 |
r=TheFs.Delete(longFile); |
|
123 | 2094 |
test_Value(r, r==KErrNone || r==KErrNotFound); |
0 | 2095 |
r=TheFs.Delete(_L("\\temp")); |
123 | 2096 |
test_Value(r, r==KErrNone || r==KErrNotFound); |
0 | 2097 |
} |
2098 |
ReadDirDisk(dirBuf); |
|
2099 |
||
2100 |
test.End(); |
|
2101 |
} |
|
2102 |
||
2103 |
LOCAL_C void DoMatchingEntries() |
|
2104 |
// |
|
2105 |
// Tests that scandrive detects/corrects entries with the same start cluster |
|
2106 |
// Copies entry to new location - replicates start cluster |
|
2107 |
// |
|
2108 |
{ |
|
2109 |
test.Next(_L("Check matching entries")); |
|
2110 |
TPtr8 fatBuf=FatBufPtr->Des(); |
|
2111 |
TPtr8 dirBuf=DirBufPtr->Des(); |
|
2112 |
ReadDirDisk(dirBuf); |
|
2113 |
ReadFatDisk(fatBuf); |
|
2114 |
||
2115 |
// first entry in \scndrv\almostfull\ + root dir |
|
2116 |
test.Start(_L("matching entries in subdir + root dir")); |
|
2117 |
TEntryInfo from1(ClusterEntryToBytes(gClusterDir2_AFull,2),6); |
|
2118 |
TEntryInfo to1(ClusterEntryToBytes(gClusterRootDir,2),6); |
|
2119 |
CreateMatchingEntry(to1,from1,EFalse); |
|
2120 |
TBool res=TestMatchingEntry(to1); |
|
2121 |
test(res); |
|
2122 |
||
2123 |
// matching entries between 2 subdirs, one which has a full cluster |
|
271 | 2124 |
// first entry in \scndrv\dir2\full\ + end of \scndrv\dir2\almostfull |
0 | 2125 |
test.Next(_L("matching entries between 2 subdirs")); |
2126 |
TEntryInfo from2(ClusterEntryToBytes(gClusterDir2_Full,2),2); |
|
2127 |
TEntryInfo to2(ClusterEntryToBytes(gClusterDir2_AFull,14),2); |
|
2128 |
CreateMatchingEntry(to2,from2,EFalse); |
|
2129 |
res=TestMatchingEntry(to2); |
|
2130 |
test(res); |
|
2131 |
||
2132 |
// matching entries between two subdirs - one with end of dir marker next |
|
271 | 2133 |
// \scndrv\dir2\somedirwith3entries to \scndrv |
0 | 2134 |
test.Next(_L("matching entries between two subdirs")); |
2135 |
TEntryInfo from3(ClusterEntryToBytes(gClusterDir2,4),3); |
|
2136 |
TEntryInfo to3(ClusterEntryToBytes(gClusterScnDrv,6),3); |
|
2137 |
CreateMatchingEntry(to3,from3,ETrue); |
|
2138 |
res=TestMatchingEntry(to3); |
|
2139 |
test(res); |
|
2140 |
||
2141 |
// matching entries in same subdir, one in new cluster - irrelevant if matching names |
|
271 | 2142 |
// 1st and last entries in \scndrv\dir2\full |
0 | 2143 |
test.Next(_L("matching entries in same subdir")); |
2144 |
// delete entries to allow contiguous clusters in \scndrv\dir2\full directory |
|
2145 |
TInt r=TheFs.RmDir(_L("\\scndrv\\dir2\\somedirwith3entries\\")); |
|
123 | 2146 |
test_KErrNone(r); |
0 | 2147 |
r=TheFs.RmDir(_L("\\scndrv\\dir2\\somedir2with3entries\\")); |
123 | 2148 |
test_KErrNone(r); |
0 | 2149 |
// ensure directory is expanded |
2150 |
RFile temp; |
|
2151 |
r=temp.Create(TheFs,_L("\\scndrv\\dir2\\full\\temp"),EFileShareAny); |
|
123 | 2152 |
test_KErrNone(r); |
0 | 2153 |
temp.Close(); |
2154 |
r=TheFs.Delete(_L("\\scndrv\\dir2\\full\\temp")); |
|
123 | 2155 |
test_KErrNone(r); |
0 | 2156 |
ReadDirDisk(dirBuf); |
2157 |
ReadFatDisk(fatBuf); |
|
2158 |
TEntryInfo from4(ClusterEntryToBytes(gClusterDir2_Full,4),2); |
|
2159 |
TEntryInfo to4(ClusterEntryToBytes(gClusterDir2_Full+1,0),2); |
|
2160 |
CreateMatchingEntry(to4,from4,ETrue); |
|
2161 |
res=TestMatchingEntry(to4); |
|
2162 |
test(res); |
|
2163 |
||
271 | 2164 |
// \scndrv\dir1\very long name to \\scndrv\dir2\full |
0 | 2165 |
test.Next(_L("matching entries in diff dirs + new cluster")); |
2166 |
// delete last entry in directory |
|
2167 |
r=TheFs.Delete(LastInFull); |
|
123 | 2168 |
test_KErrNone(r); |
0 | 2169 |
TFileName veryLongName=_L("\\scndrv\\dir2\\full\\"); |
2170 |
MakeVeryLongName(veryLongName); |
|
2171 |
r=temp.Create(TheFs,veryLongName,EFileShareAny); |
|
123 | 2172 |
test_KErrNone(r); |
0 | 2173 |
temp.Close(); |
2174 |
r=TheFs.Delete(veryLongName); |
|
123 | 2175 |
test_KErrNone(r); |
0 | 2176 |
ReadDirDisk(dirBuf); |
2177 |
ReadFatDisk(fatBuf); |
|
2178 |
TEntryInfo from5(ClusterEntryToBytes(gClusterDir1,2),19); |
|
2179 |
TEntryInfo to5(ClusterEntryToBytes(gClusterDir2_Full,gEntriesPerCluster-2),19); |
|
2180 |
CreateMatchingEntry(to5,from5,EFalse); |
|
2181 |
res=TestMatchingEntry(to5); |
|
2182 |
test(res); |
|
2183 |
||
2184 |
test.End(); |
|
2185 |
} |
|
2186 |
||
2187 |
||
2188 |
LOCAL_C void DoMaxDepth() |
|
2189 |
// |
|
2190 |
// Test directory structure with max possible depth |
|
2191 |
// |
|
2192 |
{ |
|
2193 |
test.Next(_L("Check max directory depth")); |
|
2194 |
test.Start(_L("Using single character names")); |
|
2195 |
TPtr8 fatBuf=FatBufPtr->Des(); |
|
2196 |
TPtr8 dirBuf=DirBufPtr->Des(); |
|
2197 |
// Create dir structure |
|
2198 |
TFileName dir1=_L("\\"); |
|
2199 |
TFileName dir2; |
|
2200 |
CreateMaxDepthDir(dir1,dir2); |
|
2201 |
ReadDirDisk(dirBuf); |
|
2202 |
ReadFatDisk(fatBuf); |
|
2203 |
// run scandisk and compare |
|
2204 |
TInt r=TheFs.ScanDrive(gSessionPath); |
|
123 | 2205 |
test_KErrNone(r); |
0 | 2206 |
TBool res=IsSameAsDrive(fatBuf,dirBuf); |
2207 |
test(res); |
|
2208 |
// Create a entry with matching start cluster and check fixed up |
|
2209 |
TEntryInfo from(ClusterEntryToBytes(gClusterDir2_AFull,2),6); |
|
2210 |
TEntryInfo to(ClusterEntryToBytes(gClusterEndMaxDepth,2),6); |
|
2211 |
CreateMatchingEntry(to,from,ETrue); |
|
2212 |
res=TestMatchingEntry(to); |
|
2213 |
test(res); |
|
2214 |
// DeleteMaxDepthStructure |
|
2215 |
DeleteMaxDepthDir(dir1,dir2); |
|
2216 |
test.End(); |
|
2217 |
} |
|
2218 |
||
2219 |
LOCAL_C void DoRootDir() |
|
2220 |
// |
|
2221 |
// Check that a full root directory is searched OK |
|
2222 |
// |
|
2223 |
{ |
|
2224 |
test.Next(_L("Check a full root directory")); |
|
2225 |
FillUpRootDir(); |
|
2226 |
TPtr8 fatBuf=FatBufPtr->Des(); |
|
2227 |
TPtr8 dirBuf=DirBufPtr->Des(); |
|
2228 |
ReadDirDisk(dirBuf); |
|
2229 |
ReadFatDisk(fatBuf); |
|
2230 |
||
2231 |
TInt r=TheFs.ScanDrive(gSessionPath); |
|
123 | 2232 |
test_KErrNone(r); |
0 | 2233 |
|
2234 |
TBool res=IsSameAsDrive(fatBuf,dirBuf); |
|
2235 |
test(res); |
|
2236 |
UnFillUpRootDir(); |
|
2237 |
} |
|
2238 |
||
2239 |
LOCAL_C void TestNonVfatNames(const TPtrC& aDirName, TInt aDirCluster, TInt aEntry=2) |
|
2240 |
// |
|
2241 |
// Check that files without 'long' entries are kept intact. Creates files with |
|
2242 |
// a DOS type name, and for each one created except the last deletes the VFAT |
|
2243 |
// entry by copying the DOS entry over it and writing end of directory. This |
|
2244 |
// leaves a VFAT entry at the end of the directory, except when there is only |
|
2245 |
// room for one file. |
|
2246 |
// |
|
2247 |
// The layout, for 1 sector per cluster, is thus like: |
|
2248 |
// 0 . |
|
2249 |
// 1 .. |
|
2250 |
// 2 TEMPFILE.000 |
|
2251 |
// 3 TEMPFILE.001 |
|
2252 |
// ... |
|
2253 |
// 14 tempfile.012 VFAT |
|
2254 |
// 15 TEMPFILE.012 |
|
2255 |
// |
|
2256 |
// or for an almost full directory |
|
2257 |
// |
|
2258 |
// 0 . |
|
2259 |
// 1 .. |
|
2260 |
// whatever... |
|
2261 |
// 14 TEMPFILE.000 |
|
2262 |
// 15 end of directory |
|
2263 |
// |
|
2264 |
{ |
|
2265 |
test.Printf(_L("Test cluster %2d, aEntry %d: %S\n"), aDirCluster, aEntry, &aDirName); |
|
2266 |
TPtr8 fatBuf=FatBufPtr->Des(); |
|
2267 |
TPtr8 dirBuf=DirBufPtr->Des(); |
|
2268 |
TInt cluster = aDirCluster; |
|
2269 |
||
2270 |
TInt maxEntry = gEntriesPerCluster; |
|
2271 |
if (aDirName.Compare(_L("\\")) == KErrNone) |
|
2272 |
maxEntry = Min(gRootDirEntries, gEntriesPerCluster); |
|
2273 |
||
2274 |
TInt entry = aEntry; |
|
2275 |
TInt r = KErrNone; |
|
2276 |
TInt i; |
|
2277 |
||
2278 |
while (entry > gEntriesPerCluster) |
|
2279 |
{ |
|
2280 |
entry -= gEntriesPerCluster; |
|
2281 |
cluster++; |
|
2282 |
} |
|
2283 |
||
2284 |
TInt nFiles = maxEntry - entry - 1; |
|
2285 |
TInt startEntry = entry; |
|
2286 |
||
2287 |
test.Printf(_L("cluster %d, entry %d maxEntry %d, nFiles %d\n"), cluster, entry, maxEntry, nFiles); |
|
2288 |
||
2289 |
TBuf8<256> buf; |
|
2290 |
buf.Fill('*', 256); |
|
2291 |
||
2292 |
// Set up files, ignoring used slots |
|
2293 |
TInt filesThisTime = nFiles; |
|
2294 |
TInt totalFilesCreated = 0; |
|
2295 |
FOREVER |
|
2296 |
{ |
|
2297 |
// |
|
2298 |
// Create a number of VFat entries |
|
2299 |
// |
|
2300 |
// - We create as many as we can fit in the cluster in one go. |
|
2301 |
// This is faster than creating a single entry then copying, as writing the |
|
2302 |
// entries one at a time using RRawDisk causes a remount of the file system, |
|
2303 |
// which can take a very long time on a large disk. |
|
2304 |
// |
|
2305 |
filesThisTime = (nFiles - totalFilesCreated) >> 1; |
|
2306 |
if(filesThisTime == 0) |
|
2307 |
{ |
|
2308 |
if(nFiles == totalFilesCreated) |
|
2309 |
{ |
|
2310 |
test.Printf(_L("Created all Non-VFAT entries\n")); |
|
2311 |
break; |
|
2312 |
} |
|
2313 |
||
2314 |
//...creating the final entry |
|
2315 |
filesThisTime = 1; |
|
2316 |
} |
|
2317 |
||
2318 |
for (i = 0; i < filesThisTime; i++) |
|
2319 |
{ |
|
2320 |
TFileName name(aDirName); |
|
2321 |
name.Append(_L("tempfile.")); |
|
2322 |
name.AppendNumFixedWidth(i+totalFilesCreated, EHex, 3); |
|
2323 |
RFile f; |
|
2324 |
r = f.Create(TheFs, name, EFileShareAny); |
|
123 | 2325 |
test_KErrNone(r); |
0 | 2326 |
r = f.Write(buf); |
123 | 2327 |
test_KErrNone(r); |
0 | 2328 |
f.Close(); |
2329 |
} |
|
2330 |
||
2331 |
// |
|
2332 |
// Move DOS FAT entries up using RRawDisk, deleting the original VFAT entries |
|
2333 |
// |
|
2334 |
ReadDirDisk(dirBuf, cluster); |
|
2335 |
TInt dosEntry = entry + 1; |
|
2336 |
for (i = 0; i < filesThisTime; i++) |
|
2337 |
{ |
|
2338 |
// Copy VFAT to Non-VFAT entries |
|
2339 |
if (entry+2 < maxEntry || nFiles < 2) |
|
2340 |
{ |
|
2341 |
TInt posVFAT = ClusterEntryToBytes(cluster, entry); |
|
2342 |
TInt posEOD = ClusterEntryToBytes(cluster, entry+1); |
|
2343 |
TInt posDOS = ClusterEntryToBytes(cluster, dosEntry); |
|
2344 |
||
2345 |
WriteCopyDir(posDOS, posVFAT); // Copy the DOS entry |
|
2346 |
WriteDelete(posDOS,2); // Delete the original entry |
|
2347 |
WriteEndOfDir(posEOD); // Write End Of Directory |
|
2348 |
||
2349 |
entry += 1; |
|
2350 |
dosEntry += 2; |
|
2351 |
} |
|
2352 |
else |
|
2353 |
{ |
|
2354 |
// last entry has VFAT intact, to fill cluster |
|
2355 |
entry += 2; |
|
2356 |
} |
|
2357 |
||
2358 |
} |
|
2359 |
||
123 | 2360 |
WriteDirEntryToDisk(dirBuf, cluster); |
0 | 2361 |
totalFilesCreated += filesThisTime; |
2362 |
test.Printf(_L(" created %d entries\n"), totalFilesCreated); |
|
2363 |
} |
|
2364 |
||
2365 |
ReadDirDisk(dirBuf); |
|
2366 |
ReadFatDisk(fatBuf); |
|
2367 |
||
2368 |
DumpData(NULL, aDirCluster, cluster+1); |
|
2369 |
||
2370 |
test.Printf(_L("Running ScanDrive\n"), filesThisTime); |
|
2371 |
r=TheFs.ScanDrive(gSessionPath); |
|
123 | 2372 |
test_KErrNone(r); |
0 | 2373 |
|
2374 |
TBool res=IsSameAsDrive(fatBuf,dirBuf); |
|
2375 |
test(res); |
|
2376 |
||
2377 |
test.Printf(_L("Deleting %d files\n"), nFiles); |
|
2378 |
for (i = 0; i < nFiles; i++) |
|
2379 |
{ |
|
2380 |
TFileName name(aDirName); |
|
2381 |
name.Append(_L("tempfile.")); |
|
2382 |
name.AppendNumFixedWidth(i, EHex, 3); |
|
2383 |
r = TheFs.Delete(name); |
|
123 | 2384 |
test_KErrNone(r); |
0 | 2385 |
} |
2386 |
||
2387 |
ReadDirDisk(dirBuf); |
|
2388 |
ReadFatDisk(fatBuf); |
|
2389 |
WriteEndOfDir(ClusterEntryToBytes(cluster, startEntry)); |
|
123 | 2390 |
WriteDirEntryToDisk(dirBuf); |
0 | 2391 |
|
2392 |
test.Printf(_L("Running ScanDrive\n"), filesThisTime); |
|
2393 |
r=TheFs.ScanDrive(gSessionPath); |
|
123 | 2394 |
test_KErrNone(r); |
0 | 2395 |
res=IsSameAsDrive(fatBuf,dirBuf); |
2396 |
test(res); |
|
2397 |
} |
|
2398 |
||
2399 |
LOCAL_C void DoNonVfatNames() |
|
2400 |
// |
|
2401 |
// Check that files without 'long' entries are kept intact |
|
2402 |
// |
|
2403 |
{ |
|
2404 |
test.Next(_L("Check non-VFAT file names")); |
|
2405 |
TestNonVfatNames(_L("\\"), gClusterRootDir, 2); |
|
2406 |
TestNonVfatNames(_L("\\scndrv\\dir1\\"), gClusterDir1, 2+19); |
|
2407 |
TestNonVfatNames(_L("\\scndrv\\dir2\\somedirwith3entries\\"), gClusterDir2_SD3E, 2); |
|
2408 |
TestNonVfatNames(_L("\\scndrv\\dir2\\almostfull\\"), gClusterDir2_AFull, 14); |
|
2409 |
} |
|
2410 |
||
2411 |
||
2412 |
LOCAL_C void DoTests() |
|
2413 |
{ |
|
2414 |
||
2415 |
Format(); |
|
2416 |
DoReadBootSector(); |
|
2417 |
DumpBootSector(); |
|
2418 |
InitialiseBuffers(); |
|
2419 |
CreateRootDir(); |
|
2420 |
CreateDirectoryStructure(); |
|
2421 |
TPtr8 fatBuf=FatBufPtr->Des(); |
|
2422 |
TPtr8 dirBuf=DirBufPtr->Des(); |
|
2423 |
ReadDirDisk(dirBuf); |
|
2424 |
ReadFatDisk(fatBuf); |
|
2425 |
DumpFat(); |
|
2426 |
DumpData(NULL, DirBufPtr->Ptr()); |
|
2427 |
||
2428 |
DoNonVfatNames(); |
|
2429 |
DoRootDir(); |
|
2430 |
DoMaxDepth(); |
|
2431 |
DoMatchingEntries(); |
|
2432 |
DoPartEntries(); |
|
2433 |
DoLostClusters(); |
|
2434 |
DoHangingClusters(); |
|
123 | 2435 |
DoHangingAndLostClusters(); |
0 | 2436 |
TestMountAndScan(); |
2437 |
TestConsecutiveMountAndScans(); |
|
2438 |
DeleteDirectoryStructure(); |
|
2439 |
DeleteRootDir(); |
|
2440 |
TestExtendedChars(); |
|
2441 |
||
2442 |
DumpBootSector(); |
|
2443 |
DumpFat(); |
|
2444 |
DumpData(NULL, 0, 200); |
|
2445 |
||
2446 |
delete FatDiskPtr; |
|
2447 |
delete DirDiskPtr; |
|
2448 |
delete FatBufPtr; |
|
2449 |
delete DirBufPtr; |
|
2450 |
} |
|
2451 |
||
2452 |
||
2453 |
void CallTestsL() |
|
2454 |
{ |
|
2455 |
TInt r; |
|
2456 |
r = TheFs.CharToDrive(gSessionPath[0], gDriveNumber); |
|
123 | 2457 |
test_KErrNone(r); |
0 | 2458 |
|
2459 |
||
2460 |
//-- set up console output |
|
2461 |
Fat_Test_Utils::SetConsole(test.Console()); |
|
2462 |
||
2463 |
//-- print drive information |
|
2464 |
PrintDrvInfo(TheFs, gDriveNumber); |
|
2465 |
||
2466 |
if (!Is_Fat(TheFs, gDriveNumber)) |
|
2467 |
{ |
|
2468 |
test.Printf(_L("CallTestsL: Skipped: test requires FAT filesystem\n")); |
|
2469 |
return; |
|
2470 |
} |
|
2471 |
||
2472 |
// check this is not the internal ram drive |
|
2473 |
TVolumeInfo v; |
|
2474 |
r=TheFs.Volume(v); |
|
123 | 2475 |
test_KErrNone(r); |
0 | 2476 |
if(v.iDrive.iMediaAtt&KMediaAttVariableSize) |
2477 |
{ |
|
2478 |
test.Printf(_L("Error: Internal ram drive not tested\n")); |
|
2479 |
return; |
|
2480 |
} |
|
2481 |
||
2482 |
r=TheFs.SetSessionPath(gSessionPath); |
|
123 | 2483 |
test_KErrNone(r); |
0 | 2484 |
|
2485 |
DoTests(); |
|
2486 |
||
2487 |
return; |
|
2488 |
} |
|
2489 |
||
2490 |
||
2491 |
||
2492 |
||
2493 |
||
2494 |