|
1 /* |
|
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef SL_BPB1_H |
|
20 #define SL_BPB1_H |
|
21 |
|
22 #include <f32fsys.h> |
|
23 #include <f32ver.h> |
|
24 #include <f32dbg.h> |
|
25 #include <e32svr.h> |
|
26 |
|
27 #pragma warning (disable:4103) // : used #pragma pack to change alignment |
|
28 |
|
29 static const TInt KFatDirNameSize=11; |
|
30 static const TInt KFatDirReservedSize=10; |
|
31 static const TInt KVolumeLabelSize=11; |
|
32 static const TInt KFileSysTypeSize=8; |
|
33 static const TInt KVendorIdSize=8; |
|
34 static const TInt KVFatEntryAttribute=0x0F; |
|
35 static const TInt KBootSectorSignature=0xAA55; |
|
36 |
|
37 class TFatDirEntry; |
|
38 enum TFault |
|
39 { |
|
40 EVFatNoLongName, |
|
41 EFatChkDskFailed, |
|
42 EFatBadParameter, |
|
43 EFatCacheBadRead, |
|
44 EFatCacheNotFatSector, |
|
45 EFatBadLocalDrive, |
|
46 EFatBadBootSectorParameter, |
|
47 EFatBadDirEntryParameter, |
|
48 EFatAddClusterNotLastInList, |
|
49 EFatBadEntryValue, |
|
50 EFatBadClusterValue, |
|
51 EFatBadStdFormatName, |
|
52 EFatBadDosFormatName, |
|
53 EFatCorrupt, |
|
54 EFatChkDskBitListOverFlow, |
|
55 EFatChkDskIndexOverFlow, |
|
56 EFatChkDskIllegalClusterNumber, |
|
57 EFatChkDskClusterAlreadyInUse, |
|
58 EFatChkDskBadCluster, |
|
59 EFatChkDskInvalidEntrySize, |
|
60 EFatDesTooBig, |
|
61 EFatFilePosBeyondEnd, |
|
62 EFatFileSeekIndexTooSmall, |
|
63 EFatFileSeekIndexTooSmall2, |
|
64 EFatDataAllocBadSeg, |
|
65 EFatFileSystemBadMemory, |
|
66 EFatFileSystemCreate1, |
|
67 EFatFileSystemCreate2, |
|
68 EFatFileSystemCreate3, |
|
69 ECacheAllocatorSetMax, |
|
70 EFatLruCacheBadGranularity, |
|
71 EFatFixedCacheBadGranularity, |
|
72 EFatFixedCacheBadCall, |
|
73 EFatRawReadTooBig, |
|
74 EFatRawWriteTooBig, |
|
75 EWinsBadRamDriveRead, |
|
76 EWinsBadRamDriveWrite, |
|
77 EFatReadUidFailed, |
|
78 ELruCacheFlushNotSupported |
|
79 }; |
|
80 |
|
81 struct SFatDirEntry |
|
82 { |
|
83 TUint8 iName[KFatDirNameSize]; |
|
84 TUint8 iAttributes; |
|
85 TUint8 iReserved[KFatDirReservedSize]; |
|
86 TUint16 iTime; |
|
87 TUint16 iDate; |
|
88 TUint16 iStartCluster; |
|
89 TUint32 iSize; |
|
90 }; |
|
91 #define pDir ((SFatDirEntry*)&iData[0]) |
|
92 |
|
93 // |
|
94 typedef TBuf8<KFatDirNameSize> TShortName; |
|
95 // |
|
96 const TInt KSizeOfFatBootSector=62; |
|
97 const TInt KSizeOfFatDirEntry=32; |
|
98 class TFatBootSector |
|
99 { |
|
100 public: |
|
101 inline const TPtrC8 VendorId() const; |
|
102 inline TInt BytesPerSector() const{return iBytesPerSector;} |
|
103 inline TInt SectorsPerCluster() const{return iSectorsPerCluster;} |
|
104 inline TInt ReservedSectors() const {return iReservedSectors;}; |
|
105 inline TInt NumberOfFats() const {return iNumberOfFats;} |
|
106 inline TInt RootDirEntries() const{return iRootDirEntries;} |
|
107 inline TInt TotalSectors() const{return iTotalSectors;} |
|
108 inline TUint8 MediaDescriptor() const {return iMediaDescriptor;} |
|
109 inline TInt FatSectors() const {return iFatSectors;} |
|
110 inline TInt SectorsPerTrack() const {return iSectorsPerTrack;} |
|
111 inline TInt NumberOfHeads() const{return iNumberOfHeads;} |
|
112 inline TInt HiddenSectors() const {return iHiddenSectors;} |
|
113 inline TInt HugeSectors() const{return iHugeSectors;} |
|
114 inline TInt PhysicalDriveNumber() const; |
|
115 inline TInt ExtendedBootSignature() const; |
|
116 inline TUint32 UniqueID() const; |
|
117 inline const TPtrC8 VolumeLabel() const; |
|
118 inline const TPtrC8 FileSysType() const {return TPtrC8(iFileSysType,KFileSysTypeSize);} |
|
119 inline TInt BootSectorSignature() const; |
|
120 inline void SetJumpInstruction(); |
|
121 inline void SetVendorID(const TDesC8& aDes); |
|
122 inline void SetBytesPerSector(TInt aBytesPerSector); |
|
123 inline void SetSectorsPerCluster(TInt aSectorsPerCluster); |
|
124 inline void SetReservedSectors(TInt aReservedSectors); |
|
125 inline void SetNumberOfFats(TInt aNumberOfFats); |
|
126 inline void SetRootDirEntries(TInt aRootDirEntries); |
|
127 inline void SetTotalSectors(TInt aTotalSectors); |
|
128 inline void SetMediaDescriptor(TUint8 aMediaDescriptor); |
|
129 inline void SetFatSectors(TInt aFatSectors); |
|
130 inline void SetSectorsPerTrack(TInt aSectorsPerTrack); |
|
131 inline void SetNumberOfHeads(TInt aNumberOfHeads); |
|
132 inline void SetHiddenSectors(TUint32 aHiddenSectors); |
|
133 inline void SetHugeSectors(TUint32 aTotalSectors); |
|
134 inline void SetPhysicalDriveNumber(TInt aPhysicalDriveNumber); |
|
135 inline void SetReservedByte(TUint8 aReservedByte); |
|
136 inline void SetExtendedBootSignature(TInt anExtendedBootSignature); |
|
137 inline void SetUniqueID(TUint32 anUniqueID); |
|
138 inline void SetVolumeLabel(const TDesC8& aDes); |
|
139 inline void SetFileSysType(const TDesC8& aDes); |
|
140 |
|
141 public: |
|
142 inline TBool Is16BitFat() {return(FileSysType()==_L8("FAT16 "));} |
|
143 TInt FirstFatSectorPos() |
|
144 { |
|
145 return(ReservedSectors()*BytesPerSector()); |
|
146 } |
|
147 inline TInt RootDirStartSector(); |
|
148 inline TInt FirstFreeSector(); |
|
149 public: |
|
150 TUint8 iJumpInstruction[3]; ///< Jump instruction used for bootable volumes |
|
151 TUint8 iVendorId[KVendorIdSize]; ///< Vendor ID of the file system that formatted the volume |
|
152 TUint16 iBytesPerSector; ///< Bytes per sector |
|
153 TUint8 iSectorsPerCluster; ///< Sectors per cluster ratio |
|
154 TUint16 iReservedSectors; ///< Number of reserved sectors on the volume |
|
155 TUint8 iNumberOfFats; ///< Number of Fats on the volume |
|
156 TUint16 iRootDirEntries; ///< Number of entries allowed in the root directory, specific to Fat12/16, zero for FAT32 |
|
157 TUint16 iTotalSectors; ///< Total sectors on the volume, zero for FAT32 |
|
158 TUint8 iMediaDescriptor; ///< Media descriptor |
|
159 TUint16 iFatSectors; ///< Sectors used for the Fat table, zero for FAT32 |
|
160 TUint16 iSectorsPerTrack; ///< Sectors per track |
|
161 TUint16 iNumberOfHeads; ///< Number of heads |
|
162 TUint32 iHiddenSectors; ///< Number of hidden sectors in the volume |
|
163 TUint32 iHugeSectors; ///< Total sectors in the volume, Used if totalSectors > 65535 |
|
164 TUint32 iFatSectors32; ///< Start of additional elements @ offset 36 for FAT32, Sectors in Fat table for 32 bit volume |
|
165 TUint16 iFATFlags; ///< Fat flags |
|
166 TUint16 iVersionNumber; ///< Version number of the file system |
|
167 TUint32 iRootClusterNum; ///< Cluster number of the root directory |
|
168 TUint16 iFSInfoSectorNum; ///< Sector number containing the FSIInfo structure |
|
169 TUint16 iBkBootRecSector; ///< Backup boot sector |
|
170 TUint8 iReserved2[12]; ///< Reserved space, End of Fat32 Only parameters section |
|
171 TUint8 iPhysicalDriveNumber; ///< Physical drive number, not used in OS |
|
172 TUint8 iReserved; ///< Reserved byte |
|
173 TUint8 iExtendedBootSignature; ///< Extended boot signiture |
|
174 TUint32 iUniqueID; ///< Unique volume ID |
|
175 TUint8 iVolumeLabel[KVolumeLabelSize]; ///< The volume's label |
|
176 TUint8 iFileSysType[KFileSysTypeSize]; ///< File system type |
|
177 }; |
|
178 |
|
179 void Fault(TAny* aTestStep,TFault anError); |
|
180 GLREF_C TBool IsPowerOfTwo(TInt aNum); |
|
181 GLREF_C TInt Log2(TInt aNum); |
|
182 GLREF_C TTime DosTimeToTTime(TInt aDosTime,TInt aDosDate); |
|
183 GLREF_C TInt DosTimeFromTTime(const TTime& aTime); |
|
184 GLREF_C TInt DosDateFromTTime(const TTime& aTime); |
|
185 |
|
186 class TFatDirEntry |
|
187 { |
|
188 public: |
|
189 const TPtrC8 Name() const |
|
190 {return TPtrC8((TUint8*)&(pDir->iName),11); |
|
191 } |
|
192 TInt Attributes() const |
|
193 { |
|
194 return pDir->iAttributes; |
|
195 } |
|
196 inline TTime Time() const; |
|
197 TInt StartCluster() const |
|
198 { |
|
199 return pDir->iStartCluster; |
|
200 } |
|
201 inline TUint32 Size() const; |
|
202 TBool IsErased() const |
|
203 { |
|
204 return (TBool)(iData[0]==0xe5); |
|
205 } |
|
206 inline TBool IsCurrentDirectory() const; |
|
207 inline TBool IsParentDirectory() const; |
|
208 TBool IsEndOfDirectory() const |
|
209 { |
|
210 return (TBool)(iData[0]==0x00); |
|
211 } |
|
212 TBool IsGarbage() const; |
|
213 inline void SetName(const TDesC8& aDes); |
|
214 inline void SetAttributes(TInt anAtt); |
|
215 inline void SetTime(const TTime& aTime); |
|
216 void SetStartCluster(TInt aStartCluster) |
|
217 { |
|
218 __ASSERT_DEBUG(!(aStartCluster&~KMaxTUint16),Fault( this,EFatBadDirEntryParameter)); |
|
219 pDir->iStartCluster=(TUint16)aStartCluster; |
|
220 } |
|
221 inline void SetSize(TUint32 aFilesize); |
|
222 inline void SetErased(); |
|
223 inline void SetCurrentDirectory(); |
|
224 inline void SetParentDirectory(); |
|
225 inline void SetEndOfDirectory(); |
|
226 inline void ZeroReserved(); |
|
227 public: |
|
228 void InitializeRootEntry(); |
|
229 void InitializeAsVFat(TUint8 aCheckSum); |
|
230 void SetVFatEntry(const TDesC& aName,TInt aRemainderLen); |
|
231 void ReadVFatEntry(TDes16& aVBuf); |
|
232 inline TBool IsLongNameStart() const; |
|
233 TBool IsVFatEntry() const |
|
234 { |
|
235 return (TBool)(Attributes()==0x0F && IsEndOfDirectory()==EFalse); |
|
236 } |
|
237 inline TInt NumFollowing() const; |
|
238 public: |
|
239 TUint8 iData[KSizeOfFatDirEntry]; |
|
240 }; |
|
241 |
|
242 #endif // SL_BPB1_H |