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 |
#include "sl_std.h"
|
|
27 |
|
|
28 |
//---------------------------------------------------------------------------------------------------------------------------------
|
|
29 |
|
|
30 |
const TInt KMaxMatchingEntries = 2; ///< Maximum number of matching directory entries scan drive can fix. Any more indicates a fault in the file system
|
|
31 |
const TInt KMaxArrayDepth = 6; ///< Maximum array depth for cluster storage when KMaxScanDepth is reached
|
|
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 |
Data structure used to store the locations of entries with matching
|
|
45 |
start cluster numbers.
|
|
46 |
*/
|
|
47 |
struct TMatchingStartCluster
|
|
48 |
{
|
|
49 |
TEntryPos iEntries[KMaxMatchingEntries]; ///< The positions of the matching entries
|
|
50 |
TInt iCount; ///< Count of matching entries
|
|
51 |
TInt iStartCluster; ///< The matching cluster number found in more than one entry
|
|
52 |
};
|
|
53 |
|
|
54 |
/**
|
|
55 |
Scan drive class performs scan drive functionality on all types
|
|
56 |
of fat volume.
|
|
57 |
*/
|
|
58 |
class CScanDrive : public CBase
|
|
59 |
{
|
|
60 |
public:
|
|
61 |
/**
|
|
62 |
Error type found by scan drive, only a single error should occur in
|
|
63 |
any scan of the volume
|
|
64 |
*/
|
|
65 |
enum TDirError{EScanMatchingEntry=1,EScanPartEntry, ETruncation};
|
|
66 |
|
|
67 |
public:
|
|
68 |
|
|
69 |
~CScanDrive();
|
|
70 |
static CScanDrive* NewL(CFatMountCB* aMount);
|
|
71 |
void ConstructL(CFatMountCB* aMount);
|
|
72 |
|
|
73 |
TInt StartL();
|
|
74 |
TBool ProblemsDiscovered() const;
|
|
75 |
|
|
76 |
|
|
77 |
private:
|
|
78 |
#if defined(DEBUG_SCANDRIVE)
|
|
79 |
void PrintErrors();
|
|
80 |
void CompareFatsL() const;
|
|
81 |
#endif
|
|
82 |
void FixupDirErrorL();
|
|
83 |
|
|
84 |
void ReadMediaFatL();
|
|
85 |
void DoParseFatL();
|
|
86 |
void DoParseFat32L();
|
|
87 |
void DoParseFat32Buf(const TPtrC8& aBuf, TUint32& aCurrFatEntry);
|
|
88 |
|
|
89 |
TBool AlreadyUsedL(TUint aCluster) const;
|
|
90 |
void SetUsedL(TUint aCluster);
|
|
91 |
|
|
92 |
TUint32 ReadFatL(TInt aClusterNum) const;
|
|
93 |
void FindSameStartClusterL();
|
|
94 |
TInt FindStartClusterL(TInt aDirCluster);
|
|
95 |
void CheckDirStructureL();
|
|
96 |
void CheckDirL(TInt aCluster);
|
|
97 |
void ProcessEntryL(const TFatDirEntry& aEntry);
|
|
98 |
TInt CheckEntryClusterL(const TFatDirEntry& aEntry, const TEntryPos& aEntryPos);
|
|
99 |
void WriteClusterChainL(TInt aCluster,TUint aSizeInBytes);
|
|
100 |
TBool MoveToVFatEndL(TEntryPos& aPos,TFatDirEntry& aEntry,TInt& aDirLength);
|
|
101 |
TBool IsValidVFatEntry(const TFatDirEntry& aEntry,TInt prevNum)const;
|
|
102 |
TBool IsDosEntry(const TFatDirEntry& aEntry)const;
|
|
103 |
void AddPartialVFatL(const TEntryPos& aStartPos, const TFatDirEntry& aEntry);
|
|
104 |
TBool AddMatchingEntryL(const TEntryPos& aEntryPos);
|
|
105 |
TInt GetReservedidL(const TEntryPos aVFatPos);
|
|
106 |
void WriteNewFatsL();
|
|
107 |
void FixPartEntryL();
|
|
108 |
void FixMatchingEntryL();
|
|
109 |
void MovePastEntriesL(TEntryPos& aEntryPos,TFatDirEntry& aEntry,TInt aToMove,TInt& aDirEntries);
|
|
110 |
void AddToClusterListL(TInt aCluster);
|
|
111 |
inline TBool AlreadyExistsL(TInt aCluster)const;
|
|
112 |
inline TBool IsEndOfRootDir(const TEntryPos& aPos)const;
|
|
113 |
inline TBool IsEofF(TInt aVal)const;
|
|
114 |
inline TBool IsDirError()const;
|
|
115 |
void MoveToNextEntryL(TEntryPos& aPos);
|
|
116 |
void ReadDirEntryL(const TEntryPos& aPos,TFatDirEntry& aDirEntry);
|
|
117 |
|
|
118 |
void IndicateErrorsFound();
|
|
119 |
|
|
120 |
private:
|
|
121 |
CFatMountCB* iMount; ///< The owning Fat mount
|
|
122 |
TPartVFatEntry iPartEntry; ///< Storage for a partial VFat entry set error
|
|
123 |
TMatchingStartCluster iMatching; ///< Storage for Matching start cluster error
|
|
124 |
TDirError iDirError; ///< Indicates the error tpye found also used to indicate if an error has occured
|
|
125 |
TInt iDirsChecked; ///< Count of the number of directories checked
|
|
126 |
TInt iRecursiveDepth; ///< Depth of recursion the scan has reached
|
|
127 |
RArray<TInt>* iClusterListArray[KMaxArrayDepth]; ///< Size in bytes of the bit packed Fat Cluster list array used when maximum depth has been reached so that directory may be re-visited. Avoid stack overflow
|
|
128 |
TInt iListArrayIndex; ///< Current position into cluster list array
|
|
129 |
TInt iTruncationCluster; ///< Cluster at which cluster chain truncation should take place, used for truncation errors
|
|
130 |
|
|
131 |
TBool iFoundProblems; ///< if ETrue after finish, it means that there where some problems FS structure and they were probably fixed;
|
|
132 |
RBitVector iMediaFatBits; ///< Storage for bit packed Fat read from media
|
|
133 |
RBitVector iScanFatBits; ///< Storage for bit packed Fat built up by the scan
|
|
134 |
|
|
135 |
};
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
#endif //SL_SCANDRV_H
|
|
140 |
|
|
141 |
|