|
1 /* |
|
2 * Copyright (c) 2006-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 * This class represents the boot sector of a FAT32 image. |
|
16 * This class is derived from basebootsector class which is constitutes |
|
17 * the common boot sector fields for FAT16 and FAT32 class. |
|
18 * @internalComponent |
|
19 * @released |
|
20 * |
|
21 */ |
|
22 |
|
23 #include "fat32bootsector.h" |
|
24 #include <cstring> |
|
25 |
|
26 /** |
|
27 Constructor of the fat16 boot sector class |
|
28 |
|
29 @internalComponent |
|
30 @released |
|
31 */ |
|
32 TFAT32BootSector::TFAT32BootSector() |
|
33 { |
|
34 } |
|
35 |
|
36 /** |
|
37 Destructor of the fat16 boot sector class |
|
38 |
|
39 @internalComponent |
|
40 @released |
|
41 */ |
|
42 TFAT32BootSector::~TFAT32BootSector() |
|
43 { |
|
44 } |
|
45 /** |
|
46 Set the file system type |
|
47 |
|
48 @internalComponent |
|
49 @released |
|
50 */ |
|
51 void TFAT32BootSector::SetFileSysType() |
|
52 { |
|
53 strcpy(reinterpret_cast<char*>(iFileSysType),"FAT32 "); |
|
54 } |
|
55 |
|
56 |
|
57 //Number of entries allowed in the root directory, specific to Fat12/16, zero for FAT32 |
|
58 void TFAT32BootSector::SetRootDirEntries() |
|
59 { |
|
60 iRootDirEntries = KFat32RootDirEntries;; |
|
61 } |
|
62 |
|
63 |
|
64 //Sets the number of reserved sectors on the volume |
|
65 void TFAT32BootSector::SetReservedSectors() |
|
66 { |
|
67 iReservedSectors = KDefaultFat32ReservedSectors; |
|
68 } |
|
69 |
|
70 /** |
|
71 Set the sectors per cluster ratio |
|
72 |
|
73 @internalComponent |
|
74 @released |
|
75 |
|
76 @param aPartitionSize partition size in bytes |
|
77 */ |
|
78 void TFAT32BootSector::ComputeSectorsPerCluster(Long64 aPartitionSize) |
|
79 { |
|
80 if (aPartitionSize > K32GB) |
|
81 { |
|
82 iSectorsPerCluster = K64SectorsPerCluster; |
|
83 } |
|
84 else if(aPartitionSize > K16GB) |
|
85 { |
|
86 iSectorsPerCluster = K32SectorsPerCluster; |
|
87 } |
|
88 else if(aPartitionSize > K8GB) |
|
89 { |
|
90 iSectorsPerCluster = K16SectorsPerCluster; |
|
91 } |
|
92 else if ( aPartitionSize > K260MB) |
|
93 { |
|
94 iSectorsPerCluster = K8SectorsPerCluster; |
|
95 } |
|
96 else |
|
97 { |
|
98 iSectorsPerCluster = K1SectorsPerCluster; |
|
99 } |
|
100 } |
|
101 |
|
102 /** |
|
103 Set the sectors per cluster ratio |
|
104 |
|
105 |
|
106 To refer this mathematical computation, Please see: |
|
107 Microsoft Extensible Firmware Initiative FAT32 File System |
|
108 Specification document |
|
109 |
|
110 @internalComponent |
|
111 @released |
|
112 |
|
113 @param aPartitionSize partition size in bytes |
|
114 */ |
|
115 void TFAT32BootSector::ComputeFatSectors(Long64 aPartitionSize) |
|
116 { |
|
117 int iRootDirSectors = ((iRootDirEntries*32) + (iBytesPerSector - 1)) / iBytesPerSector; |
|
118 int Log2OfBytesPerSector = Log2(iBytesPerSector); |
|
119 Long64 TotalSectors64 = aPartitionSize >> Log2OfBytesPerSector; |
|
120 Long64 tmpval1 = TotalSectors64 - (iReservedSectors + iRootDirSectors); |
|
121 Long64 tmpval2 =(256 * iSectorsPerCluster) + iNumberOfFats; |
|
122 tmpval2 = tmpval2 / 2; |
|
123 Long64 FatSectors = (tmpval1 + (tmpval2 - 1)) / tmpval2; |
|
124 iFatSectors = 0; |
|
125 iFatSectors32 = (unsigned int)FatSectors; |
|
126 } |
|
127 /** |
|
128 Sets the Fat flags |
|
129 |
|
130 @internalComponent |
|
131 @released |
|
132 */ |
|
133 void TFAT32BootSector::SetExtFlags() |
|
134 { |
|
135 iExtFlags = KDefaultExtFlags; |
|
136 } |
|
137 |
|
138 /** |
|
139 Returns the Fat flags |
|
140 |
|
141 @internalComponent |
|
142 @released |
|
143 |
|
144 @return fat flags |
|
145 */ |
|
146 unsigned short TFAT32BootSector::ExtFlags() |
|
147 { |
|
148 return iExtFlags; |
|
149 } |
|
150 |
|
151 /** |
|
152 Sets the version number of the file system |
|
153 |
|
154 @internalComponent |
|
155 @released |
|
156 */ |
|
157 void TFAT32BootSector::SetFileSystemVersion() |
|
158 { |
|
159 iFileSystemVersion = KDefaultVersion; |
|
160 } |
|
161 |
|
162 /** |
|
163 Returns the version number of the file system |
|
164 |
|
165 @internalComponent |
|
166 @released |
|
167 |
|
168 @return file system version |
|
169 */ |
|
170 unsigned short TFAT32BootSector::FileSystemVersion() |
|
171 { |
|
172 return iFileSystemVersion; |
|
173 } |
|
174 |
|
175 /** |
|
176 Sets the cluster number of the root directory |
|
177 |
|
178 @internalComponent |
|
179 @released |
|
180 */ |
|
181 void TFAT32BootSector::SetRootCluster() |
|
182 { |
|
183 iRootCluster = KDefaultRootDirClusterNumber; |
|
184 } |
|
185 |
|
186 /** |
|
187 Returns the cluster number of the root directory |
|
188 |
|
189 @internalComponent |
|
190 @released |
|
191 |
|
192 @return cluster number allocated to root directory,usually 2. |
|
193 */ |
|
194 unsigned int TFAT32BootSector::RootCluster() |
|
195 { |
|
196 return iRootCluster; |
|
197 } |
|
198 |
|
199 /** |
|
200 Set the sector number containing the FSIInfo structure |
|
201 |
|
202 @internalComponent |
|
203 @released |
|
204 */ |
|
205 void TFAT32BootSector::SetFSInfo() |
|
206 { |
|
207 iFSInfo = KDefaultFSInfoSector; |
|
208 } |
|
209 |
|
210 /** |
|
211 Returns the sector number containing the FSIInfo structure |
|
212 |
|
213 @internalComponent |
|
214 @released |
|
215 |
|
216 @return FSInfo structure |
|
217 */ |
|
218 unsigned short TFAT32BootSector::FSInfo() |
|
219 { |
|
220 return iFSInfo; |
|
221 } |
|
222 |
|
223 /** |
|
224 Set the backup boot sector |
|
225 |
|
226 @internalComponent |
|
227 @released |
|
228 */ |
|
229 void TFAT32BootSector::SetBackUpBootSector() |
|
230 { |
|
231 iBackUpBootSector = KDefaultBkUpBootSec; |
|
232 } |
|
233 |
|
234 /** |
|
235 Returns the backup boot sector |
|
236 |
|
237 @internalComponent |
|
238 @released |
|
239 |
|
240 @return backup boot sector |
|
241 */ |
|
242 unsigned short TFAT32BootSector::BackUpBootSector() |
|
243 { |
|
244 return iBackUpBootSector; |
|
245 } |
|
246 |
|
247 /** |
|
248 Reserved for future expansion. Code that formats FAT32 volumes should always |
|
249 set all of the bytes of this field to 0. |
|
250 |
|
251 @internalComponent |
|
252 @released |
|
253 */ |
|
254 void TFAT32BootSector::SetFutureReserved() |
|
255 { |
|
256 for(int i = 0;i < KMaxSizeFutureExpansion;i++) |
|
257 iFutureReserved[i] = 0; |
|
258 } |
|
259 |
|
260 /** |
|
261 Returns field value reserved for future expansion |
|
262 |
|
263 @internalComponent |
|
264 @released |
|
265 |
|
266 @return zero as this field is initialized to null value here |
|
267 */ |
|
268 unsigned char* TFAT32BootSector::FutureReserved() |
|
269 { |
|
270 return iFutureReserved; |
|
271 } |
|
272 |
|
273 |
|
274 /**Returns the file system type |
|
275 |
|
276 @internalComponent |
|
277 @released |
|
278 |
|
279 @return file system type |
|
280 */ |
|
281 unsigned char* TFAT32BootSector::FileSysType() |
|
282 { |
|
283 return iFileSysType; |
|
284 } |