branch | RCL_3 |
changeset 43 | c1f20ce4abcf |
parent 21 | e7d2d738d3c2 |
child 44 | 3e88ff8f41d5 |
42:a179b74831c9 | 43:c1f20ce4abcf |
---|---|
13 // Description: |
13 // Description: |
14 // f32test\server\b_fat32.cpp |
14 // f32test\server\b_fat32.cpp |
15 // |
15 // |
16 // |
16 // |
17 |
17 |
18 #define __E32TEST_EXTENSION__ |
|
18 #include <f32file.h> |
19 #include <f32file.h> |
19 #include <e32test.h> |
20 #include <e32test.h> |
20 #include <e32math.h> |
21 #include <e32math.h> |
21 |
22 |
22 #include "fat_utils.h" |
23 #include "fat_utils.h" |
146 ptr = (TUint8*)aFat + pos; |
147 ptr = (TUint8*)aFat + pos; |
147 else |
148 else |
148 { |
149 { |
149 pos += TheBootSector.ReservedSectors() * TheBootSector.BytesPerSector(); |
150 pos += TheBootSector.ReservedSectors() * TheBootSector.BytesPerSector(); |
150 TInt r=TheDisk.Open(TheFs,gSessionPath[0]-'A'); |
151 TInt r=TheDisk.Open(TheFs,gSessionPath[0]-'A'); |
151 test(r==KErrNone); |
152 test_KErrNone(r); |
152 TPtr8 buf(&data[0], 4); |
153 TPtr8 buf(&data[0], 4); |
153 r=TheDisk.Read(pos, buf); |
154 r=TheDisk.Read(pos, buf); |
154 test(r==KErrNone); |
155 test_KErrNone(r); |
155 TheDisk.Close(); |
156 TheDisk.Close(); |
156 } |
157 } |
157 |
158 |
158 TUint32 val = 0; |
159 TUint32 val = 0; |
159 switch (gDiskType) |
160 switch (gDiskType) |
183 { |
184 { |
184 TInt pos = PosInBytes(aIndex); |
185 TInt pos = PosInBytes(aIndex); |
185 pos += TheBootSector.ReservedSectors() * TheBootSector.BytesPerSector(); |
186 pos += TheBootSector.ReservedSectors() * TheBootSector.BytesPerSector(); |
186 |
187 |
187 TInt r=TheDisk.Open(TheFs,gSessionPath[0]-'A'); |
188 TInt r=TheDisk.Open(TheFs,gSessionPath[0]-'A'); |
188 test(r==KErrNone); |
189 test_KErrNone(r); |
189 TUint8 data[4]; |
190 TUint8 data[4]; |
190 TPtr8 buf(&data[0], 4); |
191 TPtr8 buf(&data[0], 4); |
191 r=TheDisk.Read(pos, buf); |
192 r=TheDisk.Read(pos, buf); |
192 test(r==KErrNone); |
193 test_KErrNone(r); |
193 data[3] &= 0x0F; |
194 data[3] &= 0x0F; |
194 data[3] |= 0xA0; |
195 data[3] |= 0xA0; |
195 r=TheDisk.Write(pos, buf); |
196 r=TheDisk.Write(pos, buf); |
196 test(r==KErrNone); |
197 test_KErrNone(r); |
197 TheDisk.Close(); |
198 TheDisk.Close(); |
198 } |
199 } |
199 |
200 |
200 void DumpBootSector() |
201 void DumpBootSector() |
201 // |
202 // |
466 { |
467 { |
467 HBufC8* buf=HBufC8::New(gBytesPerCluster); |
468 HBufC8* buf=HBufC8::New(gBytesPerCluster); |
468 test(buf!=NULL); |
469 test(buf!=NULL); |
469 TPtr8 ptr=buf->Des(); |
470 TPtr8 ptr=buf->Des(); |
470 TInt r=TheDisk.Open(TheFs,gSessionPath[0]-'A'); |
471 TInt r=TheDisk.Open(TheFs,gSessionPath[0]-'A'); |
471 test(r==KErrNone); |
472 test_KErrNone(r); |
472 r=TheDisk.Read(ClusterToByte(cluster), ptr); |
473 r=TheDisk.Read(ClusterToByte(cluster), ptr); |
473 test(r==KErrNone); |
474 test_KErrNone(r); |
474 TheDisk.Close(); |
475 TheDisk.Close(); |
475 RDebug::Print(_L("Cluster %d @ 0x%08X:"), cluster, ClusterToByte(cluster)); |
476 RDebug::Print(_L("Cluster %d @ 0x%08X:"), cluster, ClusterToByte(cluster)); |
476 DumpDirCluster(ptr.Ptr()); |
477 DumpDirCluster(ptr.Ptr()); |
477 delete buf; |
478 delete buf; |
478 } |
479 } |
497 TInt ent = 0; |
498 TInt ent = 0; |
498 HBufC8* buf=HBufC8::New(KSizeOfFatDirEntry); |
499 HBufC8* buf=HBufC8::New(KSizeOfFatDirEntry); |
499 test(buf!=NULL); |
500 test(buf!=NULL); |
500 TPtr8 ptr=buf->Des(); |
501 TPtr8 ptr=buf->Des(); |
501 TInt r=TheDisk.Open(TheFs,gSessionPath[0]-'A'); |
502 TInt r=TheDisk.Open(TheFs,gSessionPath[0]-'A'); |
502 test(r==KErrNone); |
503 test_KErrNone(r); |
503 RDebug::Print(_L("--------------- ROOT DIR ------------------")); |
504 RDebug::Print(_L("--------------- ROOT DIR ------------------")); |
504 for (TInt i = 0; i < num; i++) |
505 for (TInt i = 0; i < num; i++) |
505 { |
506 { |
506 r=TheDisk.Read(pos, ptr); |
507 r=TheDisk.Read(pos, ptr); |
507 test(r==KErrNone); |
508 test_KErrNone(r); |
508 if (!DumpDirEntry(ent, ptr.Ptr())) |
509 if (!DumpDirEntry(ent, ptr.Ptr())) |
509 break; |
510 break; |
510 pos += KSizeOfFatDirEntry; |
511 pos += KSizeOfFatDirEntry; |
511 } |
512 } |
512 RDebug::Print(_L("-------------------------------------------")); |
513 RDebug::Print(_L("-------------------------------------------")); |
761 default: |
762 default: |
762 test(0); |
763 test(0); |
763 } |
764 } |
764 |
765 |
765 TInt r=TheDisk.Open(TheFs,CurrentDrive()); |
766 TInt r=TheDisk.Open(TheFs,CurrentDrive()); |
766 test(r==KErrNone); |
767 test_KErrNone(r); |
767 test(ReadWriteDWord(pos,mask,aValue)==KErrNone); |
768 test(ReadWriteDWord(pos,mask,aValue)==KErrNone); |
768 TheDisk.Close(); |
769 TheDisk.Close(); |
769 } |
770 } |
770 |
771 |
771 static void TestRwWord(TInt64 aPos,TInt anErr) |
772 static void TestRwWord(TInt64 aPos,TInt anErr) |
1081 FatWrite(clust,gEndOfChain); |
1082 FatWrite(clust,gEndOfChain); |
1082 if ((r=TheFs.Delete(_L("\\LOOPED1.TMP")))!=KErrNone) |
1083 if ((r=TheFs.Delete(_L("\\LOOPED1.TMP")))!=KErrNone) |
1083 Error(_L("Error deleting file"),r); |
1084 Error(_L("Error deleting file"),r); |
1084 RDebug::Print(_L("File removed")); |
1085 RDebug::Print(_L("File removed")); |
1085 r=TheFs.CheckDisk(gSessionPath); |
1086 r=TheFs.CheckDisk(gSessionPath); |
1086 test(r==KErrNone); |
1087 test_KErrNone(r); |
1087 } |
1088 } |
1088 |
1089 |
1089 static void TestFatEntry(TUint16 aFileSize,TInt aCorruptFatCluster) |
1090 static void TestFatEntry(TUint16 aFileSize,TInt aCorruptFatCluster) |
1090 // |
1091 // |
1091 // Test fat entry |
1092 // Test fat entry |
1094 TInt r; |
1095 TInt r; |
1095 test.Printf(_L("File size=%d, cluster value=0x%x\n"),aFileSize,aCorruptFatCluster); |
1096 test.Printf(_L("File size=%d, cluster value=0x%x\n"),aFileSize,aCorruptFatCluster); |
1096 FormatPack(); |
1097 FormatPack(); |
1097 |
1098 |
1098 r=TheFile.Replace(TheFs,_L("\\CORRUPT2.TMP"),EFileRead|EFileWrite); |
1099 r=TheFile.Replace(TheFs,_L("\\CORRUPT2.TMP"),EFileRead|EFileWrite); |
1099 test(r==KErrNone); |
1100 test_KErrNone(r); |
1100 TheBuffer.SetLength(aFileSize); |
1101 TheBuffer.SetLength(aFileSize); |
1101 Mem::Fill(&TheBuffer[0],aFileSize,'A'); |
1102 Mem::Fill(&TheBuffer[0],aFileSize,'A'); |
1102 r=TheFile.Write(TheBuffer); |
1103 r=TheFile.Write(TheBuffer); |
1103 test(r==KErrNone); |
1104 test_KErrNone(r); |
1104 TheFile.Close(); |
1105 TheFile.Close(); |
1105 |
1106 |
1106 FatWrite(gFirstDataCluster,aCorruptFatCluster); |
1107 FatWrite(gFirstDataCluster,aCorruptFatCluster); |
1107 |
1108 |
1108 TInt pos=0; |
1109 TInt pos=0; |
1109 r=TheFile.Open(TheFs,_L("\\CORRUPT2.TMP"),EFileRead|EFileWrite); |
1110 r=TheFile.Open(TheFs,_L("\\CORRUPT2.TMP"),EFileRead|EFileWrite); |
1110 test(r==KErrNone || r==KErrCorrupt); |
1111 test_Value(r, r == KErrNone || r==KErrCorrupt); |
1111 if (r==KErrNone) |
1112 if (r==KErrNone) |
1112 { |
1113 { |
1113 r=TheFile.Seek(ESeekStart,pos); |
1114 r=TheFile.Seek(ESeekStart,pos); |
1114 test(r==KErrNone); |
1115 test_KErrNone(r); |
1115 r=TheFile.Write(TheBuffer); |
1116 r=TheFile.Write(TheBuffer); |
1116 |
1117 |
1117 if ((gDriveCacheFlags & EFileCacheWriteOn) && (r == KErrNone)) |
1118 if ((gDriveCacheFlags & EFileCacheWriteOn) && (r == KErrNone)) |
1118 r = TheFile.Flush(); |
1119 r = TheFile.Flush(); |
1119 |
1120 |
1127 |
1128 |
1128 FatWrite(gFirstDataCluster,gEndOfChain); |
1129 FatWrite(gFirstDataCluster,gEndOfChain); |
1129 |
1130 |
1130 pos=0; |
1131 pos=0; |
1131 r=TheFile.Open(TheFs,_L("\\CORRUPT2.TMP"),EFileRead|EFileWrite); |
1132 r=TheFile.Open(TheFs,_L("\\CORRUPT2.TMP"),EFileRead|EFileWrite); |
1132 test(r==KErrNone); |
1133 test_KErrNone(r); |
1133 r=TheFile.Seek(ESeekStart,pos); |
1134 r=TheFile.Seek(ESeekStart,pos); |
1134 test(r==KErrNone); |
1135 test_KErrNone(r); |
1135 r=TheFile.Write(TheBuffer); |
1136 r=TheFile.Write(TheBuffer); |
1136 |
1137 |
1137 if ((gDriveCacheFlags & EFileCacheWriteOn) && (r == KErrNone)) |
1138 if ((gDriveCacheFlags & EFileCacheWriteOn) && (r == KErrNone)) |
1138 r = TheFile.Flush(); |
1139 r = TheFile.Flush(); |
1139 |
1140 |
1169 |
1170 |
1170 test(TheFile.Create(TheFs,_L("\\CORRUPT1.TMP"),EFileRead|EFileWrite)==KErrNone); |
1171 test(TheFile.Create(TheFs,_L("\\CORRUPT1.TMP"),EFileRead|EFileWrite)==KErrNone); |
1171 TheBuffer.SetLength(anInitialSize); |
1172 TheBuffer.SetLength(anInitialSize); |
1172 Mem::Fill(&TheBuffer[0],anInitialSize,'A'); |
1173 Mem::Fill(&TheBuffer[0],anInitialSize,'A'); |
1173 r=TheFile.Write(TheBuffer); |
1174 r=TheFile.Write(TheBuffer); |
1174 test(r==KErrNone); |
1175 test_KErrNone(r); |
1175 TheFile.Close(); |
1176 TheFile.Close(); |
1176 |
1177 |
1177 r=TheDisk.Open(TheFs,CurrentDrive()); |
1178 r=TheDisk.Open(TheFs,CurrentDrive()); |
1178 test(r==KErrNone); |
1179 test_KErrNone(r); |
1179 TPtr8 sectorBuf((TUint8*)pBuffer1->Ptr(),TheBootSector.BytesPerSector()); |
1180 TPtr8 sectorBuf((TUint8*)pBuffer1->Ptr(),TheBootSector.BytesPerSector()); |
1180 TInt pos = gRootDirStart; |
1181 TInt pos = gRootDirStart; |
1181 r=TheDisk.Read(pos,sectorBuf); |
1182 r=TheDisk.Read(pos,sectorBuf); |
1182 test(r==KErrNone); |
1183 test_KErrNone(r); |
1183 TFatDirEntry* pE=(TFatDirEntry*)pBuffer1->Ptr(); |
1184 TFatDirEntry* pE=(TFatDirEntry*)pBuffer1->Ptr(); |
1184 while (pE->IsVFatEntry()) // UNICODE entries are VFat by definition |
1185 while (pE->IsVFatEntry()) // UNICODE entries are VFat by definition |
1185 pE++; |
1186 pE++; |
1186 |
1187 |
1187 pE->SetStartCluster(aCorruptStartCluster); |
1188 pE->SetStartCluster(aCorruptStartCluster); |
1191 //-- a small hack to avoid problems with the fact that FAT[1] entry |
1192 //-- a small hack to avoid problems with the fact that FAT[1] entry |
1192 //-- is now used for marking volume as clean. TheDisk.Close() cause volume remout and |
1193 //-- is now used for marking volume as clean. TheDisk.Close() cause volume remout and |
1193 //-- the data |
1194 //-- the data |
1194 TheDisk.Close(); |
1195 TheDisk.Close(); |
1195 r=TheDisk.Open(TheFs,CurrentDrive()); |
1196 r=TheDisk.Open(TheFs,CurrentDrive()); |
1196 test(r==KErrNone); |
1197 test_KErrNone(r); |
1197 |
1198 |
1198 |
1199 |
1199 pos=0; |
1200 pos=0; |
1200 TPtr8 buffer1(pBuffer1->Des()); |
1201 TPtr8 buffer1(pBuffer1->Des()); |
1201 r=TheDisk.Read(pos,buffer1); |
1202 r=TheDisk.Read(pos,buffer1); |
1202 test(r==KErrNone); |
1203 test_KErrNone(r); |
1203 TheDisk.Close(); |
1204 TheDisk.Close(); |
1204 r=TheFs.Entry(_L("\\CORRUPT1.TMP"),TheEntry); |
1205 r=TheFs.Entry(_L("\\CORRUPT1.TMP"),TheEntry); |
1205 test(r==KErrNone || r==KErrCorrupt); |
1206 test_Value(r, r == KErrNone || r==KErrCorrupt); |
1206 TTime saveTime=TheEntry.iModified; |
1207 TTime saveTime=TheEntry.iModified; |
1207 if (r!=KErrNone) |
1208 if (r!=KErrNone) |
1208 saveTime.HomeTime(); |
1209 saveTime.HomeTime(); |
1209 |
1210 |
1210 r=TheFile.Open(TheFs,_L("\\CORRUPT1.TMP"),EFileRead|EFileWrite); |
1211 r=TheFile.Open(TheFs,_L("\\CORRUPT1.TMP"),EFileRead|EFileWrite); |
1219 } |
1220 } |
1220 TheFile.Close(); |
1221 TheFile.Close(); |
1221 } |
1222 } |
1222 |
1223 |
1223 r=TheDisk.Open(TheFs,CurrentDrive()); |
1224 r=TheDisk.Open(TheFs,CurrentDrive()); |
1224 test(r==KErrNone); |
1225 test_KErrNone(r); |
1225 pos=0; |
1226 pos=0; |
1226 TPtr8 buffer2(pBuffer2->Des()); |
1227 TPtr8 buffer2(pBuffer2->Des()); |
1227 r=TheDisk.Read(pos,buffer2); |
1228 r=TheDisk.Read(pos,buffer2); |
1228 test(r==KErrNone); |
1229 test_KErrNone(r); |
1229 |
1230 |
1230 //-- this bit is dodgy. The buffers may differ because of volume finalisation stuff |
1231 //-- this bit is dodgy. The buffers may differ because of volume finalisation stuff |
1231 //-- FAT[1] and FSInfo sectors |
1232 //-- FAT[1] and FSInfo sectors |
1232 test(buffer1==buffer2); |
1233 test(buffer1==buffer2); |
1233 TheDisk.Close(); |
1234 TheDisk.Close(); |
1234 |
1235 |
1235 r=TheFs.SetModified(_L("\\CORRUPT1.TMP"),saveTime); |
1236 r=TheFs.SetModified(_L("\\CORRUPT1.TMP"),saveTime); |
1236 test(r==KErrNone || r==KErrCorrupt); |
1237 test_Value(r, r == KErrNone || r==KErrCorrupt); |
1237 r=TheFs.Entry(_L("\\CORRUPT1.TMP"),TheEntry); |
1238 r=TheFs.Entry(_L("\\CORRUPT1.TMP"),TheEntry); |
1238 test(r==KErrNone || r==KErrCorrupt); |
1239 test_Value(r, r == KErrNone || r==KErrCorrupt); |
1239 } |
1240 } |
1240 |
1241 |
1241 static void TestBounds() |
1242 static void TestBounds() |
1242 // |
1243 // |
1243 // Test reading/writing past the end of a drive |
1244 // Test reading/writing past the end of a drive |
1245 { |
1246 { |
1246 test.Next(_L("Test read/write past boundaries")); |
1247 test.Next(_L("Test read/write past boundaries")); |
1247 test(TheFs.Volume(TheVolumeInfo,CurrentDrive())==KErrNone); |
1248 test(TheFs.Volume(TheVolumeInfo,CurrentDrive())==KErrNone); |
1248 TInt64 size=TheVolumeInfo.iSize; |
1249 TInt64 size=TheVolumeInfo.iSize; |
1249 TInt r=TheDisk.Open(TheFs,CurrentDrive()); |
1250 TInt r=TheDisk.Open(TheFs,CurrentDrive()); |
1250 test(r==KErrNone); |
1251 test_KErrNone(r); |
1251 TPtr8 buffer(pBuffer1->Des()); |
1252 TPtr8 buffer(pBuffer1->Des()); |
1252 TInt64 pos=size - 2*buffer.MaxLength(); |
1253 TInt64 pos=size - 2*buffer.MaxLength(); |
1253 TInt inc=buffer.MaxLength(); |
1254 TInt inc=buffer.MaxLength(); |
1254 FOREVER |
1255 FOREVER |
1255 { |
1256 { |
1256 TPtr8 tempbuf((TUint8*)pBuffer1->Ptr(),inc); |
1257 TPtr8 tempbuf((TUint8*)pBuffer1->Ptr(),inc); |
1257 r=TheDisk.Read(pos,tempbuf); |
1258 r=TheDisk.Read(pos,tempbuf); |
1258 test.Printf(_L("Read %08X:%08X len %d r %d\r"), I64HIGH(pos),I64LOW(pos), inc, r); |
1259 test.Printf(_L("Read %08X:%08X len %d r %d\r"), I64HIGH(pos),I64LOW(pos), inc, r); |
1259 test(r==KErrNone || r==KErrCorrupt); |
1260 test_Value(r, r == KErrNone || r==KErrCorrupt); |
1260 if (r==KErrNone) |
1261 if (r==KErrNone) |
1261 pos+=inc; |
1262 pos+=inc; |
1262 else |
1263 else |
1263 { |
1264 { |
1264 inc>>=1; |
1265 inc>>=1; |
1292 { |
1293 { |
1293 TPtr8 temp((TUint8*) (pBuffer1->Ptr()), (TInt) bsize); |
1294 TPtr8 temp((TUint8*) (pBuffer1->Ptr()), (TInt) bsize); |
1294 TInt expect = (lpos+bsize-1 < maxpos ? KErrNone : KErrCorrupt); |
1295 TInt expect = (lpos+bsize-1 < maxpos ? KErrNone : KErrCorrupt); |
1295 r=TheDisk.Read(lpos, temp); |
1296 r=TheDisk.Read(lpos, temp); |
1296 RDebug::Print(_L("Read %08X:%08X result %d \r"), I64HIGH(lpos), I64LOW(lpos), r); |
1297 RDebug::Print(_L("Read %08X:%08X result %d \r"), I64HIGH(lpos), I64LOW(lpos), r); |
1297 test(r==expect); |
1298 test_Value(r, r == expect); |
1298 } |
1299 } |
1299 } |
1300 } |
1300 } |
1301 } |
1301 |
1302 |
1302 RDebug::Print(_L("\n")); |
1303 RDebug::Print(_L("\n")); |
1388 |
1389 |
1389 RFile f; |
1390 RFile f; |
1390 TInt r; |
1391 TInt r; |
1391 |
1392 |
1392 r=f.Replace(TheFs,_L("\\GOBLIN.TMP"),EFileRead|EFileWrite); |
1393 r=f.Replace(TheFs,_L("\\GOBLIN.TMP"),EFileRead|EFileWrite); |
1393 test(r==KErrNone); |
1394 test_KErrNone(r); |
1394 f.SetSize(4*gBytesPerCluster); // 4 Clusters |
1395 f.SetSize(4*gBytesPerCluster); // 4 Clusters |
1395 f.Close(); |
1396 f.Close(); |
1396 |
1397 |
1397 r=f.Replace(TheFs,_L("\\WIZARD.TMP"),EFileRead|EFileWrite); |
1398 r=f.Replace(TheFs,_L("\\WIZARD.TMP"),EFileRead|EFileWrite); |
1398 test(r==KErrNone); |
1399 test_KErrNone(r); |
1399 f.SetSize(5*gBytesPerCluster); // 5 Clusters |
1400 f.SetSize(5*gBytesPerCluster); // 5 Clusters |
1400 f.Close(); |
1401 f.Close(); |
1401 |
1402 |
1402 r=f.Replace(TheFs,_L("\\TROLL.TMP"),EFileRead|EFileWrite); |
1403 r=f.Replace(TheFs,_L("\\TROLL.TMP"),EFileRead|EFileWrite); |
1403 test(r==KErrNone); |
1404 test_KErrNone(r); |
1404 f.SetSize(3*gBytesPerCluster); // 3 Clusters |
1405 f.SetSize(3*gBytesPerCluster); // 3 Clusters |
1405 f.Close(); |
1406 f.Close(); |
1406 |
1407 |
1407 r=f.Replace(TheFs,_L("\\GNOME.TMP"),EFileRead|EFileWrite); |
1408 r=f.Replace(TheFs,_L("\\GNOME.TMP"),EFileRead|EFileWrite); |
1408 test(r==KErrNone); |
1409 test_KErrNone(r); |
1409 f.SetSize(10*gBytesPerCluster); // 10 Clusters |
1410 f.SetSize(10*gBytesPerCluster); // 10 Clusters |
1410 f.Close(); |
1411 f.Close(); |
1411 |
1412 |
1412 r=f.Replace(TheFs,_L("\\CYCLOPS.TMP"),EFileRead|EFileWrite); |
1413 r=f.Replace(TheFs,_L("\\CYCLOPS.TMP"),EFileRead|EFileWrite); |
1413 test(r==KErrNone); |
1414 test_KErrNone(r); |
1414 f.SetSize(gBytesPerCluster); // 1 Cluster |
1415 f.SetSize(gBytesPerCluster); // 1 Cluster |
1415 f.Close(); |
1416 f.Close(); |
1416 |
1417 |
1417 r=f.Replace(TheFs,_L("\\PIXIE.TMP"),EFileRead|EFileWrite); |
1418 r=f.Replace(TheFs,_L("\\PIXIE.TMP"),EFileRead|EFileWrite); |
1418 test(r==KErrNone); |
1419 test_KErrNone(r); |
1419 f.SetSize(gBytesPerCluster); // 1 Cluster |
1420 f.SetSize(gBytesPerCluster); // 1 Cluster |
1420 f.Close(); |
1421 f.Close(); |
1421 |
1422 |
1422 r=TheDisk.Open(TheFs,CurrentDrive()); |
1423 r=TheDisk.Open(TheFs,CurrentDrive()); |
1423 test(r==KErrNone); |
1424 test_KErrNone(r); |
1424 TPtr8 sectorBuf((TUint8*)pBuffer1->Ptr(),TheBootSector.BytesPerSector()); |
1425 TPtr8 sectorBuf((TUint8*)pBuffer1->Ptr(),TheBootSector.BytesPerSector()); |
1425 TInt pos = gRootDirStart; |
1426 TInt pos = gRootDirStart; |
1426 test(TheDisk.Read(pos,sectorBuf)==KErrNone); |
1427 test(TheDisk.Read(pos,sectorBuf)==KErrNone); |
1427 TheDisk.Close(); |
1428 TheDisk.Close(); |
1428 |
1429 |
1477 test((pE->StartCluster()-cluster)==1); |
1478 test((pE->StartCluster()-cluster)==1); |
1478 name=pE->Name(); |
1479 name=pE->Name(); |
1479 test(name==_L8("PIXIE TMP")); |
1480 test(name==_L8("PIXIE TMP")); |
1480 |
1481 |
1481 r=TheFs.Delete(_L("\\GOBLIN.TMP")); |
1482 r=TheFs.Delete(_L("\\GOBLIN.TMP")); |
1482 test(r==KErrNone); |
1483 test_KErrNone(r); |
1483 r=TheFs.Delete(_L("\\WIZARD.TMP")); |
1484 r=TheFs.Delete(_L("\\WIZARD.TMP")); |
1484 test(r==KErrNone); |
1485 test_KErrNone(r); |
1485 r=TheFs.Delete(_L("\\TROLL.TMP")); |
1486 r=TheFs.Delete(_L("\\TROLL.TMP")); |
1486 test(r==KErrNone); |
1487 test_KErrNone(r); |
1487 r=TheFs.Delete(_L("\\GNOME.TMP")); |
1488 r=TheFs.Delete(_L("\\GNOME.TMP")); |
1488 test(r==KErrNone); |
1489 test_KErrNone(r); |
1489 r=TheFs.Delete(_L("\\CYCLOPS.TMP")); |
1490 r=TheFs.Delete(_L("\\CYCLOPS.TMP")); |
1490 test(r==KErrNone); |
1491 test_KErrNone(r); |
1491 r=TheFs.Delete(_L("\\PIXIE.TMP")); |
1492 r=TheFs.Delete(_L("\\PIXIE.TMP")); |
1492 test(r==KErrNone); |
1493 test_KErrNone(r); |
1493 |
1494 |
1494 FormatPack(); |
1495 FormatPack(); |
1495 |
1496 |
1496 } |
1497 } |
1497 |
1498 |
1502 // |
1503 // |
1503 { |
1504 { |
1504 test.Printf(_L("Checking cluster %02d, parent %d: \"%S\"\n"), aNewClust, aParentClust, &aName); |
1505 test.Printf(_L("Checking cluster %02d, parent %d: \"%S\"\n"), aNewClust, aParentClust, &aName); |
1505 |
1506 |
1506 TInt r=TheFs.MkDir(aName); |
1507 TInt r=TheFs.MkDir(aName); |
1507 test(r==KErrNone || r==KErrAlreadyExists); |
1508 test_Value(r, r == KErrNone || r==KErrAlreadyExists); |
1508 |
1509 |
1509 TInt pos=ClusterToByte(aNewClust); |
1510 TInt pos=ClusterToByte(aNewClust); |
1510 TPtr8 sectorBuf((TUint8*)pBuffer1->Ptr(),gBytesPerCluster); |
1511 TPtr8 sectorBuf((TUint8*)pBuffer1->Ptr(),gBytesPerCluster); |
1511 |
1512 |
1512 r=TheDisk.Open(TheFs,CurrentDrive()); |
1513 r=TheDisk.Open(TheFs,CurrentDrive()); |
1668 CreateFatEntry(_L("\\"), EFalse); |
1669 CreateFatEntry(_L("\\"), EFalse); |
1669 |
1670 |
1670 } |
1671 } |
1671 |
1672 |
1672 r = f.Create(TheFs, _L("\\123456.78"), EFileRead|EFileWrite); |
1673 r = f.Create(TheFs, _L("\\123456.78"), EFileRead|EFileWrite); |
1673 test(r==KErrDirFull); |
1674 test_Value(r, r == KErrDirFull); |
1674 f.Close(); |
1675 f.Close(); |
1675 |
1676 |
1676 |
1677 |
1677 TInt i=0; |
1678 TInt i=0; |
1678 for (i=0;i<KMaxFiles;i++) |
1679 for (i=0;i<KMaxFiles;i++) |
1679 { |
1680 { |
1680 r=TheFs.Delete(fileName[i]); |
1681 r=TheFs.Delete(fileName[i]); |
1681 test(r==KErrNone); |
1682 test_KErrNone(r); |
1682 } |
1683 } |
1683 |
1684 |
1684 r=TheFs.SetSessionPath(_L("\\")); |
1685 r=TheFs.SetSessionPath(_L("\\")); |
1685 test(r==KErrNone); |
1686 test_KErrNone(r); |
1686 |
1687 |
1687 TInt nameLength=(KMaxFiles-1)*13; // -1 for zero terminator |
1688 TInt nameLength=(KMaxFiles-1)*13; // -1 for zero terminator |
1688 CreateLongName(tempName,gSeed,nameLength*2); |
1689 CreateLongName(tempName,gSeed,nameLength*2); |
1689 r=f.Create(TheFs,tempName,0); // Needs 9 free entries - there are only 5 available |
1690 r=f.Create(TheFs,tempName,0); // Needs 9 free entries - there are only 5 available |
1690 test(r==KErrDirFull); |
1691 test_Value(r, r == KErrDirFull); |
1691 tempName.SetLength(nameLength+1); |
1692 tempName.SetLength(nameLength+1); |
1692 r=f.Create(TheFs,tempName,0); // Needs 6 free entries - there are only 5 available |
1693 r=f.Create(TheFs,tempName,0); // Needs 6 free entries - there are only 5 available |
1693 test(r==KErrDirFull); |
1694 test_Value(r, r == KErrDirFull); |
1694 tempName.SetLength(nameLength); |
1695 tempName.SetLength(nameLength); |
1695 r=f.Create(TheFs,tempName,0); // Needs 5 free entries - there are 5 available |
1696 r=f.Create(TheFs,tempName,0); // Needs 5 free entries - there are 5 available |
1696 test(r==KErrNone); |
1697 test_KErrNone(r); |
1697 f.Close(); |
1698 f.Close(); |
1698 |
1699 |
1699 #if 0 // This is the old test that assumed UNICODE builds |
1700 #if 0 // This is the old test that assumed UNICODE builds |
1700 // which created VFAT entries even for uppercase 8.3 file names |
1701 // which created VFAT entries even for uppercase 8.3 file names |
1701 TInt i=0; |
1702 TInt i=0; |
1702 for (i=0;i<KMaxFiles-2;i++) |
1703 for (i=0;i<KMaxFiles-2;i++) |
1703 { |
1704 { |
1704 r=TheFs.Delete(fileName[i]); // UNICODE build - free 6 entries (delete 3 files) |
1705 r=TheFs.Delete(fileName[i]); // UNICODE build - free 6 entries (delete 3 files) |
1705 test(r==KErrNone); |
1706 test_KErrNone(r); |
1706 } |
1707 } |
1707 |
1708 |
1708 r=TheFs.SetSessionPath(_L("\\")); |
1709 r=TheFs.SetSessionPath(_L("\\")); |
1709 test(r==KErrNone); |
1710 test_KErrNone(r); |
1710 |
1711 |
1711 TInt vFatUnitNameSize=13; |
1712 TInt vFatUnitNameSize=13; |
1712 TInt nameLength=(KMaxFiles-1)*vFatUnitNameSize-1; // |
1713 TInt nameLength=(KMaxFiles-1)*vFatUnitNameSize-1; // |
1713 CreateLongName(tempName,gSeed,nameLength*2); |
1714 CreateLongName(tempName,gSeed,nameLength*2); |
1714 r=f.Create(TheFs,tempName,0); // Needs 9 free entries |
1715 r=f.Create(TheFs,tempName,0); // Needs 9 free entries |
1715 test(r==KErrDirFull); |
1716 test_Value(r, r == KErrDirFull); |
1716 |
1717 |
1717 nameLength=(KMaxFiles)*vFatUnitNameSize; |
1718 nameLength=(KMaxFiles)*vFatUnitNameSize; |
1718 tempName.SetLength(nameLength+1); |
1719 tempName.SetLength(nameLength+1); |
1719 r=f.Create(TheFs,tempName,0); // Needs 7 free entries |
1720 r=f.Create(TheFs,tempName,0); // Needs 7 free entries |
1720 test(r==KErrDirFull); |
1721 test_Value(r, r == KErrDirFull); |
1721 tempName.SetLength(nameLength); |
1722 tempName.SetLength(nameLength); |
1722 r=f.Create(TheFs,tempName,0); // Needs 6 free entries |
1723 r=f.Create(TheFs,tempName,0); // Needs 6 free entries |
1723 test(r==KErrNone); |
1724 test_KErrNone(r); |
1724 f.Close(); |
1725 f.Close(); |
1725 #endif |
1726 #endif |
1726 |
1727 |
1727 TheFs.Delete(tempName); |
1728 TheFs.Delete(tempName); |
1728 tempName.SetLength(nameLength-7); |
1729 tempName.SetLength(nameLength-7); |
1729 r=f.Create(TheFs,tempName,0); |
1730 r=f.Create(TheFs,tempName,0); |
1730 test(r==KErrNone); |
1731 test_KErrNone(r); |
1731 f.Close(); |
1732 f.Close(); |
1732 |
1733 |
1733 r=f.Create(TheFs,_L("ASDF"),0); |
1734 r=f.Create(TheFs,_L("ASDF"),0); |
1734 test(r==KErrDirFull); |
1735 test_Value(r, r == KErrDirFull); |
1735 |
1736 |
1736 TheFs.Delete(tempName); |
1737 TheFs.Delete(tempName); |
1737 tempName.SetLength(nameLength-15); |
1738 tempName.SetLength(nameLength-15); |
1738 r=f.Create(TheFs,tempName,0); |
1739 r=f.Create(TheFs,tempName,0); |
1739 test(r==KErrNone); |
1740 test_KErrNone(r); |
1740 f.Close(); |
1741 f.Close(); |
1741 |
1742 |
1742 tempName=_L("testname"); |
1743 tempName=_L("testname"); |
1743 r=f.Create(TheFs,tempName,0); |
1744 r=f.Create(TheFs,tempName,0); |
1744 test(r==KErrDirFull); |
1745 test_Value(r, r == KErrDirFull); |
1745 tempName.UpperCase(); |
1746 tempName.UpperCase(); |
1746 r=f.Create(TheFs,tempName,0); |
1747 r=f.Create(TheFs,tempName,0); |
1747 test(r==KErrNone); |
1748 test_KErrNone(r); |
1748 f.Close(); |
1749 f.Close(); |
1749 |
1750 |
1750 |
1751 |
1751 r=TheFs.SetSessionPath(gSessionPath); |
1752 r=TheFs.SetSessionPath(gSessionPath); |
1752 test(r==KErrNone); |
1753 test_KErrNone(r); |
1753 } |
1754 } |
1754 |
1755 |
1755 static void TestVolumeSize() |
1756 static void TestVolumeSize() |
1756 // |
1757 // |
1757 // Test the volume size is zero when empty |
1758 // Test the volume size is zero when empty |
1760 test.Next(_L("Test the volume size")); |
1761 test.Next(_L("Test the volume size")); |
1761 FormatPack(); |
1762 FormatPack(); |
1762 |
1763 |
1763 TVolumeInfo volInfo; |
1764 TVolumeInfo volInfo; |
1764 TInt r=TheFs.Volume(volInfo); |
1765 TInt r=TheFs.Volume(volInfo); |
1765 test(r==KErrNone); |
1766 test_KErrNone(r); |
1766 TInt64 calcsize = MAKE_TINT64(0, gClusterCount)*gBytesPerCluster; |
1767 TInt64 calcsize = MAKE_TINT64(0, gClusterCount)*gBytesPerCluster; |
1767 if (volInfo.iSize > calcsize) |
1768 if (volInfo.iSize > calcsize) |
1768 { |
1769 { |
1769 test.Printf(_L("volInfo.iSize = %ld\n"), volInfo.iSize); |
1770 test.Printf(_L("volInfo.iSize = %ld\n"), volInfo.iSize); |
1770 test.Printf(_L("volInfo.iFree = %ld\n"), volInfo.iFree); |
1771 test.Printf(_L("volInfo.iFree = %ld\n"), volInfo.iFree); |
1792 for (i=0;i<KMaxFiles;i++) |
1793 for (i=0;i<KMaxFiles;i++) |
1793 { |
1794 { |
1794 fileName=_L("\\File"); |
1795 fileName=_L("\\File"); |
1795 fileName.AppendNum(i); |
1796 fileName.AppendNum(i); |
1796 r=f[i].Create(TheFs,fileName,0); |
1797 r=f[i].Create(TheFs,fileName,0); |
1797 test(r==KErrNone); |
1798 test_KErrNone(r); |
1798 } |
1799 } |
1799 |
1800 |
1800 TInt maxTotalSize=1048576; |
1801 TInt maxTotalSize=1048576; |
1801 TInt maxFileSize=maxTotalSize/KMaxFiles; |
1802 TInt maxFileSize=maxTotalSize/KMaxFiles; |
1802 TInt maxIterations=20; |
1803 TInt maxIterations=20; |
1805 { |
1806 { |
1806 for (i=0;i<KMaxFiles;i++) |
1807 for (i=0;i<KMaxFiles;i++) |
1807 { |
1808 { |
1808 TInt randSize=Math::Rand(gSeed)%maxFileSize; |
1809 TInt randSize=Math::Rand(gSeed)%maxFileSize; |
1809 r=f[i].SetSize(randSize); |
1810 r=f[i].SetSize(randSize); |
1810 test(r==KErrNone); |
1811 test_KErrNone(r); |
1811 } |
1812 } |
1812 test.Printf(_L("Countdown .. %d \r"),maxIterations); |
1813 test.Printf(_L("Countdown .. %d \r"),maxIterations); |
1813 } |
1814 } |
1814 |
1815 |
1815 test.Printf(_L("\n")); |
1816 test.Printf(_L("\n")); |
1818 |
1819 |
1819 for (i=0;i<KMaxFiles;i++) |
1820 for (i=0;i<KMaxFiles;i++) |
1820 { |
1821 { |
1821 TInt size=0; |
1822 TInt size=0; |
1822 r=f[i].Size(size); |
1823 r=f[i].Size(size); |
1823 test(r==KErrNone); |
1824 test_KErrNone(r); |
1824 totalSize+=((size+gBytesPerCluster-1)/gBytesPerCluster)*gBytesPerCluster; |
1825 totalSize+=((size+gBytesPerCluster-1)/gBytesPerCluster)*gBytesPerCluster; |
1825 } |
1826 } |
1826 |
1827 |
1827 r=TheFs.Volume(volInfo); |
1828 r=TheFs.Volume(volInfo); |
1828 test(r==KErrNone); |
1829 test_KErrNone(r); |
1829 if (gDiskType == EFat32) |
1830 if (gDiskType == EFat32) |
1830 volInfo.iSize -= gBytesPerCluster; // root dir is part of the 'size' |
1831 volInfo.iSize -= gBytesPerCluster; // root dir is part of the 'size' |
1831 if (volInfo.iSize-volInfo.iFree!=totalSize) |
1832 if (volInfo.iSize-volInfo.iFree!=totalSize) |
1832 { |
1833 { |
1833 test.Printf(_L("volInfo.iSize = %ld\n"), volInfo.iSize); |
1834 test.Printf(_L("volInfo.iSize = %ld\n"), volInfo.iSize); |
1844 for (i=0;i<KMaxFiles;i++) |
1845 for (i=0;i<KMaxFiles;i++) |
1845 { |
1846 { |
1846 fileName=_L("\\File"); |
1847 fileName=_L("\\File"); |
1847 fileName.AppendNum(i); |
1848 fileName.AppendNum(i); |
1848 r=TheFs.Delete(fileName); |
1849 r=TheFs.Delete(fileName); |
1849 test(r==KErrNone); |
1850 test_KErrNone(r); |
1850 } |
1851 } |
1851 |
1852 |
1852 r=TheFs.Volume(volInfo); |
1853 r=TheFs.Volume(volInfo); |
1853 if (gDiskType == EFat32) |
1854 if (gDiskType == EFat32) |
1854 volInfo.iSize -= gBytesPerCluster; // root dir is part of the 'size' |
1855 volInfo.iSize -= gBytesPerCluster; // root dir is part of the 'size' |
1855 test(r==KErrNone); |
1856 test_KErrNone(r); |
1856 test(volInfo.iSize-volInfo.iFree==0); |
1857 test(volInfo.iSize-volInfo.iFree==0); |
1857 |
1858 |
1858 MakeDir(gSessionPath); |
1859 MakeDir(gSessionPath); |
1859 |
1860 |
1860 TInt entries=(gBytesPerCluster/KSizeOfFatDirEntry)*5-2; |
1861 TInt entries=(gBytesPerCluster/KSizeOfFatDirEntry)*5-2; |
1868 CreateFatEntry(gSessionPath, EFalse); |
1869 CreateFatEntry(gSessionPath, EFalse); |
1869 } |
1870 } |
1870 |
1871 |
1871 |
1872 |
1872 r=TheFs.Volume(volInfo); |
1873 r=TheFs.Volume(volInfo); |
1873 test(r==KErrNone); |
1874 test_KErrNone(r); |
1874 if (gDiskType == EFat32) |
1875 if (gDiskType == EFat32) |
1875 volInfo.iSize -= gBytesPerCluster; // root dir is part of the 'size' |
1876 volInfo.iSize -= gBytesPerCluster; // root dir is part of the 'size' |
1876 test.Printf(_L("volInfo.iSize = %ld\n"), volInfo.iSize); |
1877 test.Printf(_L("volInfo.iSize = %ld\n"), volInfo.iSize); |
1877 test.Printf(_L("volInfo.iFree = %ld\n"), volInfo.iFree); |
1878 test.Printf(_L("volInfo.iFree = %ld\n"), volInfo.iFree); |
1878 if (volInfo.iSize-volInfo.iFree!=clusters*gBytesPerCluster) |
1879 if (volInfo.iSize-volInfo.iFree!=clusters*gBytesPerCluster) |
1884 |
1885 |
1885 //-- create 1 FAT dir. entry |
1886 //-- create 1 FAT dir. entry |
1886 CreateFatEntry(gSessionPath, EFalse); |
1887 CreateFatEntry(gSessionPath, EFalse); |
1887 |
1888 |
1888 r=TheFs.Volume(volInfo); |
1889 r=TheFs.Volume(volInfo); |
1889 test(r==KErrNone); |
1890 test_KErrNone(r); |
1890 if (gDiskType == EFat32) |
1891 if (gDiskType == EFat32) |
1891 volInfo.iSize -= gBytesPerCluster; // root dir is part of the 'size' |
1892 volInfo.iSize -= gBytesPerCluster; // root dir is part of the 'size' |
1892 test.Printf(_L("volInfo.iSize = %ld\n"), volInfo.iSize); |
1893 test.Printf(_L("volInfo.iSize = %ld\n"), volInfo.iSize); |
1893 test.Printf(_L("volInfo.iFree = %ld\n"), volInfo.iFree); |
1894 test.Printf(_L("volInfo.iFree = %ld\n"), volInfo.iFree); |
1894 if (volInfo.iSize-volInfo.iFree!=(clusters+1)*gBytesPerCluster) |
1895 if (volInfo.iSize-volInfo.iFree!=(clusters+1)*gBytesPerCluster) |
1898 } |
1899 } |
1899 test(volInfo.iSize-volInfo.iFree==(clusters+1)*gBytesPerCluster); |
1900 test(volInfo.iSize-volInfo.iFree==(clusters+1)*gBytesPerCluster); |
1900 |
1901 |
1901 CFileMan* fMan=CFileMan::NewL(TheFs); |
1902 CFileMan* fMan=CFileMan::NewL(TheFs); |
1902 r=fMan->RmDir(gSessionPath); |
1903 r=fMan->RmDir(gSessionPath); |
1903 test(r==KErrNone); |
1904 test_KErrNone(r); |
1904 delete fMan; |
1905 delete fMan; |
1905 r=TheFs.Volume(volInfo); |
1906 r=TheFs.Volume(volInfo); |
1906 test(r==KErrNone); |
1907 test_KErrNone(r); |
1907 if (gDiskType == EFat32) |
1908 if (gDiskType == EFat32) |
1908 volInfo.iSize -= gBytesPerCluster; // root dir is part of the 'size' |
1909 volInfo.iSize -= gBytesPerCluster; // root dir is part of the 'size' |
1909 if (volInfo.iSize-volInfo.iFree!=0) |
1910 if (volInfo.iSize-volInfo.iFree!=0) |
1910 { |
1911 { |
1911 DumpFat(); |
1912 DumpFat(); |
1933 buffer.SetLength(KDirEntrySize); |
1934 buffer.SetLength(KDirEntrySize); |
1934 buffer.FillZ(); |
1935 buffer.FillZ(); |
1935 buffer.Replace(0,11,_L8("TEST1 ")); |
1936 buffer.Replace(0,11,_L8("TEST1 ")); |
1936 |
1937 |
1937 TInt r=TheDisk.Open(TheFs,CurrentDrive()); |
1938 TInt r=TheDisk.Open(TheFs,CurrentDrive()); |
1938 test(r==KErrNone); |
1939 test_KErrNone(r); |
1939 r=TheDisk.Write(pos,buffer); |
1940 r=TheDisk.Write(pos,buffer); |
1940 test(r==KErrNone); |
1941 test_KErrNone(r); |
1941 TheDisk.Close(); |
1942 TheDisk.Close(); |
1942 |
1943 |
1943 r=TheDir.Open(TheFs,_L("\\"),KEntryAttMaskSupported); |
1944 r=TheDir.Open(TheFs,_L("\\"),KEntryAttMaskSupported); |
1944 test(r==KErrNone); |
1945 test_KErrNone(r); |
1945 r=TheDir.Read(TheEntry); |
1946 r=TheDir.Read(TheEntry); |
1946 test(r==KErrNone); |
1947 test_KErrNone(r); |
1947 test(TheEntry.iName==_L("TEST1")); |
1948 test(TheEntry.iName==_L("TEST1")); |
1948 r=TheDir.Read(TheEntry); |
1949 r=TheDir.Read(TheEntry); |
1949 test(r==KErrEof); |
1950 test_Value(r, r == KErrEof); |
1950 TheDir.Close(); |
1951 TheDir.Close(); |
1951 |
1952 |
1952 r=TheFs.SetSessionPath(_L("\\")); |
1953 r=TheFs.SetSessionPath(_L("\\")); |
1953 test(r==KErrNone); |
1954 test_KErrNone(r); |
1954 TEntry e; |
1955 TEntry e; |
1955 r=TheFs.Entry(_L("TEST1"),e); |
1956 r=TheFs.Entry(_L("TEST1"),e); |
1956 if(e.iName!=_L("TEST1")) |
1957 if(e.iName!=_L("TEST1")) |
1957 { |
1958 { |
1958 test.Printf(_L("e.iName = %S\n"),&e.iName); |
1959 test.Printf(_L("e.iName = %S\n"),&e.iName); |
1983 HBufC8 *infop = HBufC8::NewL(seclen); |
1984 HBufC8 *infop = HBufC8::NewL(seclen); |
1984 TPtr8 info((TUint8*)bootp, seclen); |
1985 TPtr8 info((TUint8*)bootp, seclen); |
1985 TInt r=TheDisk.Open(TheFs,CurrentDrive()); |
1986 TInt r=TheDisk.Open(TheFs,CurrentDrive()); |
1986 if (r != KErrNone) |
1987 if (r != KErrNone) |
1987 test.Printf(_L("Error %d opening on %C"), r, (TUint)gDriveToTest); |
1988 test.Printf(_L("Error %d opening on %C"), r, (TUint)gDriveToTest); |
1988 test(r==KErrNone); |
1989 test_KErrNone(r); |
1989 r=TheDisk.Read(0, boot); |
1990 r=TheDisk.Read(0, boot); |
1990 test(r==KErrNone); |
1991 test_KErrNone(r); |
1991 TUint32 val = GetValue(boot, 510, 2); |
1992 TUint32 val = GetValue(boot, 510, 2); |
1992 RDebug::Print(_L("BPB magic number = 0x%X\n"), val); |
1993 RDebug::Print(_L("BPB magic number = 0x%X\n"), val); |
1993 test(aTestOnly || val == 0xAA55); |
1994 test(aTestOnly || val == 0xAA55); |
1994 switch (boot[0]) |
1995 switch (boot[0]) |
1995 { |
1996 { |
2111 Mem::Fill(&TheBuffer[0],2048,'X'); |
2112 Mem::Fill(&TheBuffer[0],2048,'X'); |
2112 |
2113 |
2113 for(i=0; i<=20; i++) |
2114 for(i=0; i<=20; i++) |
2114 { |
2115 { |
2115 r = TheFile.Write(TheBuffer); |
2116 r = TheFile.Write(TheBuffer); |
2116 test(r==KErrNone); |
2117 test_KErrNone(r); |
2117 } |
2118 } |
2118 |
2119 |
2119 TheFile.Close(); |
2120 TheFile.Close(); |
2120 |
2121 |
2121 for (i=8; i <=15; i++) |
2122 for (i=8; i <=15; i++) |
2468 testVal.iNumberOfFats, |
2469 testVal.iNumberOfFats, |
2469 testVal.iMaxDiskSectors, |
2470 testVal.iMaxDiskSectors, |
2470 testVal.iSectorsPerCluster, |
2471 testVal.iSectorsPerCluster, |
2471 testVal.iRootDirEntries); |
2472 testVal.iRootDirEntries); |
2472 TInt r = fatAlignment.AdjustFirstDataSectorAlignment(testVal.iBlockSize); |
2473 TInt r = fatAlignment.AdjustFirstDataSectorAlignment(testVal.iBlockSize); |
2473 test (r == KErrNone); |
2474 test_KErrNone(r); |
2474 fatAlignment.Display(); |
2475 fatAlignment.Display(); |
2475 } |
2476 } |
2476 |
2477 |
2477 const TInt64 KOneMByte = 1024*1024; |
2478 const TInt64 KOneMByte = 1024*1024; |
2478 const TInt64 KOneGByte = 1024*KOneMByte; |
2479 const TInt64 KOneGByte = 1024*KOneMByte; |
2581 |
2582 |
2582 TInt r; |
2583 TInt r; |
2583 |
2584 |
2584 TVolumeInfo volInfo; |
2585 TVolumeInfo volInfo; |
2585 r=TheFs.Volume(volInfo); |
2586 r=TheFs.Volume(volInfo); |
2586 test(r==KErrNone); |
2587 test_KErrNone(r); |
2587 |
2588 |
2588 TInt64 spaceToUse = volInfo.iFree - gBytesPerCluster; // whole disk except 1 cluster |
2589 TInt64 spaceToUse = volInfo.iFree - gBytesPerCluster; // whole disk except 1 cluster |
2589 |
2590 |
2590 test.Printf(_L("spaceToUse %ld gClusterCount %d gBytesPerCluster %d\n"), spaceToUse, gClusterCount, gBytesPerCluster); |
2591 test.Printf(_L("spaceToUse %ld gClusterCount %d gBytesPerCluster %d\n"), spaceToUse, gClusterCount, gBytesPerCluster); |
2591 test.Printf(_L("Before fill, volInfo.iSize %ld volInfo.iFree %ld\n"), volInfo.iSize, volInfo.iFree); |
2592 test.Printf(_L("Before fill, volInfo.iSize %ld volInfo.iFree %ld\n"), volInfo.iSize, volInfo.iFree); |
2595 TInt tempfiles = 0; |
2596 TInt tempfiles = 0; |
2596 while (spaceToUse > K1GigaByte) |
2597 while (spaceToUse > K1GigaByte) |
2597 { |
2598 { |
2598 TFileName tempName; |
2599 TFileName tempName; |
2599 r=f.Temp(TheFs,_L("\\"),tempName,EFileRead|EFileWrite); |
2600 r=f.Temp(TheFs,_L("\\"),tempName,EFileRead|EFileWrite); |
2600 test(r==KErrNone); |
2601 test_KErrNone(r); |
2601 r=f.SetSize(K1GigaByte); |
2602 r=f.SetSize(K1GigaByte); |
2602 test(r==KErrNone); |
2603 test_KErrNone(r); |
2603 f.Close(); |
2604 f.Close(); |
2604 spaceToUse -= K1GigaByte; |
2605 spaceToUse -= K1GigaByte; |
2605 tempfiles++; |
2606 tempfiles++; |
2606 } |
2607 } |
2607 |
2608 |
2608 r=f.Replace(TheFs,_L("\\USESPACE.TMP"),EFileRead|EFileWrite); |
2609 r=f.Replace(TheFs,_L("\\USESPACE.TMP"),EFileRead|EFileWrite); |
2609 test(r==KErrNone); |
2610 test_KErrNone(r); |
2610 r=f.SetSize((TInt)spaceToUse); |
2611 r=f.SetSize((TInt)spaceToUse); |
2611 test(r==KErrNone); |
2612 test_KErrNone(r); |
2612 f.Close(); |
2613 f.Close(); |
2613 |
2614 |
2614 r=TheFs.Volume(volInfo); |
2615 r=TheFs.Volume(volInfo); |
2615 test(r==KErrNone); |
2616 test_KErrNone(r); |
2616 test.Printf(_L("After fill, volInfo.iSize %ld volInfo.iFree %ld\n"), volInfo.iSize, volInfo.iFree); |
2617 test.Printf(_L("After fill, volInfo.iSize %ld volInfo.iFree %ld\n"), volInfo.iSize, volInfo.iFree); |
2617 |
2618 |
2618 test(volInfo.iFree==gBytesPerCluster); // check we have 1 cluster free |
2619 test(volInfo.iFree==gBytesPerCluster); // check we have 1 cluster free |
2619 |
2620 |
2620 r=f.Replace(TheFs,_L("\\FILE.TMP"),EFileRead|EFileWrite); |
2621 r=f.Replace(TheFs,_L("\\FILE.TMP"),EFileRead|EFileWrite); |
2621 test(r==KErrNone); |
2622 test_KErrNone(r); |
2622 r=f.SetSize(2*gBytesPerCluster); // 2 clusters (will fail since there's not space) |
2623 r=f.SetSize(2*gBytesPerCluster); // 2 clusters (will fail since there's not space) |
2623 test(r==KErrDiskFull); |
2624 test_Value(r, r == KErrDiskFull); |
2624 f.Close(); |
2625 f.Close(); |
2625 |
2626 |
2626 r=TheFs.Volume(volInfo); |
2627 r=TheFs.Volume(volInfo); |
2627 test(r==KErrNone); |
2628 test_KErrNone(r); |
2628 test(volInfo.iFree==gBytesPerCluster); // check we still have 1 cluster free |
2629 test(volInfo.iFree==gBytesPerCluster); // check we still have 1 cluster free |
2629 |
2630 |
2630 r=f.Replace(TheFs,_L("\\USESPACE.TMP"),EFileRead|EFileWrite); // truncate file to 0 |
2631 r=f.Replace(TheFs,_L("\\USESPACE.TMP"),EFileRead|EFileWrite); // truncate file to 0 |
2631 test(r==KErrNone); |
2632 test_KErrNone(r); |
2632 f.Close(); |
2633 f.Close(); |
2633 |
2634 |
2634 r=TheFs.Volume(volInfo); |
2635 r=TheFs.Volume(volInfo); |
2635 test(r==KErrNone); |
2636 test_KErrNone(r); |
2636 test(volInfo.iFree==(spaceToUse+gBytesPerCluster)); // check we've freed up the space from USESPACE plus one cluster |
2637 test(volInfo.iFree==(spaceToUse+gBytesPerCluster)); // check we've freed up the space from USESPACE plus one cluster |
2637 |
2638 |
2638 |
2639 |
2639 test(TheBootSector.IsValid()); //-- TheBootSector is read after formatting |
2640 test(TheBootSector.IsValid()); //-- TheBootSector is read after formatting |
2640 TInt64 rootDirpos = gRootDirStart; |
2641 TInt64 rootDirpos = gRootDirStart; |
2641 |
2642 |
2642 |
2643 |
2643 //-- read 1 sector of the root dir. |
2644 //-- read 1 sector of the root dir. |
2644 r = MediaRawRead(TheFs, CurrentDrive(), rootDirpos, TheBootSector.BytesPerSector(), TheBuffer); |
2645 r = MediaRawRead(TheFs, CurrentDrive(), rootDirpos, TheBootSector.BytesPerSector(), TheBuffer); |
2645 test(r == KErrNone); |
2646 test_KErrNone(r); |
2646 |
2647 |
2647 const TFatDirEntry* pE=(TFatDirEntry*)TheBuffer.Ptr(); |
2648 const TFatDirEntry* pE=(TFatDirEntry*)TheBuffer.Ptr(); |
2648 while (tempfiles-- > 0) |
2649 while (tempfiles-- > 0) |
2649 { |
2650 { |
2650 while (pE->IsVFatEntry()) |
2651 while (pE->IsVFatEntry()) |
2687 |
2688 |
2688 |
2689 |
2689 |
2690 |
2690 TInt drvNum; |
2691 TInt drvNum; |
2691 TInt r=TheFs.CharToDrive(gDriveToTest,drvNum); |
2692 TInt r=TheFs.CharToDrive(gDriveToTest,drvNum); |
2692 test(r==KErrNone); |
2693 test_KErrNone(r); |
2693 |
2694 |
2694 if (!Is_Fat(TheFs,drvNum)) |
2695 if (!Is_Fat(TheFs,drvNum)) |
2695 { |
2696 { |
2696 test.Printf(_L("CallTestsL: Skipped: test requires FAT filesystem\n")); |
2697 test.Printf(_L("CallTestsL: Skipped: test requires FAT filesystem\n")); |
2697 return; |
2698 return; |
2702 PrintDrvInfo(TheFs, drvNum); |
2703 PrintDrvInfo(TheFs, drvNum); |
2703 |
2704 |
2704 // check this is not the internal ram drive |
2705 // check this is not the internal ram drive |
2705 TVolumeInfo v; |
2706 TVolumeInfo v; |
2706 r=TheFs.Volume(v, drvNum); |
2707 r=TheFs.Volume(v, drvNum); |
2707 test(r==KErrNone); |
2708 test_KErrNone(r); |
2708 TBool isRamDrive = v.iDrive.iMediaAtt&KMediaAttVariableSize; |
2709 TBool isRamDrive = v.iDrive.iMediaAtt&KMediaAttVariableSize; |
2709 |
2710 |
2710 gSessionPath[0] = (TText)gDriveToTest; |
2711 gSessionPath[0] = (TText)gDriveToTest; |
2711 // verify that the drive is large enough for proper testing |
2712 // verify that the drive is large enough for proper testing |
2712 if (v.iSize<512*1024) |
2713 if (v.iSize<512*1024) |