341 |
341 |
342 /** |
342 /** |
343 Zero fill RAM area corresponding to the cluster number aCluster |
343 Zero fill RAM area corresponding to the cluster number aCluster |
344 @param aCluster a cluster number to be zero-filled |
344 @param aCluster a cluster number to be zero-filled |
345 */ |
345 */ |
346 void CRamFatTable::ZeroFillClusterL(TInt aCluster) |
346 void CRamFatTable::ZeroFillCluster(TInt aCluster) |
347 { |
347 { |
348 TLinAddr clusterPos= I64LOW(DataPositionInBytesL(aCluster)); |
348 TLinAddr clusterPos= I64LOW(DataPositionInBytes(aCluster)); |
349 Mem::FillZ(iRamDiskBase+clusterPos, 1<< iOwner->ClusterSizeLog2()); |
349 Mem::FillZ(iRamDiskBase+clusterPos, 1<< iOwner->ClusterSizeLog2()); |
350 } |
350 } |
351 |
351 |
352 |
352 |
353 /** |
353 /** |
354 Return the location of a Cluster in the data section of the media |
354 Return the location of a Cluster in the data section of the media |
355 |
355 |
356 @param aCluster to find location of |
356 @param aCluster to find location of |
357 @return Byte offset of the cluster data |
357 @return Byte offset of the cluster data |
358 */ |
358 */ |
359 TInt64 CRamFatTable::DataPositionInBytesL(TUint32 aCluster) const |
359 TInt64 CRamFatTable::DataPositionInBytes(TUint32 aCluster) const |
360 { |
360 { |
361 //__PRINT(_L("CRamFatTable::DataPositionInBytes")); |
361 //__PRINT(_L("CRamFatTable::DataPositionInBytes")); |
362 if(!ClusterNumberValid(aCluster)) |
|
363 { |
|
364 __ASSERT_DEBUG(0, Fault(EFatTable_InvalidIndex)); |
|
365 User::Leave(KErrCorrupt); |
|
366 } |
|
367 |
|
368 ReadIndirectionTable(aCluster); |
362 ReadIndirectionTable(aCluster); |
369 return(aCluster<<iOwner->ClusterSizeLog2()); |
363 return(aCluster<<iOwner->ClusterSizeLog2()); |
370 } |
364 } |
371 |
365 |
372 //----------------------------------------------------------------------------- |
366 //----------------------------------------------------------------------------- |
421 TUint32 CRamFatTable::AllocateSingleClusterL(TUint32 aNearestCluster) |
415 TUint32 CRamFatTable::AllocateSingleClusterL(TUint32 aNearestCluster) |
422 { |
416 { |
423 __PRINT(_L("CRamFatTable::AllocateSingleClusterL")); |
417 __PRINT(_L("CRamFatTable::AllocateSingleClusterL")); |
424 iOwner->EnlargeL(1<<iOwner->ClusterSizeLog2()); // First enlarge the RAM drive |
418 iOwner->EnlargeL(1<<iOwner->ClusterSizeLog2()); // First enlarge the RAM drive |
425 TInt fileAllocated=CFatTable::AllocateSingleClusterL(aNearestCluster); // Now update the free cluster and fat/fit |
419 TInt fileAllocated=CFatTable::AllocateSingleClusterL(aNearestCluster); // Now update the free cluster and fat/fit |
426 ZeroFillClusterL(fileAllocated); //-- zero-fill allocated cluster |
420 ZeroFillCluster(fileAllocated); //-- zero-fill allocated cluster |
427 return(fileAllocated); |
421 return(fileAllocated); |
428 } |
422 } |
429 |
423 |
430 |
424 |
431 /** |
425 /** |
462 |
456 |
463 WriteFatEntryEofL(freeCluster); // Must write EOF for FindClosestFreeCluster to work again |
457 WriteFatEntryEofL(freeCluster); // Must write EOF for FindClosestFreeCluster to work again |
464 DecrementFreeClusterCount(1); |
458 DecrementFreeClusterCount(1); |
465 WriteL(aCluster,freeCluster); |
459 WriteL(aCluster,freeCluster); |
466 aCluster=freeCluster; |
460 aCluster=freeCluster; |
467 ZeroFillClusterL(freeCluster); //-- zero fill just allocated cluster (RAM area) |
461 ZeroFillCluster(freeCluster); //-- zero fill just allocated cluster (RAM area) |
468 } |
462 } |
469 |
463 |
470 SetFreeClusterHint(aCluster); |
464 SetFreeClusterHint(aCluster); |
471 |
465 |
472 } |
466 } |
497 TInt num=CountContiguousClustersL(startCluster,endCluster,KMaxTInt); |
491 TInt num=CountContiguousClustersL(startCluster,endCluster,KMaxTInt); |
498 if (GetNextClusterL(endCluster)==EFalse || endCluster==0) |
492 if (GetNextClusterL(endCluster)==EFalse || endCluster==0) |
499 endCluster=EOF_32Bit; // endCluster==0 -> file contained FAT loop |
493 endCluster=EOF_32Bit; // endCluster==0 -> file contained FAT loop |
500 |
494 |
501 // Real position in bytes of the start cluster in the data area |
495 // Real position in bytes of the start cluster in the data area |
502 TLinAddr startClusterPos=I64LOW(DataPositionInBytesL(startCluster)); |
496 TLinAddr startClusterPos=I64LOW(DataPositionInBytes(startCluster)); |
503 // Sliding value when more than one block is freed |
497 // Sliding value when more than one block is freed |
504 TLinAddr trg=startClusterPos-(totalFreed<<clusterShift); |
498 TLinAddr trg=startClusterPos-(totalFreed<<clusterShift); |
505 __PRINT1(_L("trg=0x%x"),trg); |
499 __PRINT1(_L("trg=0x%x"),trg); |
506 |
500 |
507 // Beginning of data area to move |
501 // Beginning of data area to move |
519 |
513 |
520 srcEnd=I64LOW(iOwner->Size()); |
514 srcEnd=I64LOW(iOwner->Size()); |
521 __PRINT1(_L("srcEnd=0x%x"),srcEnd); |
515 __PRINT1(_L("srcEnd=0x%x"),srcEnd); |
522 } |
516 } |
523 else // Just move up to the next part of the chain |
517 else // Just move up to the next part of the chain |
524 srcEnd=I64LOW(DataPositionInBytesL(endCluster)); |
518 srcEnd=I64LOW(DataPositionInBytes(endCluster)); |
525 |
519 |
526 //-- Copy (srcEnd-srcStart) bytes from iRamDiskBase+srcStart onto iRamDiskBase+trg |
520 //-- Copy (srcEnd-srcStart) bytes from iRamDiskBase+srcStart onto iRamDiskBase+trg |
527 //-- zero-filling free space to avoid leaving something important there |
521 //-- zero-filling free space to avoid leaving something important there |
528 ASSERT(srcEnd >= srcStart); |
522 ASSERT(srcEnd >= srcStart); |
529 if(srcEnd-srcStart > 0) |
523 if(srcEnd-srcStart > 0) |
549 TInt num=CountContiguousClustersL(startCluster,endCluster,KMaxTInt); |
543 TInt num=CountContiguousClustersL(startCluster,endCluster,KMaxTInt); |
550 if (GetNextClusterL(endCluster)==EFalse || endCluster==0) |
544 if (GetNextClusterL(endCluster)==EFalse || endCluster==0) |
551 endCluster=EOF_16Bit; // endCluster==0 -> file contained FAT loop |
545 endCluster=EOF_16Bit; // endCluster==0 -> file contained FAT loop |
552 |
546 |
553 // Real position in bytes of the start cluster in the data area |
547 // Real position in bytes of the start cluster in the data area |
554 TLinAddr startClusterPos=I64LOW(DataPositionInBytesL(startCluster)); |
548 TLinAddr startClusterPos=I64LOW(DataPositionInBytes(startCluster)); |
555 // Sliding value when more than one block is freed |
549 // Sliding value when more than one block is freed |
556 TLinAddr trg=startClusterPos-(totalFreed<<clusterShift); |
550 TLinAddr trg=startClusterPos-(totalFreed<<clusterShift); |
557 __PRINT1(_L("trg=0x%x"),trg); |
551 __PRINT1(_L("trg=0x%x"),trg); |
558 |
552 |
559 // Beginning of data area to move |
553 // Beginning of data area to move |
571 |
565 |
572 srcEnd=I64LOW(iOwner->Size()); |
566 srcEnd=I64LOW(iOwner->Size()); |
573 __PRINT1(_L("srcEnd=0x%x"),srcEnd); |
567 __PRINT1(_L("srcEnd=0x%x"),srcEnd); |
574 } |
568 } |
575 else // Just move up to the next part of the chain |
569 else // Just move up to the next part of the chain |
576 srcEnd=I64LOW(DataPositionInBytesL(endCluster)); |
570 srcEnd=I64LOW(DataPositionInBytes(endCluster)); |
577 |
571 |
578 //-- Copy (srcEnd-srcStart) bytes from iRamDiskBase+srcStart onto iRamDiskBase+trg |
572 //-- Copy (srcEnd-srcStart) bytes from iRamDiskBase+srcStart onto iRamDiskBase+trg |
579 //-- zero-filling free space to avoid leaving something important there |
573 //-- zero-filling free space to avoid leaving something important there |
580 ASSERT(srcEnd >= srcStart); |
574 ASSERT(srcEnd >= srcStart); |
581 if(srcEnd-srcStart > 0) |
575 if(srcEnd-srcStart > 0) |
637 TUint32 CRamFatTable::CountContiguousClustersL(TUint32 aStartCluster, TUint32& aEndCluster, TUint32 aMaxCount) const |
631 TUint32 CRamFatTable::CountContiguousClustersL(TUint32 aStartCluster, TUint32& aEndCluster, TUint32 aMaxCount) const |
638 { |
632 { |
639 __PRINT2(_L("CRamFatTable::CountContiguousClustersL() start:%d, max:%d"),aStartCluster, aMaxCount); |
633 __PRINT2(_L("CRamFatTable::CountContiguousClustersL() start:%d, max:%d"),aStartCluster, aMaxCount); |
640 TUint32 clusterListLen=1; |
634 TUint32 clusterListLen=1; |
641 TUint32 endCluster=aStartCluster; |
635 TUint32 endCluster=aStartCluster; |
642 TInt64 endClusterPos=DataPositionInBytesL(endCluster); |
636 TInt64 endClusterPos=DataPositionInBytes(endCluster); |
643 while (clusterListLen<aMaxCount) |
637 while (clusterListLen<aMaxCount) |
644 { |
638 { |
645 TInt oldCluster=endCluster; |
639 TInt oldCluster=endCluster; |
646 TInt64 oldClusterPos=endClusterPos; |
640 TInt64 oldClusterPos=endClusterPos; |
647 if (GetNextClusterL(endCluster)==EFalse || (endClusterPos=DataPositionInBytesL(endCluster))!=(oldClusterPos+(1<<iOwner->ClusterSizeLog2()))) |
641 if (GetNextClusterL(endCluster)==EFalse || (endClusterPos=DataPositionInBytes(endCluster))!=(oldClusterPos+(1<<iOwner->ClusterSizeLog2()))) |
648 { |
642 { |
649 endCluster=oldCluster; |
643 endCluster=oldCluster; |
650 break; |
644 break; |
651 } |
645 } |
652 clusterListLen++; |
646 clusterListLen++; |