kerneltest/f32test/filesystem/fat/t_scn32dr1.cpp
branchRCL_3
changeset 43 c1f20ce4abcf
parent 42 a179b74831c9
child 44 3e88ff8f41d5
equal deleted inserted replaced
42:a179b74831c9 43:c1f20ce4abcf
     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();
   706     if (aEnd < 0)
   708     if (aEnd < 0)
   707         aEnd = aStart + 1;
   709         aEnd = aStart + 1;
   708     if (aStart < 2 && gDiskType != EFat32)
   710     if (aStart < 2 && gDiskType != EFat32)
   709         {
   711         {
   710         HBufC8* buf=HBufC8::New(BootSector.RootDirEntries() * KSizeOfFatDirEntry);
   712         HBufC8* buf=HBufC8::New(BootSector.RootDirEntries() * KSizeOfFatDirEntry);
   711         test(buf != NULL);
   713         test_NotNull(buf);
   712         TPtr8 ptr=buf->Des();
   714         TPtr8 ptr=buf->Des();
   713         TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
   715         TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
   714         test(r==KErrNone);
   716         test_KErrNone(r);
   715         r=TheRawDisk.Read(gRootDirStart, ptr);
   717         r=TheRawDisk.Read(gRootDirStart, ptr);
   716         test(r==KErrNone);
   718         test_KErrNone(r);
   717         TheRawDisk.Close();
   719         TheRawDisk.Close();
   718         DumpRootDir(buf->Ptr());
   720         DumpRootDir(buf->Ptr());
   719         delete(buf);
   721         delete(buf);
   720         aStart = 2;
   722         aStart = 2;
   721         }
   723         }
   722     for (TInt cluster = aStart; cluster < aEnd; cluster++)
   724     for (TInt cluster = aStart; cluster < aEnd; cluster++)
   723         {
   725         {
   724         if (GetFatEntry(cluster, aFat) != 0)
   726         if (GetFatEntry(cluster, aFat) != 0)
   725             {
   727             {
   726             HBufC8* buf=HBufC8::New(gBytesPerCluster);
   728             HBufC8* buf=HBufC8::New(gBytesPerCluster);
   727             test(buf!=NULL);
   729             test_NotNull(buf);
   728             TPtr8 ptr=buf->Des();
   730             TPtr8 ptr=buf->Des();
   729             TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
   731             TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
   730             test(r==KErrNone);
   732             test_KErrNone(r);
   731             r=TheRawDisk.Read(ClusterToByte(cluster), ptr);
   733             r=TheRawDisk.Read(ClusterToByte(cluster), ptr);
   732             test(r==KErrNone);
   734             test_KErrNone(r);
   733             TheRawDisk.Close();
   735             TheRawDisk.Close();
   734             RDebug::Print(_L("Cluster %d @ 0x%08X:"), cluster, ClusterToByte(cluster));
   736             RDebug::Print(_L("Cluster %d @ 0x%08X:"), cluster, ClusterToByte(cluster));
   735             DumpDirCluster(ptr.Ptr());
   737             DumpDirCluster(ptr.Ptr());
   736             delete buf;
   738             delete buf;
   737             }
   739             }
   796 // 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
   797 // directory cluster, return -1 if not available (invalid entry).
   799 // directory cluster, return -1 if not available (invalid entry).
   798 //
   800 //
   799     {
   801     {
   800     HBufC8* buf=HBufC8::New(gBytesPerCluster*2);
   802     HBufC8* buf=HBufC8::New(gBytesPerCluster*2);
   801     test(buf!=NULL);
   803     test_NotNull(buf);
   802     TPtr8 ptr=buf->Des();
   804     TPtr8 ptr=buf->Des();
   803     TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
   805     TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
   804     test(r==KErrNone);
   806     test_KErrNone(r);
   805     r=TheRawDisk.Read(ClusterToByte(aCluster), ptr);
   807     r=TheRawDisk.Read(ClusterToByte(aCluster), ptr);
   806     test(r==KErrNone);
   808     test_KErrNone(r);
   807     TheRawDisk.Close();
   809     TheRawDisk.Close();
   808     RDebug::Print(_L("Cluster %d @ 0x%08X:"), aCluster, ClusterToByte(aCluster));
   810     RDebug::Print(_L("Cluster %d @ 0x%08X:"), aCluster, ClusterToByte(aCluster));
   809     TFatDirEntry* d = (TFatDirEntry*)ptr.Ptr() + aEntry;
   811     TFatDirEntry* d = (TFatDirEntry*)ptr.Ptr() + aEntry;
   810     while (((TInt)d->Attributes() & KDirAttrLongMask) == KDirAttrLongName && aEntry < gEntriesPerCluster)
   812     while (((TInt)d->Attributes() & KDirAttrLongMask) == KDirAttrLongName && aEntry < gEntriesPerCluster)
   811         {
   813         {
   839     nRes = FormatFatDrive(TheFs, CurrentDrive(), ETrue, &fmt);
   841     nRes = FormatFatDrive(TheFs, CurrentDrive(), ETrue, &fmt);
   840 #else
   842 #else
   841     nRes = FormatFatDrive(TheFs, CurrentDrive(), ETrue);
   843     nRes = FormatFatDrive(TheFs, CurrentDrive(), ETrue);
   842 #endif
   844 #endif
   843 
   845 
   844     test(nRes == KErrNone);
   846     test_KErrNone(nRes);
   845 
   847 
   846     }
   848     }
   847 
   849 
   848 LOCAL_C void CreateDeepDir(TFileName& aDir,TInt aDepth)
   850 LOCAL_C void CreateDeepDir(TFileName& aDir,TInt aDepth)
   849 //
   851 //
   857     while(aDepth--)
   859     while(aDepth--)
   858         {
   860         {
   859         num[0] = TText(aDepth % 26 + 'A');
   861         num[0] = TText(aDepth % 26 + 'A');
   860         aDir+=num;
   862         aDir+=num;
   861         r=TheFs.MkDir(aDir);
   863         r=TheFs.MkDir(aDir);
   862         test(r==KErrNone);
   864         test_KErrNone(r);
   863         }
   865         }
   864     }
   866     }
   865 
   867 
   866 LOCAL_C void DeleteDeepDir(TFileName& aDir,TInt aDepth)
   868 LOCAL_C void DeleteDeepDir(TFileName& aDir,TInt aDepth)
   867 //
   869 //
   870     {
   872     {
   871     TInt r;
   873     TInt r;
   872     while(aDepth--)
   874     while(aDepth--)
   873         {
   875         {
   874         r=TheFs.RmDir(aDir);
   876         r=TheFs.RmDir(aDir);
   875         test(r==KErrNone);
   877         test_KErrNone(r);
   876         aDir.SetLength(aDir.Length()-2);
   878         aDir.SetLength(aDir.Length()-2);
   877         }
   879         }
   878     }
   880     }
   879 
   881 
   880 LOCAL_C void CreateMaxDepthDir(TFileName& aDir1,TFileName& aDir2)
   882 LOCAL_C void CreateMaxDepthDir(TFileName& aDir1,TFileName& aDir2)
   887     CreateDeepDir(aDir1,25);
   889     CreateDeepDir(aDir1,25);
   888     // split dir structure
   890     // split dir structure
   889     aDir2=aDir1;
   891     aDir2=aDir1;
   890     aDir2+=_L("a\\");
   892     aDir2+=_L("a\\");
   891     TInt r=TheFs.MkDir(aDir2);
   893     TInt r=TheFs.MkDir(aDir2);
   892     test(r==KErrNone);
   894     test_KErrNone(r);
   893     // 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
   894     CreateDeepDir(aDir1,101);
   896     CreateDeepDir(aDir1,101);
   895     // create dir with depth of 90
   897     // create dir with depth of 90
   896     CreateDeepDir(aDir2,64);
   898     CreateDeepDir(aDir2,64);
   897     }
   899     }
   901 // Deletes max depth dir structure.
   903 // Deletes max depth dir structure.
   902 //
   904 //
   903     {
   905     {
   904     DeleteDeepDir(aDir2,64);
   906     DeleteDeepDir(aDir2,64);
   905     TInt r=TheFs.RmDir(aDir2);
   907     TInt r=TheFs.RmDir(aDir2);
   906     test(r==KErrNone);
   908     test_KErrNone(r);
   907     aDir2.SetLength(aDir2.Length()-2);
   909     aDir2.SetLength(aDir2.Length()-2);
   908     DeleteDeepDir(aDir1,102);
   910     DeleteDeepDir(aDir1,102);
   909     DeleteDeepDir(aDir1,24);
   911     DeleteDeepDir(aDir1,24);
   910     }
   912     }
   911 
   913 
   935         {
   937         {
   936         aLong[len+0] = TText(count/26 + 'A');
   938         aLong[len+0] = TText(count/26 + 'A');
   937         aLong[len+1] = TText(count%26 + 'A');
   939         aLong[len+1] = TText(count%26 + 'A');
   938         count++;
   940         count++;
   939         TInt r=temp.Create(TheFs,aLong,EFileShareAny);
   941         TInt r=temp.Create(TheFs,aLong,EFileShareAny);
   940         test(r==KErrNone);
   942         test_KErrNone(r);
   941         temp.Close();
   943         temp.Close();
   942         }
   944         }
   943     }
   945     }
   944 
   946 
   945 GLDEF_C void DeleteLongNames(TFileName& aLong, TInt aClusters)
   947 GLDEF_C void DeleteLongNames(TFileName& aLong, TInt aClusters)
   954         {
   956         {
   955         aLong[len+0] = TText(count/26 + 'A');
   957         aLong[len+0] = TText(count/26 + 'A');
   956         aLong[len+1] = TText(count%26 + 'A');
   958         aLong[len+1] = TText(count%26 + 'A');
   957         count++;
   959         count++;
   958         TInt r=TheFs.Delete(aLong);
   960         TInt r=TheFs.Delete(aLong);
   959         test(r==KErrNone || r==KErrNotFound);
   961         test_Value(r, r==KErrNone || r==KErrNotFound);
   960         }
   962         }
   961     }
   963     }
   962 
   964 
   963 LOCAL_C void DeleteRootDir(TInt aNum=0)
   965 LOCAL_C void DeleteRootDir(TInt aNum=0)
   964 //
   966 //
   976         {
   978         {
   977         name[1]=(TUint16)(count/26/26+'a');
   979         name[1]=(TUint16)(count/26/26+'a');
   978         name[2]=(TUint16)(count/26%26+'a');
   980         name[2]=(TUint16)(count/26%26+'a');
   979         name[3]=(TUint16)(count%26+'a');
   981         name[3]=(TUint16)(count%26+'a');
   980         r=TheFs.Delete(name);
   982         r=TheFs.Delete(name);
   981         test(r==KErrNone || r==KErrNotFound);
   983         test_Value(r, r==KErrNone || r==KErrNotFound);
   982         ++count;
   984         ++count;
   983         }
   985         }
   984     }
   986     }
   985 
   987 
   986 LOCAL_C void CreateRootDir()
   988 LOCAL_C void CreateRootDir()
  1000         {
  1002         {
  1001         name[1]=(TUint16)(count/26/26+'a');
  1003         name[1]=(TUint16)(count/26/26+'a');
  1002         name[2]=(TUint16)(count/26%26+'a');
  1004         name[2]=(TUint16)(count/26%26+'a');
  1003         name[3]=(TUint16)(count%26+'a');
  1005         name[3]=(TUint16)(count%26+'a');
  1004         r=f.Create(TheFs, name, EFileWrite);
  1006         r=f.Create(TheFs, name, EFileWrite);
  1005         test(r==KErrNone);
  1007         test_KErrNone(r);
  1006         f.Close();
  1008         f.Close();
  1007         ++count;
  1009         ++count;
  1008         }
  1010         }
  1009     DeleteRootDir(1);
  1011     DeleteRootDir(1);
  1010     }
  1012     }
  1022     while(entriesSoFar<maxRootEntries)
  1024     while(entriesSoFar<maxRootEntries)
  1023         {
  1025         {
  1024         dir[1]=(TUint16)(count/26+'a');
  1026         dir[1]=(TUint16)(count/26+'a');
  1025         dir[2]=(TUint16)(count%26+'a');
  1027         dir[2]=(TUint16)(count%26+'a');
  1026         r=TheFs.MkDir(dir);
  1028         r=TheFs.MkDir(dir);
  1027         test(r==KErrNone);
  1029         test_KErrNone(r);
  1028         entriesSoFar+=2;
  1030         entriesSoFar+=2;
  1029         ++count;
  1031         ++count;
  1030         }
  1032         }
  1031     }
  1033     }
  1032 
  1034 
  1042     while(entriesSoFar>2)
  1044     while(entriesSoFar>2)
  1043         {
  1045         {
  1044         dir[1]=TUint16(count/26+'a');
  1046         dir[1]=TUint16(count/26+'a');
  1045         dir[2]=TUint16(count%26+'a');
  1047         dir[2]=TUint16(count%26+'a');
  1046         r=TheFs.RmDir(dir);
  1048         r=TheFs.RmDir(dir);
  1047         test(r==KErrNone);
  1049         test_KErrNone(r);
  1048         entriesSoFar-=2;
  1050         entriesSoFar-=2;
  1049         ++count;
  1051         ++count;
  1050         }
  1052         }
  1051     }
  1053     }
  1052 
  1054 
  1055 // deletes the directory structure
  1057 // deletes the directory structure
  1056 //
  1058 //
  1057     {
  1059     {
  1058     test.Next(_L("Delete Directory Structure"));
  1060     test.Next(_L("Delete Directory Structure"));
  1059     TInt r=TheFs.RmDir(_L("\\scndrv\\dir2\\almostfull\\"));
  1061     TInt r=TheFs.RmDir(_L("\\scndrv\\dir2\\almostfull\\"));
  1060     test(r==KErrNone);
  1062     test_KErrNone(r);
  1061     TInt entriesNeeded=(gEntriesPerCluster-2) / 2;  //7*2entries + . + .. = full sector
  1063     TInt entriesNeeded=(gEntriesPerCluster-2) / 2;  //7*2entries + . + .. = full sector
  1062     for (TInt i = 0; i < entriesNeeded; i++)
  1064     for (TInt i = 0; i < entriesNeeded; i++)
  1063         {
  1065         {
  1064         TFileName file=_L("\\scndrv\\dir2\\full\\__a");
  1066         TFileName file=_L("\\scndrv\\dir2\\full\\__a");
  1065         file.AppendNum(i);
  1067         file.AppendNum(i);
  1066         r=TheFs.Delete(file);
  1068         r=TheFs.Delete(file);
  1067         test(r==KErrNone||r==KErrNotFound);
  1069         test_Value(r, r==KErrNone||r==KErrNotFound);
  1068         }
  1070         }
  1069     r=TheFs.RmDir(_L("\\scndrv\\dir2\\full\\"));
  1071     r=TheFs.RmDir(_L("\\scndrv\\dir2\\full\\"));
  1070     test(r==KErrNone);
  1072     test_KErrNone(r);
  1071     r=TheFs.RmDir(_L("\\scndrv\\dir2\\"));
  1073     r=TheFs.RmDir(_L("\\scndrv\\dir2\\"));
  1072     test(r==KErrNone);
  1074     test_KErrNone(r);
  1073     TFileName veryLongName=(_L("\\scndrv\\dir1\\"));
  1075     TFileName veryLongName=(_L("\\scndrv\\dir1\\"));
  1074     MakeVeryLongName(veryLongName);
  1076     MakeVeryLongName(veryLongName);
  1075     r=TheFs.Delete(veryLongName);
  1077     r=TheFs.Delete(veryLongName);
  1076     test(r==KErrNone);
  1078     test_KErrNone(r);
  1077     r=TheFs.RmDir(_L("\\scndrv\\dir1\\"));
  1079     r=TheFs.RmDir(_L("\\scndrv\\dir1\\"));
  1078     test(r==KErrNone);
  1080     test_KErrNone(r);
  1079     r=TheFs.RmDir(_L("\\scndrv\\"));
  1081     r=TheFs.RmDir(_L("\\scndrv\\"));
  1080     test(r==KErrNone);
  1082     test_KErrNone(r);
  1081     }
  1083     }
  1082 
  1084 
  1083 LOCAL_C void CreateDirectoryStructure()
  1085 LOCAL_C void CreateDirectoryStructure()
  1084 //
  1086 //
  1085 // creates the directory structure
  1087 // creates the directory structure
  1086 //
  1088 //
  1087     {
  1089     {
  1088     test.Next(_L("Create Directory Structure"));
  1090     test.Next(_L("Create Directory Structure"));
  1089     // cluster 3 (root dir is cluster 2)
  1091     // cluster 3 (root dir is cluster 2)
  1090     TInt r=TheFs.MkDir(_L("\\scndrv\\"));
  1092     TInt r=TheFs.MkDir(_L("\\scndrv\\"));
  1091     test(r==KErrNone);
  1093     test_KErrNone(r);
  1092     // cluster 4
  1094     // cluster 4
  1093     r=TheFs.MkDir(_L("\\scndrv\\dir1\\"));
  1095     r=TheFs.MkDir(_L("\\scndrv\\dir1\\"));
  1094     test(r==KErrNone);
  1096     test_KErrNone(r);
  1095     TFileName veryLongName=(_L("\\scndrv\\dir1\\"));
  1097     TFileName veryLongName=(_L("\\scndrv\\dir1\\"));
  1096     MakeVeryLongName(veryLongName);
  1098     MakeVeryLongName(veryLongName);
  1097     RFile f;
  1099     RFile f;
  1098     // cluster 5
  1100     // cluster 5
  1099     r=f.Create(TheFs,veryLongName,EFileShareAny);
  1101     r=f.Create(TheFs,veryLongName,EFileShareAny);
  1100     test(r==KErrNone);
  1102     test_KErrNone(r);
  1101     r=f.SetSize(512);
  1103     r=f.SetSize(512);
  1102     test(r==KErrNone);
  1104     test_KErrNone(r);
  1103     f.Close();
  1105     f.Close();
  1104     // cluster 6
  1106     // cluster 6
  1105     r=TheFs.MkDir(_L("\\scndrv\\dir2\\"));
  1107     r=TheFs.MkDir(_L("\\scndrv\\dir2\\"));
  1106     test(r==KErrNone);
  1108     test_KErrNone(r);
  1107     // cluster 7
  1109     // cluster 7
  1108     r=TheFs.MkDir(_L("\\scndrv\\dir2\\full\\"));
  1110     r=TheFs.MkDir(_L("\\scndrv\\dir2\\full\\"));
  1109     test(r==KErrNone);
  1111     test_KErrNone(r);
  1110     // cluster 8
  1112     // cluster 8
  1111     r=TheFs.MkDir(_L("\\scndrv\\dir2\\somedirwith3entries\\"));
  1113     r=TheFs.MkDir(_L("\\scndrv\\dir2\\somedirwith3entries\\"));
  1112     test(r==KErrNone);
  1114     test_KErrNone(r);
  1113     // cluster 9
  1115     // cluster 9
  1114     r=TheFs.MkDir(_L("\\scndrv\\dir2\\somedir2with3entries\\"));
  1116     r=TheFs.MkDir(_L("\\scndrv\\dir2\\somedir2with3entries\\"));
  1115     test(r==KErrNone);
  1117     test_KErrNone(r);
  1116     // cluster 10
  1118     // cluster 10
  1117     r=TheFs.MkDir(_L("\\scndrv\\dir2\\almostfull\\"));
  1119     r=TheFs.MkDir(_L("\\scndrv\\dir2\\almostfull\\"));
  1118     test(r==KErrNone);
  1120     test_KErrNone(r);
  1119     // cluster 11-17
  1121     // cluster 11-17
  1120     TInt entriesNeeded=(gEntriesPerCluster-2) / 2;  //7*2entries + . + .. = full sector
  1122     TInt entriesNeeded=(gEntriesPerCluster-2) / 2;  //7*2entries + . + .. = full sector
  1121     for (TInt i = 0; i < entriesNeeded; i++)
  1123     for (TInt i = 0; i < entriesNeeded; i++)
  1122         {
  1124         {
  1123         TFileName file=_L("\\scndrv\\dir2\\full\\__a");
  1125         TFileName file=_L("\\scndrv\\dir2\\full\\__a");
  1124         file.AppendNum(i);
  1126         file.AppendNum(i);
  1125         LastInFull = file;
  1127         LastInFull = file;
  1126         r=f.Create(TheFs,file,EFileShareAny);
  1128         r=f.Create(TheFs,file,EFileShareAny);
  1127         test(r==KErrNone);
  1129         test_KErrNone(r);
  1128         if (i < 7)
  1130         if (i < 7)
  1129             {
  1131             {
  1130             r=f.SetSize(512);
  1132             r=f.SetSize(512);
  1131             test(r==KErrNone);
  1133             test_KErrNone(r);
  1132             }
  1134             }
  1133         f.Close();
  1135         f.Close();
  1134         }
  1136         }
  1135     // cluster 18-19
  1137     // cluster 18-19
  1136     TInt charLength=13*4+1; // name to take up 6 entries
  1138     TInt charLength=13*4+1; // name to take up 6 entries
  1142         }
  1144         }
  1143     TFileName file2=file1;
  1145     TFileName file2=file1;
  1144     file1.AppendNum(1);
  1146     file1.AppendNum(1);
  1145     file2.AppendNum(2);
  1147     file2.AppendNum(2);
  1146     r=f.Create(TheFs,file1,EFileShareAny);
  1148     r=f.Create(TheFs,file1,EFileShareAny);
  1147     test(r==KErrNone);
  1149     test_KErrNone(r);
  1148     r=f.SetSize(512);
  1150     r=f.SetSize(512);
  1149     test(r==KErrNone);
  1151     test_KErrNone(r);
  1150     f.Close();
  1152     f.Close();
  1151     r=f.Create(TheFs,file2,EFileShareAny);
  1153     r=f.Create(TheFs,file2,EFileShareAny);
  1152     test(r==KErrNone);
  1154     test_KErrNone(r);
  1153     r=f.SetSize(512);
  1155     r=f.SetSize(512);
  1154     test(r==KErrNone);
  1156     test_KErrNone(r);
  1155     f.Close();
  1157     f.Close();
  1156     }
  1158     }
  1157 
  1159 
  1158 LOCAL_C TUint8* DirPtr(TInt aOffset)
  1160 LOCAL_C TUint8* DirPtr(TInt aOffset)
  1159 //
  1161 //
  1175         {
  1177         {
  1176         // allocate buffer for 2 clusters, starting at the cluster which
  1178         // allocate buffer for 2 clusters, starting at the cluster which
  1177         // contains aOffset
  1179         // contains aOffset
  1178         ExtBufLen = 2 * gBytesPerCluster;
  1180         ExtBufLen = 2 * gBytesPerCluster;
  1179         ExtBufPtr = HBufC8::New(ExtBufLen);
  1181         ExtBufPtr = HBufC8::New(ExtBufLen);
  1180         test(ExtBufPtr != NULL);
  1182         test_NotNull(ExtBufPtr);
  1181         // read the clusters in
  1183         // read the clusters in
  1182         ExtBufAdd = aOffset - aOffset % gBytesPerCluster;
  1184         ExtBufAdd = aOffset - aOffset % gBytesPerCluster;
  1183         TInt clust = (ExtBufAdd - (gDataStartBytes - gRootDirStart)) /gBytesPerCluster + 2;
  1185         TInt clust = (ExtBufAdd - (gDataStartBytes - gRootDirStart)) /gBytesPerCluster + 2;
  1184         RDebug::Print(_L("Extension buffer for cluster %d allocated"), clust);
  1186         RDebug::Print(_L("Extension buffer for cluster %d allocated"), clust);
  1185         TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
  1187         TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
  1186         test(r==KErrNone);
  1188         test_KErrNone(r);
  1187         TPtr8 des(ExtBufPtr->Des());
  1189         TPtr8 des(ExtBufPtr->Des());
  1188         r=TheRawDisk.Read(gRootDirStart + ExtBufAdd, des);
  1190         r=TheRawDisk.Read(gRootDirStart + ExtBufAdd, des);
  1189         test(r==KErrNone);
  1191         test_KErrNone(r);
  1190         TheRawDisk.Close();
  1192         TheRawDisk.Close();
  1191         }
  1193         }
  1192     // convert to offset in the extension buffer
  1194     // convert to offset in the extension buffer
  1193     aOffset -= ExtBufAdd;
  1195     aOffset -= ExtBufAdd;
  1194     if (aOffset >= ExtBufLen)
  1196     if (aOffset >= ExtBufLen)
  1219 LOCAL_C void ReadDirDisk(TDes8& aDirBuf, TInt aCluster = -1)
  1221 LOCAL_C void ReadDirDisk(TDes8& aDirBuf, TInt aCluster = -1)
  1220 //
  1222 //
  1221 // reads directory section of disk into buffer
  1223 // reads directory section of disk into buffer
  1222 //
  1224 //
  1223     {
  1225     {
  1224     test(aCluster != 1);
  1226     test_Value(aCluster, aCluster != 1);
  1225 
  1227 
  1226     TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
  1228     TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
  1227     test(r==KErrNone);
  1229     test_KErrNone(r);
  1228 
  1230 
  1229     if (aCluster == -1) // all clusters ?
  1231     if (aCluster == -1) // all clusters ?
  1230         {
  1232         {
  1231         r=TheRawDisk.Read(gRootDirStart, aDirBuf);
  1233         r=TheRawDisk.Read(gRootDirStart, aDirBuf);
  1232         }
  1234         }
  1243             (gRootDirSectors * BootSector.BytesPerSector());
  1245             (gRootDirSectors * BootSector.BytesPerSector());
  1244         TPtr8 dirPtr = aDirBuf.MidTPtr(pos, gBytesPerCluster);
  1246         TPtr8 dirPtr = aDirBuf.MidTPtr(pos, gBytesPerCluster);
  1245         r=TheRawDisk.Read(gRootDirStart + pos, dirPtr);
  1247         r=TheRawDisk.Read(gRootDirStart + pos, dirPtr);
  1246         }
  1248         }
  1247 
  1249 
  1248     test(r==KErrNone);
  1250     test_KErrNone(r);
  1249     TheRawDisk.Close();
  1251     TheRawDisk.Close();
  1250     }
  1252     }
  1251 
  1253 
  1252 LOCAL_C void ReadFatDisk(TDes8& aFatBuf)
  1254 LOCAL_C void ReadFatDisk(TDes8& aFatBuf)
  1253 //
  1255 //
  1254 // reads fat section of disk info buffer
  1256 // reads fat section of disk info buffer
  1255 //
  1257 //
  1256     {
  1258     {
  1257     TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
  1259     TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
  1258     test(r==KErrNone);
  1260     test_KErrNone(r);
  1259     r=TheRawDisk.Read(gFatStartBytes, aFatBuf);
  1261     r=TheRawDisk.Read(gFatStartBytes, aFatBuf);
  1260     test(r==KErrNone);
  1262     test_KErrNone(r);
  1261     TheRawDisk.Close();
  1263     TheRawDisk.Close();
  1262     }
  1264     }
  1263 
  1265 
  1264 LOCAL_C void WriteDirDisk(TDes8& aDirBuf, TInt aCluster = -1)
  1266 LOCAL_C void WriteDirEntryToDisk(TDes8& aDirBuf, TInt aCluster = -1)
  1265 //
  1267 //
  1266 // writes dir buffer to disk
  1268 // writes dir entry buffer to disk
  1267 //
  1269 //
  1268     {
  1270     {
  1269     test(aCluster != 1);
  1271 	test_Value(aCluster, aCluster != 1);
  1270 
  1272 
  1271     TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
  1273     TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
  1272     test(r==KErrNone);
  1274     test_KErrNone(r);
  1273 
  1275 
  1274     if (aCluster == -1)
  1276     if (aCluster == -1)
  1275         {
  1277         {
  1276         r=TheRawDisk.Write(gRootDirStart, aDirBuf);
  1278         r=TheRawDisk.Write(gRootDirStart, aDirBuf);
  1277         }
  1279         }
  1288             (gRootDirSectors * BootSector.BytesPerSector());
  1290             (gRootDirSectors * BootSector.BytesPerSector());
  1289         TPtr8 dirPtr = aDirBuf.MidTPtr(pos, gBytesPerCluster);
  1291         TPtr8 dirPtr = aDirBuf.MidTPtr(pos, gBytesPerCluster);
  1290         r=TheRawDisk.Write(gRootDirStart + pos, dirPtr);
  1292         r=TheRawDisk.Write(gRootDirStart + pos, dirPtr);
  1291         }
  1293         }
  1292 
  1294 
  1293     test(r==KErrNone);
  1295     test_KErrNone(r);
  1294     if (ExtBufPtr)
  1296     if (ExtBufPtr)
  1295         {
  1297         {
  1296         TPtr8 des(ExtBufPtr->Des());
  1298         TPtr8 des(ExtBufPtr->Des());
  1297         r=TheRawDisk.Write(gRootDirStart + ExtBufAdd, des);
  1299         r=TheRawDisk.Write(gRootDirStart + ExtBufAdd, des);
  1298         test(r==KErrNone);
  1300         test_KErrNone(r);
  1299         }
  1301         }
  1300     TheRawDisk.Close();
  1302     TheRawDisk.Close();
  1301     }
  1303     }
  1302 
  1304 
  1303 LOCAL_C void WriteFatDisk(TDes8& aFatBuf, TInt aStart=0)
  1305 LOCAL_C void WriteFatToDisk(TDes8& aFatBuf, TInt aStart=0)
  1304 //
  1306 //
  1305 // writes fat buffer to disk
  1307 // writes fat buffer to disk
  1306 //
  1308 //
  1307     {
  1309     {
  1308     TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
  1310     TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
  1309     test(r==KErrNone);
  1311     test_KErrNone(r);
  1310     TInt fatCount=BootSector.NumberOfFats() - aStart;
  1312     TInt fatCount=BootSector.NumberOfFats() - aStart;
  1311     TInt pos = gFatStartBytes + aStart * gFatSizeSectors*BootSector.BytesPerSector();
  1313     TInt pos = gFatStartBytes + aStart * gFatSizeSectors*BootSector.BytesPerSector();
  1312     while(fatCount--)
  1314     while(fatCount--)
  1313         {
  1315         {
  1314         r=TheRawDisk.Write(pos, aFatBuf);
  1316         r=TheRawDisk.Write(pos, aFatBuf);
  1315         test(r==KErrNone);
  1317         test_KErrNone(r);
  1316         pos += gFatSizeSectors*BootSector.BytesPerSector();
  1318         pos += gFatSizeSectors*BootSector.BytesPerSector();
  1317         }
  1319         }
  1318     TheRawDisk.Close();
  1320     TheRawDisk.Close();
  1319     }
  1321     }
  1320 
  1322 
  1367     gFatTestEntries = MaxClusters();
  1369     gFatTestEntries = MaxClusters();
  1368     if (gFatTestEntries > KMaxFatSize)
  1370     if (gFatTestEntries > KMaxFatSize)
  1369         gFatTestEntries = KMaxFatSize;
  1371         gFatTestEntries = KMaxFatSize;
  1370     gFatTestSize = PosInBytes(gFatTestEntries);
  1372     gFatTestSize = PosInBytes(gFatTestEntries);
  1371     FatBufPtr=HBufC8::New(gFatTestSize);
  1373     FatBufPtr=HBufC8::New(gFatTestSize);
  1372     test(FatBufPtr!=NULL);
  1374     test_NotNull(FatBufPtr);
  1373     DirBufPtr=HBufC8::New(DirBufferSize());
  1375     DirBufPtr=HBufC8::New(DirBufferSize());
  1374     test(DirBufPtr!=NULL);
  1376     test_NotNull(DirBufPtr);
  1375 
  1377 
  1376     // Buffers for reading from disk
  1378     // Buffers for reading from disk
  1377     FatDiskPtr=HBufC8::New(gFatTestSize);
  1379     FatDiskPtr=HBufC8::New(gFatTestSize);
  1378     test(FatDiskPtr!=NULL);
  1380     test_NotNull(FatDiskPtr);
  1379     DirDiskPtr=HBufC8::New(DirBufferSize());
  1381     DirDiskPtr=HBufC8::New(DirBufferSize());
  1380     test(DirDiskPtr!=NULL);
  1382     test_NotNull(DirDiskPtr);
  1381     }
  1383     }
  1382 
  1384 
  1383 LOCAL_C TBool IsSameAsDrive(const TDes8& aFatBuf,const TDes8& aDirBuf)
  1385 LOCAL_C TBool IsSameAsDrive(const TDes8& aFatBuf,const TDes8& aDirBuf)
  1384 //
  1386 //
  1385 // compares the two bufs passed in with those on disk
  1387 // compares the two bufs passed in with those on disk
  1462 		DumpData(fatDisk.Ptr(), dirDisk.Ptr());
  1464 		DumpData(fatDisk.Ptr(), dirDisk.Ptr());
  1463         }
  1465         }
  1464     else if (ExtBufPtr)
  1466     else if (ExtBufPtr)
  1465         {
  1467         {
  1466         HBufC8* extPtr = HBufC8::New(ExtBufLen);
  1468         HBufC8* extPtr = HBufC8::New(ExtBufLen);
  1467         test(extPtr != NULL);
  1469         test_NotNull(extPtr);
  1468         TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
  1470         TInt r=TheRawDisk.Open(TheFs,gSessionPath[0]-'A');
  1469         test(r==KErrNone);
  1471         test_KErrNone(r);
  1470         TPtr8 des(extPtr->Des());
  1472         TPtr8 des(extPtr->Des());
  1471         r=TheRawDisk.Read(ExtBufAdd+gRootDirStart, des);
  1473         r=TheRawDisk.Read(ExtBufAdd+gRootDirStart, des);
  1472         test(r==KErrNone);
  1474         test_KErrNone(r);
  1473         TheRawDisk.Close();
  1475         TheRawDisk.Close();
  1474         TInt i = FindUnMatch(ExtBufPtr->Ptr(), extPtr->Ptr(), ExtBufLen);
  1476         TInt i = FindUnMatch(ExtBufPtr->Ptr(), extPtr->Ptr(), ExtBufLen);
  1475         if (i >= 0)
  1477         if (i >= 0)
  1476             {
  1478             {
  1477             TInt extcl = (ExtBufAdd - (gDataStartBytes-gRootDirStart)) / gBytesPerCluster + 2;
  1479             TInt extcl = (ExtBufAdd - (gDataStartBytes-gRootDirStart)) / gBytesPerCluster + 2;
  1516     {
  1518     {
  1517     WriteErased(aTrg,aToDelete);
  1519     WriteErased(aTrg,aToDelete);
  1518     if(aAddEOfDir)
  1520     if(aAddEOfDir)
  1519         WriteEndOfDir(aTrg.iBytePos+aTrg.iLength*KSizeOfFatDirEntry);
  1521         WriteEndOfDir(aTrg.iBytePos+aTrg.iLength*KSizeOfFatDirEntry);
  1520     TPtr8 dirBuf=DirBufPtr->Des();
  1522     TPtr8 dirBuf=DirBufPtr->Des();
  1521     WriteDirDisk(dirBuf);
  1523     WriteDirEntryToDisk(dirBuf);
  1522     }
  1524     }
  1523 
  1525 
  1524 LOCAL_C TBool TestPartialEntry(TEntryInfo aEntry)
  1526 LOCAL_C TBool TestPartialEntry(TEntryInfo aEntry)
  1525 //
  1527 //
  1526 // 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
  1527 //
  1529 //
  1528     {
  1530     {
  1529     test.Next(_L("TestPartialEntry"));
  1531     test.Next(_L("TestPartialEntry"));
  1530     TInt r=TheFs.ScanDrive(gSessionPath);
  1532     TInt r=TheFs.ScanDrive(gSessionPath);
  1531     test(r==KErrNone);
  1533     test_KErrNone(r);
  1532     WriteDelete(aEntry.iBytePos,aEntry.iLength);
  1534     WriteDelete(aEntry.iBytePos,aEntry.iLength);
  1533 
  1535 
  1534     TPtr8 fatBuf=FatBufPtr->Des();
  1536     TPtr8 fatBuf=FatBufPtr->Des();
  1535     TPtr8 dirBuf=DirBufPtr->Des();
  1537     TPtr8 dirBuf=DirBufPtr->Des();
  1536 
  1538 
  1549     Mem::Copy(dst, src, aSrc.iLength*KSizeOfFatDirEntry);
  1551     Mem::Copy(dst, src, aSrc.iLength*KSizeOfFatDirEntry);
  1550     WriteReservedId(aTrg.iBytePos+(aTrg.iLength-1)*KSizeOfFatDirEntry);
  1552     WriteReservedId(aTrg.iBytePos+(aTrg.iLength-1)*KSizeOfFatDirEntry);
  1551     if(aAddEOfDir)
  1553     if(aAddEOfDir)
  1552         WriteEndOfDir(aTrg.iBytePos+aTrg.iLength*KSizeOfFatDirEntry);
  1554         WriteEndOfDir(aTrg.iBytePos+aTrg.iLength*KSizeOfFatDirEntry);
  1553     TPtr8 dirBuf=DirBufPtr->Des();
  1555     TPtr8 dirBuf=DirBufPtr->Des();
  1554     WriteDirDisk(dirBuf);
  1556     WriteDirEntryToDisk(dirBuf);
  1555     }
  1557     }
  1556 
  1558 
  1557 LOCAL_C TBool TestMatchingEntry(TEntryInfo aToDelete)
  1559 LOCAL_C TBool TestMatchingEntry(TEntryInfo aToDelete)
  1558 //
  1560 //
  1559 // tests that scandrive deals with matching entries correctly
  1561 // tests that scandrive deals with matching entries correctly
  1560 //
  1562 //
  1561     {
  1563     {
  1562     test.Next(_L("TestMatchingEntries"));
  1564     test.Next(_L("TestMatchingEntries"));
  1563     WriteDelete(aToDelete.iBytePos,aToDelete.iLength);
  1565     WriteDelete(aToDelete.iBytePos,aToDelete.iLength);
  1564     TInt r=TheFs.ScanDrive(gSessionPath);
  1566     TInt r=TheFs.ScanDrive(gSessionPath);
  1565     test(r==KErrNone);
  1567     test_KErrNone(r);
  1566 
  1568 
  1567     TPtr8 fatBuf=FatBufPtr->Des();
  1569     TPtr8 fatBuf=FatBufPtr->Des();
  1568     TPtr8 dirBuf=DirBufPtr->Des();
  1570     TPtr8 dirBuf=DirBufPtr->Des();
  1569 
  1571 
  1570     TBool res=IsSameAsDrive(fatBuf,dirBuf);
  1572     TBool res=IsSameAsDrive(fatBuf,dirBuf);
  1584 
  1586 
  1585     _LIT(KRoot,"\\");
  1587     _LIT(KRoot,"\\");
  1586     CDir* dirs;
  1588     CDir* dirs;
  1587     // check no entries in the root directory
  1589     // check no entries in the root directory
  1588     TInt r=TheFs.GetDir(KRoot,KEntryAttMaskSupported,ESortNone,dirs);
  1590     TInt r=TheFs.GetDir(KRoot,KEntryAttMaskSupported,ESortNone,dirs);
  1589     test(r==KErrNone);
  1591     test_KErrNone(r);
  1590     test(dirs->Count()==0);
  1592     test_Equal(0,dirs->Count());
  1591     delete(dirs);
  1593     delete(dirs);
  1592     dirs=NULL;
  1594     dirs=NULL;
  1593 
  1595 
  1594     // create file
  1596     // create file
  1595     _LIT(KOrigShortName,"P_SSI.TXT");
  1597     _LIT(KOrigShortName,"P_SSI.TXT");
  1603     ExtShortName[1] = 0xC4; //-- replace '$' with this code
  1605     ExtShortName[1] = 0xC4; //-- replace '$' with this code
  1604 
  1606 
  1605 
  1607 
  1606     RFile file;
  1608     RFile file;
  1607     r=file.Replace(TheFs,TestFileName,EFileShareExclusive);
  1609     r=file.Replace(TheFs,TestFileName,EFileShareExclusive);
  1608     test(r==KErrNone);
  1610     test_KErrNone(r);
  1609     file.Close();
  1611     file.Close();
  1610 
  1612 
  1611     // get short name
  1613     // get short name
  1612     TFileName shortName;
  1614     TFileName shortName;
  1613     r=TheFs.GetShortName(TestFileName,shortName);
  1615     r=TheFs.GetShortName(TestFileName,shortName);
  1614     test(r==KErrNone);
  1616     test_KErrNone(r);
  1615     test(shortName==KOrigShortName);
  1617     test(shortName==KOrigShortName);
  1616 
  1618 
  1617     // must be first entry in root, modify to read like
  1619     // must be first entry in root, modify to read like
  1618     // a windows-generated short name (ie. contains extended character)
  1620     // a windows-generated short name (ie. contains extended character)
  1619     DumpData(NULL, 0, 20);
  1621     DumpData(NULL, 0, 20);
  1620     TInt bytePos=ClusterEntryToBytes(0,1);
  1622     TInt bytePos=ClusterEntryToBytes(0,1);
  1621     RRawDisk raw;
  1623     RRawDisk raw;
  1622     r=raw.Open(TheFs,gSessionPath[0]-'A');
  1624     r=raw.Open(TheFs,gSessionPath[0]-'A');
  1623     test(r==KErrNone);
  1625     test_KErrNone(r);
  1624     TBuf8<1> buf(1);
  1626     TBuf8<1> buf(1);
  1625 
  1627 
  1626     //-- change 2nd character in the short name (Fat DOS entry)
  1628     //-- change 2nd character in the short name (Fat DOS entry)
  1627     buf[0]=(TUint8)'\xC4';
  1629     buf[0]=(TUint8)'\xC4';
  1628     r=raw.Write(gRootDirStart+bytePos+1,buf);
  1630     r=raw.Write(gRootDirStart+bytePos+1,buf);
  1629     test(r==KErrNone);
  1631     test_KErrNone(r);
  1630 
  1632 
  1631     //-- fix the fiddled short name checksum in the corresponding VFat entry
  1633     //-- fix the fiddled short name checksum in the corresponding VFat entry
  1632     bytePos=ClusterEntryToBytes(0,0);
  1634     bytePos=ClusterEntryToBytes(0,0);
  1633     buf[0]=(TUint8)0x2f;
  1635     buf[0]=(TUint8)0x2f;
  1634     r=raw.Write(gRootDirStart+bytePos+13,buf);
  1636     r=raw.Write(gRootDirStart+bytePos+13,buf);
  1635     test(r==KErrNone);
  1637     test_KErrNone(r);
  1636 
  1638 
  1637     // retrieve short name from media.
  1639     // retrieve short name from media.
  1638     // 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.
  1639     bytePos=ClusterEntryToBytes(0,1);
  1641     bytePos=ClusterEntryToBytes(0,1);
  1640     TBuf8<11> shortNameBuf8;
  1642     TBuf8<11> shortNameBuf8;
  1641     r=raw.Read(gRootDirStart+bytePos,shortNameBuf8);
  1643     r=raw.Read(gRootDirStart+bytePos,shortNameBuf8);
  1642     test(r==KErrNone);
  1644     test_KErrNone(r);
  1643     shortNameBuf8 = DosNameFromStdFormat(shortNameBuf8);
  1645     shortNameBuf8 = DosNameFromStdFormat(shortNameBuf8);
  1644     shortName.Copy(shortNameBuf8);
  1646     shortName.Copy(shortNameBuf8);
  1645     raw.Close();
  1647     raw.Close();
  1646 
  1648 
  1647 
  1649 
  1648     test(shortName==ExtShortName);
  1650     test(shortName==ExtShortName);
  1649     DumpData(NULL, 0, 20);
  1651     DumpData(NULL, 0, 20);
  1650     //TheFs.SetDebugRegister(KFSYS);
  1652     //TheFs.SetDebugRegister(KFSYS);
  1651     r=TheFs.ScanDrive(gSessionPath);
  1653     r=TheFs.ScanDrive(gSessionPath);
  1652     TheFs.SetDebugRegister(0);
  1654     TheFs.SetDebugRegister(0);
  1653     test(r==KErrNone);
  1655     test_KErrNone(r);
  1654     DumpData(NULL, 0, 20);
  1656     DumpData(NULL, 0, 20);
  1655 
  1657 
  1656     // retrieve short name from media.
  1658     // retrieve short name from media.
  1657     r=raw.Open(TheFs,gSessionPath[0]-'A');
  1659     r=raw.Open(TheFs,gSessionPath[0]-'A');
  1658     test(r==KErrNone);
  1660     test_KErrNone(r);
  1659     bytePos=ClusterEntryToBytes(0,1);
  1661     bytePos=ClusterEntryToBytes(0,1);
  1660     r=raw.Read(gRootDirStart+bytePos,shortNameBuf8);
  1662     r=raw.Read(gRootDirStart+bytePos,shortNameBuf8);
  1661     test(r==KErrNone);
  1663     test_KErrNone(r);
  1662     shortNameBuf8 = DosNameFromStdFormat(shortNameBuf8);
  1664     shortNameBuf8 = DosNameFromStdFormat(shortNameBuf8);
  1663     shortName.Copy(shortNameBuf8);
  1665     shortName.Copy(shortNameBuf8);
  1664     raw.Close();
  1666     raw.Close();
  1665 
  1667 
  1666     test(shortName==ExtShortName);
  1668     test(shortName==ExtShortName);
  1667 
  1669 
  1668     // delete file
  1670     // delete file
  1669     r=TheFs.Delete(TestFileName);
  1671     r=TheFs.Delete(TestFileName);
  1670     test(r==KErrNone);
  1672     test_KErrNone(r);
  1671     }
  1673     }
  1672 
  1674 
  1673 LOCAL_C void TestMountAndScan()
  1675 LOCAL_C void TestMountAndScan()
  1674 //
  1676 //
  1675 // test MountFileSystemAndScan()
  1677 // test MountFileSystemAndScan()
  1678     TFullName extName;
  1680     TFullName extName;
  1679     TBool primaryExtensionExists = EFalse;
  1681     TBool primaryExtensionExists = EFalse;
  1680 
  1682 
  1681     test.Next(_L("TestMountAndScan"));
  1683     test.Next(_L("TestMountAndScan"));
  1682     HBufC8* newFat=HBufC8::New(gFatTestSize);
  1684     HBufC8* newFat=HBufC8::New(gFatTestSize);
  1683     test(newFat!=NULL);
  1685     test_NotNull(newFat);
  1684     TPtr8 fat=newFat->Des();
  1686     TPtr8 fat=newFat->Des();
  1685     TPtr8 origFat=FatBufPtr->Des();
  1687     TPtr8 origFat=FatBufPtr->Des();
  1686     TPtr8 origDir=DirBufPtr->Des();
  1688     TPtr8 origDir=DirBufPtr->Des();
  1687 
  1689 
  1688     // set cluster of \scndrv\dir1\ to a hanging cluster
  1690     // set cluster of \scndrv\dir1\ to a hanging cluster
  1689     ReadFatDisk(fat);
  1691     ReadFatDisk(fat);
  1690     WriteFat(gClusterDir1ext,35,fat.Ptr());
  1692     WriteToFatBuf(gClusterDir1ext,35,fat.Ptr());
  1691     WriteFat(35,36,fat.Ptr());
  1693     WriteToFatBuf(35,36,fat.Ptr());
  1692     WriteFatDisk(fat);
  1694     WriteFatToDisk(fat);
  1693     // set the default path to something other than the current drive
  1695     // set the default path to something other than the current drive
  1694     TFileName fsName;
  1696     TFileName fsName;
  1695     TInt r=TheFs.FileSystemName(fsName,gSessionPath[0]-'A');
  1697     TInt r=TheFs.FileSystemName(fsName,gSessionPath[0]-'A');
  1696     test(r==KErrNone);
  1698     test_KErrNone(r);
  1697     TFileName origDefPath, newDefPath;
  1699     TFileName origDefPath, newDefPath;
  1698     r=TheFs.SessionPath(origDefPath);
  1700     r=TheFs.SessionPath(origDefPath);
  1699     test(r==KErrNone);
  1701     test_KErrNone(r);
  1700     newDefPath=origDefPath;
  1702     newDefPath=origDefPath;
  1701     newDefPath[0]=(TText)'z';
  1703     newDefPath[0]=(TText)'z';
  1702     r=TheFs.SetSessionPath(newDefPath);
  1704     r=TheFs.SetSessionPath(newDefPath);
  1703     test(r==KErrNone);
  1705     test_KErrNone(r);
  1704     r = TheFs.ExtensionName(extName,gSessionPath[0]-'A',0);
  1706     r = TheFs.ExtensionName(extName,gSessionPath[0]-'A',0);
  1705     if (r == KErrNone)
  1707     if (r == KErrNone)
  1706         {
  1708         {
  1707         primaryExtensionExists = ETrue;
  1709         primaryExtensionExists = ETrue;
  1708         }
  1710         }
  1709     r=TheFs.DismountFileSystem(fsName,gSessionPath[0]-'A');
  1711     r=TheFs.DismountFileSystem(fsName,gSessionPath[0]-'A');
  1710     test(r==KErrNone);
  1712     test_KErrNone(r);
  1711     // mount file system and check scandrive corrects error
  1713     // mount file system and check scandrive corrects error
  1712     TBool isMount;
  1714     TBool isMount;
  1713     if (primaryExtensionExists)
  1715     if (primaryExtensionExists)
  1714         r=TheFs.MountFileSystemAndScan(fsName,extName,gSessionPath[0]-'A',isMount);
  1716         r=TheFs.MountFileSystemAndScan(fsName,extName,gSessionPath[0]-'A',isMount);
  1715     else
  1717     else
  1716         r=TheFs.MountFileSystemAndScan(fsName,gSessionPath[0]-'A',isMount);
  1718         r=TheFs.MountFileSystemAndScan(fsName,gSessionPath[0]-'A',isMount);
  1717     test(isMount && r==KErrNone);
  1719     test(isMount);
       
  1720     test_KErrNone(r);
  1718     TBool res=IsSameAsDrive(origFat,origDir);
  1721     TBool res=IsSameAsDrive(origFat,origDir);
  1719     test(res);
  1722     test(res);
  1720 
  1723 
  1721     r=TheFs.SetSessionPath(origDefPath);
  1724     r=TheFs.SetSessionPath(origDefPath);
  1722     test(r==KErrNone);
  1725     test_KErrNone(r);
  1723     delete newFat;
  1726     delete newFat;
  1724     }
  1727     }
  1725 
  1728 
  1726 
  1729 
  1727 LOCAL_C void TestConsecutiveMountAndScans()
  1730 LOCAL_C void TestConsecutiveMountAndScans()
  1731     {
  1734     {
  1732     TFullName extName;
  1735     TFullName extName;
  1733     TBool primaryExtensionExists = EFalse;
  1736     TBool primaryExtensionExists = EFalse;
  1734     TFileName fsName;
  1737     TFileName fsName;
  1735     TInt r=TheFs.FileSystemName(fsName,gSessionPath[0]-'A');
  1738     TInt r=TheFs.FileSystemName(fsName,gSessionPath[0]-'A');
  1736     test(r==KErrNone);
  1739     test_KErrNone(r);
  1737     r = TheFs.ExtensionName(extName,gSessionPath[0]-'A',0);
  1740     r = TheFs.ExtensionName(extName,gSessionPath[0]-'A',0);
  1738     if (r == KErrNone)
  1741     if (r == KErrNone)
  1739         {
  1742         {
  1740         primaryExtensionExists = ETrue;
  1743         primaryExtensionExists = ETrue;
  1741         }
  1744         }
  1742     r=TheFs.DismountFileSystem(fsName,gSessionPath[0]-'A');
  1745     r=TheFs.DismountFileSystem(fsName,gSessionPath[0]-'A');
  1743     test(r==KErrNone);
  1746     test_KErrNone(r);
  1744 
  1747 
  1745     // RFs::MountFileSystemAndScan twice consecutively
  1748     // RFs::MountFileSystemAndScan twice consecutively
  1746     // first time
  1749     // first time
  1747     TBool isMount;
  1750     TBool isMount;
  1748     if (primaryExtensionExists)
  1751     if (primaryExtensionExists)
  1749         r=TheFs.MountFileSystemAndScan(fsName,extName,gSessionPath[0]-'A',isMount);
  1752         r=TheFs.MountFileSystemAndScan(fsName,extName,gSessionPath[0]-'A',isMount);
  1750     else
  1753     else
  1751         r=TheFs.MountFileSystemAndScan(fsName,gSessionPath[0]-'A',isMount);
  1754         r=TheFs.MountFileSystemAndScan(fsName,gSessionPath[0]-'A',isMount);
  1752     test(isMount && r==KErrNone);
  1755     test(isMount);
       
  1756     test_KErrNone(r);
  1753     // and a second time
  1757     // and a second time
  1754     if (primaryExtensionExists)
  1758     if (primaryExtensionExists)
  1755         r=TheFs.MountFileSystemAndScan(fsName,extName,gSessionPath[0]-'A',isMount);
  1759         r=TheFs.MountFileSystemAndScan(fsName,extName,gSessionPath[0]-'A',isMount);
  1756     else
  1760     else
  1757         r=TheFs.MountFileSystemAndScan(fsName,gSessionPath[0]-'A',isMount);
  1761         r=TheFs.MountFileSystemAndScan(fsName,gSessionPath[0]-'A',isMount);
  1758     test(!isMount && r==KErrAccessDenied);
  1762     test(!isMount);
  1759     }
  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 
  1760 
  1785 
  1761 LOCAL_C void DoHangingClusters()
  1786 LOCAL_C void DoHangingClusters()
  1762 //
  1787 //
  1763 // Tests that scandrive removes hanging clusters
  1788 // Tests that scandrive removes hanging clusters
  1764 //
  1789 //
  1765     {
  1790     {
  1766     test.Next(_L("Check Hanging clusters"));
  1791     test.Next(_L("Check Hanging clusters"));
  1767     HBufC8* newFat=HBufC8::New(gFatTestSize);
  1792     HBufC8* newFat=HBufC8::New(gFatTestSize);
  1768     test(newFat!=NULL);
  1793     test_NotNull(newFat);
  1769     TPtr8 fat=newFat->Des();
  1794     TPtr8 fat=newFat->Des();
  1770     TPtr8 origFat=FatBufPtr->Des();
  1795     TPtr8 origFat=FatBufPtr->Des();
  1771     TPtr8 origDir=DirBufPtr->Des();
  1796     TPtr8 origDir=DirBufPtr->Des();
  1772 
  1797 
  1773     // set cluster of \scndrv\dir1\ to a hanging cluster
  1798     // Set cluster of \scndrv\dir1\ to hanging cluster chain
  1774     test.Start(_L("Test hanging cluster in \\scndrv\\dir1\\"));
  1799     test.Start(_L("Test hanging cluster in \\scndrv\\dir1\\"));
  1775     ReadFatDisk(fat);
  1800     ReadFatDisk(fat);
  1776     WriteFat(gClusterDir1ext,35,fat.Ptr());
  1801     WriteToFatBuf(gClusterDir1ext,35,fat.Ptr());
  1777     WriteFat(35,36,fat.Ptr());
  1802     WriteToFatBuf(35,36,fat.Ptr());
  1778     WriteFatDisk(fat);
  1803     WriteFatToDisk(fat); // gClusterDir1ext->35->36
  1779     TInt r=TheFs.ScanDrive(gSessionPath);
  1804     TInt r=TheFs.ScanDrive(gSessionPath);
  1780     test(r==KErrNone);
  1805     test_KErrNone(r);
  1781     TBool res=IsSameAsDrive(origFat,origDir);
  1806     TBool res=IsSameAsDrive(origFat,origDir);
  1782     test(res);
  1807     test(res);
  1783 
  1808 
  1784     // set  cluster chain of first entry of \scndrv\dir1\ to
  1809     // Set cluster chain of first entry of \scndrv\dir1\ to
  1785     // larger size than file size
  1810     // larger size than file size
  1786     test.Next(_L("Test hanging cluster in first entry"));
  1811     test.Next(_L("Test hanging cluster in first entry"));
  1787     ReadFatDisk(fat);
  1812     ReadFatDisk(fat);
  1788     WriteFat(gClusterDir1ext,39,fat.Ptr());
  1813     WriteToFatBuf(gClusterDir1ext,39,fat.Ptr());
  1789     WriteFat(39,500,fat.Ptr());
  1814     WriteToFatBuf(39,500,fat.Ptr());
  1790     WriteFat(500,gEndOfChain,fat.Ptr());
  1815     CreateContiguousClusterChain(500, 505, fat.Ptr(), ETrue);
  1791     WriteFatDisk(fat);
  1816     WriteFatToDisk(fat); // gClusterDir1ext->39->500->501->502->503->504->505->EOC
  1792     r=TheFs.ScanDrive(gSessionPath);
  1817     r=TheFs.ScanDrive(gSessionPath);
  1793     test(r==KErrNone);
  1818     test_KErrNone(r);
  1794     res=IsSameAsDrive(origFat,origDir);
  1819     res=IsSameAsDrive(origFat,origDir);
  1795     test(res);
  1820     test(res);
  1796 
  1821 
  1797     // set cluster of \scndrv\ to a hanging cluster
  1822     // Set cluster of \scndrv\ to a hanging cluster
  1798     test.Next(_L("Test hanging cluster of \\scndrv\\"));
  1823     test.Next(_L("Test hanging cluster of \\scndrv\\"));
  1799     ReadFatDisk(fat);
  1824     ReadFatDisk(fat);
  1800     WriteFat(gClusterScnDrv,511,fat.Ptr());
  1825     WriteToFatBuf(gClusterScnDrv,511,fat.Ptr());
  1801     WriteFatDisk(fat);
  1826     WriteFatToDisk(fat); // gClusterScnDrv->511
  1802     r=TheFs.ScanDrive(gSessionPath);
  1827     r=TheFs.ScanDrive(gSessionPath);
  1803     test(r==KErrNone);
  1828     test_KErrNone(r);
  1804     res=IsSameAsDrive(origFat,origDir);
  1829     res=IsSameAsDrive(origFat,origDir);
  1805     test(res);
  1830     test(res);
  1806 
  1831 
  1807     delete newFat;
  1832     delete newFat;
  1808     test.End();
  1833     test.End();
  1813 // Tests that scandrive removes lost clusters
  1838 // Tests that scandrive removes lost clusters
  1814 //
  1839 //
  1815     {
  1840     {
  1816     test.Next(_L("Check lost clusters"));
  1841     test.Next(_L("Check lost clusters"));
  1817     HBufC8* newFat=HBufC8::New(gFatTestSize);
  1842     HBufC8* newFat=HBufC8::New(gFatTestSize);
  1818     test(newFat!=NULL);
  1843     test_NotNull(newFat);
  1819     TPtr8 fat=newFat->Des();
  1844     TPtr8 fat=newFat->Des();
  1820     TPtr8 origFat=FatBufPtr->Des();
  1845     TPtr8 origFat=FatBufPtr->Des();
  1821     TPtr8 origDir=DirBufPtr->Des();
  1846     TPtr8 origDir=DirBufPtr->Des();
  1822     ReadFatDisk(origFat);
  1847     ReadFatDisk(origFat);
  1823     ReadDirDisk(origDir);
  1848     ReadDirDisk(origDir);
  1824 
  1849 
  1825     // write cluster chain
  1850     // write cluster chain
  1826     test.Start(_L("Test removal of lost cluster chain"));
  1851     test.Start(_L("Test removal of lost cluster chain"));
  1827     ReadFatDisk(fat);
  1852     ReadFatDisk(fat);
  1828     for(TInt i=25;i<35;++i)
  1853     CreateContiguousClusterChain(25, 35, fat.Ptr(), ETrue);
  1829         WriteFat(i,i+1,fat.Ptr());
  1854     WriteFatToDisk(fat); // 25->26->27->28->29->30->31->32->33->34->35->EOC
  1830     WriteFat(35,gEndOfChain,fat.Ptr());
       
  1831     WriteFatDisk(fat);
       
  1832     TInt r=TheFs.ScanDrive(gSessionPath);
  1855     TInt r=TheFs.ScanDrive(gSessionPath);
  1833     test(r==KErrNone);
  1856     test_KErrNone(r);
  1834     TBool res=IsSameAsDrive(origFat,origDir);
  1857     TBool res=IsSameAsDrive(origFat,origDir);
  1835     test(res);
  1858     test(res);
  1836 
  1859 
  1837     // write semi-random changes to first fat
  1860     // write semi-random changes to first fat
  1838     test.Next(_L("Test semi-random changes to first fat"));
  1861     test.Next(_L("Test semi-random changes to first fat"));
  1839     for(TInt j=1;j<gFatTestSize/BootSector.BytesPerSector();++j)
  1862     for(TInt j=1;j<gFatTestSize/BootSector.BytesPerSector();++j)
  1840         {
  1863         {
  1841         TInt off = j*BootSector.BytesPerSector()+j*7%512;
  1864         TInt off = j*BootSector.BytesPerSector()+j*7%512;
  1842         fat[off]=1;
  1865         fat[off]=1;
  1843         }
  1866         }
  1844     WriteFatDisk(fat);
  1867     WriteFatToDisk(fat);
  1845     r=TheFs.ScanDrive(gSessionPath);
  1868     r=TheFs.ScanDrive(gSessionPath);
  1846     test(r==KErrNone);
  1869     test_KErrNone(r);
  1847     res=IsSameAsDrive(origFat,origDir);
  1870     res=IsSameAsDrive(origFat,origDir);
  1848     test(res);
  1871     test(res);
  1849 
  1872 
  1850     // write semi-random changes to second fat
  1873     // write semi-random changes to second fat
  1851     test.Next(_L("Test semi-random changes to second fat"));
  1874     test.Next(_L("Test semi-random changes to second fat"));
  1852     WriteFatDisk(fat, 1);
  1875     WriteFatToDisk(fat, 1);
  1853     r=TheFs.ScanDrive(gSessionPath);
  1876     r=TheFs.ScanDrive(gSessionPath);
  1854     test(r==KErrNone);
  1877     test_KErrNone(r);
  1855     res=IsSameAsDrive(origFat,origDir);
  1878     res=IsSameAsDrive(origFat,origDir);
  1856     test(res);
  1879     test(res);
  1857 
  1880 
  1858     delete newFat;
  1881     delete newFat;
  1859     test.End();
  1882     test.End();
  1860     }
  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 
  1861 
  1952 
  1862 LOCAL_C void DoPartEntries()
  1953 LOCAL_C void DoPartEntries()
  1863 //
  1954 //
  1864 // Tests that scandrive detects/corrects partial entries
  1955 // Tests that scandrive detects/corrects partial entries
  1865 //
  1956 //
  1870     test.Start(_L("Check partial entries"));
  1961     test.Start(_L("Check partial entries"));
  1871     TPtr8 fatBuf=FatBufPtr->Des();
  1962     TPtr8 fatBuf=FatBufPtr->Des();
  1872     TPtr8 dirBuf=DirBufPtr->Des();
  1963     TPtr8 dirBuf=DirBufPtr->Des();
  1873 
  1964 
  1874     TInt r=TheFs.RmDir(_L("\\scndrv\\dir2\\somedirwith3entries\\"));
  1965     TInt r=TheFs.RmDir(_L("\\scndrv\\dir2\\somedirwith3entries\\"));
  1875     test(r==KErrNone || r==KErrNotFound || KErrPathNotFound);
  1966     test_Value(r, r==KErrNone || r==KErrNotFound || r==KErrPathNotFound);
  1876     r=TheFs.RmDir(_L("\\scndrv\\dir2\\somedir2with3entries\\"));
  1967     r=TheFs.RmDir(_L("\\scndrv\\dir2\\somedir2with3entries\\"));
  1877     test(r==KErrNone || r==KErrNotFound || KErrPathNotFound);
  1968     test_Value(r, r==KErrNone || r==KErrNotFound || r==KErrPathNotFound);
  1878 
  1969 
  1879     if (BootSector.RootDirEntries() != 0)
  1970     if (BootSector.RootDirEntries() != 0)
  1880         {
  1971         {
  1881         // 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
  1882         // partial entry that fills up the root dir
  1973         // partial entry that fills up the root dir
  1883         test.Next(_L("Partial entry at end of rootdir"));
  1974         test.Next(_L("Partial entry at end of rootdir"));
  1884         FillUpRootDir(2);
  1975         FillUpRootDir(2);
  1885         r=temp.Create(TheFs,_L("\\temp"),EFileShareAny);
  1976         r=temp.Create(TheFs,_L("\\temp"),EFileShareAny);
  1886         test(r==KErrNone);
  1977         test_KErrNone(r);
  1887         temp.Close();
  1978         temp.Close();
  1888         ReadDirDisk(dirBuf);
  1979         ReadDirDisk(dirBuf);
  1889         ReadFatDisk(fatBuf);
  1980         ReadFatDisk(fatBuf);
  1890         TEntryInfo partial1(ClusterEntryToBytes(gClusterRootDir,BootSector.RootDirEntries()-2),2);
  1981         TEntryInfo partial1(ClusterEntryToBytes(gClusterRootDir,BootSector.RootDirEntries()-2),2);
  1891         CreatePartialEntry(partial1,1,EFalse);
  1982         CreatePartialEntry(partial1,1,EFalse);
  1901     last = GetStartCluster(gClusterDir2_AFull,7);
  1992     last = GetStartCluster(gClusterDir2_AFull,7);
  1902     TEntryInfo partial2(ClusterEntryToBytes(gClusterDir2_AFull,2),6);
  1993     TEntryInfo partial2(ClusterEntryToBytes(gClusterDir2_AFull,2),6);
  1903     CreatePartialEntry(partial2,3,EFalse);
  1994     CreatePartialEntry(partial2,3,EFalse);
  1904     // 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
  1905     if (last > 0)
  1996     if (last > 0)
  1906         WriteFat(last,0,fatBuf.Ptr());
  1997         WriteToFatBuf(last,0,fatBuf.Ptr());
  1907     res=TestPartialEntry(partial2);
  1998     res=TestPartialEntry(partial2);
  1908     test(res);
  1999     test(res);
  1909 
  2000 
  1910     // reduce size of \scndrv\dir2\full\ 
  2001     // reduce size of \scndrv\dir2\full\ 
  1911     test.Next(_L("Test directory reclaim"));
  2002     test.Next(_L("Test directory reclaim"));
  1912     last = GetStartCluster(gClusterDir2_Full,gEntriesPerCluster-2);
  2003     last = GetStartCluster(gClusterDir2_Full,gEntriesPerCluster-2);
  1913     WriteEndOfDir(ClusterEntryToBytes(gClusterDir2_Full,gEntriesPerCluster-2));
  2004     WriteEndOfDir(ClusterEntryToBytes(gClusterDir2_Full,gEntriesPerCluster-2));
  1914     WriteDirDisk(dirBuf);
  2005     WriteDirEntryToDisk(dirBuf);
  1915     TInt entry = GetFatEntry(gClusterDir2_Full, fatBuf.Ptr());
  2006     TInt entry = GetFatEntry(gClusterDir2_Full, fatBuf.Ptr());
  1916     WriteFat(gClusterDir2_Full,gEndOfChain,fatBuf.Ptr());
  2007     WriteToFatBuf(gClusterDir2_Full,gEndOfChain,fatBuf.Ptr());
  1917     while (entry && (entry & gEndOfChain) != gEndOfChain)
  2008     while (entry && (entry & gEndOfChain) != gEndOfChain)
  1918         {
  2009         {
  1919         TInt next = GetFatEntry(entry, fatBuf.Ptr());
  2010         TInt next = GetFatEntry(entry, fatBuf.Ptr());
  1920         WriteFat(entry,0,fatBuf.Ptr());
  2011         WriteToFatBuf(entry,0,fatBuf.Ptr());
  1921         entry = next;
  2012         entry = next;
  1922         }
  2013         }
  1923     if (last > 0)
  2014     if (last > 0)
  1924         WriteFat(last,0,fatBuf.Ptr());
  2015         WriteToFatBuf(last,0,fatBuf.Ptr());
  1925     r=TheFs.ScanDrive(gSessionPath);
  2016     r=TheFs.ScanDrive(gSessionPath);
  1926     test(r==KErrNone);
  2017     test_KErrNone(r);
  1927     res=IsSameAsDrive(fatBuf,dirBuf);
  2018     res=IsSameAsDrive(fatBuf,dirBuf);
  1928     test(res);
  2019     test(res);
  1929 
  2020 
  1930     // use last entry of first cluster in \scndrv\dir2\full\ 
  2021     // use last entry of first cluster in \scndrv\dir2\full\ 
  1931     test.Next(_L("Partial entry at end of subdir"));
  2022     test.Next(_L("Partial entry at end of subdir"));
  1932     r=temp.Create(TheFs,_L("\\scndrv\\dir2\\full\\temp"),EFileShareAny);
  2023     r=temp.Create(TheFs,_L("\\scndrv\\dir2\\full\\temp"),EFileShareAny);
  1933     test(r==KErrNone);
  2024     test_KErrNone(r);
  1934     temp.Close();
  2025     temp.Close();
  1935     ReadDirDisk(dirBuf);
  2026     ReadDirDisk(dirBuf);
  1936     ReadFatDisk(fatBuf);
  2027     ReadFatDisk(fatBuf);
  1937     TEntryInfo partial3(ClusterEntryToBytes(gClusterDir2_Full,gEntriesPerCluster-2),2);
  2028     TEntryInfo partial3(ClusterEntryToBytes(gClusterDir2_Full,gEntriesPerCluster-2),2);
  1938     CreatePartialEntry(partial3,1,EFalse);
  2029     CreatePartialEntry(partial3,1,EFalse);
  1941 
  2032 
  1942     // use entry in \scndrv\dir2\almostfull\ 
  2033     // use entry in \scndrv\dir2\almostfull\ 
  1943     test.Next(_L("Partial entry preceeding end-of-dir marker"));
  2034     test.Next(_L("Partial entry preceeding end-of-dir marker"));
  1944     last = GetStartCluster(gClusterDir2_AFull,14);
  2035     last = GetStartCluster(gClusterDir2_AFull,14);
  1945     if (last > 0)
  2036     if (last > 0)
  1946         WriteFat(last,0,fatBuf.Ptr());
  2037         WriteToFatBuf(last,0,fatBuf.Ptr());
  1947     last = GetStartCluster(gClusterDir2_AFull,8);
  2038     last = GetStartCluster(gClusterDir2_AFull,8);
  1948     if (last > 0)
  2039     if (last > 0)
  1949         WriteFat(last,0,fatBuf.Ptr());
  2040         WriteToFatBuf(last,0,fatBuf.Ptr());
  1950     WriteEndOfDir(ClusterEntryToBytes(gClusterDir2_AFull,14));
  2041     WriteEndOfDir(ClusterEntryToBytes(gClusterDir2_AFull,14));
  1951     WriteDirDisk(dirBuf);
  2042     WriteDirEntryToDisk(dirBuf);
  1952     TEntryInfo partial4(ClusterEntryToBytes(gClusterDir2_AFull,8),6);
  2043     TEntryInfo partial4(ClusterEntryToBytes(gClusterDir2_AFull,8),6);
  1953     CreatePartialEntry(partial4,4,EFalse);
  2044     CreatePartialEntry(partial4,4,EFalse);
  1954     res=TestPartialEntry(partial4);
  2045     res=TestPartialEntry(partial4);
  1955     test(res);
  2046     test(res);
  1956 
  2047 
  1962 	//	DBCS charater.
  2053 	//	DBCS charater.
  1963 
  2054 
  1964 	// create entry in \scndrv\dir2\almostfull\ 
  2055 	// create entry in \scndrv\dir2\almostfull\ 
  1965 //	test.Next(_L("Partial entry with invalid dos name"));
  2056 //	test.Next(_L("Partial entry with invalid dos name"));
  1966 //	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);
  1967 //	test(r==KErrNone);
  2058 //	test_KErrNone(r);
  1968 //	temp.Close();
  2059 //	temp.Close();
  1969 //	ReadDirDisk(dirBuf);
  2060 //	ReadDirDisk(dirBuf);
  1970 //	TInt dosStart=ClusterEntryToBytes(gClusterDir2_AFull,4);
  2061 //	TInt dosStart=ClusterEntryToBytes(gClusterDir2_AFull,4);
  1971 //	dirBuf[dosStart+4]=0x1;
  2062 //	dirBuf[dosStart+4]=0x1;
  1972 //	WriteDirDisk(dirBuf);
  2063 //	WriteDirDisk(dirBuf);
  1973 //	r=TheFs.ScanDrive(gSessionPath);
  2064 //	r=TheFs.ScanDrive(gSessionPath);
  1974 //	test(r==KErrNone);
  2065 //	test_KErrNone(r);
  1975 //	WriteDelete(dosStart-2*32,3);
  2066 //	WriteDelete(dosStart-2*32,3);
  1976 //	res=IsSameAsDrive(fatBuf,dirBuf);
  2067 //	res=IsSameAsDrive(fatBuf,dirBuf);
  1977 //	test(res);
  2068 //	test(res);
  1978 
  2069 
  1979     if (BootSector.SectorsPerCluster() == 1)
  2070     if (BootSector.SectorsPerCluster() == 1)
  1981         // use entry created in \scndrv\dir2\ 
  2072         // use entry created in \scndrv\dir2\ 
  1982         test.Next(_L("Partial entry spanning more than two clusters"));
  2073         test.Next(_L("Partial entry spanning more than two clusters"));
  1983         last = GetStartCluster(gClusterDir2_Full,gEntriesPerCluster-1);
  2074         last = GetStartCluster(gClusterDir2_Full,gEntriesPerCluster-1);
  1984         WriteEndOfDir(ClusterEntryToBytes(gClusterDir2_Full,gEntriesPerCluster-2));
  2075         WriteEndOfDir(ClusterEntryToBytes(gClusterDir2_Full,gEntriesPerCluster-2));
  1985         WriteEndOfDir(ClusterEntryToBytes(gClusterDir2_Full,gEntriesPerCluster-1));
  2076         WriteEndOfDir(ClusterEntryToBytes(gClusterDir2_Full,gEntriesPerCluster-1));
  1986         WriteDirDisk(dirBuf);
  2077         WriteDirEntryToDisk(dirBuf);
  1987         TFileName longFile=_L("\\scndrv\\dir2\\full\\");
  2078         TFileName longFile=_L("\\scndrv\\dir2\\full\\");
  1988         MakeVeryLongName(longFile);
  2079         MakeVeryLongName(longFile);
  1989         r=temp.Create(TheFs,longFile,EFileShareAny);
  2080         r=temp.Create(TheFs,longFile,EFileShareAny);
  1990         test(r==KErrNone);
  2081         test_KErrNone(r);
  1991         temp.Close();
  2082         temp.Close();
  1992         ReadDirDisk(dirBuf);
  2083         ReadDirDisk(dirBuf);
  1993         WriteFat(gClusterDir2_Full,gClusterDir2_SD3E,fatBuf.Ptr());
  2084         WriteToFatBuf(gClusterDir2_Full,gClusterDir2_SD3E,fatBuf.Ptr());
  1994         WriteFat(gClusterDir2_SD3E,gClusterDir2_SD23E,fatBuf.Ptr());
  2085         WriteToFatBuf(gClusterDir2_SD3E,gClusterDir2_SD23E,fatBuf.Ptr());
  1995         WriteFat(gClusterDir2_SD23E,gEndOfChain,fatBuf.Ptr());
  2086         WriteToFatBuf(gClusterDir2_SD23E,gEndOfChain,fatBuf.Ptr());
  1996         if (last > 0)
  2087         if (last > 0)
  1997             WriteFat(last,0,fatBuf.Ptr());
  2088             WriteToFatBuf(last,0,fatBuf.Ptr());
  1998         TEntryInfo partial5(ClusterEntryToBytes(gClusterDir2_Full,gEntriesPerCluster-2),19);
  2089         TEntryInfo partial5(ClusterEntryToBytes(gClusterDir2_Full,gEntriesPerCluster-2),19);
  1999         CreatePartialEntry(partial5,7,EFalse);
  2090         CreatePartialEntry(partial5,7,EFalse);
  2000         res=TestPartialEntry(partial5);
  2091         res=TestPartialEntry(partial5);
  2001         test(res);
  2092         test(res);
  2002         r=TheFs.Delete(longFile);
  2093         r=TheFs.Delete(longFile);
  2003         test(r==KErrNone || r==KErrNotFound);
  2094         test_Value(r, r==KErrNone || r==KErrNotFound);
  2004         r=TheFs.Delete(_L("\\temp"));
  2095         r=TheFs.Delete(_L("\\temp"));
  2005         test(r==KErrNone || r==KErrNotFound);
  2096         test_Value(r, r==KErrNone || r==KErrNotFound);
  2006         }
  2097         }
  2007     ReadDirDisk(dirBuf);
  2098     ReadDirDisk(dirBuf);
  2008 
  2099 
  2009     test.End();
  2100     test.End();
  2010     }
  2101     }
  2050     // 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
  2051     // 1st and last entries in \scndrv\dir2\full\ 
  2142     // 1st and last entries in \scndrv\dir2\full\ 
  2052     test.Next(_L("matching entries in same subdir"));
  2143     test.Next(_L("matching entries in same subdir"));
  2053     // delete entries to allow contiguous clusters in \scndrv\dir2\full directory
  2144     // delete entries to allow contiguous clusters in \scndrv\dir2\full directory
  2054     TInt r=TheFs.RmDir(_L("\\scndrv\\dir2\\somedirwith3entries\\"));
  2145     TInt r=TheFs.RmDir(_L("\\scndrv\\dir2\\somedirwith3entries\\"));
  2055     test(r==KErrNone);
  2146     test_KErrNone(r);
  2056     r=TheFs.RmDir(_L("\\scndrv\\dir2\\somedir2with3entries\\"));
  2147     r=TheFs.RmDir(_L("\\scndrv\\dir2\\somedir2with3entries\\"));
  2057     test(r==KErrNone);
  2148     test_KErrNone(r);
  2058     // ensure directory is expanded
  2149     // ensure directory is expanded
  2059     RFile temp;
  2150     RFile temp;
  2060     r=temp.Create(TheFs,_L("\\scndrv\\dir2\\full\\temp"),EFileShareAny);
  2151     r=temp.Create(TheFs,_L("\\scndrv\\dir2\\full\\temp"),EFileShareAny);
  2061     test(r==KErrNone);
  2152     test_KErrNone(r);
  2062     temp.Close();
  2153     temp.Close();
  2063     r=TheFs.Delete(_L("\\scndrv\\dir2\\full\\temp"));
  2154     r=TheFs.Delete(_L("\\scndrv\\dir2\\full\\temp"));
  2064     test(r==KErrNone);
  2155     test_KErrNone(r);
  2065     ReadDirDisk(dirBuf);
  2156     ReadDirDisk(dirBuf);
  2066     ReadFatDisk(fatBuf);
  2157     ReadFatDisk(fatBuf);
  2067     TEntryInfo from4(ClusterEntryToBytes(gClusterDir2_Full,4),2);
  2158     TEntryInfo from4(ClusterEntryToBytes(gClusterDir2_Full,4),2);
  2068     TEntryInfo to4(ClusterEntryToBytes(gClusterDir2_Full+1,0),2);
  2159     TEntryInfo to4(ClusterEntryToBytes(gClusterDir2_Full+1,0),2);
  2069     CreateMatchingEntry(to4,from4,ETrue);
  2160     CreateMatchingEntry(to4,from4,ETrue);
  2072 
  2163 
  2073     // \scndrv\dir1\very long name to \\scndrv\dir2\full\ 
  2164     // \scndrv\dir1\very long name to \\scndrv\dir2\full\ 
  2074     test.Next(_L("matching entries in diff dirs + new cluster"));
  2165     test.Next(_L("matching entries in diff dirs + new cluster"));
  2075     // delete last entry in directory
  2166     // delete last entry in directory
  2076     r=TheFs.Delete(LastInFull);
  2167     r=TheFs.Delete(LastInFull);
  2077     test(r==KErrNone);
  2168     test_KErrNone(r);
  2078     TFileName veryLongName=_L("\\scndrv\\dir2\\full\\");
  2169     TFileName veryLongName=_L("\\scndrv\\dir2\\full\\");
  2079     MakeVeryLongName(veryLongName);
  2170     MakeVeryLongName(veryLongName);
  2080     r=temp.Create(TheFs,veryLongName,EFileShareAny);
  2171     r=temp.Create(TheFs,veryLongName,EFileShareAny);
  2081     test(r==KErrNone);
  2172     test_KErrNone(r);
  2082     temp.Close();
  2173     temp.Close();
  2083     r=TheFs.Delete(veryLongName);
  2174     r=TheFs.Delete(veryLongName);
  2084     test(r==KErrNone);
  2175     test_KErrNone(r);
  2085     ReadDirDisk(dirBuf);
  2176     ReadDirDisk(dirBuf);
  2086     ReadFatDisk(fatBuf);
  2177     ReadFatDisk(fatBuf);
  2087     TEntryInfo from5(ClusterEntryToBytes(gClusterDir1,2),19);
  2178     TEntryInfo from5(ClusterEntryToBytes(gClusterDir1,2),19);
  2088     TEntryInfo to5(ClusterEntryToBytes(gClusterDir2_Full,gEntriesPerCluster-2),19);
  2179     TEntryInfo to5(ClusterEntryToBytes(gClusterDir2_Full,gEntriesPerCluster-2),19);
  2089     CreateMatchingEntry(to5,from5,EFalse);
  2180     CreateMatchingEntry(to5,from5,EFalse);
  2109     CreateMaxDepthDir(dir1,dir2);
  2200     CreateMaxDepthDir(dir1,dir2);
  2110     ReadDirDisk(dirBuf);
  2201     ReadDirDisk(dirBuf);
  2111     ReadFatDisk(fatBuf);
  2202     ReadFatDisk(fatBuf);
  2112     // run scandisk and compare
  2203     // run scandisk and compare
  2113     TInt r=TheFs.ScanDrive(gSessionPath);
  2204     TInt r=TheFs.ScanDrive(gSessionPath);
  2114     test(r==KErrNone);
  2205     test_KErrNone(r);
  2115     TBool res=IsSameAsDrive(fatBuf,dirBuf);
  2206     TBool res=IsSameAsDrive(fatBuf,dirBuf);
  2116     test(res);
  2207     test(res);
  2117     // Create a entry with matching start cluster and check fixed up
  2208     // Create a entry with matching start cluster and check fixed up
  2118     TEntryInfo from(ClusterEntryToBytes(gClusterDir2_AFull,2),6);
  2209     TEntryInfo from(ClusterEntryToBytes(gClusterDir2_AFull,2),6);
  2119     TEntryInfo to(ClusterEntryToBytes(gClusterEndMaxDepth,2),6);
  2210     TEntryInfo to(ClusterEntryToBytes(gClusterEndMaxDepth,2),6);
  2136     TPtr8 dirBuf=DirBufPtr->Des();
  2227     TPtr8 dirBuf=DirBufPtr->Des();
  2137     ReadDirDisk(dirBuf);
  2228     ReadDirDisk(dirBuf);
  2138     ReadFatDisk(fatBuf);
  2229     ReadFatDisk(fatBuf);
  2139 
  2230 
  2140     TInt r=TheFs.ScanDrive(gSessionPath);
  2231     TInt r=TheFs.ScanDrive(gSessionPath);
  2141     test(r==KErrNone);
  2232     test_KErrNone(r);
  2142 
  2233 
  2143     TBool res=IsSameAsDrive(fatBuf,dirBuf);
  2234     TBool res=IsSameAsDrive(fatBuf,dirBuf);
  2144     test(res);
  2235     test(res);
  2145     UnFillUpRootDir();
  2236     UnFillUpRootDir();
  2146     }
  2237     }
  2229             TFileName name(aDirName);
  2320             TFileName name(aDirName);
  2230             name.Append(_L("tempfile."));
  2321             name.Append(_L("tempfile."));
  2231             name.AppendNumFixedWidth(i+totalFilesCreated, EHex, 3);
  2322             name.AppendNumFixedWidth(i+totalFilesCreated, EHex, 3);
  2232             RFile f;
  2323             RFile f;
  2233             r = f.Create(TheFs, name, EFileShareAny);
  2324             r = f.Create(TheFs, name, EFileShareAny);
  2234             test(r == KErrNone);
  2325             test_KErrNone(r);
  2235             r = f.Write(buf);
  2326             r = f.Write(buf);
  2236             test(r == KErrNone);
  2327             test_KErrNone(r);
  2237             f.Close();
  2328             f.Close();
  2238             }
  2329             }
  2239 
  2330 
  2240         //
  2331         //
  2241         // 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
  2264                 entry += 2;
  2355                 entry += 2;
  2265                 }
  2356                 }
  2266 
  2357 
  2267             }
  2358             }
  2268 
  2359 
  2269         WriteDirDisk(dirBuf, cluster);
  2360         WriteDirEntryToDisk(dirBuf, cluster);
  2270         totalFilesCreated += filesThisTime;
  2361         totalFilesCreated += filesThisTime;
  2271         test.Printf(_L("   created %d entries\n"), totalFilesCreated);
  2362         test.Printf(_L("   created %d entries\n"), totalFilesCreated);
  2272         }
  2363         }
  2273 
  2364 
  2274     ReadDirDisk(dirBuf);
  2365     ReadDirDisk(dirBuf);
  2276 
  2367 
  2277     DumpData(NULL, aDirCluster, cluster+1);
  2368     DumpData(NULL, aDirCluster, cluster+1);
  2278 
  2369 
  2279     test.Printf(_L("Running ScanDrive\n"), filesThisTime);
  2370     test.Printf(_L("Running ScanDrive\n"), filesThisTime);
  2280     r=TheFs.ScanDrive(gSessionPath);
  2371     r=TheFs.ScanDrive(gSessionPath);
  2281     test(r==KErrNone);
  2372     test_KErrNone(r);
  2282 
  2373 
  2283     TBool res=IsSameAsDrive(fatBuf,dirBuf);
  2374     TBool res=IsSameAsDrive(fatBuf,dirBuf);
  2284     test(res);
  2375     test(res);
  2285 
  2376 
  2286     test.Printf(_L("Deleting %d files\n"), nFiles);
  2377     test.Printf(_L("Deleting %d files\n"), nFiles);
  2288         {
  2379         {
  2289         TFileName name(aDirName);
  2380         TFileName name(aDirName);
  2290         name.Append(_L("tempfile."));
  2381         name.Append(_L("tempfile."));
  2291         name.AppendNumFixedWidth(i, EHex, 3);
  2382         name.AppendNumFixedWidth(i, EHex, 3);
  2292         r = TheFs.Delete(name);
  2383         r = TheFs.Delete(name);
  2293         test(r == KErrNone);
  2384         test_KErrNone(r);
  2294         }
  2385         }
  2295 
  2386 
  2296     ReadDirDisk(dirBuf);
  2387     ReadDirDisk(dirBuf);
  2297     ReadFatDisk(fatBuf);
  2388     ReadFatDisk(fatBuf);
  2298     WriteEndOfDir(ClusterEntryToBytes(cluster, startEntry));
  2389     WriteEndOfDir(ClusterEntryToBytes(cluster, startEntry));
  2299     WriteDirDisk(dirBuf);
  2390     WriteDirEntryToDisk(dirBuf);
  2300 
  2391 
  2301     test.Printf(_L("Running ScanDrive\n"), filesThisTime);
  2392     test.Printf(_L("Running ScanDrive\n"), filesThisTime);
  2302     r=TheFs.ScanDrive(gSessionPath);
  2393     r=TheFs.ScanDrive(gSessionPath);
  2303     test(r==KErrNone);
  2394     test_KErrNone(r);
  2304     res=IsSameAsDrive(fatBuf,dirBuf);
  2395     res=IsSameAsDrive(fatBuf,dirBuf);
  2305     test(res);
  2396     test(res);
  2306     }
  2397     }
  2307 
  2398 
  2308 LOCAL_C void DoNonVfatNames()
  2399 LOCAL_C void DoNonVfatNames()
  2339     DoMaxDepth();
  2430     DoMaxDepth();
  2340     DoMatchingEntries();
  2431     DoMatchingEntries();
  2341     DoPartEntries();
  2432     DoPartEntries();
  2342     DoLostClusters();
  2433     DoLostClusters();
  2343     DoHangingClusters();
  2434     DoHangingClusters();
       
  2435     DoHangingAndLostClusters();
  2344     TestMountAndScan();
  2436     TestMountAndScan();
  2345     TestConsecutiveMountAndScans();
  2437     TestConsecutiveMountAndScans();
  2346     DeleteDirectoryStructure();
  2438     DeleteDirectoryStructure();
  2347     DeleteRootDir();
  2439     DeleteRootDir();
  2348     TestExtendedChars();
  2440     TestExtendedChars();
  2360 
  2452 
  2361 void CallTestsL()
  2453 void CallTestsL()
  2362     {
  2454     {
  2363     TInt r;
  2455     TInt r;
  2364     r = TheFs.CharToDrive(gSessionPath[0], gDriveNumber);
  2456     r = TheFs.CharToDrive(gSessionPath[0], gDriveNumber);
  2365     test( KErrNone == r );
  2457     test_KErrNone(r);
  2366 
  2458 
  2367 
  2459 
  2368     //-- set up console output
  2460     //-- set up console output
  2369     Fat_Test_Utils::SetConsole(test.Console());
  2461     Fat_Test_Utils::SetConsole(test.Console());
  2370 
  2462 
  2378         }
  2470         }
  2379 
  2471 
  2380     // check this is not the internal ram drive
  2472     // check this is not the internal ram drive
  2381     TVolumeInfo v;
  2473     TVolumeInfo v;
  2382     r=TheFs.Volume(v);
  2474     r=TheFs.Volume(v);
  2383     test(r==KErrNone);
  2475     test_KErrNone(r);
  2384     if(v.iDrive.iMediaAtt&KMediaAttVariableSize)
  2476     if(v.iDrive.iMediaAtt&KMediaAttVariableSize)
  2385         {
  2477         {
  2386         test.Printf(_L("Error: Internal ram drive not tested\n"));
  2478         test.Printf(_L("Error: Internal ram drive not tested\n"));
  2387         return;
  2479         return;
  2388         }
  2480         }
  2389 
  2481 
  2390     r=TheFs.SetSessionPath(gSessionPath);
  2482     r=TheFs.SetSessionPath(gSessionPath);
  2391     test(r==KErrNone);
  2483     test_KErrNone(r);
  2392 
  2484 
  2393     DoTests();
  2485     DoTests();
  2394 
  2486 
  2395     return;
  2487     return;
  2396     }
  2488     }