kerneltest/f32test/filesystem/fat/t_scn32dr1.cpp
changeset 109 b3a1d9898418
parent 90 947f0dc9f7a8
child 210 b592f7984442
child 271 dc268b18d709
equal deleted inserted replaced
102:ef2a444a7410 109:b3a1d9898418
     9 // Nokia Corporation - initial contribution.
     9 // Nokia Corporation - initial contribution.
    10 //
    10 //
    11 // Contributors:
    11 // Contributors:
    12 //
    12 //
    13 // Description:
    13 // Description:
    14 // f32test\scndrv\t_scn32dr1.cpp
    14 // f32test\filesystem\fat\t_scn32dr1.cpp
    15 //
    15 // Tests that ScanDrive fixes known errors to a Rugged FAT drive
    16 //
    16 //
       
    17 
       
    18 #define __E32TEST_EXTENSION__
    17 
    19 
    18 #include <f32file.h>
    20 #include <f32file.h>
    19 #include <e32test.h>
    21 #include <e32test.h>
    20 
    22 
    21 #include "t_server.h"
    23 #include "t_server.h"
   260         ptr = (TUint8*)aFat + pos;
   262         ptr = (TUint8*)aFat + pos;
   261     else
   263     else
   262         {
   264         {
   263         pos += BootSector.ReservedSectors() * BootSector.BytesPerSector();
   265         pos += BootSector.ReservedSectors() * BootSector.BytesPerSector();
   264         TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
   266         TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
   265         test(r==KErrNone);
   267         test_KErrNone(r);
   266         TPtr8 buf(&data[0], 4);
   268         TPtr8 buf(&data[0], 4);
   267         r=TheRawDisk.Read(pos, buf);
   269         r=TheRawDisk.Read(pos, buf);
   268         test(r==KErrNone);
   270         test_KErrNone(r);
   269         TheRawDisk.Close();
   271         TheRawDisk.Close();
   270         }
   272         }
   271 
   273 
   272     TUint32 val = 0;
   274     TUint32 val = 0;
   273     switch (gDiskType)
   275     switch (gDiskType)
   288             test(0);
   290             test(0);
   289         }
   291         }
   290     return val;
   292     return val;
   291     }
   293     }
   292 
   294 
   293 LOCAL_C void WriteFat(TInt aFatIndex,TInt aValue,const TUint8* aFat)
   295 LOCAL_C void WriteToFatBuf(TInt aFatIndex,TInt aValue,const TUint8* aFat)
   294 //
   296 //
   295 // Write a value to both fats starting at aFat
   297 // Write a value to both fats starting at aFat
   296 //
   298 //
   297     {
   299     {
   298     TUint8* p=(TUint8*)(aFat+PosInBytes(aFatIndex));
   300     TUint8* p=(TUint8*)(aFat+PosInBytes(aFatIndex));
   342 
   344 
   343 static void DoReadBootSector()
   345 static void DoReadBootSector()
   344     {
   346     {
   345 
   347 
   346     TInt nRes = ReadBootSector(TheFs, CurrentDrive(), KBootSectorNum<<KDefaultSectorLog2, BootSector);
   348     TInt nRes = ReadBootSector(TheFs, CurrentDrive(), KBootSectorNum<<KDefaultSectorLog2, BootSector);
   347     test(nRes == KErrNone);
   349     test_KErrNone(nRes);
   348 
   350 
   349     if(!BootSector.IsValid())
   351     if(!BootSector.IsValid())
   350         {
   352         {
   351         test.Printf(_L("Wrong bootsector! Dump:\n"));
   353         test.Printf(_L("Wrong bootsector! Dump:\n"));
   352         BootSector.PrintDebugInfo();
   354         BootSector.PrintDebugInfo();
   578             break;
   580             break;
   579     aName[i++] = qu;
   581     aName[i++] = qu;
   580     aName.SetLength(i);
   582     aName.SetLength(i);
   581     }
   583     }
   582 
   584 
       
   585 TDes& MakePrintable(TDes& aDes)
       
   586 	{
       
   587 	TInt len = aDes.Length();
       
   588 
       
   589 	for (TInt i=0; i<len; i++)
       
   590 		{
       
   591 		if ((TUint8) aDes[i] < 0x20)
       
   592 			aDes[i] = '?';
       
   593 		}
       
   594 	return aDes;
       
   595 	}
       
   596 
   583 GLDEF_C TBool DumpDirEntry(TInt aNum, const TUint8* aEntry)
   597 GLDEF_C TBool DumpDirEntry(TInt aNum, const TUint8* aEntry)
   584 //
   598 //
   585 // Dump a single directory entry to the log.  Return false if it was end of
   599 // Dump a single directory entry to the log.  Return false if it was end of
   586 // directory or an invalid entry (and don't display it).
   600 // directory or an invalid entry (and don't display it).
   587 //
   601 //
   601         {
   615         {
   602         TBuf16<15> name;
   616         TBuf16<15> name;
   603         ExtractNameString(name, aEntry);
   617         ExtractNameString(name, aEntry);
   604         TInt ord = aEntry[0];
   618         TInt ord = aEntry[0];
   605         if (ord & KDirLastLongEntry)
   619         if (ord & KDirLastLongEntry)
   606             RDebug::Print(_L("%5d: %-15S #%-2d LAST"), aNum, &name, ord & ~KDirLastLongEntry);
   620             RDebug::Print(_L("%5d: %-15S #%-2d LAST"), aNum, &MakePrintable(name), ord & ~KDirLastLongEntry);
   607         else
   621         else
   608             RDebug::Print(_L("%5d: %-15S #%-2d"), aNum, &name, ord & ~KDirLastLongEntry);
   622             RDebug::Print(_L("%5d: %-15S #%-2d"), aNum, &MakePrintable(name), ord & ~KDirLastLongEntry);
   609         }
   623         }
   610     else if (!IsValidDirEntry(d))
   624     else if (!IsValidDirEntry(d))
   611         {
   625         {
   612         if (aNum > 0)
   626         if (aNum > 0)
   613             RDebug::Print(_L("%5d: ============= INVALID ENTRY"), aNum);
   627             RDebug::Print(_L("%5d: ============= INVALID ENTRY"), aNum);
   616     else
   630     else
   617         {
   631         {
   618         TBuf<11> name;
   632         TBuf<11> name;
   619         name.Copy(d->Name());
   633         name.Copy(d->Name());
   620         RDebug::Print(_L("%5d: '%S'   %S  start %-5d size %d"),
   634         RDebug::Print(_L("%5d: '%S'   %S  start %-5d size %d"),
   621                       aNum, &name, DirAttributes(d->Attributes()), d->StartCluster(), d->Size());
   635                       aNum, &MakePrintable(name), DirAttributes(d->Attributes()), d->StartCluster(), d->Size());
   622         }
   636         }
   623     return ETrue;
   637     return ETrue;
   624     }
   638     }
   625 
   639 
   626 GLDEF_C void DumpDirCluster(const TUint8* aData, TInt aCluster=0)
   640 GLDEF_C void DumpDirCluster(const TUint8* aData, TInt aCluster=0)
   694     if (aEnd < 0)
   708     if (aEnd < 0)
   695         aEnd = aStart + 1;
   709         aEnd = aStart + 1;
   696     if (aStart < 2 && gDiskType != EFat32)
   710     if (aStart < 2 && gDiskType != EFat32)
   697         {
   711         {
   698         HBufC8* buf=HBufC8::New(BootSector.RootDirEntries() * KSizeOfFatDirEntry);
   712         HBufC8* buf=HBufC8::New(BootSector.RootDirEntries() * KSizeOfFatDirEntry);
   699         test(buf != NULL);
   713         test_NotNull(buf);
   700         TPtr8 ptr=buf->Des();
   714         TPtr8 ptr=buf->Des();
   701         TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
   715         TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
   702         test(r==KErrNone);
   716         test_KErrNone(r);
   703         r=TheRawDisk.Read(gRootDirStart, ptr);
   717         r=TheRawDisk.Read(gRootDirStart, ptr);
   704         test(r==KErrNone);
   718         test_KErrNone(r);
   705         TheRawDisk.Close();
   719         TheRawDisk.Close();
   706         DumpRootDir(buf->Ptr());
   720         DumpRootDir(buf->Ptr());
   707         delete(buf);
   721         delete(buf);
   708         aStart = 2;
   722         aStart = 2;
   709         }
   723         }
   710     for (TInt cluster = aStart; cluster < aEnd; cluster++)
   724     for (TInt cluster = aStart; cluster < aEnd; cluster++)
   711         {
   725         {
   712         if (GetFatEntry(cluster, aFat) != 0)
   726         if (GetFatEntry(cluster, aFat) != 0)
   713             {
   727             {
   714             HBufC8* buf=HBufC8::New(gBytesPerCluster);
   728             HBufC8* buf=HBufC8::New(gBytesPerCluster);
   715             test(buf!=NULL);
   729             test_NotNull(buf);
   716             TPtr8 ptr=buf->Des();
   730             TPtr8 ptr=buf->Des();
   717             TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
   731             TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
   718             test(r==KErrNone);
   732             test_KErrNone(r);
   719             r=TheRawDisk.Read(ClusterToByte(cluster), ptr);
   733             r=TheRawDisk.Read(ClusterToByte(cluster), ptr);
   720             test(r==KErrNone);
   734             test_KErrNone(r);
   721             TheRawDisk.Close();
   735             TheRawDisk.Close();
   722             RDebug::Print(_L("Cluster %d @ 0x%08X:"), cluster, ClusterToByte(cluster));
   736             RDebug::Print(_L("Cluster %d @ 0x%08X:"), cluster, ClusterToByte(cluster));
   723             DumpDirCluster(ptr.Ptr());
   737             DumpDirCluster(ptr.Ptr());
   724             delete buf;
   738             delete buf;
   725             }
   739             }
   784 // Get the start cluster pertaining to a directory entry in a specific
   798 // Get the start cluster pertaining to a directory entry in a specific
   785 // directory cluster, return -1 if not available (invalid entry).
   799 // directory cluster, return -1 if not available (invalid entry).
   786 //
   800 //
   787     {
   801     {
   788     HBufC8* buf=HBufC8::New(gBytesPerCluster*2);
   802     HBufC8* buf=HBufC8::New(gBytesPerCluster*2);
   789     test(buf!=NULL);
   803     test_NotNull(buf);
   790     TPtr8 ptr=buf->Des();
   804     TPtr8 ptr=buf->Des();
   791     TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
   805     TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
   792     test(r==KErrNone);
   806     test_KErrNone(r);
   793     r=TheRawDisk.Read(ClusterToByte(aCluster), ptr);
   807     r=TheRawDisk.Read(ClusterToByte(aCluster), ptr);
   794     test(r==KErrNone);
   808     test_KErrNone(r);
   795     TheRawDisk.Close();
   809     TheRawDisk.Close();
   796     RDebug::Print(_L("Cluster %d @ 0x%08X:"), aCluster, ClusterToByte(aCluster));
   810     RDebug::Print(_L("Cluster %d @ 0x%08X:"), aCluster, ClusterToByte(aCluster));
   797     TFatDirEntry* d = (TFatDirEntry*)ptr.Ptr() + aEntry;
   811     TFatDirEntry* d = (TFatDirEntry*)ptr.Ptr() + aEntry;
   798     while (((TInt)d->Attributes() & KDirAttrLongMask) == KDirAttrLongName && aEntry < gEntriesPerCluster)
   812     while (((TInt)d->Attributes() & KDirAttrLongMask) == KDirAttrLongName && aEntry < gEntriesPerCluster)
   799         {
   813         {
   827     nRes = FormatFatDrive(TheFs, CurrentDrive(), ETrue, &fmt);
   841     nRes = FormatFatDrive(TheFs, CurrentDrive(), ETrue, &fmt);
   828 #else
   842 #else
   829     nRes = FormatFatDrive(TheFs, CurrentDrive(), ETrue);
   843     nRes = FormatFatDrive(TheFs, CurrentDrive(), ETrue);
   830 #endif
   844 #endif
   831 
   845 
   832     test(nRes == KErrNone);
   846     test_KErrNone(nRes);
   833 
   847 
   834     }
   848     }
   835 
   849 
   836 LOCAL_C void CreateDeepDir(TFileName& aDir,TInt aDepth)
   850 LOCAL_C void CreateDeepDir(TFileName& aDir,TInt aDepth)
   837 //
   851 //
   845     while(aDepth--)
   859     while(aDepth--)
   846         {
   860         {
   847         num[0] = TText(aDepth % 26 + 'A');
   861         num[0] = TText(aDepth % 26 + 'A');
   848         aDir+=num;
   862         aDir+=num;
   849         r=TheFs.MkDir(aDir);
   863         r=TheFs.MkDir(aDir);
   850         test(r==KErrNone);
   864         test_KErrNone(r);
   851         }
   865         }
   852     }
   866     }
   853 
   867 
   854 LOCAL_C void DeleteDeepDir(TFileName& aDir,TInt aDepth)
   868 LOCAL_C void DeleteDeepDir(TFileName& aDir,TInt aDepth)
   855 //
   869 //
   858     {
   872     {
   859     TInt r;
   873     TInt r;
   860     while(aDepth--)
   874     while(aDepth--)
   861         {
   875         {
   862         r=TheFs.RmDir(aDir);
   876         r=TheFs.RmDir(aDir);
   863         test(r==KErrNone);
   877         test_KErrNone(r);
   864         aDir.SetLength(aDir.Length()-2);
   878         aDir.SetLength(aDir.Length()-2);
   865         }
   879         }
   866     }
   880     }
   867 
   881 
   868 LOCAL_C void CreateMaxDepthDir(TFileName& aDir1,TFileName& aDir2)
   882 LOCAL_C void CreateMaxDepthDir(TFileName& aDir1,TFileName& aDir2)
   875     CreateDeepDir(aDir1,25);
   889     CreateDeepDir(aDir1,25);
   876     // split dir structure
   890     // split dir structure
   877     aDir2=aDir1;
   891     aDir2=aDir1;
   878     aDir2+=_L("a\\");
   892     aDir2+=_L("a\\");
   879     TInt r=TheFs.MkDir(aDir2);
   893     TInt r=TheFs.MkDir(aDir2);
   880     test(r==KErrNone);
   894     test_KErrNone(r);
   881     // create dir with depth of 126 directories - one short of max depth
   895     // create dir with depth of 126 directories - one short of max depth
   882     CreateDeepDir(aDir1,101);
   896     CreateDeepDir(aDir1,101);
   883     // create dir with depth of 90
   897     // create dir with depth of 90
   884     CreateDeepDir(aDir2,64);
   898     CreateDeepDir(aDir2,64);
   885     }
   899     }
   889 // Deletes max depth dir structure.
   903 // Deletes max depth dir structure.
   890 //
   904 //
   891     {
   905     {
   892     DeleteDeepDir(aDir2,64);
   906     DeleteDeepDir(aDir2,64);
   893     TInt r=TheFs.RmDir(aDir2);
   907     TInt r=TheFs.RmDir(aDir2);
   894     test(r==KErrNone);
   908     test_KErrNone(r);
   895     aDir2.SetLength(aDir2.Length()-2);
   909     aDir2.SetLength(aDir2.Length()-2);
   896     DeleteDeepDir(aDir1,102);
   910     DeleteDeepDir(aDir1,102);
   897     DeleteDeepDir(aDir1,24);
   911     DeleteDeepDir(aDir1,24);
   898     }
   912     }
   899 
   913 
   923         {
   937         {
   924         aLong[len+0] = TText(count/26 + 'A');
   938         aLong[len+0] = TText(count/26 + 'A');
   925         aLong[len+1] = TText(count%26 + 'A');
   939         aLong[len+1] = TText(count%26 + 'A');
   926         count++;
   940         count++;
   927         TInt r=temp.Create(TheFs,aLong,EFileShareAny);
   941         TInt r=temp.Create(TheFs,aLong,EFileShareAny);
   928         test(r==KErrNone);
   942         test_KErrNone(r);
   929         temp.Close();
   943         temp.Close();
   930         }
   944         }
   931     }
   945     }
   932 
   946 
   933 GLDEF_C void DeleteLongNames(TFileName& aLong, TInt aClusters)
   947 GLDEF_C void DeleteLongNames(TFileName& aLong, TInt aClusters)
   942         {
   956         {
   943         aLong[len+0] = TText(count/26 + 'A');
   957         aLong[len+0] = TText(count/26 + 'A');
   944         aLong[len+1] = TText(count%26 + 'A');
   958         aLong[len+1] = TText(count%26 + 'A');
   945         count++;
   959         count++;
   946         TInt r=TheFs.Delete(aLong);
   960         TInt r=TheFs.Delete(aLong);
   947         test(r==KErrNone || r==KErrNotFound);
   961         test_Value(r, r==KErrNone || r==KErrNotFound);
   948         }
   962         }
   949     }
   963     }
   950 
   964 
   951 LOCAL_C void DeleteRootDir(TInt aNum=0)
   965 LOCAL_C void DeleteRootDir(TInt aNum=0)
   952 //
   966 //
   964         {
   978         {
   965         name[1]=(TUint16)(count/26/26+'a');
   979         name[1]=(TUint16)(count/26/26+'a');
   966         name[2]=(TUint16)(count/26%26+'a');
   980         name[2]=(TUint16)(count/26%26+'a');
   967         name[3]=(TUint16)(count%26+'a');
   981         name[3]=(TUint16)(count%26+'a');
   968         r=TheFs.Delete(name);
   982         r=TheFs.Delete(name);
   969         test(r==KErrNone || r==KErrNotFound);
   983         test_Value(r, r==KErrNone || r==KErrNotFound);
   970         ++count;
   984         ++count;
   971         }
   985         }
   972     }
   986     }
   973 
   987 
   974 LOCAL_C void CreateRootDir()
   988 LOCAL_C void CreateRootDir()
   988         {
  1002         {
   989         name[1]=(TUint16)(count/26/26+'a');
  1003         name[1]=(TUint16)(count/26/26+'a');
   990         name[2]=(TUint16)(count/26%26+'a');
  1004         name[2]=(TUint16)(count/26%26+'a');
   991         name[3]=(TUint16)(count%26+'a');
  1005         name[3]=(TUint16)(count%26+'a');
   992         r=f.Create(TheFs, name, EFileWrite);
  1006         r=f.Create(TheFs, name, EFileWrite);
   993         test(r==KErrNone);
  1007         test_KErrNone(r);
   994         f.Close();
  1008         f.Close();
   995         ++count;
  1009         ++count;
   996         }
  1010         }
   997     DeleteRootDir(1);
  1011     DeleteRootDir(1);
   998     }
  1012     }
  1010     while(entriesSoFar<maxRootEntries)
  1024     while(entriesSoFar<maxRootEntries)
  1011         {
  1025         {
  1012         dir[1]=(TUint16)(count/26+'a');
  1026         dir[1]=(TUint16)(count/26+'a');
  1013         dir[2]=(TUint16)(count%26+'a');
  1027         dir[2]=(TUint16)(count%26+'a');
  1014         r=TheFs.MkDir(dir);
  1028         r=TheFs.MkDir(dir);
  1015         test(r==KErrNone);
  1029         test_KErrNone(r);
  1016         entriesSoFar+=2;
  1030         entriesSoFar+=2;
  1017         ++count;
  1031         ++count;
  1018         }
  1032         }
  1019     }
  1033     }
  1020 
  1034 
  1030     while(entriesSoFar>2)
  1044     while(entriesSoFar>2)
  1031         {
  1045         {
  1032         dir[1]=TUint16(count/26+'a');
  1046         dir[1]=TUint16(count/26+'a');
  1033         dir[2]=TUint16(count%26+'a');
  1047         dir[2]=TUint16(count%26+'a');
  1034         r=TheFs.RmDir(dir);
  1048         r=TheFs.RmDir(dir);
  1035         test(r==KErrNone);
  1049         test_KErrNone(r);
  1036         entriesSoFar-=2;
  1050         entriesSoFar-=2;
  1037         ++count;
  1051         ++count;
  1038         }
  1052         }
  1039     }
  1053     }
  1040 
  1054 
  1043 // deletes the directory structure
  1057 // deletes the directory structure
  1044 //
  1058 //
  1045     {
  1059     {
  1046     test.Next(_L("Delete Directory Structure"));
  1060     test.Next(_L("Delete Directory Structure"));
  1047     TInt r=TheFs.RmDir(_L("\\scndrv\\dir2\\almostfull\\"));
  1061     TInt r=TheFs.RmDir(_L("\\scndrv\\dir2\\almostfull\\"));
  1048     test(r==KErrNone);
  1062     test_KErrNone(r);
  1049     TInt entriesNeeded=(gEntriesPerCluster-2) / 2;  //7*2entries + . + .. = full sector
  1063     TInt entriesNeeded=(gEntriesPerCluster-2) / 2;  //7*2entries + . + .. = full sector
  1050     for (TInt i = 0; i < entriesNeeded; i++)
  1064     for (TInt i = 0; i < entriesNeeded; i++)
  1051         {
  1065         {
  1052         TFileName file=_L("\\scndrv\\dir2\\full\\__a");
  1066         TFileName file=_L("\\scndrv\\dir2\\full\\__a");
  1053         file.AppendNum(i);
  1067         file.AppendNum(i);
  1054         r=TheFs.Delete(file);
  1068         r=TheFs.Delete(file);
  1055         test(r==KErrNone||r==KErrNotFound);
  1069         test_Value(r, r==KErrNone||r==KErrNotFound);
  1056         }
  1070         }
  1057     r=TheFs.RmDir(_L("\\scndrv\\dir2\\full\\"));
  1071     r=TheFs.RmDir(_L("\\scndrv\\dir2\\full\\"));
  1058     test(r==KErrNone);
  1072     test_KErrNone(r);
  1059     r=TheFs.RmDir(_L("\\scndrv\\dir2\\"));
  1073     r=TheFs.RmDir(_L("\\scndrv\\dir2\\"));
  1060     test(r==KErrNone);
  1074     test_KErrNone(r);
  1061     TFileName veryLongName=(_L("\\scndrv\\dir1\\"));
  1075     TFileName veryLongName=(_L("\\scndrv\\dir1\\"));
  1062     MakeVeryLongName(veryLongName);
  1076     MakeVeryLongName(veryLongName);
  1063     r=TheFs.Delete(veryLongName);
  1077     r=TheFs.Delete(veryLongName);
  1064     test(r==KErrNone);
  1078     test_KErrNone(r);
  1065     r=TheFs.RmDir(_L("\\scndrv\\dir1\\"));
  1079     r=TheFs.RmDir(_L("\\scndrv\\dir1\\"));
  1066     test(r==KErrNone);
  1080     test_KErrNone(r);
  1067     r=TheFs.RmDir(_L("\\scndrv\\"));
  1081     r=TheFs.RmDir(_L("\\scndrv\\"));
  1068     test(r==KErrNone);
  1082     test_KErrNone(r);
  1069     }
  1083     }
  1070 
  1084 
  1071 LOCAL_C void CreateDirectoryStructure()
  1085 LOCAL_C void CreateDirectoryStructure()
  1072 //
  1086 //
  1073 // creates the directory structure
  1087 // creates the directory structure
  1074 //
  1088 //
  1075     {
  1089     {
  1076     test.Next(_L("Create Directory Structure"));
  1090     test.Next(_L("Create Directory Structure"));
  1077     // cluster 3 (root dir is cluster 2)
  1091     // cluster 3 (root dir is cluster 2)
  1078     TInt r=TheFs.MkDir(_L("\\scndrv\\"));
  1092     TInt r=TheFs.MkDir(_L("\\scndrv\\"));
  1079     test(r==KErrNone);
  1093     test_KErrNone(r);
  1080     // cluster 4
  1094     // cluster 4
  1081     r=TheFs.MkDir(_L("\\scndrv\\dir1\\"));
  1095     r=TheFs.MkDir(_L("\\scndrv\\dir1\\"));
  1082     test(r==KErrNone);
  1096     test_KErrNone(r);
  1083     TFileName veryLongName=(_L("\\scndrv\\dir1\\"));
  1097     TFileName veryLongName=(_L("\\scndrv\\dir1\\"));
  1084     MakeVeryLongName(veryLongName);
  1098     MakeVeryLongName(veryLongName);
  1085     RFile f;
  1099     RFile f;
  1086     // cluster 5
  1100     // cluster 5
  1087     r=f.Create(TheFs,veryLongName,EFileShareAny);
  1101     r=f.Create(TheFs,veryLongName,EFileShareAny);
  1088     test(r==KErrNone);
  1102     test_KErrNone(r);
  1089     r=f.SetSize(512);
  1103     r=f.SetSize(512);
  1090     test(r==KErrNone);
  1104     test_KErrNone(r);
  1091     f.Close();
  1105     f.Close();
  1092     // cluster 6
  1106     // cluster 6
  1093     r=TheFs.MkDir(_L("\\scndrv\\dir2\\"));
  1107     r=TheFs.MkDir(_L("\\scndrv\\dir2\\"));
  1094     test(r==KErrNone);
  1108     test_KErrNone(r);
  1095     // cluster 7
  1109     // cluster 7
  1096     r=TheFs.MkDir(_L("\\scndrv\\dir2\\full\\"));
  1110     r=TheFs.MkDir(_L("\\scndrv\\dir2\\full\\"));
  1097     test(r==KErrNone);
  1111     test_KErrNone(r);
  1098     // cluster 8
  1112     // cluster 8
  1099     r=TheFs.MkDir(_L("\\scndrv\\dir2\\somedirwith3entries\\"));
  1113     r=TheFs.MkDir(_L("\\scndrv\\dir2\\somedirwith3entries\\"));
  1100     test(r==KErrNone);
  1114     test_KErrNone(r);
  1101     // cluster 9
  1115     // cluster 9
  1102     r=TheFs.MkDir(_L("\\scndrv\\dir2\\somedir2with3entries\\"));
  1116     r=TheFs.MkDir(_L("\\scndrv\\dir2\\somedir2with3entries\\"));
  1103     test(r==KErrNone);
  1117     test_KErrNone(r);
  1104     // cluster 10
  1118     // cluster 10
  1105     r=TheFs.MkDir(_L("\\scndrv\\dir2\\almostfull\\"));
  1119     r=TheFs.MkDir(_L("\\scndrv\\dir2\\almostfull\\"));
  1106     test(r==KErrNone);
  1120     test_KErrNone(r);
  1107     // cluster 11-17
  1121     // cluster 11-17
  1108     TInt entriesNeeded=(gEntriesPerCluster-2) / 2;  //7*2entries + . + .. = full sector
  1122     TInt entriesNeeded=(gEntriesPerCluster-2) / 2;  //7*2entries + . + .. = full sector
  1109     for (TInt i = 0; i < entriesNeeded; i++)
  1123     for (TInt i = 0; i < entriesNeeded; i++)
  1110         {
  1124         {
  1111         TFileName file=_L("\\scndrv\\dir2\\full\\__a");
  1125         TFileName file=_L("\\scndrv\\dir2\\full\\__a");
  1112         file.AppendNum(i);
  1126         file.AppendNum(i);
  1113         LastInFull = file;
  1127         LastInFull = file;
  1114         r=f.Create(TheFs,file,EFileShareAny);
  1128         r=f.Create(TheFs,file,EFileShareAny);
  1115         test(r==KErrNone);
  1129         test_KErrNone(r);
  1116         if (i < 7)
  1130         if (i < 7)
  1117             {
  1131             {
  1118             r=f.SetSize(512);
  1132             r=f.SetSize(512);
  1119             test(r==KErrNone);
  1133             test_KErrNone(r);
  1120             }
  1134             }
  1121         f.Close();
  1135         f.Close();
  1122         }
  1136         }
  1123     // cluster 18-19
  1137     // cluster 18-19
  1124     TInt charLength=13*4+1; // name to take up 6 entries
  1138     TInt charLength=13*4+1; // name to take up 6 entries
  1130         }
  1144         }
  1131     TFileName file2=file1;
  1145     TFileName file2=file1;
  1132     file1.AppendNum(1);
  1146     file1.AppendNum(1);
  1133     file2.AppendNum(2);
  1147     file2.AppendNum(2);
  1134     r=f.Create(TheFs,file1,EFileShareAny);
  1148     r=f.Create(TheFs,file1,EFileShareAny);
  1135     test(r==KErrNone);
  1149     test_KErrNone(r);
  1136     r=f.SetSize(512);
  1150     r=f.SetSize(512);
  1137     test(r==KErrNone);
  1151     test_KErrNone(r);
  1138     f.Close();
  1152     f.Close();
  1139     r=f.Create(TheFs,file2,EFileShareAny);
  1153     r=f.Create(TheFs,file2,EFileShareAny);
  1140     test(r==KErrNone);
  1154     test_KErrNone(r);
  1141     r=f.SetSize(512);
  1155     r=f.SetSize(512);
  1142     test(r==KErrNone);
  1156     test_KErrNone(r);
  1143     f.Close();
  1157     f.Close();
  1144     }
  1158     }
  1145 
  1159 
  1146 LOCAL_C TUint8* DirPtr(TInt aOffset)
  1160 LOCAL_C TUint8* DirPtr(TInt aOffset)
  1147 //
  1161 //
  1163         {
  1177         {
  1164         // allocate buffer for 2 clusters, starting at the cluster which
  1178         // allocate buffer for 2 clusters, starting at the cluster which
  1165         // contains aOffset
  1179         // contains aOffset
  1166         ExtBufLen = 2 * gBytesPerCluster;
  1180         ExtBufLen = 2 * gBytesPerCluster;
  1167         ExtBufPtr = HBufC8::New(ExtBufLen);
  1181         ExtBufPtr = HBufC8::New(ExtBufLen);
  1168         test(ExtBufPtr != NULL);
  1182         test_NotNull(ExtBufPtr);
  1169         // read the clusters in
  1183         // read the clusters in
  1170         ExtBufAdd = aOffset - aOffset % gBytesPerCluster;
  1184         ExtBufAdd = aOffset - aOffset % gBytesPerCluster;
  1171         TInt clust = (ExtBufAdd - (gDataStartBytes - gRootDirStart)) /gBytesPerCluster + 2;
  1185         TInt clust = (ExtBufAdd - (gDataStartBytes - gRootDirStart)) /gBytesPerCluster + 2;
  1172         RDebug::Print(_L("Extension buffer for cluster %d allocated"), clust);
  1186         RDebug::Print(_L("Extension buffer for cluster %d allocated"), clust);
  1173         TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
  1187         TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
  1174         test(r==KErrNone);
  1188         test_KErrNone(r);
  1175         TPtr8 des(ExtBufPtr->Des());
  1189         TPtr8 des(ExtBufPtr->Des());
  1176         r=TheRawDisk.Read(gRootDirStart + ExtBufAdd, des);
  1190         r=TheRawDisk.Read(gRootDirStart + ExtBufAdd, des);
  1177         test(r==KErrNone);
  1191         test_KErrNone(r);
  1178         TheRawDisk.Close();
  1192         TheRawDisk.Close();
  1179         }
  1193         }
  1180     // convert to offset in the extension buffer
  1194     // convert to offset in the extension buffer
  1181     aOffset -= ExtBufAdd;
  1195     aOffset -= ExtBufAdd;
  1182     if (aOffset >= ExtBufLen)
  1196     if (aOffset >= ExtBufLen)
  1207 LOCAL_C void ReadDirDisk(TDes8& aDirBuf, TInt aCluster = -1)
  1221 LOCAL_C void ReadDirDisk(TDes8& aDirBuf, TInt aCluster = -1)
  1208 //
  1222 //
  1209 // reads directory section of disk into buffer
  1223 // reads directory section of disk into buffer
  1210 //
  1224 //
  1211     {
  1225     {
  1212     test(aCluster != 1);
  1226     test_Value(aCluster, aCluster != 1);
  1213 
  1227 
  1214     TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
  1228     TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
  1215     test(r==KErrNone);
  1229     test_KErrNone(r);
  1216 
  1230 
  1217     if (aCluster == -1) // all clusters ?
  1231     if (aCluster == -1) // all clusters ?
  1218         {
  1232         {
  1219         r=TheRawDisk.Read(gRootDirStart, aDirBuf);
  1233         r=TheRawDisk.Read(gRootDirStart, aDirBuf);
  1220         }
  1234         }
  1231             (gRootDirSectors * BootSector.BytesPerSector());
  1245             (gRootDirSectors * BootSector.BytesPerSector());
  1232         TPtr8 dirPtr = aDirBuf.MidTPtr(pos, gBytesPerCluster);
  1246         TPtr8 dirPtr = aDirBuf.MidTPtr(pos, gBytesPerCluster);
  1233         r=TheRawDisk.Read(gRootDirStart + pos, dirPtr);
  1247         r=TheRawDisk.Read(gRootDirStart + pos, dirPtr);
  1234         }
  1248         }
  1235 
  1249 
  1236     test(r==KErrNone);
  1250     test_KErrNone(r);
  1237     TheRawDisk.Close();
  1251     TheRawDisk.Close();
  1238     }
  1252     }
  1239 
  1253 
  1240 LOCAL_C void ReadFatDisk(TDes8& aFatBuf)
  1254 LOCAL_C void ReadFatDisk(TDes8& aFatBuf)
  1241 //
  1255 //
  1242 // reads fat section of disk info buffer
  1256 // reads fat section of disk info buffer
  1243 //
  1257 //
  1244     {
  1258     {
  1245     TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
  1259     TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
  1246     test(r==KErrNone);
  1260     test_KErrNone(r);
  1247     r=TheRawDisk.Read(gFatStartBytes, aFatBuf);
  1261     r=TheRawDisk.Read(gFatStartBytes, aFatBuf);
  1248     test(r==KErrNone);
  1262     test_KErrNone(r);
  1249     TheRawDisk.Close();
  1263     TheRawDisk.Close();
  1250     }
  1264     }
  1251 
  1265 
  1252 LOCAL_C void WriteDirDisk(TDes8& aDirBuf, TInt aCluster = -1)
  1266 LOCAL_C void WriteDirEntryToDisk(TDes8& aDirBuf, TInt aCluster = -1)
  1253 //
  1267 //
  1254 // writes dir buffer to disk
  1268 // writes dir entry buffer to disk
  1255 //
  1269 //
  1256     {
  1270     {
  1257     test(aCluster != 1);
  1271 	test_Value(aCluster, aCluster != 1);
  1258 
  1272 
  1259     TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
  1273     TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
  1260     test(r==KErrNone);
  1274     test_KErrNone(r);
  1261 
  1275 
  1262     if (aCluster == -1)
  1276     if (aCluster == -1)
  1263         {
  1277         {
  1264         r=TheRawDisk.Write(gRootDirStart, aDirBuf);
  1278         r=TheRawDisk.Write(gRootDirStart, aDirBuf);
  1265         }
  1279         }
  1276             (gRootDirSectors * BootSector.BytesPerSector());
  1290             (gRootDirSectors * BootSector.BytesPerSector());
  1277         TPtr8 dirPtr = aDirBuf.MidTPtr(pos, gBytesPerCluster);
  1291         TPtr8 dirPtr = aDirBuf.MidTPtr(pos, gBytesPerCluster);
  1278         r=TheRawDisk.Write(gRootDirStart + pos, dirPtr);
  1292         r=TheRawDisk.Write(gRootDirStart + pos, dirPtr);
  1279         }
  1293         }
  1280 
  1294 
  1281     test(r==KErrNone);
  1295     test_KErrNone(r);
  1282     if (ExtBufPtr)
  1296     if (ExtBufPtr)
  1283         {
  1297         {
  1284         TPtr8 des(ExtBufPtr->Des());
  1298         TPtr8 des(ExtBufPtr->Des());
  1285         r=TheRawDisk.Write(gRootDirStart + ExtBufAdd, des);
  1299         r=TheRawDisk.Write(gRootDirStart + ExtBufAdd, des);
  1286         test(r==KErrNone);
  1300         test_KErrNone(r);
  1287         }
  1301         }
  1288     TheRawDisk.Close();
  1302     TheRawDisk.Close();
  1289     }
  1303     }
  1290 
  1304 
  1291 LOCAL_C void WriteFatDisk(TDes8& aFatBuf, TInt aStart=0)
  1305 LOCAL_C void WriteFatToDisk(TDes8& aFatBuf, TInt aStart=0)
  1292 //
  1306 //
  1293 // writes fat buffer to disk
  1307 // writes fat buffer to disk
  1294 //
  1308 //
  1295     {
  1309     {
  1296     TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
  1310     TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
  1297     test(r==KErrNone);
  1311     test_KErrNone(r);
  1298     TInt fatCount=BootSector.NumberOfFats() - aStart;
  1312     TInt fatCount=BootSector.NumberOfFats() - aStart;
  1299     TInt pos = gFatStartBytes + aStart * gFatSizeSectors*BootSector.BytesPerSector();
  1313     TInt pos = gFatStartBytes + aStart * gFatSizeSectors*BootSector.BytesPerSector();
  1300     while(fatCount--)
  1314     while(fatCount--)
  1301         {
  1315         {
  1302         r=TheRawDisk.Write(pos, aFatBuf);
  1316         r=TheRawDisk.Write(pos, aFatBuf);
  1303         test(r==KErrNone);
  1317         test_KErrNone(r);
  1304         pos += gFatSizeSectors*BootSector.BytesPerSector();
  1318         pos += gFatSizeSectors*BootSector.BytesPerSector();
  1305         }
  1319         }
  1306     TheRawDisk.Close();
  1320     TheRawDisk.Close();
  1307     }
  1321     }
  1308 
  1322 
  1355     gFatTestEntries = MaxClusters();
  1369     gFatTestEntries = MaxClusters();
  1356     if (gFatTestEntries > KMaxFatSize)
  1370     if (gFatTestEntries > KMaxFatSize)
  1357         gFatTestEntries = KMaxFatSize;
  1371         gFatTestEntries = KMaxFatSize;
  1358     gFatTestSize = PosInBytes(gFatTestEntries);
  1372     gFatTestSize = PosInBytes(gFatTestEntries);
  1359     FatBufPtr=HBufC8::New(gFatTestSize);
  1373     FatBufPtr=HBufC8::New(gFatTestSize);
  1360     test(FatBufPtr!=NULL);
  1374     test_NotNull(FatBufPtr);
  1361     DirBufPtr=HBufC8::New(DirBufferSize());
  1375     DirBufPtr=HBufC8::New(DirBufferSize());
  1362     test(DirBufPtr!=NULL);
  1376     test_NotNull(DirBufPtr);
  1363 
  1377 
  1364     // Buffers for reading from disk
  1378     // Buffers for reading from disk
  1365     FatDiskPtr=HBufC8::New(gFatTestSize);
  1379     FatDiskPtr=HBufC8::New(gFatTestSize);
  1366     test(FatDiskPtr!=NULL);
  1380     test_NotNull(FatDiskPtr);
  1367     DirDiskPtr=HBufC8::New(DirBufferSize());
  1381     DirDiskPtr=HBufC8::New(DirBufferSize());
  1368     test(DirDiskPtr!=NULL);
  1382     test_NotNull(DirDiskPtr);
  1369     }
  1383     }
  1370 
  1384 
  1371 LOCAL_C TBool IsSameAsDrive(const TDes8& aFatBuf,const TDes8& aDirBuf)
  1385 LOCAL_C TBool IsSameAsDrive(const TDes8& aFatBuf,const TDes8& aDirBuf)
  1372 //
  1386 //
  1373 // compares the two bufs passed in with those on disk
  1387 // compares the two bufs passed in with those on disk
  1450 		DumpData(fatDisk.Ptr(), dirDisk.Ptr());
  1464 		DumpData(fatDisk.Ptr(), dirDisk.Ptr());
  1451         }
  1465         }
  1452     else if (ExtBufPtr)
  1466     else if (ExtBufPtr)
  1453         {
  1467         {
  1454         HBufC8* extPtr = HBufC8::New(ExtBufLen);
  1468         HBufC8* extPtr = HBufC8::New(ExtBufLen);
  1455         test(extPtr != NULL);
  1469         test_NotNull(extPtr);
  1456         TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
  1470         TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
  1457         test(r==KErrNone);
  1471         test_KErrNone(r);
  1458         TPtr8 des(extPtr->Des());
  1472         TPtr8 des(extPtr->Des());
  1459         r=TheRawDisk.Read(ExtBufAdd+gRootDirStart, des);
  1473         r=TheRawDisk.Read(ExtBufAdd+gRootDirStart, des);
  1460         test(r==KErrNone);
  1474         test_KErrNone(r);
  1461         TheRawDisk.Close();
  1475         TheRawDisk.Close();
  1462         TInt i = FindUnMatch(ExtBufPtr->Ptr(), extPtr->Ptr(), ExtBufLen);
  1476         TInt i = FindUnMatch(ExtBufPtr->Ptr(), extPtr->Ptr(), ExtBufLen);
  1463         if (i >= 0)
  1477         if (i >= 0)
  1464             {
  1478             {
  1465             TInt extcl = (ExtBufAdd - (gDataStartBytes-gRootDirStart)) / gBytesPerCluster + 2;
  1479             TInt extcl = (ExtBufAdd - (gDataStartBytes-gRootDirStart)) / gBytesPerCluster + 2;
  1504     {
  1518     {
  1505     WriteErased(aTrg,aToDelete);
  1519     WriteErased(aTrg,aToDelete);
  1506     if(aAddEOfDir)
  1520     if(aAddEOfDir)
  1507         WriteEndOfDir(aTrg.iBytePos+aTrg.iLength*KSizeOfFatDirEntry);
  1521         WriteEndOfDir(aTrg.iBytePos+aTrg.iLength*KSizeOfFatDirEntry);
  1508     TPtr8 dirBuf=DirBufPtr->Des();
  1522     TPtr8 dirBuf=DirBufPtr->Des();
  1509     WriteDirDisk(dirBuf);
  1523     WriteDirEntryToDisk(dirBuf);
  1510     }
  1524     }
  1511 
  1525 
  1512 LOCAL_C TBool TestPartialEntry(TEntryInfo aEntry)
  1526 LOCAL_C TBool TestPartialEntry(TEntryInfo aEntry)
  1513 //
  1527 //
  1514 // tests that scandrive deals with a partial entry and returns the result
  1528 // tests that scandrive deals with a partial entry and returns the result
  1515 //
  1529 //
  1516     {
  1530     {
  1517     test.Next(_L("TestPartialEntry"));
  1531     test.Next(_L("TestPartialEntry"));
  1518     TInt r=TheFs.ScanDrive(gSessionPath);
  1532     TInt r=TheFs.ScanDrive(gSessionPath);
  1519     test(r==KErrNone);
  1533     test_KErrNone(r);
  1520     WriteDelete(aEntry.iBytePos,aEntry.iLength);
  1534     WriteDelete(aEntry.iBytePos,aEntry.iLength);
  1521 
  1535 
  1522     TPtr8 fatBuf=FatBufPtr->Des();
  1536     TPtr8 fatBuf=FatBufPtr->Des();
  1523     TPtr8 dirBuf=DirBufPtr->Des();
  1537     TPtr8 dirBuf=DirBufPtr->Des();
  1524 
  1538 
  1537     Mem::Copy(dst, src, aSrc.iLength*KSizeOfFatDirEntry);
  1551     Mem::Copy(dst, src, aSrc.iLength*KSizeOfFatDirEntry);
  1538     WriteReservedId(aTrg.iBytePos+(aTrg.iLength-1)*KSizeOfFatDirEntry);
  1552     WriteReservedId(aTrg.iBytePos+(aTrg.iLength-1)*KSizeOfFatDirEntry);
  1539     if(aAddEOfDir)
  1553     if(aAddEOfDir)
  1540         WriteEndOfDir(aTrg.iBytePos+aTrg.iLength*KSizeOfFatDirEntry);
  1554         WriteEndOfDir(aTrg.iBytePos+aTrg.iLength*KSizeOfFatDirEntry);
  1541     TPtr8 dirBuf=DirBufPtr->Des();
  1555     TPtr8 dirBuf=DirBufPtr->Des();
  1542     WriteDirDisk(dirBuf);
  1556     WriteDirEntryToDisk(dirBuf);
  1543     }
  1557     }
  1544 
  1558 
  1545 LOCAL_C TBool TestMatchingEntry(TEntryInfo aToDelete)
  1559 LOCAL_C TBool TestMatchingEntry(TEntryInfo aToDelete)
  1546 //
  1560 //
  1547 // tests that scandrive deals with matching entries correctly
  1561 // tests that scandrive deals with matching entries correctly
  1548 //
  1562 //
  1549     {
  1563     {
  1550     test.Next(_L("TestMatchingEntries"));
  1564     test.Next(_L("TestMatchingEntries"));
  1551     WriteDelete(aToDelete.iBytePos,aToDelete.iLength);
  1565     WriteDelete(aToDelete.iBytePos,aToDelete.iLength);
  1552     TInt r=TheFs.ScanDrive(gSessionPath);
  1566     TInt r=TheFs.ScanDrive(gSessionPath);
  1553     test(r==KErrNone);
  1567     test_KErrNone(r);
  1554 
  1568 
  1555     TPtr8 fatBuf=FatBufPtr->Des();
  1569     TPtr8 fatBuf=FatBufPtr->Des();
  1556     TPtr8 dirBuf=DirBufPtr->Des();
  1570     TPtr8 dirBuf=DirBufPtr->Des();
  1557 
  1571 
  1558     TBool res=IsSameAsDrive(fatBuf,dirBuf);
  1572     TBool res=IsSameAsDrive(fatBuf,dirBuf);
  1572 
  1586 
  1573     _LIT(KRoot,"\\");
  1587     _LIT(KRoot,"\\");
  1574     CDir* dirs;
  1588     CDir* dirs;
  1575     // check no entries in the root directory
  1589     // check no entries in the root directory
  1576     TInt r=TheFs.GetDir(KRoot,KEntryAttMaskSupported,ESortNone,dirs);
  1590     TInt r=TheFs.GetDir(KRoot,KEntryAttMaskSupported,ESortNone,dirs);
  1577     test(r==KErrNone);
  1591     test_KErrNone(r);
  1578     test(dirs->Count()==0);
  1592     test_Equal(0,dirs->Count());
  1579     delete(dirs);
  1593     delete(dirs);
  1580     dirs=NULL;
  1594     dirs=NULL;
  1581 
  1595 
  1582     // create file
  1596     // create file
  1583     _LIT(KOrigShortName,"P_SSI.TXT");
  1597     _LIT(KOrigShortName,"P_SSI.TXT");
  1591     ExtShortName[1] = 0xC4; //-- replace '$' with this code
  1605     ExtShortName[1] = 0xC4; //-- replace '$' with this code
  1592 
  1606 
  1593 
  1607 
  1594     RFile file;
  1608     RFile file;
  1595     r=file.Replace(TheFs,TestFileName,EFileShareExclusive);
  1609     r=file.Replace(TheFs,TestFileName,EFileShareExclusive);
  1596     test(r==KErrNone);
  1610     test_KErrNone(r);
  1597     file.Close();
  1611     file.Close();
  1598 
  1612 
  1599     // get short name
  1613     // get short name
  1600     TFileName shortName;
  1614     TFileName shortName;
  1601     r=TheFs.GetShortName(TestFileName,shortName);
  1615     r=TheFs.GetShortName(TestFileName,shortName);
  1602     test(r==KErrNone);
  1616     test_KErrNone(r);
  1603     test(shortName==KOrigShortName);
  1617     test(shortName==KOrigShortName);
  1604 
  1618 
  1605     // must be first entry in root, modify to read like
  1619     // must be first entry in root, modify to read like
  1606     // a windows-generated short name (ie. contains extended character)
  1620     // a windows-generated short name (ie. contains extended character)
  1607     DumpData(NULL, 0, 20);
  1621     DumpData(NULL, 0, 20);
  1608     TInt bytePos=ClusterEntryToBytes(0,1);
  1622     TInt bytePos=ClusterEntryToBytes(0,1);
  1609     RRawDisk raw;
  1623     RRawDisk raw;
  1610     r=raw.Open(TheFs,gSessionPath[0]-'A');
  1624     r=raw.Open(TheFs,gSessionPath[0]-'A');
  1611     test(r==KErrNone);
  1625     test_KErrNone(r);
  1612     TBuf8<1> buf(1);
  1626     TBuf8<1> buf(1);
  1613 
  1627 
  1614     //-- change 2nd character in the short name (Fat DOS entry)
  1628     //-- change 2nd character in the short name (Fat DOS entry)
  1615     buf[0]=(TUint8)'\xC4';
  1629     buf[0]=(TUint8)'\xC4';
  1616     r=raw.Write(gRootDirStart+bytePos+1,buf);
  1630     r=raw.Write(gRootDirStart+bytePos+1,buf);
  1617     test(r==KErrNone);
  1631     test_KErrNone(r);
  1618 
  1632 
  1619     //-- fix the fiddled short name checksum in the corresponding VFat entry
  1633     //-- fix the fiddled short name checksum in the corresponding VFat entry
  1620     bytePos=ClusterEntryToBytes(0,0);
  1634     bytePos=ClusterEntryToBytes(0,0);
  1621     buf[0]=(TUint8)0x2f;
  1635     buf[0]=(TUint8)0x2f;
  1622     r=raw.Write(gRootDirStart+bytePos+13,buf);
  1636     r=raw.Write(gRootDirStart+bytePos+13,buf);
  1623     test(r==KErrNone);
  1637     test_KErrNone(r);
  1624 
  1638 
  1625     // retrieve short name from media.
  1639     // retrieve short name from media.
  1626     // Note: do not use RFs::GetShortName() as its behaviours are code page dependent.
  1640     // Note: do not use RFs::GetShortName() as its behaviours are code page dependent.
  1627     bytePos=ClusterEntryToBytes(0,1);
  1641     bytePos=ClusterEntryToBytes(0,1);
  1628     TBuf8<11> shortNameBuf8;
  1642     TBuf8<11> shortNameBuf8;
  1629     r=raw.Read(gRootDirStart+bytePos,shortNameBuf8);
  1643     r=raw.Read(gRootDirStart+bytePos,shortNameBuf8);
  1630     test(r==KErrNone);
  1644     test_KErrNone(r);
  1631     shortNameBuf8 = DosNameFromStdFormat(shortNameBuf8);
  1645     shortNameBuf8 = DosNameFromStdFormat(shortNameBuf8);
  1632     shortName.Copy(shortNameBuf8);
  1646     shortName.Copy(shortNameBuf8);
  1633     raw.Close();
  1647     raw.Close();
  1634 
  1648 
  1635 
  1649 
  1636     test(shortName==ExtShortName);
  1650     test(shortName==ExtShortName);
  1637     DumpData(NULL, 0, 20);
  1651     DumpData(NULL, 0, 20);
  1638     //TheFs.SetDebugRegister(KFSYS);
  1652     //TheFs.SetDebugRegister(KFSYS);
  1639     r=TheFs.ScanDrive(gSessionPath);
  1653     r=TheFs.ScanDrive(gSessionPath);
  1640     TheFs.SetDebugRegister(0);
  1654     TheFs.SetDebugRegister(0);
  1641     test(r==KErrNone);
  1655     test_KErrNone(r);
  1642     DumpData(NULL, 0, 20);
  1656     DumpData(NULL, 0, 20);
  1643 
  1657 
  1644     // retrieve short name from media.
  1658     // retrieve short name from media.
  1645     r=raw.Open(TheFs,gSessionPath[0]-'A');
  1659     r=raw.Open(TheFs,gSessionPath[0]-'A');
  1646     test(r==KErrNone);
  1660     test_KErrNone(r);
  1647     bytePos=ClusterEntryToBytes(0,1);
  1661     bytePos=ClusterEntryToBytes(0,1);
  1648     r=raw.Read(gRootDirStart+bytePos,shortNameBuf8);
  1662     r=raw.Read(gRootDirStart+bytePos,shortNameBuf8);
  1649     test(r==KErrNone);
  1663     test_KErrNone(r);
  1650     shortNameBuf8 = DosNameFromStdFormat(shortNameBuf8);
  1664     shortNameBuf8 = DosNameFromStdFormat(shortNameBuf8);
  1651     shortName.Copy(shortNameBuf8);
  1665     shortName.Copy(shortNameBuf8);
  1652     raw.Close();
  1666     raw.Close();
  1653 
  1667 
  1654     test(shortName==ExtShortName);
  1668     test(shortName==ExtShortName);
  1655 
  1669 
  1656     // delete file
  1670     // delete file
  1657     r=TheFs.Delete(TestFileName);
  1671     r=TheFs.Delete(TestFileName);
  1658     test(r==KErrNone);
  1672     test_KErrNone(r);
  1659     }
  1673     }
  1660 
  1674 
  1661 LOCAL_C void TestMountAndScan()
  1675 LOCAL_C void TestMountAndScan()
  1662 //
  1676 //
  1663 // test MountFileSystemAndScan()
  1677 // test MountFileSystemAndScan()
  1666     TFullName extName;
  1680     TFullName extName;
  1667     TBool primaryExtensionExists = EFalse;
  1681     TBool primaryExtensionExists = EFalse;
  1668 
  1682 
  1669     test.Next(_L("TestMountAndScan"));
  1683     test.Next(_L("TestMountAndScan"));
  1670     HBufC8* newFat=HBufC8::New(gFatTestSize);
  1684     HBufC8* newFat=HBufC8::New(gFatTestSize);
  1671     test(newFat!=NULL);
  1685     test_NotNull(newFat);
  1672     TPtr8 fat=newFat->Des();
  1686     TPtr8 fat=newFat->Des();
  1673     TPtr8 origFat=FatBufPtr->Des();
  1687     TPtr8 origFat=FatBufPtr->Des();
  1674     TPtr8 origDir=DirBufPtr->Des();
  1688     TPtr8 origDir=DirBufPtr->Des();
  1675 
  1689 
  1676     // set cluster of \scndrv\dir1\ to a hanging cluster
  1690     // set cluster of \scndrv\dir1\ to a hanging cluster
  1677     ReadFatDisk(fat);
  1691     ReadFatDisk(fat);
  1678     WriteFat(gClusterDir1ext,35,fat.Ptr());
  1692     WriteToFatBuf(gClusterDir1ext,35,fat.Ptr());
  1679     WriteFat(35,36,fat.Ptr());
  1693     WriteToFatBuf(35,36,fat.Ptr());
  1680     WriteFatDisk(fat);
  1694     WriteFatToDisk(fat);
  1681     // set the default path to something other than the current drive
  1695     // set the default path to something other than the current drive
  1682     TFileName fsName;
  1696     TFileName fsName;
  1683     TInt r=TheFs.FileSystemName(fsName,gSessionPath[0]-'A');
  1697     TInt r=TheFs.FileSystemName(fsName,gSessionPath[0]-'A');
  1684     test(r==KErrNone);
  1698     test_KErrNone(r);
  1685     TFileName origDefPath, newDefPath;
  1699     TFileName origDefPath, newDefPath;
  1686     r=TheFs.SessionPath(origDefPath);
  1700     r=TheFs.SessionPath(origDefPath);
  1687     test(r==KErrNone);
  1701     test_KErrNone(r);
  1688     newDefPath=origDefPath;
  1702     newDefPath=origDefPath;
  1689     newDefPath[0]=(TText)'z';
  1703     newDefPath[0]=(TText)'z';
  1690     r=TheFs.SetSessionPath(newDefPath);
  1704     r=TheFs.SetSessionPath(newDefPath);
  1691     test(r==KErrNone);
  1705     test_KErrNone(r);
  1692     r = TheFs.ExtensionName(extName,gSessionPath[0]-'A',0);
  1706     r = TheFs.ExtensionName(extName,gSessionPath[0]-'A',0);
  1693     if (r == KErrNone)
  1707     if (r == KErrNone)
  1694         {
  1708         {
  1695         primaryExtensionExists = ETrue;
  1709         primaryExtensionExists = ETrue;
  1696         }
  1710         }
  1697     r=TheFs.DismountFileSystem(fsName,gSessionPath[0]-'A');
  1711     r=TheFs.DismountFileSystem(fsName,gSessionPath[0]-'A');
  1698     test(r==KErrNone);
  1712     test_KErrNone(r);
  1699     // mount file system and check scandrive corrects error
  1713     // mount file system and check scandrive corrects error
  1700     TBool isMount;
  1714     TBool isMount;
  1701     if (primaryExtensionExists)
  1715     if (primaryExtensionExists)
  1702         r=TheFs.MountFileSystemAndScan(fsName,extName,gSessionPath[0]-'A',isMount);
  1716         r=TheFs.MountFileSystemAndScan(fsName,extName,gSessionPath[0]-'A',isMount);
  1703     else
  1717     else
  1704         r=TheFs.MountFileSystemAndScan(fsName,gSessionPath[0]-'A',isMount);
  1718         r=TheFs.MountFileSystemAndScan(fsName,gSessionPath[0]-'A',isMount);
  1705     test(isMount && r==KErrNone);
  1719     test(isMount);
       
  1720     test_KErrNone(r);
  1706     TBool res=IsSameAsDrive(origFat,origDir);
  1721     TBool res=IsSameAsDrive(origFat,origDir);
  1707     test(res);
  1722     test(res);
  1708 
  1723 
  1709     r=TheFs.SetSessionPath(origDefPath);
  1724     r=TheFs.SetSessionPath(origDefPath);
  1710     test(r==KErrNone);
  1725     test_KErrNone(r);
  1711     delete newFat;
  1726     delete newFat;
  1712     }
  1727     }
  1713 
  1728 
  1714 
  1729 
  1715 LOCAL_C void TestConsecutiveMountAndScans()
  1730 LOCAL_C void TestConsecutiveMountAndScans()
  1719     {
  1734     {
  1720     TFullName extName;
  1735     TFullName extName;
  1721     TBool primaryExtensionExists = EFalse;
  1736     TBool primaryExtensionExists = EFalse;
  1722     TFileName fsName;
  1737     TFileName fsName;
  1723     TInt r=TheFs.FileSystemName(fsName,gSessionPath[0]-'A');
  1738     TInt r=TheFs.FileSystemName(fsName,gSessionPath[0]-'A');
  1724     test(r==KErrNone);
  1739     test_KErrNone(r);
  1725     r = TheFs.ExtensionName(extName,gSessionPath[0]-'A',0);
  1740     r = TheFs.ExtensionName(extName,gSessionPath[0]-'A',0);
  1726     if (r == KErrNone)
  1741     if (r == KErrNone)
  1727         {
  1742         {
  1728         primaryExtensionExists = ETrue;
  1743         primaryExtensionExists = ETrue;
  1729         }
  1744         }
  1730     r=TheFs.DismountFileSystem(fsName,gSessionPath[0]-'A');
  1745     r=TheFs.DismountFileSystem(fsName,gSessionPath[0]-'A');
  1731     test(r==KErrNone);
  1746     test_KErrNone(r);
  1732 
  1747 
  1733     // RFs::MountFileSystemAndScan twice consecutively
  1748     // RFs::MountFileSystemAndScan twice consecutively
  1734     // first time
  1749     // first time
  1735     TBool isMount;
  1750     TBool isMount;
  1736     if (primaryExtensionExists)
  1751     if (primaryExtensionExists)
  1737         r=TheFs.MountFileSystemAndScan(fsName,extName,gSessionPath[0]-'A',isMount);
  1752         r=TheFs.MountFileSystemAndScan(fsName,extName,gSessionPath[0]-'A',isMount);
  1738     else
  1753     else
  1739         r=TheFs.MountFileSystemAndScan(fsName,gSessionPath[0]-'A',isMount);
  1754         r=TheFs.MountFileSystemAndScan(fsName,gSessionPath[0]-'A',isMount);
  1740     test(isMount && r==KErrNone);
  1755     test(isMount);
       
  1756     test_KErrNone(r);
  1741     // and a second time
  1757     // and a second time
  1742     if (primaryExtensionExists)
  1758     if (primaryExtensionExists)
  1743         r=TheFs.MountFileSystemAndScan(fsName,extName,gSessionPath[0]-'A',isMount);
  1759         r=TheFs.MountFileSystemAndScan(fsName,extName,gSessionPath[0]-'A',isMount);
  1744     else
  1760     else
  1745         r=TheFs.MountFileSystemAndScan(fsName,gSessionPath[0]-'A',isMount);
  1761         r=TheFs.MountFileSystemAndScan(fsName,gSessionPath[0]-'A',isMount);
  1746     test(!isMount && r==KErrAccessDenied);
  1762     test(!isMount);
  1747     }
  1763     test_Equal(KErrAccessDenied,r);
       
  1764     }
       
  1765 
       
  1766 
       
  1767 static void CreateContiguousClusterChain(TUint32 aStartIndex, TUint32 aEndIndex, const TUint8* aFatPtr, TBool aMarkEoc)
       
  1768 /*
       
  1769  * Creates a contiguous cluster chain in the FAT buffer.
       
  1770  * 
       
  1771  * @param	aStartIndex	The first cluster index of the chain
       
  1772  * 			aEndIndex	The last cluster index of the chain 
       
  1773  * 			aFatPtr		FAT table buffer pointer
       
  1774  * 			aMarkEoc	If ETrue, aEndIndex will be marked as EOC, else it will be a hanging cluster chain
       
  1775  */
       
  1776 	{
       
  1777 	// Write cluster chain
       
  1778     for(TUint i=aStartIndex; i<aEndIndex; ++i)
       
  1779         WriteToFatBuf(i, i+1, aFatPtr);
       
  1780     // Mark EOC if needed
       
  1781     if (aMarkEoc)
       
  1782     	WriteToFatBuf(aEndIndex, gEndOfChain, aFatPtr);
       
  1783 	}
       
  1784 
  1748 
  1785 
  1749 LOCAL_C void DoHangingClusters()
  1786 LOCAL_C void DoHangingClusters()
  1750 //
  1787 //
  1751 // Tests that scandrive removes hanging clusters
  1788 // Tests that scandrive removes hanging clusters
  1752 //
  1789 //
  1753     {
  1790     {
  1754     test.Next(_L("Check Hanging clusters"));
  1791     test.Next(_L("Check Hanging clusters"));
  1755     HBufC8* newFat=HBufC8::New(gFatTestSize);
  1792     HBufC8* newFat=HBufC8::New(gFatTestSize);
  1756     test(newFat!=NULL);
  1793     test_NotNull(newFat);
  1757     TPtr8 fat=newFat->Des();
  1794     TPtr8 fat=newFat->Des();
  1758     TPtr8 origFat=FatBufPtr->Des();
  1795     TPtr8 origFat=FatBufPtr->Des();
  1759     TPtr8 origDir=DirBufPtr->Des();
  1796     TPtr8 origDir=DirBufPtr->Des();
  1760 
  1797 
  1761     // set cluster of \scndrv\dir1\ to a hanging cluster
  1798     // Set cluster of \scndrv\dir1\ to hanging cluster chain
  1762     test.Start(_L("Test hanging cluster in \\scndrv\\dir1\\"));
  1799     test.Start(_L("Test hanging cluster in \\scndrv\\dir1\\"));
  1763     ReadFatDisk(fat);
  1800     ReadFatDisk(fat);
  1764     WriteFat(gClusterDir1ext,35,fat.Ptr());
  1801     WriteToFatBuf(gClusterDir1ext,35,fat.Ptr());
  1765     WriteFat(35,36,fat.Ptr());
  1802     WriteToFatBuf(35,36,fat.Ptr());
  1766     WriteFatDisk(fat);
  1803     WriteFatToDisk(fat); // gClusterDir1ext->35->36
  1767     TInt r=TheFs.ScanDrive(gSessionPath);
  1804     TInt r=TheFs.ScanDrive(gSessionPath);
  1768     test(r==KErrNone);
  1805     test_KErrNone(r);
  1769     TBool res=IsSameAsDrive(origFat,origDir);
  1806     TBool res=IsSameAsDrive(origFat,origDir);
  1770     test(res);
  1807     test(res);
  1771 
  1808 
  1772     // set  cluster chain of first entry of \scndrv\dir1\ to
  1809     // Set cluster chain of first entry of \scndrv\dir1\ to
  1773     // larger size than file size
  1810     // larger size than file size
  1774     test.Next(_L("Test hanging cluster in first entry"));
  1811     test.Next(_L("Test hanging cluster in first entry"));
  1775     ReadFatDisk(fat);
  1812     ReadFatDisk(fat);
  1776     WriteFat(gClusterDir1ext,39,fat.Ptr());
  1813     WriteToFatBuf(gClusterDir1ext,39,fat.Ptr());
  1777     WriteFat(39,500,fat.Ptr());
  1814     WriteToFatBuf(39,500,fat.Ptr());
  1778     WriteFat(500,gEndOfChain,fat.Ptr());
  1815     CreateContiguousClusterChain(500, 505, fat.Ptr(), ETrue);
  1779     WriteFatDisk(fat);
  1816     WriteFatToDisk(fat); // gClusterDir1ext->39->500->501->502->503->504->505->EOC
  1780     r=TheFs.ScanDrive(gSessionPath);
  1817     r=TheFs.ScanDrive(gSessionPath);
  1781     test(r==KErrNone);
  1818     test_KErrNone(r);
  1782     res=IsSameAsDrive(origFat,origDir);
  1819     res=IsSameAsDrive(origFat,origDir);
  1783     test(res);
  1820     test(res);
  1784 
  1821 
  1785     // set cluster of \scndrv\ to a hanging cluster
  1822     // Set cluster of \scndrv\ to a hanging cluster
  1786     test.Next(_L("Test hanging cluster of \\scndrv\\"));
  1823     test.Next(_L("Test hanging cluster of \\scndrv\\"));
  1787     ReadFatDisk(fat);
  1824     ReadFatDisk(fat);
  1788     WriteFat(gClusterScnDrv,511,fat.Ptr());
  1825     WriteToFatBuf(gClusterScnDrv,511,fat.Ptr());
  1789     WriteFatDisk(fat);
  1826     WriteFatToDisk(fat); // gClusterScnDrv->511
  1790     r=TheFs.ScanDrive(gSessionPath);
  1827     r=TheFs.ScanDrive(gSessionPath);
  1791     test(r==KErrNone);
  1828     test_KErrNone(r);
  1792     res=IsSameAsDrive(origFat,origDir);
  1829     res=IsSameAsDrive(origFat,origDir);
  1793     test(res);
  1830     test(res);
  1794 
  1831 
  1795     delete newFat;
  1832     delete newFat;
  1796     test.End();
  1833     test.End();
  1801 // Tests that scandrive removes lost clusters
  1838 // Tests that scandrive removes lost clusters
  1802 //
  1839 //
  1803     {
  1840     {
  1804     test.Next(_L("Check lost clusters"));
  1841     test.Next(_L("Check lost clusters"));
  1805     HBufC8* newFat=HBufC8::New(gFatTestSize);
  1842     HBufC8* newFat=HBufC8::New(gFatTestSize);
  1806     test(newFat!=NULL);
  1843     test_NotNull(newFat);
  1807     TPtr8 fat=newFat->Des();
  1844     TPtr8 fat=newFat->Des();
  1808     TPtr8 origFat=FatBufPtr->Des();
  1845     TPtr8 origFat=FatBufPtr->Des();
  1809     TPtr8 origDir=DirBufPtr->Des();
  1846     TPtr8 origDir=DirBufPtr->Des();
  1810     ReadFatDisk(origFat);
  1847     ReadFatDisk(origFat);
  1811     ReadDirDisk(origDir);
  1848     ReadDirDisk(origDir);
  1812 
  1849 
  1813     // write cluster chain
  1850     // write cluster chain
  1814     test.Start(_L("Test removal of lost cluster chain"));
  1851     test.Start(_L("Test removal of lost cluster chain"));
  1815     ReadFatDisk(fat);
  1852     ReadFatDisk(fat);
  1816     for(TInt i=25;i<35;++i)
  1853     CreateContiguousClusterChain(25, 35, fat.Ptr(), ETrue);
  1817         WriteFat(i,i+1,fat.Ptr());
  1854     WriteFatToDisk(fat); // 25->26->27->28->29->30->31->32->33->34->35->EOC
  1818     WriteFat(35,gEndOfChain,fat.Ptr());
       
  1819     WriteFatDisk(fat);
       
  1820     TInt r=TheFs.ScanDrive(gSessionPath);
  1855     TInt r=TheFs.ScanDrive(gSessionPath);
  1821     test(r==KErrNone);
  1856     test_KErrNone(r);
  1822     TBool res=IsSameAsDrive(origFat,origDir);
  1857     TBool res=IsSameAsDrive(origFat,origDir);
  1823     test(res);
  1858     test(res);
  1824 
  1859 
  1825     // write semi-random changes to first fat
  1860     // write semi-random changes to first fat
  1826     test.Next(_L("Test semi-random changes to first fat"));
  1861     test.Next(_L("Test semi-random changes to first fat"));
  1827     for(TInt j=1;j<gFatTestSize/BootSector.BytesPerSector();++j)
  1862     for(TInt j=1;j<gFatTestSize/BootSector.BytesPerSector();++j)
  1828         {
  1863         {
  1829         TInt off = j*BootSector.BytesPerSector()+j*7%512;
  1864         TInt off = j*BootSector.BytesPerSector()+j*7%512;
  1830         fat[off]=1;
  1865         fat[off]=1;
  1831         }
  1866         }
  1832     WriteFatDisk(fat);
  1867     WriteFatToDisk(fat);
  1833     r=TheFs.ScanDrive(gSessionPath);
  1868     r=TheFs.ScanDrive(gSessionPath);
  1834     test(r==KErrNone);
  1869     test_KErrNone(r);
  1835     res=IsSameAsDrive(origFat,origDir);
  1870     res=IsSameAsDrive(origFat,origDir);
  1836     test(res);
  1871     test(res);
  1837 
  1872 
  1838     // write semi-random changes to second fat
  1873     // write semi-random changes to second fat
  1839     test.Next(_L("Test semi-random changes to second fat"));
  1874     test.Next(_L("Test semi-random changes to second fat"));
  1840     WriteFatDisk(fat, 1);
  1875     WriteFatToDisk(fat, 1);
  1841     r=TheFs.ScanDrive(gSessionPath);
  1876     r=TheFs.ScanDrive(gSessionPath);
  1842     test(r==KErrNone);
  1877     test_KErrNone(r);
  1843     res=IsSameAsDrive(origFat,origDir);
  1878     res=IsSameAsDrive(origFat,origDir);
  1844     test(res);
  1879     test(res);
  1845 
  1880 
  1846     delete newFat;
  1881     delete newFat;
  1847     test.End();
  1882     test.End();
  1848     }
  1883     }
       
  1884 
       
  1885 
       
  1886 static void DoHangingAndLostClusters()
       
  1887 /*
       
  1888  * Tests that ScanDrive fixes MULTIPLE hanging clusters and removes lost clusters.
       
  1889  * It creates multiple hanging and lost cluster chains in the FAT table and
       
  1890  * expects ScanDrive to fix them all.
       
  1891  */
       
  1892 	{
       
  1893 	test.Start(_L("Check multiple hanging and lost cluster chains"));
       
  1894 	HBufC8* newFat = HBufC8::New(gFatTestSize);
       
  1895 	test_NotNull(newFat);
       
  1896 	TPtr8 fat = newFat->Des();
       
  1897 	TPtr8 origFat = FatBufPtr->Des();
       
  1898 	TPtr8 origDir = DirBufPtr->Des();
       
  1899 	ReadFatDisk(origFat);
       
  1900 	ReadDirDisk(origDir);
       
  1901 
       
  1902 	test.Printf(_L("Create multiple hanging cluster chains\n"));
       
  1903 	ReadFatDisk(fat);
       
  1904 	// Set hanging cluster for the file in \scndrv\dir1
       
  1905 	// gClusterDir1ext+1->25->26->27->28->29->30->31->32->33->34->35
       
  1906 	WriteToFatBuf(gClusterDir1ext+1, 25, fat.Ptr());
       
  1907 	CreateContiguousClusterChain(25, 35, fat.Ptr(), EFalse);
       
  1908 	// Set hanging cluster for the first file in \scndrv\dir2
       
  1909 	// gClusterDir2_AFull+1->249->250->53->54->55->EOC
       
  1910 	WriteToFatBuf(gClusterDir2_AFull+1, 249, fat.Ptr());
       
  1911 	WriteToFatBuf(249, 250, fat.Ptr());
       
  1912 	WriteToFatBuf(250, 53, fat.Ptr());
       
  1913 	CreateContiguousClusterChain(53, 55, fat.Ptr(), ETrue);
       
  1914 	// Set hanging cluster for the fourth file in \scndrv\dir2
       
  1915 	// gClusterDir2_AFull+4->59->60->61->62->63
       
  1916 	WriteToFatBuf(gClusterDir2_AFull+4, 59, fat.Ptr());
       
  1917 	CreateContiguousClusterChain(59, 63, fat.Ptr(), EFalse);
       
  1918 	// Set hanging cluster for the second file in \scndrv\dir2
       
  1919 	// gClusterDir2_AFull+2->67->68->69->EOC
       
  1920 	WriteToFatBuf(gClusterDir2_AFull+2, 67, fat.Ptr());
       
  1921 	CreateContiguousClusterChain(67, 69, fat.Ptr(), ETrue);
       
  1922 
       
  1923 	test.Printf(_L("Create multiple lost clusters\n"));
       
  1924 	// Create 1st lost cluster chain (clusters 36-45)
       
  1925 	CreateContiguousClusterChain(36, 45, fat.Ptr(), ETrue);
       
  1926 	// Create 2nd lost cluster chain (clusters 246-248,56-58)
       
  1927 	CreateContiguousClusterChain(246, 248, fat.Ptr(), EFalse);
       
  1928 	WriteToFatBuf(248, 56, fat.Ptr());
       
  1929 	CreateContiguousClusterChain(56, 58, fat.Ptr(), ETrue);
       
  1930 	// Create 3rd lost cluster chain (clusters 251-253,564-566, with hanging end)
       
  1931 	CreateContiguousClusterChain(251, 253, fat.Ptr(), EFalse);
       
  1932 	WriteToFatBuf(253, 564, fat.Ptr());
       
  1933 	CreateContiguousClusterChain(564, 566, fat.Ptr(), EFalse);
       
  1934 	
       
  1935 	// Flush all FAT changes to the media
       
  1936 	WriteFatToDisk(fat);
       
  1937 
       
  1938 	test.Next(_L("Test ScanDrive fixes multiple hanging and lost cluster chains"));
       
  1939 	TInt r = TheFs.CheckDisk(gSessionPath);	// CheckDisk should detect an error
       
  1940 	test_Value(r, r != KErrNone);
       
  1941 	r = TheFs.ScanDrive(gSessionPath);		// ScanDrive should find the errors and fix them
       
  1942 	test_KErrNone(r);
       
  1943 	r = TheFs.CheckDisk(gSessionPath);
       
  1944 	test_KErrNone(r);
       
  1945 	TBool res = IsSameAsDrive(origFat, origDir);
       
  1946 	test(res);
       
  1947 
       
  1948 	delete newFat;
       
  1949 	test.End();
       
  1950 	}
       
  1951 
  1849 
  1952 
  1850 LOCAL_C void DoPartEntries()
  1953 LOCAL_C void DoPartEntries()
  1851 //
  1954 //
  1852 // Tests that scandrive detects/corrects partial entries
  1955 // Tests that scandrive detects/corrects partial entries
  1853 //
  1956 //
  1858     test.Start(_L("Check partial entries"));
  1961     test.Start(_L("Check partial entries"));
  1859     TPtr8 fatBuf=FatBufPtr->Des();
  1962     TPtr8 fatBuf=FatBufPtr->Des();
  1860     TPtr8 dirBuf=DirBufPtr->Des();
  1963     TPtr8 dirBuf=DirBufPtr->Des();
  1861 
  1964 
  1862     TInt r=TheFs.RmDir(_L("\\scndrv\\dir2\\somedirwith3entries\\"));
  1965     TInt r=TheFs.RmDir(_L("\\scndrv\\dir2\\somedirwith3entries\\"));
  1863     test(r==KErrNone || r==KErrNotFound || KErrPathNotFound);
  1966     test_Value(r, r==KErrNone || r==KErrNotFound || r==KErrPathNotFound);
  1864     r=TheFs.RmDir(_L("\\scndrv\\dir2\\somedir2with3entries\\"));
  1967     r=TheFs.RmDir(_L("\\scndrv\\dir2\\somedir2with3entries\\"));
  1865     test(r==KErrNone || r==KErrNotFound || KErrPathNotFound);
  1968     test_Value(r, r==KErrNone || r==KErrNotFound || r==KErrPathNotFound);
  1866 
  1969 
  1867     if (BootSector.RootDirEntries() != 0)
  1970     if (BootSector.RootDirEntries() != 0)
  1868         {
  1971         {
  1869         // Can only do this on FAT12/16, FAT32 root directory is extensible
  1972         // Can only do this on FAT12/16, FAT32 root directory is extensible
  1870         // partial entry that fills up the root dir
  1973         // partial entry that fills up the root dir
  1871         test.Next(_L("Partial entry at end of rootdir"));
  1974         test.Next(_L("Partial entry at end of rootdir"));
  1872         FillUpRootDir(2);
  1975         FillUpRootDir(2);
  1873         r=temp.Create(TheFs,_L("\\temp"),EFileShareAny);
  1976         r=temp.Create(TheFs,_L("\\temp"),EFileShareAny);
  1874         test(r==KErrNone);
  1977         test_KErrNone(r);
  1875         temp.Close();
  1978         temp.Close();
  1876         ReadDirDisk(dirBuf);
  1979         ReadDirDisk(dirBuf);
  1877         ReadFatDisk(fatBuf);
  1980         ReadFatDisk(fatBuf);
  1878         TEntryInfo partial1(ClusterEntryToBytes(gClusterRootDir,BootSector.RootDirEntries()-2),2);
  1981         TEntryInfo partial1(ClusterEntryToBytes(gClusterRootDir,BootSector.RootDirEntries()-2),2);
  1879         CreatePartialEntry(partial1,1,EFalse);
  1982         CreatePartialEntry(partial1,1,EFalse);
  1889     last = GetStartCluster(gClusterDir2_AFull,7);
  1992     last = GetStartCluster(gClusterDir2_AFull,7);
  1890     TEntryInfo partial2(ClusterEntryToBytes(gClusterDir2_AFull,2),6);
  1993     TEntryInfo partial2(ClusterEntryToBytes(gClusterDir2_AFull,2),6);
  1891     CreatePartialEntry(partial2,3,EFalse);
  1994     CreatePartialEntry(partial2,3,EFalse);
  1892     // entry has been allocated a cluster which scandrive should delete along with partial entry
  1995     // entry has been allocated a cluster which scandrive should delete along with partial entry
  1893     if (last > 0)
  1996     if (last > 0)
  1894         WriteFat(last,0,fatBuf.Ptr());
  1997         WriteToFatBuf(last,0,fatBuf.Ptr());
  1895     res=TestPartialEntry(partial2);
  1998     res=TestPartialEntry(partial2);
  1896     test(res);
  1999     test(res);
  1897 
  2000 
  1898     // reduce size of \scndrv\dir2\full\ 
  2001     // reduce size of \scndrv\dir2\full\ 
  1899     test.Next(_L("Test directory reclaim"));
  2002     test.Next(_L("Test directory reclaim"));
  1900     last = GetStartCluster(gClusterDir2_Full,gEntriesPerCluster-2);
  2003     last = GetStartCluster(gClusterDir2_Full,gEntriesPerCluster-2);
  1901     WriteEndOfDir(ClusterEntryToBytes(gClusterDir2_Full,gEntriesPerCluster-2));
  2004     WriteEndOfDir(ClusterEntryToBytes(gClusterDir2_Full,gEntriesPerCluster-2));
  1902     WriteDirDisk(dirBuf);
  2005     WriteDirEntryToDisk(dirBuf);
  1903     TInt entry = GetFatEntry(gClusterDir2_Full, fatBuf.Ptr());
  2006     TInt entry = GetFatEntry(gClusterDir2_Full, fatBuf.Ptr());
  1904     WriteFat(gClusterDir2_Full,gEndOfChain,fatBuf.Ptr());
  2007     WriteToFatBuf(gClusterDir2_Full,gEndOfChain,fatBuf.Ptr());
  1905     while (entry && (entry & gEndOfChain) != gEndOfChain)
  2008     while (entry && (entry & gEndOfChain) != gEndOfChain)
  1906         {
  2009         {
  1907         TInt next = GetFatEntry(entry, fatBuf.Ptr());
  2010         TInt next = GetFatEntry(entry, fatBuf.Ptr());
  1908         WriteFat(entry,0,fatBuf.Ptr());
  2011         WriteToFatBuf(entry,0,fatBuf.Ptr());
  1909         entry = next;
  2012         entry = next;
  1910         }
  2013         }
  1911     if (last > 0)
  2014     if (last > 0)
  1912         WriteFat(last,0,fatBuf.Ptr());
  2015         WriteToFatBuf(last,0,fatBuf.Ptr());
  1913     r=TheFs.ScanDrive(gSessionPath);
  2016     r=TheFs.ScanDrive(gSessionPath);
  1914     test(r==KErrNone);
  2017     test_KErrNone(r);
  1915     res=IsSameAsDrive(fatBuf,dirBuf);
  2018     res=IsSameAsDrive(fatBuf,dirBuf);
  1916     test(res);
  2019     test(res);
  1917 
  2020 
  1918     // use last entry of first cluster in \scndrv\dir2\full\ 
  2021     // use last entry of first cluster in \scndrv\dir2\full\ 
  1919     test.Next(_L("Partial entry at end of subdir"));
  2022     test.Next(_L("Partial entry at end of subdir"));
  1920     r=temp.Create(TheFs,_L("\\scndrv\\dir2\\full\\temp"),EFileShareAny);
  2023     r=temp.Create(TheFs,_L("\\scndrv\\dir2\\full\\temp"),EFileShareAny);
  1921     test(r==KErrNone);
  2024     test_KErrNone(r);
  1922     temp.Close();
  2025     temp.Close();
  1923     ReadDirDisk(dirBuf);
  2026     ReadDirDisk(dirBuf);
  1924     ReadFatDisk(fatBuf);
  2027     ReadFatDisk(fatBuf);
  1925     TEntryInfo partial3(ClusterEntryToBytes(gClusterDir2_Full,gEntriesPerCluster-2),2);
  2028     TEntryInfo partial3(ClusterEntryToBytes(gClusterDir2_Full,gEntriesPerCluster-2),2);
  1926     CreatePartialEntry(partial3,1,EFalse);
  2029     CreatePartialEntry(partial3,1,EFalse);
  1929 
  2032 
  1930     // use entry in \scndrv\dir2\almostfull\ 
  2033     // use entry in \scndrv\dir2\almostfull\ 
  1931     test.Next(_L("Partial entry preceeding end-of-dir marker"));
  2034     test.Next(_L("Partial entry preceeding end-of-dir marker"));
  1932     last = GetStartCluster(gClusterDir2_AFull,14);
  2035     last = GetStartCluster(gClusterDir2_AFull,14);
  1933     if (last > 0)
  2036     if (last > 0)
  1934         WriteFat(last,0,fatBuf.Ptr());
  2037         WriteToFatBuf(last,0,fatBuf.Ptr());
  1935     last = GetStartCluster(gClusterDir2_AFull,8);
  2038     last = GetStartCluster(gClusterDir2_AFull,8);
  1936     if (last > 0)
  2039     if (last > 0)
  1937         WriteFat(last,0,fatBuf.Ptr());
  2040         WriteToFatBuf(last,0,fatBuf.Ptr());
  1938     WriteEndOfDir(ClusterEntryToBytes(gClusterDir2_AFull,14));
  2041     WriteEndOfDir(ClusterEntryToBytes(gClusterDir2_AFull,14));
  1939     WriteDirDisk(dirBuf);
  2042     WriteDirEntryToDisk(dirBuf);
  1940     TEntryInfo partial4(ClusterEntryToBytes(gClusterDir2_AFull,8),6);
  2043     TEntryInfo partial4(ClusterEntryToBytes(gClusterDir2_AFull,8),6);
  1941     CreatePartialEntry(partial4,4,EFalse);
  2044     CreatePartialEntry(partial4,4,EFalse);
  1942     res=TestPartialEntry(partial4);
  2045     res=TestPartialEntry(partial4);
  1943     test(res);
  2046     test(res);
  1944 
  2047 
  1950 	//	DBCS charater.
  2053 	//	DBCS charater.
  1951 
  2054 
  1952 	// create entry in \scndrv\dir2\almostfull\ 
  2055 	// create entry in \scndrv\dir2\almostfull\ 
  1953 //	test.Next(_L("Partial entry with invalid dos name"));
  2056 //	test.Next(_L("Partial entry with invalid dos name"));
  1954 //	r=temp.Create(TheFs,_L("\\scndrv\\dir2\\almostfull\\Dodgy file name"),EFileShareAny);
  2057 //	r=temp.Create(TheFs,_L("\\scndrv\\dir2\\almostfull\\Dodgy file name"),EFileShareAny);
  1955 //	test(r==KErrNone);
  2058 //	test_KErrNone(r);
  1956 //	temp.Close();
  2059 //	temp.Close();
  1957 //	ReadDirDisk(dirBuf);
  2060 //	ReadDirDisk(dirBuf);
  1958 //	TInt dosStart=ClusterEntryToBytes(gClusterDir2_AFull,4);
  2061 //	TInt dosStart=ClusterEntryToBytes(gClusterDir2_AFull,4);
  1959 //	dirBuf[dosStart+4]=0x1;
  2062 //	dirBuf[dosStart+4]=0x1;
  1960 //	WriteDirDisk(dirBuf);
  2063 //	WriteDirDisk(dirBuf);
  1961 //	r=TheFs.ScanDrive(gSessionPath);
  2064 //	r=TheFs.ScanDrive(gSessionPath);
  1962 //	test(r==KErrNone);
  2065 //	test_KErrNone(r);
  1963 //	WriteDelete(dosStart-2*32,3);
  2066 //	WriteDelete(dosStart-2*32,3);
  1964 //	res=IsSameAsDrive(fatBuf,dirBuf);
  2067 //	res=IsSameAsDrive(fatBuf,dirBuf);
  1965 //	test(res);
  2068 //	test(res);
  1966 
  2069 
  1967     if (BootSector.SectorsPerCluster() == 1)
  2070     if (BootSector.SectorsPerCluster() == 1)
  1969         // use entry created in \scndrv\dir2\ 
  2072         // use entry created in \scndrv\dir2\ 
  1970         test.Next(_L("Partial entry spanning more than two clusters"));
  2073         test.Next(_L("Partial entry spanning more than two clusters"));
  1971         last = GetStartCluster(gClusterDir2_Full,gEntriesPerCluster-1);
  2074         last = GetStartCluster(gClusterDir2_Full,gEntriesPerCluster-1);
  1972         WriteEndOfDir(ClusterEntryToBytes(gClusterDir2_Full,gEntriesPerCluster-2));
  2075         WriteEndOfDir(ClusterEntryToBytes(gClusterDir2_Full,gEntriesPerCluster-2));
  1973         WriteEndOfDir(ClusterEntryToBytes(gClusterDir2_Full,gEntriesPerCluster-1));
  2076         WriteEndOfDir(ClusterEntryToBytes(gClusterDir2_Full,gEntriesPerCluster-1));
  1974         WriteDirDisk(dirBuf);
  2077         WriteDirEntryToDisk(dirBuf);
  1975         TFileName longFile=_L("\\scndrv\\dir2\\full\\");
  2078         TFileName longFile=_L("\\scndrv\\dir2\\full\\");
  1976         MakeVeryLongName(longFile);
  2079         MakeVeryLongName(longFile);
  1977         r=temp.Create(TheFs,longFile,EFileShareAny);
  2080         r=temp.Create(TheFs,longFile,EFileShareAny);
  1978         test(r==KErrNone);
  2081         test_KErrNone(r);
  1979         temp.Close();
  2082         temp.Close();
  1980         ReadDirDisk(dirBuf);
  2083         ReadDirDisk(dirBuf);
  1981         WriteFat(gClusterDir2_Full,gClusterDir2_SD3E,fatBuf.Ptr());
  2084         WriteToFatBuf(gClusterDir2_Full,gClusterDir2_SD3E,fatBuf.Ptr());
  1982         WriteFat(gClusterDir2_SD3E,gClusterDir2_SD23E,fatBuf.Ptr());
  2085         WriteToFatBuf(gClusterDir2_SD3E,gClusterDir2_SD23E,fatBuf.Ptr());
  1983         WriteFat(gClusterDir2_SD23E,gEndOfChain,fatBuf.Ptr());
  2086         WriteToFatBuf(gClusterDir2_SD23E,gEndOfChain,fatBuf.Ptr());
  1984         if (last > 0)
  2087         if (last > 0)
  1985             WriteFat(last,0,fatBuf.Ptr());
  2088             WriteToFatBuf(last,0,fatBuf.Ptr());
  1986         TEntryInfo partial5(ClusterEntryToBytes(gClusterDir2_Full,gEntriesPerCluster-2),19);
  2089         TEntryInfo partial5(ClusterEntryToBytes(gClusterDir2_Full,gEntriesPerCluster-2),19);
  1987         CreatePartialEntry(partial5,7,EFalse);
  2090         CreatePartialEntry(partial5,7,EFalse);
  1988         res=TestPartialEntry(partial5);
  2091         res=TestPartialEntry(partial5);
  1989         test(res);
  2092         test(res);
  1990         r=TheFs.Delete(longFile);
  2093         r=TheFs.Delete(longFile);
  1991         test(r==KErrNone || r==KErrNotFound);
  2094         test_Value(r, r==KErrNone || r==KErrNotFound);
  1992         r=TheFs.Delete(_L("\\temp"));
  2095         r=TheFs.Delete(_L("\\temp"));
  1993         test(r==KErrNone || r==KErrNotFound);
  2096         test_Value(r, r==KErrNone || r==KErrNotFound);
  1994         }
  2097         }
  1995     ReadDirDisk(dirBuf);
  2098     ReadDirDisk(dirBuf);
  1996 
  2099 
  1997     test.End();
  2100     test.End();
  1998     }
  2101     }
  2038     // matching entries in same subdir, one in new cluster - irrelevant if matching names
  2141     // matching entries in same subdir, one in new cluster - irrelevant if matching names
  2039     // 1st and last entries in \scndrv\dir2\full\ 
  2142     // 1st and last entries in \scndrv\dir2\full\ 
  2040     test.Next(_L("matching entries in same subdir"));
  2143     test.Next(_L("matching entries in same subdir"));
  2041     // delete entries to allow contiguous clusters in \scndrv\dir2\full directory
  2144     // delete entries to allow contiguous clusters in \scndrv\dir2\full directory
  2042     TInt r=TheFs.RmDir(_L("\\scndrv\\dir2\\somedirwith3entries\\"));
  2145     TInt r=TheFs.RmDir(_L("\\scndrv\\dir2\\somedirwith3entries\\"));
  2043     test(r==KErrNone);
  2146     test_KErrNone(r);
  2044     r=TheFs.RmDir(_L("\\scndrv\\dir2\\somedir2with3entries\\"));
  2147     r=TheFs.RmDir(_L("\\scndrv\\dir2\\somedir2with3entries\\"));
  2045     test(r==KErrNone);
  2148     test_KErrNone(r);
  2046     // ensure directory is expanded
  2149     // ensure directory is expanded
  2047     RFile temp;
  2150     RFile temp;
  2048     r=temp.Create(TheFs,_L("\\scndrv\\dir2\\full\\temp"),EFileShareAny);
  2151     r=temp.Create(TheFs,_L("\\scndrv\\dir2\\full\\temp"),EFileShareAny);
  2049     test(r==KErrNone);
  2152     test_KErrNone(r);
  2050     temp.Close();
  2153     temp.Close();
  2051     r=TheFs.Delete(_L("\\scndrv\\dir2\\full\\temp"));
  2154     r=TheFs.Delete(_L("\\scndrv\\dir2\\full\\temp"));
  2052     test(r==KErrNone);
  2155     test_KErrNone(r);
  2053     ReadDirDisk(dirBuf);
  2156     ReadDirDisk(dirBuf);
  2054     ReadFatDisk(fatBuf);
  2157     ReadFatDisk(fatBuf);
  2055     TEntryInfo from4(ClusterEntryToBytes(gClusterDir2_Full,4),2);
  2158     TEntryInfo from4(ClusterEntryToBytes(gClusterDir2_Full,4),2);
  2056     TEntryInfo to4(ClusterEntryToBytes(gClusterDir2_Full+1,0),2);
  2159     TEntryInfo to4(ClusterEntryToBytes(gClusterDir2_Full+1,0),2);
  2057     CreateMatchingEntry(to4,from4,ETrue);
  2160     CreateMatchingEntry(to4,from4,ETrue);
  2060 
  2163 
  2061     // \scndrv\dir1\very long name to \\scndrv\dir2\full\ 
  2164     // \scndrv\dir1\very long name to \\scndrv\dir2\full\ 
  2062     test.Next(_L("matching entries in diff dirs + new cluster"));
  2165     test.Next(_L("matching entries in diff dirs + new cluster"));
  2063     // delete last entry in directory
  2166     // delete last entry in directory
  2064     r=TheFs.Delete(LastInFull);
  2167     r=TheFs.Delete(LastInFull);
  2065     test(r==KErrNone);
  2168     test_KErrNone(r);
  2066     TFileName veryLongName=_L("\\scndrv\\dir2\\full\\");
  2169     TFileName veryLongName=_L("\\scndrv\\dir2\\full\\");
  2067     MakeVeryLongName(veryLongName);
  2170     MakeVeryLongName(veryLongName);
  2068     r=temp.Create(TheFs,veryLongName,EFileShareAny);
  2171     r=temp.Create(TheFs,veryLongName,EFileShareAny);
  2069     test(r==KErrNone);
  2172     test_KErrNone(r);
  2070     temp.Close();
  2173     temp.Close();
  2071     r=TheFs.Delete(veryLongName);
  2174     r=TheFs.Delete(veryLongName);
  2072     test(r==KErrNone);
  2175     test_KErrNone(r);
  2073     ReadDirDisk(dirBuf);
  2176     ReadDirDisk(dirBuf);
  2074     ReadFatDisk(fatBuf);
  2177     ReadFatDisk(fatBuf);
  2075     TEntryInfo from5(ClusterEntryToBytes(gClusterDir1,2),19);
  2178     TEntryInfo from5(ClusterEntryToBytes(gClusterDir1,2),19);
  2076     TEntryInfo to5(ClusterEntryToBytes(gClusterDir2_Full,gEntriesPerCluster-2),19);
  2179     TEntryInfo to5(ClusterEntryToBytes(gClusterDir2_Full,gEntriesPerCluster-2),19);
  2077     CreateMatchingEntry(to5,from5,EFalse);
  2180     CreateMatchingEntry(to5,from5,EFalse);
  2097     CreateMaxDepthDir(dir1,dir2);
  2200     CreateMaxDepthDir(dir1,dir2);
  2098     ReadDirDisk(dirBuf);
  2201     ReadDirDisk(dirBuf);
  2099     ReadFatDisk(fatBuf);
  2202     ReadFatDisk(fatBuf);
  2100     // run scandisk and compare
  2203     // run scandisk and compare
  2101     TInt r=TheFs.ScanDrive(gSessionPath);
  2204     TInt r=TheFs.ScanDrive(gSessionPath);
  2102     test(r==KErrNone);
  2205     test_KErrNone(r);
  2103     TBool res=IsSameAsDrive(fatBuf,dirBuf);
  2206     TBool res=IsSameAsDrive(fatBuf,dirBuf);
  2104     test(res);
  2207     test(res);
  2105     // Create a entry with matching start cluster and check fixed up
  2208     // Create a entry with matching start cluster and check fixed up
  2106     TEntryInfo from(ClusterEntryToBytes(gClusterDir2_AFull,2),6);
  2209     TEntryInfo from(ClusterEntryToBytes(gClusterDir2_AFull,2),6);
  2107     TEntryInfo to(ClusterEntryToBytes(gClusterEndMaxDepth,2),6);
  2210     TEntryInfo to(ClusterEntryToBytes(gClusterEndMaxDepth,2),6);
  2124     TPtr8 dirBuf=DirBufPtr->Des();
  2227     TPtr8 dirBuf=DirBufPtr->Des();
  2125     ReadDirDisk(dirBuf);
  2228     ReadDirDisk(dirBuf);
  2126     ReadFatDisk(fatBuf);
  2229     ReadFatDisk(fatBuf);
  2127 
  2230 
  2128     TInt r=TheFs.ScanDrive(gSessionPath);
  2231     TInt r=TheFs.ScanDrive(gSessionPath);
  2129     test(r==KErrNone);
  2232     test_KErrNone(r);
  2130 
  2233 
  2131     TBool res=IsSameAsDrive(fatBuf,dirBuf);
  2234     TBool res=IsSameAsDrive(fatBuf,dirBuf);
  2132     test(res);
  2235     test(res);
  2133     UnFillUpRootDir();
  2236     UnFillUpRootDir();
  2134     }
  2237     }
  2217             TFileName name(aDirName);
  2320             TFileName name(aDirName);
  2218             name.Append(_L("tempfile."));
  2321             name.Append(_L("tempfile."));
  2219             name.AppendNumFixedWidth(i+totalFilesCreated, EHex, 3);
  2322             name.AppendNumFixedWidth(i+totalFilesCreated, EHex, 3);
  2220             RFile f;
  2323             RFile f;
  2221             r = f.Create(TheFs, name, EFileShareAny);
  2324             r = f.Create(TheFs, name, EFileShareAny);
  2222             test(r == KErrNone);
  2325             test_KErrNone(r);
  2223             r = f.Write(buf);
  2326             r = f.Write(buf);
  2224             test(r == KErrNone);
  2327             test_KErrNone(r);
  2225             f.Close();
  2328             f.Close();
  2226             }
  2329             }
  2227 
  2330 
  2228         //
  2331         //
  2229         // Move DOS FAT entries up using RRawDisk, deleting the original VFAT entries
  2332         // Move DOS FAT entries up using RRawDisk, deleting the original VFAT entries
  2252                 entry += 2;
  2355                 entry += 2;
  2253                 }
  2356                 }
  2254 
  2357 
  2255             }
  2358             }
  2256 
  2359 
  2257         WriteDirDisk(dirBuf, cluster);
  2360         WriteDirEntryToDisk(dirBuf, cluster);
  2258         totalFilesCreated += filesThisTime;
  2361         totalFilesCreated += filesThisTime;
  2259         test.Printf(_L("   created %d entries\n"), totalFilesCreated);
  2362         test.Printf(_L("   created %d entries\n"), totalFilesCreated);
  2260         }
  2363         }
  2261 
  2364 
  2262     ReadDirDisk(dirBuf);
  2365     ReadDirDisk(dirBuf);
  2264 
  2367 
  2265     DumpData(NULL, aDirCluster, cluster+1);
  2368     DumpData(NULL, aDirCluster, cluster+1);
  2266 
  2369 
  2267     test.Printf(_L("Running ScanDrive\n"), filesThisTime);
  2370     test.Printf(_L("Running ScanDrive\n"), filesThisTime);
  2268     r=TheFs.ScanDrive(gSessionPath);
  2371     r=TheFs.ScanDrive(gSessionPath);
  2269     test(r==KErrNone);
  2372     test_KErrNone(r);
  2270 
  2373 
  2271     TBool res=IsSameAsDrive(fatBuf,dirBuf);
  2374     TBool res=IsSameAsDrive(fatBuf,dirBuf);
  2272     test(res);
  2375     test(res);
  2273 
  2376 
  2274     test.Printf(_L("Deleting %d files\n"), nFiles);
  2377     test.Printf(_L("Deleting %d files\n"), nFiles);
  2276         {
  2379         {
  2277         TFileName name(aDirName);
  2380         TFileName name(aDirName);
  2278         name.Append(_L("tempfile."));
  2381         name.Append(_L("tempfile."));
  2279         name.AppendNumFixedWidth(i, EHex, 3);
  2382         name.AppendNumFixedWidth(i, EHex, 3);
  2280         r = TheFs.Delete(name);
  2383         r = TheFs.Delete(name);
  2281         test(r == KErrNone);
  2384         test_KErrNone(r);
  2282         }
  2385         }
  2283 
  2386 
  2284     ReadDirDisk(dirBuf);
  2387     ReadDirDisk(dirBuf);
  2285     ReadFatDisk(fatBuf);
  2388     ReadFatDisk(fatBuf);
  2286     WriteEndOfDir(ClusterEntryToBytes(cluster, startEntry));
  2389     WriteEndOfDir(ClusterEntryToBytes(cluster, startEntry));
  2287     WriteDirDisk(dirBuf);
  2390     WriteDirEntryToDisk(dirBuf);
  2288 
  2391 
  2289     test.Printf(_L("Running ScanDrive\n"), filesThisTime);
  2392     test.Printf(_L("Running ScanDrive\n"), filesThisTime);
  2290     r=TheFs.ScanDrive(gSessionPath);
  2393     r=TheFs.ScanDrive(gSessionPath);
  2291     test(r==KErrNone);
  2394     test_KErrNone(r);
  2292     res=IsSameAsDrive(fatBuf,dirBuf);
  2395     res=IsSameAsDrive(fatBuf,dirBuf);
  2293     test(res);
  2396     test(res);
  2294     }
  2397     }
  2295 
  2398 
  2296 LOCAL_C void DoNonVfatNames()
  2399 LOCAL_C void DoNonVfatNames()
  2327     DoMaxDepth();
  2430     DoMaxDepth();
  2328     DoMatchingEntries();
  2431     DoMatchingEntries();
  2329     DoPartEntries();
  2432     DoPartEntries();
  2330     DoLostClusters();
  2433     DoLostClusters();
  2331     DoHangingClusters();
  2434     DoHangingClusters();
       
  2435     DoHangingAndLostClusters();
  2332     TestMountAndScan();
  2436     TestMountAndScan();
  2333     TestConsecutiveMountAndScans();
  2437     TestConsecutiveMountAndScans();
  2334     DeleteDirectoryStructure();
  2438     DeleteDirectoryStructure();
  2335     DeleteRootDir();
  2439     DeleteRootDir();
  2336     TestExtendedChars();
  2440     TestExtendedChars();
  2348 
  2452 
  2349 void CallTestsL()
  2453 void CallTestsL()
  2350     {
  2454     {
  2351     TInt r;
  2455     TInt r;
  2352     r = TheFs.CharToDrive(gSessionPath[0], gDriveNumber);
  2456     r = TheFs.CharToDrive(gSessionPath[0], gDriveNumber);
  2353     test( KErrNone == r );
  2457     test_KErrNone(r);
  2354 
  2458 
  2355 
  2459 
  2356     //-- set up console output
  2460     //-- set up console output
  2357     Fat_Test_Utils::SetConsole(test.Console());
  2461     Fat_Test_Utils::SetConsole(test.Console());
  2358 
  2462 
  2366         }
  2470         }
  2367 
  2471 
  2368     // check this is not the internal ram drive
  2472     // check this is not the internal ram drive
  2369     TVolumeInfo v;
  2473     TVolumeInfo v;
  2370     r=TheFs.Volume(v);
  2474     r=TheFs.Volume(v);
  2371     test(r==KErrNone);
  2475     test_KErrNone(r);
  2372     if(v.iDrive.iMediaAtt&KMediaAttVariableSize)
  2476     if(v.iDrive.iMediaAtt&KMediaAttVariableSize)
  2373         {
  2477         {
  2374         test.Printf(_L("Error: Internal ram drive not tested\n"));
  2478         test.Printf(_L("Error: Internal ram drive not tested\n"));
  2375         return;
  2479         return;
  2376         }
  2480         }
  2377 
  2481 
  2378     r=TheFs.SetSessionPath(gSessionPath);
  2482     r=TheFs.SetSessionPath(gSessionPath);
  2379     test(r==KErrNone);
  2483     test_KErrNone(r);
  2380 
  2484 
  2381     DoTests();
  2485     DoTests();
  2382 
  2486 
  2383     return;
  2487     return;
  2384     }
  2488     }