author | hgs |
Thu, 10 Jun 2010 11:48:01 +0100 | |
changeset 149 | d9f1e5bfe28c |
parent 90 | 947f0dc9f7a8 |
child 210 | b592f7984442 |
child 257 | 3e88ff8f41d5 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1996-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\b_fat32.cpp |
|
15 |
// |
|
16 |
// |
|
17 |
||
149 | 18 |
#define __E32TEST_EXTENSION__ |
0 | 19 |
#include <f32file.h> |
20 |
#include <e32test.h> |
|
21 |
#include <e32math.h> |
|
22 |
||
23 |
#include "fat_utils.h" |
|
24 |
#include "t_server.h" |
|
25 |
||
26 |
using namespace Fat_Test_Utils; |
|
27 |
||
28 |
||
29 |
RTest test(_L("B_FAT32")); |
|
30 |
||
31 |
static RRawDisk TheDisk; |
|
32 |
static RFile TheFile; |
|
33 |
static RDir TheDir; |
|
34 |
static TEntry TheEntry; |
|
35 |
static TFileName TheFileName; |
|
36 |
static TBuf<16> TheDrive; |
|
37 |
||
38 |
static HBufC8* pBuffer1=NULL; |
|
39 |
static HBufC8* pBuffer2=NULL; |
|
40 |
static TBuf8<0x800> TheBuffer; |
|
41 |
static TEntry TheFileInfo; |
|
42 |
static TVolumeInfo TheVolumeInfo; |
|
43 |
static TBuf<8> ThePddName; |
|
44 |
static TFatBootSector TheBootSector; |
|
45 |
||
46 |
static TInt64 rndSeed; |
|
47 |
static TFatType gDiskType = EInvalid; |
|
48 |
||
49 |
static TInt gFatBits = 0; |
|
50 |
static TInt gBytesPerCluster; |
|
51 |
static TInt gEntriesPerCluster; |
|
52 |
static TInt gDataStartBytes; |
|
53 |
static TInt gRootDirSectors; |
|
54 |
static TInt gTotalSectors; |
|
55 |
static TInt gRootDirStart; |
|
56 |
static TInt gRootSector; |
|
57 |
static TInt gRootCluster; |
|
58 |
static TInt gFatTestEntries; |
|
59 |
static TInt gFatSizeSectors; |
|
60 |
static TInt gFirstDataSector; |
|
61 |
static TInt gFirstDataCluster; |
|
62 |
static TInt gClusterCount; |
|
63 |
static TInt gEndOfChain; // for FAT12/16/32 |
|
64 |
||
65 |
const TInt KMaxFatEntries = 2048; |
|
66 |
const TInt KMaxFatSize = KMaxFatEntries * 4; |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
67 |
|
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
68 |
const TUint KDirAttrReadOnly = 0x01; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
69 |
const TUint KDirAttrHidden = 0x02; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
70 |
const TUint KDirAttrSystem = 0x04; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
71 |
const TUint KDirAttrVolumeId = 0x08; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
72 |
const TUint KDirAttrDirectory = 0x10; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
73 |
const TUint KDirAttrArchive = 0x20; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
74 |
const TUint KDirAttrLongName = KDirAttrReadOnly | KDirAttrHidden | KDirAttrSystem | KDirAttrVolumeId; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
75 |
const TUint KDirAttrLongMask = KDirAttrLongName | KDirAttrDirectory | KDirAttrArchive; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
76 |
const TUint KDirLastLongEntry = 0x40; |
0 | 77 |
|
78 |
void CreateFatEntry(const TDesC& aDir, TBool aVFatEntry, TDes *apFileName=NULL); |
|
79 |
||
80 |
#define Error(aMess,aErr) PutError(__FILE__, __LINE__, aMess,aErr) |
|
81 |
static void PutError(const char* aFile, TInt aLine, const TDesC& aMessage,TInt anErr) |
|
82 |
{ |
|
83 |
TFileName buf; |
|
84 |
TPtrC8 ptr((const TUint8*)aFile); |
|
85 |
buf.Copy(ptr); |
|
86 |
test.Printf(_L("%S failed - %d\n"), &aMessage,anErr); |
|
87 |
test.Printf(_L("In %S line %d\n"), &buf, aLine); |
|
88 |
test(0); |
|
89 |
} |
|
90 |
||
91 |
||
92 |
// |
|
93 |
// Position calculation and disk reading routines |
|
94 |
// Return number of bytes into the FAT |
|
95 |
static TInt PosInBytes(TInt aFatIndex) |
|
96 |
{ |
|
97 |
TInt fatPosInBytes = -1; |
|
98 |
switch (gDiskType) |
|
99 |
{ |
|
100 |
case EFat32: |
|
101 |
fatPosInBytes=aFatIndex<<2; |
|
102 |
break; |
|
103 |
case EFat16: |
|
104 |
fatPosInBytes=aFatIndex<<1; |
|
105 |
break; |
|
106 |
case EFat12: |
|
107 |
fatPosInBytes=(aFatIndex*3>>1); |
|
108 |
break; |
|
109 |
default: |
|
110 |
test(0); |
|
111 |
} |
|
112 |
return(fatPosInBytes); |
|
113 |
} |
|
114 |
||
115 |
static TUint32 MaxClusters() |
|
116 |
// |
|
117 |
// Return the number of data clusters on the disk |
|
118 |
// |
|
119 |
{ |
|
120 |
TUint32 totSec = (TheBootSector.TotalSectors() ? TheBootSector.TotalSectors() : TheBootSector.HugeSectors()); |
|
121 |
TUint32 numSec = totSec - gFirstDataSector; |
|
122 |
return numSec / TheBootSector.SectorsPerCluster(); |
|
123 |
} |
|
124 |
||
125 |
static TInt ClusterToByte(TInt aCluster) |
|
126 |
// |
|
127 |
// converts cluster number to byte offset on disk |
|
128 |
// |
|
129 |
{ |
|
130 |
if (aCluster < 2) |
|
131 |
return gRootDirStart; |
|
132 |
TInt sector = (aCluster - 2) * gBytesPerCluster + gFirstDataSector * TheBootSector.BytesPerSector(); |
|
133 |
return sector; |
|
134 |
} |
|
135 |
||
136 |
TUint32 GetFatEntry(TUint32 aIndex, const TUint8* aFat=NULL) |
|
137 |
// |
|
138 |
// Read a single FAT entry from disk or FAT copy and return it |
|
139 |
// |
|
140 |
{ |
|
141 |
TInt pos = PosInBytes(aIndex); |
|
142 |
||
143 |
TUint8 data[4]; |
|
144 |
TUint8* ptr = data; |
|
145 |
||
146 |
if (aFat) |
|
147 |
ptr = (TUint8*)aFat + pos; |
|
148 |
else |
|
149 |
{ |
|
150 |
pos += TheBootSector.ReservedSectors() * TheBootSector.BytesPerSector(); |
|
151 |
TInt r=TheDisk.Open(TheFs,gSessionPath[0]-'A'); |
|
149 | 152 |
test_KErrNone(r); |
0 | 153 |
TPtr8 buf(&data[0], 4); |
154 |
r=TheDisk.Read(pos, buf); |
|
149 | 155 |
test_KErrNone(r); |
0 | 156 |
TheDisk.Close(); |
157 |
} |
|
158 |
||
159 |
TUint32 val = 0; |
|
160 |
switch (gDiskType) |
|
161 |
{ |
|
162 |
case EFat32: |
|
163 |
val = *(TUint32*)ptr; |
|
164 |
break; |
|
165 |
case EFat16: |
|
166 |
val = *(TUint16*)ptr; |
|
167 |
break; |
|
168 |
case EFat12: |
|
169 |
val = *(TUint16*)ptr; |
|
170 |
if (aIndex & 1) |
|
171 |
val >>= 4; |
|
172 |
val &= 0xFFF; |
|
173 |
break; |
|
174 |
default: |
|
175 |
test(0); |
|
176 |
} |
|
177 |
return val; |
|
178 |
} |
|
179 |
||
180 |
void MarkFatEntry(TUint32 aIndex) |
|
181 |
// |
|
182 |
// Marks a single FAT entry by modifying it's top 4 bits to |
|
183 |
// |
|
184 |
{ |
|
185 |
TInt pos = PosInBytes(aIndex); |
|
186 |
pos += TheBootSector.ReservedSectors() * TheBootSector.BytesPerSector(); |
|
187 |
||
188 |
TInt r=TheDisk.Open(TheFs,gSessionPath[0]-'A'); |
|
149 | 189 |
test_KErrNone(r); |
0 | 190 |
TUint8 data[4]; |
191 |
TPtr8 buf(&data[0], 4); |
|
192 |
r=TheDisk.Read(pos, buf); |
|
149 | 193 |
test_KErrNone(r); |
0 | 194 |
data[3] &= 0x0F; |
195 |
data[3] |= 0xA0; |
|
196 |
r=TheDisk.Write(pos, buf); |
|
149 | 197 |
test_KErrNone(r); |
0 | 198 |
TheDisk.Close(); |
199 |
} |
|
200 |
||
201 |
void DumpBootSector() |
|
202 |
// |
|
203 |
// Display (in log) TFatBootSector structure |
|
204 |
// |
|
205 |
{ |
|
206 |
RDebug::Print(_L("BytesPerSector = %8d"), TheBootSector.BytesPerSector()); |
|
207 |
RDebug::Print(_L("SectorsPerCluster = %8d (%d bytes)"), |
|
208 |
TheBootSector.SectorsPerCluster(), gBytesPerCluster); |
|
209 |
RDebug::Print(_L("ReservedSectors = %8d"), TheBootSector.ReservedSectors()); |
|
210 |
RDebug::Print(_L("NumberOfFats = %8d"), TheBootSector.NumberOfFats()); |
|
211 |
RDebug::Print(_L("RootDirEntries = %8d"), TheBootSector.RootDirEntries()); |
|
212 |
RDebug::Print(_L("TotalSectors = %8d"), TheBootSector.TotalSectors()); |
|
213 |
RDebug::Print(_L("MediaDescriptor = %8d"), TheBootSector.MediaDescriptor()); |
|
214 |
RDebug::Print(_L("FatSectors = %8d"), TheBootSector.FatSectors()); |
|
215 |
RDebug::Print(_L("SectorsPerTrack = %8d"), TheBootSector.SectorsPerTrack()); |
|
216 |
RDebug::Print(_L("NumberOfHeads = %8d"), TheBootSector.NumberOfHeads()); |
|
217 |
RDebug::Print(_L("HiddenSectors = %8d"), TheBootSector.HiddenSectors()); |
|
218 |
RDebug::Print(_L("HugeSectors = %8d"), TheBootSector.HugeSectors()); |
|
219 |
||
220 |
//New for FAT32 |
|
221 |
||
222 |
if(TheBootSector.RootDirEntries() == 0) //indicates we have FAT32 volume |
|
223 |
{ |
|
224 |
RDebug::Print(_L("FatSectors32 = %8d"), TheBootSector.FatSectors32()); |
|
225 |
RDebug::Print(_L("FATFlags = %8d"), TheBootSector.FATFlags()); |
|
226 |
RDebug::Print(_L("VersionNumber = %8d"), TheBootSector.VersionNumber()); |
|
227 |
RDebug::Print(_L("RootClusterNum = %8d (0x%08X)"), |
|
228 |
TheBootSector.RootClusterNum(), |
|
229 |
gRootDirStart); |
|
230 |
RDebug::Print(_L("FSInfoSectorNum = %8d (0x%08X)"), |
|
231 |
TheBootSector.FSInfoSectorNum(), |
|
232 |
TheBootSector.FSInfoSectorNum() * TheBootSector.BytesPerSector()); |
|
233 |
RDebug::Print(_L("BkBootRecSector = %8d (0x%08X)"), |
|
234 |
TheBootSector.BkBootRecSector(), |
|
235 |
TheBootSector.BkBootRecSector() * TheBootSector.BytesPerSector()); |
|
236 |
} |
|
237 |
||
238 |
TInt fatEntries = gFatSizeSectors*TheBootSector.BytesPerSector(); |
|
239 |
switch (gDiskType) |
|
240 |
{ |
|
241 |
case EFat32: |
|
242 |
fatEntries /= 4; |
|
243 |
break; |
|
244 |
case EFat16: |
|
245 |
fatEntries /= 2; |
|
246 |
break; |
|
247 |
case EFat12: |
|
248 |
fatEntries *= 3; |
|
249 |
fatEntries /= 2; |
|
250 |
break; |
|
251 |
default: |
|
252 |
test(0); |
|
253 |
} |
|
254 |
||
255 |
RDebug::Print(_L("ClusterCount = %8d (%ld bytes)"), gClusterCount, ((TInt64)gClusterCount)*gBytesPerCluster); |
|
256 |
RDebug::Print(_L("FatEntries = %8d (%d sectors)"), fatEntries, gFatSizeSectors); |
|
257 |
RDebug::Print(_L("RootSector = %8d (0x%08X)"), gRootSector, gRootDirStart); |
|
258 |
RDebug::Print(_L("FirstDataSector = %8d (0x%08X)"), gFirstDataSector, gDataStartBytes); |
|
259 |
} |
|
260 |
||
261 |
void DumpFat(const TUint8* aFat=NULL) |
|
262 |
// |
|
263 |
// Dump to the log all those FAT entries which are non-zero |
|
264 |
// |
|
265 |
{ |
|
266 |
TInt32 max = MaxClusters(); |
|
267 |
if (max > KMaxFatEntries) |
|
268 |
max = KMaxFatEntries; |
|
269 |
RDebug::Print(_L("---------------- DUMP OF FAT ---------------")); |
|
270 |
for (TInt32 i = 0; i < max; i++) |
|
271 |
{ |
|
272 |
TInt32 val = GetFatEntry(i, aFat); |
|
273 |
TInt32 msk = 0x0FFFFFFF; |
|
274 |
switch (gDiskType) |
|
275 |
{ |
|
276 |
case EFat32: |
|
277 |
msk = 0x0FFFFFFF; |
|
278 |
break; |
|
279 |
case EFat16: |
|
280 |
msk = 0xFFFF; |
|
281 |
break; |
|
282 |
case EFat12: |
|
283 |
msk = 0x0FFF; |
|
284 |
break; |
|
285 |
default: |
|
286 |
test(0); |
|
287 |
} |
|
288 |
if ((val & msk) == (0x0FFFFFFF & msk)) |
|
289 |
RDebug::Print(_L(" %8d -> EOC"), i); |
|
290 |
else if ((val & msk) == (0x0FFFFFF8 & msk)) |
|
291 |
RDebug::Print(_L(" %8d -> Media"), i); |
|
292 |
else if ((val & msk) == (0x0FFFFFF7 & msk)) |
|
293 |
RDebug::Print(_L(" %8d -> BAD"), i); |
|
294 |
else if (val > max) |
|
295 |
RDebug::Print(_L(" %8d -> 0x%08X"), i, val); |
|
296 |
else if (val != 0) |
|
297 |
RDebug::Print(_L(" %8d -> %d"), i, val); |
|
298 |
} |
|
299 |
RDebug::Print(_L("--------------------------------------------")); |
|
300 |
} |
|
301 |
||
302 |
TDes* DirAttributes(TInt aAttrib) |
|
303 |
// |
|
304 |
// Return a pointer to a local buffer containing the attribute letters. |
|
305 |
// |
|
306 |
{ |
|
307 |
static TBuf<6> str(_L("------")); |
|
308 |
static char* atr = "RHSVDA"; |
|
309 |
for (TInt i = 0; i < 6; i++) |
|
310 |
if ((aAttrib >> i) & 1) |
|
311 |
str[i] = atr[i]; |
|
312 |
return &str; |
|
313 |
} |
|
314 |
||
315 |
TBool IsValidDirChar(TUint8 aChar, TUint8 aMin=0x20) |
|
316 |
// |
|
317 |
// Test whether a character is valid as part of a short filename, aMin is to |
|
318 |
// distinguish between first character (which can't be space) and later ones |
|
319 |
// which can include space but nothing less. Note that E5 is a valid character |
|
320 |
// in any position, even though it means 'erased' in the first character. |
|
321 |
// |
|
322 |
{ |
|
323 |
const TUint8* inval = (TUint8*)"\x22\x2A\x2B\x2C\x2F\x3A\x3B\x3C\x3D\x3E\x3F\x5B\x5C\x5D\x7C"; |
|
324 |
if (aChar < aMin) |
|
325 |
return EFalse; |
|
326 |
for (const TUint8* p = inval; *p; p++) |
|
327 |
if (aChar == *p) |
|
328 |
return EFalse; |
|
329 |
return ETrue; |
|
330 |
} |
|
331 |
||
332 |
TBool IsValidDirEntry(TFatDirEntry* aDir) |
|
333 |
// |
|
334 |
// Test whether buffer is a valid normal directory entry |
|
335 |
// |
|
336 |
{ |
|
337 |
// top two bits of attributes must be zero |
|
338 |
if (aDir->iData[11] & 0xC0) |
|
339 |
return EFalse; |
|
340 |
// first character must be 0x05 or greater than space |
|
341 |
if (!IsValidDirChar(aDir->iData[0], 0x21) && aDir->iData[0] != 0x05) |
|
342 |
return EFalse; |
|
343 |
// other characters in name must be not less than space |
|
344 |
for (TInt i = 1; i < 11; i++) |
|
345 |
if (!IsValidDirChar(aDir->iData[i])) |
|
346 |
return EFalse; |
|
347 |
return ETrue; |
|
348 |
} |
|
349 |
||
350 |
void GetLongNamePart(TDes16& aName, const TUint8* aEntry, TInt aPos, TInt aOffset, TInt aLength) |
|
351 |
// |
|
352 |
// Extract part of a long name entry into the name buffer. |
|
353 |
// |
|
354 |
// @param aName buffer to put name |
|
355 |
// @param aEntry directory entry raw data |
|
356 |
// @param aPos character in buffer to start name segment |
|
357 |
// @param aOffset offset in directory entry of the segment |
|
358 |
// @param aLength number of characters in the segment |
|
359 |
// |
|
360 |
{ |
|
361 |
for (TInt i = 0; i < aLength; i++) |
|
362 |
{ |
|
363 |
TInt at = i * 2 + aOffset; |
|
364 |
TInt ch = aEntry[at] + aEntry[at+1] * 256; |
|
365 |
aName[aPos++] = TText(ch); |
|
366 |
} |
|
367 |
} |
|
368 |
||
369 |
void ExtractNameString(TDes16& aName, const TUint8* aEntry) |
|
370 |
// |
|
371 |
// Extract a long name part from a directory entry, truncate it at the first |
|
372 |
// NUL (0) character and put quotes round it. |
|
373 |
// |
|
374 |
{ |
|
375 |
aName.SetLength(15); |
|
376 |
TInt len = aName.Length() - 1; |
|
377 |
TText qu = '\''; |
|
378 |
aName[0] = qu; |
|
379 |
GetLongNamePart(aName, aEntry, 1, 1, 5); |
|
380 |
GetLongNamePart(aName, aEntry, 6, 14, 6); |
|
381 |
GetLongNamePart(aName, aEntry, 12, 28, 2); |
|
382 |
TInt i; |
|
383 |
for (i = 0; i < len; i++) |
|
384 |
if (aName[i] == 0) |
|
385 |
break; |
|
386 |
aName[i++] = qu; |
|
387 |
aName.SetLength(i); |
|
388 |
} |
|
389 |
||
390 |
TBool DumpDirEntry(TInt aNum, const TUint8* aEntry) |
|
391 |
// |
|
392 |
// Dump a single directory entry to the log. Return false if it was end of |
|
393 |
// directory or an invalid entry (and don't display it). |
|
394 |
// |
|
395 |
{ |
|
396 |
TFatDirEntry* d = (TFatDirEntry*)aEntry; |
|
397 |
if (d->IsErased()) |
|
398 |
{ |
|
399 |
// RDebug::Print(_L("%5d: ERASED"), aNum); |
|
400 |
} |
|
401 |
else if (d->IsEndOfDirectory()) |
|
402 |
{ |
|
403 |
RDebug::Print(_L("%5d: END-OF-DIRECTORY"), aNum); |
|
404 |
return EFalse; |
|
405 |
} |
|
406 |
else if ((d->Attributes() & KDirAttrLongMask) == KDirAttrLongName) |
|
407 |
{ |
|
408 |
TBuf16<15> name; |
|
409 |
ExtractNameString(name, aEntry); |
|
410 |
TInt ord = aEntry[0]; |
|
411 |
if (ord & KDirLastLongEntry) |
|
412 |
RDebug::Print(_L("%5d: %-15S #%-2d LAST"), aNum, &name, ord & ~KDirLastLongEntry); |
|
413 |
else |
|
414 |
RDebug::Print(_L("%5d: %-15S #%-2d"), aNum, &name, ord & ~KDirLastLongEntry); |
|
415 |
} |
|
416 |
else if (!IsValidDirEntry(d)) |
|
417 |
{ |
|
418 |
RDebug::Print(_L("%5d: not valid"), aNum); |
|
419 |
return EFalse; |
|
420 |
} |
|
421 |
else |
|
422 |
{ |
|
423 |
TBuf<11> name; |
|
424 |
name.Copy(d->Name()); |
|
425 |
RDebug::Print(_L("%5d: '%S' %S cluster %d"), |
|
426 |
aNum, &name, DirAttributes(d->Attributes()), d->StartCluster()); |
|
427 |
} |
|
428 |
return ETrue; |
|
429 |
} |
|
430 |
||
431 |
void DumpDirCluster(const TUint8* aData, TInt aCluster=0) |
|
432 |
// |
|
433 |
// Dump directory entries until end of cluster or invalid/end entry found. |
|
434 |
// |
|
435 |
{ |
|
436 |
if (aCluster > 2) |
|
437 |
aData += (aCluster-2) * gBytesPerCluster; |
|
438 |
for (TInt i = 0; i < gBytesPerCluster; i += KSizeOfFatDirEntry) |
|
439 |
{ |
|
440 |
if (DumpDirEntry(i/KSizeOfFatDirEntry, aData)) |
|
441 |
aData += KSizeOfFatDirEntry; |
|
442 |
else |
|
443 |
break; |
|
444 |
} |
|
445 |
} |
|
446 |
||
447 |
void DumpData(const TUint8* aFat, TInt aStart, TInt aEnd=-1) |
|
448 |
// |
|
449 |
// Dump clusters from disk (allows dumping of clusters not in our buffers). |
|
450 |
// Only look at clusters marked as 'used' in the FAT. Note that if aFat is |
|
451 |
// NULL the FAT entries will also be read from disk (slower but allows for ones |
|
452 |
// outside our copy in memory). |
|
453 |
// |
|
454 |
{ |
|
455 |
if (aStart > gFatTestEntries) |
|
456 |
return; |
|
457 |
if (aEnd > gFatTestEntries) |
|
458 |
aEnd = gFatTestEntries; |
|
459 |
if (aEnd <= 0) |
|
460 |
aEnd = aStart + 1; |
|
461 |
RDebug::Print(_L("--------------- DATA AREA ------------------")); |
|
462 |
if (aEnd > gFatTestEntries) |
|
463 |
aEnd = gFatTestEntries; |
|
464 |
for (TInt cluster = aStart; cluster < aEnd; cluster++) |
|
465 |
{ |
|
466 |
if (GetFatEntry(cluster, aFat) != 0) |
|
467 |
{ |
|
468 |
HBufC8* buf=HBufC8::New(gBytesPerCluster); |
|
469 |
test(buf!=NULL); |
|
470 |
TPtr8 ptr=buf->Des(); |
|
471 |
TInt r=TheDisk.Open(TheFs,gSessionPath[0]-'A'); |
|
149 | 472 |
test_KErrNone(r); |
0 | 473 |
r=TheDisk.Read(ClusterToByte(cluster), ptr); |
149 | 474 |
test_KErrNone(r); |
0 | 475 |
TheDisk.Close(); |
476 |
RDebug::Print(_L("Cluster %d @ 0x%08X:"), cluster, ClusterToByte(cluster)); |
|
477 |
DumpDirCluster(ptr.Ptr()); |
|
478 |
delete buf; |
|
479 |
} |
|
480 |
} |
|
481 |
RDebug::Print(_L("--------------------------------------------")); |
|
482 |
} |
|
483 |
||
484 |
void DumpData(TInt aStart=0, TInt aEnd=0) |
|
485 |
// |
|
486 |
// Dump clusters from disk (allows dumping of clusters not in our buffers). |
|
487 |
// Only look at clusters marked as 'used' in the FAT. Note that if aFat is |
|
488 |
// NULL the FAT entries will also be read from disk (slower but allows for ones |
|
489 |
// outside our copy in memory). |
|
490 |
// |
|
491 |
{ |
|
492 |
if (aStart == 0) |
|
493 |
{ |
|
494 |
if (aEnd <= 0) |
|
495 |
aEnd = 1; |
|
496 |
TInt num = (gDiskType == EFat32 ? aEnd*gEntriesPerCluster : TheBootSector.RootDirEntries()); |
|
497 |
TInt pos = gRootDirStart; |
|
498 |
TInt ent = 0; |
|
499 |
HBufC8* buf=HBufC8::New(KSizeOfFatDirEntry); |
|
500 |
test(buf!=NULL); |
|
501 |
TPtr8 ptr=buf->Des(); |
|
502 |
TInt r=TheDisk.Open(TheFs,gSessionPath[0]-'A'); |
|
149 | 503 |
test_KErrNone(r); |
0 | 504 |
RDebug::Print(_L("--------------- ROOT DIR ------------------")); |
505 |
for (TInt i = 0; i < num; i++) |
|
506 |
{ |
|
507 |
r=TheDisk.Read(pos, ptr); |
|
149 | 508 |
test_KErrNone(r); |
0 | 509 |
if (!DumpDirEntry(ent, ptr.Ptr())) |
510 |
break; |
|
511 |
pos += KSizeOfFatDirEntry; |
|
512 |
} |
|
513 |
RDebug::Print(_L("-------------------------------------------")); |
|
514 |
TheDisk.Close(); |
|
515 |
delete buf; |
|
516 |
} |
|
517 |
else if (aStart == 1) |
|
518 |
{ |
|
519 |
DumpData(0, 1); |
|
520 |
DumpData(NULL, gFirstDataCluster, aEnd); |
|
521 |
} |
|
522 |
else |
|
523 |
{ |
|
524 |
DumpData(NULL, aStart, aEnd); |
|
525 |
} |
|
526 |
} |
|
527 |
||
528 |
void DumpHex(const TUint8* aData, TInt aLen) |
|
529 |
// |
|
530 |
// Dump a block of memory to the log in hex. |
|
531 |
// |
|
532 |
{ |
|
533 |
for (TInt base = 0; base < aLen; base += 16) |
|
534 |
{ |
|
535 |
TBuf<16*3> buf; |
|
536 |
TInt off; |
|
537 |
for (off = base; off < aLen && off < base + 16; off++) |
|
538 |
{ |
|
539 |
buf.Append(TText(' ')); |
|
540 |
buf.AppendNumFixedWidth(aData[off], EHex, 2); |
|
541 |
} |
|
542 |
RDebug::Print(_L("%04X: %S"), base, &buf); |
|
543 |
} |
|
544 |
} |
|
545 |
||
546 |
||
547 |
//--------------------------------------------------------------------------------------------------------------- |
|
548 |
||
549 |
static void DoReadBootSector(TFatBootSector& aBootSector) |
|
550 |
{ |
|
551 |
TInt nRes = ReadBootSector(TheFs, CurrentDrive(), KBootSectorNum<<KDefaultSectorLog2, aBootSector); |
|
552 |
test(nRes == KErrNone); |
|
553 |
||
554 |
if(!aBootSector.IsValid()) |
|
555 |
{ |
|
556 |
test.Printf(_L("Wrong bootsector! Dump:\n")); |
|
557 |
aBootSector.PrintDebugInfo(); |
|
558 |
test(0); |
|
559 |
} |
|
560 |
||
561 |
// Calculate derived variables (fixed for a particular disk format) |
|
562 |
||
563 |
if (TheBootSector.FatType() == EFat32) |
|
564 |
{ |
|
565 |
gDiskType = EFat32; |
|
566 |
gFatBits = 32; |
|
567 |
gEndOfChain = 0x0FFFFFFF; |
|
568 |
} |
|
569 |
else if (TheBootSector.FatType() == EFat16) |
|
570 |
{ |
|
571 |
gDiskType = EFat16; |
|
572 |
gFatBits = 16; |
|
573 |
gEndOfChain = 0xFFFF; |
|
574 |
} |
|
575 |
else |
|
576 |
{ |
|
577 |
gDiskType = EFat12; |
|
578 |
gFatBits = 12; |
|
579 |
gEndOfChain = 0x0FFF; |
|
580 |
} |
|
581 |
||
582 |
gBytesPerCluster = TheBootSector.BytesPerSector() * TheBootSector.SectorsPerCluster(); |
|
583 |
gRootDirSectors = ((TheBootSector.RootDirEntries() * KSizeOfFatDirEntry + TheBootSector.BytesPerSector() - 1) / |
|
584 |
TheBootSector.BytesPerSector()); |
|
585 |
gEntriesPerCluster = gBytesPerCluster / KSizeOfFatDirEntry; |
|
586 |
gTotalSectors = (TheBootSector.TotalSectors() ? TheBootSector.TotalSectors() : TheBootSector.HugeSectors()); |
|
587 |
||
588 |
switch (gDiskType) |
|
589 |
{ |
|
590 |
case EFat12: |
|
591 |
case EFat16: |
|
592 |
gFatSizeSectors = TheBootSector.FatSectors(); |
|
593 |
gRootSector = TheBootSector.ReservedSectors() + TheBootSector.NumberOfFats() * gFatSizeSectors; |
|
594 |
gFirstDataSector = gRootSector + gRootDirSectors; |
|
595 |
gRootCluster = 0; |
|
596 |
gFirstDataCluster = 2; |
|
597 |
gDataStartBytes = gFirstDataSector * TheBootSector.BytesPerSector(); |
|
598 |
gRootDirStart = gRootSector * TheBootSector.BytesPerSector(); |
|
599 |
break; |
|
600 |
case EFat32: |
|
601 |
gFatSizeSectors = TheBootSector.FatSectors32(); |
|
602 |
gRootSector = TheBootSector.ReservedSectors() + TheBootSector.NumberOfFats() * gFatSizeSectors; |
|
603 |
gFirstDataSector = gRootSector + gRootDirSectors; |
|
604 |
gRootCluster = 2; |
|
605 |
gFirstDataCluster = 3; |
|
606 |
gDataStartBytes = gFirstDataSector * TheBootSector.BytesPerSector(); |
|
607 |
gRootDirStart = (TheBootSector.RootClusterNum() - 2) * gBytesPerCluster + gDataStartBytes; |
|
608 |
break; |
|
609 |
default: |
|
610 |
break; |
|
611 |
} |
|
612 |
||
613 |
gClusterCount = (gTotalSectors - gFirstDataSector) / TheBootSector.SectorsPerCluster(); |
|
614 |
||
615 |
gFatTestEntries = MaxClusters(); |
|
616 |
if (gFatTestEntries > KMaxFatSize) |
|
617 |
gFatTestEntries = KMaxFatSize; |
|
618 |
} |
|
619 |
||
620 |
||
621 |
static TInt CalcShifts(TInt aSize) |
|
622 |
// |
|
623 |
// Calculate the number of shifts to get >= aSize (aSize should be a power of 2 |
|
624 |
// anyway). |
|
625 |
// |
|
626 |
{ |
|
627 |
TInt x=0; |
|
628 |
while (aSize>>=1) |
|
629 |
x++; |
|
630 |
return(x); |
|
631 |
} |
|
632 |
||
633 |
static TInt SectorShifts() |
|
634 |
// |
|
635 |
// Calculate number of shifts for sector size. |
|
636 |
// |
|
637 |
{ |
|
638 |
return(CalcShifts(TheBootSector.BytesPerSector())); |
|
639 |
} |
|
640 |
||
641 |
static TInt ClusterShifts() |
|
642 |
// |
|
643 |
// Calculate number of shifts for cluster size. |
|
644 |
// |
|
645 |
{ |
|
646 |
return(CalcShifts(TheBootSector.BytesPerSector()*TheBootSector.SectorsPerCluster())); |
|
647 |
} |
|
648 |
||
649 |
||
650 |
// |
|
651 |
// Quick Format the disk |
|
652 |
// |
|
653 |
static void FormatPack() |
|
654 |
{ |
|
655 |
||
656 |
#if 0 |
|
657 |
//-- FAT32 SPC:1; for the FAT32 testing on the emulator |
|
658 |
TFatFormatParam fp; |
|
659 |
fp.iFatType = EFat32; |
|
660 |
fp.iSecPerCluster = 1; |
|
661 |
FormatFatDrive(TheFs, CurrentDrive(), ETrue, &fp); |
|
662 |
#else |
|
663 |
||
664 |
FormatFatDrive(TheFs, CurrentDrive(), ETrue); |
|
665 |
||
666 |
#endif |
|
667 |
||
668 |
DoReadBootSector(TheBootSector); |
|
669 |
||
670 |
} |
|
671 |
||
672 |
||
673 |
||
674 |
static void TestReadWrite(TInt64 aPos,TInt aLen,TInt anErr) |
|
675 |
// |
|
676 |
// Read and write to the disk |
|
677 |
// |
|
678 |
{ |
|
679 |
TPtr8 buffer((TUint8*)pBuffer1->Ptr(),aLen); |
|
680 |
test.Printf(_L("TestReadWrite pos=0x%lx,len=%d\n"),aPos,aLen); |
|
681 |
TInt r; |
|
682 |
if ((r=TheDisk.Read(aPos,buffer))!=anErr) |
|
683 |
{ |
|
684 |
test.Printf(_L("ERROR: anErr=%d ret=%d\n"),anErr,r); |
|
685 |
test(EFalse); |
|
686 |
} |
|
687 |
buffer.SetLength(aLen); |
|
688 |
if ((r=TheDisk.Write(aPos,buffer))!=anErr) |
|
689 |
{ |
|
690 |
test.Printf(_L("ERROR: anErr=%d ret=%d\n"),anErr,r); |
|
691 |
test(EFalse); |
|
692 |
} |
|
693 |
} |
|
694 |
||
695 |
static TInt ReadWriteWord(TInt64 aPos,TInt aMask,TInt aValue) |
|
696 |
// |
|
697 |
// Read 2 bytes from aPos and Write over masked bits with aValue |
|
698 |
// |
|
699 |
{ |
|
700 |
TUint16 word; |
|
701 |
TPtr8 buffer((TUint8*)&word,sizeof(word)); |
|
702 |
||
703 |
TInt r=TheDisk.Read(aPos,buffer); |
|
704 |
if (r!=KErrNone) |
|
705 |
return(r); |
|
706 |
||
707 |
word&=((aValue&aMask)|~aMask); |
|
708 |
word|=(aValue&aMask); |
|
709 |
||
710 |
r=TheDisk.Write(aPos,buffer); |
|
711 |
return(r); |
|
712 |
} |
|
713 |
||
714 |
static TInt ReadWriteDWord(TInt64 aPos,TInt aMask,TInt aValue) |
|
715 |
// |
|
716 |
// Read 4 bytes from aPos and Write over masked bits with aValue |
|
717 |
// |
|
718 |
{ |
|
719 |
TUint32 word; |
|
720 |
TPtr8 buffer((TUint8*)&word,sizeof(word)); |
|
721 |
||
722 |
TInt r=TheDisk.Read(aPos,buffer); |
|
723 |
if (r!=KErrNone) |
|
724 |
return(r); |
|
725 |
||
726 |
word&=((aValue&aMask)|~aMask); |
|
727 |
word|=(aValue&aMask); |
|
728 |
||
729 |
r=TheDisk.Write(aPos,buffer); |
|
730 |
return(r); |
|
731 |
} |
|
732 |
||
733 |
static void FatWrite(TInt aCluster,TInt aValue) |
|
734 |
// |
|
735 |
// |
|
736 |
// |
|
737 |
{ |
|
738 |
TInt pos=0; |
|
739 |
TInt mask=0; |
|
740 |
||
741 |
const TUint32 KFirstFatSectorPos = TheBootSector.FirstFatSector() * TheBootSector.BytesPerSector(); |
|
742 |
||
743 |
switch (gDiskType) |
|
744 |
{ |
|
745 |
case EFat32: |
|
746 |
mask=0xffffffff; |
|
747 |
pos=KFirstFatSectorPos+(aCluster<<2); |
|
748 |
break; |
|
749 |
case EFat16: |
|
750 |
mask=0xffff; |
|
751 |
pos=KFirstFatSectorPos+(aCluster<<1); |
|
752 |
break; |
|
753 |
case EFat12: |
|
754 |
mask=0x0fff; |
|
755 |
pos=KFirstFatSectorPos+aCluster+(aCluster>>1); |
|
756 |
if (aCluster & 1) |
|
757 |
{ |
|
758 |
mask=0xfff0; |
|
759 |
aValue<<=4; |
|
760 |
} |
|
761 |
break; |
|
762 |
default: |
|
763 |
test(0); |
|
764 |
} |
|
765 |
||
766 |
TInt r=TheDisk.Open(TheFs,CurrentDrive()); |
|
149 | 767 |
test_KErrNone(r); |
0 | 768 |
test(ReadWriteDWord(pos,mask,aValue)==KErrNone); |
769 |
TheDisk.Close(); |
|
770 |
} |
|
771 |
||
772 |
static void TestRwWord(TInt64 aPos,TInt anErr) |
|
773 |
// |
|
774 |
// |
|
775 |
// |
|
776 |
{ |
|
777 |
TInt r; |
|
778 |
TUint16 wBuf; |
|
779 |
TUint16 rBuf; |
|
780 |
TUint16 mask=0; |
|
781 |
TUint16 value=0; |
|
782 |
||
783 |
test.Printf(_L("Test read and write value to 0x%lx\n"),aPos); |
|
784 |
||
785 |
if ((r=ReadWriteWord(aPos,mask,value))!=anErr) |
|
786 |
{ |
|
787 |
test.Printf(_L("ERROR: anErr=%d, ret=%d\n"),anErr,r); |
|
788 |
test(EFalse); |
|
789 |
} |
|
790 |
||
791 |
if (anErr==KErrNone && aPos==0) |
|
792 |
{ |
|
793 |
wBuf=0xff00; |
|
794 |
TPtrC8 writebuf((TUint8*)&wBuf,sizeof(wBuf)); |
|
795 |
test(TheDisk.Write(aPos,writebuf)==KErrNone); |
|
796 |
||
797 |
mask=0x0505; |
|
798 |
value=0xa4a4; |
|
799 |
test.Printf(_L("Test RWW mask=%04x value%04x\n"),mask,value); |
|
800 |
if ((r=ReadWriteWord(aPos,mask,value))!=anErr) |
|
801 |
{ |
|
802 |
test.Printf(_L("ERROR: anErr=%d, ret=%d\n"),anErr,r); |
|
803 |
test(EFalse); |
|
804 |
} |
|
805 |
||
806 |
TPtr8 readBuf((TUint8*)&rBuf,sizeof(rBuf)); |
|
807 |
if ((r=TheDisk.Read(aPos,readBuf))!=KErrNone) |
|
808 |
{ |
|
809 |
test.Printf(_L("ERROR: anErr=%d, ret=%d\n"),anErr,r); |
|
810 |
test(EFalse); |
|
811 |
} |
|
812 |
test(rBuf==0xfe04); |
|
813 |
} |
|
814 |
||
815 |
if (anErr==KErrNone && aPos==1) |
|
816 |
{ |
|
817 |
wBuf=0xff00; |
|
818 |
TPtrC8 writebuf((TUint8*)&wBuf,sizeof(wBuf)); |
|
819 |
test(TheDisk.Write(aPos,writebuf)==KErrNone); |
|
820 |
||
821 |
mask=0xffff; |
|
822 |
value=0xa3a3; |
|
823 |
test.Printf(_L("Test RWW mask=%04x value%04x\n"),mask,value); |
|
824 |
if ((r=ReadWriteWord(aPos,mask,value))!=anErr) |
|
825 |
{ |
|
826 |
test.Printf(_L("ERROR: anErr=%d, ret=%d\n"),anErr,r); |
|
827 |
test(EFalse); |
|
828 |
} |
|
829 |
||
830 |
TPtr8 readBuf((TUint8*)&rBuf,sizeof(rBuf)); |
|
831 |
if ((r=TheDisk.Read(aPos,readBuf))!=KErrNone) |
|
832 |
{ |
|
833 |
test.Printf(_L("ERROR: anErr=%d, ret=%d\n"),anErr,r); |
|
834 |
test(EFalse); |
|
835 |
} |
|
836 |
test(rBuf==0xa3a3); |
|
837 |
} |
|
838 |
} |
|
839 |
||
840 |
static void TestRwDWord(TInt64 aPos,TInt anErr) |
|
841 |
// |
|
842 |
// |
|
843 |
// |
|
844 |
{ |
|
845 |
TInt r; |
|
846 |
TUint32 wBuf; |
|
847 |
TUint32 rBuf; |
|
848 |
TUint32 mask=0; |
|
849 |
TUint32 value=0; |
|
850 |
||
851 |
test.Printf(_L("Test read and write value to 0x%lx\n"),aPos); |
|
852 |
||
853 |
if ((r=ReadWriteDWord(aPos,mask,value))!=anErr) |
|
854 |
{ |
|
855 |
test.Printf(_L("ERROR: anErr=%d, ret=%d\n"),anErr,r); |
|
856 |
test(EFalse); |
|
857 |
} |
|
858 |
||
859 |
if (anErr==KErrNone && aPos==0) |
|
860 |
{ |
|
861 |
wBuf=0xff00ff00; |
|
862 |
TPtrC8 writebuf((TUint8*)&wBuf,sizeof(wBuf)); |
|
863 |
test(TheDisk.Write(aPos,writebuf)==KErrNone); |
|
864 |
||
865 |
mask = 0x0505195c; |
|
866 |
value = 0xa4a4c634; |
|
867 |
test.Printf(_L("Test RWW mask=%04x value%04x\n"),mask,value); |
|
868 |
if ((r=ReadWriteDWord(aPos,mask,value))!=anErr) |
|
869 |
{ |
|
870 |
test.Printf(_L("ERROR: anErr=%d, ret=%d\n"),anErr,r); |
|
871 |
test(EFalse); |
|
872 |
} |
|
873 |
||
874 |
TPtr8 readBuf((TUint8*)&rBuf,sizeof(rBuf)); |
|
875 |
if ((r=TheDisk.Read(aPos,readBuf))!=KErrNone) |
|
876 |
{ |
|
877 |
test.Printf(_L("ERROR: anErr=%d, ret=%d\n"),anErr,r); |
|
878 |
test(EFalse); |
|
879 |
} |
|
880 |
test(rBuf==0xfe04e614); |
|
881 |
} |
|
882 |
||
883 |
if (anErr==KErrNone && aPos==1) |
|
884 |
{ |
|
885 |
wBuf=0xff0000ff; |
|
886 |
TPtrC8 writebuf((TUint8*)&wBuf,sizeof(wBuf)); |
|
887 |
test(TheDisk.Write(aPos,writebuf)==KErrNone); |
|
888 |
||
889 |
mask=0xffffffff; |
|
890 |
value=0xa3a3dead; |
|
891 |
test.Printf(_L("Test RWW mask=%04x value%04x\n"),mask,value); |
|
892 |
if ((r=ReadWriteDWord(aPos,mask,value))!=anErr) |
|
893 |
{ |
|
894 |
test.Printf(_L("ERROR: anErr=%d, ret=%d\n"),anErr,r); |
|
895 |
test(EFalse); |
|
896 |
} |
|
897 |
||
898 |
TPtr8 readBuf((TUint8*)&rBuf,sizeof(rBuf)); |
|
899 |
if ((r=TheDisk.Read(aPos,readBuf))!=KErrNone) |
|
900 |
{ |
|
901 |
test.Printf(_L("ERROR: anErr=%d, ret=%d\n"),anErr,r); |
|
902 |
test(EFalse); |
|
903 |
} |
|
904 |
test(rBuf==0xa3a3dead); |
|
905 |
} |
|
906 |
} |
|
907 |
||
908 |
||
909 |
static TInt ThrottleDirEntries(TInt aDirEntries, TInt aRemainder) |
|
910 |
{ |
|
911 |
// throttle the number of entries needed, since for large cluster |
|
912 |
// sizes, this can take forever (eg 2GB card -> a cluster size of 32K |
|
913 |
// -> 1024 entries per cluster |
|
914 |
const TInt KMaxDirEntries = 2048; |
|
915 |
test(aRemainder < KMaxDirEntries); |
|
916 |
TInt maxDirEntries = KMaxDirEntries - aRemainder; |
|
917 |
||
918 |
if (aDirEntries > maxDirEntries) |
|
919 |
{ |
|
920 |
RDebug::Print(_L("Reducing directory entries from %d to %d"), aDirEntries, maxDirEntries); |
|
921 |
aDirEntries = maxDirEntries; |
|
922 |
} |
|
923 |
||
924 |
return aDirEntries; |
|
925 |
} |
|
926 |
||
927 |
static void TestLoopedSubDir() |
|
928 |
// |
|
929 |
// |
|
930 |
{ |
|
931 |
test.Printf(_L("Test looped sub-dir\n")); |
|
932 |
FormatPack(); |
|
933 |
TInt r=TheFs.MkDir(_L("\\D\\")); |
|
934 |
if (r!=KErrNone && r!=KErrAlreadyExists) |
|
935 |
Error(_L("Failed to make directory"),r); |
|
936 |
TheFileName=_L("\\D\\"); |
|
937 |
||
938 |
TInt i=0; |
|
939 |
TInt dirEntriesNeeded = ((TheBootSector.BytesPerSector()*TheBootSector.SectorsPerCluster()/KSizeOfFatDirEntry)-2); |
|
940 |
dirEntriesNeeded = ThrottleDirEntries(dirEntriesNeeded, 2); |
|
941 |
||
942 |
||
943 |
//-- generate some number of VFAT dir. entries by creating 8.3 temp. files in a lower case |
|
944 |
for (i=0;i<dirEntriesNeeded;i++) |
|
945 |
{ |
|
946 |
CreateFatEntry(TheFileName, ETrue); |
|
947 |
} |
|
948 |
||
949 |
test.Printf(_L("Test dir with no match\n")); |
|
950 |
FatWrite(gFirstDataCluster,gFirstDataCluster); |
|
951 |
if ((r=TheDir.Open(TheFs,_L("\\D\\nomatch"),KEntryAttMaskSupported))!=KErrNone) |
|
952 |
Error(_L("Failed Directory open"),r); |
|
953 |
if ((r=TheDir.Read(TheEntry))!=KErrCorrupt) |
|
954 |
Error(_L("Failed Directory read"),r); |
|
955 |
TheDir.Close(); |
|
956 |
||
957 |
test.Printf(_L("Test dir with match\n")); |
|
958 |
if ((r=TheDir.Open(TheFs,_L("\\D\\*.*"),KEntryAttMaskSupported))!=KErrNone) |
|
959 |
Error(_L("Failed Directory open"),r); |
|
960 |
if ((r=TheDir.Read(TheEntry))!=KErrNone) |
|
961 |
Error(_L("Failed Directory read"),r); |
|
962 |
TheDir.Close(); |
|
963 |
||
964 |
test.Printf(_L("Test dir without loop\n")); |
|
965 |
FatWrite(gFirstDataCluster,gEndOfChain); |
|
966 |
if ((r=TheDir.Open(TheFs,_L("\\D\\nomatch"),KEntryAttMaskSupported))!=KErrNone) |
|
967 |
Error(_L("Directory open"),r); |
|
968 |
if ((r=TheDir.Read(TheEntry))!=KErrEof) |
|
969 |
Error(_L("Reading empty dir returned"),r); |
|
970 |
TheDir.Close(); |
|
971 |
||
972 |
test.Printf(_L("Test dir with long filenames\n")); |
|
973 |
||
974 |
FormatPack(); |
|
975 |
r=TheFs.MkDir(_L("\\D\\")); |
|
976 |
if (r!=KErrNone && r!=KErrAlreadyExists) |
|
977 |
Error(_L("Failed to make directory"),r); |
|
978 |
TheFileName=_L("\\D\\"); |
|
979 |
||
980 |
dirEntriesNeeded = ((TheBootSector.BytesPerSector()*TheBootSector.SectorsPerCluster()/KSizeOfFatDirEntry)-3); |
|
981 |
dirEntriesNeeded = ThrottleDirEntries(dirEntriesNeeded, 3); |
|
982 |
||
983 |
//-- generate some number of VFAT dir. entries by creating 8.3 temp. files in a lower case |
|
984 |
for (i=0;i<dirEntriesNeeded;i++) |
|
985 |
{ |
|
986 |
CreateFatEntry(TheFileName, ETrue); |
|
987 |
} |
|
988 |
||
989 |
MakeFile(_L("\\D\\longfileName.Long")); |
|
990 |
||
991 |
test.Printf(_L("Test dir with no match\n")); |
|
992 |
FatWrite(gFirstDataCluster,gFirstDataCluster); |
|
993 |
if ((r=TheDir.Open(TheFs,_L("\\D\\nomatch"),KEntryAttMaskSupported))!=KErrNone) |
|
994 |
Error(_L("Failed Directory open"),r); |
|
995 |
if ((r=TheDir.Read(TheEntry))!=KErrCorrupt) |
|
996 |
Error(_L("Failed Directory read"),r); |
|
997 |
TheDir.Close(); |
|
998 |
||
999 |
test.Printf(_L("Test dir with match\n")); |
|
1000 |
if ((r=TheDir.Open(TheFs,_L("\\D\\*.*"),KEntryAttMaskSupported))!=KErrNone) |
|
1001 |
Error(_L("Failed Directory open"),r); |
|
1002 |
if ((r=TheDir.Read(TheEntry))!=KErrNone) |
|
1003 |
Error(_L("Failed Directory read"),r); |
|
1004 |
TheDir.Close(); |
|
1005 |
||
1006 |
test.Printf(_L("Test dir without loop\n")); |
|
1007 |
FatWrite(gFirstDataCluster,gEndOfChain); |
|
1008 |
if ((r=TheDir.Open(TheFs,_L("\\D\\nomatch"),KEntryAttMaskSupported))!=KErrNone) |
|
1009 |
Error(_L("Directory open"),r); |
|
1010 |
||
1011 |
#if !defined _UNICODE |
|
1012 |
if ((r=TheDir.Read(TheEntry))!=KErrCorrupt) |
|
1013 |
Error(_L("Reading empty dir returned"),r); |
|
1014 |
#endif |
|
1015 |
TheDir.Close(); |
|
1016 |
} |
|
1017 |
||
1018 |
static void TestLoopedFile() |
|
1019 |
// |
|
1020 |
// Test Looped file |
|
1021 |
// |
|
1022 |
{ |
|
1023 |
test.Printf(_L("Test looped file\n")); |
|
1024 |
FormatPack(); |
|
1025 |
TInt r; |
|
1026 |
||
1027 |
||
1028 |
||
1029 |
test.Next(_L("CreateFile")); |
|
1030 |
test(TheFile.Replace(TheFs,_L("\\LOOPED1.TMP"),EFileRead|EFileWrite)==KErrNone); |
|
1031 |
TPtr8 buf=pBuffer1->Des(); |
|
1032 |
||
1033 |
test(TheFile.Write(buf,TheBootSector.BytesPerSector()-1)==KErrNone); |
|
1034 |
TheFile.Close(); |
|
1035 |
||
1036 |
test.Next(_L("Write 1 cluster loop")); |
|
1037 |
FatWrite(gFirstDataCluster,gFirstDataCluster); /* tiny loop */ |
|
1038 |
if ((r=TheFile.Open(TheFs,_L("\\LOOPED1.TMP"),EFileRead|EFileWrite))!=KErrCorrupt) |
|
1039 |
Error(_L("Error opening corrupt file"),r); |
|
1040 |
FatWrite(gFirstDataCluster,0); |
|
1041 |
if ((r=TheFile.Open(TheFs,_L("\\LOOPED1.TMP"),EFileRead|EFileWrite))!=KErrCorrupt) |
|
1042 |
Error(_L("Error opening corrupt file"),r); |
|
1043 |
FatWrite(gFirstDataCluster,gEndOfChain); |
|
1044 |
if ((r=TheFile.Open(TheFs,_L("\\LOOPED1.TMP"),EFileRead|EFileWrite))!=KErrNone) |
|
1045 |
Error(_L("Error opening file"),r); |
|
1046 |
if ((r=TheFile.Write(buf,TheBootSector.BytesPerSector()*TheBootSector.SectorsPerCluster()*2-1))!=0) |
|
1047 |
Error(_L("Error writing to file"),r); |
|
1048 |
TheFile.Close(); |
|
1049 |
||
1050 |
test.Next(_L("Write 2 cluster loop")); |
|
1051 |
FatWrite(gFirstDataCluster+1,gFirstDataCluster); /* 2 cluster loop */ |
|
1052 |
if ((r=TheFile.Open(TheFs,_L("\\LOOPED1.TMP"),EFileRead|EFileWrite))!=KErrCorrupt) |
|
1053 |
Error(_L("Error opening corrupt file"),r); |
|
1054 |
FatWrite(gFirstDataCluster+1,gEndOfChain); |
|
1055 |
if ((r=TheFile.Open(TheFs,_L("\\LOOPED1.TMP"),EFileRead|EFileWrite))!=KErrNone) |
|
1056 |
Error(_L("Error opening file"),r); |
|
1057 |
||
1058 |
TInt len=16384; |
|
1059 |
TInt size=0L; |
|
1060 |
while (size < gBytesPerCluster * 500) |
|
1061 |
{ |
|
1062 |
test.Printf(_L("\rWriting %d "),size); |
|
1063 |
if ((r=TheFile.Write(buf,len))!=KErrNone) |
|
1064 |
{ |
|
1065 |
if (r!=KErrDiskFull) |
|
1066 |
Error(_L("File write error"),r); |
|
1067 |
len>>=1; |
|
1068 |
if (len==0) |
|
1069 |
break; |
|
1070 |
} |
|
1071 |
else |
|
1072 |
size+=len; |
|
1073 |
} |
|
1074 |
test.Printf(_L("\n")); |
|
1075 |
TheFile.Close(); |
|
1076 |
||
1077 |
RDebug::Print(_L("File created size %d"), size); |
|
1078 |
TInt clust=((size-1)>>ClusterShifts())+gFirstDataCluster; |
|
1079 |
FatWrite(clust,gFirstDataCluster); |
|
1080 |
if ((r=TheFile.Open(TheFs,_L("\\LOOPED1.TMP"),EFileRead|EFileWrite))!=KErrCorrupt) |
|
1081 |
Error(_L("Error opening corrupt file"),r); |
|
1082 |
FatWrite(clust,gEndOfChain); |
|
1083 |
if ((r=TheFs.Delete(_L("\\LOOPED1.TMP")))!=KErrNone) |
|
1084 |
Error(_L("Error deleting file"),r); |
|
1085 |
RDebug::Print(_L("File removed")); |
|
1086 |
r=TheFs.CheckDisk(gSessionPath); |
|
149 | 1087 |
test_KErrNone(r); |
0 | 1088 |
} |
1089 |
||
1090 |
static void TestFatEntry(TUint16 aFileSize,TInt aCorruptFatCluster) |
|
1091 |
// |
|
1092 |
// Test fat entry |
|
1093 |
// |
|
1094 |
{ |
|
1095 |
TInt r; |
|
1096 |
test.Printf(_L("File size=%d, cluster value=0x%x\n"),aFileSize,aCorruptFatCluster); |
|
1097 |
FormatPack(); |
|
1098 |
||
1099 |
r=TheFile.Replace(TheFs,_L("\\CORRUPT2.TMP"),EFileRead|EFileWrite); |
|
149 | 1100 |
test_KErrNone(r); |
0 | 1101 |
TheBuffer.SetLength(aFileSize); |
1102 |
Mem::Fill(&TheBuffer[0],aFileSize,'A'); |
|
1103 |
r=TheFile.Write(TheBuffer); |
|
149 | 1104 |
test_KErrNone(r); |
0 | 1105 |
TheFile.Close(); |
1106 |
||
1107 |
FatWrite(gFirstDataCluster,aCorruptFatCluster); |
|
1108 |
||
1109 |
TInt pos=0; |
|
1110 |
r=TheFile.Open(TheFs,_L("\\CORRUPT2.TMP"),EFileRead|EFileWrite); |
|
149 | 1111 |
test_Value(r, r == KErrNone || r==KErrCorrupt); |
0 | 1112 |
if (r==KErrNone) |
1113 |
{ |
|
1114 |
r=TheFile.Seek(ESeekStart,pos); |
|
149 | 1115 |
test_KErrNone(r); |
0 | 1116 |
r=TheFile.Write(TheBuffer); |
1117 |
||
1118 |
if ((gDriveCacheFlags & EFileCacheWriteOn) && (r == KErrNone)) |
|
1119 |
r = TheFile.Flush(); |
|
1120 |
||
1121 |
if (r != KErrCorrupt) |
|
1122 |
{ |
|
1123 |
test.Printf(_L("Predicted error %d Actual error %d\n"),KErrCorrupt,r); |
|
1124 |
Error(_L("Failed write"),r); |
|
1125 |
} |
|
1126 |
TheFile.Close(); |
|
1127 |
} |
|
1128 |
||
1129 |
FatWrite(gFirstDataCluster,gEndOfChain); |
|
1130 |
||
1131 |
pos=0; |
|
1132 |
r=TheFile.Open(TheFs,_L("\\CORRUPT2.TMP"),EFileRead|EFileWrite); |
|
149 | 1133 |
test_KErrNone(r); |
0 | 1134 |
r=TheFile.Seek(ESeekStart,pos); |
149 | 1135 |
test_KErrNone(r); |
0 | 1136 |
r=TheFile.Write(TheBuffer); |
1137 |
||
1138 |
if ((gDriveCacheFlags & EFileCacheWriteOn) && (r == KErrNone)) |
|
1139 |
r = TheFile.Flush(); |
|
1140 |
||
1141 |
// if the file size <= cluster size then writing last cluster marker to |
|
1142 |
// cluster 2 should have no effect |
|
1143 |
if(aFileSize>TheBootSector.SectorsPerCluster()<<SectorShifts()) |
|
1144 |
{ |
|
1145 |
if (r!=KErrCorrupt) |
|
1146 |
{ |
|
1147 |
test.Printf(_L("Predicted error %d Actual error %d\n"),KErrCorrupt,r); |
|
1148 |
Error(_L("Failed write"),r); |
|
1149 |
} |
|
1150 |
} |
|
1151 |
else |
|
1152 |
{ |
|
1153 |
if (r!=KErrNone) |
|
1154 |
{ |
|
1155 |
test.Printf(_L("Predicted error %d Actual error %d\n"),KErrNone,r); |
|
1156 |
Error(_L("Failed write"),r); |
|
1157 |
} |
|
1158 |
} |
|
1159 |
TheFile.Close(); |
|
1160 |
} |
|
1161 |
||
1162 |
static void TestDirEntry(TInt anInitialSize,TInt aWriteLen,TInt aCorruptStartCluster) |
|
1163 |
// |
|
1164 |
// Test directory entry |
|
1165 |
// |
|
1166 |
{ |
|
1167 |
test.Printf(_L("Initial size=%d, len=%d, start cluster=0x%x\n"),anInitialSize,aWriteLen,aCorruptStartCluster); |
|
1168 |
FormatPack(); |
|
1169 |
TInt r; |
|
1170 |
||
1171 |
test(TheFile.Create(TheFs,_L("\\CORRUPT1.TMP"),EFileRead|EFileWrite)==KErrNone); |
|
1172 |
TheBuffer.SetLength(anInitialSize); |
|
1173 |
Mem::Fill(&TheBuffer[0],anInitialSize,'A'); |
|
1174 |
r=TheFile.Write(TheBuffer); |
|
149 | 1175 |
test_KErrNone(r); |
0 | 1176 |
TheFile.Close(); |
1177 |
||
1178 |
r=TheDisk.Open(TheFs,CurrentDrive()); |
|
149 | 1179 |
test_KErrNone(r); |
0 | 1180 |
TPtr8 sectorBuf((TUint8*)pBuffer1->Ptr(),TheBootSector.BytesPerSector()); |
1181 |
TInt pos = gRootDirStart; |
|
1182 |
r=TheDisk.Read(pos,sectorBuf); |
|
149 | 1183 |
test_KErrNone(r); |
0 | 1184 |
TFatDirEntry* pE=(TFatDirEntry*)pBuffer1->Ptr(); |
1185 |
while (pE->IsVFatEntry()) // UNICODE entries are VFat by definition |
|
1186 |
pE++; |
|
1187 |
||
1188 |
pE->SetStartCluster(aCorruptStartCluster); |
|
1189 |
test(TheDisk.Write(pos,sectorBuf)==KErrNone); |
|
1190 |
||
1191 |
||
1192 |
//-- a small hack to avoid problems with the fact that FAT[1] entry |
|
1193 |
//-- is now used for marking volume as clean. TheDisk.Close() cause volume remout and |
|
1194 |
//-- the data |
|
1195 |
TheDisk.Close(); |
|
1196 |
r=TheDisk.Open(TheFs,CurrentDrive()); |
|
149 | 1197 |
test_KErrNone(r); |
0 | 1198 |
|
1199 |
||
1200 |
pos=0; |
|
1201 |
TPtr8 buffer1(pBuffer1->Des()); |
|
1202 |
r=TheDisk.Read(pos,buffer1); |
|
149 | 1203 |
test_KErrNone(r); |
0 | 1204 |
TheDisk.Close(); |
1205 |
r=TheFs.Entry(_L("\\CORRUPT1.TMP"),TheEntry); |
|
149 | 1206 |
test_Value(r, r == KErrNone || r==KErrCorrupt); |
0 | 1207 |
TTime saveTime=TheEntry.iModified; |
1208 |
if (r!=KErrNone) |
|
1209 |
saveTime.HomeTime(); |
|
1210 |
||
1211 |
r=TheFile.Open(TheFs,_L("\\CORRUPT1.TMP"),EFileRead|EFileWrite); |
|
1212 |
if (r==KErrNone) |
|
1213 |
{ |
|
1214 |
TheBuffer.SetLength(aWriteLen); |
|
1215 |
Mem::Fill(&TheBuffer[0],aWriteLen,'B'); |
|
1216 |
if ((r=TheFile.Write(TheBuffer))!=KErrCorrupt) |
|
1217 |
{ |
|
1218 |
test.Printf(_L("Predicted error %d Actual error %d\n"),KErrCorrupt,r); |
|
1219 |
Error(_L("Failed write"),r); |
|
1220 |
} |
|
1221 |
TheFile.Close(); |
|
1222 |
} |
|
1223 |
||
1224 |
r=TheDisk.Open(TheFs,CurrentDrive()); |
|
149 | 1225 |
test_KErrNone(r); |
0 | 1226 |
pos=0; |
1227 |
TPtr8 buffer2(pBuffer2->Des()); |
|
1228 |
r=TheDisk.Read(pos,buffer2); |
|
149 | 1229 |
test_KErrNone(r); |
0 | 1230 |
|
1231 |
//-- this bit is dodgy. The buffers may differ because of volume finalisation stuff |
|
1232 |
//-- FAT[1] and FSInfo sectors |
|
1233 |
test(buffer1==buffer2); |
|
1234 |
TheDisk.Close(); |
|
1235 |
||
1236 |
r=TheFs.SetModified(_L("\\CORRUPT1.TMP"),saveTime); |
|
149 | 1237 |
test_Value(r, r == KErrNone || r==KErrCorrupt); |
0 | 1238 |
r=TheFs.Entry(_L("\\CORRUPT1.TMP"),TheEntry); |
149 | 1239 |
test_Value(r, r == KErrNone || r==KErrCorrupt); |
0 | 1240 |
} |
1241 |
||
1242 |
static void TestBounds() |
|
1243 |
// |
|
1244 |
// Test reading/writing past the end of a drive |
|
1245 |
// |
|
1246 |
{ |
|
1247 |
test.Next(_L("Test read/write past boundaries")); |
|
1248 |
test(TheFs.Volume(TheVolumeInfo,CurrentDrive())==KErrNone); |
|
1249 |
TInt64 size=TheVolumeInfo.iSize; |
|
1250 |
TInt r=TheDisk.Open(TheFs,CurrentDrive()); |
|
149 | 1251 |
test_KErrNone(r); |
0 | 1252 |
TPtr8 buffer(pBuffer1->Des()); |
1253 |
TInt64 pos=size - 2*buffer.MaxLength(); |
|
1254 |
TInt inc=buffer.MaxLength(); |
|
1255 |
FOREVER |
|
1256 |
{ |
|
1257 |
TPtr8 tempbuf((TUint8*)pBuffer1->Ptr(),inc); |
|
1258 |
r=TheDisk.Read(pos,tempbuf); |
|
1259 |
test.Printf(_L("Read %08X:%08X len %d r %d\r"), I64HIGH(pos),I64LOW(pos), inc, r); |
|
149 | 1260 |
test_Value(r, r == KErrNone || r==KErrCorrupt); |
0 | 1261 |
if (r==KErrNone) |
1262 |
pos+=inc; |
|
1263 |
else |
|
1264 |
{ |
|
1265 |
inc>>=1; |
|
1266 |
if (inc==0) |
|
1267 |
break; |
|
1268 |
} |
|
1269 |
test(pos<2*size); |
|
1270 |
} |
|
1271 |
||
1272 |
TInt64 maxcalc= TInt64(gTotalSectors) * TInt64(TheBootSector.BytesPerSector()); |
|
1273 |
||
1274 |
test.Printf(_L("\n")); |
|
1275 |
test.Printf(_L("Volume size = %ld\n"), size); |
|
1276 |
test.Printf(_L("RawDiskSize = %ld\n"), maxcalc); |
|
1277 |
test.Printf(_L("MaxReadPos = %ld\n"), pos); |
|
1278 |
||
1279 |
TInt64 maxpos = pos; |
|
1280 |
||
1281 |
// check that the calculated raw size of the disk is equal to the MaxReadPos that |
|
1282 |
// has just been discovered by trial and error |
|
1283 |
test(maxcalc == maxpos); |
|
1284 |
||
1285 |
for (TInt64 bsize = 1; bsize < 8; bsize++) |
|
1286 |
{ |
|
1287 |
test.Printf(_L("\n")); |
|
1288 |
test.Printf(_L("Buffer size %d\n"), bsize); |
|
1289 |
for (TInt64 bpos = MAKE_TINT64(0, 0x1000); bpos < MAKE_TINT64(0x3FFFFFFF,0); bpos<<=1) |
|
1290 |
{ |
|
1291 |
TInt64 endPos = (bpos + 1); |
|
1292 |
for (TInt64 lpos = bpos - bsize; lpos <= endPos; lpos++) |
|
1293 |
{ |
|
1294 |
TPtr8 temp((TUint8*) (pBuffer1->Ptr()), (TInt) bsize); |
|
1295 |
TInt expect = (lpos+bsize-1 < maxpos ? KErrNone : KErrCorrupt); |
|
1296 |
r=TheDisk.Read(lpos, temp); |
|
1297 |
RDebug::Print(_L("Read %08X:%08X result %d \r"), I64HIGH(lpos), I64LOW(lpos), r); |
|
149 | 1298 |
test_Value(r, r == expect); |
0 | 1299 |
} |
1300 |
} |
|
1301 |
} |
|
1302 |
||
1303 |
RDebug::Print(_L("\n")); |
|
1304 |
||
1305 |
TestReadWrite(0L,0,0); |
|
1306 |
TestReadWrite(0L,1,0); |
|
1307 |
TestReadWrite(pos-1,1,0); |
|
1308 |
TestReadWrite(pos-0x100,0x100,0); |
|
1309 |
TestReadWrite(pos-1,2,KErrCorrupt); |
|
1310 |
TestReadWrite(pos-0x100,0x101,KErrCorrupt); |
|
1311 |
TestReadWrite(pos-0xff,0x100,KErrCorrupt); |
|
1312 |
TestReadWrite(pos,0,0); |
|
1313 |
TestReadWrite(pos,1,KErrCorrupt); |
|
1314 |
||
1315 |
TestReadWrite(pos-16384,16384,0); |
|
1316 |
TestReadWrite(pos-16384,16385,KErrCorrupt); |
|
1317 |
||
1318 |
TInt errVal=(pos>32768+0x100) ? KErrNone : KErrCorrupt; |
|
1319 |
TestReadWrite(32768L,0x100,errVal); |
|
1320 |
errVal=(pos>32768+0x101) ? KErrNone : KErrCorrupt; |
|
1321 |
TestReadWrite(32768L,0x101,errVal); |
|
1322 |
errVal=(pos>32768+0x1ff) ? KErrNone : KErrCorrupt; |
|
1323 |
TestReadWrite(32768L,0xff,errVal); |
|
1324 |
errVal=(pos>65000+0x100) ? KErrNone : KErrCorrupt; |
|
1325 |
TestReadWrite(65000L,0x100,errVal); |
|
1326 |
||
1327 |
errVal=(pos>0x2000000+1) ? KErrNone : KErrCorrupt; |
|
1328 |
TestReadWrite(0x2000000L,1,errVal); |
|
1329 |
||
1330 |
TestRwWord(0L,0); |
|
1331 |
TestRwWord(1L,0); |
|
1332 |
TestRwWord(pos-2,0); |
|
1333 |
TestRwWord(pos-1,KErrCorrupt); |
|
1334 |
TestRwWord(pos,KErrCorrupt); |
|
1335 |
TestRwWord(pos+1,KErrCorrupt); |
|
1336 |
||
1337 |
TestRwDWord(0L,0); |
|
1338 |
TestRwDWord(1L,0); |
|
1339 |
TestRwDWord(2L,0); |
|
1340 |
TestRwDWord(3L,0); |
|
1341 |
TestRwDWord(pos-4,0); |
|
1342 |
TestRwDWord(pos-3,KErrCorrupt); |
|
1343 |
TestRwDWord(pos-2,KErrCorrupt); |
|
1344 |
TestRwDWord(pos-1,KErrCorrupt); |
|
1345 |
TestRwDWord(pos,KErrCorrupt); |
|
1346 |
TestRwDWord(pos+1,KErrCorrupt); |
|
1347 |
||
1348 |
TheDisk.Close(); |
|
1349 |
} |
|
1350 |
||
1351 |
static void TestClusters() |
|
1352 |
{ |
|
1353 |
test.Next(_L("Test corrupt start cluster")); |
|
1354 |
// Initial Write Corrupt |
|
1355 |
// Size Len Cluster |
|
1356 |
TestDirEntry(1024, 513, 0); |
|
1357 |
TestDirEntry( 512, 512, 0); |
|
1358 |
TestDirEntry(1024, 513, 1); |
|
1359 |
TestDirEntry( 512, 512, 1); |
|
1360 |
TestDirEntry(1024, 513, 0xff0); |
|
1361 |
||
1362 |
test.Printf(_L("Test corrupt chain\n")); |
|
1363 |
TestFatEntry(1536,0); |
|
1364 |
TestFatEntry(1536,1); |
|
1365 |
||
1366 |
// TInt fatCacheSize=FatCacheSize(); |
|
1367 |
// TUint16 cluster16=(TUint16)(fatCacheSize/2); |
|
1368 |
// TUint16 cluster12=(TUint16)((fatCacheSize/3)*2); |
|
1369 |
// TestFatEntry(1536,cluster12); |
|
1370 |
// TestFatEntry(1536,cluster16); |
|
1371 |
TestFatEntry(1536,0xff0); |
|
1372 |
// don't test when only one cluster for the file |
|
1373 |
if(1536>gBytesPerCluster) |
|
1374 |
TestFatEntry(1536,gEndOfChain); |
|
1375 |
||
1376 |
TestLoopedFile(); |
|
1377 |
TestLoopedSubDir(); |
|
1378 |
} |
|
1379 |
||
1380 |
||
1381 |
static void TestClusterAllocation() |
|
1382 |
// |
|
1383 |
// Test number of clusters allocated |
|
1384 |
// |
|
1385 |
{ |
|
1386 |
test.Next(_L("Test number of clusters allocated is correct")); |
|
1387 |
||
1388 |
FormatPack(); |
|
1389 |
||
1390 |
RFile f; |
|
1391 |
TInt r; |
|
1392 |
||
1393 |
r=f.Replace(TheFs,_L("\\GOBLIN.TMP"),EFileRead|EFileWrite); |
|
149 | 1394 |
test_KErrNone(r); |
0 | 1395 |
f.SetSize(4*gBytesPerCluster); // 4 Clusters |
1396 |
f.Close(); |
|
1397 |
||
1398 |
r=f.Replace(TheFs,_L("\\WIZARD.TMP"),EFileRead|EFileWrite); |
|
149 | 1399 |
test_KErrNone(r); |
0 | 1400 |
f.SetSize(5*gBytesPerCluster); // 5 Clusters |
1401 |
f.Close(); |
|
1402 |
||
1403 |
r=f.Replace(TheFs,_L("\\TROLL.TMP"),EFileRead|EFileWrite); |
|
149 | 1404 |
test_KErrNone(r); |
0 | 1405 |
f.SetSize(3*gBytesPerCluster); // 3 Clusters |
1406 |
f.Close(); |
|
1407 |
||
1408 |
r=f.Replace(TheFs,_L("\\GNOME.TMP"),EFileRead|EFileWrite); |
|
149 | 1409 |
test_KErrNone(r); |
0 | 1410 |
f.SetSize(10*gBytesPerCluster); // 10 Clusters |
1411 |
f.Close(); |
|
1412 |
||
1413 |
r=f.Replace(TheFs,_L("\\CYCLOPS.TMP"),EFileRead|EFileWrite); |
|
149 | 1414 |
test_KErrNone(r); |
0 | 1415 |
f.SetSize(gBytesPerCluster); // 1 Cluster |
1416 |
f.Close(); |
|
1417 |
||
1418 |
r=f.Replace(TheFs,_L("\\PIXIE.TMP"),EFileRead|EFileWrite); |
|
149 | 1419 |
test_KErrNone(r); |
0 | 1420 |
f.SetSize(gBytesPerCluster); // 1 Cluster |
1421 |
f.Close(); |
|
1422 |
||
1423 |
r=TheDisk.Open(TheFs,CurrentDrive()); |
|
149 | 1424 |
test_KErrNone(r); |
0 | 1425 |
TPtr8 sectorBuf((TUint8*)pBuffer1->Ptr(),TheBootSector.BytesPerSector()); |
1426 |
TInt pos = gRootDirStart; |
|
1427 |
test(TheDisk.Read(pos,sectorBuf)==KErrNone); |
|
1428 |
TheDisk.Close(); |
|
1429 |
||
1430 |
TFatDirEntry* pE=(TFatDirEntry*)pBuffer1->Ptr(); |
|
1431 |
while (pE->IsVFatEntry()) // UNICODE 8.3 filenames are VFAT by definition |
|
1432 |
pE++; |
|
1433 |
||
1434 |
TInt cluster=pE->StartCluster(); |
|
1435 |
TBuf8<15> name=pE->Name(); |
|
1436 |
test(name==_L8("GOBLIN TMP")); |
|
1437 |
||
1438 |
pE++; |
|
1439 |
while (pE->IsVFatEntry()) |
|
1440 |
pE++; |
|
1441 |
||
1442 |
test((pE->StartCluster()-cluster)==4); |
|
1443 |
cluster=pE->StartCluster(); |
|
1444 |
name=pE->Name(); |
|
1445 |
test(name==_L8("WIZARD TMP")); |
|
1446 |
||
1447 |
pE++; |
|
1448 |
while (pE->IsVFatEntry()) |
|
1449 |
pE++; |
|
1450 |
||
1451 |
test((pE->StartCluster()-cluster)==5); |
|
1452 |
cluster=pE->StartCluster(); |
|
1453 |
name=pE->Name(); |
|
1454 |
test(name==_L8("TROLL TMP")); |
|
1455 |
||
1456 |
pE++; |
|
1457 |
while (pE->IsVFatEntry()) |
|
1458 |
pE++; |
|
1459 |
||
1460 |
test((pE->StartCluster()-cluster)==3); |
|
1461 |
cluster=pE->StartCluster(); |
|
1462 |
name=pE->Name(); |
|
1463 |
test(name==_L8("GNOME TMP")); |
|
1464 |
||
1465 |
pE++; |
|
1466 |
while (pE->IsVFatEntry()) |
|
1467 |
pE++; |
|
1468 |
||
1469 |
test ((pE->StartCluster()-cluster)==10); |
|
1470 |
cluster=pE->StartCluster(); |
|
1471 |
name=pE->Name(); |
|
1472 |
test(name==_L8("CYCLOPS TMP")); |
|
1473 |
||
1474 |
pE++; |
|
1475 |
while (pE->IsVFatEntry()) |
|
1476 |
pE++; |
|
1477 |
||
1478 |
test((pE->StartCluster()-cluster)==1); |
|
1479 |
name=pE->Name(); |
|
1480 |
test(name==_L8("PIXIE TMP")); |
|
1481 |
||
1482 |
r=TheFs.Delete(_L("\\GOBLIN.TMP")); |
|
149 | 1483 |
test_KErrNone(r); |
0 | 1484 |
r=TheFs.Delete(_L("\\WIZARD.TMP")); |
149 | 1485 |
test_KErrNone(r); |
0 | 1486 |
r=TheFs.Delete(_L("\\TROLL.TMP")); |
149 | 1487 |
test_KErrNone(r); |
0 | 1488 |
r=TheFs.Delete(_L("\\GNOME.TMP")); |
149 | 1489 |
test_KErrNone(r); |
0 | 1490 |
r=TheFs.Delete(_L("\\CYCLOPS.TMP")); |
149 | 1491 |
test_KErrNone(r); |
0 | 1492 |
r=TheFs.Delete(_L("\\PIXIE.TMP")); |
149 | 1493 |
test_KErrNone(r); |
0 | 1494 |
|
1495 |
FormatPack(); |
|
1496 |
||
1497 |
} |
|
1498 |
||
1499 |
||
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1500 |
static void TestMakeDir(const TDesC& aName, TUint aNewClust, TUint aParentClust) |
0 | 1501 |
// |
1502 |
// Test make dir |
|
1503 |
// |
|
1504 |
{ |
|
1505 |
test.Printf(_L("Checking cluster %02d, parent %d: \"%S\"\n"), aNewClust, aParentClust, &aName); |
|
1506 |
||
1507 |
TInt r=TheFs.MkDir(aName); |
|
149 | 1508 |
test_Value(r, r == KErrNone || r==KErrAlreadyExists); |
0 | 1509 |
|
1510 |
TInt pos=ClusterToByte(aNewClust); |
|
1511 |
TPtr8 sectorBuf((TUint8*)pBuffer1->Ptr(),gBytesPerCluster); |
|
1512 |
||
1513 |
r=TheDisk.Open(TheFs,CurrentDrive()); |
|
1514 |
if ((r=TheDisk.Read(pos,sectorBuf))!=KErrNone) |
|
1515 |
Error(_L("Reading data"),r); |
|
1516 |
TheDisk.Close(); |
|
1517 |
||
1518 |
TFatDirEntry* pE=(TFatDirEntry*)pBuffer1->Ptr(); |
|
1519 |
if (pE->Name()[0]!='.' || pE->Name()[1]!=' ') |
|
1520 |
{ |
|
1521 |
while (pE->IsVFatEntry()) |
|
1522 |
pE++; |
|
1523 |
if (pE->Name()[0]!='.' || pE->Name()[1]!=' ') |
|
1524 |
Error(_L("Failed to find '.' entry"),KErrNone); |
|
1525 |
} |
|
1526 |
if (pE->StartCluster()!=aNewClust) |
|
1527 |
Error(_L("Bad directory start cluster"),KErrNone); |
|
1528 |
pE++; |
|
1529 |
if (pE->Name()[0]!='.' || pE->Name()[1]!='.') |
|
1530 |
Error(_L("Second entry is not '..'"),KErrNone); |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1531 |
if (pE->StartCluster() != ((aParentClust==(TUint)gRootCluster)?0:aParentClust)) |
0 | 1532 |
Error(_L("Start cluster of .. is not parent directory"),KErrNone); |
1533 |
} |
|
1534 |
||
1535 |
||
1536 |
||
1537 |
static void TestParentDir(TBool aUseVfat) |
|
1538 |
{ |
|
1539 |
||
1540 |
test.Next(_L("TestParentDir()")); |
|
1541 |
||
1542 |
TInt root = gRootCluster; |
|
1543 |
TInt cl = gFirstDataCluster; |
|
1544 |
TInt p1 = cl; |
|
1545 |
||
1546 |
FormatPack(); |
|
1547 |
||
1548 |
TestMakeDir(_L("\\P1\\"), cl++, root); |
|
1549 |
||
1550 |
||
1551 |
const TInt nDirEntries= gBytesPerCluster / KSizeOfFatDirEntry; //-- number of dir. entries to fill 1 cluster |
|
1552 |
const TInt nFiles = aUseVfat ? nDirEntries/2 : nDirEntries; //-- number of 8.3 files to fill 1 cluster |
|
1553 |
||
1554 |
cl++; |
|
1555 |
for (TInt i=0;i<nFiles;i++) |
|
1556 |
{ |
|
1557 |
CreateFatEntry(_L("\\P1\\"), aUseVfat); |
|
1558 |
} |
|
1559 |
||
1560 |
||
1561 |
TInt p1p2 = cl; |
|
1562 |
if(aUseVfat) |
|
1563 |
{ |
|
1564 |
TestMakeDir(_L("\\p1\\p2\\"), cl++, p1); |
|
1565 |
TestMakeDir(_L("\\p1\\p21\\"), cl++, p1); |
|
1566 |
TestMakeDir(_L("\\p1\\p2\\p3\\"), cl++, p1p2); |
|
1567 |
TestMakeDir(_L("\\p1\\p2\\p33\\"), cl++, p1p2); |
|
1568 |
TestMakeDir(_L("\\p1\\p2\\p34\\"), cl++, p1p2); |
|
1569 |
TestMakeDir(_L("\\p1\\p2\\p35\\"), cl++, p1p2); |
|
1570 |
TestMakeDir(_L("\\p1\\p2\\p36\\"), cl++, p1p2); |
|
1571 |
TestMakeDir(_L("\\p1\\p2\\p37\\"), cl++, p1p2); |
|
1572 |
TestMakeDir(_L("\\p1\\p2\\p38\\"), cl++, p1p2); |
|
1573 |
} |
|
1574 |
else |
|
1575 |
{ |
|
1576 |
TestMakeDir(_L("\\P1\\P2\\"), cl++, p1); |
|
1577 |
TestMakeDir(_L("\\P1\\P21\\"), cl++, p1); |
|
1578 |
TestMakeDir(_L("\\P1\\P2\\P3\\"), cl++, p1p2); |
|
1579 |
TestMakeDir(_L("\\P1\\P2\\P33\\"), cl++, p1p2); |
|
1580 |
TestMakeDir(_L("\\P1\\P2\\P34\\"), cl++, p1p2); |
|
1581 |
TestMakeDir(_L("\\P1\\P2\\P35\\"), cl++, p1p2); |
|
1582 |
TestMakeDir(_L("\\P1\\P2\\P36\\"), cl++, p1p2); |
|
1583 |
TestMakeDir(_L("\\P1\\P2\\P37\\"), cl++, p1p2); |
|
1584 |
TestMakeDir(_L("\\P1\\P2\\P38\\"), cl++, p1p2); |
|
1585 |
||
1586 |
TestMakeDir(_L("\\P1\\P2\\P39\\"), cl++, p1p2); |
|
1587 |
TestMakeDir(_L("\\P1\\P2\\P40\\"), cl++, p1p2); |
|
1588 |
TestMakeDir(_L("\\P1\\P2\\P41\\"), cl++, p1p2); |
|
1589 |
TestMakeDir(_L("\\P1\\P2\\P42\\"), cl++, p1p2); |
|
1590 |
TestMakeDir(_L("\\P1\\P2\\P43\\"), cl++, p1p2); |
|
1591 |
TestMakeDir(_L("\\P1\\P2\\P44\\"), cl++, p1p2); |
|
1592 |
TestMakeDir(_L("\\P1\\P2\\P45\\"), cl++, p1p2); |
|
1593 |
} |
|
1594 |
||
1595 |
// if sectors/cluster == 1 then the directory \p1\p2\ will now have to |
|
1596 |
// allocate another cluster |
|
1597 |
if(TheBootSector.SectorsPerCluster()==1) |
|
1598 |
++cl; |
|
1599 |
if(aUseVfat) |
|
1600 |
{ |
|
1601 |
TestMakeDir(_L("\\p1\\p2\\p310\\"), cl++, p1p2); |
|
1602 |
TestMakeDir(_L("\\p1\\p2\\p311\\"), cl++, p1p2); |
|
1603 |
TestMakeDir(_L("\\p1\\p2\\p312\\"), cl++, p1p2); |
|
1604 |
TestMakeDir(_L("\\p1\\p2\\p313\\"), cl++, p1p2); |
|
1605 |
TestMakeDir(_L("\\p1\\p2\\p314\\"), cl++, p1p2); |
|
1606 |
TestMakeDir(_L("\\p1\\p2\\p315\\"), cl++, p1p2); |
|
1607 |
TestMakeDir(_L("\\p1\\p2\\p316\\"), cl++, p1p2); |
|
1608 |
TestMakeDir(_L("\\p1\\p2\\p317\\"), cl++, p1p2); |
|
1609 |
} |
|
1610 |
else |
|
1611 |
{ |
|
1612 |
TestMakeDir(_L("\\P1\\P2\\P310\\"), cl++, p1p2); |
|
1613 |
TestMakeDir(_L("\\P1\\P2\\P311\\"), cl++, p1p2); |
|
1614 |
TestMakeDir(_L("\\P1\\P2\\P312\\"), cl++, p1p2); |
|
1615 |
TestMakeDir(_L("\\P1\\P2\\P313\\"), cl++, p1p2); |
|
1616 |
TestMakeDir(_L("\\P1\\P2\\P314\\"), cl++, p1p2); |
|
1617 |
TestMakeDir(_L("\\P1\\P2\\P315\\"), cl++, p1p2); |
|
1618 |
TestMakeDir(_L("\\P1\\P2\\P316\\"), cl++, p1p2); |
|
1619 |
TestMakeDir(_L("\\P1\\P2\\P317\\"), cl++, p1p2); |
|
1620 |
||
1621 |
TestMakeDir(_L("\\P1\\P2\\P318\\"), cl++, p1p2); |
|
1622 |
TestMakeDir(_L("\\P1\\P2\\P319\\"), cl++, p1p2); |
|
1623 |
TestMakeDir(_L("\\P1\\P2\\P320\\"), cl++, p1p2); |
|
1624 |
TestMakeDir(_L("\\P1\\P2\\P321\\"), cl++, p1p2); |
|
1625 |
TestMakeDir(_L("\\P1\\P2\\P322\\"), cl++, p1p2); |
|
1626 |
TestMakeDir(_L("\\P1\\P2\\P323\\"), cl++, p1p2); |
|
1627 |
TestMakeDir(_L("\\P1\\P2\\P324\\"), cl++, p1p2); |
|
1628 |
TestMakeDir(_L("\\P1\\P2\\P325\\"), cl++, p1p2); |
|
1629 |
} |
|
1630 |
||
1631 |
// if sectors/cluster <= 2 then the directory \p1\p2\ will have to |
|
1632 |
// allocate another cluster |
|
1633 |
if(TheBootSector.SectorsPerCluster()<=2) |
|
1634 |
++cl; |
|
1635 |
TestMakeDir(_L("\\P1\\P2\\P330\\"), cl++, p1p2); |
|
1636 |
TestMakeDir(_L("\\P11\\"), cl++, root); |
|
1637 |
} |
|
1638 |
||
1639 |
static const TInt KMaxFiles=5; |
|
1640 |
||
1641 |
// |
|
1642 |
// Test root dir size |
|
1643 |
// |
|
1644 |
static void TestRoot() |
|
1645 |
{ |
|
1646 |
test.Next(_L("Test root dir size")); |
|
1647 |
||
1648 |
if (gDiskType == EFat32) |
|
1649 |
{ |
|
1650 |
test.Printf(_L("Not possible on FAT32 filesystem\n")); |
|
1651 |
return; |
|
1652 |
} |
|
1653 |
||
1654 |
FormatPack(); |
|
1655 |
TInt rootEntries=TheBootSector.RootDirEntries(); |
|
1656 |
test.Printf(_L("Total root entries allowed = %d\n"),rootEntries); |
|
1657 |
TFileName fileName[KMaxFiles]; // KMaxFiles=5 in this test |
|
1658 |
TFileName tempName; |
|
1659 |
TInt numberOfEntries=rootEntries; |
|
1660 |
TInt r; |
|
1661 |
RFile f; |
|
1662 |
||
1663 |
//-- generate 8.3 FAT entries, temp files created in upper-case, otherwise it will be 2 vFAT entries |
|
1664 |
while(numberOfEntries--) |
|
1665 |
{ |
|
1666 |
if (numberOfEntries<KMaxFiles) |
|
1667 |
CreateFatEntry(_L("\\"), EFalse, &fileName[numberOfEntries]); |
|
1668 |
else |
|
1669 |
CreateFatEntry(_L("\\"), EFalse); |
|
1670 |
||
1671 |
} |
|
1672 |
||
1673 |
r = f.Create(TheFs, _L("\\123456.78"), EFileRead|EFileWrite); |
|
149 | 1674 |
test_Value(r, r == KErrDirFull); |
0 | 1675 |
f.Close(); |
1676 |
||
1677 |
||
1678 |
TInt i=0; |
|
1679 |
for (i=0;i<KMaxFiles;i++) |
|
1680 |
{ |
|
1681 |
r=TheFs.Delete(fileName[i]); |
|
149 | 1682 |
test_KErrNone(r); |
0 | 1683 |
} |
1684 |
||
1685 |
r=TheFs.SetSessionPath(_L("\\")); |
|
149 | 1686 |
test_KErrNone(r); |
0 | 1687 |
|
1688 |
TInt nameLength=(KMaxFiles-1)*13; // -1 for zero terminator |
|
1689 |
CreateLongName(tempName,gSeed,nameLength*2); |
|
1690 |
r=f.Create(TheFs,tempName,0); // Needs 9 free entries - there are only 5 available |
|
149 | 1691 |
test_Value(r, r == KErrDirFull); |
0 | 1692 |
tempName.SetLength(nameLength+1); |
1693 |
r=f.Create(TheFs,tempName,0); // Needs 6 free entries - there are only 5 available |
|
149 | 1694 |
test_Value(r, r == KErrDirFull); |
0 | 1695 |
tempName.SetLength(nameLength); |
1696 |
r=f.Create(TheFs,tempName,0); // Needs 5 free entries - there are 5 available |
|
149 | 1697 |
test_KErrNone(r); |
0 | 1698 |
f.Close(); |
1699 |
||
1700 |
#if 0 // This is the old test that assumed UNICODE builds |
|
1701 |
// which created VFAT entries even for uppercase 8.3 file names |
|
1702 |
TInt i=0; |
|
1703 |
for (i=0;i<KMaxFiles-2;i++) |
|
1704 |
{ |
|
1705 |
r=TheFs.Delete(fileName[i]); // UNICODE build - free 6 entries (delete 3 files) |
|
149 | 1706 |
test_KErrNone(r); |
0 | 1707 |
} |
1708 |
||
1709 |
r=TheFs.SetSessionPath(_L("\\")); |
|
149 | 1710 |
test_KErrNone(r); |
0 | 1711 |
|
1712 |
TInt vFatUnitNameSize=13; |
|
1713 |
TInt nameLength=(KMaxFiles-1)*vFatUnitNameSize-1; // |
|
1714 |
CreateLongName(tempName,gSeed,nameLength*2); |
|
1715 |
r=f.Create(TheFs,tempName,0); // Needs 9 free entries |
|
149 | 1716 |
test_Value(r, r == KErrDirFull); |
0 | 1717 |
|
1718 |
nameLength=(KMaxFiles)*vFatUnitNameSize; |
|
1719 |
tempName.SetLength(nameLength+1); |
|
1720 |
r=f.Create(TheFs,tempName,0); // Needs 7 free entries |
|
149 | 1721 |
test_Value(r, r == KErrDirFull); |
0 | 1722 |
tempName.SetLength(nameLength); |
1723 |
r=f.Create(TheFs,tempName,0); // Needs 6 free entries |
|
149 | 1724 |
test_KErrNone(r); |
0 | 1725 |
f.Close(); |
1726 |
#endif |
|
1727 |
||
1728 |
TheFs.Delete(tempName); |
|
1729 |
tempName.SetLength(nameLength-7); |
|
1730 |
r=f.Create(TheFs,tempName,0); |
|
149 | 1731 |
test_KErrNone(r); |
0 | 1732 |
f.Close(); |
1733 |
||
1734 |
r=f.Create(TheFs,_L("ASDF"),0); |
|
149 | 1735 |
test_Value(r, r == KErrDirFull); |
0 | 1736 |
|
1737 |
TheFs.Delete(tempName); |
|
1738 |
tempName.SetLength(nameLength-15); |
|
1739 |
r=f.Create(TheFs,tempName,0); |
|
149 | 1740 |
test_KErrNone(r); |
0 | 1741 |
f.Close(); |
1742 |
||
1743 |
tempName=_L("testname"); |
|
1744 |
r=f.Create(TheFs,tempName,0); |
|
149 | 1745 |
test_Value(r, r == KErrDirFull); |
0 | 1746 |
tempName.UpperCase(); |
1747 |
r=f.Create(TheFs,tempName,0); |
|
149 | 1748 |
test_KErrNone(r); |
0 | 1749 |
f.Close(); |
1750 |
||
1751 |
||
1752 |
r=TheFs.SetSessionPath(gSessionPath); |
|
149 | 1753 |
test_KErrNone(r); |
0 | 1754 |
} |
1755 |
||
1756 |
static void TestVolumeSize() |
|
1757 |
// |
|
1758 |
// Test the volume size is zero when empty |
|
1759 |
// |
|
1760 |
{ |
|
1761 |
test.Next(_L("Test the volume size")); |
|
1762 |
FormatPack(); |
|
1763 |
||
1764 |
TVolumeInfo volInfo; |
|
1765 |
TInt r=TheFs.Volume(volInfo); |
|
149 | 1766 |
test_KErrNone(r); |
0 | 1767 |
TInt64 calcsize = MAKE_TINT64(0, gClusterCount)*gBytesPerCluster; |
1768 |
if (volInfo.iSize > calcsize) |
|
1769 |
{ |
|
1770 |
test.Printf(_L("volInfo.iSize = %ld\n"), volInfo.iSize); |
|
1771 |
test.Printf(_L("volInfo.iFree = %ld\n"), volInfo.iFree); |
|
1772 |
test.Printf(_L("calculated = %ld\n"), calcsize); |
|
1773 |
TInt diff = I64LOW(volInfo.iSize-calcsize); |
|
1774 |
test.Printf(_L("difference = %d (%d clusters)\n"), diff, diff/gBytesPerCluster); |
|
1775 |
test(0); |
|
1776 |
} |
|
1777 |
if (gDiskType == EFat32) |
|
1778 |
volInfo.iSize -= gBytesPerCluster; // root dir is part of the 'size' |
|
1779 |
if (volInfo.iSize != volInfo.iFree) |
|
1780 |
{ |
|
1781 |
test.Printf(_L("volInfo.iSize = %ld\n"), volInfo.iSize); |
|
1782 |
test.Printf(_L("volInfo.iFree = %ld\n"), volInfo.iFree); |
|
1783 |
TInt diff = I64LOW(volInfo.iSize-volInfo.iFree); |
|
1784 |
test.Printf(_L("difference = %d (%d clusters)\n"), diff, diff/gBytesPerCluster); |
|
1785 |
DumpData(); |
|
1786 |
DumpFat(); |
|
1787 |
test(0); |
|
1788 |
} |
|
1789 |
||
1790 |
RFile f[KMaxFiles]; |
|
1791 |
TFileName fileName; |
|
1792 |
TInt i=0; |
|
1793 |
for (i=0;i<KMaxFiles;i++) |
|
1794 |
{ |
|
1795 |
fileName=_L("\\File"); |
|
1796 |
fileName.AppendNum(i); |
|
1797 |
r=f[i].Create(TheFs,fileName,0); |
|
149 | 1798 |
test_KErrNone(r); |
0 | 1799 |
} |
1800 |
||
1801 |
TInt maxTotalSize=1048576; |
|
1802 |
TInt maxFileSize=maxTotalSize/KMaxFiles; |
|
1803 |
TInt maxIterations=20; |
|
1804 |
||
1805 |
while(maxIterations--) |
|
1806 |
{ |
|
1807 |
for (i=0;i<KMaxFiles;i++) |
|
1808 |
{ |
|
1809 |
TInt randSize=Math::Rand(gSeed)%maxFileSize; |
|
1810 |
r=f[i].SetSize(randSize); |
|
149 | 1811 |
test_KErrNone(r); |
0 | 1812 |
} |
1813 |
test.Printf(_L("Countdown .. %d \r"),maxIterations); |
|
1814 |
} |
|
1815 |
||
1816 |
test.Printf(_L("\n")); |
|
1817 |
||
1818 |
TInt totalSize=0; |
|
1819 |
||
1820 |
for (i=0;i<KMaxFiles;i++) |
|
1821 |
{ |
|
1822 |
TInt size=0; |
|
1823 |
r=f[i].Size(size); |
|
149 | 1824 |
test_KErrNone(r); |
0 | 1825 |
totalSize+=((size+gBytesPerCluster-1)/gBytesPerCluster)*gBytesPerCluster; |
1826 |
} |
|
1827 |
||
1828 |
r=TheFs.Volume(volInfo); |
|
149 | 1829 |
test_KErrNone(r); |
0 | 1830 |
if (gDiskType == EFat32) |
1831 |
volInfo.iSize -= gBytesPerCluster; // root dir is part of the 'size' |
|
1832 |
if (volInfo.iSize-volInfo.iFree!=totalSize) |
|
1833 |
{ |
|
1834 |
test.Printf(_L("volInfo.iSize = %ld\n"), volInfo.iSize); |
|
1835 |
test.Printf(_L("volInfo.iFree = %ld\n"), volInfo.iFree); |
|
1836 |
test.Printf(_L("totalSize = %ld\n"), totalSize); |
|
1837 |
TInt diff = I64LOW(volInfo.iSize-volInfo.iFree) - totalSize; |
|
1838 |
test.Printf(_L("difference = %d (%d clusters)\n"), diff, diff/gBytesPerCluster); |
|
1839 |
} |
|
1840 |
test(volInfo.iSize-volInfo.iFree==totalSize); |
|
1841 |
||
1842 |
for (i=0;i<KMaxFiles;i++) |
|
1843 |
f[i].Close(); |
|
1844 |
||
1845 |
for (i=0;i<KMaxFiles;i++) |
|
1846 |
{ |
|
1847 |
fileName=_L("\\File"); |
|
1848 |
fileName.AppendNum(i); |
|
1849 |
r=TheFs.Delete(fileName); |
|
149 | 1850 |
test_KErrNone(r); |
0 | 1851 |
} |
1852 |
||
1853 |
r=TheFs.Volume(volInfo); |
|
1854 |
if (gDiskType == EFat32) |
|
1855 |
volInfo.iSize -= gBytesPerCluster; // root dir is part of the 'size' |
|
149 | 1856 |
test_KErrNone(r); |
0 | 1857 |
test(volInfo.iSize-volInfo.iFree==0); |
1858 |
||
1859 |
MakeDir(gSessionPath); |
|
1860 |
||
1861 |
TInt entries=(gBytesPerCluster/KSizeOfFatDirEntry)*5-2; |
|
1862 |
entries = ThrottleDirEntries(entries, 2); |
|
1863 |
||
1864 |
TInt clusters = ((entries * KSizeOfFatDirEntry) + gBytesPerCluster-1) / gBytesPerCluster; |
|
1865 |
||
1866 |
//-- create "entries" FAT dir. entries by creating 8.3 files in upper case |
|
1867 |
while(entries--) |
|
1868 |
{ |
|
1869 |
CreateFatEntry(gSessionPath, EFalse); |
|
1870 |
} |
|
1871 |
||
1872 |
||
1873 |
r=TheFs.Volume(volInfo); |
|
149 | 1874 |
test_KErrNone(r); |
0 | 1875 |
if (gDiskType == EFat32) |
1876 |
volInfo.iSize -= gBytesPerCluster; // root dir is part of the 'size' |
|
1877 |
test.Printf(_L("volInfo.iSize = %ld\n"), volInfo.iSize); |
|
1878 |
test.Printf(_L("volInfo.iFree = %ld\n"), volInfo.iFree); |
|
1879 |
if (volInfo.iSize-volInfo.iFree!=clusters*gBytesPerCluster) |
|
1880 |
{ |
|
1881 |
DumpFat(); |
|
1882 |
DumpData(1, 200); |
|
1883 |
} |
|
1884 |
test(volInfo.iSize-volInfo.iFree==clusters*gBytesPerCluster); |
|
1885 |
||
1886 |
//-- create 1 FAT dir. entry |
|
1887 |
CreateFatEntry(gSessionPath, EFalse); |
|
1888 |
||
1889 |
r=TheFs.Volume(volInfo); |
|
149 | 1890 |
test_KErrNone(r); |
0 | 1891 |
if (gDiskType == EFat32) |
1892 |
volInfo.iSize -= gBytesPerCluster; // root dir is part of the 'size' |
|
1893 |
test.Printf(_L("volInfo.iSize = %ld\n"), volInfo.iSize); |
|
1894 |
test.Printf(_L("volInfo.iFree = %ld\n"), volInfo.iFree); |
|
1895 |
if (volInfo.iSize-volInfo.iFree!=(clusters+1)*gBytesPerCluster) |
|
1896 |
{ |
|
1897 |
DumpFat(); |
|
1898 |
DumpData(1, 200); |
|
1899 |
} |
|
1900 |
test(volInfo.iSize-volInfo.iFree==(clusters+1)*gBytesPerCluster); |
|
1901 |
||
1902 |
CFileMan* fMan=CFileMan::NewL(TheFs); |
|
1903 |
r=fMan->RmDir(gSessionPath); |
|
149 | 1904 |
test_KErrNone(r); |
0 | 1905 |
delete fMan; |
1906 |
r=TheFs.Volume(volInfo); |
|
149 | 1907 |
test_KErrNone(r); |
0 | 1908 |
if (gDiskType == EFat32) |
1909 |
volInfo.iSize -= gBytesPerCluster; // root dir is part of the 'size' |
|
1910 |
if (volInfo.iSize-volInfo.iFree!=0) |
|
1911 |
{ |
|
1912 |
DumpFat(); |
|
1913 |
DumpData(1, 200); |
|
1914 |
} |
|
1915 |
test(volInfo.iSize-volInfo.iFree==0); |
|
1916 |
} |
|
1917 |
||
1918 |
||
1919 |
// |
|
1920 |
// Writes a standard dos entry to the disk and checks that this can be read |
|
1921 |
// (in Unicode build) |
|
1922 |
// |
|
1923 |
static void TestUnicodeEntry() |
|
1924 |
{ |
|
1925 |
test.Next(_L("Test Unicode entry")); |
|
1926 |
||
1927 |
const TInt KDirEntrySize=32; |
|
1928 |
||
1929 |
FormatPack(); |
|
1930 |
DoReadBootSector(TheBootSector); |
|
1931 |
TInt pos=gRootDirStart; |
|
1932 |
||
1933 |
TBuf8<KDirEntrySize> buffer; |
|
1934 |
buffer.SetLength(KDirEntrySize); |
|
1935 |
buffer.FillZ(); |
|
1936 |
buffer.Replace(0,11,_L8("TEST1 ")); |
|
1937 |
||
1938 |
TInt r=TheDisk.Open(TheFs,CurrentDrive()); |
|
149 | 1939 |
test_KErrNone(r); |
0 | 1940 |
r=TheDisk.Write(pos,buffer); |
149 | 1941 |
test_KErrNone(r); |
0 | 1942 |
TheDisk.Close(); |
1943 |
||
1944 |
r=TheDir.Open(TheFs,_L("\\"),KEntryAttMaskSupported); |
|
149 | 1945 |
test_KErrNone(r); |
0 | 1946 |
r=TheDir.Read(TheEntry); |
149 | 1947 |
test_KErrNone(r); |
0 | 1948 |
test(TheEntry.iName==_L("TEST1")); |
1949 |
r=TheDir.Read(TheEntry); |
|
149 | 1950 |
test_Value(r, r == KErrEof); |
0 | 1951 |
TheDir.Close(); |
1952 |
||
1953 |
r=TheFs.SetSessionPath(_L("\\")); |
|
149 | 1954 |
test_KErrNone(r); |
0 | 1955 |
TEntry e; |
1956 |
r=TheFs.Entry(_L("TEST1"),e); |
|
1957 |
if(e.iName!=_L("TEST1")) |
|
1958 |
{ |
|
1959 |
test.Printf(_L("e.iName = %S\n"),&e.iName); |
|
1960 |
test(EFalse); |
|
1961 |
} |
|
1962 |
} |
|
1963 |
||
1964 |
static TUint32 GetValue(const TPtrC8& aData, TInt aOffset, TInt aLength) |
|
1965 |
{ |
|
1966 |
TUint32 val = 0; |
|
1967 |
while (aLength-- > 0) |
|
1968 |
val = val * 256 + aData[aOffset+aLength]; |
|
1969 |
return val; |
|
1970 |
} |
|
1971 |
||
1972 |
static void TestDiskIntegrity(TBool aTestOnly=EFalse) |
|
1973 |
// |
|
1974 |
// Does 'sanity checking' on the BPB and other areas |
|
1975 |
// |
|
1976 |
{ |
|
1977 |
if (!aTestOnly) |
|
1978 |
test.Next(_L("Test disk boot area integrity")); |
|
1979 |
TInt seclen = TheBootSector.BytesPerSector(); |
|
1980 |
HBufC8 *bootp = HBufC8::NewL(seclen); |
|
1981 |
TPtr8 boot((TUint8*)bootp, seclen); |
|
1982 |
HBufC8 *backp = HBufC8::NewL(seclen); |
|
1983 |
TPtr8 back((TUint8*)backp, seclen); |
|
1984 |
HBufC8 *infop = HBufC8::NewL(seclen); |
|
1985 |
TPtr8 info((TUint8*)bootp, seclen); |
|
1986 |
TInt r=TheDisk.Open(TheFs,CurrentDrive()); |
|
1987 |
if (r != KErrNone) |
|
1988 |
test.Printf(_L("Error %d opening on %C"), r, (TUint)gDriveToTest); |
|
149 | 1989 |
test_KErrNone(r); |
0 | 1990 |
r=TheDisk.Read(0, boot); |
149 | 1991 |
test_KErrNone(r); |
0 | 1992 |
TUint32 val = GetValue(boot, 510, 2); |
1993 |
RDebug::Print(_L("BPB magic number = 0x%X\n"), val); |
|
1994 |
test(aTestOnly || val == 0xAA55); |
|
1995 |
switch (boot[0]) |
|
1996 |
{ |
|
1997 |
case 0xEB: |
|
1998 |
RDebug::Print(_L("Jump %02X 0x%02X\n"), boot[0], boot[1]); |
|
1999 |
test(aTestOnly || boot[2] == 0x90); |
|
2000 |
break; |
|
2001 |
case 0xE9: |
|
2002 |
RDebug::Print(_L("Jump %02X 0x%02X%02X\n"), boot[0], boot[2], boot[1]); |
|
2003 |
break; |
|
2004 |
default: |
|
2005 |
RDebug::Print(_L("Invalid boot start: %02X %02X %02X\n"), boot[0], boot[1], boot[2]); |
|
2006 |
test(aTestOnly); |
|
2007 |
} |
|
2008 |
switch (gDiskType) |
|
2009 |
{ |
|
2010 |
case EFat12: |
|
2011 |
test(aTestOnly || TheBootSector.ReservedSectors() >= 1); |
|
2012 |
test.Printf(_L("BPB sector OK\n")); |
|
2013 |
break; |
|
2014 |
case EFat16: |
|
2015 |
test(aTestOnly || TheBootSector.ReservedSectors() >= 1); |
|
2016 |
test.Printf(_L("BPB sector OK\n")); |
|
2017 |
break; |
|
2018 |
default: |
|
2019 |
test(aTestOnly || TheBootSector.ReservedSectors() >= 1); |
|
2020 |
test(aTestOnly || TheBootSector.ReservedSectors() > TheBootSector.BkBootRecSector()); |
|
2021 |
test(aTestOnly || TheBootSector.ReservedSectors() > TheBootSector.FSInfoSectorNum()); |
|
2022 |
test.Printf(_L("BPB sector OK\n")); |
|
2023 |
if (TheBootSector.BkBootRecSector() > 0) |
|
2024 |
{ |
|
2025 |
r=TheDisk.Read(TheBootSector.BkBootRecSector()*seclen, back); |
|
2026 |
test(aTestOnly || r==KErrNone); |
|
2027 |
if (boot != back) |
|
2028 |
{ |
|
2029 |
RDebug::Print(_L("Boot sector != backup\n")); |
|
2030 |
RDebug::Print(_L("Sector 0: Boot sector\n")); |
|
2031 |
DumpHex(boot.Ptr(), seclen); |
|
2032 |
RDebug::Print(_L("Sector %d: Backup sector\n"), TheBootSector.BkBootRecSector()); |
|
2033 |
DumpHex(back.Ptr(), seclen); |
|
2034 |
test(aTestOnly); |
|
2035 |
} |
|
2036 |
test.Printf(_L("Backup BPB sector OK\n")); |
|
2037 |
} |
|
2038 |
else |
|
2039 |
test.Printf(_L("Backup BPB not present\n")); |
|
2040 |
if (TheBootSector.FSInfoSectorNum() > 0) |
|
2041 |
{ |
|
2042 |
r=TheDisk.Read(TheBootSector.FSInfoSectorNum()*seclen, info); |
|
2043 |
test(aTestOnly || r==KErrNone); |
|
2044 |
// Test the 'magic numbers' (signatures) as specified |
|
2045 |
val = GetValue(info, 0, 4); |
|
2046 |
RDebug::Print(_L("FSI signature 1 = 0x%X\n"), val); |
|
2047 |
test(aTestOnly || val == 0x41615252); |
|
2048 |
val = GetValue(info, 484, 4); |
|
2049 |
RDebug::Print(_L("FSI signature 2 = 0x%X\n"), val); |
|
2050 |
test(aTestOnly || val == 0x61417272); |
|
2051 |
val = GetValue(info, 508, 4); |
|
2052 |
RDebug::Print(_L("FSI magic number = 0x%X\n"), val); |
|
2053 |
test(aTestOnly || val == 0xAA550000); |
|
2054 |
// Check the last known free count and the next free cluster value. If |
|
2055 |
// they are not calculated they should be 0xFFFFFFFF, otherwise must be |
|
2056 |
// less than the number of clusters. |
|
2057 |
val = GetValue(info, 488, 4); |
|
2058 |
RDebug::Print(_L("FSI last free # = 0x%X\n"), val); |
|
2059 |
test(aTestOnly || val == 0xFFFFFFFF || val <= (TUint32)gClusterCount); |
|
2060 |
val = GetValue(info, 492, 4); |
|
2061 |
RDebug::Print(_L("FSI next free # = 0x%X\n"), val); |
|
2062 |
test(aTestOnly || val == 0xFFFFFFFF || val < (TUint32)gClusterCount); |
|
2063 |
test.Printf(_L("FSInfo sector OK\n")); |
|
2064 |
} |
|
2065 |
break; |
|
2066 |
} |
|
2067 |
TheDisk.Close(); |
|
2068 |
delete bootp; |
|
2069 |
delete backp; |
|
2070 |
delete infop; |
|
2071 |
} |
|
2072 |
||
2073 |
static void TestFATTableEntries() |
|
2074 |
// |
|
2075 |
// Test that reading/writing FAT table entries preserves the upper 4 bits of data. |
|
2076 |
// |
|
2077 |
{ |
|
2078 |
test.Next(_L("Test reading/writing FAT table entries")); |
|
2079 |
FormatPack(); |
|
2080 |
||
2081 |
TUint32 buf[16]; |
|
2082 |
TInt i=0; |
|
2083 |
TInt r=KErrNone; |
|
2084 |
||
2085 |
for (i=0; i <=7; i++) |
|
2086 |
{ |
|
2087 |
buf[i] = GetFatEntry(i); |
|
2088 |
} |
|
2089 |
||
2090 |
test.Printf(_L("First 8 FAT Entries before signature: \n")); |
|
2091 |
test.Printf(_L("%08x, %08x, %08x, %08x, %08x, %08x, %08x, %08x\n"), |
|
2092 |
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]); |
|
2093 |
||
2094 |
for (i=0; i <=7; i++) |
|
2095 |
{ |
|
2096 |
MarkFatEntry(i); |
|
2097 |
} |
|
2098 |
||
2099 |
for (i=0; i <=7; i++) |
|
2100 |
{ |
|
2101 |
buf[i] = GetFatEntry(i); |
|
2102 |
} |
|
2103 |
||
2104 |
test.Printf(_L("First 8 FAT Entries after signature: \n")); |
|
2105 |
test.Printf(_L("%08x, %08x, %08x, %08x, %08x, %08x, %08x, %08x\n"), |
|
2106 |
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]); |
|
2107 |
||
2108 |
||
2109 |
test(TheFile.Create(TheFs,_L("\\CORRUPT1.TMP"),EFileRead|EFileWrite)==KErrNone); |
|
2110 |
||
2111 |
TheBuffer.SetLength(2048); |
|
2112 |
Mem::Fill(&TheBuffer[0],2048,'X'); |
|
2113 |
||
2114 |
for(i=0; i<=20; i++) |
|
2115 |
{ |
|
2116 |
r = TheFile.Write(TheBuffer); |
|
149 | 2117 |
test_KErrNone(r); |
0 | 2118 |
} |
2119 |
||
2120 |
TheFile.Close(); |
|
2121 |
||
2122 |
for (i=8; i <=15; i++) |
|
2123 |
{ |
|
2124 |
buf[i] = GetFatEntry(i-8); |
|
2125 |
} |
|
2126 |
||
2127 |
test.Printf(_L("First 8 FAT Entries after file write: \n")); |
|
2128 |
test.Printf(_L("%08x, %08x, %08x, %08x, %08x, %08x, %08x, %08x\n"), |
|
2129 |
buf[8], buf[9], buf[10], buf[11], buf[12], buf[13], buf[14], buf[15]); |
|
2130 |
||
2131 |
for (i=0; i<=7; i++) |
|
2132 |
{ |
|
2133 |
test((buf[i] & 0xF0000000) == (buf[i+8] & 0xF0000000)); |
|
2134 |
} |
|
2135 |
||
2136 |
test.Printf(_L("Top 4 bits of first 8 FAT Entries have been preserved.\n")); |
|
2137 |
} |
|
2138 |
||
2139 |
||
2140 |
//----------------------------------------------------------------------------- |
|
2141 |
/** |
|
2142 |
Test that FAT[0] and FAT[1] just after formatting are compliant to FAT specs. |
|
2143 |
So that this test step shall be called just after the volume formatted. |
|
2144 |
*/ |
|
2145 |
static void TestFirst2FatEntries() |
|
2146 |
{ |
|
2147 |
test.Next(_L("Test FAT[0] and FAT[1] after formatting")); |
|
2148 |
||
2149 |
TInt nRes; |
|
2150 |
TBuf8<8> fat1Buf; //-- buffer for FAT[0] & FAT[1] read from 1st FAT copy |
|
2151 |
TBuf8<8> fatBufCurr; |
|
2152 |
||
2153 |
//-- read first several FAT entries from FAT1 |
|
2154 |
const TUint32 posFat1Start = TheBootSector.FirstFatSector() * TheBootSector.BytesPerSector(); |
|
2155 |
const TUint32 fatSize = TheBootSector.TotalFatSectors() * TheBootSector.BytesPerSector(); |
|
2156 |
const TInt numFATs = TheBootSector.NumberOfFats(); |
|
2157 |
||
2158 |
||
2159 |
nRes = MediaRawRead(TheFs, CurrentDrive(), posFat1Start, 8, fat1Buf); |
|
2160 |
test(nRes==KErrNone); |
|
2161 |
||
2162 |
switch(gDiskType) |
|
2163 |
{ |
|
2164 |
//----------- FAT12 --------------------- |
|
2165 |
case EFat12: |
|
2166 |
{ |
|
2167 |
fat1Buf.SetLength(3); //-- FAT12 entry occupies 1.5 bytes |
|
2168 |
test.Printf(_L("FAT12, first 2 entries: %x %x %x\n"), fat1Buf[0], fat1Buf[1], fat1Buf[2]); |
|
2169 |
||
2170 |
test(fat1Buf[0]==0xF8 && fat1Buf[1]==0xFF && fat1Buf[2]==0xFF); //-- see FAT specs, these are first 2 entries |
|
2171 |
||
2172 |
//-- test that all copies of FAT have the same values in FAT[0] & FAT[1] |
|
2173 |
for(TInt i=1; i<numFATs; ++i) |
|
2174 |
{ |
|
2175 |
nRes = MediaRawRead(TheFs, CurrentDrive(), posFat1Start + i*fatSize, 8, fatBufCurr); |
|
2176 |
test(nRes==KErrNone); |
|
2177 |
||
2178 |
fatBufCurr.SetLength(3); |
|
2179 |
||
2180 |
if(fatBufCurr != fat1Buf) |
|
2181 |
{ |
|
2182 |
test.Printf(_L("1st 2 FAT entries in FAT#%d are different from FAT1!\n"), i); |
|
2183 |
test(0); |
|
2184 |
} |
|
2185 |
} |
|
2186 |
||
2187 |
||
2188 |
} |
|
2189 |
break; |
|
2190 |
||
2191 |
//----------- FAT16 --------------------- |
|
2192 |
case EFat16: |
|
2193 |
{ |
|
2194 |
typedef TUint16 TFat16Entry; |
|
2195 |
||
2196 |
fat1Buf.SetLength(2*sizeof(TFat16Entry)); |
|
2197 |
const TFat16Entry* pFat = (const TFat16Entry*)fat1Buf.Ptr(); |
|
2198 |
||
2199 |
const TFat16Entry fatEntry_0 = pFat[0]; //-- do not mask entries |
|
2200 |
const TFat16Entry fatEntry_1 = pFat[1]; //-- do not mask entries |
|
2201 |
||
2202 |
test.Printf(_L("FAT16[0]=0x%x, FAT16[1]=0x%x\n"), fatEntry_0, fatEntry_1); |
|
2203 |
||
2204 |
test(fatEntry_0 == 0xFFF8); //-- see FAT specs |
|
2205 |
test(fatEntry_1 == 0xFFFF); //-- the volume shall be clean just after the formatting. It can be 0x7FFF if a write to the volume occured. |
|
2206 |
||
2207 |
//-- test that all copies of FAT have the same values in FAT[0] & FAT[1] |
|
2208 |
for(TInt i=1; i<numFATs; ++i) |
|
2209 |
{ |
|
2210 |
nRes = MediaRawRead(TheFs, CurrentDrive(), posFat1Start + i*fatSize, 8, fatBufCurr); |
|
2211 |
test(nRes==KErrNone); |
|
2212 |
||
2213 |
fatBufCurr.SetLength(2*sizeof(TFat16Entry)); |
|
2214 |
||
2215 |
if(fatBufCurr != fat1Buf) |
|
2216 |
{ |
|
2217 |
test.Printf(_L("1st 2 FAT entries in FAT#%d are different from FAT1!\n"), i); |
|
2218 |
test(0); |
|
2219 |
} |
|
2220 |
} |
|
2221 |
||
2222 |
} |
|
2223 |
break; |
|
2224 |
||
2225 |
//----------- FAT32 --------------------- |
|
2226 |
case EFat32: |
|
2227 |
{ |
|
2228 |
typedef TUint32 TFat32Entry; |
|
2229 |
||
2230 |
fat1Buf.SetLength(2*sizeof(TFat32Entry)); |
|
2231 |
const TFat32Entry* pFat = (const TFat32Entry*)fat1Buf.Ptr(); |
|
2232 |
||
2233 |
const TFat32Entry fatEntry_0 = pFat[0]; //-- do not mask entries |
|
2234 |
const TFat32Entry fatEntry_1 = pFat[1]; //-- do not mask entries |
|
2235 |
||
2236 |
test.Printf(_L("FAT32[0]=0x%x, FAT32[1]=0x%x\n"), fatEntry_0, fatEntry_1); |
|
2237 |
||
2238 |
test(fatEntry_0 == 0x0FFFFFF8); //-- see FAT specs |
|
2239 |
test(fatEntry_1 == 0x0FFFFFFF); //-- the volume shall be clean just after the formatting. It can be 0x07FFFFFF if a write to the volume occured. |
|
2240 |
||
2241 |
//-- test that all copies of FAT have the same values in FAT[0] & FAT[1] |
|
2242 |
for(TInt i=1; i<numFATs; ++i) |
|
2243 |
{ |
|
2244 |
nRes = MediaRawRead(TheFs, CurrentDrive(), posFat1Start + i*fatSize, 8, fatBufCurr); |
|
2245 |
test(nRes==KErrNone); |
|
2246 |
||
2247 |
fatBufCurr.SetLength(2*sizeof(TFat32Entry)); |
|
2248 |
||
2249 |
if(fatBufCurr != fat1Buf) |
|
2250 |
{ |
|
2251 |
test.Printf(_L("1st 2 FAT entries in FAT#%d are different from FAT1!\n"), i); |
|
2252 |
test(0); |
|
2253 |
} |
|
2254 |
} |
|
2255 |
} |
|
2256 |
break; |
|
2257 |
||
2258 |
default: |
|
2259 |
test(0); |
|
2260 |
break; |
|
2261 |
||
2262 |
};//switch(gDiskType) |
|
2263 |
||
2264 |
||
2265 |
||
2266 |
} |
|
2267 |
||
2268 |
||
2269 |
/** |
|
2270 |
Exhaustive test of Data alignmemnt calculation |
|
2271 |
in this code the function |
|
2272 |
TInt TFatAlignment::AdjustFirstDataSectorAlignment(TInt aBlockSize) |
|
2273 |
should be exactly the same as |
|
2274 |
TInt CFatFormatCB::AdjustFirstDataSectorAlignment(TInt aBlockSize) |
|
2275 |
*/ |
|
2276 |
class TFatAlignment |
|
2277 |
{ |
|
2278 |
public: |
|
2279 |
enum {KDefFatResvdSec = 1, KDefFat32ResvdSec = 32}; ///< default number of FAT32 reserved sectors |
|
2280 |
public: |
|
2281 |
TFatAlignment(); |
|
2282 |
void Init(TBool aFat32, TInt aNumberOfFats, TInt aMaxDiskSectors, TInt aSectorsPerCluster, TInt aRootDirEntries); |
|
2283 |
TUint32 MaxFat32Sectors() const; |
|
2284 |
TInt MaxFat16Sectors() const; |
|
2285 |
TInt MaxFat12Sectors() const; |
|
2286 |
TUint32 RootDirSectors() const; |
|
2287 |
TInt FirstDataSector() const; |
|
2288 |
TBool Is32BitFat() const; |
|
2289 |
TBool Is16BitFat() const; |
|
2290 |
||
2291 |
TInt AdjustFirstDataSectorAlignment(TInt aBlockSize); |
|
2292 |
void Display(); |
|
2293 |
public: |
|
2294 |
TInt iBytesPerSector; |
|
2295 |
TInt iNumberOfFats; |
|
2296 |
TInt iMaxDiskSectors; |
|
2297 |
TInt iSectorsPerCluster; |
|
2298 |
TInt iReservedSectors; |
|
2299 |
TInt iSectorsPerFat; |
|
2300 |
TInt iRootDirEntries; |
|
2301 |
||
2302 |
TBool iFat32; // 0 = FAT16, 1 = FAT32 |
|
2303 |
TInt iMaxIterations; |
|
2304 |
}; |
|
2305 |
||
2306 |
TFatAlignment::TFatAlignment() |
|
2307 |
{ |
|
2308 |
iMaxIterations = 0; |
|
2309 |
} |
|
2310 |
||
2311 |
void TFatAlignment::Init(TBool aFat32, TInt aNumberOfFats, TInt aMaxDiskSectors, TInt aSectorsPerCluster, TInt aRootDirEntries) |
|
2312 |
{ |
|
2313 |
iBytesPerSector = 512; |
|
2314 |
iFat32 = aFat32; |
|
2315 |
iNumberOfFats = aNumberOfFats; |
|
2316 |
iMaxDiskSectors = aMaxDiskSectors; |
|
2317 |
iSectorsPerCluster = aSectorsPerCluster; |
|
2318 |
iRootDirEntries = aRootDirEntries; |
|
2319 |
||
2320 |
iReservedSectors = iFat32 ? KDefFat32ResvdSec : KDefFatResvdSec; |
|
2321 |
iSectorsPerFat = iFat32 ? MaxFat32Sectors() : MaxFat16Sectors(); |
|
2322 |
} |
|
2323 |
||
2324 |
void TFatAlignment::Display() |
|
2325 |
{ |
|
2326 |
RDebug::Print(_L("iFat32 %u iNumberOfFats %u,iMaxDiskSectors %u,iSectorsPerCluster %u,iReservedSectors %u,iSectorsPerFat %u, iRootDirEntries %u, FirstDataSector %08X"), |
|
2327 |
iFat32, |
|
2328 |
iNumberOfFats, |
|
2329 |
iMaxDiskSectors, |
|
2330 |
iSectorsPerCluster, |
|
2331 |
iReservedSectors, |
|
2332 |
iSectorsPerFat, |
|
2333 |
iRootDirEntries, |
|
2334 |
FirstDataSector()); |
|
2335 |
} |
|
2336 |
||
2337 |
TInt TFatAlignment::MaxFat16Sectors() const |
|
2338 |
{ |
|
2339 |
||
2340 |
TInt fatSizeInBytes=(2*iMaxDiskSectors)/iSectorsPerCluster+(iBytesPerSector-1); |
|
2341 |
return(fatSizeInBytes/iBytesPerSector); |
|
2342 |
} |
|
2343 |
||
2344 |
||
2345 |
TInt TFatAlignment::MaxFat12Sectors() const |
|
2346 |
{ |
|
2347 |
TInt maxDiskClusters=iMaxDiskSectors/iSectorsPerCluster; |
|
2348 |
TInt fatSizeInBytes=maxDiskClusters+(maxDiskClusters>>1)+(iBytesPerSector-1); |
|
2349 |
return(fatSizeInBytes/iBytesPerSector); |
|
2350 |
} |
|
2351 |
||
2352 |
||
2353 |
TUint32 TFatAlignment::MaxFat32Sectors() const |
|
2354 |
{ |
|
2355 |
TUint32 calc1 = iMaxDiskSectors - iReservedSectors; |
|
2356 |
TUint32 calc2 = (256 * iSectorsPerCluster) + iNumberOfFats; |
|
2357 |
calc2 = calc2 >> 1; |
|
2358 |
return (calc1 + (calc2 - 1))/calc2; |
|
2359 |
} |
|
2360 |
||
2361 |
||
2362 |
/** |
|
2363 |
@return Number of sectors in root directory. 0 for FAT32 |
|
2364 |
*/ |
|
2365 |
TUint32 TFatAlignment::RootDirSectors() const |
|
2366 |
{ |
|
2367 |
const TInt KSizeOfFatDirEntry =32; ///< Size in bytes of a Fat directry entry |
|
2368 |
||
2369 |
return ( (iRootDirEntries * KSizeOfFatDirEntry + (iBytesPerSector-1)) / iBytesPerSector ); |
|
2370 |
} |
|
2371 |
||
2372 |
TInt TFatAlignment::FirstDataSector() const |
|
2373 |
{ |
|
2374 |
return( iReservedSectors + iNumberOfFats * iSectorsPerFat + RootDirSectors()); |
|
2375 |
} |
|
2376 |
||
2377 |
TBool TFatAlignment::Is32BitFat() const |
|
2378 |
{ |
|
2379 |
return iFat32; |
|
2380 |
} |
|
2381 |
||
2382 |
TBool TFatAlignment::Is16BitFat() const |
|
2383 |
{ |
|
2384 |
return !iFat32; |
|
2385 |
} |
|
2386 |
||
2387 |
#define __PRINT1 |
|
2388 |
||
2389 |
||
2390 |
// AdjustFirstDataSectorAlignment() |
|
2391 |
// Attempts to align the first data sector on an erase block boundary by modifying the |
|
2392 |
// number of reserved sectors. |
|
2393 |
TInt TFatAlignment::AdjustFirstDataSectorAlignment(TInt aEraseBlockSizeInSectors) |
|
2394 |
{ |
|
2395 |
const TBool bFat16 = Is16BitFat(); |
|
2396 |
const TBool bFat32 = Is32BitFat(); |
|
2397 |
||
2398 |
// Save these 2 values in the event of a convergence failure; this should |
|
2399 |
// hopefully never happen, but we will cater for this in release mode to be safe, |
|
2400 |
TInt reservedSectorsSaved = iReservedSectors; |
|
2401 |
TInt sectorsPerFatSaved = iSectorsPerFat; |
|
2402 |
||
2403 |
TInt reservedSectorsOld = 0; |
|
2404 |
||
2405 |
// zero for FAT32 |
|
2406 |
TInt rootDirSectors = (iRootDirEntries * KSizeOfFatDirEntry + (iBytesPerSector-1)) / iBytesPerSector; |
|
2407 |
TInt fatSectors = 0; |
|
2408 |
||
2409 |
TInt KMaxIterations = 10; |
|
2410 |
TInt n; |
|
2411 |
for (n=0; n<KMaxIterations && reservedSectorsOld != iReservedSectors; n++) |
|
2412 |
{ |
|
2413 |
reservedSectorsOld = iReservedSectors; |
|
2414 |
||
2415 |
iSectorsPerFat = bFat32 ? MaxFat32Sectors() : bFat16 ? MaxFat16Sectors() : MaxFat12Sectors(); |
|
2416 |
||
2417 |
fatSectors = iSectorsPerFat * iNumberOfFats; |
|
2418 |
||
2419 |
// calculate number of blocks |
|
2420 |
TInt nBlocks = (iReservedSectors + fatSectors + rootDirSectors + aEraseBlockSizeInSectors-1) / aEraseBlockSizeInSectors; |
|
2421 |
||
2422 |
iReservedSectors = (nBlocks * aEraseBlockSizeInSectors) - rootDirSectors - fatSectors; |
|
2423 |
} |
|
2424 |
||
2425 |
ASSERT(iReservedSectors >= (TInt) (bFat32 ? KDefFat32ResvdSec : KDefFatResvdSec)); |
|
2426 |
||
2427 |
if ((FirstDataSector() & (aEraseBlockSizeInSectors-1)) == 0) |
|
2428 |
{ |
|
2429 |
return KErrNone; |
|
2430 |
} |
|
2431 |
else |
|
2432 |
{ |
|
2433 |
iReservedSectors = reservedSectorsSaved; |
|
2434 |
iSectorsPerFat = sectorsPerFatSaved; |
|
2435 |
return KErrGeneral; |
|
2436 |
} |
|
2437 |
} |
|
2438 |
||
2439 |
||
2440 |
void TestFirstDataSectorAlignment() |
|
2441 |
{ |
|
2442 |
test.Start(_L("Exhaustive test of data alignment calculation")); |
|
2443 |
||
2444 |
typedef struct |
|
2445 |
{ |
|
2446 |
TInt iNumberOfFats; |
|
2447 |
TInt iMaxDiskSectors; |
|
2448 |
TInt iSectorsPerCluster; |
|
2449 |
TInt iBlockSize; |
|
2450 |
TInt iRootDirEntries; |
|
2451 |
} STestVal; |
|
2452 |
STestVal testVals[] = |
|
2453 |
{ |
|
2454 |
{2, 15720448, 32, 16*1024, 0}, // 4GB MoviNand, cluster size = 16K |
|
2455 |
{2, 106496, 2, 2048, 512}, // diskSize = 54MB, = block size = 1MB |
|
2456 |
{2, 1048576, 8, 2048, 0}, // diskSize = 512 MB |
|
2457 |
{2, 1048578, 8, 2048, 0}, // Doesn't converge with original algorithm |
|
2458 |
}; |
|
2459 |
||
2460 |
TFatAlignment fatAlignment; |
|
2461 |
TInt numOfTests = sizeof(testVals) / sizeof(STestVal); |
|
2462 |
for (TInt n=0; n<numOfTests; n++) |
|
2463 |
{ |
|
2464 |
STestVal& testVal = testVals[n]; |
|
2465 |
TBool fat32 = testVal.iMaxDiskSectors >= 1048576; |
|
2466 |
||
2467 |
fatAlignment.Init( |
|
2468 |
fat32, |
|
2469 |
testVal.iNumberOfFats, |
|
2470 |
testVal.iMaxDiskSectors, |
|
2471 |
testVal.iSectorsPerCluster, |
|
2472 |
testVal.iRootDirEntries); |
|
2473 |
TInt r = fatAlignment.AdjustFirstDataSectorAlignment(testVal.iBlockSize); |
|
149 | 2474 |
test_KErrNone(r); |
0 | 2475 |
fatAlignment.Display(); |
2476 |
} |
|
2477 |
||
2478 |
const TInt64 KOneMByte = 1024*1024; |
|
2479 |
const TInt64 KOneGByte = 1024*KOneMByte; |
|
2480 |
const TInt64 KLastSizeToTest = 32*KOneGByte; |
|
2481 |
TInt iteration=0; |
|
2482 |
TInt64 diskSize; |
|
2483 |
||
2484 |
||
2485 |
||
2486 |
TInt successes = 0; |
|
2487 |
TInt failures = 0; |
|
2488 |
||
2489 |
for (iteration=0, diskSize = 16*KOneMByte; diskSize < KLastSizeToTest; iteration++, diskSize+=512) |
|
2490 |
{ |
|
2491 |
TInt diskSizeInSectors = (TInt) (diskSize >> 9); |
|
2492 |
||
2493 |
const TInt KMaxFAT16Entries=0xFFF0; ///< Maximum number of clusters in a Fat16 Fat table, 65520 |
|
2494 |
||
2495 |
TBool fat32 = EFalse; |
|
2496 |
TInt numberOfFats = 2; |
|
2497 |
TInt rootDirEntries; |
|
2498 |
TInt sectorsPerCluster; |
|
2499 |
TInt blockSizeInSectors = 32; // 16K for FAT16 |
|
2500 |
||
2501 |
if (diskSizeInSectors<4096) // < 2MB |
|
2502 |
{ |
|
2503 |
rootDirEntries=128; |
|
2504 |
sectorsPerCluster=1; |
|
2505 |
} |
|
2506 |
else if (diskSizeInSectors<8400) // < 4MB |
|
2507 |
{ |
|
2508 |
rootDirEntries=256; |
|
2509 |
sectorsPerCluster=2; |
|
2510 |
} |
|
2511 |
else if (diskSizeInSectors<16384) // < 8MB |
|
2512 |
{ |
|
2513 |
rootDirEntries=512; |
|
2514 |
sectorsPerCluster=4; |
|
2515 |
} |
|
2516 |
else if (diskSizeInSectors<32680) // < 16MB |
|
2517 |
{ |
|
2518 |
rootDirEntries=512; |
|
2519 |
sectorsPerCluster=8; |
|
2520 |
} |
|
2521 |
else if(diskSizeInSectors<1048576) // >= 16Mb - FAT16 < (1048576) 512MB |
|
2522 |
{ |
|
2523 |
TInt minSectorsPerCluster=(diskSizeInSectors+KMaxFAT16Entries-1)/KMaxFAT16Entries; |
|
2524 |
rootDirEntries=512; |
|
2525 |
sectorsPerCluster=1; |
|
2526 |
while (minSectorsPerCluster>sectorsPerCluster) |
|
2527 |
sectorsPerCluster<<=1; |
|
2528 |
} |
|
2529 |
else //use FAT32 |
|
2530 |
{ |
|
2531 |
rootDirEntries=0; //this is always the case for fat32 |
|
2532 |
if(diskSizeInSectors < 16777216) //8GB in 512byte sectors |
|
2533 |
sectorsPerCluster=8; |
|
2534 |
else if(diskSizeInSectors < 33554432) //16GB in 512byte sectors |
|
2535 |
sectorsPerCluster=16; |
|
2536 |
else if(diskSizeInSectors < 67108864) //32GB in 512byte sectors |
|
2537 |
sectorsPerCluster=32; |
|
2538 |
else |
|
2539 |
sectorsPerCluster=64; //Anything >= 32GB uses a 32K cluster size |
|
2540 |
blockSizeInSectors = 2048; // 1MB for FAT32 |
|
2541 |
fat32 = ETrue; |
|
2542 |
} |
|
2543 |
||
2544 |
||
2545 |
fatAlignment.Init( |
|
2546 |
fat32, |
|
2547 |
numberOfFats, |
|
2548 |
diskSizeInSectors, |
|
2549 |
sectorsPerCluster, |
|
2550 |
rootDirEntries); |
|
2551 |
TInt r = fatAlignment.AdjustFirstDataSectorAlignment(blockSizeInSectors); |
|
2552 |
if (r == KErrNone) |
|
2553 |
successes++; |
|
2554 |
else |
|
2555 |
failures++; |
|
2556 |
||
2557 |
||
2558 |
// if (diskSize % 0x08000000 == 0) |
|
2559 |
// { |
|
2560 |
// RDebug::Print(_L("Iter %10lX of %10lX"), diskSize, KLastSizeToTest); |
|
2561 |
// fatAlignment.Display(); |
|
2562 |
// } |
|
2563 |
} |
|
2564 |
RDebug::Print(_L("Total iterations %u"), iteration); |
|
2565 |
RDebug::Print(_L("Max loop count %u"), fatAlignment.iMaxIterations); |
|
2566 |
RDebug::Print(_L("successes %d failures %d, success rate %ld"), |
|
2567 |
successes, failures, (TInt64(successes) * 100) / TInt64(successes + failures)); |
|
2568 |
test (failures == 0); |
|
2569 |
||
2570 |
} |
|
2571 |
||
2572 |
||
2573 |
static void TestZeroLengthFile() |
|
2574 |
// |
|
2575 |
// Test what happens if you write more to a zero length file than |
|
2576 |
// will fit in the filesystem. |
|
2577 |
// |
|
2578 |
{ |
|
2579 |
test.Next(_L("Test behaviour of extending a zero length file")); |
|
2580 |
||
2581 |
FormatPack(); |
|
2582 |
||
2583 |
TInt r; |
|
2584 |
||
2585 |
TVolumeInfo volInfo; |
|
2586 |
r=TheFs.Volume(volInfo); |
|
149 | 2587 |
test_KErrNone(r); |
0 | 2588 |
|
2589 |
TInt64 spaceToUse = volInfo.iFree - gBytesPerCluster; // whole disk except 1 cluster |
|
2590 |
||
2591 |
test.Printf(_L("spaceToUse %ld gClusterCount %d gBytesPerCluster %d\n"), spaceToUse, gClusterCount, gBytesPerCluster); |
|
2592 |
test.Printf(_L("Before fill, volInfo.iSize %ld volInfo.iFree %ld\n"), volInfo.iSize, volInfo.iFree); |
|
2593 |
||
2594 |
RFile f; |
|
2595 |
||
2596 |
TInt tempfiles = 0; |
|
2597 |
while (spaceToUse > K1GigaByte) |
|
2598 |
{ |
|
2599 |
TFileName tempName; |
|
2600 |
r=f.Temp(TheFs,_L("\\"),tempName,EFileRead|EFileWrite); |
|
149 | 2601 |
test_KErrNone(r); |
0 | 2602 |
r=f.SetSize(K1GigaByte); |
149 | 2603 |
test_KErrNone(r); |
0 | 2604 |
f.Close(); |
2605 |
spaceToUse -= K1GigaByte; |
|
2606 |
tempfiles++; |
|
2607 |
} |
|
2608 |
||
2609 |
r=f.Replace(TheFs,_L("\\USESPACE.TMP"),EFileRead|EFileWrite); |
|
149 | 2610 |
test_KErrNone(r); |
0 | 2611 |
r=f.SetSize((TInt)spaceToUse); |
149 | 2612 |
test_KErrNone(r); |
0 | 2613 |
f.Close(); |
2614 |
||
2615 |
r=TheFs.Volume(volInfo); |
|
149 | 2616 |
test_KErrNone(r); |
0 | 2617 |
test.Printf(_L("After fill, volInfo.iSize %ld volInfo.iFree %ld\n"), volInfo.iSize, volInfo.iFree); |
2618 |
||
2619 |
test(volInfo.iFree==gBytesPerCluster); // check we have 1 cluster free |
|
2620 |
||
2621 |
r=f.Replace(TheFs,_L("\\FILE.TMP"),EFileRead|EFileWrite); |
|
149 | 2622 |
test_KErrNone(r); |
0 | 2623 |
r=f.SetSize(2*gBytesPerCluster); // 2 clusters (will fail since there's not space) |
149 | 2624 |
test_Value(r, r == KErrDiskFull); |
0 | 2625 |
f.Close(); |
2626 |
||
2627 |
r=TheFs.Volume(volInfo); |
|
149 | 2628 |
test_KErrNone(r); |
0 | 2629 |
test(volInfo.iFree==gBytesPerCluster); // check we still have 1 cluster free |
2630 |
||
2631 |
r=f.Replace(TheFs,_L("\\USESPACE.TMP"),EFileRead|EFileWrite); // truncate file to 0 |
|
149 | 2632 |
test_KErrNone(r); |
0 | 2633 |
f.Close(); |
2634 |
||
2635 |
r=TheFs.Volume(volInfo); |
|
149 | 2636 |
test_KErrNone(r); |
0 | 2637 |
test(volInfo.iFree==(spaceToUse+gBytesPerCluster)); // check we've freed up the space from USESPACE plus one cluster |
2638 |
||
2639 |
||
2640 |
test(TheBootSector.IsValid()); //-- TheBootSector is read after formatting |
|
2641 |
TInt64 rootDirpos = gRootDirStart; |
|
2642 |
||
2643 |
||
2644 |
//-- read 1 sector of the root dir. |
|
2645 |
r = MediaRawRead(TheFs, CurrentDrive(), rootDirpos, TheBootSector.BytesPerSector(), TheBuffer); |
|
149 | 2646 |
test_KErrNone(r); |
0 | 2647 |
|
2648 |
const TFatDirEntry* pE=(TFatDirEntry*)TheBuffer.Ptr(); |
|
2649 |
while (tempfiles-- > 0) |
|
2650 |
{ |
|
2651 |
while (pE->IsVFatEntry()) |
|
2652 |
pE++; |
|
2653 |
test(pE->Size()==(TUint)K1GigaByte); |
|
2654 |
pE++; |
|
2655 |
} |
|
2656 |
||
2657 |
while (pE->IsVFatEntry()) |
|
2658 |
pE++; |
|
2659 |
||
2660 |
TBuf8<15> name=pE->Name(); |
|
2661 |
test(name==_L8("USESPACETMP")); |
|
2662 |
test(pE->StartCluster()==0); |
|
2663 |
||
2664 |
pE++; |
|
2665 |
while (pE->IsVFatEntry()) |
|
2666 |
pE++; |
|
2667 |
||
2668 |
name=pE->Name(); |
|
2669 |
test(name==_L8("FILE TMP")); |
|
2670 |
test(pE->StartCluster()==0); |
|
2671 |
||
2672 |
FormatPack(); |
|
2673 |
||
2674 |
} |
|
2675 |
||
2676 |
||
2677 |
// |
|
2678 |
// Call tests that may leave |
|
2679 |
// |
|
2680 |
void CallTestsL() |
|
2681 |
{ |
|
2682 |
||
2683 |
//-- init random generator |
|
2684 |
rndSeed = Math::Random(); |
|
2685 |
||
2686 |
//-- set up console output |
|
2687 |
Fat_Test_Utils::SetConsole(test.Console()); |
|
2688 |
||
2689 |
||
2690 |
||
2691 |
TInt drvNum; |
|
2692 |
TInt r=TheFs.CharToDrive(gDriveToTest,drvNum); |
|
149 | 2693 |
test_KErrNone(r); |
0 | 2694 |
|
2695 |
if (!Is_Fat(TheFs,drvNum)) |
|
2696 |
{ |
|
2697 |
test.Printf(_L("CallTestsL: Skipped: test requires FAT filesystem\n")); |
|
2698 |
return; |
|
2699 |
} |
|
2700 |
||
2701 |
||
2702 |
//-- print drive information |
|
2703 |
PrintDrvInfo(TheFs, drvNum); |
|
2704 |
||
2705 |
// check this is not the internal ram drive |
|
2706 |
TVolumeInfo v; |
|
2707 |
r=TheFs.Volume(v, drvNum); |
|
149 | 2708 |
test_KErrNone(r); |
0 | 2709 |
TBool isRamDrive = v.iDrive.iMediaAtt&KMediaAttVariableSize; |
2710 |
||
2711 |
gSessionPath[0] = (TText)gDriveToTest; |
|
2712 |
// verify that the drive is large enough for proper testing |
|
2713 |
if (v.iSize<512*1024) |
|
2714 |
{ |
|
2715 |
test.Printf(_L("CallTestsL: Skipped: test not supported on drives smaller than 512 KB\n")); |
|
2716 |
return; |
|
2717 |
} |
|
2718 |
||
2719 |
FormatPack(); |
|
2720 |
DumpBootSector(); |
|
2721 |
||
2722 |
test.Printf(_L("TotalSectors = %u (%u bytes)\n"),gTotalSectors,gTotalSectors*TheBootSector.BytesPerSector()); |
|
2723 |
test.Printf(_L("Sector size = %u\n"),TheBootSector.BytesPerSector()); |
|
2724 |
test.Printf(_L("Cluster size = %u sectors\n"),TheBootSector.SectorsPerCluster()); |
|
2725 |
test.Printf(_L("Alloc unit = %u\n"), gBytesPerCluster); |
|
2726 |
test.Printf(_L("Fat is %u bit\n"), gFatBits); |
|
2727 |
User::After(200000); // 1/5 secs |
|
2728 |
||
2729 |
// set up buffers |
|
2730 |
TInt bufLen = 16*gBytesPerCluster; |
|
2731 |
if (bufLen < 16*1024) |
|
2732 |
bufLen = 16*1024; |
|
2733 |
pBuffer1=HBufC8::NewL(bufLen); |
|
2734 |
pBuffer2=HBufC8::NewL(bufLen); |
|
2735 |
||
2736 |
if (pBuffer1==NULL || pBuffer2==NULL) |
|
2737 |
Error(_L("OOM"),KErrNoMemory); |
|
2738 |
||
2739 |
||
2740 |
pBuffer1->Des().Zero(); |
|
2741 |
pBuffer1->Des().SetLength(bufLen); |
|
2742 |
||
2743 |
pBuffer2->Des().Zero(); |
|
2744 |
pBuffer2->Des().SetLength(bufLen); |
|
2745 |
||
2746 |
if (isRamDrive) |
|
2747 |
{ |
|
2748 |
User::After(200000); // 1/5 secs |
|
2749 |
test.Printf(_L("*** Tests not valid on internal ram drive %C:\n"), (TUint)gDriveToTest); |
|
2750 |
User::After(200000); // 1/5 secs |
|
2751 |
} |
|
2752 |
else |
|
2753 |
{ |
|
2754 |
TestZeroLengthFile(); |
|
2755 |
||
2756 |
#if defined(__WINS__) |
|
2757 |
TestFirstDataSectorAlignment(); |
|
2758 |
#endif |
|
2759 |
||
2760 |
TestFirst2FatEntries(); |
|
2761 |
||
2762 |
TestDiskIntegrity(); |
|
2763 |
||
2764 |
TestBounds(); |
|
2765 |
TestUnicodeEntry(); |
|
2766 |
||
2767 |
TestClusters(); |
|
2768 |
||
2769 |
TestClusterAllocation(); |
|
2770 |
||
2771 |
||
2772 |
TestParentDir(EFalse); // Test without VFAT entries |
|
2773 |
TestParentDir(ETrue); // Test with VFAT entries |
|
2774 |
||
2775 |
TestRoot(); |
|
2776 |
TestVolumeSize(); |
|
2777 |
TestFATTableEntries(); |
|
2778 |
||
2779 |
FormatPack(); |
|
2780 |
||
2781 |
} |
|
2782 |
delete pBuffer1; |
|
2783 |
delete pBuffer2; |
|
2784 |
} |
|
2785 |
||
2786 |
||
2787 |
/** |
|
2788 |
Generate unique temp file name in upper (FAT entry) or lower case (2 VFAT entries) |
|
2789 |
@param aFN descriptor for the file name |
|
2790 |
@param aUpperCase if ETrue, the file name will be in upper case, in a lower case otherwise. |
|
2791 |
||
2792 |
*/ |
|
2793 |
void GenerateTmpFileName(TDes& aFN, TBool aUpperCase) |
|
2794 |
{ |
|
2795 |
const TInt rnd = Math::Rand(rndSeed); |
|
2796 |
||
2797 |
aFN.Format(_L("%08x.tmp"), rnd); |
|
2798 |
||
2799 |
if(aUpperCase) |
|
2800 |
aFN.UpperCase(); |
|
2801 |
else |
|
2802 |
aFN.LowerCase(); |
|
2803 |
||
2804 |
} |
|
2805 |
||
2806 |
/** |
|
2807 |
Create FAT or VFAT entry in a speciified directory |
|
2808 |
||
2809 |
@param aDir specifies the directory where enntry will be created |
|
2810 |
@param aVFatEntry if true, VFAT entry will be created (2 FAT entries, actually), otherwise - FAT entry |
|
2811 |
@param apFileName in !=NULL there will be placed the name of the file created |
|
2812 |
*/ |
|
2813 |
void CreateFatEntry(const TDesC& aDir, TBool aVFatEntry, TDes *apFileName/*=NULL*/) |
|
2814 |
{ |
|
2815 |
TFileName tmpFN; |
|
2816 |
RFile file; |
|
2817 |
TInt nRes; |
|
2818 |
||
2819 |
do |
|
2820 |
{ |
|
2821 |
GenerateTmpFileName(tmpFN, !aVFatEntry); //-- generates 8.3 file name FAT (1 entry) or VFAT (2 entries) |
|
2822 |
tmpFN.Insert(0, aDir); |
|
2823 |
||
2824 |
nRes = file.Create(TheFs, tmpFN, EFileRead|EFileWrite); |
|
2825 |
||
2826 |
if(nRes == KErrAlreadyExists) |
|
2827 |
continue; //-- current random name generator isn't perfect... |
|
2828 |
||
2829 |
if(nRes != KErrNone) |
|
2830 |
Error(_L("Error creating a file"),nRes); |
|
2831 |
||
2832 |
file.Close(); |
|
2833 |
||
2834 |
}while(nRes != KErrNone); |
|
2835 |
||
2836 |
if(apFileName) |
|
2837 |
*apFileName = tmpFN; |
|
2838 |
||
2839 |
} |
|
2840 |
||
2841 |