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