|
1 // Copyright (c) 1996-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_std.inl |
|
15 // |
|
16 // |
|
17 |
|
18 #ifndef SL_STD_INL |
|
19 #define SL_STD_INL |
|
20 |
|
21 |
|
22 |
|
23 TBool IsPowerOf2(TUint32 aVal) |
|
24 { |
|
25 if (aVal==0) |
|
26 return EFalse; |
|
27 |
|
28 return !(aVal & (aVal-1)); |
|
29 } |
|
30 |
|
31 TUint32 Pow2(TUint32 aVal) |
|
32 { |
|
33 //ASSERT(aVal<32); |
|
34 return 1 << aVal; |
|
35 } |
|
36 |
|
37 |
|
38 //--------------------------------------------------------------------------------------------------------------------------------- |
|
39 // class TEntryPos |
|
40 TUint32 TEntryPos::Cluster() const |
|
41 { |
|
42 return (TUint32) iCluster; |
|
43 } |
|
44 |
|
45 TUint32 TEntryPos::Pos() const |
|
46 { |
|
47 return (TUint32) iPos; |
|
48 } |
|
49 |
|
50 TBool TEntryPos::operator==(const TEntryPos& aRhs) const |
|
51 { |
|
52 ASSERT(this != &aRhs); |
|
53 return (iCluster == aRhs.iCluster && iPos == aRhs.iPos); |
|
54 } |
|
55 |
|
56 |
|
57 //--------------------------------------------------------------------------------------------------------------------------------- |
|
58 // class CFatMountCB |
|
59 |
|
60 inline TInt CFatMountCB::RootDirectorySector() const |
|
61 {return iVolParam.RootDirectorySector();} |
|
62 |
|
63 inline TUint CFatMountCB::RootDirEnd() const |
|
64 {return iVolParam.RootDirEnd();} |
|
65 |
|
66 inline TUint32 CFatMountCB::RootClusterNum() const |
|
67 {return iVolParam.RootClusterNum(); } |
|
68 |
|
69 |
|
70 inline TInt CFatMountCB::StartCluster(const TFatDirEntry & anEntry) const |
|
71 {return anEntry.StartCluster();} |
|
72 |
|
73 |
|
74 |
|
75 /** |
|
76 returns true for root dir on Fat12/16 (fixed root dir versions of Fat). |
|
77 this function is used to handle special cases for reading/writing the root directory on FAT via the use of cluster zero. |
|
78 |
|
79 @param aEntry position on volume being queried |
|
80 @return Whether Root dir position or not |
|
81 */ |
|
82 TBool CFatMountCB::IsRootDir(const TEntryPos &aEntry) const |
|
83 {return((aEntry.iCluster==0) ? (TBool)ETrue : (TBool)EFalse);} |
|
84 |
|
85 /** |
|
86 Indicates the root directory cluster, For Fat12/16 root is always indicated by cluster number zero |
|
87 @return The root cluster indicator |
|
88 */ |
|
89 TInt CFatMountCB::RootIndicator() const |
|
90 {return 0;} |
|
91 |
|
92 |
|
93 TBool CFatMountCB::Is16BitFat() const |
|
94 {return(iFatType == EFat16);} |
|
95 |
|
96 /** @return Log2 of cluster size on volume */ |
|
97 TInt CFatMountCB::ClusterSizeLog2() const |
|
98 {return(iVolParam.ClusterSizeLog2());} |
|
99 |
|
100 /** @return Log2 of media sector size */ |
|
101 TInt CFatMountCB::SectorSizeLog2() const |
|
102 {return(iVolParam.SectorSizeLog2());} |
|
103 |
|
104 /** @return sector per cluster */ |
|
105 TInt CFatMountCB::SectorsPerCluster() const |
|
106 {return(1<<(iVolParam.ClusterSizeLog2()-iVolParam.SectorSizeLog2()));} |
|
107 |
|
108 /** @return the base position of a cluster */ |
|
109 TInt CFatMountCB::ClusterBasePosition() const |
|
110 {return(iFirstFreeByte);} |
|
111 |
|
112 /** @return the offset into a cluster of a byte address */ |
|
113 TInt CFatMountCB::ClusterRelativePos(TInt aPos) const |
|
114 {return(aPos&((1<<ClusterSizeLog2())-1));} |
|
115 |
|
116 /** |
|
117 Calculates the maximum number of clusters |
|
118 @return maximum number of clusters |
|
119 */ |
|
120 TUint32 CFatMountCB::MaxClusterNumber() const |
|
121 {return(TotalSectors()>>(ClusterSizeLog2()-SectorSizeLog2()));} |
|
122 |
|
123 /** @return the the total sectors on volume */ |
|
124 TInt CFatMountCB::TotalSectors() const |
|
125 {return iVolParam.TotalSectors();} |
|
126 |
|
127 /** @return total size of a Fat in bytes */ |
|
128 TInt CFatMountCB::FatSizeInBytes() const |
|
129 {return iVolParam.FatSizeInBytes();} |
|
130 |
|
131 /** @return first sector of the Fat */ |
|
132 TUint32 CFatMountCB::FirstFatSector() const |
|
133 {return iVolParam.FirstFatSector();} |
|
134 |
|
135 /** @return the byte offset of the Fat */ |
|
136 TInt CFatMountCB::StartOfFatInBytes() const |
|
137 {return(FirstFatSector()<<SectorSizeLog2());} |
|
138 |
|
139 /** @return Number of Fats used by the volume */ |
|
140 TInt CFatMountCB::NumberOfFats() const |
|
141 {return iVolParam.NumberOfFats();} |
|
142 |
|
143 |
|
144 /** @return refrence to the fat table owned by the mount */ |
|
145 CFatTable& CFatMountCB::FAT() const |
|
146 {return(*iFatTable);} |
|
147 /** |
|
148 Returns a refrence to the file system object owned by the coresponding TDrive for a drive used for creating subsession objects |
|
149 @return refrence to file system object |
|
150 */ |
|
151 CFatFileSystem& CFatMountCB::FatFileSystem() const |
|
152 {return((CFatFileSystem&)Drive().FSys());} |
|
153 |
|
154 |
|
155 /** @return refrence to a raw disk object owned by the mount */ |
|
156 CRawDisk& CFatMountCB::RawDisk() const |
|
157 {return(*iRawDisk);} |
|
158 |
|
159 /** |
|
160 @return ETrue if aCluster value is bad cluster marker defined in FAT specification |
|
161 */ |
|
162 TBool CFatMountCB::IsBadCluster(TInt aCluster) const |
|
163 {return Is16BitFat() ? aCluster==0xFFF7 : aCluster==0xFF7;} |
|
164 |
|
165 /** |
|
166 Returns whether the current mount is running as rugged Fat or not, this is held in the file system object |
|
167 @return Is rugged fat flag |
|
168 */ |
|
169 TBool CFatMountCB::IsRuggedFSys() const |
|
170 {return Drive().IsRugged();} |
|
171 |
|
172 /** |
|
173 Sets the rugged flag in the file system object |
|
174 @param Flag to set or clear the rugged flag |
|
175 */ |
|
176 void CFatMountCB::SetRuggedFSys(TBool aVal) |
|
177 {Drive().SetRugged(aVal);} |
|
178 |
|
179 /** @return the usable clusters count for a volume */ |
|
180 TUint32 CFatMountCB::UsableClusters() const |
|
181 {return(iUsableClusters);} |
|
182 |
|
183 |
|
184 TUint CFatMountCB::StartOfRootDirInBytes() const |
|
185 {return iVolParam.RootDirectorySector()<<SectorSizeLog2();} |
|
186 |
|
187 |
|
188 /** @return FAT type for this mount */ |
|
189 TFatType CFatMountCB::FatType() const |
|
190 { |
|
191 return iFatType; |
|
192 } |
|
193 |
|
194 CAsyncNotifier* CFatMountCB::Notifier() const |
|
195 {return iNotifier;} |
|
196 |
|
197 |
|
198 /** |
|
199 Set or reset Read Only mode for the mount. |
|
200 @param aReadOnlyMode if ETrue, the mount will be set RO. |
|
201 */ |
|
202 void CFatMountCB::SetReadOnly(TBool aReadOnlyMode) |
|
203 { |
|
204 iReadOnly = aReadOnlyMode; |
|
205 } |
|
206 |
|
207 |
|
208 /** |
|
209 @return ETrue if the volume is in Read-Only state |
|
210 */ |
|
211 TBool CFatMountCB::ReadOnly(void) const |
|
212 { |
|
213 return iReadOnly; |
|
214 } |
|
215 |
|
216 /** @return state of the CFatMountCB*/ |
|
217 CFatMountCB::TFatMntState CFatMountCB::State() const |
|
218 { |
|
219 return iState; |
|
220 } |
|
221 |
|
222 /** |
|
223 Set state of the CFatMountCB |
|
224 @param aState state to set |
|
225 */ |
|
226 void CFatMountCB::SetState(TFatMntState aState) |
|
227 { |
|
228 //__PRINT3(_L("#- CFatMountCB::SetState() drv:%d, %d->%d\n"),DriveNumber(),iState,aState); |
|
229 iState = aState; |
|
230 } |
|
231 |
|
232 |
|
233 TFatDriveInterface& CFatMountCB::DriveInterface() const |
|
234 { |
|
235 return (TFatDriveInterface&)iDriverInterface; |
|
236 } |
|
237 |
|
238 const TFatConfig& CFatMountCB::FatConfig() const |
|
239 { |
|
240 return iFatConfig; |
|
241 } |
|
242 |
|
243 //--------------------------------------------------------------------------------------------------------------------------------- |
|
244 /** |
|
245 Check if the XFileCreationHelper object is initialised. |
|
246 */ |
|
247 TBool CFatMountCB::XFileCreationHelper::IsInitialised() const |
|
248 { |
|
249 return isInitialised; |
|
250 } |
|
251 |
|
252 /** |
|
253 Get number of new entries for file creation. |
|
254 */ |
|
255 TUint16 CFatMountCB::XFileCreationHelper::NumOfAddingEntries() const |
|
256 { |
|
257 ASSERT(isInitialised); |
|
258 return iNumOfAddingEntries; |
|
259 } |
|
260 |
|
261 /** |
|
262 Get position of new entries for file creation. |
|
263 */ |
|
264 TEntryPos CFatMountCB::XFileCreationHelper::EntryAddingPos() const |
|
265 { |
|
266 ASSERT(isInitialised); |
|
267 return iEntryAddingPos; |
|
268 } |
|
269 |
|
270 /** |
|
271 Check if position of new entries has been found. |
|
272 */ |
|
273 TBool CFatMountCB::XFileCreationHelper::IsNewEntryPosFound() const |
|
274 { |
|
275 ASSERT(isInitialised); |
|
276 return isNewEntryPosFound; |
|
277 } |
|
278 |
|
279 /** |
|
280 Check if file name of the new file is a legal dos name. |
|
281 */ |
|
282 TBool CFatMountCB::XFileCreationHelper::IsTrgNameLegalDosName() const |
|
283 { |
|
284 ASSERT(isInitialised); |
|
285 return isTrgNameLegalDosName; |
|
286 } |
|
287 |
|
288 /** |
|
289 Set entry position for new entries to be added. |
|
290 */ |
|
291 void CFatMountCB::XFileCreationHelper::SetEntryAddingPos(const TEntryPos& aEntryPos) |
|
292 { |
|
293 iEntryAddingPos = aEntryPos; |
|
294 } |
|
295 |
|
296 /** |
|
297 Set condition if position of new entries has been found. |
|
298 */ |
|
299 void CFatMountCB::XFileCreationHelper::SetIsNewEntryPosFound(TBool aFound) |
|
300 { |
|
301 isNewEntryPosFound = aFound; |
|
302 } |
|
303 |
|
304 |
|
305 |
|
306 //------- debug methods |
|
307 #ifdef _DEBUG |
|
308 /** |
|
309 Debug function indicates whether write fails are active or not, for test |
|
310 @return ETrue if write fails on or not |
|
311 */ |
|
312 TBool CFatMountCB::IsWriteFail()const |
|
313 {return(iIsWriteFail);} |
|
314 /** |
|
315 Switches write fails on or off, for test |
|
316 @param aIsWriteFail set true or false to set write fails on or off |
|
317 */ |
|
318 void CFatMountCB::SetWriteFail(TBool aIsWriteFail) |
|
319 {iIsWriteFail=aIsWriteFail;} |
|
320 |
|
321 /** @return number of write fails to occur, for test */ |
|
322 TInt CFatMountCB::WriteFailCount()const |
|
323 {return(iWriteFailCount);} |
|
324 |
|
325 /** |
|
326 Set the number of Write fails |
|
327 @param aFailCount number of write fails, for test |
|
328 */ |
|
329 void CFatMountCB::SetWriteFailCount(TInt aFailCount) |
|
330 {iWriteFailCount=aFailCount;} |
|
331 |
|
332 /** Decrement the number of write fails, for test */ |
|
333 void CFatMountCB::DecWriteFailCount() |
|
334 {--iWriteFailCount;} |
|
335 |
|
336 /** @return Error for a write failure, for test */ |
|
337 TInt CFatMountCB::WriteFailError()const |
|
338 {return iWriteFailError;} |
|
339 |
|
340 /** |
|
341 Set the write fail error code, for test |
|
342 @param aErrorValue The Error for a write fails |
|
343 */ |
|
344 void CFatMountCB::SetWriteFailError(TInt aErrorValue) |
|
345 {iWriteFailError=aErrorValue;} |
|
346 |
|
347 #endif |
|
348 |
|
349 |
|
350 //--------------------------------------------------------------------------------------------------------------------------------- |
|
351 // class CFatFormatCB |
|
352 |
|
353 TBool CFatFormatCB::Is16BitFat() const |
|
354 {return(iFileSystemName==KFileSystemName16);} |
|
355 |
|
356 CFatMountCB& CFatFormatCB::FatMount() |
|
357 {return *(CFatMountCB*)&Mount();} |
|
358 |
|
359 /** |
|
360 Returns the local drive used by the file systems from the owning mount |
|
361 @return Pointer to the local drive |
|
362 */ |
|
363 CProxyDrive* CFatFormatCB::LocalDrive() |
|
364 {return(FatMount().LocalDrive());} |
|
365 |
|
366 |
|
367 //--------------------------------------------------------------------------------------------------------------------------------- |
|
368 // class CFatFileCB |
|
369 |
|
370 /** |
|
371 Returns the owning mount from file object |
|
372 |
|
373 @return pointer to the owning mount object |
|
374 */ |
|
375 CFatMountCB& CFatFileCB::FatMount() const |
|
376 {return((CFatMountCB&)Mount());} |
|
377 |
|
378 /** |
|
379 Returns the fat table used by the file system for this mount |
|
380 |
|
381 @return Refrence to the Fat table owned by the mount |
|
382 */ |
|
383 CFatTable& CFatFileCB::FAT() |
|
384 {return(FatMount().FAT());} |
|
385 |
|
386 /** |
|
387 Position with in a cluster for a given address |
|
388 |
|
389 @param aPos Byte position |
|
390 */ |
|
391 TInt CFatFileCB::ClusterRelativePos(TInt aPos) |
|
392 {return(FatMount().ClusterRelativePos(aPos));} |
|
393 /** |
|
394 Returns Log2 of cluster size from mount |
|
395 |
|
396 @return cluster size |
|
397 */ |
|
398 TInt CFatFileCB::ClusterSizeLog2() |
|
399 {return(FatMount().ClusterSizeLog2());} |
|
400 |
|
401 /* |
|
402 Note: this replaces SeekIndex() which was only used in sl_mnt |
|
403 to verify whether the seek index had been created/initialised |
|
404 */ |
|
405 inline TBool CFatFileCB::IsSeekIndex() const |
|
406 {return (iSeekIndex==NULL?(TBool)EFalse:(TBool)ETrue); } |
|
407 |
|
408 |
|
409 //--------------------------------------------------------------------------------------------------------------------------------- |
|
410 // class CFatDirCB |
|
411 |
|
412 /** |
|
413 Returns the owning mount from directory object |
|
414 |
|
415 @return pointer to the owning mount object |
|
416 */ |
|
417 CFatMountCB& CFatDirCB::FatMount() |
|
418 {return((CFatMountCB&)Mount());} |
|
419 |
|
420 |
|
421 |
|
422 //--------------------------------------------------------------------------------------------------------------------------------- |
|
423 // class CFatTable |
|
424 |
|
425 TUint32 CFatTable::FreeClusters() const |
|
426 { |
|
427 return iFreeClusters; |
|
428 } |
|
429 |
|
430 |
|
431 TBool CFatTable::IsEof16Bit(TInt aCluster) const |
|
432 {return(aCluster>=0xFFF8 && aCluster<=0xFFFF);} |
|
433 |
|
434 TBool CFatTable::IsEof12Bit(TInt aCluster) const |
|
435 {return(aCluster>=0xFF8 && aCluster<=0xFFF);} |
|
436 |
|
437 TInt CFatTable::SectorSizeLog2() const |
|
438 {return(iOwner->SectorSizeLog2());} |
|
439 |
|
440 //--------------------------------------------------------------------------------------------------------------------------------- |
|
441 |
|
442 inline TBool CFatTable::IsFat12() const |
|
443 { |
|
444 return iFatType == EFat12; |
|
445 } |
|
446 |
|
447 inline TBool CFatTable::IsFat16() const |
|
448 { |
|
449 return iFatType == EFat16; |
|
450 } |
|
451 |
|
452 inline TFatType CFatTable::FatType() const |
|
453 { |
|
454 return iFatType; |
|
455 } |
|
456 /** |
|
457 @return Maximal number of addresable FAT entries. This value is taken from the owning mount |
|
458 */ |
|
459 inline TUint32 CFatTable::MaxEntries() const |
|
460 { |
|
461 ASSERT(iMaxEntries > 0); |
|
462 return iMaxEntries; |
|
463 } |
|
464 |
|
465 |
|
466 // class TFatDriveInterface |
|
467 TBool TFatDriveInterface::NotifyUser() const |
|
468 {return(iMount->GetNotifyUser());} |
|
469 |
|
470 |
|
471 |
|
472 //---------------------------------------------------------------------------------------------------- |
|
473 // class CRawDisk |
|
474 |
|
475 /** |
|
476 Get pointer to the directory cache interface. Any client that reads/writes directory entries |
|
477 MUST do it via this interface. |
|
478 Default implementation returns NULL |
|
479 |
|
480 @return pointer to the MWTCacheInterface interface, or NULL if it is not present. |
|
481 */ |
|
482 MWTCacheInterface* CRawDisk::DirCacheInterface() |
|
483 { |
|
484 return NULL; |
|
485 } |
|
486 |
|
487 //--------------------------------------------------------------------------------------------------------------------------------- |
|
488 //-- class RBitVector |
|
489 |
|
490 /** @return size of the vector (number of bits) */ |
|
491 inline TUint32 RBitVector::Size() const |
|
492 { |
|
493 return iNumBits; |
|
494 } |
|
495 |
|
496 /** |
|
497 Get a bit by index |
|
498 |
|
499 @param aIndex index in a bit vector |
|
500 @return 0 if the bit at pos aIndex is 0, not zero otherwise |
|
501 @panic EIndexOutOfRange if aIndex is out of range |
|
502 */ |
|
503 inline TBool RBitVector::operator[](TUint32 aIndex) const |
|
504 { |
|
505 __ASSERT_ALWAYS(aIndex < iNumBits, Panic(EIndexOutOfRange)); |
|
506 return (ipData[WordNum(aIndex)] & (1<<BitInWord(aIndex))); |
|
507 } |
|
508 |
|
509 /** |
|
510 Set a bit at pos aIndex to '1' |
|
511 @param aIndex index in a bit vector |
|
512 @panic EIndexOutOfRange if aIndex is out of range |
|
513 */ |
|
514 inline void RBitVector::SetBit(TUint32 aIndex) |
|
515 { |
|
516 __ASSERT_ALWAYS(aIndex < iNumBits, Panic(EIndexOutOfRange)); |
|
517 ipData[WordNum(aIndex)] |= (1<<BitInWord(aIndex)); |
|
518 } |
|
519 |
|
520 /** |
|
521 Set a bit at pos aIndex to '0' |
|
522 @param aIndex index in a bit vector |
|
523 @panic EIndexOutOfRange if aIndex is out of range |
|
524 */ |
|
525 inline void RBitVector::ResetBit(TUint32 aIndex) |
|
526 { |
|
527 __ASSERT_ALWAYS(aIndex < iNumBits, Panic(EIndexOutOfRange)); |
|
528 ipData[WordNum(aIndex)] &= ~(1<<BitInWord(aIndex)); |
|
529 } |
|
530 |
|
531 /** |
|
532 Invert a bit at pos aIndex |
|
533 @param aIndex index in a bit vector |
|
534 @panic EIndexOutOfRange if aIndex is out of range |
|
535 */ |
|
536 inline void RBitVector::InvertBit(TUint32 aIndex) |
|
537 { |
|
538 __ASSERT_ALWAYS(aIndex < iNumBits, Panic(EIndexOutOfRange)); |
|
539 ipData[WordNum(aIndex)] ^= (1<<BitInWord(aIndex)); |
|
540 } |
|
541 |
|
542 /** |
|
543 Set bit value at position aIndex |
|
544 @param aIndex index in a bit vector |
|
545 @panic EIndexOutOfRange if aIndex is out of range |
|
546 */ |
|
547 inline void RBitVector::SetBitVal(TUint32 aIndex, TBool aVal) |
|
548 { |
|
549 if(aVal) |
|
550 SetBit(aIndex); |
|
551 else |
|
552 ResetBit(aIndex); |
|
553 } |
|
554 |
|
555 |
|
556 inline TUint32 RBitVector::MaskLastWord(TUint32 aVal) const |
|
557 { |
|
558 const TUint32 shift = (32-(iNumBits & 0x1F)) & 0x1F; |
|
559 return (aVal << shift) >> shift; //-- mask unused high bits |
|
560 } |
|
561 |
|
562 |
|
563 |
|
564 inline TUint32 RBitVector::WordNum(TUint32 aBitPos) const |
|
565 { |
|
566 return aBitPos >> 5; |
|
567 } |
|
568 |
|
569 inline TUint32 RBitVector::BitInWord(TUint32 aBitPos) const |
|
570 { |
|
571 return aBitPos & 0x1F; |
|
572 } |
|
573 |
|
574 /** |
|
575 Calculate offset of the page starting position in the cluster |
|
576 @param aPos the current entry position in bytes in the cluster |
|
577 @param aPageSzLog2 page size in log2 |
|
578 @return the starting position of the page that contains aPos |
|
579 */ |
|
580 inline TUint32 CalculatePageOffsetInCluster(TUint32 aPos, TUint aPageSzLog2) |
|
581 { |
|
582 return (aPos >> aPageSzLog2) << aPageSzLog2; |
|
583 } |
|
584 |
|
585 #endif //SL_STD_INL |
|
586 |
|
587 |
|
588 |
|
589 |
|
590 |