|
0
|
1 |
// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
2 |
// All rights reserved.
|
|
|
3 |
// This component and the accompanying materials are made available
|
|
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
|
|
5 |
// which accompanies this distribution, and is available
|
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
|
7 |
//
|
|
|
8 |
// Initial Contributors:
|
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
|
10 |
//
|
|
|
11 |
// Contributors:
|
|
|
12 |
//
|
|
|
13 |
// Description:
|
|
|
14 |
// f32\sfat\ram_fat_table.cpp
|
|
|
15 |
// FAT16 File Allocation Table classes implementation for the RAM media
|
|
|
16 |
//
|
|
|
17 |
//
|
|
|
18 |
|
|
|
19 |
/**
|
|
|
20 |
@file
|
|
|
21 |
@internalTechnology
|
|
|
22 |
*/
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
|
26 |
#include "sl_std.h"
|
|
|
27 |
#include "sl_fatcache.h"
|
|
|
28 |
#include "fat_table.h"
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
//#######################################################################################################################################
|
|
|
32 |
//# CRamFatTable class implementation
|
|
|
33 |
//#######################################################################################################################################
|
|
|
34 |
|
|
|
35 |
/**
|
|
|
36 |
Constructor, the RamFatTable allows disk compression by redirecting the FAT
|
|
|
37 |
|
|
|
38 |
@param aOwner Owning mount.
|
|
|
39 |
*/
|
|
|
40 |
CRamFatTable::CRamFatTable(CFatMountCB& aOwner)
|
|
|
41 |
:CFatTable(aOwner)
|
|
|
42 |
{
|
|
|
43 |
iFatTablePos=aOwner.FirstFatSector()<<aOwner.SectorSizeLog2();
|
|
|
44 |
iIndirectionTablePos=iFatTablePos+aOwner.FatSizeInBytes();
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
/** factory method */
|
|
|
48 |
CRamFatTable* CRamFatTable::NewL(CFatMountCB& aOwner)
|
|
|
49 |
{
|
|
|
50 |
__PRINT1(_L("CRamFatTable::NewL() drv:%d"),aOwner.DriveNumber());
|
|
|
51 |
|
|
|
52 |
CRamFatTable* pSelf = new (ELeave) CRamFatTable(aOwner);
|
|
|
53 |
|
|
|
54 |
CleanupStack::PushL(pSelf);
|
|
|
55 |
pSelf->InitializeL();
|
|
|
56 |
CleanupStack::Pop();
|
|
|
57 |
|
|
|
58 |
return pSelf;
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
void CRamFatTable::InitializeL()
|
|
|
62 |
{
|
|
|
63 |
CFatTable::InitializeL();
|
|
|
64 |
|
|
|
65 |
ASSERT(iMediaAtt & KMediaAttVariableSize);
|
|
|
66 |
|
|
|
67 |
iFatTablePos=iOwner->FirstFatSector()<<iOwner->SectorSizeLog2();
|
|
|
68 |
iIndirectionTablePos=iFatTablePos+iOwner->FatSizeInBytes();
|
|
|
69 |
|
|
|
70 |
//-- set RAM disk base
|
|
|
71 |
TLocalDriveCapsV2 caps;
|
|
|
72 |
TPckg<TLocalDriveCapsV2> capsPckg(caps);
|
|
|
73 |
User::LeaveIfError(iOwner->LocalDrive()->Caps(capsPckg));
|
|
|
74 |
|
|
|
75 |
iRamDiskBase = caps.iBaseAddress;
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
/**
|
|
|
79 |
Remount the FAT table. This method call means that the media parameters wasn't changed,
|
|
|
80 |
otherwise CFatMountCB::DoReMountL() would reject it.
|
|
|
81 |
Just do some re-initialisation work.
|
|
|
82 |
*/
|
|
|
83 |
void CRamFatTable::ReMountL()
|
|
|
84 |
{
|
|
|
85 |
//-- re-initialise, actually
|
|
|
86 |
ASSERT(iMediaAtt & KMediaAttVariableSize);
|
|
|
87 |
ASSERT(FatType() == EFat16);
|
|
|
88 |
|
|
|
89 |
iFatTablePos=iOwner->FirstFatSector()<<iOwner->SectorSizeLog2();
|
|
|
90 |
iIndirectionTablePos=iFatTablePos+iOwner->FatSizeInBytes();
|
|
|
91 |
|
|
|
92 |
//-- set RAM disk base
|
|
|
93 |
TLocalDriveCapsV2 caps;
|
|
|
94 |
TPckg<TLocalDriveCapsV2> capsPckg(caps);
|
|
|
95 |
User::LeaveIfError(iOwner->LocalDrive()->Caps(capsPckg));
|
|
|
96 |
|
|
|
97 |
iRamDiskBase = caps.iBaseAddress;
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
|
|
|
101 |
/**
|
|
|
102 |
Return the start address of the Ram Drive
|
|
|
103 |
|
|
|
104 |
@return start address of the Ram Drive
|
|
|
105 |
*/
|
|
|
106 |
TUint8 *CRamFatTable::RamDiskBase() const
|
|
|
107 |
{
|
|
|
108 |
return(iRamDiskBase);
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
|
|
|
112 |
/**
|
|
|
113 |
Allocate a new cluster number
|
|
|
114 |
|
|
|
115 |
@return New cluster number
|
|
|
116 |
*/
|
|
|
117 |
TInt CRamFatTable::AllocateClusterNumber()
|
|
|
118 |
{
|
|
|
119 |
return(iOwner->MaxClusterNumber()-NumberOfFreeClusters());
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
/**
|
|
|
123 |
Write a value to the FAT (indirection table)
|
|
|
124 |
|
|
|
125 |
@param aFatIndex Cluster to write to
|
|
|
126 |
@param aValue value to write to Fat
|
|
|
127 |
@leave
|
|
|
128 |
*/
|
|
|
129 |
void CRamFatTable::WriteL(TUint32 aFatIndex, TUint32 aValue)
|
|
|
130 |
{
|
|
|
131 |
//__PRINT(_L("CRamFatTable::WriteL"));
|
|
|
132 |
|
|
|
133 |
__ASSERT_ALWAYS(aFatIndex>=2 && (aValue>=2 || aValue==0) && aValue<=0xFFFF,User::Leave(KErrCorrupt));
|
|
|
134 |
TUint32 indirectCluster=aFatIndex;
|
|
|
135 |
TUint32 indirectClusterNewVal=0;
|
|
|
136 |
ReadIndirectionTable(indirectCluster);
|
|
|
137 |
// If value in indirection table!=0 we assume we have already written to the indirection table
|
|
|
138 |
// So just update the FAT table
|
|
|
139 |
if (indirectCluster!=0 && aValue!=0)
|
|
|
140 |
{
|
|
|
141 |
WriteFatTable(aFatIndex,aValue);
|
|
|
142 |
return;
|
|
|
143 |
}
|
|
|
144 |
// If value in indirection table is 0, we haven't written to it yet, though the memory has
|
|
|
145 |
// already been allocated by the EnlargeL() function
|
|
|
146 |
if (indirectCluster==0 && aValue!=0) // Assumes memory has already been allocated
|
|
|
147 |
indirectClusterNewVal=AllocateClusterNumber();
|
|
|
148 |
// Write aValue into aFaxIndex and indirectClusterNewVal into the corresponding position
|
|
|
149 |
// in the indirection table
|
|
|
150 |
WriteFatTable(aFatIndex,aValue,indirectClusterNewVal);
|
|
|
151 |
}
|
|
|
152 |
|
|
|
153 |
/**
|
|
|
154 |
Read the value of a cluster in the Fat
|
|
|
155 |
|
|
|
156 |
@param aFatIndex A cluster to read
|
|
|
157 |
@leave
|
|
|
158 |
@return The cluster value read
|
|
|
159 |
*/
|
|
|
160 |
|
|
|
161 |
TUint32 CRamFatTable::ReadL(TUint32 aFatIndex) const
|
|
|
162 |
{
|
|
|
163 |
__ASSERT_ALWAYS(aFatIndex>=KFatFirstSearchCluster,User::Leave(KErrCorrupt));
|
|
|
164 |
TUint clusterVal=*(TUint16*)(RamDiskBase()+PosInBytes(aFatIndex)+iFatTablePos);
|
|
|
165 |
return(clusterVal);
|
|
|
166 |
}
|
|
|
167 |
|
|
|
168 |
/**
|
|
|
169 |
Write a value to the FAT and indirection table
|
|
|
170 |
|
|
|
171 |
@param aFatIndex Cluster number to write to
|
|
|
172 |
@param aFatValue Cluster value for Fat
|
|
|
173 |
@param anIndirectionValue Value for indirection table
|
|
|
174 |
*/
|
|
|
175 |
void CRamFatTable::WriteFatTable(TInt aFatIndex,TInt aFatValue,TInt anIndirectionValue)
|
|
|
176 |
{
|
|
|
177 |
TUint8* pos=RamDiskBase()+PosInBytes(aFatIndex);
|
|
|
178 |
*(TUint16*)(pos+iFatTablePos)=(TUint16)aFatValue;
|
|
|
179 |
*(TUint16*)(pos+iIndirectionTablePos)=(TUint16)anIndirectionValue;
|
|
|
180 |
}
|
|
|
181 |
|
|
|
182 |
/**
|
|
|
183 |
Write to just the fat table
|
|
|
184 |
|
|
|
185 |
@param aFatIndex Cluster number to write to
|
|
|
186 |
@param aFatValue Cluster value for Fat
|
|
|
187 |
*/
|
|
|
188 |
void CRamFatTable::WriteFatTable(TInt aFatIndex,TInt aFatValue)
|
|
|
189 |
{
|
|
|
190 |
*(TUint16*)(RamDiskBase()+PosInBytes(aFatIndex)+iFatTablePos)=(TUint16)aFatValue;
|
|
|
191 |
}
|
|
|
192 |
|
|
|
193 |
/**
|
|
|
194 |
Write to just the fat table
|
|
|
195 |
|
|
|
196 |
@param aFatIndex Cluster number to write to
|
|
|
197 |
@param aFatValue Value for indirection table
|
|
|
198 |
*/
|
|
|
199 |
void CRamFatTable::WriteIndirectionTable(TInt aFatIndex,TInt aFatValue)
|
|
|
200 |
{
|
|
|
201 |
*(TUint16*)(RamDiskBase()+PosInBytes(aFatIndex)+iIndirectionTablePos)=(TUint16)aFatValue;
|
|
|
202 |
}
|
|
|
203 |
|
|
|
204 |
/**
|
|
|
205 |
Find the real location of aCluster
|
|
|
206 |
|
|
|
207 |
@param aCluster Cluster to read, contians cluster value upon return
|
|
|
208 |
*/
|
|
|
209 |
void CRamFatTable::ReadIndirectionTable(TUint32& aCluster) const
|
|
|
210 |
{
|
|
|
211 |
aCluster=*(TUint16*)(RamDiskBase()+PosInBytes(aCluster)+iIndirectionTablePos);
|
|
|
212 |
}
|
|
|
213 |
|
|
|
214 |
/**
|
|
|
215 |
Copy memory in RAM drive area, unlocking required
|
|
|
216 |
|
|
|
217 |
@param aTrg Pointer to destination location
|
|
|
218 |
@param aSrc Pointer to source location
|
|
|
219 |
@param aLength Length of data to copy
|
|
|
220 |
@return Pointer to end of data copied
|
|
|
221 |
*/
|
|
|
222 |
TUint8* CRamFatTable::MemCopy(TAny* aTrg,const TAny* aSrc,TInt aLength)
|
|
|
223 |
{
|
|
|
224 |
TUint8* p=Mem::Copy(aTrg,aSrc,aLength);
|
|
|
225 |
return(p);
|
|
|
226 |
}
|
|
|
227 |
|
|
|
228 |
/**
|
|
|
229 |
Copy memory with filling the source buffer with zeroes. Target and source buffers can overlap.
|
|
|
230 |
Used on RAMDrive srinking in order to wipe data from the file that is being deleted.
|
|
|
231 |
|
|
|
232 |
@param aTrg pointer to the target address
|
|
|
233 |
@param aSrc pointer to the destination address
|
|
|
234 |
@param aLength how many bytes to copy
|
|
|
235 |
@return A pointer to a location aLength bytes beyond aTrg (i.e. the location aTrg+aLength).
|
|
|
236 |
*/
|
|
|
237 |
TUint8* CRamFatTable::MemCopyFillZ(TAny* aTrg, TAny* aSrc,TInt aLength)
|
|
|
238 |
{
|
|
|
239 |
//-- just copy src to the trg, the memory areas can overlap.
|
|
|
240 |
TUint8* p=Mem::Copy(aTrg, aSrc, aLength);
|
|
|
241 |
|
|
|
242 |
//-- now zero-fill the source memory area taking into account possible overlap.
|
|
|
243 |
TUint8* pSrc = static_cast<TUint8*>(aSrc);
|
|
|
244 |
TUint8* pTrg = static_cast<TUint8*>(aTrg);
|
|
|
245 |
|
|
|
246 |
TUint8* pZFill = NULL; //-- pointer to the beginning of zerofilled area
|
|
|
247 |
TInt zFillLen = 0; //-- a number of bytes to zero-fill
|
|
|
248 |
|
|
|
249 |
if(aTrg < aSrc)
|
|
|
250 |
{
|
|
|
251 |
if(pTrg+aLength < pSrc)
|
|
|
252 |
{//-- target and source areas do not overlap
|
|
|
253 |
pZFill = pSrc;
|
|
|
254 |
zFillLen = aLength;
|
|
|
255 |
}
|
|
|
256 |
else
|
|
|
257 |
{//-- target and source areas overlap, try not to corrupt the target area
|
|
|
258 |
zFillLen = pSrc-pTrg;
|
|
|
259 |
pZFill = pTrg+aLength;
|
|
|
260 |
}
|
|
|
261 |
}
|
|
|
262 |
else
|
|
|
263 |
{
|
|
|
264 |
if(pSrc+aLength < pTrg)
|
|
|
265 |
{//-- target and source areas do not overlap
|
|
|
266 |
pZFill = pSrc;
|
|
|
267 |
zFillLen = aLength;
|
|
|
268 |
}
|
|
|
269 |
else
|
|
|
270 |
{//-- target and source areas overlap, try not to corrupt the target area
|
|
|
271 |
zFillLen = pSrc+aLength-pTrg;
|
|
|
272 |
pZFill = pSrc;
|
|
|
273 |
}
|
|
|
274 |
}
|
|
|
275 |
|
|
|
276 |
Mem::FillZ(pZFill, zFillLen);
|
|
|
277 |
|
|
|
278 |
return(p);
|
|
|
279 |
}
|
|
|
280 |
|
|
|
281 |
/**
|
|
|
282 |
Zero fill RAM area corresponding to the cluster number aCluster
|
|
|
283 |
@param aCluster a cluster number to be zero-filled
|
|
|
284 |
*/
|
|
|
285 |
void CRamFatTable::ZeroFillCluster(TInt aCluster)
|
|
|
286 |
{
|
|
|
287 |
TLinAddr clusterPos= I64LOW(DataPositionInBytes(aCluster));
|
|
|
288 |
Mem::FillZ(iRamDiskBase+clusterPos, 1<< iOwner->ClusterSizeLog2());
|
|
|
289 |
}
|
|
|
290 |
|
|
|
291 |
|
|
|
292 |
/**
|
|
|
293 |
Return the location of a Cluster in the data section of the media
|
|
|
294 |
|
|
|
295 |
@param aCluster to find location of
|
|
|
296 |
@return Byte offset of the cluster data
|
|
|
297 |
*/
|
|
|
298 |
TInt64 CRamFatTable::DataPositionInBytes(TUint32 aCluster) const
|
|
|
299 |
{
|
|
|
300 |
//__PRINT(_L("CRamFatTable::DataPositionInBytes"));
|
|
|
301 |
ReadIndirectionTable(aCluster);
|
|
|
302 |
return(aCluster<<iOwner->ClusterSizeLog2());
|
|
|
303 |
}
|
|
|
304 |
|
|
|
305 |
/**
|
|
|
306 |
Allocate and mark as EOF a single cluster as close as possible to aNearestCluster,
|
|
|
307 |
calls base class implementation but must Enlarge the RAM drive first. Allocated cluster RAM area will be zero-filled.
|
|
|
308 |
|
|
|
309 |
@param aNearestCluster Cluster the new cluster should be nearest to
|
|
|
310 |
@leave System wide error codes
|
|
|
311 |
@return The cluster number allocated
|
|
|
312 |
*/
|
|
|
313 |
TUint32 CRamFatTable::AllocateSingleClusterL(TUint32 aNearestCluster)
|
|
|
314 |
{
|
|
|
315 |
__PRINT(_L("CRamFatTable::AllocateSingleClusterL"));
|
|
|
316 |
iOwner->EnlargeL(1<<iOwner->ClusterSizeLog2()); // First enlarge the RAM drive
|
|
|
317 |
TInt fileAllocated=CFatTable::AllocateSingleClusterL(aNearestCluster); // Now update the free cluster and fat/fit
|
|
|
318 |
ZeroFillCluster(fileAllocated); //-- zero-fill allocated cluster
|
|
|
319 |
return(fileAllocated);
|
|
|
320 |
}
|
|
|
321 |
|
|
|
322 |
|
|
|
323 |
/**
|
|
|
324 |
Extend a file or directory cluster chain, enlarging RAM drive first. Allocated clusters are zero-filled.
|
|
|
325 |
Leaves if there are no free clusters (the disk is full).
|
|
|
326 |
Note that method now doesn't call CFatTable::ExtendClusterListL() from its base class, be careful making changes there.
|
|
|
327 |
|
|
|
328 |
@param aNumber number of clusters to allocate
|
|
|
329 |
@param aCluster starting cluster number / ending cluster number after
|
|
|
330 |
@leave KErrDiskFull + system wide error codes
|
|
|
331 |
*/
|
|
|
332 |
void CRamFatTable::ExtendClusterListL(TUint32 aNumber,TInt& aCluster)
|
|
|
333 |
{
|
|
|
334 |
__PRINT(_L("CRamFatTable::ExtendClusterListL"));
|
|
|
335 |
__ASSERT_DEBUG(aNumber>0,Fault(EFatBadParameter));
|
|
|
336 |
|
|
|
337 |
iOwner->EnlargeL(aNumber<<iOwner->ClusterSizeLog2());
|
|
|
338 |
|
|
|
339 |
while(aNumber && GetNextClusterL(aCluster))
|
|
|
340 |
aNumber--;
|
|
|
341 |
|
|
|
342 |
if(!aNumber)
|
|
|
343 |
return;
|
|
|
344 |
|
|
|
345 |
if (NumberOfFreeClusters() < aNumber)
|
|
|
346 |
{
|
|
|
347 |
__PRINT(_L("CRamFatTable::ExtendClusterListL - leaving KErrDirFull"));
|
|
|
348 |
User::Leave(KErrDiskFull);
|
|
|
349 |
}
|
|
|
350 |
|
|
|
351 |
while (aNumber--)
|
|
|
352 |
{
|
|
|
353 |
const TInt freeCluster=FindClosestFreeClusterL(aCluster);
|
|
|
354 |
|
|
|
355 |
WriteFatEntryEofL(freeCluster); // Must write EOF for FindClosestFreeCluster to work again
|
|
|
356 |
DecrementFreeClusterCount(1);
|
|
|
357 |
WriteL(aCluster,freeCluster);
|
|
|
358 |
aCluster=freeCluster;
|
|
|
359 |
ZeroFillCluster(freeCluster); //-- zero fill just allocated cluster (RAM area)
|
|
|
360 |
}
|
|
|
361 |
|
|
|
362 |
SetFreeClusterHint(aCluster);
|
|
|
363 |
|
|
|
364 |
}
|
|
|
365 |
|
|
|
366 |
/**
|
|
|
367 |
Mark a chain of clusters as free in the FAT. Shrinks the RAM drive once the
|
|
|
368 |
clusters are free
|
|
|
369 |
|
|
|
370 |
@param aCluster Start cluster of cluster chain to free
|
|
|
371 |
@leave System wide error codes
|
|
|
372 |
*/
|
|
|
373 |
void CRamFatTable::FreeClusterListL(TUint32 aCluster)
|
|
|
374 |
{
|
|
|
375 |
__PRINT1(_L("CRamFatTable::FreeClusterListL aCluster=%d"),aCluster);
|
|
|
376 |
if (aCluster==0)
|
|
|
377 |
return; // File has no cluster allocated
|
|
|
378 |
|
|
|
379 |
const TInt clusterShift=iOwner->ClusterSizeLog2();
|
|
|
380 |
TInt startCluster=aCluster;
|
|
|
381 |
TInt endCluster=0;
|
|
|
382 |
TInt totalFreed=0;
|
|
|
383 |
TLinAddr srcEnd=0;
|
|
|
384 |
|
|
|
385 |
while(endCluster!=EOF_16Bit)
|
|
|
386 |
{
|
|
|
387 |
TInt num=CountContiguousClustersL(startCluster,endCluster,KMaxTInt);
|
|
|
388 |
if (GetNextClusterL(endCluster)==EFalse || endCluster==0)
|
|
|
389 |
endCluster=EOF_16Bit; // endCluster==0 -> file contained FAT loop
|
|
|
390 |
|
|
|
391 |
// Real position in bytes of the start cluster in the data area
|
|
|
392 |
TLinAddr startClusterPos= I64LOW(DataPositionInBytes(startCluster));
|
|
|
393 |
// Sliding value when more than one block is freed
|
|
|
394 |
TLinAddr trg=startClusterPos-(totalFreed<<clusterShift);
|
|
|
395 |
__PRINT1(_L("trg=0x%x"),trg);
|
|
|
396 |
|
|
|
397 |
// Beginning of data area to move
|
|
|
398 |
TLinAddr srcStart=startClusterPos+(num<<clusterShift);
|
|
|
399 |
__PRINT1(_L("srcStart=0x%x"),srcStart);
|
|
|
400 |
// Position of next part of cluster chain or position of end of ram drive
|
|
|
401 |
if (endCluster==EOF_16Bit) // Last cluster is the end of the chain
|
|
|
402 |
{
|
|
|
403 |
|
|
|
404 |
|
|
|
405 |
// Fixed to use the genuine RAM drive size rather than the number
|
|
|
406 |
// of free clusters - though they *should* be the same
|
|
|
407 |
// It avoids the problem of iFreeClusters getting out of sync with
|
|
|
408 |
// the RAM drive size but doesn't solve the issue of why it can happen...
|
|
|
409 |
|
|
|
410 |
srcEnd=I64LOW(iOwner->Size());
|
|
|
411 |
__PRINT1(_L("srcEnd=0x%x"),srcEnd);
|
|
|
412 |
}
|
|
|
413 |
else // Just move up to the next part of the chain
|
|
|
414 |
srcEnd=I64LOW(DataPositionInBytes(endCluster));
|
|
|
415 |
|
|
|
416 |
//-- Copy (srcEnd-srcStart) bytes from iRamDiskBase+srcStart onto iRamDiskBase+trg
|
|
|
417 |
//-- zero-filling free space to avoid leaving something important there
|
|
|
418 |
ASSERT(srcEnd >= srcStart);
|
|
|
419 |
if(srcEnd-srcStart > 0)
|
|
|
420 |
{
|
|
|
421 |
MemCopyFillZ(iRamDiskBase+trg,iRamDiskBase+srcStart,srcEnd-srcStart);
|
|
|
422 |
}
|
|
|
423 |
else
|
|
|
424 |
{//-- we are freeing the cluster chain at the end of the RAMdrive; Nothing to copy to the drive space that has become free,
|
|
|
425 |
//-- but nevertheless zero fill this space.
|
|
|
426 |
Mem::FillZ(iRamDiskBase+trg, num<<clusterShift);
|
|
|
427 |
}
|
|
|
428 |
|
|
|
429 |
totalFreed+=num;
|
|
|
430 |
startCluster=endCluster;
|
|
|
431 |
UpdateIndirectionTable(srcStart>>clusterShift,srcEnd>>clusterShift,totalFreed);
|
|
|
432 |
}
|
|
|
433 |
TInt bytesFreed=totalFreed<<clusterShift;
|
|
|
434 |
|
|
|
435 |
// First free the cluster list
|
|
|
436 |
CFatTable::FreeClusterListL(aCluster);
|
|
|
437 |
// Now reduce the size of the RAM drive
|
|
|
438 |
iOwner->ReduceSizeL(srcEnd-bytesFreed,bytesFreed);
|
|
|
439 |
}
|
|
|
440 |
|
|
|
441 |
/**
|
|
|
442 |
Shift any clusters between aStart and anEnd backwards by aClusterShift
|
|
|
443 |
|
|
|
444 |
@param aStart Start of shift region
|
|
|
445 |
@param anEnd End of shift region
|
|
|
446 |
@param aClusterShift amount to shift cluster by
|
|
|
447 |
*/
|
|
|
448 |
void CRamFatTable::UpdateIndirectionTable(TUint32 aStart,TUint32 anEnd,TInt aClusterShift)
|
|
|
449 |
{
|
|
|
450 |
__PRINT(_L("CRamFatTable::UpdateIndirectionTable"));
|
|
|
451 |
#if defined(__WINS__)
|
|
|
452 |
TUint32 count=iOwner->MaxClusterNumber();
|
|
|
453 |
while (count--)
|
|
|
454 |
{
|
|
|
455 |
TUint32 cluster=count;
|
|
|
456 |
ReadIndirectionTable(cluster);
|
|
|
457 |
if (cluster>=aStart && cluster<anEnd)
|
|
|
458 |
WriteIndirectionTable(count,cluster-aClusterShift);
|
|
|
459 |
}
|
|
|
460 |
#else
|
|
|
461 |
TUint16* table=(TUint16*)(RamDiskBase()+iIndirectionTablePos);
|
|
|
462 |
TUint16* entry=table+iOwner->MaxClusterNumber();
|
|
|
463 |
while (entry>table)
|
|
|
464 |
{
|
|
|
465 |
TUint32 cluster=*--entry;
|
|
|
466 |
if (cluster<aStart)
|
|
|
467 |
continue;
|
|
|
468 |
if (cluster<anEnd)
|
|
|
469 |
*entry=TUint16(cluster-aClusterShift);
|
|
|
470 |
}
|
|
|
471 |
#endif
|
|
|
472 |
}
|
|
|
473 |
|
|
|
474 |
|
|
|
475 |
|
|
|
476 |
|
|
|
477 |
|
|
|
478 |
|