author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 18 Jan 2010 21:31:10 +0200 | |
changeset 8 | 538db54a451d |
parent 6 | 0173bcd7697c |
child 22 | 2f92ad2dc5db |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1998-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\sfat32\sl_scan32.cpp |
|
15 |
// ScanDrive code, specific for EFAT32.FSY |
|
16 |
// |
|
17 |
// |
|
18 |
||
19 |
/** |
|
20 |
@file |
|
21 |
@internalTechnology |
|
22 |
*/ |
|
23 |
||
24 |
#include "sl_std.h" |
|
25 |
#include "sl_scandrv.h" |
|
26 |
||
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
27 |
const TInt KMaxScanDepth = 20; ///< Maximum scan depth of to avoid stack over flow |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
28 |
const TInt KClusterListGranularity = 8; ///< Granularity of cluster list used for storage of clusters when KMaxScanDepth is reached |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
29 |
|
0 | 30 |
|
31 |
||
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
32 |
/** |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
33 |
CScanDrive factory method |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
34 |
@param aMount the owning mount |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
35 |
*/ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
36 |
CScanDrive* CScanDrive::NewL(CFatMountCB* aMount) |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
37 |
{ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
38 |
if(!aMount) |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
39 |
{ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
40 |
ASSERT(0); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
41 |
User::Leave(KErrArgument); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
42 |
} |
0 | 43 |
|
44 |
CScanDrive* self=new (ELeave) CScanDrive(); |
|
45 |
CleanupStack::PushL(self); |
|
46 |
self->ConstructL(aMount); |
|
47 |
CleanupStack::Pop(); |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
48 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
49 |
return self; |
0 | 50 |
} |
51 |
||
52 |
||
53 |
CScanDrive::~CScanDrive() |
|
54 |
{ |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
55 |
for(TUint i=0; i<KMaxArrayDepth && iClusterListArray[i]!=NULL; ++i) |
0 | 56 |
{ |
57 |
iClusterListArray[i]->Close(); |
|
58 |
delete iClusterListArray[i]; |
|
59 |
} |
|
60 |
||
61 |
iMediaFatBits.Close(); |
|
62 |
iScanFatBits.Close(); |
|
63 |
||
64 |
} |
|
65 |
||
66 |
/** |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
67 |
Creates the structure of this class. |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
68 |
@param aMount The owning mount |
0 | 69 |
*/ |
70 |
void CScanDrive::ConstructL(CFatMountCB* aMount) |
|
71 |
{ |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
72 |
ASSERT(aMount); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
73 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
74 |
//--- setting up |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
75 |
iMount=aMount; |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
76 |
iGenericError = ENoErrors; |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
77 |
iDirError = ENoDirError; |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
78 |
iMaxClusters = iMount->UsableClusters()+KFatFirstSearchCluster; //-- UsableClusters() doesn't count first 2 unused clusers |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
79 |
//------------------------------ |
0 | 80 |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
81 |
//-- create bit vectors that will represent FAT on media and reconstructed by ScanDrive. Each bit in the vector represents 1 FAT cluster. |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
82 |
const TUint32 KClustersNum = MaxClusters(); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
83 |
|
0 | 84 |
CleanupClosePushL(iMediaFatBits); |
85 |
CleanupClosePushL(iScanFatBits); |
|
86 |
||
87 |
iMediaFatBits.CreateL(KClustersNum); |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
88 |
iScanFatBits.CreateL(KClustersNum); |
0 | 89 |
|
90 |
CleanupStack::Pop(&iScanFatBits); |
|
91 |
CleanupStack::Pop(&iMediaFatBits); |
|
92 |
} |
|
93 |
||
94 |
//---------------------------------------------------------------------------------------------------- |
|
95 |
/** |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
96 |
FAT type-agnostic parser. Reads whole FAT and sets up a bit vector. |
0 | 97 |
for FAT12/16 it's OK, because the FAT12/16 is fully cached. |
98 |
*/ |
|
99 |
void CScanDrive::DoParseFatL() |
|
100 |
{ |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
101 |
const TInt KMaxClusters = MaxClusters(); |
0 | 102 |
|
103 |
iMediaFatBits.Fill(0); |
|
104 |
||
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
105 |
__PRINT1(_L("CScanDrive::DoParseFatL(), clusters:%d"), KMaxClusters); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
106 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
107 |
for(TInt i=KFatFirstSearchCluster; i<KMaxClusters; ++i) |
0 | 108 |
{ |
109 |
const TUint32 nFatEntry = ReadFatL(i); |
|
110 |
||
111 |
//-- each '1' bit represents a used cluster |
|
112 |
if(nFatEntry != KSpareCluster) |
|
113 |
iMediaFatBits.SetBit(i); |
|
114 |
} |
|
115 |
} |
|
116 |
||
117 |
//---------------------------------------------------------------------------------------------------- |
|
118 |
/** |
|
119 |
Parse FAT32 buffer. |
|
120 |
@param aBuf buffer, containing FAT32 entries (current portion of FAT) |
|
121 |
@param aCurrFatEntry current FAT entry processed |
|
122 |
*/ |
|
123 |
void CScanDrive::DoParseFat32Buf(const TPtrC8& aBuf, TUint32& aCurrFatEntry) |
|
124 |
{ |
|
125 |
ASSERT((aBuf.Size() & (sizeof(TFat32Entry)-1)) == 0); |
|
126 |
||
127 |
const TInt KNumEntries = aBuf.Size() >> KFat32EntrySzLog2; |
|
128 |
const TFat32Entry* const pFatEntry = (const TFat32Entry*)(aBuf.Ptr()); |
|
129 |
||
130 |
for(TInt i=0; i<KNumEntries; ++i) |
|
131 |
{ |
|
132 |
if(aCurrFatEntry >= KFatFirstSearchCluster) |
|
133 |
{ |
|
134 |
if((pFatEntry[i] & KFat32EntryMask) != KSpareCluster) |
|
135 |
{//-- found a non-free FAT32 entry |
|
136 |
iMediaFatBits.SetBit(aCurrFatEntry); |
|
137 |
} |
|
138 |
} |
|
139 |
++aCurrFatEntry; |
|
140 |
} |
|
141 |
} |
|
142 |
||
143 |
//---------------------------------------------------------------------------------------------------- |
|
144 |
/** |
|
145 |
A specialised method to read and parse FAT32 using a larger buffer. |
|
146 |
1. Larger buffer gives better read performance |
|
147 |
2. using dedicated buffer doesn't trash FAT32 LRU cache. |
|
148 |
*/ |
|
149 |
void CScanDrive::DoParseFat32L() |
|
150 |
{ |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
151 |
const TInt KNumClusters = MaxClusters(); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
152 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
153 |
__PRINT1(_L("CScanDrive::DoParseFat32L(), clusters:%d"), KNumClusters); |
0 | 154 |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
155 |
ASSERT(iMount->FatType() == EFat32); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
156 |
|
0 | 157 |
const TUint32 KFat1StartPos = iMount->StartOfFatInBytes(); |
158 |
const TUint32 KFatSize = KNumClusters * sizeof(TFat32Entry); //-- usable size of one FAT. |
|
159 |
||
160 |
const TUint32 KFatBufSz = 32*K1KiloByte; //-- buffer size for FAT reading. 32K seems to be optimal size |
|
161 |
||
162 |
iMediaFatBits.Fill(0); |
|
163 |
||
164 |
RBuf8 buf; |
|
165 |
CleanupClosePushL(buf); |
|
166 |
||
167 |
//-- allocate memory for FAT parse buffer |
|
168 |
buf.CreateMaxL(KFatBufSz); |
|
169 |
||
170 |
//-- read FAT directly from the media into the large buffer and parse it |
|
171 |
TUint32 rem = KFatSize; |
|
172 |
TUint32 mediaPos = KFat1StartPos; |
|
173 |
TUint32 currFatEntry = 0; |
|
174 |
||
175 |
while(rem) |
|
176 |
{ |
|
177 |
const TUint32 bytesToRead=Min(rem, KFatBufSz); |
|
178 |
TPtrC8 ptrData(buf.Ptr(), bytesToRead); |
|
179 |
||
180 |
//-- read portion of the FAT into buffer |
|
181 |
User::LeaveIfError(iMount->LocalDrive()->Read(mediaPos, bytesToRead, buf)); |
|
182 |
||
183 |
//-- parse the buffer and populate bit vector |
|
184 |
DoParseFat32Buf(ptrData, currFatEntry); |
|
185 |
||
186 |
mediaPos += bytesToRead; |
|
187 |
rem -= bytesToRead; |
|
188 |
} |
|
189 |
||
190 |
buf.Close(); |
|
191 |
CleanupStack::PopAndDestroy(&buf); |
|
192 |
} |
|
193 |
||
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
194 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
195 |
|
0 | 196 |
//---------------------------------------------------------------------------------------------------- |
197 |
/** |
|
198 |
Sets up a bit list representation of the media fat |
|
199 |
Reads whole FAT and sets '1' bits in the bit vector corresponding to the occupied clusters. |
|
200 |
*/ |
|
201 |
void CScanDrive::ReadMediaFatL() |
|
202 |
{ |
|
203 |
ASSERT(iMount->ConsistentState()); |
|
204 |
||
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
205 |
TInt nRes; |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
206 |
|
0 | 207 |
if(iMount->FatType() == EFat32) |
208 |
{//-- for FAT32 try to use specialised method of parsing |
|
209 |
TRAP(nRes, DoParseFat32L()) |
|
210 |
if(nRes == KErrNone) |
|
211 |
return; |
|
212 |
} |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
213 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
214 |
|
0 | 215 |
//-- use old FAT-agnostic parsing |
216 |
DoParseFatL(); |
|
217 |
} |
|
218 |
||
219 |
||
220 |
/** |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
221 |
@return True if a directory error has been found |
0 | 222 |
*/ |
223 |
TBool CScanDrive::IsDirError() const |
|
224 |
{ |
|
225 |
return(iDirError!=0); |
|
226 |
} |
|
227 |
||
228 |
/** |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
229 |
After StartL() and finishing allows us to know if there were any problems discovered at all. |
0 | 230 |
The client may wish to remount the filesystem if there were errors. |
231 |
||
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
232 |
@return The code describing the problem. |
0 | 233 |
*/ |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
234 |
CScanDrive::TGenericError CScanDrive::ProblemsDiscovered() const |
0 | 235 |
{ |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
236 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
237 |
if(IsDirError()) |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
238 |
return EScanDriveDirError; |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
239 |
else |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
240 |
return iGenericError; |
0 | 241 |
} |
242 |
||
243 |
/** |
|
244 |
Sets the flag indicating than there are errors in filesystem structure |
|
245 |
See ProblemsDiscovered() |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
246 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
247 |
@param aError a code describing the error |
0 | 248 |
*/ |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
249 |
void CScanDrive::IndicateErrorsFound(TGenericError aError) |
0 | 250 |
{ |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
251 |
ASSERT(aError != ENoErrors); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
252 |
iGenericError = aError; |
0 | 253 |
} |
254 |
||
255 |
||
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
256 |
//---------------------------------------------------------------------------------------------------- |
0 | 257 |
/** |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
258 |
Start the scanner. The this calss description about what it actually does. |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
259 |
@param aMode specifies the operational mode. |
0 | 260 |
*/ |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
261 |
void CScanDrive::StartL(TScanDriveMode aMode) |
0 | 262 |
{ |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
263 |
__PRINT2(_L("CScanDrive::StartL(%d), drive:%d"), aMode, iMount->DriveNumber()); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
264 |
iScanDriveMode = aMode; |
0 | 265 |
|
266 |
//-- used for measuring time |
|
267 |
TTime timeStart; |
|
268 |
TTime timeEnd; |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
269 |
|
0 | 270 |
timeStart.UniversalTime(); //-- take start time |
271 |
||
272 |
ReadMediaFatL(); |
|
273 |
||
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
274 |
//timeEnd.UniversalTime(); //-- take end time |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
275 |
//elapsedTime = (TInt)( (timeEnd.MicroSecondsFrom(timeStart)).Int64() / K1mSec); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
276 |
//__PRINT1(_L("#@@@ CScanDrive #1:%d ms "), elapsedTime); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
277 |
|
0 | 278 |
CheckDirStructureL(); |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
279 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
280 |
//-- uncomments a line below if you need to compare real and restored FAT tables and print out all differences |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
281 |
//CompareFatsL(EFalse); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
282 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
283 |
//timeEnd.UniversalTime(); //-- take end time |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
284 |
//elapsedTime = (TInt)( (timeEnd.MicroSecondsFrom(timeStart)).Int64() / K1mSec); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
285 |
//__PRINT1(_L("#@@@ CScanDrive #2:%d ms "), elapsedTime); |
0 | 286 |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
287 |
if(CheckDiskMode()) |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
288 |
{//-- in check disk mode it is nesessarily just to detech FS errors |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
289 |
CompareFatsL(ETrue); //-- will stop on the first error found |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
290 |
} |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
291 |
else |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
292 |
{//-- In ScanDrive mode we need to find and fix Rugged FAT artefacts. |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
293 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
294 |
if(IsDirError()) |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
295 |
FixupDirErrorL(); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
296 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
297 |
CompareAndFixFatsL(); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
298 |
} |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
299 |
|
0 | 300 |
PrintErrors(); |
301 |
||
302 |
||
303 |
timeEnd.UniversalTime(); //-- take end time |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
304 |
const TInt elapsedTime = (TInt)( (timeEnd.MicroSecondsFrom(timeStart)).Int64() / K1mSec); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
305 |
(void)elapsedTime; |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
306 |
|
0 | 307 |
__PRINT1(_L("CScanDrive: Directories visisted = %d\n"),iDirsChecked); |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
308 |
__PRINT1(_L("#@@@ CScanDrive time taken:%d ms "), elapsedTime); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
309 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
310 |
|
0 | 311 |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
312 |
return; |
0 | 313 |
} |
314 |
||
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
315 |
//---------------------------------------------------------------------------------------------------- |
0 | 316 |
/** |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
317 |
Fix errors detected by the drive scan |
0 | 318 |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
319 |
@leave System wide error code |
0 | 320 |
*/ |
321 |
void CScanDrive::FixupDirErrorL() |
|
322 |
{ |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
323 |
ASSERT(!CheckDiskMode()); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
324 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
325 |
if(!IsDirError()) |
0 | 326 |
return; |
327 |
||
328 |
if(iDirError==EScanMatchingEntry) |
|
329 |
{ |
|
330 |
FindSameStartClusterL(); |
|
331 |
FixMatchingEntryL(); |
|
332 |
} |
|
333 |
else |
|
334 |
{ |
|
335 |
FixPartEntryL(); |
|
336 |
} |
|
337 |
||
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
338 |
IndicateErrorsFound(EScanDriveDirError); //-- indicate that we have found errors |
0 | 339 |
} |
340 |
||
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
341 |
//---------------------------------------------------------------------------------------------------- |
0 | 342 |
/** |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
343 |
Find positions of entries with same start cluster for error correction, searches |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
344 |
the whole volume. Starts at the root directory. |
0 | 345 |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
346 |
@leave System wide error code |
0 | 347 |
*/ |
348 |
void CScanDrive::FindSameStartClusterL() |
|
349 |
{ |
|
350 |
TInt err=FindStartClusterL(iMount->RootIndicator()); |
|
351 |
if(err==KErrNone) |
|
352 |
return; |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
353 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
354 |
for(TUint i=0;i<KMaxArrayDepth && iClusterListArray[i]!=NULL;++i) |
0 | 355 |
{ |
356 |
RArray<TInt>* clusterList=iClusterListArray[i]; |
|
357 |
for(TInt j=0;j<clusterList->Count();++j) |
|
358 |
{ |
|
359 |
iRecursiveDepth=0; |
|
360 |
err=FindStartClusterL((*clusterList)[j]); |
|
361 |
if(err==KErrNone) |
|
362 |
return; |
|
363 |
} |
|
364 |
} |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
365 |
|
0 | 366 |
__ASSERT_ALWAYS(err==KErrNone,User::Leave(KErrNotFound)); |
367 |
} |
|
368 |
||
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
369 |
//---------------------------------------------------------------------------------------------------- |
0 | 370 |
/** |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
371 |
Scan through directory structure looking for start cluster found in iMatching |
0 | 372 |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
373 |
@param aDirCluster Start cluster for scan to start |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
374 |
@return System wide error value |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
375 |
@leave |
0 | 376 |
*/ |
377 |
TInt CScanDrive::FindStartClusterL(TInt aDirCluster) |
|
378 |
{ |
|
379 |
__PRINT1(_L("CScanDrive::FindStartCluster dirCluster=%d"),aDirCluster); |
|
380 |
__ASSERT_ALWAYS(aDirCluster>=iMount->RootIndicator(),User::Leave(KErrCorrupt)); |
|
381 |
if(++iRecursiveDepth==KMaxScanDepth) |
|
382 |
{ |
|
383 |
--iRecursiveDepth; |
|
384 |
return(KErrNotFound); |
|
385 |
} |
|
386 |
TEntryPos entryPos(aDirCluster,0); |
|
387 |
TInt dirEntries=0; |
|
388 |
FOREVER |
|
389 |
{ |
|
390 |
TFatDirEntry entry; |
|
391 |
ReadDirEntryL(entryPos,entry); |
|
392 |
if(entry.IsParentDirectory()||entry.IsCurrentDirectory()||entry.IsErased()) |
|
393 |
{ |
|
394 |
if(IsEndOfRootDir(entryPos)) |
|
395 |
break; |
|
396 |
MoveToNextEntryL(entryPos); |
|
397 |
continue; |
|
398 |
} |
|
399 |
if(entry.IsEndOfDirectory()) |
|
400 |
break; |
|
401 |
TBool isComplete; |
|
402 |
TEntryPos vfatPos=entryPos; |
|
403 |
isComplete=MoveToVFatEndL(entryPos,entry,dirEntries); |
|
404 |
__ASSERT_ALWAYS(isComplete,User::Leave(KErrBadName)); |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
405 |
|
0 | 406 |
TInt err=CheckEntryClusterL(entry,vfatPos); |
407 |
if(err==KErrNone) |
|
408 |
{ |
|
409 |
--iRecursiveDepth; |
|
410 |
return(err); |
|
411 |
} |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
412 |
|
0 | 413 |
if(IsEndOfRootDir(entryPos)) |
414 |
break; |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
415 |
|
0 | 416 |
MoveToNextEntryL(entryPos); |
417 |
} |
|
418 |
--iRecursiveDepth; |
|
419 |
return(KErrNotFound); |
|
420 |
} |
|
421 |
||
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
422 |
//---------------------------------------------------------------------------------------------------- |
0 | 423 |
/** |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
424 |
Procces aEntry to find matching start cluster |
0 | 425 |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
426 |
@param aEntry Directory entry to check |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
427 |
@param aEntryPos Position of directory to check |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
428 |
@return System wide error value |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
429 |
@leave |
0 | 430 |
*/ |
431 |
TInt CScanDrive::CheckEntryClusterL(const TFatDirEntry& aEntry, const TEntryPos& aEntryPos) |
|
432 |
{ |
|
433 |
__PRINT(_L("CScanDrive::CheckEntryClusterL")); |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
434 |
if((TUint)iMount->StartCluster(aEntry)==iMatching.iStartCluster) |
0 | 435 |
{ |
436 |
TBool complete=AddMatchingEntryL(aEntryPos); |
|
437 |
if(complete) |
|
438 |
return(KErrNone); |
|
439 |
} |
|
440 |
else if(aEntry.Attributes()&KEntryAttDir) |
|
441 |
return(FindStartClusterL(iMount->StartCluster(aEntry))); |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
442 |
|
0 | 443 |
return(KErrNotFound); |
444 |
} |
|
445 |
||
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
446 |
//---------------------------------------------------------------------------------------------------- |
0 | 447 |
/** |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
448 |
Checks directory structure for errors, can be considered the start point of the scan. |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
449 |
Handles recursion depth to avoid stack overflow. |
0 | 450 |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
451 |
@leave System wide error code |
0 | 452 |
*/ |
453 |
void CScanDrive::CheckDirStructureL() |
|
454 |
{ |
|
455 |
CheckDirL(iMount->RootIndicator()); |
|
456 |
// Due to recursive nature of CheckDirL when a depth of |
|
457 |
// KMaxScanDepth is reached clusters are stored in a list |
|
458 |
// and passed into CheckDirL afresh |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
459 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
460 |
for(TUint i=0;i<KMaxArrayDepth && iClusterListArray[i]!=NULL;++i) |
0 | 461 |
{ |
462 |
RArray<TInt>* clusterList=iClusterListArray[i]; |
|
463 |
++iListArrayIndex; |
|
464 |
for(TInt j=0;j<clusterList->Count();++j) |
|
465 |
{ |
|
466 |
iRecursiveDepth=0; |
|
467 |
CheckDirL((*clusterList)[j]); |
|
468 |
} |
|
469 |
} |
|
470 |
} |
|
471 |
||
472 |
||
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
473 |
//---------------------------------------------------------------------------------------------------- |
0 | 474 |
/** |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
475 |
This function is called recursively with Process entry untill the whole volume has been scanned. |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
476 |
Each directory entry is scanned for errors, these are recorded for later fixing. |
0 | 477 |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
478 |
@param aCluster Directory cluster to start checking |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
479 |
@leave System wide error codes |
0 | 480 |
*/ |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
481 |
void CScanDrive::CheckDirL(TUint32 aCluster) |
0 | 482 |
{ |
483 |
__PRINT1(_L("CScanDrive::CheckDirL aCluster=%d"),aCluster); |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
484 |
|
0 | 485 |
// check depth of recursion |
486 |
if(++iRecursiveDepth==KMaxScanDepth) |
|
487 |
{ |
|
488 |
AddToClusterListL(aCluster); |
|
489 |
--iRecursiveDepth; |
|
490 |
return; |
|
491 |
} |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
492 |
|
0 | 493 |
++iDirsChecked; |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
494 |
|
0 | 495 |
TEntryPos entryPos(aCluster,0); |
496 |
TInt dirEntries=0; |
|
497 |
FOREVER |
|
498 |
{ |
|
499 |
TFatDirEntry entry; |
|
500 |
ReadDirEntryL(entryPos,entry); |
|
501 |
if(!iMount->IsEndOfClusterCh(entryPos.iCluster)) |
|
502 |
++dirEntries; |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
503 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
504 |
if(entry.IsParentDirectory() || entry.IsCurrentDirectory() || entry.IsErased()) |
0 | 505 |
{ |
506 |
if(IsEndOfRootDir(entryPos)) |
|
507 |
break; |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
508 |
|
0 | 509 |
MoveToNextEntryL(entryPos); |
510 |
continue; |
|
511 |
} |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
512 |
|
0 | 513 |
if(entry.IsEndOfDirectory()) |
514 |
{ |
|
515 |
if(aCluster) |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
516 |
RecordClusterChainL(aCluster,dirEntries<<KSizeOfFatDirEntryLog2); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
517 |
|
0 | 518 |
break; |
519 |
} |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
520 |
|
0 | 521 |
TEntryPos origPos=entryPos; |
522 |
TFatDirEntry origEntry=entry; |
|
523 |
TInt origDirEntries=dirEntries; |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
524 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
525 |
const TBool isComplete = MoveToVFatEndL(entryPos,entry,dirEntries); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
526 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
527 |
if(!isComplete && CheckDiskMode()) |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
528 |
{//-- broken VFAT entryset; in CheckDisk mode this is the FS error, abort further activity |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
529 |
IndicateErrorsFound(EInvalidEntrySize); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
530 |
User::Leave(KErrCorrupt); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
531 |
} |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
532 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
533 |
// Only assume that this is a corrupted VFAT entry if the VFAT attributes are set; |
0 | 534 |
// assuming a non-VFAT corrupted entry is a VFAT entry is dangerous as we then assume that the |
535 |
// first byte is a count of entries to skip, thus completely invalidating the next <n> directories. |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
536 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
537 |
//-- this code seems to deal with one of the Rugged FAT artefacts: partially deleted VFAT entryset, when DOS entry is deleted first |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
538 |
//-- and delettion of VFAT ones had failed |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
539 |
if(!isComplete && origEntry.IsVFatEntry()) |
0 | 540 |
{ |
541 |
AddPartialVFatL(origPos,origEntry); |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
542 |
if(!IsEofF(entryPos.iCluster)) |
0 | 543 |
{ |
544 |
TInt toMove=origEntry.NumFollowing()-(dirEntries-origDirEntries); |
|
545 |
if(toMove) |
|
546 |
MovePastEntriesL(entryPos,entry,toMove,dirEntries); |
|
547 |
} |
|
548 |
else |
|
549 |
{ |
|
550 |
// we fell off the end of the directory file, so just strip this |
|
551 |
// incomplete long file name entry |
|
552 |
dirEntries = origDirEntries; |
|
553 |
} |
|
554 |
} |
|
555 |
else |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
556 |
{ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
557 |
ProcessEntryL(entry); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
558 |
} |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
559 |
|
0 | 560 |
if(IsEndOfRootDir(entryPos)) |
561 |
break; |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
562 |
|
0 | 563 |
MoveToNextEntryL(entryPos); |
564 |
} |
|
565 |
--iRecursiveDepth; |
|
566 |
} |
|
567 |
||
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
568 |
//---------------------------------------------------------------------------------------------------- |
0 | 569 |
/** |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
570 |
Process non trivial entries, such as files, if they are correct by filling out their |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
571 |
cluster allocation in the bit packed Fat table. If it comes accross a directory |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
572 |
CheckDirL will be called. |
0 | 573 |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
574 |
@param aEntry Directory entry to check |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
575 |
@leave System wide error code |
0 | 576 |
*/ |
577 |
void CScanDrive::ProcessEntryL(const TFatDirEntry& aEntry) |
|
578 |
{ |
|
579 |
__PRINT(_L("CScanDrive::ProcessEntryL")); |
|
580 |
TInt entryAtt=aEntry.Attributes(); |
|
581 |
||
582 |
__ASSERT_ALWAYS(!(entryAtt&~KEntryAttMaskSupported)&&!aEntry.IsErased(),User::Leave(KErrCorrupt)); |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
583 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
584 |
if(!(entryAtt&(KEntryAttDir|KEntryAttVolume)) && iMount->StartCluster(aEntry)>0) |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
585 |
{//-- this is a file with length >0. Check that its cluster chain corresponds to its size |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
586 |
RecordClusterChainL(iMount->StartCluster(aEntry),(TUint) aEntry.Size()); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
587 |
} |
0 | 588 |
else if(entryAtt&KEntryAttDir) |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
589 |
{//-- this is the directory, walk into it |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
590 |
CheckDirL(iMount->StartCluster(aEntry)); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
591 |
} |
0 | 592 |
} |
593 |
||
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
594 |
//---------------------------------------------------------------------------------------------------- |
0 | 595 |
/** |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
596 |
Walks the cluster chain for a correct file or directory, checks that the cluster |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
597 |
has not already been used and that the correct number of clusters are allocated for the |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
598 |
size of file. Registers cluster as used, if correct. |
0 | 599 |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
600 |
@param aCluster Cluster chain start point |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
601 |
@param aSizeInBytes Size of the file or directory in bytes |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
602 |
@leave System wide error values |
0 | 603 |
*/ |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
604 |
void CScanDrive::RecordClusterChainL(TInt aCluster, TUint aSizeInBytes) |
0 | 605 |
{ |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
606 |
__PRINT2(_L("CScanDrive::RecordClusterChainL() cl:%d, sz:%d") ,aCluster, aSizeInBytes); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
607 |
__ASSERT_ALWAYS(aCluster>0, User::Leave(KErrCorrupt)); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
608 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
609 |
TUint clusterCount; |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
610 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
611 |
if(aSizeInBytes==0) |
0 | 612 |
clusterCount=1; |
613 |
else |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
614 |
{ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
615 |
const TUint64 tmp = aSizeInBytes + Pow2_64(iMount->ClusterSizeLog2()) - 1; |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
616 |
clusterCount = (TUint) (tmp >> iMount->ClusterSizeLog2()); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
617 |
} |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
618 |
|
0 | 619 |
TInt startCluster=aCluster; |
620 |
while(clusterCount) |
|
621 |
{ |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
622 |
if(IsClusterUsedL(aCluster)) |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
623 |
{//-- this cluster already seems to belong to some other object; crosslinked cluster chain. Can't fix it. |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
624 |
if(CheckDiskMode()) |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
625 |
{//-- in check disk mode this is a FS error; Indicate error and abort furter scanning |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
626 |
__PRINT1(_L("CScanDrive::RecordClusterChainL #1 %d"),aCluster); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
627 |
IndicateErrorsFound(EClusterAlreadyInUse); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
628 |
User::Leave(KErrCorrupt); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
629 |
} |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
630 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
631 |
__ASSERT_ALWAYS(!IsDirError() && iMatching.iStartCluster==0 && aCluster==startCluster,User::Leave(KErrCorrupt)); |
0 | 632 |
iMatching.iStartCluster=aCluster; |
633 |
iDirError=EScanMatchingEntry; //ERROR POINT |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
634 |
IndicateErrorsFound(EScanDriveDirError); //-- indicate that we have found errors |
0 | 635 |
return; |
636 |
} |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
637 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
638 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
639 |
if(clusterCount==1) |
0 | 640 |
{ |
641 |
if(!iMount->IsEndOfClusterCh(ReadFatL(aCluster))) |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
642 |
{//-- seems to be a rugged FAT artefact; File truncation had failed before and now file length is less than |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
643 |
//-- the corresponding cluster chain shall be. It will be truncated. |
0 | 644 |
iTruncationCluster = aCluster; |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
645 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
646 |
if(CheckDiskMode()) |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
647 |
{//-- in check disk mode this is a FS error; Indicate error and abort furter scanning |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
648 |
__PRINT1(_L("CScanDrive::RecordClusterChainL #2 %d"),aCluster); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
649 |
IndicateErrorsFound(EInvalidEntrySize); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
650 |
User::Leave(KErrCorrupt); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
651 |
} |
0 | 652 |
} |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
653 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
654 |
//__PRINT1(_L("#--: %d -> EOC"), aCluster); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
655 |
MarkClusterUsedL(aCluster); |
0 | 656 |
return; |
657 |
} |
|
658 |
else |
|
659 |
{ |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
660 |
const TUint clusterVal=ReadFatL(aCluster); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
661 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
662 |
//__PRINT2(_L("#--: %d -> %d"), aCluster, clusterVal); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
663 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
664 |
__ASSERT_ALWAYS(!IsEofF(clusterVal) && clusterVal !=KSpareCluster, User::Leave(KErrCorrupt)); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
665 |
MarkClusterUsedL(aCluster); |
0 | 666 |
aCluster=clusterVal; |
667 |
--clusterCount; |
|
668 |
} |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
669 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
670 |
}//while(clusterCount) |
0 | 671 |
} |
672 |
||
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
673 |
//---------------------------------------------------------------------------------------------------- |
0 | 674 |
/** |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
675 |
Move to dos entry, checking all vfat entry ID numbers are in sequence. |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
676 |
Assumes aEntry is not erased |
0 | 677 |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
678 |
@param aPos Position of the entry to move from, returns with new position |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
679 |
@param aEntry The Dos entry after the Vfat entries on return |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
680 |
@param aDirLength Running total of the length of the directory in entries |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
681 |
@leave System wide error codes |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
682 |
@return EFalse if not valid vfat entries or dos entry, else returns ETrue |
0 | 683 |
*/ |
684 |
TBool CScanDrive::MoveToVFatEndL(TEntryPos& aPos,TFatDirEntry& aEntry,TInt& aDirLength) |
|
685 |
{ |
|
686 |
__PRINT2(_L("CScanDrive::MoveToVFatEndL cluster=%d,pos=%d"),aPos.iCluster,aPos.iPos); |
|
687 |
if(!aEntry.IsVFatEntry()) |
|
688 |
return IsDosEntry(aEntry); |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
689 |
|
0 | 690 |
TInt toFollow=aEntry.NumFollowing(); |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
691 |
__ASSERT_ALWAYS(toFollow>0 && !aEntry.IsErased(), User::Leave(KErrCorrupt)); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
692 |
|
0 | 693 |
FOREVER |
694 |
{ |
|
695 |
MoveToNextEntryL(aPos); |
|
696 |
ReadDirEntryL(aPos,aEntry); |
|
697 |
++aDirLength; |
|
698 |
--toFollow; |
|
699 |
if(!toFollow) |
|
700 |
break; |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
701 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
702 |
if(!IsValidVFatEntry(aEntry,toFollow)) |
0 | 703 |
return(EFalse); |
704 |
} |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
705 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
706 |
return(IsDosEntry(aEntry)); |
0 | 707 |
} |
708 |
||
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
709 |
//---------------------------------------------------------------------------------------------------- |
0 | 710 |
/** |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
711 |
Check if an entry is valid VFat |
0 | 712 |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
713 |
@param aEntry Entry to check |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
714 |
@param aPrevNum Number into VFat entries for a dos entry to ensure in correct position |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
715 |
@return ETrue if aEntry is a valid vfat entry |
0 | 716 |
*/ |
717 |
TBool CScanDrive::IsValidVFatEntry(const TFatDirEntry& aEntry,TInt aPrevNum)const |
|
718 |
{ |
|
719 |
if(aEntry.IsErased()||!aEntry.IsVFatEntry()) |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
720 |
return EFalse; |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
721 |
|
0 | 722 |
return(aEntry.NumFollowing()==aPrevNum); |
723 |
} |
|
724 |
||
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
725 |
//---------------------------------------------------------------------------------------------------- |
0 | 726 |
/** |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
727 |
Check if an entry is a Dos entry |
0 | 728 |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
729 |
@param aEntry Entry to check |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
730 |
@return ETrue if aEntry is a dos entry |
0 | 731 |
*/ |
732 |
TBool CScanDrive::IsDosEntry(const TFatDirEntry& aEntry)const |
|
733 |
{ |
|
734 |
TBool res = !(aEntry.Attributes()&~KEntryAttMaskSupported) && !aEntry.IsErased() && !aEntry.IsVFatEntry() && !aEntry.IsEndOfDirectory(); |
|
735 |
return res; |
|
736 |
} |
|
737 |
||
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
738 |
//---------------------------------------------------------------------------------------------------- |
0 | 739 |
/** |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
740 |
Add partial entry to iPartEntry under the error condition of not all Vfat entries being present |
0 | 741 |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
742 |
@param aStartPos Position of the Dos entry associated with the VFat entries |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
743 |
@param aEntry Directory Entry of the Dos entry associated with the VFat entries |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
744 |
@leave KErrCorrupt Occurs if the entry is not valid |
0 | 745 |
*/ |
746 |
void CScanDrive::AddPartialVFatL(const TEntryPos& aStartPos, const TFatDirEntry& aEntry) |
|
747 |
{ |
|
748 |
__PRINT2(_L("CScanDrive::AddPartialVFatL cluster=%d pos=%d"),aStartPos.iCluster,aStartPos.iPos); |
|
749 |
__ASSERT_ALWAYS(!IsDirError(),User::Leave(KErrCorrupt)); |
|
750 |
iPartEntry.iEntryPos=aStartPos; |
|
751 |
iPartEntry.iEntry=aEntry; |
|
752 |
iDirError=EScanPartEntry; |
|
753 |
} |
|
754 |
||
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
755 |
//---------------------------------------------------------------------------------------------------- |
0 | 756 |
/** |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
757 |
Add entry position to iMatching |
0 | 758 |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
759 |
@param aEntryPos Position of the entry with the matching entry |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
760 |
@leave KErrCorrupt if the start cluster is 0 or more that two matching entries occurs |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
761 |
@return |
0 | 762 |
*/ |
763 |
TBool CScanDrive::AddMatchingEntryL(const TEntryPos& aEntryPos) |
|
764 |
{ |
|
765 |
__PRINT2(_L("CScanDrive::AddMatchingEntryL cluster=%d pos=%d"),aEntryPos.iCluster,aEntryPos.iPos); |
|
766 |
__ASSERT_ALWAYS(iMatching.iStartCluster>0 && iMatching.iCount<KMaxMatchingEntries,User::Leave(KErrCorrupt)); |
|
767 |
iMatching.iEntries[iMatching.iCount++]=aEntryPos; |
|
768 |
return iMatching.iCount==KMaxMatchingEntries; |
|
769 |
} |
|
770 |
||
771 |
||
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
772 |
//---------------------------------------------------------------------------------------------------- |
0 | 773 |
/** |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
774 |
Scan for differnces in the new and old FAT table writing them to media if discovered |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
775 |
It is supposed to be called in 'ScanDrive' mode only |
0 | 776 |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
777 |
@leave System wide error codes |
0 | 778 |
*/ |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
779 |
void CScanDrive::CompareAndFixFatsL() |
0 | 780 |
{ |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
781 |
__PRINT1(_L("CScanDrive::CompareAndFixFatsL() drv:%d"),iMount->DriveNumber()); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
782 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
783 |
ASSERT(!CheckDiskMode()); |
0 | 784 |
|
785 |
TUint32 nClustersFixed = 0; //-- fixed clusters count |
|
786 |
TUint32 nBadClusters = 0; //-- bad cluster count |
|
787 |
TUint32 dirtyFatSector = 0; //-- FAT table media sector with not-flushed data |
|
788 |
||
789 |
const TUint32 KSectorSzLog2 = iMount->SectorSizeLog2(); //-- Log2(media Sector Size) |
|
790 |
||
791 |
TUint32 diffPos; |
|
792 |
if(iMediaFatBits.Diff(iScanFatBits, diffPos)) |
|
793 |
{//-- there is a difference between FATs' bit representation |
|
794 |
||
795 |
ASSERT(diffPos >= KFatFirstSearchCluster); |
|
796 |
||
797 |
const TUint32 maxClusters = iScanFatBits.Size(); |
|
798 |
||
799 |
for(TUint32 i=diffPos; i<maxClusters; ++i) |
|
800 |
{ |
|
801 |
if(BoolXOR(iMediaFatBits[i], iScanFatBits[i])) |
|
802 |
{//-- difference in the cluster "i" between a real FAT and what ScanDrive restored. |
|
803 |
||
804 |
//-- indicate that there are some problems in FAT. and we probably wrote something there. |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
805 |
IndicateErrorsFound(EScanDriveDirError); |
0 | 806 |
|
807 |
//-- skip BAD cluster, can't mark it as unused. |
|
808 |
if(iMount->IsBadCluster(ReadFatL(i))) |
|
809 |
{ |
|
810 |
++nBadClusters; |
|
811 |
continue; |
|
812 |
} |
|
813 |
||
814 |
//-- here we found a lost cluster. Its FAT entry will be replaced with KSpareCluster. In the case of multiple lost clusters FAT table will |
|
815 |
//-- be flushed on media sector basis. It is much faster than flushing FAT after every write and will |
|
816 |
//-- guarantee that FAT won't be corrupted if the media driver provides atomic sector write. |
|
817 |
if(nClustersFixed == 0) |
|
818 |
{//-- this is the first lost cluster entry we found |
|
819 |
||
820 |
//-- relative FAT media sector for the 'i' entry. The real value doesn't matter, |
|
821 |
//-- we will just be flushing FAT before writing to the different FAT media sector. |
|
822 |
dirtyFatSector = iMount->FAT().PosInBytes(i) >> KSectorSzLog2; |
|
823 |
||
824 |
iMount->FAT().WriteL(i, KSpareCluster); //-- fix lost cluster |
|
825 |
} |
|
826 |
else |
|
827 |
{ |
|
828 |
const TUint32 fatSec = iMount->FAT().PosInBytes(i) >> KSectorSzLog2; |
|
829 |
||
830 |
if(fatSec != dirtyFatSector) |
|
831 |
{//-- we are going to write to a differrent media sector |
|
832 |
iMount->FAT().FlushL(); |
|
833 |
iMount->FAT().WriteL(i, KSpareCluster); //-- fix lost cluster |
|
834 |
dirtyFatSector = fatSec; |
|
835 |
} |
|
836 |
else |
|
837 |
{//-- write to the same FAT media sector without flushing |
|
838 |
iMount->FAT().WriteL(i, KSpareCluster); //-- fix lost cluster |
|
839 |
} |
|
840 |
||
841 |
} |
|
842 |
||
843 |
++nClustersFixed; |
|
844 |
||
845 |
}//if(BoolXOR(iMediaFatBits[i], iScanFatBits[i]) |
|
846 |
||
847 |
}//for(TInt i=KFatFirstSearchCluster; i<maxClusters; ++i) |
|
848 |
||
849 |
}//if(iMediaFatBits.Diff(iScanFatBits, diffPos)) |
|
850 |
||
851 |
||
852 |
if(nClustersFixed) |
|
853 |
iMount->FAT().FlushL(); |
|
854 |
||
855 |
//------ |
|
856 |
||
857 |
if(iTruncationCluster != 0) |
|
858 |
{ |
|
859 |
iMount->FAT().WriteFatEntryEofL(iTruncationCluster); |
|
860 |
iMount->FAT().FlushL(); |
|
861 |
||
862 |
//-- indicate that there are some problems in FAT. and we probably wrote something there. |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
863 |
IndicateErrorsFound(EScanDriveDirError); //-- indicate that we have found errors |
0 | 864 |
|
865 |
++nClustersFixed; |
|
866 |
} |
|
867 |
||
868 |
__PRINT2(_L("CScanDrive::WriteNewFatsL() fixed:%d, bad:%d"), nClustersFixed, nBadClusters); |
|
869 |
} |
|
870 |
||
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
871 |
//---------------------------------------------------------------------------------------------------- |
0 | 872 |
/** |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
873 |
Read the "Rugged FAT" ID, stored in reserved2 in the Dos entry or associated with the Dos entry of the |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
874 |
Entry at the position passed in. This is used to find which version of two matching entries should be kept. |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
875 |
|
0 | 876 |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
877 |
@param aVFatPos Position of an entry to read ID from |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
878 |
@leave System wide error codes |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
879 |
@return The ID found in reserved2 field of dos entry |
0 | 880 |
*/ |
881 |
TInt CScanDrive::GetReservedidL(TEntryPos aVFatPos) |
|
882 |
{ |
|
883 |
__PRINT(_L("CScanDrive::GetReservedidL")); |
|
884 |
TFatDirEntry entry; |
|
885 |
ReadDirEntryL(aVFatPos,entry); |
|
886 |
if(!IsDosEntry(entry)) |
|
887 |
{ |
|
888 |
TInt toMove=entry.NumFollowing(); |
|
889 |
while(toMove--) |
|
890 |
MoveToNextEntryL(aVFatPos); |
|
891 |
ReadDirEntryL(aVFatPos,entry); |
|
892 |
} |
|
893 |
return(entry.RuggedFatEntryId()); |
|
894 |
} |
|
895 |
||
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
896 |
//---------------------------------------------------------------------------------------------------- |
0 | 897 |
/** |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
898 |
Erase part entry found in iPartEntry |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
899 |
@leave System wide error code |
0 | 900 |
*/ |
901 |
void CScanDrive::FixPartEntryL() |
|
902 |
{ |
|
903 |
__PRINT2(_L("CScanDrive::FixPartEntryL cluster=%d,pos=%d"),iPartEntry.iEntryPos.iCluster,iPartEntry.iEntryPos.iPos); |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
904 |
ASSERT(!CheckDiskMode()); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
905 |
iMount->EraseDirEntryL(iPartEntry.iEntryPos,iPartEntry.iEntry); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
906 |
IndicateErrorsFound(EScanDriveDirError); //-- indicate that we have found errors |
0 | 907 |
} |
908 |
||
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
909 |
//---------------------------------------------------------------------------------------------------- |
0 | 910 |
/** |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
911 |
Delete entry with largest value in the reserved2 section(bytes 20 and 21) of dos entry |
0 | 912 |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
913 |
@leave System wide error code |
0 | 914 |
*/ |
915 |
void CScanDrive::FixMatchingEntryL() |
|
916 |
{ |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
917 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
918 |
__PRINT1(_L("CScanDrive::FixMatchingEntryL() start cluster=%d"),iMatching.iStartCluster); |
0 | 919 |
__ASSERT_ALWAYS(iMatching.iCount==KMaxMatchingEntries,User::Leave(KErrCorrupt)); |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
920 |
ASSERT(!CheckDiskMode()); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
921 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
922 |
TInt idOne=GetReservedidL(iMatching.iEntries[0]); |
0 | 923 |
TInt idTwo=GetReservedidL(iMatching.iEntries[1]); |
924 |
TFatDirEntry entry; |
|
925 |
TInt num=idOne>idTwo?0:1; |
|
926 |
ReadDirEntryL(iMatching.iEntries[num],entry); |
|
927 |
iMount->EraseDirEntryL(iMatching.iEntries[num],entry); |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
928 |
IndicateErrorsFound(EScanDriveDirError); //-- indicate that we have found errors |
0 | 929 |
} |
930 |
||
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
931 |
//---------------------------------------------------------------------------------------------------- |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
932 |
/** |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
933 |
Move past specified number of entries |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
934 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
935 |
@param aEntryPos Start position to move from, updated as move takes place |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
936 |
@param aEntry Directory entry moved to |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
937 |
@param aToMove Number of entries to move through |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
938 |
@param aDirEntries Number of entries moved, updated as move takes place |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
939 |
@leave System wide error code |
0 | 940 |
*/ |
941 |
void CScanDrive::MovePastEntriesL(TEntryPos& aEntryPos,TFatDirEntry& aEntry,TInt aToMove,TInt& aDirEntries) |
|
942 |
{ |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
943 |
while(aToMove-- && !IsEofF(aEntryPos.iCluster)) |
0 | 944 |
{ |
945 |
MoveToNextEntryL(aEntryPos); |
|
946 |
++aDirEntries; |
|
947 |
} |
|
948 |
ReadDirEntryL(aEntryPos,aEntry); |
|
949 |
} |
|
950 |
||
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
951 |
//---------------------------------------------------------------------------------------------------- |
0 | 952 |
/** |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
953 |
Adds aCluster to cluster list array so that it may be revisited later, avoids stack |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
954 |
over flow |
0 | 955 |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
956 |
@param aCluster Directory cluster number to add to the list |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
957 |
@leave KErrNoMemory If allocation fails |
0 | 958 |
*/ |
959 |
void CScanDrive::AddToClusterListL(TInt aCluster) |
|
960 |
{ |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
961 |
|
0 | 962 |
if(iListArrayIndex>=KMaxArrayDepth) |
963 |
return; |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
964 |
|
0 | 965 |
if(iClusterListArray[iListArrayIndex]==NULL) |
966 |
iClusterListArray[iListArrayIndex]=new(ELeave) RArray<TInt>(KClusterListGranularity); |
|
967 |
iClusterListArray[iListArrayIndex]->Append(aCluster); |
|
968 |
} |
|
969 |
||
970 |
||
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
971 |
//---------------------------------------------------------------------------------------------------- |
0 | 972 |
/** |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
973 |
Used in "CheckDisk" mode mostly. Compares first FAT table on the media with the FAT bitmap restored by walking the directory structure. |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
974 |
Displays any differences and records an error if found. |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
975 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
976 |
@param aStopOnFirstErrorFound if ETrue will stop after discovering first error (FATs discrepancy) |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
977 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
978 |
@leave System wide error codes |
0 | 979 |
*/ |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
980 |
void CScanDrive::CompareFatsL(TBool aStopOnFirstErrorFound) |
0 | 981 |
{ |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
982 |
__PRINT1(_L("CScanDrive::CompareFatsL(%d)"), aStopOnFirstErrorFound); |
0 | 983 |
|
984 |
||
985 |
TUint32 diffPos; |
|
986 |
if(!iMediaFatBits.Diff(iScanFatBits, diffPos)) |
|
987 |
return; //-- FATs are identical |
|
988 |
||
989 |
//-- there is a difference between the real FAT and reconstructed one. Find the mismaching bit and fix FAT. |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
990 |
const TUint clusters = iMount->UsableClusters(); |
0 | 991 |
ASSERT(diffPos < (TUint32)clusters); |
992 |
||
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
993 |
TUint scanusedcnt=0; |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
994 |
TUint mediausedcnt=0; |
0 | 995 |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
996 |
for(TUint i=diffPos; i<clusters; ++i) |
0 | 997 |
{ |
998 |
const TBool bRealFatEntry = iMediaFatBits[i]; |
|
999 |
const TBool bNewFatEntry = iScanFatBits[i]; |
|
1000 |
||
1001 |
if(BoolXOR(bRealFatEntry, bNewFatEntry)) |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1002 |
{//-- mismatch between FAT on the media and the FAT bitmap restored by walking directory structure |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1003 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1004 |
if(bRealFatEntry) |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1005 |
{//-- FAT[i] on the media is marked as occupied, but retored FAT bitmap shows that it is free |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1006 |
if(iMount->IsBadCluster(ReadFatL(i))) |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1007 |
continue; //-- this is a BAD cluster it can't be occupied by the FS object, OK. |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1008 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1009 |
__PRINT2(_L("FAT[%d] = %d\n"), i, ReadFatL(i)); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1010 |
__PRINT1(_L("iTruncationCluster = %d\n"), iTruncationCluster); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1011 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1012 |
//-- this is a lost cluster |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1013 |
if(!IsEofF(ReadFatL(i)) && (i==iTruncationCluster)) |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1014 |
{//-- seems to be a Rugged FAT ertefact |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1015 |
__PRINT1(_L("Hanging cluster = %d\n"),i); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1016 |
} |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1017 |
else |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1018 |
{ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1019 |
__PRINT1(_L("Lost cluster=%d\n"),i); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1020 |
} |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1021 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1022 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1023 |
IndicateErrorsFound(EBadClusterValue); |
0 | 1024 |
} |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1025 |
else |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1026 |
{//-- FAT[i] on the media is marked as free, but retored FAT bitmap shows that it is occupied by some object |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1027 |
IndicateErrorsFound(EClusterAlreadyInUse); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1028 |
__PRINT1(_L("Unflushed cluster = %d\n"),i); |
0 | 1029 |
} |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1030 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1031 |
if(aStopOnFirstErrorFound) |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1032 |
break; //-- not asked to check for errors further |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1033 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1034 |
} |
0 | 1035 |
|
1036 |
if(bRealFatEntry) |
|
1037 |
mediausedcnt++; |
|
1038 |
||
1039 |
if(bNewFatEntry) |
|
1040 |
scanusedcnt++; |
|
1041 |
} |
|
1042 |
||
1043 |
__PRINT2(_L("Scan Fat Used=%d, Media Fat Used=%d \n"),scanusedcnt,mediausedcnt); |
|
1044 |
} |
|
1045 |
||
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1046 |
//---------------------------------------------------------------------------------------------------- |
0 | 1047 |
/** |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1048 |
For debug purposes, print errors found as debug output |
0 | 1049 |
*/ |
1050 |
void CScanDrive::PrintErrors() |
|
1051 |
{ |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1052 |
#if defined(_DEBUG) |
0 | 1053 |
__PRINT1(_L("Directories visisted = %d\n"),iDirsChecked); |
1054 |
||
1055 |
if(iDirError==EScanPartEntry) |
|
1056 |
{ |
|
1057 |
__PRINT2(_L("Part entry-dir cluster=%d,dir pos=%d,\n"),iPartEntry.iEntryPos.iCluster,iPartEntry.iEntryPos.iPos); |
|
1058 |
} |
|
1059 |
else if(iDirError==EScanMatchingEntry) |
|
1060 |
{ |
|
1061 |
__PRINT1(_L("Matching cluster - cluster no=%d\n"),iMatching.iStartCluster); |
|
1062 |
__PRINT2(_L("\tcluster 1 - dir cluster=%d,dir pos=%d\n"),iMatching.iEntries[0].iCluster,iMatching.iEntries[0].iPos); |
|
1063 |
__PRINT2(_L("\tcluster 2 - dir cluster=%d,dir pos=%d\n"),iMatching.iEntries[1].iCluster,iMatching.iEntries[1].iPos); |
|
1064 |
} |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1065 |
#endif |
0 | 1066 |
} |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1067 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1068 |
|
0 | 1069 |
|
1070 |
/** |
|
1071 |
Read a FAT directory entry from disk, either reads directly from the main cache or |
|
1072 |
from the cluster buffer if scan drive is running in a seperate thread. |
|
1073 |
||
1074 |
@param aPos Media position of entry to read |
|
1075 |
@param aDirEntry Contents of directory entry read |
|
1076 |
@leave System wide error code |
|
1077 |
*/ |
|
1078 |
void CScanDrive::ReadDirEntryL(const TEntryPos& aPos,TFatDirEntry& aDirEntry) |
|
1079 |
{ |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1080 |
//__PRINT(_L("CScanDrive::ReadDirEntryL")); |
0 | 1081 |
if (iMount->IsEndOfClusterCh(aPos.iCluster)) |
1082 |
{ |
|
1083 |
Mem::FillZ(&aDirEntry,sizeof(TFatDirEntry)); |
|
1084 |
return; |
|
1085 |
} |
|
1086 |
||
1087 |
iMount->ReadDirEntryL(aPos, aDirEntry); |
|
1088 |
} |
|
1089 |
||
1090 |
||
1091 |
/** |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1092 |
Move to next directory entry, if anEntry is at the end of the cluster, and we are not |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1093 |
the root dir, move it to the next cluster in the chain. |
0 | 1094 |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1095 |
@param aPos Current directory position up dated to position of next entry. |
0 | 1096 |
*/ |
1097 |
void CScanDrive::MoveToNextEntryL(TEntryPos& aPos) |
|
1098 |
{ |
|
1099 |
//__PRINT(_L("CScanDrive::MoveToNextEntryL")); |
|
1100 |
iMount->MoveToNextEntryL(aPos); |
|
1101 |
} |
|
1102 |
||
1103 |
/** |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1104 |
Read a cluster from the Media Fat if scan run in a seperate thread read from scan fat table |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1105 |
otherwise read from mount owned Fat table |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1106 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1107 |
@param aClusterNum Cluster to read |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1108 |
@return Value of cluster read from Fat |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1109 |
*/ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1110 |
TUint32 CScanDrive::ReadFatL(TUint aClusterNum) |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1111 |
{ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1112 |
if(aClusterNum < KFatFirstSearchCluster || aClusterNum >= MaxClusters()) |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1113 |
{ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1114 |
IndicateErrorsFound(EBadClusterNumber); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1115 |
User::Leave(KErrCorrupt); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1116 |
} |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1117 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1118 |
//-- actually, ReadL() can leave with some error code, that won't be reflected in IndicateErrorsFound(). |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1119 |
//-- it's possible to improve but is it worth it? |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1120 |
return iMount->FAT().ReadL(aClusterNum); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1121 |
} |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1122 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1123 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1124 |
/** |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1125 |
Set a cluster as visited in the bit packed scan Fat |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1126 |
@param aCluster Cluster number |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1127 |
*/ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1128 |
void CScanDrive::MarkClusterUsedL(TUint aClusterNum) |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1129 |
{ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1130 |
if(aClusterNum < KFatFirstSearchCluster || aClusterNum >= MaxClusters()) |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1131 |
{ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1132 |
IndicateErrorsFound(EBadClusterNumber); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1133 |
User::Leave(KErrCorrupt); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1134 |
} |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1135 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1136 |
iScanFatBits.SetBit(aClusterNum); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1137 |
} |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1138 |
|
0 | 1139 |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1140 |
/** |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1141 |
Query whether a cluster is already set as used |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1142 |
@param aCluster Cluster to query |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1143 |
*/ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1144 |
TBool CScanDrive::IsClusterUsedL(TUint aClusterNum) |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1145 |
{ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1146 |
if(aClusterNum < KFatFirstSearchCluster || aClusterNum >= MaxClusters()) |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1147 |
{ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1148 |
IndicateErrorsFound(EBadClusterNumber); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1149 |
User::Leave(KErrCorrupt); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1150 |
} |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1151 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1152 |
return iScanFatBits[aClusterNum]; |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1153 |
} |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1154 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1155 |
/** |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1156 |
@param aPos Position in a directory cluster |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1157 |
@return ETrue if aPos is the last entry in the root directory |
0 | 1158 |
*/ |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1159 |
TBool CScanDrive::IsEndOfRootDir(const TEntryPos& aPos)const |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1160 |
{ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1161 |
return(iMount->IsRootDir(aPos)&&(iMount->StartOfRootDirInBytes()+aPos.iPos==(iMount->RootDirEnd()-KSizeOfFatDirEntry))); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1162 |
} |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1163 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1164 |
/** |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1165 |
@param aVal Value of the cluster to be tested |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1166 |
@return ETrue if aVal is the end of cluster marker |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1167 |
*/ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1168 |
TBool CScanDrive::IsEofF(TInt aVal) const |
0 | 1169 |
{ |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1170 |
return iMount->IsEndOfClusterCh(aVal); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1171 |
} |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1172 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1173 |
/** @return max. number of clusters on the volume being scanned */ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1174 |
TUint32 CScanDrive::MaxClusters() const |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1175 |
{ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1176 |
ASSERT(iMaxClusters); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1177 |
return iMaxClusters; |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1178 |
} |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1179 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1180 |
/** @return ETrue in we are operating in "CheckDisk" mode*/ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1181 |
TBool CScanDrive::CheckDiskMode() const |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1182 |
{ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
6
diff
changeset
|
1183 |
return iScanDriveMode == ECheckDisk; |
0 | 1184 |
} |
1185 |
||
1186 |
||
1187 |
||
1188 |
||
1189 |
||
1190 |
||
1191 |
||
1192 |
||
1193 |