Update contrib.
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Tests for the blockmap API. The blockmap API enumerates the resources
15 // used by a file depending upon the type of media on which the file
17 // 002 Test Initialise error checking
18 // 003 Test processing of user-side block map into extent list
19 // 004 Test processing of user-side block map into extent list, block size > read unit size
20 // 005 Test Read error checking
22 // Test BlockMap API functionality.
26 //! @SYMTestCaseID KBASE-T_BLOCKMAP-0337
29 //! @SYMTestCaseDesc Demand Paging Blockmap tests
30 //! @SYMTestActions 001 Unit tests the TKernBlockMap class
31 //! @SYMTestExpectedResults All tests should pass.
32 //! @SYMTestPriority High
33 //! @SYMTestStatus Implemented
43 RTest test( _L("T_BLOCKMAP") );
45 const TInt KReadBufferSize = 1024;
46 const TInt KMaxFragmentSize = 400;
47 const TInt KMaxFileSize = 10000;
49 TInt RamFatDrive = -1;
50 TInt RemovableFatDrive = -1;
51 TInt InternalRemovableFatDrive = -1;
53 TBool Pageable = EFalse;
54 TBool Finished = EFalse;
61 EDriveInternalRemovable
64 _LIT( KTestFile, "Z:\\TEST\\T_FILE.CPP");
65 _LIT( KTestFileFAT, "Z:\\Multiple\\T_file.cpp");
66 _LIT( KTestFileName, "T_FILE.CPP");
67 _LIT( KFragmentedFileName1, "FRAG1.TXT");
68 _LIT( KFragmentedFileName2, "FRAG2.TXT");
69 _LIT( KDriveBase, " :\\" );
71 LOCAL_C TInt TestBlockMapNandFATUserData(TInt64 aStartPos, TInt64 aEndPos)
73 CFileMan* fMan=CFileMan::NewL(TheFs);
75 TFileName name(KDriveBase);
76 name[0] = TText('A' + NandDrive);
77 name.Append( KTestFileName );
79 TInt r = fMan->Attribs(name, 0, KEntryAttReadOnly, 0);
80 r = fMan->Delete(name);
82 r = fMan->Copy(KTestFile, name);
83 test( r == KErrNone );
85 TInt localDriveNum = 0;
87 r = testFile.Open( TheFs, name, EFileRead );
88 test( r == KErrNone );
90 RArray<SBlockMapInfo> map; // From RArray<TBlockMapEntry> map; to RArray<SBlockMapInfo> map;
93 TInt startPos = aStartPos;
96 // Store SBlockMapInfo objects in map:RArray until KErrCompletion is returned.
99 bmErr = testFile.BlockMap(info, aStartPos, aEndPos, ETestDebug);
100 if (bmErr != 0 && bmErr != KErrCompletion)
104 r = fMan->Attribs(name, 0, KEntryAttReadOnly, 0);
105 test( r == KErrNone );
106 r = fMan->Delete(name);
107 test( r == KErrNone );
113 localDriveNum = info.iLocalDriveNumber;
114 } while ( bmErr == 0 && bmErr != KErrCompletion );
115 test( bmErr == KErrCompletion );
119 r = testFile.Size(size);
120 test( r == KErrNone );
122 TBuf8<KReadBufferSize> buf1;
123 TBuf8<KReadBufferSize> buf2;
126 TBusLocalDrive localDrive;
128 UserSvr::UnlockRamDrive();
130 TBlockMapEntry* myBlockMapEntry;
132 TInt totalSegments = 0;
138 for ( c = 0; c < map.Count(); c++ )
140 myBlockMapEntry = (TBlockMapEntry*) map[c].iMap.Ptr();
141 granularity = map[c].iMap.Size()/sizeof(TBlockMapEntry);
142 totalSegments += granularity;
145 const TInt KTotalSegments = totalSegments;
146 r = localDrive.Connect( localDriveNum, changed );
147 test( r == KErrNone );
149 // For each SBlockMapInfo object in RArray map
150 for ( c = 0; c < map.Count(); c++ )
152 myBlockMapEntry = (TBlockMapEntry*) map[c].iMap.Ptr();
153 granularity = map[c].iMap.Size()/sizeof(TBlockMapEntry);
157 length = size - startPos;
161 length = aEndPos - startPos;
163 for ( TInt c2 = 1; c2 <= granularity; c2++)
166 if ( c2 == KTotalSegments && aEndPos%map[c].iBlockGranularity != 0 )
167 remainder = map[c].iBlockGranularity - aEndPos%map[c].iBlockGranularity;
170 miniLength = map[c].iBlockGranularity*myBlockMapEntry->iNumberOfBlocks - remainder - (c2 == 1?map[c].iBlockStartOffset:0);
173 if ( miniLength >= KReadBufferSize )
175 testFile.Read( startPos + amountRead, buf1, KReadBufferSize );
176 localDrive.Read( map[c].iStartBlockAddress + myBlockMapEntry->iStartBlock * map[c].iBlockGranularity + (c2 == 1?map[c].iBlockStartOffset:0) + myCounter*KReadBufferSize, KReadBufferSize, buf2);
177 r = buf1.Compare( buf2 );
182 miniLength -= KReadBufferSize;
183 length -= KReadBufferSize;
184 amountRead += KReadBufferSize;
188 testFile.Read(startPos + amountRead, buf1, miniLength);
189 localDrive.Read( map[c].iStartBlockAddress + myBlockMapEntry->iStartBlock * map[c].iBlockGranularity + (c2 == 1?map[c].iBlockStartOffset:0) + myCounter*KReadBufferSize, miniLength, buf2);
190 r = buf1.Compare( buf2 );
192 amountRead += miniLength;
193 length -= miniLength;
196 } while ( miniLength != 0 && length != 0);
203 r=fMan->Attribs(name, 0, KEntryAttReadOnly, 0);
204 test( r == KErrNone );
205 r = fMan->Delete(name);
206 test( r == KErrNone );
211 LOCAL_C TInt TestBlockMapNandFAT(TInt64 aStartPos, TInt64 aEndPos)
213 // Test BlockMap retrieval on NAND FAT.
216 TInt localDriveNum = 0;
218 TInt r = testFile.Open( TheFs, KTestFileFAT, EFileRead );
219 test( r == KErrNone );
221 RArray<SBlockMapInfo> map; // From RArray<TBlockMapEntry> map; to RArray<SBlockMapInfo> map;
224 TInt startPos = aStartPos;
227 // Store SBlockMapInfo objects in map:RArray until KErrCompletion is returned.
230 bmErr = testFile.BlockMap(info, aStartPos, aEndPos, Pageable?EBlockMapUsagePaging:ETestDebug);
231 if (bmErr != 0 && bmErr != KErrCompletion)
239 localDriveNum = info.iLocalDriveNumber;
240 } while ( bmErr == 0 && bmErr != KErrCompletion );
241 test( bmErr == KErrCompletion );
245 r = testFile.Size(size);
246 test( r == KErrNone );
248 TBuf8<KReadBufferSize> buf1;
249 TBuf8<KReadBufferSize> buf2;
252 TBusLocalDrive localDrive;
254 TBlockMapEntry* myBlockMapEntry;
256 TInt totalSegments = 0;
262 for ( c = 0; c < map.Count(); c++ )
264 myBlockMapEntry = (TBlockMapEntry*) map[c].iMap.Ptr();
265 granularity = map[c].iMap.Size()/sizeof(TBlockMapEntry);
266 totalSegments += granularity;
269 const TInt KTotalSegments = totalSegments;
270 r = localDrive.Connect( localDriveNum, changed );
271 test( r == KErrNone );
273 // For each SBlockMapInfo object in RArray map
274 for ( c = 0; c < map.Count(); c++ )
276 myBlockMapEntry = (TBlockMapEntry*) map[c].iMap.Ptr();
277 granularity = map[c].iMap.Size()/sizeof(TBlockMapEntry);
282 length = size - startPos;
286 length = aEndPos - startPos;
288 for ( TInt c2 = 1; c2 <= granularity; c2++)
291 if ( c2 == KTotalSegments && aEndPos%map[c].iBlockGranularity != 0 )
292 remainder = map[c].iBlockGranularity - aEndPos%map[c].iBlockGranularity;
295 miniLength = map[c].iBlockGranularity*myBlockMapEntry->iNumberOfBlocks - remainder - (c2 == 1?map[c].iBlockStartOffset:0);
298 if ( miniLength >= KReadBufferSize )
300 testFile.Read( startPos + amountRead, buf1, KReadBufferSize );
301 localDrive.Read( map[c].iStartBlockAddress + myBlockMapEntry->iStartBlock * map[c].iBlockGranularity + (c2 == 1?map[c].iBlockStartOffset:0) + myCounter*KReadBufferSize, KReadBufferSize, buf2);
302 r = buf1.Compare( buf2 );
307 miniLength -= KReadBufferSize;
308 length -= KReadBufferSize;
309 amountRead += KReadBufferSize;
313 testFile.Read(startPos + amountRead, buf1, miniLength);
314 localDrive.Read( map[c].iStartBlockAddress + myBlockMapEntry->iStartBlock * map[c].iBlockGranularity + (c2 == 1?map[c].iBlockStartOffset:0) + myCounter*KReadBufferSize, miniLength, buf2);
315 r = buf1.Compare( buf2 );
317 amountRead += miniLength;
318 length -= miniLength;
321 } while ( miniLength != 0 && length != 0);
330 LOCAL_C TInt TestBlockMapNandROFS(TInt64 aStartPos, TInt64 aEndPos)
332 // Test BlockMap retrieval on NAND ROFS.
335 TInt localDriveNum = 0;
337 TInt r = testFile.Open( TheFs, KTestFile, EFileRead );
338 test( r == KErrNone );
340 RArray<SBlockMapInfo> map; // From RArray<TBlockMapEntry> map; to RArray<SBlockMapInfo> map;
343 TInt startPos = aStartPos;
346 // Store SBlockMapInfo objects in map:RArray until KErrCompletion is returned.
349 bmErr = testFile.BlockMap(info, aStartPos, aEndPos, Pageable?EBlockMapUsagePaging:ETestDebug);
350 if (bmErr != 0 && bmErr != KErrCompletion)
358 localDriveNum = info.iLocalDriveNumber;
359 } while ( bmErr == 0 && bmErr != KErrCompletion );
360 test( bmErr == KErrCompletion );
364 r = testFile.Size(size);
365 test( r == KErrNone );
367 TBuf8<KReadBufferSize> buf1;
368 TBuf8<KReadBufferSize> buf2;
371 TBusLocalDrive localDrive;
373 TBlockMapEntry* myBlockMapEntry;
375 TInt totalSegments = 0;
380 for ( c = 0; c < map.Count(); c++ )
382 myBlockMapEntry = (TBlockMapEntry*) map[c].iMap.Ptr();
383 granularity = map[c].iMap.Size()/sizeof(TBlockMapEntry);
384 totalSegments += granularity;
386 r = localDrive.Connect( localDriveNum, changed );
387 test( r == KErrNone );
389 // For each SBlockMapInfo object in RArray map
390 for ( c = 0; c < map.Count(); c++ )
392 myBlockMapEntry = (TBlockMapEntry*) map[c].iMap.Ptr();
393 granularity = map[c].iMap.Size()/sizeof(TBlockMapEntry);
398 length = size - startPos;
402 length = aEndPos - startPos;
404 for ( TInt c2 = 1; c2 <= granularity; c2++)
410 if ( miniLength >= KReadBufferSize )
412 testFile.Read( startPos + amountRead, buf1, KReadBufferSize );
413 localDrive.Read( map[c].iStartBlockAddress + myBlockMapEntry->iStartBlock * map[c].iBlockGranularity + (c2 == 1?map[c].iBlockStartOffset:0) + myCounter*KReadBufferSize, KReadBufferSize, buf2);
414 r = buf1.Compare( buf2 );
419 miniLength -= KReadBufferSize;
420 length -= KReadBufferSize;
421 amountRead += KReadBufferSize;
425 testFile.Read(startPos + amountRead, buf1, miniLength);
426 localDrive.Read( map[c].iStartBlockAddress + myBlockMapEntry->iStartBlock * map[c].iBlockGranularity + (c2 == 1?map[c].iBlockStartOffset:0) + myCounter*KReadBufferSize, miniLength, buf2);
427 r = buf1.Compare( buf2 );
429 amountRead += miniLength;
430 length -= miniLength;
433 } while ( miniLength != 0 && length != 0);
443 LOCAL_C TInt TestBlockMapRamFAT(TInt64 aStartPos, TInt64 aEndPos)
445 // Test BlockMap retrieval on RAM FAT.
448 CFileMan* fMan=CFileMan::NewL(TheFs);
450 TFileName name(KDriveBase);
451 name[0] = TText('A' + RamFatDrive);
452 name.Append( KTestFileName );
454 TInt r = fMan->Attribs(name, 0, KEntryAttReadOnly, 0);
455 r = fMan->Delete(name);
457 r = fMan->Copy(KTestFile, name);
458 test( r == KErrNone || r == KErrAlreadyExists);
460 TInt localDriveNum = 0;
462 r = testFile.Open( TheFs, name, EFileRead );
463 test( r == KErrNone );
465 RArray<SBlockMapInfo> map; // From RArray<TBlockMapEntry> map; to RArray<SBlockMapInfo> map;
468 TInt startPos = aStartPos;
471 // Store SBlockMapInfo objects in map:RArray until KErrCompletion is returned.
474 bmErr = testFile.BlockMap(info, aStartPos, aEndPos, ETestDebug);
475 if (bmErr != 0 && bmErr != KErrCompletion)
479 r = fMan->Attribs(name, 0, KEntryAttReadOnly, 0);
480 test( r == KErrNone );
481 r = fMan->Delete(name);
482 test( r == KErrNone );
488 localDriveNum = info.iLocalDriveNumber;
489 } while ( bmErr == 0 && bmErr != KErrCompletion );
490 test( bmErr == KErrCompletion );
494 r = testFile.Size(size);
495 test( r == KErrNone );
497 TBuf8<KReadBufferSize> buf1;
498 TBuf8<KReadBufferSize> buf2;
501 TBusLocalDrive localDrive;
503 UserSvr::UnlockRamDrive();
505 TBlockMapEntry* myBlockMapEntry;
507 TInt totalSegments = 0;
513 for ( c = 0; c < map.Count(); c++ )
515 myBlockMapEntry = (TBlockMapEntry*) map[c].iMap.Ptr();
516 granularity = map[c].iMap.Size()/sizeof(TBlockMapEntry);
517 totalSegments += granularity;
520 const TInt KTotalSegments = totalSegments;
522 r = localDrive.Connect( localDriveNum, changed );
523 test( r == KErrNone );
525 // For each SBlockMapInfo object in RArray map
526 for ( c = 0; c < map.Count(); c++ )
528 myBlockMapEntry = (TBlockMapEntry*) map[c].iMap.Ptr();
529 granularity = map[c].iMap.Size()/sizeof(TBlockMapEntry);
534 length = size - startPos;
538 length = aEndPos - startPos;
540 for ( TInt c2 = 1; c2 <= granularity; c2++)
543 if ( c2 == KTotalSegments && aEndPos%map[c].iBlockGranularity != 0 )
544 remainder = map[c].iBlockGranularity - aEndPos%map[c].iBlockGranularity;
547 miniLength = map[c].iBlockGranularity*myBlockMapEntry->iNumberOfBlocks - remainder - (c2 == 1?map[c].iBlockStartOffset:0);
550 if ( miniLength >= KReadBufferSize )
552 testFile.Read( startPos + amountRead, buf1, KReadBufferSize );
553 localDrive.Read( map[c].iStartBlockAddress + myBlockMapEntry->iStartBlock * map[c].iBlockGranularity + (c2 == 1?map[c].iBlockStartOffset:0) + myCounter*KReadBufferSize, KReadBufferSize, buf2);
554 r = buf1.Compare( buf2 );
559 miniLength -= KReadBufferSize;
560 length -= KReadBufferSize;
561 amountRead += KReadBufferSize;
565 testFile.Read(startPos + amountRead, buf1, miniLength);
566 localDrive.Read( map[c].iStartBlockAddress + myBlockMapEntry->iStartBlock * map[c].iBlockGranularity + (c2 == 1?map[c].iBlockStartOffset:0) + myCounter*KReadBufferSize, miniLength, buf2);
567 r = buf1.Compare( buf2 );
569 amountRead += miniLength;
570 length -= miniLength;
573 } while ( miniLength != 0 && length != 0);
580 r=fMan->Attribs(name, 0, KEntryAttReadOnly, 0);
581 test( r == KErrNone );
582 r = fMan->Delete(name);
583 test( r == KErrNone );
588 LOCAL_C TInt TestBlockMapRamFAT2(TInt64 aStartPos, TInt64 aEndPos)
590 // Test BlockMap retrieval on Ram FAT.
593 CFileMan* fMan=CFileMan::NewL(TheFs);
595 TFileName name(KDriveBase);
596 name[0] = TText('A' + RamFatDrive);
597 name.Append( KTestFileName );
599 TInt r = fMan->Attribs(name, 0, KEntryAttReadOnly, 0);
600 r = fMan->Delete(name);
602 r = fMan->Copy(KTestFile, name);
603 test( r == KErrNone || r == KErrAlreadyExists);
606 r = testFile.Open( TheFs, name, EFileRead );
607 test( r == KErrNone );
609 RArray<SBlockMapInfo> map; // From RArray<TBlockMapEntry> map; to RArray<SBlockMapInfo> map;
613 bmErr = testFile.BlockMap(info, aStartPos, aEndPos, EBlockMapUsagePaging);
618 r = fMan->Attribs(name, 0, KEntryAttReadOnly, 0);
619 test( r == KErrNone );
620 r = fMan->Delete(name);
621 test( r == KErrNone );
626 LOCAL_C TInt TestBlockMapRemovableFAT(TInt64 aStartPos, TInt64 aEndPos)
628 // Test BlockMap retrieval on Removable FAT.
631 CFileMan* fMan=CFileMan::NewL(TheFs);
633 TFileName name(KDriveBase);
634 name[0] = TText('A' + RemovableFatDrive);
635 name.Append( KTestFileName );
637 TInt r=fMan->Copy(KTestFile, name);
638 test( r == KErrNone || r == KErrAlreadyExists);
641 r = testFile.Open( TheFs, name, EFileRead );
642 test( r == KErrNone );
644 RArray<SBlockMapInfo> map; // From RArray<TBlockMapEntry> map; to RArray<SBlockMapInfo> map;
646 TInt bmErr = testFile.BlockMap(info, aStartPos, aEndPos, Pageable?EBlockMapUsagePaging:ETestDebug);
650 r=fMan->Attribs(name, 0, KEntryAttReadOnly, 0);
651 test( r == KErrNone );
652 r = fMan->Delete(name);
653 test( r == KErrNone );
658 LOCAL_C TInt TestBlockMapInternalRemovableFAT(TInt64 aStartPos, TInt64 aEndPos)
660 // Test BlockMap retrieval on internal removable FAT.
663 CFileMan* fMan=CFileMan::NewL(TheFs);
665 TFileName name(KDriveBase);
666 name[0] = TText('A' + RamFatDrive);
667 name.Append( KTestFileName );
669 TInt r=fMan->Copy(KTestFile, name);
670 test( r == KErrNone || r == KErrAlreadyExists);
672 TInt localDriveNum = 0;
674 r = testFile.Open( TheFs, name, EFileRead );
675 test( r == KErrNone );
677 RArray<SBlockMapInfo> map; // From RArray<TBlockMapEntry> map; to RArray<SBlockMapInfo> map;
680 TInt startPos = aStartPos;
683 // Store SBlockMapInfo objects in map:RArray until KErrCompletion is returned.
686 bmErr = testFile.BlockMap(info, aStartPos, aEndPos, ETestDebug);
687 if (bmErr != 0 && bmErr != KErrCompletion)
691 r = fMan->Attribs(name, 0, KEntryAttReadOnly, 0);
692 test( r == KErrNone );
693 r = fMan->Delete(name);
694 test( r == KErrNone );
700 localDriveNum = info.iLocalDriveNumber;
701 } while ( bmErr == 0 && bmErr != KErrCompletion );
702 test( bmErr == KErrCompletion );
706 r = testFile.Size(size);
707 test( r == KErrNone );
709 TBuf8<KReadBufferSize> buf1;
710 TBuf8<KReadBufferSize> buf2;
713 TBusLocalDrive localDrive;
715 UserSvr::UnlockRamDrive();
717 TBlockMapEntry* myBlockMapEntry;
719 TInt totalSegments = 0;
725 for ( c = 0; c < map.Count(); c++ )
727 myBlockMapEntry = (TBlockMapEntry*) map[c].iMap.Ptr();
728 granularity = map[c].iMap.Size()/sizeof(TBlockMapEntry);
729 totalSegments += granularity;
732 const TInt KTotalSegments = totalSegments;
734 r = localDrive.Connect( localDriveNum, changed );
735 test( r == KErrNone );
737 // For each SBlockMapInfo object in RArray map
738 for ( c = 0; c < map.Count(); c++ )
740 myBlockMapEntry = (TBlockMapEntry*) map[c].iMap.Ptr();
741 granularity = map[c].iMap.Size()/sizeof(TBlockMapEntry);
746 length = size - startPos;
750 length = aEndPos - startPos;
752 for ( TInt c2 = 1; c2 <= granularity; c2++)
755 if ( c2 == KTotalSegments && aEndPos%map[c].iBlockGranularity != 0 )
756 remainder = map[c].iBlockGranularity - aEndPos%map[c].iBlockGranularity;
759 miniLength = map[c].iBlockGranularity*myBlockMapEntry->iNumberOfBlocks - remainder - (c2 == 1?map[c].iBlockStartOffset:0);
762 if ( miniLength >= KReadBufferSize )
764 testFile.Read( startPos + amountRead, buf1, KReadBufferSize );
765 localDrive.Read( map[c].iStartBlockAddress + myBlockMapEntry->iStartBlock * map[c].iBlockGranularity + (c2 == 1?map[c].iBlockStartOffset:0) + myCounter*KReadBufferSize, KReadBufferSize, buf2);
766 r = buf1.Compare( buf2 );
771 miniLength -= KReadBufferSize;
772 length -= KReadBufferSize;
773 amountRead += KReadBufferSize;
777 testFile.Read(startPos + amountRead, buf1, miniLength);
778 localDrive.Read( map[c].iStartBlockAddress + myBlockMapEntry->iStartBlock * map[c].iBlockGranularity + (c2 == 1?map[c].iBlockStartOffset:0) + myCounter*KReadBufferSize, miniLength, buf2);
779 r = buf1.Compare( buf2 );
781 amountRead += miniLength;
782 length -= miniLength;
785 } while ( miniLength != 0 && length != 0);
792 r=fMan->Attribs(name, 0, KEntryAttReadOnly, 0);
793 test( r == KErrNone );
794 r = fMan->Delete(name);
795 test( r == KErrNone );
800 LOCAL_C TInt TestBlockMapFragmented(DriveType aDriveType, TInt64 aStartPos, TInt64 aEndPos)
802 CFileMan* fMan=CFileMan::NewL(TheFs);
804 TFileName name(KDriveBase);
805 if (aDriveType==EDriveRam)
806 name[0] = TText('A' + RamFatDrive);
807 else if (aDriveType==EDriveRemovable)
808 name[0] = TText('A' + RemovableFatDrive);
809 else if (aDriveType==EDriveNand)
810 name[0] = TText('A' + NandDrive);
812 name[0] = TText('A' + InternalRemovableFatDrive);
813 name.Append( KFragmentedFileName1 );
814 TInt localDriveNum = 0;
816 TInt r = testFile.Open( TheFs, name, EFileRead );
817 test( r == KErrNone );
818 RArray<SBlockMapInfo> map; // From RArray<TBlockMapEntry> map; to RArray<SBlockMapInfo> map;
821 TInt startPos = aStartPos;
824 // Store SBlockMapInfo objects in map:RArray until KErrCompletion is returned.
827 bmErr = testFile.BlockMap(info, aStartPos, aEndPos, ETestDebug);
828 if (bmErr != 0 && bmErr != KErrCompletion)
834 r = fMan->Attribs(name, 0, KEntryAttReadOnly, 0);
835 test( r == KErrNone );
836 r = fMan->Delete(name);
837 test( r == KErrNone );
844 localDriveNum = info.iLocalDriveNumber;
845 } while ( bmErr == 0 && bmErr != KErrCompletion );
846 test( bmErr == KErrCompletion );
849 r = testFile.Size(size);
850 test( r == KErrNone );
852 TBuf8<KReadBufferSize> buf1;
853 TBuf8<KReadBufferSize> buf2;
856 TBusLocalDrive localDrive;
858 UserSvr::UnlockRamDrive();
860 TBlockMapEntry* myBlockMapEntry;
862 TInt totalSegments = 0;
868 for ( c = 0; c < map.Count(); c++ )
870 myBlockMapEntry = (TBlockMapEntry*) map[c].iMap.Ptr();
871 granularity = map[c].iMap.Size()/sizeof(TBlockMapEntry);
872 totalSegments += granularity;
875 const TInt KTotalSegments = totalSegments;
876 r = localDrive.Connect( localDriveNum, changed );
877 test( r == KErrNone );
879 // For each SBlockMapInfo object in RArray map
880 for ( c = 0; c < map.Count(); c++ )
882 myBlockMapEntry = (TBlockMapEntry*) map[c].iMap.Ptr();
883 granularity = map[c].iMap.Size()/sizeof(TBlockMapEntry);
888 length = size - startPos;
892 length = aEndPos - startPos;
894 for ( TInt c2 = 1; c2 <= granularity; c2++)
897 if ( c2 == KTotalSegments && aEndPos%map[c].iBlockGranularity != 0 )
898 remainder = map[c].iBlockGranularity - aEndPos%map[c].iBlockGranularity;
901 miniLength = map[c].iBlockGranularity*myBlockMapEntry->iNumberOfBlocks - remainder - (c2 == 1?map[c].iBlockStartOffset:0);
904 if ( miniLength >= KReadBufferSize )
906 testFile.Read( startPos + amountRead, buf1, KReadBufferSize );
907 localDrive.Read( map[c].iStartBlockAddress + myBlockMapEntry->iStartBlock * map[c].iBlockGranularity + (c2 == 1?map[c].iBlockStartOffset:0) + myCounter*KReadBufferSize, KReadBufferSize, buf2);
908 r = buf1.Compare( buf2 );
913 miniLength -= KReadBufferSize;
914 length -= KReadBufferSize;
915 amountRead += KReadBufferSize;
919 testFile.Read(startPos + amountRead, buf1, miniLength );
920 localDrive.Read( map[c].iStartBlockAddress + myBlockMapEntry->iStartBlock * map[c].iBlockGranularity + (c2 == 1?map[c].iBlockStartOffset:0) + myCounter*KReadBufferSize, miniLength, buf2);
921 r = buf1.Compare( buf2 );
923 amountRead += miniLength;
924 length -= miniLength;
927 } while ( miniLength != 0 && length != 0);
936 r=fMan->Attribs(name, 0, KEntryAttReadOnly, 0);
937 test( r == KErrNone );
938 r = fMan->Delete(name);
939 test( r == KErrNone );
945 LOCAL_C void GenerateFragmentedFiles(DriveType aDriveType)
948 TFileName name1(KDriveBase);
949 if (aDriveType==EDriveRam)
950 name1[0] = TText('A' + RamFatDrive);
951 else if (aDriveType==EDriveRemovable)
952 name1[0] = TText('A' + RemovableFatDrive);
953 else if (aDriveType==EDriveNand)
954 name1[0] = TText('A' + NandDrive);
956 name1[0] = TText('A' + InternalRemovableFatDrive);
957 name1.Append( KFragmentedFileName1 );
959 r = file1.Create(TheFs, name1, EFileWrite);
960 test( r == KErrNone );
963 TFileName name2(KDriveBase);
964 if (aDriveType==EDriveRam)
965 name2[0] = TText('A' + RamFatDrive);
966 else if (aDriveType==EDriveRemovable)
967 name2[0] = TText('A' + RemovableFatDrive);
968 else if (aDriveType==EDriveNand)
969 name2[0] = TText('A' + NandDrive);
971 name2[0] = TText('A' + InternalRemovableFatDrive);
972 name2.Append( KFragmentedFileName2 );
974 r = file2.Create(TheFs, name2, EFileWrite);
975 test( r == KErrNone );
978 TBuf8<KMaxFragmentSize> tempBuf;
991 buf = (TUint8*) tempBuf.Ptr();
993 randomLength = Math::Random() % KMaxFragmentSize;
994 randomSeed = Math::Random();
995 tempBuf.SetLength(randomLength);
997 while (randomLength-- && fragmentSize++ < KMaxFragmentSize && fileSize++ < KMaxFileSize)
999 *buf++ = (TUint8)('A' + (Math::Rand(randomSeed) % ('Z' - 'A')));
1001 r = file1.Open( TheFs, name1, EFileWrite );
1002 test( r == KErrNone );
1003 r = file1.Seek( ESeekEnd, pos1 );
1004 test( r == KErrNone );
1005 r = file1.Write( pos1, tempBuf );
1006 test( r == KErrNone );
1008 test( r == KErrNone );
1010 if ( mycount++ < 6 )
1012 r = file2.Open( TheFs, name2, EFileWrite );
1013 test( r == KErrNone );
1014 r = file2.Seek( ESeekEnd, pos2 );
1015 test( r == KErrNone );
1016 r = file2.Write( pos2, tempBuf );
1017 test( r == KErrNone );
1019 test( r == KErrNone );
1022 } while ( fileSize < KMaxFileSize );
1023 CFileMan* fMan=CFileMan::NewL(TheFs);
1025 r = fMan->Delete(name2);
1026 test( r == KErrNone );
1030 LOCAL_C void FindDrive(DriveType aDriveType)
1034 for( i = EDriveA; i < EDriveZ; i++ )
1037 TInt r = TheFs.Drive(info, i);
1038 if ( r != KErrNone )
1040 test( r == KErrNone );
1041 if ( aDriveType == EDriveNand )
1043 c++ == 0 ? test.Printf( _L("Searching for NAND drive.")) : test.Printf( _L("."));
1044 if ( info.iType == EMediaNANDFlash && ((info.iMediaAtt & KMediaAttWriteProtected) == 0) )
1046 if ( info.iDriveAtt & KDriveAttPageable )
1049 test.Printf( _L("Found NAND drive: %d\n"), NandDrive );
1053 else if ( aDriveType == EDriveRam )
1055 c++ == 0 ? test.Printf( _L("Searching for RAM FAT drive.")) : test.Printf( _L("."));
1056 if ( (info.iType == EMediaRam) && ( info.iDriveAtt == (KDriveAttLocal|KDriveAttInternal) ) && ( info.iMediaAtt == (KMediaAttVariableSize|KMediaAttFormattable) ) )
1058 if ( info.iDriveAtt & KDriveAttPageable )
1061 test.Printf( _L("Found RAM FAT drive: %d\n"), RamFatDrive );
1065 else if ( aDriveType == EDriveRemovable )
1067 c++ == 0 ? test.Printf( _L("Searching for removable FAT drive.")) : test.Printf( _L("."));
1068 if ( info.iType == EMediaHardDisk && ( info.iDriveAtt == (KDriveAttLocal|KDriveAttRemovable) ) )
1070 if ( info.iDriveAtt & KDriveAttPageable )
1072 RemovableFatDrive = i;
1073 test.Printf( _L("Found removable FAT drive: %d\n"), RemovableFatDrive );
1077 else if ( aDriveType == EDriveInternalRemovable )
1079 c++ == 0 ? test.Printf( _L("Searching for internal removable FAT drive.")) : test.Printf( _L("."));
1080 if ( info.iType == EMediaHardDisk && ( info.iDriveAtt == (KDriveAttLocal|KDriveAttInternal) ) )
1082 if ( info.iDriveAtt & KDriveAttPageable )
1084 InternalRemovableFatDrive = i;
1085 test.Printf( _L("Found internal removable FAT drive: %d\n"), InternalRemovableFatDrive );
1095 test.Printf( _L("NAND drive not found.\n") );
1098 test.Printf( _L("RAM FAT drive not found.\n") );
1100 case EDriveRemovable:
1101 test.Printf( _L("Removable FAT drive not found.\n") );
1103 case EDriveInternalRemovable:
1104 test.Printf( _L("Internal removable FAT drive not found.\n") );
1107 test.Printf( _L("Drive not found.\n") );
1112 //************************
1115 GLDEF_C void CallTestsL(void)
1118 test.Start( _L("BlockMap Test\n") );
1120 TInt testFileSize = 0;
1122 TInt r = testFile.Open(TheFs, KTestFile, EFileRead);
1124 r = testFile.Size(testFileSize);
1126 test(testFileSize>16384);
1129 if ( gDriveToTest == 'C' )
1132 r = HAL::Get( HAL::EMachineUid, value );
1133 test( r == KErrNone );
1134 if ( value != HAL::EMachineUid_Lubbock ) // Lubbock cannot run FindDrive as it doesn't support the NAND API
1136 test.Next(_L("Test BlockMap retrieval on NAND FAT."));
1137 FindDrive(EDriveNand);
1138 if ( NandDrive > -1 ) // not finding a NAND drive isn't an error as only NAND builds have one
1140 r = TestBlockMapNandFATUserData(0, -1);
1141 test( r == KErrCompletion );
1142 r = TestBlockMapNandFATUserData(1024, 4096);
1143 test( r == KErrCompletion );
1144 r = TestBlockMapNandFATUserData(1020, 4100);
1145 test( r == KErrCompletion );
1146 r = TestBlockMapNandFATUserData(1024, 4100);
1147 test( r == KErrCompletion );
1148 r = TestBlockMapNandFATUserData(1020, 4096);
1149 test( r == KErrCompletion );
1150 r = TestBlockMapNandFATUserData(1025, 1200);
1151 test( r == KErrCompletion );
1152 r = TestBlockMapNandFATUserData(0, testFileSize+100);
1153 test( r == KErrArgument );
1154 r = TestBlockMapNandFATUserData(-5, -1);
1155 test( r == KErrArgument );
1156 r = TestBlockMapNandFATUserData(-5, testFileSize+100);
1157 test( r == KErrArgument );
1158 r = TestBlockMapNandFATUserData(0, 0);
1159 test( r == KErrArgument );
1160 r = TestBlockMapNandFATUserData(testFileSize, -1);
1161 test( r == KErrArgument );
1162 r = TestBlockMapNandFATUserData(0, -1);
1163 test( r == KErrCompletion );
1164 r = TestBlockMapNandFATUserData(2000, 2001);
1165 test( r == KErrCompletion );
1166 r = TestBlockMapNandFATUserData(0, 0);
1167 test( r == KErrArgument );
1168 r = TestBlockMapNandFATUserData(2000, 2000);
1169 test( r == KErrArgument );
1170 r = TestBlockMapNandFATUserData(2048, 2048);
1171 test( r == KErrArgument );
1172 test.Printf(_L("Generating Fragmented File..."));
1173 GenerateFragmentedFiles(EDriveNand);
1174 test.Printf(_L("Done!\n"));
1175 test.Next(_L("Test BlockMap retrieval on NAND FAT (User area) (fragmented)."));
1176 r = TestBlockMapFragmented(EDriveNand, 0, -1);
1177 test( r == KErrCompletion );
1178 r = TestBlockMapFragmented(EDriveNand, 1024, 4096);
1179 test( r == KErrCompletion );
1180 r = TestBlockMapFragmented(EDriveNand, 1020, 4100);
1181 test( r == KErrCompletion );
1182 r = TestBlockMapFragmented(EDriveNand, 1024, 4100);
1183 test( r == KErrCompletion );
1184 r = TestBlockMapFragmented(EDriveNand, 1020, 4096);
1185 test( r == KErrCompletion );
1186 r = TestBlockMapFragmented(EDriveNand, 1025, 1200);
1187 test( r == KErrCompletion );
1188 r = TestBlockMapFragmented(EDriveNand, 0, testFileSize+100);
1189 test( r == KErrArgument );
1190 r = TestBlockMapFragmented(EDriveNand, -5, -1);
1191 test( r == KErrArgument );
1192 r = TestBlockMapFragmented(EDriveNand, -5, testFileSize+100);
1193 test( r == KErrArgument );
1194 r = TestBlockMapFragmented(EDriveNand, 0, 0);
1195 test( r == KErrArgument );
1196 r = TestBlockMapFragmented(EDriveNand, testFileSize, -1);
1197 test( r == KErrArgument );
1198 r = TestBlockMapFragmented(EDriveNand, 0, -1);
1199 test( r == KErrCompletion );
1200 r = TestBlockMapFragmented(EDriveNand, 2000, 2001);
1201 test( r == KErrCompletion );
1202 r = TestBlockMapFragmented(EDriveNand, 0, 0);
1203 test( r == KErrArgument );
1204 r = TestBlockMapFragmented(EDriveNand, 2000, 2000);
1205 test( r == KErrArgument );
1207 r = TestBlockMapFragmented(EDriveNand, 2048, 2048);
1208 test( r == KErrArgument );
1209 test.Next(_L("Test BlockMap retrieval on NAND FAT."));
1210 r = TestBlockMapNandFAT(0, -1);
1211 test( r == KErrCompletion );
1212 r = TestBlockMapNandFAT(1024, 4096);
1213 test( r == KErrCompletion );
1214 r = TestBlockMapNandFAT(1020, 4100);
1215 test( r == KErrCompletion );
1216 r = TestBlockMapNandFAT(1024, 4100);
1217 test( r == KErrCompletion );
1218 r = TestBlockMapNandFAT(1020, 4096);
1219 test( r == KErrCompletion );
1220 r = TestBlockMapNandFAT(1025, 1200);
1221 test( r == KErrCompletion );
1222 r = TestBlockMapNandFAT(0, testFileSize+100);
1223 test( r == KErrArgument );
1224 r = TestBlockMapNandFAT(-5, -1);
1225 test( r == KErrArgument );
1226 r = TestBlockMapNandFAT(-5, testFileSize+100);
1227 test( r == KErrArgument );
1228 r = TestBlockMapNandFAT(0, 0);
1229 test( r == KErrArgument );
1230 r = TestBlockMapNandFAT(testFileSize, -1);
1231 test( r == KErrArgument );
1232 r = TestBlockMapNandFAT(0, -1);
1233 test( r == KErrCompletion );
1234 r = TestBlockMapNandFAT(2000, 2001);
1235 test( r == KErrCompletion );
1236 r = TestBlockMapNandFAT(0, 0);
1237 test( r == KErrArgument );
1238 r = TestBlockMapNandFAT(2000, 2000);
1239 test( r == KErrArgument );
1240 r = TestBlockMapNandFAT(2048, 2048);
1241 test( r == KErrArgument );
1242 test.Next(_L("Test BlockMap retrieval on NAND ROFS."));
1243 r = TestBlockMapNandROFS(0, -1);
1244 test( r == KErrCompletion );
1245 r = TestBlockMapNandROFS(1024, 4096);
1246 test( r == KErrCompletion );
1247 r = TestBlockMapNandROFS(1020, 4100);
1248 test( r == KErrCompletion );
1249 r = TestBlockMapNandROFS(1024, 4100);
1250 test( r == KErrCompletion );
1251 r = TestBlockMapNandROFS(1020, 4096);
1252 test( r == KErrCompletion );
1253 r = TestBlockMapNandROFS(1025, 1200);
1254 test( r == KErrCompletion );
1255 r = TestBlockMapNandROFS(0, testFileSize+100);
1256 test( r == KErrArgument );
1257 r = TestBlockMapNandROFS(-5, -1);
1258 test( r == KErrArgument );
1259 r = TestBlockMapNandROFS(-5, testFileSize+100);
1260 test( r == KErrArgument );
1261 r = TestBlockMapNandROFS(0, 0);
1262 test( r == KErrArgument );
1263 r = TestBlockMapNandROFS(testFileSize, -1);
1264 test( r == KErrArgument );
1265 r = TestBlockMapNandROFS(0, -1);
1266 test( r == KErrCompletion );
1267 r = TestBlockMapNandROFS(2000, 2001);
1268 test( r == KErrCompletion );
1269 r = TestBlockMapNandROFS(0, 0);
1270 test( r == KErrArgument );
1271 r = TestBlockMapNandROFS(2000, 2000);
1272 test( r == KErrArgument );
1273 r = TestBlockMapNandROFS(2048, 2048);
1274 test( r == KErrArgument );
1275 test.Next(_L("Test BlockMap retrieval on RAM FAT."));
1276 FindDrive(EDriveRam);
1277 test( RamFatDrive > -1 );
1278 r = TestBlockMapRamFAT(0, -1);
1279 test( r == KErrCompletion );
1280 r = TestBlockMapRamFAT(1024, 4096);
1281 test( r == KErrCompletion );
1282 r = TestBlockMapRamFAT(1020, 4100);
1283 test( r == KErrCompletion );
1284 r = TestBlockMapRamFAT(1024, 4100);
1285 test( r == KErrCompletion );
1286 r = TestBlockMapRamFAT(1020, 4096);
1287 test( r == KErrCompletion );
1288 r = TestBlockMapRamFAT(1025, 1200);
1289 test( r == KErrCompletion );
1290 r = TestBlockMapRamFAT(0, testFileSize+100);
1291 test( r == KErrArgument );
1292 r = TestBlockMapRamFAT(-5, -1);
1293 test( r == KErrArgument );
1294 r = TestBlockMapRamFAT(-5, testFileSize+100);
1295 test( r == KErrArgument );
1296 r = TestBlockMapRamFAT(0, 0);
1297 test( r == KErrArgument );
1298 r = TestBlockMapRamFAT(testFileSize, -1);
1299 test( r == KErrArgument );
1300 r = TestBlockMapRamFAT(0, -1);
1301 test( r == KErrCompletion );
1302 r = TestBlockMapRamFAT(2000, 2001);
1303 test( r == KErrCompletion );
1304 r = TestBlockMapRamFAT(0, 0);
1305 test( r == KErrArgument );
1306 r = TestBlockMapRamFAT(2000, 2000);
1307 test( r == KErrArgument );
1308 r = TestBlockMapRamFAT(2048, 2048);
1309 test( r == KErrArgument );
1310 test.Next(_L("Test BlockMap retrieval on Ram FAT (2)."));
1311 r = TestBlockMapRamFAT2(0, -1);
1312 test( r == KErrNotSupported );
1313 FindDrive(EDriveRemovable);
1314 if ( RemovableFatDrive > -1)
1316 test.Next(_L("Test BlockMap retrieval on removable FAT."));
1317 r = TestBlockMapRemovableFAT(0, -1);
1318 Pageable?test( r == KErrNotSupported ):test( r == KErrCompletion );
1322 test.Next(_L("Test BlockMap retrieval on internal removable FAT."));
1323 FindDrive(EDriveInternalRemovable);
1324 test( InternalRemovableFatDrive > -1);
1325 r = TestBlockMapInternalRemovableFAT(0, -1);
1326 test( r == KErrCompletion );
1327 r = TestBlockMapInternalRemovableFAT(1024, 4096);
1328 test( r == KErrCompletion );
1329 r = TestBlockMapInternalRemovableFAT(1020, 4100);
1330 test( r == KErrCompletion );
1331 r = TestBlockMapInternalRemovableFAT(1024, 4100);
1332 test( r == KErrCompletion );
1333 r = TestBlockMapInternalRemovableFAT(1020, 4096);
1334 test( r == KErrCompletion );
1335 r = TestBlockMapInternalRemovableFAT(1025, 1200);
1336 test( r == KErrCompletion );
1337 r = TestBlockMapInternalRemovableFAT(0, testFileSize+100);
1338 test( r == KErrArgument );
1339 r = TestBlockMapInternalRemovableFAT(-5, -1);
1340 test( r == KErrArgument );
1341 r = TestBlockMapInternalRemovableFAT(-5, testFileSize+100);
1342 test( r == KErrArgument );
1343 r = TestBlockMapInternalRemovableFAT(0, 0);
1344 test( r == KErrArgument );
1345 r = TestBlockMapInternalRemovableFAT(testFileSize, -1);
1346 test( r == KErrArgument );
1347 r = TestBlockMapInternalRemovableFAT(0, -1);
1348 test( r == KErrCompletion );
1349 r = TestBlockMapInternalRemovableFAT(2000, 2001);
1350 test( r == KErrCompletion );
1351 r = TestBlockMapInternalRemovableFAT(0, 0);
1352 test( r == KErrArgument );
1353 r = TestBlockMapInternalRemovableFAT(2000, 2000);
1354 test( r == KErrArgument );
1355 r = TestBlockMapInternalRemovableFAT(2048, 2048);
1356 test( r == KErrArgument );
1358 test.Next(_L("Test BlockMap retrieval on Ram FAT (fragmented)."));
1359 test.Printf(_L("Generating Fragmented File..."));
1360 GenerateFragmentedFiles(EDriveRam);
1361 test.Printf(_L("Done!\n"));
1363 r = TestBlockMapFragmented(EDriveRam, 0, -1);
1364 test( r == KErrCompletion );
1365 r = TestBlockMapFragmented(EDriveRam, 1020, 4100);
1366 test( r == KErrCompletion );
1367 r = TestBlockMapFragmented(EDriveRam, 2049, 4096);
1368 test( r == KErrCompletion );
1369 r = TestBlockMapFragmented(EDriveRam, 1024, 4100);
1370 test( r == KErrCompletion );
1371 r = TestBlockMapFragmented(EDriveRam, 1020, 4096);
1372 test( r == KErrCompletion );
1373 r = TestBlockMapFragmented(EDriveRam, 1025, 1200);
1374 test( r == KErrCompletion );
1375 r = TestBlockMapFragmented(EDriveRam, 0, testFileSize+100);
1376 test( r == KErrArgument );
1377 r = TestBlockMapFragmented(EDriveRam, -5, -1);
1378 test( r == KErrArgument );
1379 r = TestBlockMapFragmented(EDriveRam, -5, testFileSize+100);
1380 test( r == KErrArgument );
1381 r = TestBlockMapFragmented(EDriveRam, 0, 0);
1382 test( r == KErrArgument );
1383 r = TestBlockMapFragmented(EDriveRam, testFileSize, -1);
1384 test( r == KErrArgument );
1385 r = TestBlockMapFragmented(EDriveRam, 0, -1);
1386 test( r == KErrCompletion );
1387 r = TestBlockMapFragmented(EDriveRam, 2000, 2001);
1388 test( r == KErrCompletion );
1389 r = TestBlockMapFragmented(EDriveRam, 0, 0);
1390 test( r == KErrArgument );
1391 r = TestBlockMapFragmented(EDriveRam, 2000, 2000);
1392 test( r == KErrArgument );
1394 r = TestBlockMapFragmented(EDriveRam, 2048, 2048);
1395 test( r == KErrArgument );
1399 test.Printf( _L("NAND drive not found, skipping test.\n") );