1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/userlibandfileserver/fileserver/sfat/inc/sl_std.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,1192 @@
1.4 +// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// f32\sfat\inc\sl_std.h
1.18 +//
1.19 +//
1.20 +
1.21 +/**
1.22 + @file
1.23 + @internalTechnology
1.24 +*/
1.25 +
1.26 +//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1.27 +//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1.28 +//!!
1.29 +//!! WARNING!! DO NOT edit this file !! '\sfat' component is obsolete and is not being used. '\sfat32'replaces it
1.30 +//!!
1.31 +//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1.32 +//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1.33 +
1.34 +
1.35 +#ifndef SL_STD_H
1.36 +#define SL_STD_H
1.37 +
1.38 +//
1.39 +// #define _DEBUG_RELEASE
1.40 +//
1.41 +
1.42 +#include "common.h"
1.43 +#include <f32ver.h>
1.44 +#include <e32svr.h>
1.45 +#include <kernel/localise.h>
1.46 +#include "filesystem_fat.h"
1.47 +
1.48 +#include "common_constants.h"
1.49 +#include "sl_bpb.h"
1.50 +#include "fat_config.h"
1.51 +#include "fat_dir_entry.h"
1.52 +
1.53 +using namespace FileSystem_FAT;
1.54 +
1.55 +#ifdef _DEBUG
1.56 +_LIT(KThisFsyName,"EFAT.FSY"); ///< This FSY name
1.57 +#endif
1.58 +
1.59 +class CFatMountCB;
1.60 +class CFatFileSystem;
1.61 +
1.62 +/**
1.63 +Represents the position of a directory entery in terms of a cluster and off set into it
1.64 +*/
1.65 +class TEntryPos
1.66 + {
1.67 +public:
1.68 + TEntryPos() {}
1.69 + TEntryPos(TInt aCluster,TUint aPos) : iCluster(aCluster), iPos(aPos) {}
1.70 +
1.71 + inline TUint32 Cluster() const;
1.72 + inline TUint32 Pos() const;
1.73 + inline TBool operator==(const TEntryPos& aRhs) const;
1.74 +
1.75 +public:
1.76 + TInt iCluster;
1.77 + TUint iPos;
1.78 + };
1.79 +
1.80 +
1.81 +/**
1.82 + Interface class between the file system and the local drive media interface,
1.83 + handles incomplete writes to media with the ability to notify the user.
1.84 + This class can't be instantinated by user; only CFatMountCB can do this; see CFatMountCB::DriveInterface()
1.85 +
1.86 +*/
1.87 +class TFatDriveInterface
1.88 + {
1.89 +public:
1.90 + enum TAction {ERetry=1};
1.91 +
1.92 +public:
1.93 +
1.94 + //-- public interface to the local drive. Provides media driver's error handling (critical and non-critical user notifiers)
1.95 + //-- and thread-safety if required.
1.96 + TInt ReadNonCritical(TInt64 aPos,TInt aLength,const TAny* aTrg,const RMessagePtr2 &aMessage,TInt anOffset) const;
1.97 + TInt ReadNonCritical(TInt64 aPos,TInt aLength,TDes8& aTrg) const;
1.98 + TInt ReadCritical(TInt64 aPos,TInt aLength,TDes8& aTrg) const;
1.99 +
1.100 + TInt WriteCritical(TInt64 aPos,const TDesC8& aSrc);
1.101 + TInt WriteNonCritical(TInt64 aPos,TInt aLength,const TAny* aSrc,const RMessagePtr2 &aMessage,TInt anOffset);
1.102 +
1.103 + TInt GetLastErrorInfo(TDes8& aErrorInfo) const;
1.104 +
1.105 + //-- lock the mutex guarding CProxyDrive interface in order to be sure that no other thread can access it.
1.106 + //-- The thread that calls this method may be suspended until another signals the mutex, i.e. leaves the critical section.
1.107 + inline void AcquireLock() const {} //-- dummy
1.108 +
1.109 + //-- release the mutex guarding CProxyDrive.
1.110 + inline void ReleaseLock() const {} //-- dummy
1.111 +
1.112 +
1.113 +protected:
1.114 + TFatDriveInterface();
1.115 + TFatDriveInterface(const TFatDriveInterface&);
1.116 + TFatDriveInterface& operator=(const TFatDriveInterface&);
1.117 +
1.118 + TBool Init(CFatMountCB* aMount);
1.119 + void Close();
1.120 +
1.121 + inline TBool NotifyUser() const;
1.122 + TInt HandleRecoverableError(TInt aRes) const;
1.123 + TInt HandleCriticalError(TInt aRes) const;
1.124 + TInt UnlockAndReMount() const;
1.125 + TBool IsDriveWriteProtected() const;
1.126 + TBool IsRecoverableRemount() const;
1.127 +
1.128 +private:
1.129 +
1.130 + /**
1.131 + An internal class that represents a thread-safe wrapper around raw interface to the CProxyDrive
1.132 + and restricts access to it.
1.133 + */
1.134 + class XProxyDriveWrapper
1.135 + {
1.136 + public:
1.137 +
1.138 + XProxyDriveWrapper();
1.139 + ~XProxyDriveWrapper();
1.140 +
1.141 + TBool Init(CProxyDrive* aProxyDrive);
1.142 +
1.143 + inline void EnterCriticalSection() const {} //-- dummy
1.144 + inline void LeaveCriticalSection() const {} //-- dummy
1.145 +
1.146 + //-- methods' wrappers that are used by TFatDriveInterface
1.147 + TInt Read(TInt64 aPos,TInt aLength,const TAny* aTrg,const RMessagePtr2 &aMessage,TInt anOffset) const;
1.148 + TInt Read(TInt64 aPos,TInt aLength,TDes8& aTrg) const;
1.149 + TInt Write(TInt64 aPos,TInt aLength,const TAny* aSrc,const RMessagePtr2 &aMessage,TInt anOffset);
1.150 + TInt Write(TInt64 aPos, const TDesC8& aSrc);
1.151 + TInt GetLastErrorInfo(TDes8& aErrorInfo) const;
1.152 + TInt Caps(TDes8& anInfo) const;
1.153 +
1.154 + private:
1.155 +
1.156 + CProxyDrive* iLocalDrive; ///< raw interface to the media operations
1.157 + mutable RMutex iLock; ///< used for sorting out multithreaded access to the iLocalDrive
1.158 + };
1.159 +
1.160 + CFatMountCB* iMount; ///< Pointer to the owning file system mount
1.161 + XProxyDriveWrapper iProxyDrive; ///< wrapper around raw interface to the media operations
1.162 +
1.163 + };
1.164 +
1.165 +
1.166 +
1.167 +/**
1.168 + Class providing FAT table interface and basic functionality.
1.169 +*/
1.170 +class CFatTable : public CBase
1.171 + {
1.172 +public:
1.173 + static CFatTable* NewL(CFatMountCB& aOwner, const TLocalDriveCaps& aLocDrvCaps);
1.174 +
1.175 + virtual ~CFatTable();
1.176 +
1.177 + /** Empty and deallocate the cache*/
1.178 + virtual void Dismount(TBool /*aDiscardDirtyData*/) {}
1.179 +
1.180 + /** Flush data cahed data to the media */
1.181 + virtual void FlushL() {};
1.182 +
1.183 + /**
1.184 + Invalidate specified region of the FAT cache
1.185 + Depending of cache type this may just mark part of the cache invalid with reading on demand later
1.186 + or re-read whole cache from the media.
1.187 +
1.188 + @param aPos absolute media position where the region being invalidated starts.
1.189 + @param aLength length in bytes of region to invalidate / refresh
1.190 + */
1.191 + virtual void InvalidateCacheL(TInt64 /*aPos*/,TUint32 /*aLength*/) {};
1.192 +
1.193 +
1.194 + /**
1.195 + Invalidate whole FAT cache.
1.196 + Depending of cache type this may just mark cache invalid with reading on demand or re-read whole cache from the media
1.197 + */
1.198 + virtual void InvalidateCacheL() {};
1.199 +
1.200 +
1.201 + /**
1.202 + Gets the next cluster in a cluster chain
1.203 +
1.204 + @param aCluster Cluster number to start lookup. On return contains number of the next cluster.
1.205 + @return EFalse if cluster is at the end of a cluster chain
1.206 + */
1.207 + virtual TBool GetNextClusterL(TInt& aCluster) const;
1.208 +
1.209 + /**
1.210 + Writes end of cluster chain
1.211 + @param aFatIndex index in Fat table where EOF will be written to.
1.212 + */
1.213 + virtual void WriteFatEntryEofL(TUint32 aFatIndex);
1.214 +
1.215 + /**
1.216 + Read an entry from the FAT.
1.217 +
1.218 + @param aFatIndex aFatIndex index in Fat table
1.219 + @return value of the FAT entry number aFatIndex
1.220 + */
1.221 + virtual TUint32 ReadL(TUint32 aFatIndex) const = 0;
1.222 +
1.223 + /**
1.224 + Write FAT entry to FAT by its index.
1.225 +
1.226 + @param aFatIndex index in FAT
1.227 + @param aValue value to write
1.228 + */
1.229 + virtual void WriteL(TUint32 aFatIndex, TUint32 aValue) = 0;
1.230 +
1.231 + /**
1.232 + return the byte position of a cluster in the fat table
1.233 +
1.234 + @param aCluster cluster to find position of
1.235 + @return byte position of the cluster
1.236 + */
1.237 + virtual TInt64 DataPositionInBytes(TUint32 aCluster) const = 0;
1.238 +
1.239 + virtual void FreeClusterListL(TUint32 aCluster);
1.240 + virtual void ExtendClusterListL(TUint32 aNumber,TInt& aCluster);
1.241 + virtual TUint32 AllocateSingleClusterL(TUint32 aNearestCluster);
1.242 + virtual TUint32 AllocateClusterListL(TUint32 aNumber,TUint32 aNearestCluster);
1.243 + virtual void CountFreeClustersL();
1.244 +
1.245 + virtual void RequestRawWriteAccess(TInt64 /*aPos*/, TUint32 /*aLen*/) const {};
1.246 +
1.247 +
1.248 +public:
1.249 +
1.250 + void MarkAsBadClusterL(TUint32 aCluster);
1.251 + TInt CountContiguousClustersL(TUint32 aStartCluster,TInt& anEndCluster, TUint32 aMaxCount) const;
1.252 +
1.253 + virtual TUint32 FreeClusterHint() const;
1.254 + virtual void SetFreeClusterHint(TUint32 aCluster);
1.255 +
1.256 + virtual TUint32 NumberOfFreeClusters(TBool aSyncOperation=EFalse) const;
1.257 + virtual void SetFreeClusters(TUint32 aFreeClusters);
1.258 +
1.259 + virtual TBool RequestFreeClusters(TUint32 aClustersRequired) const;
1.260 +
1.261 + inline TUint32 MaxEntries() const;
1.262 + virtual void InitializeL();
1.263 + virtual TBool ConsistentState() const {return ETrue;} //-- dummy
1.264 +
1.265 +protected:
1.266 + CFatTable(CFatMountCB& aOwner);
1.267 +
1.268 + //-- outlawed
1.269 + CFatTable();
1.270 + CFatTable(const CFatTable&);
1.271 + CFatTable& operator=(const CFatTable&);
1.272 +
1.273 +
1.274 +
1.275 + void DecrementFreeClusterCount(TUint32 aCount);
1.276 + void IncrementFreeClusterCount(TUint32 aCount);
1.277 +
1.278 + inline TUint32 FreeClusters() const;
1.279 +
1.280 + inline TBool IsEof16Bit(TInt aCluster) const;
1.281 + inline TBool IsEof12Bit(TInt aCluster) const;
1.282 + inline TInt SectorSizeLog2() const;
1.283 + inline TFatType FatType() const;
1.284 +
1.285 + TUint32 PosInBytes(TUint32 aFatIndex) const;
1.286 + TUint32 FindClosestFreeClusterL(TUint32 aCluster);
1.287 +
1.288 + inline TBool IsFat12() const;
1.289 + inline TBool IsFat16() const;
1.290 +
1.291 + inline TBool ClusterNumberValid(TUint32 aClusterNo) const;
1.292 +
1.293 + typedef RArray<TUint> RClusterArray;
1.294 + void DoFreedClustersNotify(RClusterArray &aFreedClusters);
1.295 +
1.296 +
1.297 +protected:
1.298 +
1.299 + CFatMountCB* iOwner; ///< Owning file system mount
1.300 + TUint iMediaAtt; ///< Cached copy of TLocalDriveCaps::iMediaAtt
1.301 +
1.302 +private:
1.303 +
1.304 + TUint32 iFreeClusters; ///< Number of free cluster in the fat table
1.305 + TUint32 iFreeClusterHint; ///< Next free custer in the fat table, just for use in TFsInfo; This is just a hint, not required to contain exact information.
1.306 + TFatType iFatType; ///< FAT type 12/16/32, cached from the iOwner
1.307 + TUint32 iMaxEntries; ///< maximal number of FAT entries in the table. This value is taken from the CFatMount that calculates it
1.308 +
1.309 + };
1.310 +
1.311 +
1.312 +class MWTCacheInterface;
1.313 +
1.314 +
1.315 +//---------------------------------------------------------------------------------------------------------------------------------
1.316 +
1.317 +/**
1.318 +Base class abstraction of a raw media disk
1.319 +*/
1.320 +class CRawDisk : public CBase
1.321 + {
1.322 +public:
1.323 +
1.324 + static CRawDisk* NewL(CFatMountCB& aOwner, const TLocalDriveCaps& aLocDrvCaps);
1.325 +
1.326 + virtual void InitializeL();
1.327 +
1.328 + virtual TInt GetLastErrorInfo(TDes8& aErrorInfo) const;
1.329 +public:
1.330 +
1.331 + /**
1.332 + Read data from the media via simple WT data cache if it is present. Some media types, like RAM do not have caches.
1.333 + This method is mostly used to read UIDs of executable modules and store them in the cache.
1.334 +
1.335 + @param aPos Media position in bytes
1.336 + @param aLength Length in bytes of read
1.337 + @param aDes Data from read
1.338 + */
1.339 + virtual void ReadCachedL(TInt64 aPos,TInt aLength,TDes8& aDes) const = 0;
1.340 +
1.341 + /**
1.342 + Write data to the media via simple WT data cache if it is present. Some media types, like RAM do not have caches.
1.343 + @param aPos Media position in bytes
1.344 + @param aDes Data to write
1.345 + */
1.346 + virtual void WriteCachedL(TInt64 aPos,const TDesC8& aDes) = 0;
1.347 +
1.348 + virtual void InvalidateUidCache() {}
1.349 + virtual void InvalidateUidCachePage(TUint64 /*aPos*/) {}
1.350 +
1.351 +
1.352 + /**
1.353 + Disk read function
1.354 +
1.355 + @param aPos Media position in bytes
1.356 + @param aLength Length in bytes of read
1.357 + @param aTrg Pointer to the data descriptor, i.e. (const TAny*)(&TDes8)
1.358 + @param aMessage Refrence to server message from request
1.359 + @param anOffset Offset into read data to write
1.360 + */
1.361 + virtual void ReadL(TInt64 aPos,TInt aLength,const TAny* aTrg,const RMessagePtr2 &aMessage,TInt anOffset) const = 0;
1.362 +
1.363 + /**
1.364 + Disk write function
1.365 +
1.366 + @param aPos Media position in bytes
1.367 + @param aLength Length in bytes of write
1.368 + @param aTrg Pointer to the data descriptor, i.e. (const TAny*)(&TDes8)
1.369 + @param aMessage Refrence to server message from request, contains data
1.370 + @param anOffset Offset into write data to use in write
1.371 + */
1.372 + virtual void WriteL(TInt64 aPos,TInt aLength,const TAny* aSrc,const RMessagePtr2 &aMessage,TInt anOffset) = 0;
1.373 +
1.374 +
1.375 + virtual inline MWTCacheInterface* DirCacheInterface();
1.376 +
1.377 +
1.378 +
1.379 +
1.380 +protected:
1.381 +
1.382 + CRawDisk(CFatMountCB& aOwner);
1.383 +
1.384 + //-- outlawed
1.385 + CRawDisk();
1.386 + CRawDisk(const CRawDisk&);
1.387 + CRawDisk& operator=(const CRawDisk&);
1.388 +
1.389 +
1.390 +protected:
1.391 +
1.392 + CFatMountCB* iFatMount; ///< Owning file system mount
1.393 +
1.394 +
1.395 +
1.396 + };
1.397 +
1.398 +class CFatFileCB;
1.399 +class RBitVector;
1.400 +
1.401 +/**
1.402 + A helper class. Holds the FAT volume parameters, which in turn are obtained from the Boot Sector
1.403 +*/
1.404 +class TFatVolParam
1.405 + {
1.406 + public:
1.407 +
1.408 + TFatVolParam();
1.409 + void Populate(const TFatBootSector& aBootSector);
1.410 + TBool operator==(const TFatVolParam& aRhs) const;
1.411 +
1.412 + //-- simple getters
1.413 + TUint32 ClusterSizeLog2() const {return iClusterSizeLog2; }
1.414 + TUint32 SectorSizeLog2() const {return iSectorSizeLog2; }
1.415 + TUint32 RootDirEnd() const {return iRootDirEnd; }
1.416 + TUint32 SectorsPerCluster() const {return iSectorsPerCluster; }
1.417 + TUint32 RootDirectorySector() const {return iRootDirectorySector;}
1.418 + TUint32 FirstFatSector() const {return iFirstFatSector; }
1.419 + TUint32 TotalSectors() const {return iTotalSectors; }
1.420 + TUint32 NumberOfFats() const {return iNumberOfFats; }
1.421 + TUint32 FatSizeInBytes() const {return iFatSizeInBytes; }
1.422 + TUint32 RootClusterNum() const {return iRootClusterNum; }
1.423 + TUint32 FSInfoSectorNum() const {return iFSInfoSectorNum; }
1.424 + TUint32 BkFSInfoSectorNum() const {return iBkFSInfoSectorNum; }
1.425 +
1.426 + protected:
1.427 + TUint32 iClusterSizeLog2; ///< Log2 of fat file system cluster size
1.428 + TUint32 iSectorSizeLog2; ///< Log2 of media sector size
1.429 + TUint32 iRootDirEnd; ///< End position of the root directory for Fat12/16
1.430 + TUint32 iSectorsPerCluster; ///< Sector per cluster ratio for mounted Fat file system volume
1.431 + TUint32 iRootDirectorySector; ///< Start sector of the root directory for Fat12/16
1.432 + TUint32 iFirstFatSector; ///< Start sector of the first Fat table in volume
1.433 + TUint32 iTotalSectors; ///< Total sectors on media partition
1.434 + TUint32 iNumberOfFats; ///< Number of Fats the volume has
1.435 + TUint32 iFatSizeInBytes; ///< Size of a single Fat table in volume
1.436 + TUint32 iRootClusterNum; ///< Cluster number for Root directory, for Fat32
1.437 + TUint32 iFSInfoSectorNum; ///< FSInfo Sector number. If 0, this means that corresponding value isn't set in BPB
1.438 + TUint32 iBkFSInfoSectorNum; ///< backup FSInfo Sector number
1.439 + };
1.440 +
1.441 +TUint32 CalculatePageOffsetInCluster(TUint32 aPos, TUint aPageSzLog2);
1.442 +class CLruCache;
1.443 +class TLeafDirData;
1.444 +class CLeafDirCache;
1.445 +/**
1.446 +Fat file system mount implmentation, provides all that is required of a plug in
1.447 +file system mount as well as Fat mount specific functionality
1.448 +*/
1.449 +class CFatMountCB : public CLocDrvMountCB,
1.450 + public MFileSystemSubType,
1.451 + public MFileSystemClusterSize,
1.452 + public CMountCB::MFileAccessor
1.453 + {
1.454 +public:
1.455 + static CFatMountCB* NewL();
1.456 + ~CFatMountCB();
1.457 + void ConstructL();
1.458 +
1.459 +public:
1.460 +
1.461 + //-- overrides from the abstract CMountCB
1.462 + void MountL(TBool aForceMount);
1.463 + TInt ReMount();
1.464 + void Dismounted();
1.465 + void VolumeL(TVolumeInfo& aVolume) const;
1.466 + void SetVolumeL(TDes& aName);
1.467 + void MkDirL(const TDesC& aName);
1.468 + void RmDirL(const TDesC& aName);
1.469 + void DeleteL(const TDesC& aName);
1.470 + void RenameL(const TDesC& anOldName,const TDesC& anNewName);
1.471 + void ReplaceL(const TDesC& anOldName,const TDesC& anNewName);
1.472 + void EntryL(const TDesC& aName,TEntry& anEntry) const;
1.473 + void SetEntryL(const TDesC& aName,const TTime& aTime,TUint aMask,TUint aVal);
1.474 + void FileOpenL(const TDesC& aName,TUint aMode,TFileOpen anOpen,CFileCB* aFile);
1.475 + void DirOpenL(const TDesC& aName,CDirCB* aDir);
1.476 + void RawReadL(TInt64 aPos,TInt aLength,const TAny* aTrg,TInt anOffset,const RMessagePtr2& aMessage) const;
1.477 + void RawWriteL(TInt64 aPos,TInt aLength,const TAny* aSrc,TInt anOffset,const RMessagePtr2& aMessage);
1.478 + void GetShortNameL(const TDesC& aLongName,TDes& aShortName);
1.479 + void GetLongNameL(const TDesC& aShortName,TDes& aLongName);
1.480 + void ReadSectionL(const TDesC& aName,TInt aPos,TAny* aTrg,TInt aLength,const RMessagePtr2& aMessage);
1.481 + TInt CheckDisk();
1.482 + TInt ScanDrive();
1.483 + TInt ControlIO(const RMessagePtr2& aMessage,TInt aCommand,TAny* aParam1,TAny* aParam2);
1.484 + TInt Lock(TMediaPassword& aOld,TMediaPassword& aNew,TBool aStore);
1.485 + TInt Unlock(TMediaPassword& aPassword,TBool aStore);
1.486 + TInt ClearPassword(TMediaPassword& aPassword);
1.487 + TInt ErasePassword();
1.488 + TInt ForceRemountDrive(const TDesC8* aMountInfo,TInt aMountInfoMessageHandle,TUint aFlags);
1.489 +
1.490 + void FinaliseMountL();
1.491 + void FinaliseMountL(TInt aOperation, TAny* aParam1=NULL, TAny* aParam2=NULL);
1.492 + TInt MountControl(TInt aLevel, TInt aOption, TAny* aParam);
1.493 + TTimeIntervalSeconds TimeOffset() const;
1.494 +
1.495 +protected:
1.496 +
1.497 + /** CFatMountCB states */
1.498 + enum TFatMntState
1.499 + {
1.500 + ENotMounted = 0, ///< 0, initial state, not mounted (mount state is inconsistent)
1.501 + EMounting, ///< 1, Mounting started (mount state is inconsistent)
1.502 + EInit_R, ///< 2, Initialised and not written (mount state is Consistent)
1.503 + EInit_W, ///< 3, Initialised and written (mount state is Consistent)
1.504 + EFinalised, ///< 4, Finalised (mount state is Consistent)
1.505 + EDismounted, ///< 5, Dismounted (mount state is inconsistent)
1.506 + EInit_Forced, ///< 6, forcedly mounted, special case (mount state is inconsistent)
1.507 + };
1.508 +
1.509 + inline TFatMntState State() const;
1.510 + inline void SetState(TFatMntState aState);
1.511 + TInt OpenMountForWrite();
1.512 + TInt IsFinalised(TBool& aFinalised);
1.513 +
1.514 + /**
1.515 + A wrapper around TFatDriveInterface providing its instantination and destruction.
1.516 + You must not create objects of this class, use DriveInterface() instead.
1.517 + */
1.518 + class XDriveInterface: public TFatDriveInterface
1.519 + {
1.520 + public:
1.521 + XDriveInterface() : TFatDriveInterface() {}
1.522 + ~XDriveInterface() {Close();}
1.523 + TBool Init(CFatMountCB* aMount) {return TFatDriveInterface::Init(aMount);}
1.524 + };
1.525 +
1.526 +public:
1.527 +
1.528 + enum TRenMode {EModeReplace,EModeRename};
1.529 +
1.530 + TBool ConsistentState() const;
1.531 + void CheckWritableL() const;
1.532 + void CheckStateConsistentL() const;
1.533 +
1.534 + inline TBool ReadOnly(void) const;
1.535 + inline void SetReadOnly(TBool aReadOnlyMode);
1.536 + inline TInt StartCluster(const TFatDirEntry & anEntry) const;
1.537 + inline CRawDisk& RawDisk() const;
1.538 + inline CFatFileSystem& FatFileSystem() const;
1.539 + inline CFatTable& FAT() const;
1.540 + inline TInt ClusterSizeLog2() const;
1.541 + inline TInt SectorSizeLog2() const;
1.542 + inline TInt TotalSectors() const;
1.543 + inline TInt SectorsPerCluster() const;
1.544 + inline TInt ClusterBasePosition() const;
1.545 + inline TInt RootDirectorySector() const;
1.546 + inline TUint RootDirEnd() const;
1.547 + inline TUint32 RootClusterNum() const;
1.548 +
1.549 + inline TFatType FatType() const;
1.550 + inline TBool Is16BitFat() const;
1.551 + inline TBool Is32BitFat() const {return EFalse;} //-- dummy
1.552 +
1.553 + inline TUint32 MaxClusterNumber() const;
1.554 + inline TInt StartOfFatInBytes() const;
1.555 + inline TUint32 FirstFatSector() const;
1.556 +
1.557 + inline TInt NumberOfFats() const;
1.558 + inline TInt FatSizeInBytes() const;
1.559 + inline TInt ClusterRelativePos(TInt aPos) const;
1.560 + inline TUint StartOfRootDirInBytes() const;
1.561 + inline TUint32 UsableClusters() const;
1.562 + inline TBool IsBadCluster(TInt aCluster) const;
1.563 + inline TBool IsRuggedFSys() const;
1.564 + inline void SetRuggedFSys(TBool aVal);
1.565 +
1.566 + inline TInt RootIndicator() const;
1.567 +
1.568 + inline TBool IsRootDir(const TEntryPos &aEntry) const;
1.569 + inline CAsyncNotifier* Notifier() const;
1.570 + inline TFatDriveInterface& DriveInterface() const;
1.571 +
1.572 + void ReadUidL(TInt aCluster,TEntry& anEntry) const;
1.573 +
1.574 + void ReadDirEntryL(const TEntryPos& aPos,TFatDirEntry& aDirEntry) const;
1.575 + void WriteDirEntryL(const TEntryPos& aPos,const TFatDirEntry& aDirEntry);
1.576 +
1.577 + void DirReadL(const TEntryPos& aPos,TInt aLength,TDes8& aDes) const;
1.578 + void DirWriteL(const TEntryPos& aPos,const TDesC8& aDes);
1.579 +
1.580 + void ReadFromClusterListL(TEntryPos& aPos,TInt aLength,const TAny* aTrg,const RMessagePtr2& aMessage,TInt anOffset) const;
1.581 + void WriteToClusterListL(TEntryPos& aPos,TInt aLength,const TAny* aSrc,const RMessagePtr2& aMessage,TInt anOffset, TInt& aBadcluster, TInt& aGoodcluster);
1.582 + void MoveToNextEntryL(TEntryPos& aPos) const;
1.583 + void MoveToDosEntryL(TEntryPos& aPos,TFatDirEntry& anEntry) const;
1.584 + void EnlargeL(TInt aSize);
1.585 + void ReduceSizeL(TInt aPos,TInt aLength);
1.586 + void DoDismount();
1.587 +
1.588 +
1.589 +
1.590 + void CheckIndirectionTableL(TInt& anEndCluster) const;
1.591 + void DoRenameOrReplaceL(const TDesC& anOldName,const TDesC& aNewName,TRenMode aMode,TEntryPos& aNewPos);
1.592 + void FindDosNameL(const TDesC& aName,TUint anAtt,TEntryPos& aDosEntryPos,TFatDirEntry& aDosEntry,TDes& aFileName,TInt anError) const;
1.593 +
1.594 + void Dismount();
1.595 + TBool IsEndOfClusterCh(TInt aCluster) const;
1.596 + void SetEndOfClusterCh(TInt &aCluster) const;
1.597 + void InitializeRootEntry(TFatDirEntry & anEntry) const;
1.598 +
1.599 + TInt64 MakeLinAddrL(const TEntryPos& aPos) const;
1.600 +
1.601 + inline const TFatConfig& FatConfig() const;
1.602 + TBool CheckVolumeTheSame();
1.603 +
1.604 + void InvalidateLeafDirCache();
1.605 +
1.606 + void BlockMapReadFromClusterListL(TEntryPos& aPos, TInt aLength, SBlockMapInfo& aInfo);
1.607 + virtual TInt GetInterface(TInt aInterfaceId,TAny*& aInterface,TAny* aInput);
1.608 + virtual TInt GetFileUniqueId(const TDesC& aName, TInt64& aUniqueId);
1.609 + virtual TInt Spare3(TInt aVal, TAny* aPtr1, TAny* aPtr2);
1.610 + virtual TInt Spare2(TInt aVal, TAny* aPtr1, TAny* aPtr2);
1.611 + virtual TInt Spare1(TInt aVal, TAny* aPtr1, TAny* aPtr2);
1.612 +
1.613 +public:
1.614 +
1.615 + // interface extension implementation
1.616 + virtual TInt SubType(TDes& aName) const;
1.617 + virtual TInt ClusterSize() const;
1.618 +
1.619 +private:
1.620 +
1.621 + /** An ad hoc internal helper object for using in DoFindL() method and its derivatives */
1.622 + class TFindHelper
1.623 + {
1.624 + public:
1.625 + TFindHelper() {isInitialised = EFalse;}
1.626 + void InitialiseL(const TDesC& aTargetName);
1.627 + TBool MatchDosEntryName(const TUint8* apDosEntryName) const;
1.628 + TBool TrgtNameIsLegalDos() const {ASSERT (isInitialised) ;return isLegalDosName;}
1.629 +
1.630 + private:
1.631 + TFindHelper(const TFindHelper&);
1.632 + TFindHelper& operator=(const TFindHelper&);
1.633 + public:
1.634 + TPtrC iTargetName; ///< pointer to the aTargetName, used in DoRummageDirCacheL() as a parameter
1.635 + private:
1.636 + TBool isInitialised :1; ///< ETrue if the object is initialised. It can be done only once.
1.637 + TBool isLegalDosName :1; ///< ETrue if iTargetName is a legal DOS name
1.638 + TShortName iShortName; ///< a short DOS name in XXXXXXXXYYY format generated from aTargetName
1.639 + };
1.640 +
1.641 +
1.642 + /**
1.643 + An ad hoc internal helper object for entry creations
1.644 + */
1.645 + class XFileCreationHelper
1.646 + {
1.647 + public:
1.648 + XFileCreationHelper();
1.649 + ~XFileCreationHelper();
1.650 + void Close();
1.651 + void InitialiseL(const TDesC& aTargetName);
1.652 + TInt GetValidatedShortName(TShortName& aShortName) const;
1.653 + void CheckShortNameCandidates(const TUint8* apDosEntryName);
1.654 +
1.655 + // inline functions for sets and gets
1.656 + // note all the get functions have been checked against initialisation status
1.657 + inline TBool IsInitialised() const;
1.658 + inline TUint16 NumOfAddingEntries() const;
1.659 + inline TEntryPos EntryAddingPos()const;
1.660 + inline TBool IsNewEntryPosFound() const;
1.661 + inline TBool IsTrgNameLegalDosName() const;
1.662 +
1.663 + inline void SetEntryAddingPos(const TEntryPos& aEntryPos);
1.664 + inline void SetIsNewEntryPosFound(TBool aFound);
1.665 +
1.666 + private:
1.667 + XFileCreationHelper(const XFileCreationHelper&);
1.668 + XFileCreationHelper& operator=(const TFindHelper&);
1.669 +
1.670 + private:
1.671 + TPtrC iTargetName; ///< pointer to hold the long file name of the target file
1.672 + TUint16 iNumOfAddingEntries;///< calculated number of entries to add
1.673 + TEntryPos iEntryAddingPos; ///< contains new entry position for adding if found any
1.674 + TBool isNewEntryPosFound; ///< flags whether the position for new entries is found
1.675 + TBool isInitialised :1; ///< flags whether the object is initialised
1.676 + TBool isTrgNameLegalDosName :1; ///< flags whether the target file name is a valid Dos name
1.677 + /**
1.678 + an array that holds short name candidates, prepared on initialisation.
1.679 + */
1.680 + RArray<TShortName> iShortNameCandidates;
1.681 + };
1.682 +
1.683 +
1.684 + TBool DoRummageDirCacheL(TUint anAtt,TEntryPos& aStartEntryPos,TFatDirEntry& aStartEntry,TEntryPos& aDosEntryPos,TFatDirEntry& aDosEntry,TDes& aFileName, const TFindHelper& aAuxParam, XFileCreationHelper* aFileCreationHelper, const TLeafDirData& aLeafDirData) const;
1.685 + TBool DoFindL(const TDesC& aName,TUint anAtt,TEntryPos& aStartEntryPos,TFatDirEntry& aStartEntry,TEntryPos& aDosEntryPos,TFatDirEntry& aDosEntry,TDes& aFileName,TInt anError, XFileCreationHelper* aFileCreationHelper, const TLeafDirData& aLeafDirData) const;
1.686 + void FindEntryStartL(const TDesC& aName,TUint anAtt,TFatDirEntry& anEntry,TEntryPos& aPos, XFileCreationHelper* aFileCreationHelper) const;
1.687 +
1.688 + void FindEntryStartL(const TDesC& aName,TUint anAtt,TFatDirEntry& anEntry,TEntryPos& aPos) const;
1.689 +
1.690 + void CheckFatForLoopsL(const TFatDirEntry& anEntry) const;
1.691 + void DoCheckFatForLoopsL(TInt aCluster,TInt& aPreviousCluster,TInt& aChangePreviousCluster,TInt& aCount) const;
1.692 + void InitializeL(const TLocalDriveCaps& aLocDrvCaps, TBool aIgnoreFSInfo=EFalse);
1.693 + void DoReadFromClusterListL(TEntryPos& aPos,TInt aLength,const TAny* aTrg,const RMessagePtr2& aMessage,TInt anOffset) const;
1.694 + void DoWriteToClusterListL(TEntryPos& aPos,TInt aLength,const TAny* aSrc,const RMessagePtr2& aMessage,TInt anOffset, TInt aLastcluster, TInt& aBadcluster, TInt& aGoodcluster);
1.695 + TBool IsUniqueNameL(const TShortName& aName,TInt aDirCluster);
1.696 + TBool FindShortNameL(const TShortName& aName,TEntryPos& anEntryPos);
1.697 + void ReplaceClashingNameL(const TShortName& aNewName,const TEntryPos& anEntryPos);
1.698 + TBool GenerateShortNameL(TInt aDirCluster,const TDesC& aLongName,TShortName& aShortName, TBool aForceRandomize=EFalse);
1.699 + TInt FindLeafDirL(const TDesC& aName, TLeafDirData& aLeafDir) const;
1.700 +
1.701 + TInt GetDirEntry(TEntryPos& aPos,TFatDirEntry& aDosEntry,TFatDirEntry& aStartEntry,TDes& aLongFileName) const;
1.702 + TBool DoGetDirEntryL(TEntryPos& aPos,TFatDirEntry& aDosEntry,TFatDirEntry& aStartEntry,TDes& aLongFileName) const;
1.703 +
1.704 + void WriteDirEntryL(TEntryPos& aPos,const TFatDirEntry& aFatDirEntry,const TDesC& aLongFileName);
1.705 + void EraseDirEntryL(TEntryPos aPos,const TFatDirEntry& anEntry);
1.706 + void EraseDirEntryL(const TEntryPos& aPos);
1.707 + void InitializeFirstDirClusterL(TInt aCluster,TInt aParentCluster);
1.708 + void AddDirEntryL(TEntryPos& aPos,TInt aNameLength);
1.709 + void ZeroDirClusterL(TInt aCluster);
1.710 +
1.711 + TInt DoWriteBootSector(TInt64 aMediaPos, const TFatBootSector& aBootSector) const;
1.712 + TInt DoReadBootSector(TInt64 aMediaPos, TFatBootSector& aBootSector) const;
1.713 + TInt ReadBootSector(TFatBootSector& aBootSector, TBool aDoNotReadBkBootSec=EFalse);
1.714 +
1.715 + TBool IsDirectoryEmptyL(TInt aCluster);
1.716 + void ExtendClusterListZeroedL(TInt aNumber,TInt& aCluster);
1.717 + void WritePasswordData();
1.718 +
1.719 + void WriteVolumeLabelL(const TDesC8& aVolumeLabel) const;
1.720 + TInt ReadVolumeLabelFile(TDes8& aLabel);
1.721 + void WriteVolumeLabelFileL(const TDesC8& aNewName);
1.722 + void FindVolumeLabelFileL(TDes8& aLabel, TEntryPos& aDosEntryPos, TFatDirEntry& aDosEntry);
1.723 + void GetVolumeLabelFromDiskL(const TFatBootSector& aBootSector);
1.724 + void TrimVolumeLabel(TDes8& aLabel) const;
1.725 +
1.726 + TInt DoRunScanDrive();
1.727 + TBool VolumeCleanL();
1.728 + void SetVolumeCleanL(TBool aClean);
1.729 + TBool VolCleanFlagSupported() const;
1.730 +
1.731 + void DoUpdateFSInfoSectorsL(TBool) {return;} //-- dummy, only FAT32 has FSInfo sector
1.732 + void UnFinaliseMountL();
1.733 + void DoReMountL();
1.734 +
1.735 +private:
1.736 +
1.737 + TBool ValidClusterNumber(TUint32 aCluster) const;
1.738 + void CheckUnvisitedClustersL(const RBitVector& aFatBitVec) const;
1.739 + TInt WalkClusterListL(RBitVector& aFatBitVec, TInt aCluster);
1.740 + void ChkEntryL(RBitVector& aFatBitVec, const TFatDirEntry& anEntry);
1.741 + void ChkDirL(RBitVector& aFatBitVec, TInt aDirCluster);
1.742 +
1.743 + CFatMountCB();
1.744 +
1.745 + TInt GetDosEntryFromNameL(const TDesC& aName, TEntryPos& aDosEntryPos, TFatDirEntry& aDosEntry);
1.746 +
1.747 + TInt MntCtl_DoCheckFileSystemMountable();
1.748 +
1.749 +private:
1.750 +
1.751 + TBool iReadOnly : 1; ///< if true, the drive is in read-only mode
1.752 + TBool iRamDrive : 1; ///< true if this is a RAM drive
1.753 +
1.754 + TFatMntState iState; ///< this mounnt internal state
1.755 + TFatType iFatType; ///< FAT type, FAT12,16 or 32
1.756 +
1.757 + CLeafDirCache* iLeafDirCache; ///< A cache for most recently visited directories, only valid when limit is set bigger than 1
1.758 + HBufC* iLastLeafDir; ///< The last visited directory, only valid when limit of iLeafDirCache is less than 1
1.759 + TInt iLastLeafDirCluster; ///< Cluster number of the last visited cluster, only valid when limit of iLeafDirCache is less than 1
1.760 +
1.761 + TFatVolParam iVolParam; ///< FAT volume parameters, populated form the boot sector values.
1.762 +
1.763 + TInt iFirstFreeByte; ///< First free byte in media (start of the data area on the volume)
1.764 + TUint32 iUsableClusters; ///< Number of usable cluster on the volume
1.765 +
1.766 + CFatTable* iFatTable; ///< Pointer to the volume Fat
1.767 + CRawDisk* iRawDisk; ///< Pointer to the raw data interface class
1.768 +
1.769 + CAsyncNotifier* iNotifier; ///< Async notifier for notifying user of Fat error conditions
1.770 + CLruCache* iLruUidCache; ///< LRU Data cache used for dealing with executable files' UIDs
1.771 +
1.772 + XDriveInterface iDriverInterface; ///< the object representing interface to the drive, provides read/write access and notifiers
1.773 + TInt iChkDiscRecLevel; ///< Check disk recursion level counter. A temporary measure.
1.774 + TFatConfig iFatConfig; ///< FAT parametrers from estart.txt
1.775 +
1.776 + XFileCreationHelper iFileCreationHelper;
1.777 +
1.778 +#ifdef _DEBUG
1.779 + private:
1.780 + //-- debug odds and ends
1.781 + inline TBool IsWriteFail()const;
1.782 + inline void SetWriteFail(TBool aIsWriteFail);
1.783 + inline TInt WriteFailCount()const;
1.784 + inline void SetWriteFailCount(TInt aFailCount);
1.785 + inline void DecWriteFailCount();
1.786 + inline TInt WriteFailError()const;
1.787 + inline void SetWriteFailError(TInt aErrorValue);
1.788 +
1.789 +
1.790 + TBool iIsWriteFail : 1; ///< Flag to indicate if write failed used for debugging
1.791 + TBool iCBRecFlag : 1; ///< in debug mode used for checking unwanted recursion
1.792 +
1.793 + TInt iWriteFailCount; ///< Write fail count for debug
1.794 + TInt iWriteFailError; ///< Write fail error to use for debug
1.795 +
1.796 +#endif
1.797 +
1.798 +friend class CFatFormatCB;
1.799 +friend class CScanDrive;
1.800 +friend class TFatDriveInterface;
1.801 + };
1.802 +
1.803 +
1.804 +
1.805 +
1.806 +/**
1.807 +Fat file system file subsession implmentation, provides all that is required of a plug in
1.808 +file system file as well as Fat specific functionality
1.809 +*/
1.810 +class CFatFileCB : public CFileCB, public CFileCB::MBlockMapInterface, public CFileCB::MExtendedFileInterface
1.811 + {
1.812 +public:
1.813 + CFatFileCB();
1.814 + ~CFatFileCB();
1.815 +public:
1.816 + void RenameL(const TDesC& aNewName);
1.817 + void ReadL(TInt aPos,TInt& aLength,const TAny* aDes,const RMessagePtr2& aMessage);
1.818 + void WriteL(TInt aPos,TInt& aLength,const TAny* aDes,const RMessagePtr2& aMessage);
1.819 + void SetSizeL(TInt aSize);
1.820 + void SetEntryL(const TTime& aTime,TUint aMask,TUint aVal);
1.821 + void FlushDataL();
1.822 + void FlushAllL();
1.823 +public:
1.824 + void CheckPosL(TUint aPos);
1.825 + void SetL(const TFatDirEntry& aFatDirEntry,TShare aShare,const TEntryPos& aPos);
1.826 + void CreateSeekIndex();
1.827 +
1.828 + inline TBool IsSeekIndex() const;
1.829 +
1.830 + // from MBlockMapInterface
1.831 + TInt BlockMap(SBlockMapInfo& aInfo, TInt64& aStartPos, TInt64 aEndPos);
1.832 +
1.833 + // from CFileCB
1.834 + virtual TInt GetInterface(TInt aInterfaceId,TAny*& aInterface,TAny* aInput);
1.835 +
1.836 + // from CFileCB::MExtendedFileInterface
1.837 + virtual void ReadL(TInt64 aPos,TInt& aLength,TDes8* aDes,const RMessagePtr2& aMessage, TInt aOffset);
1.838 + virtual void WriteL(TInt64 aPos,TInt& aLength,const TDesC8* aDes,const RMessagePtr2& aMessage, TInt aOffset);
1.839 + virtual void SetSizeL(TInt64 aSize);
1.840 +
1.841 +private:
1.842 + inline CFatMountCB& FatMount() const;
1.843 + inline CFatTable& FAT();
1.844 + inline TInt ClusterSizeLog2();
1.845 + inline TInt ClusterRelativePos(TInt aPos);
1.846 +
1.847 +
1.848 + void FlushStartClusterL();
1.849 + TInt SeekToPosition(TInt aNewCluster,TInt aClusterOffset);
1.850 + void SetSeekIndexValueL(TInt aFileCluster,TInt aStoredCluster);
1.851 + void ResizeIndex(TInt aNewMult,TUint aNewSize);
1.852 + TInt CalcSeekIndexSize(TUint aSize);
1.853 + TBool IsSeekBackwards(TUint aPos);
1.854 + void ClearIndex(TUint aNewSize);
1.855 + void DoSetSizeL(TUint aSize,TBool aIsSizeWrite);
1.856 + void WriteFileSizeL(TUint aSize);
1.857 +
1.858 +private:
1.859 +
1.860 + TUint32* iSeekIndex; ///< Seek index into file
1.861 + TInt iSeekIndexSize; ///< size of seek index
1.862 + TBool iAttPending;
1.863 + TInt iStartCluster; ///< Start cluster number of file
1.864 + TEntryPos iCurrentPos; ///< Current position in file data
1.865 + TEntryPos iFileDirPos; ///< File directory entry position
1.866 + TBool iFileSizeModified;
1.867 + };
1.868 +//
1.869 +
1.870 +/**
1.871 +Fat file system directory subsession implmentation, provides all that is required of a plug in
1.872 +file system directory as well as Fat specific functionality
1.873 +*/
1.874 +class CFatDirCB : public CDirCB
1.875 + {
1.876 +public:
1.877 + static CFatDirCB* NewL();
1.878 + ~CFatDirCB();
1.879 +public:
1.880 + void ReadL(TEntry& anEntry);
1.881 + void StoreLongEntryNameL(const TDesC& aName);
1.882 +public:
1.883 + void SetDirL(const TFatDirEntry& anEntry,const TDesC& aMatchName);
1.884 + inline CFatMountCB& FatMount();
1.885 +private:
1.886 + CFatDirCB();
1.887 +private:
1.888 + TFatDirEntry iEntry; ///< Current directory entry in this directory
1.889 + TEntryPos iCurrentPos; ///< Current position in directory
1.890 + HBufC* iMatch; ///< Current name being searched in directory (Dos Name)
1.891 + HBufC* iLongNameBuf; ///< Long name storage
1.892 + TBool iMatchUid; ///< Flag to indicate if UID matches
1.893 + };
1.894 +
1.895 +/**
1.896 +Fat file system Format subsession implmentation, provides all that is required of a plug in
1.897 +file system format as well as Fat specific functionality
1.898 +*/
1.899 +class CFatFormatCB : public CFormatCB
1.900 + {
1.901 +public:
1.902 + CFatFormatCB();
1.903 + ~CFatFormatCB();
1.904 +public:
1.905 +
1.906 + //-- overrides from CFormatCB
1.907 + void DoFormatStepL();
1.908 +
1.909 +private:
1.910 + //-- overrides from CFormatCB
1.911 + TInt GetInterface(TInt aInterfaceId,TAny*& aInterface,TAny* aInput);
1.912 +
1.913 +private:
1.914 +
1.915 + TInt DoProcessTVolFormatParam(const TVolFormatParam_FAT* apVolFormatParam);
1.916 +
1.917 + void CreateBootSectorL();
1.918 + void InitializeFormatDataL();
1.919 + void DoZeroFillMediaL(TInt64 aStartPos, TInt64 aEndPos);
1.920 +
1.921 + TInt InitFormatDataForVariableSizeDisk(TInt aDiskSizeInSectors);
1.922 + TInt InitFormatDataForFixedSizeDiskNormal(TInt aDiskSizeInSectors, const TLocalDriveCapsV6& aCaps);
1.923 + TInt InitFormatDataForFixedSizeDiskCustom(const TLDFormatInfo& aFormatInfo);
1.924 + TInt InitFormatDataForFixedSizeDiskUser(TInt aDiskSizeInSectors);
1.925 + void AdjustClusterSize(TInt aRecommendedSectorsPerCluster);
1.926 + TInt AdjustFirstDataSectorAlignment(TInt aBlockSize);
1.927 + TInt FirstDataSector() const;
1.928 +
1.929 + TInt HandleCorrupt(TInt aError);
1.930 + TInt BadSectorToCluster();
1.931 + void TranslateL();
1.932 + TInt DoTranslate(TPtr8& aBuf, RArray<TInt>& aArray);
1.933 + void RecordOldInfoL();
1.934 + TInt MaxFat12Sectors() const;
1.935 + TInt MaxFat16Sectors() const;
1.936 + inline TBool Is16BitFat() const;
1.937 + inline CFatMountCB& FatMount();
1.938 + inline CProxyDrive* LocalDrive();
1.939 + TFatType SuggestFatType() const;
1.940 +
1.941 +private:
1.942 +
1.943 + TBool iVariableSize; ///< Flag to indicat if we are dealing with a variable size volume
1.944 + TInt iBytesPerSector; ///< Byte per sector of media
1.945 + TInt iSectorSizeLog2; ///< Sector size in log2
1.946 + TInt iNumberOfFats; ///< Number of Fats the volume will contain
1.947 + TInt iReservedSectors; ///< Number of reserved sectors in the volume
1.948 + TInt iRootDirEntries; ///< Nummer of root directory entries the root dir will have, specific to Fat12/16 volumes
1.949 + TInt iSectorsPerCluster; ///< Sector per cluster ration the volume will be formatted with
1.950 + TInt iSectorsPerFat; ///< Number of sectors the Fat uses
1.951 + TInt iMaxDiskSectors; ///< number of sectors the volume has
1.952 + TFormatInfo iFormatInfo; ///< format information for a custom format
1.953 + TBuf8<16> iFileSystemName;///< Buffer to contain the volume name
1.954 + TInt iHiddenSectors; ///< Number of hidden sectors in the volume
1.955 + TInt iNumberOfHeads; ///< Number of heads the media device has, not used so far as only used on solid state media.
1.956 + TInt iSectorsPerTrack; ///< Number of sectors the media device has, not used so far as only used on solid state media.
1.957 + RArray<TInt> iBadClusters; ///< Array of bad cluster numbers
1.958 + RArray<TInt> iBadSectors; ///< Array of bad sector numbers
1.959 + TBool iDiskCorrupt; ///< Disk is corrupt when format or not
1.960 + TInt iOldFirstFreeSector;
1.961 + TInt iOldSectorsPerCluster;
1.962 + };
1.963 +
1.964 +
1.965 +/**
1.966 +Required file system class used by file server to create the file system objects
1.967 +*/
1.968 +class CFatFileSystem : public CFileSystem
1.969 + {
1.970 +public:
1.971 + static CFatFileSystem* New();
1.972 + ~CFatFileSystem();
1.973 +public:
1.974 + TInt Install();
1.975 + CMountCB* NewMountL() const;
1.976 + CFileCB* NewFileL() const;
1.977 + CDirCB* NewDirL() const;
1.978 + CFormatCB* NewFormatL() const;
1.979 + void DriveInfo(TDriveInfo& anInfo,TInt aDriveNumber) const;
1.980 + TInt DefaultPath(TDes& aPath) const;
1.981 + TBool IsExtensionSupported() const;
1.982 + TBool GetUseLocalTime() const;
1.983 + void SetUseLocalTime(TBool aFlag);
1.984 + TInt GetInterface(TInt aInterfaceId, TAny*& aInterface,TAny* aInput);
1.985 +protected:
1.986 + CFatFileSystem();
1.987 + /**
1.988 + If true, then local time will be used when writing timestamps to FS. When reading,
1.989 + timestamps will be assumed local and converted back to UTC.
1.990 + At present, this behaviour will also be conditional upon a particular drive being logically removable.
1.991 + */
1.992 + TBool iUseLocalTimeIfRemovable;
1.993 + };
1.994 +
1.995 +
1.996 +
1.997 +/**
1.998 +Locale utilities allows the file system to call into a specific locale for tasks
1.999 +such as Dos name to unicode conversions and testing the legality of characters for
1.1000 +any given locale.
1.1001 +*/
1.1002 +class LocaleUtils
1.1003 +
1.1004 + {
1.1005 +public:
1.1006 + static void ConvertFromUnicodeL(TDes8& aForeign, const TDesC16& aUnicode, TFatUtilityFunctions::TOverflowAction aOverflowAction=TFatUtilityFunctions::EOverflowActionTruncate);
1.1007 + static void ConvertToUnicodeL(TDes16& aUnicode, const TDesC8& aForeign, TFatUtilityFunctions::TOverflowAction aOverflowAction=TFatUtilityFunctions::EOverflowActionTruncate);
1.1008 + static TBool IsLegalShortNameCharacter(TUint aCharacter,TBool aUseExtendedChars=EFalse);
1.1009 + };
1.1010 +
1.1011 +//
1.1012 +
1.1013 +TPtrC RemoveTrailingDots(const TDesC& aName);
1.1014 +
1.1015 +/**
1.1016 +Indicates if a number passed in is a power of two
1.1017 +@return ETrue if aVal is a power of 2
1.1018 +*/
1.1019 +inline TBool IsPowerOf2(TUint32 aVal);
1.1020 +
1.1021 +/**
1.1022 +Calculates the log2 of a number
1.1023 +
1.1024 +@param aNum Number to calulate the log two of
1.1025 +@return The log two of the number passed in
1.1026 +*/
1.1027 +TUint32 Log2(TUint32 aVal);
1.1028 +
1.1029 +/** @return 2^aVal*/
1.1030 +inline TUint32 Pow2(TUint32 aVal);
1.1031 +
1.1032 +
1.1033 +/**
1.1034 +Converts Dos time (from a directory entry) to TTime format
1.1035 +
1.1036 +@param aDosTime Dos format time
1.1037 +@param aDosDate Dos format Date
1.1038 +@return TTime format of Dos time passed in
1.1039 +*/
1.1040 +TTime DosTimeToTTime(TInt aDosTime,TInt aDosDate);
1.1041 +/**
1.1042 +Converts TTime format to Dos time format
1.1043 +
1.1044 +@param aTime TTime to convert to Dos time
1.1045 +@return Dos time format
1.1046 +*/
1.1047 +TInt DosTimeFromTTime(const TTime& aTime);
1.1048 +/**
1.1049 +Converts TTime format to Dos time format
1.1050 +
1.1051 +@param aTime TTime to convert to Dos Date
1.1052 +@return Dos Date format
1.1053 +*/
1.1054 +TInt DosDateFromTTime(const TTime& aTime);
1.1055 +/**
1.1056 +Converts Dos Directory entry format to 8.3 format
1.1057 +
1.1058 +@param aDosName Directory entry format with space delimeter
1.1059 +@return 8.3 Dos filename format
1.1060 +*/
1.1061 +TBuf8<12> DosNameToStdFormat(const TDesC8& aDosName);
1.1062 +/**
1.1063 +Converts 8.3 format to Dos Directory entry format
1.1064 +
1.1065 +@param aStdFormatName 8.3 Dos filename format
1.1066 +@return Directory entry format with space delimeter
1.1067 +*/
1.1068 +TBuf8<12> DosNameFromStdFormat(const TDesC8& aStdFormatName);
1.1069 +/**
1.1070 +Fault function calls user panic with a fault reason
1.1071 +
1.1072 +@param Enumerated fault reason
1.1073 +*/
1.1074 +void Fault(TFault aFault);
1.1075 +/**
1.1076 +calculates the number of VFat directory entries for a given file/directory name length
1.1077 +
1.1078 +@param the length in characters of the name
1.1079 +@return the number of VFat entries required
1.1080 +*/
1.1081 +TInt NumberOfVFatEntries(TInt aNameLength);
1.1082 +/**
1.1083 +Calculates the check sum for a standard directory entry
1.1084 +
1.1085 +@param the Dos name for the directory entry
1.1086 +@return the checksum
1.1087 +*/
1.1088 +TUint8 CalculateShortNameCheckSum(const TDesC8& aShortName);
1.1089 +
1.1090 +
1.1091 +TBool IsLegalDosName(const TDesC& aName,TBool anAllowWildCards,TBool aUseExtendedChars, TBool aInScanDrive, TBool aAllowLowerCase, TBool aIsForFileCreation);
1.1092 +TBool IsLegalDOSNameChar(TChar aCharacter, TBool aUseExtendedChars);
1.1093 +
1.1094 +
1.1095 +
1.1096 +//-----------------------------------------------------------------------------
1.1097 +
1.1098 +/**
1.1099 + This class represents a bit vector i.e. an array of bits. Vector size can be 1..2^32 bits.
1.1100 +*/
1.1101 +class RBitVector
1.1102 + {
1.1103 + public:
1.1104 +
1.1105 + RBitVector(); //-- Creates an empty vector. see Create() methods for memory allocation
1.1106 + ~RBitVector();
1.1107 +
1.1108 + void Close();
1.1109 +
1.1110 + TInt Create(TUint32 aNumBits);
1.1111 + void CreateL(TUint32 aNumBits);
1.1112 +
1.1113 + inline TUint32 Size() const;
1.1114 +
1.1115 + //-- single bit manipulation methods
1.1116 + inline TBool operator[](TUint32 aIndex) const;
1.1117 + inline void SetBit(TUint32 aIndex);
1.1118 + inline void ResetBit(TUint32 aIndex);
1.1119 + inline void InvertBit(TUint32 aIndex);
1.1120 + inline void SetBitVal(TUint32 aIndex, TBool aVal);
1.1121 +
1.1122 + void Fill(TBool aVal);
1.1123 + void Fill(TUint32 aIndexFrom, TUint32 aIndexTo, TBool aVal);
1.1124 + void Invert();
1.1125 +
1.1126 + TBool operator==(const RBitVector& aRhs) const;
1.1127 + TBool operator!=(const RBitVector& aRhs) const;
1.1128 +
1.1129 + //-- logical operations between 2 vectors.
1.1130 + void And(const RBitVector& aRhs);
1.1131 + void Or (const RBitVector& aRhs);
1.1132 + void Xor(const RBitVector& aRhs);
1.1133 +
1.1134 + TBool Diff(const RBitVector& aRhs, TUint32& aDiffIndex) const;
1.1135 +
1.1136 + /** Bit search specifiers */
1.1137 + enum TFindDirection
1.1138 + {
1.1139 + ELeft, ///< Search from the given position to the left (towards lower index)
1.1140 + ERight, ///< Search from the given position to the right (towards higher index)
1.1141 + ENearestL, ///< Search in both directions starting from the given position; in the case of the equal distances return the position to the left
1.1142 + ENearestR ///< Search in both directions starting from the given position; in the case of the equal distances return the position to the right
1.1143 +
1.1144 + //-- N.B the current position the search starts with isn't included to the search.
1.1145 + };
1.1146 +
1.1147 + TBool Find(TUint32& aStartPos, TBool aBitVal, TFindDirection aDir) const;
1.1148 +
1.1149 + /** panic codes */
1.1150 + enum TPanicCode
1.1151 + {
1.1152 + EIndexOutOfRange, ///< index out of range
1.1153 + EWrondFindDirection, ///< a value doesn't belong to TFindDirection
1.1154 + ESizeMismatch, ///< Size mismatch for binary operators
1.1155 + ENotInitialised, ///< No memory allocated for the array
1.1156 + ENotImplemented, ///< functionality isn't implemented
1.1157 + };
1.1158 +
1.1159 + protected:
1.1160 +
1.1161 + //-- these are outlawed. Can't use them because memory allocator can leave and we don't have conthrol on it in these methods.
1.1162 + RBitVector(const RBitVector& aRhs);
1.1163 + RBitVector& operator=(const RBitVector& aRhs);
1.1164 +
1.1165 + void Panic(TPanicCode aPanicCode) const;
1.1166 +
1.1167 + inline TUint32 WordNum(TUint32 aBitPos) const;
1.1168 + inline TUint32 BitInWord(TUint32 aBitPos) const;
1.1169 +
1.1170 + private:
1.1171 + TBool FindToRight(TUint32& aStartPos, TBool aBitVal) const;
1.1172 + TBool FindToLeft (TUint32& aStartPos, TBool aBitVal) const;
1.1173 + TBool FindNearest(TUint32& aStartPos, TBool aBitVal, TBool aToLeft) const;
1.1174 +
1.1175 + inline TUint32 MaskLastWord(TUint32 aVal) const;
1.1176 + inline TBool ItrLeft(TUint32& aIdx) const;
1.1177 + inline TBool ItrRight(TUint32& aIdx) const;
1.1178 +
1.1179 +
1.1180 + protected:
1.1181 +
1.1182 + TUint32 iNumBits; ///< number of bits in the vector
1.1183 + TUint32* ipData; ///< pointer to the data
1.1184 + TUint32 iNumWords;///< number of 32-bit words that store bits
1.1185 + };
1.1186 +
1.1187 +
1.1188 +//-----------------------------------------------------------------------------
1.1189 +
1.1190 +
1.1191 +#include "sl_std.inl"
1.1192 +#include "sl_bpb.inl"
1.1193 +#include "fat_dir_entry.inl"
1.1194 +
1.1195 +#endif //SL_STD_H