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 } |
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 |
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) |
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 |
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); |
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); |
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() |