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\sfat\inc\sl_scandrv.h
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
/**
|
|
19 |
@file
|
|
20 |
@internalTechnology
|
|
21 |
*/
|
|
22 |
|
|
23 |
#ifndef SL_SCANDRV_H
|
|
24 |
#define SL_SCANDRV_H
|
|
25 |
|
|
26 |
//---------------------------------------------------------------------------------------------------------------------------------
|
|
27 |
|
|
28 |
const TInt KMaxMatchingEntries = 2; ///< Maximum number of matching directory entries scan drive can fix. Any more indicates a fault in the file system
|
|
29 |
const TInt KMaxArrayDepth = 6; ///< Maximum array depth for cluster storage when KMaxScanDepth is reached
|
|
30 |
|
|
31 |
//---------------------------------------------------------------------------------------------------------------------------------
|
|
32 |
|
|
33 |
/**
|
|
34 |
Data structure used to store the location of a partial VFat entry
|
|
35 |
*/
|
|
36 |
struct TPartVFatEntry
|
|
37 |
{
|
|
38 |
TEntryPos iEntryPos; ///< The position of the partial VFat entry
|
|
39 |
TFatDirEntry iEntry; ///< The Dos entry The VFat entries belong with
|
|
40 |
};
|
|
41 |
|
|
42 |
//---------------------------------------------------------------------------------------------------------------------------------
|
|
43 |
|
|
44 |
/**
|
|
45 |
Data structure used to store the locations of entries with matching
|
|
46 |
start cluster numbers.
|
|
47 |
*/
|
|
48 |
struct TMatchingStartCluster
|
|
49 |
{
|
|
50 |
TEntryPos iEntries[KMaxMatchingEntries]; ///< The positions of the matching entries
|
|
51 |
TInt iCount; ///< Count of matching entries
|
|
52 |
TInt iStartCluster; ///< The matching cluster number found in more than one entry
|
|
53 |
};
|
|
54 |
|
|
55 |
|
|
56 |
//---------------------------------------------------------------------------------------------------------------------------------
|
|
57 |
|
|
58 |
class CCheckFatTable : public CBase
|
|
59 |
{
|
|
60 |
public:
|
|
61 |
static CCheckFatTable* NewL(CFatMountCB* aOwner);
|
|
62 |
CCheckFatTable(CFatMountCB* aOwner);
|
|
63 |
~CCheckFatTable();
|
|
64 |
void InitializeL();
|
|
65 |
TBool FlushL();
|
|
66 |
TBool GetNextClusterL(TInt& aCluster) const;
|
|
67 |
void WriteFatEntryEofFL(TInt aCluster);
|
|
68 |
TInt ReadL(TInt aFatIndex) const;
|
|
69 |
void WriteL(TInt aFatIndex,TInt aValue);
|
|
70 |
private:
|
|
71 |
void WriteMediaDescriptor();
|
|
72 |
TInt PosInBytes(TInt aFatIndex) const;
|
|
73 |
TInt PosInIndex(TInt aBytePos) const;
|
|
74 |
inline TBool IsEof16Bit(TInt aCluster) const;
|
|
75 |
inline TBool IsEof12Bit(TInt aCluster) const;
|
|
76 |
inline TInt MaxFatIndex() const;
|
|
77 |
protected:
|
|
78 |
TInt iMaxFatIndex;
|
|
79 |
TUint8* iCheckFat;
|
|
80 |
CFatMountCB* iOwner;
|
|
81 |
};
|
|
82 |
|
|
83 |
|
|
84 |
//---------------------------------------------------------------------------------------------------------------------------------
|
|
85 |
|
|
86 |
/**
|
|
87 |
Scan drive class performs scan drive functionality on all types
|
|
88 |
of fat volume.
|
|
89 |
*/
|
|
90 |
class CScanDrive : public CBase
|
|
91 |
{
|
|
92 |
public:
|
|
93 |
enum TDirError{EScanMatchingEntry=1,EScanPartEntry};
|
|
94 |
public:
|
|
95 |
CScanDrive();
|
|
96 |
~CScanDrive();
|
|
97 |
static CScanDrive* NewL(CFatMountCB* aMount);
|
|
98 |
void ConstructL(CFatMountCB* aMount);
|
|
99 |
TInt StartL();
|
|
100 |
TBool ProblemsDiscovered() const;
|
|
101 |
|
|
102 |
|
|
103 |
private:
|
|
104 |
|
|
105 |
#if defined(DEBUG_SCANDRIVE)
|
|
106 |
void PrintErrors();
|
|
107 |
void CompareFatsL() const;
|
|
108 |
#endif
|
|
109 |
|
|
110 |
void FixupDirErrorL();
|
|
111 |
void FindSameStartClusterL();
|
|
112 |
TInt FindStartClusterL(TInt aDirCluster);
|
|
113 |
void CheckDirStructureL();
|
|
114 |
void CheckDirL(TInt aCluster);
|
|
115 |
void ProcessEntryL(const TFatDirEntry& aEntry);
|
|
116 |
TInt CheckEntryClusterL(const TFatDirEntry& aEntry, const TEntryPos& aEntryPos);
|
|
117 |
void WriteClusterChainL(TInt aCluster,TInt aSizeInBytes);
|
|
118 |
TBool MoveToVFatEndL(TEntryPos& aPos,TFatDirEntry& aEntry,TInt& aDirLength);
|
|
119 |
TBool IsValidVFatEntry(const TFatDirEntry& aEntry,TInt prevNum)const;
|
|
120 |
TBool IsDosEntry(const TFatDirEntry& aEntry)const;
|
|
121 |
void AddPartialVFatL(const TEntryPos& aStartPos, const TFatDirEntry& aEntry);
|
|
122 |
TBool AddMatchingEntryL(const TEntryPos& aEntryPos);
|
|
123 |
TInt GetReservedidL(const TEntryPos aVFatPos);
|
|
124 |
void WriteNewFatsL();
|
|
125 |
void FixPartEntryL();
|
|
126 |
void FixMatchingEntryL();
|
|
127 |
void MovePastEntriesL(TEntryPos& aEntryPos,TFatDirEntry& aEntry,TInt aToMove,TInt& aDirEntries);
|
|
128 |
void AddToClusterListL(TInt aCluster);
|
|
129 |
inline TBool AlreadyExistsL(TInt aCluster)const;
|
|
130 |
inline TBool IsEndOfRootDir(const TEntryPos& aPos)const;
|
|
131 |
inline TBool IsEofF(TInt aVal)const;
|
|
132 |
inline TBool IsDirError()const;
|
|
133 |
void IndicateErrorsFound();
|
|
134 |
|
|
135 |
private:
|
|
136 |
CFatMountCB* iMount;
|
|
137 |
CCheckFatTable* iNewFat;
|
|
138 |
TPartVFatEntry iPartEntry;
|
|
139 |
TMatchingStartCluster iMatching;
|
|
140 |
TDirError iDirError;
|
|
141 |
TInt iDirsChecked;
|
|
142 |
TInt iRecursiveDepth;
|
|
143 |
RArray<TInt>* iClusterListArray[KMaxArrayDepth];
|
|
144 |
TInt iListArrayIndex;
|
|
145 |
TBool iFoundProblems; ///< if ETrue after finish, it means that there where some problems FS structure and they were probably fixed;
|
|
146 |
};
|
|
147 |
|
|
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
|
152 |
#endif //SL_SCANDRV_H
|
|
153 |
|
|
154 |
|