os/kernelhwsrv/userlibandfileserver/fileserver/sfat32/inc/sl_std.inl
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/userlibandfileserver/fileserver/sfat32/inc/sl_std.inl	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,555 @@
     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\sfat32\inc\sl_std.inl
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#ifndef SL_STD_INL
    1.22 +#define SL_STD_INL
    1.23 +
    1.24 +
    1.25 +
    1.26 +//---------------------------------------------------------------------------------------------------------------------------------
    1.27 +// class TEntryPos
    1.28 +TUint32 TEntryPos::Cluster() const 
    1.29 +    {
    1.30 +    return (TUint32) iCluster;
    1.31 +    }
    1.32 +
    1.33 +TUint32 TEntryPos::Pos() const 
    1.34 +    {
    1.35 +    return (TUint32) iPos;
    1.36 +    }
    1.37 +
    1.38 +TBool TEntryPos::operator==(const TEntryPos& aRhs) const
    1.39 +    {
    1.40 +    ASSERT(this != &aRhs);
    1.41 +    return (iCluster == aRhs.iCluster && iPos == aRhs.iPos);
    1.42 +    }
    1.43 +
    1.44 +
    1.45 +//---------------------------------------------------------------------------------------------------------------------------------
    1.46 +// class CFatMountCB
    1.47 +
    1.48 +inline TInt CFatMountCB::RootDirectorySector() const
    1.49 +    {return iVolParam.RootDirectorySector();}
    1.50 +
    1.51 +inline TUint CFatMountCB::RootDirEnd() const
    1.52 +    {return iVolParam.RootDirEnd();}
    1.53 +
    1.54 +inline TUint32 CFatMountCB::RootClusterNum() const
    1.55 +    {return iVolParam.RootClusterNum(); }        
    1.56 +
    1.57 +
    1.58 +inline TInt CFatMountCB::StartCluster(const TFatDirEntry & anEntry) const
    1.59 +	{
    1.60 +	if(Is32BitFat())	
    1.61 +		return anEntry.StartCluster();
    1.62 +	else
    1.63 +		return 0xFFFF&anEntry.StartCluster();
    1.64 +	}
    1.65 +
    1.66 +/**
    1.67 +returns true for root dir on Fat12/16 (fixed root dir versions of Fat) false on fat32 
    1.68 +this function is used to handle special cases for reading/writing the root directory on FAT via the use of cluster zero.
    1.69 +
    1.70 +@param aEntry position on volume being queried
    1.71 +@return Whether Root dir position or not
    1.72 +*/
    1.73 +TBool CFatMountCB::IsRootDir(const TEntryPos &aEntry) const
    1.74 +	{
    1.75 +	if(Is32BitFat())
    1.76 +		return EFalse;
    1.77 +	else
    1.78 +		return((aEntry.iCluster==0) ? (TBool)ETrue : (TBool)EFalse);	
    1.79 +	}
    1.80 +/**
    1.81 +Indicates the root directory cluster, For Fat12/16 root is always indicated by cluster number zero, on Fat32 the is a root cluster number
    1.82 +@return The root cluster indicator
    1.83 +*/
    1.84 +TInt CFatMountCB::RootIndicator() const
    1.85 +	{
    1.86 +	if(Is32BitFat())
    1.87 +        return iVolParam.RootClusterNum();
    1.88 +	else
    1.89 +		return 0;
    1.90 +	}
    1.91 +
    1.92 +
    1.93 +/** @return Log2 of cluster size on volume */
    1.94 +TInt CFatMountCB::ClusterSizeLog2() const
    1.95 +    {return(iVolParam.ClusterSizeLog2());}
    1.96 +
    1.97 +/** @return Log2 of media sector size  */
    1.98 +TInt CFatMountCB::SectorSizeLog2() const
    1.99 +    {return(iVolParam.SectorSizeLog2());}
   1.100 +
   1.101 +/** @return sector per cluster */
   1.102 +TInt CFatMountCB::SectorsPerCluster() const
   1.103 +    {return(1<<(iVolParam.ClusterSizeLog2()-iVolParam.SectorSizeLog2()));}
   1.104 +
   1.105 +/** @return the base position of a cluster */
   1.106 +TInt CFatMountCB::ClusterBasePosition() const
   1.107 +	{return(iFirstFreeByte);}
   1.108 +
   1.109 +/** @return the offset into a cluster of a byte address */
   1.110 +TInt CFatMountCB::ClusterRelativePos(TInt aPos) const
   1.111 +	{return(aPos&((1<<ClusterSizeLog2())-1));}
   1.112 +
   1.113 +/**
   1.114 +Calculates the maximum number of clusters
   1.115 +@return  maximum number of clusters
   1.116 +*/
   1.117 +TUint32 CFatMountCB::MaxClusterNumber() const
   1.118 +    {return(TotalSectors()>>(ClusterSizeLog2()-SectorSizeLog2()));}
   1.119 +
   1.120 +/** @return the the total sectors on volume */
   1.121 +TInt CFatMountCB::TotalSectors() const
   1.122 +    {return iVolParam.TotalSectors();}
   1.123 +
   1.124 +/** @return total size of a Fat in bytes */
   1.125 +TInt CFatMountCB::FatSizeInBytes() const
   1.126 +    {return iVolParam.FatSizeInBytes();}
   1.127 +
   1.128 +/** @return first sector of the Fat */
   1.129 +TUint32 CFatMountCB::FirstFatSector() const
   1.130 +    {return iVolParam.FirstFatSector();}
   1.131 +
   1.132 +/** @return the byte offset of the Fat */
   1.133 +TInt CFatMountCB::StartOfFatInBytes() const
   1.134 +	{return(FirstFatSector()<<SectorSizeLog2());}
   1.135 +
   1.136 +/** @return Number of Fats used by the volume */
   1.137 +TInt CFatMountCB::NumberOfFats() const
   1.138 +    {return iVolParam.NumberOfFats();}
   1.139 +
   1.140 +
   1.141 +/** @return refrence to the fat table owned by the mount */
   1.142 +CFatTable& CFatMountCB::FAT() const
   1.143 +	{return(*iFatTable);}
   1.144 +/**
   1.145 +    @return refrence to the file system object that has produced this CFatMountCB
   1.146 +*/
   1.147 +CFatFileSystem& CFatMountCB::FatFileSystem() const
   1.148 +	{
   1.149 +    return (CFatFileSystem&)(*FileSystem()); //-- CMountCB::FileSystem() provides correct answer
   1.150 +    }
   1.151 +
   1.152 +
   1.153 +/** @return  refrence to a raw disk object owned by the mount */
   1.154 +CRawDisk& CFatMountCB::RawDisk() const
   1.155 +	{return(*iRawDisk);}
   1.156 +
   1.157 +/**
   1.158 +@return ETrue if aCluster value is bad cluster marker defined in FAT specification
   1.159 +*/
   1.160 +TBool CFatMountCB::IsBadCluster(TInt aCluster) const
   1.161 +	{return Is32BitFat() ? aCluster==0xFFFFFF7 : Is16BitFat() ? aCluster==0xFFF7 : aCluster==0xFF7;}
   1.162 +
   1.163 +/**
   1.164 +Returns whether the current mount is running as rugged Fat or not, this is held in the file system object
   1.165 +@return Is rugged fat flag
   1.166 +*/
   1.167 +TBool CFatMountCB::IsRuggedFSys() const
   1.168 +	{return Drive().IsRugged();}
   1.169 +
   1.170 +/**
   1.171 +Sets the rugged flag in the file system object
   1.172 +@param Flag to set or clear the rugged flag
   1.173 +*/
   1.174 +void CFatMountCB::SetRuggedFSys(TBool aVal)
   1.175 +	{Drive().SetRugged(aVal);}
   1.176 +
   1.177 +/** @return the usable clusters count for a volume */
   1.178 +TUint32 CFatMountCB::UsableClusters() const
   1.179 +	{return(iUsableClusters);}
   1.180 +
   1.181 +
   1.182 +TUint CFatMountCB::StartOfRootDirInBytes() const
   1.183 +    {return iVolParam.RootDirectorySector()<<SectorSizeLog2();}
   1.184 +
   1.185 +
   1.186 +/** @return FAT type for this mount */
   1.187 +TFatType CFatMountCB::FatType() const
   1.188 +{
   1.189 +    return iFatType;
   1.190 +}
   1.191 +
   1.192 +/** @return ETrue if the mount has 16bit FAT */
   1.193 +TBool CFatMountCB::Is16BitFat() const
   1.194 +{
   1.195 +    return FatType() == EFat16;
   1.196 +} 
   1.197 +
   1.198 +/** @return ETrue if the mount has 32bit FAT */
   1.199 +TBool CFatMountCB::Is32BitFat() const
   1.200 +{   
   1.201 +    return FatType() == EFat32;
   1.202 +}
   1.203 +
   1.204 +CAsyncNotifier* CFatMountCB::Notifier() const
   1.205 +	{return iNotifier;}	
   1.206 +
   1.207 +
   1.208 +
   1.209 +/**
   1.210 +    Set or reset Read Only mode for the mount.
   1.211 +    @param    aReadOnlyMode if ETrue, the mount will be set RO.
   1.212 +*/
   1.213 +void  CFatMountCB::SetReadOnly(TBool aReadOnlyMode) 
   1.214 +    {
   1.215 +    iReadOnly = aReadOnlyMode;
   1.216 +    }
   1.217 +
   1.218 +
   1.219 +/**
   1.220 +    @return ETrue if the volume is in Read-Only state
   1.221 +*/
   1.222 +TBool CFatMountCB::ReadOnly(void) const
   1.223 +    {
   1.224 +    return iReadOnly;
   1.225 +    }
   1.226 +
   1.227 +/** @return state of the CFatMountCB*/
   1.228 +CFatMountCB::TFatMntState CFatMountCB::State() const 
   1.229 +    {
   1.230 +    return iState;
   1.231 +    }
   1.232 +
   1.233 +/** 
   1.234 +    Set state of the CFatMountCB
   1.235 +    @param  aState state to set
   1.236 +*/
   1.237 +void CFatMountCB::SetState(TFatMntState aState)
   1.238 +    {
   1.239 +    __PRINT3(_L("#- CFatMountCB::SetState() drv:%d, %d->%d\n"),DriveNumber(),iState,aState);
   1.240 +    iState = aState;
   1.241 +    }
   1.242 +
   1.243 +
   1.244 +TDriveInterface& CFatMountCB::DriveInterface() const 
   1.245 +    {
   1.246 +    return (TDriveInterface&)iDriverInterface; 
   1.247 +    }
   1.248 +
   1.249 +const TFatConfig& CFatMountCB::FatConfig() const 
   1.250 +    {
   1.251 +    return iFatConfig;
   1.252 +    }
   1.253 +
   1.254 +//---------------------------------------------------------------------------------------------------------------------------------
   1.255 +/** 
   1.256 +Check if the XFileCreationHelper object is initialised.
   1.257 +*/
   1.258 +TBool CFatMountCB::XFileCreationHelper::IsInitialised() const 
   1.259 +	{
   1.260 +	return isInitialised;
   1.261 +	}
   1.262 +
   1.263 +/** 
   1.264 +Get number of new entries for file creation.
   1.265 +*/
   1.266 +TUint16	CFatMountCB::XFileCreationHelper::NumOfAddingEntries() const
   1.267 +	{
   1.268 +	ASSERT(isInitialised); 
   1.269 +	return iNumOfAddingEntries;
   1.270 +	}
   1.271 +
   1.272 +/** 
   1.273 +Get position of new entries for file creation.
   1.274 +*/
   1.275 +TEntryPos CFatMountCB::XFileCreationHelper::EntryAddingPos() const 
   1.276 +	{
   1.277 +	ASSERT(isInitialised); 
   1.278 +	return iEntryAddingPos;
   1.279 +	}
   1.280 +
   1.281 +/** 
   1.282 +Check if position of new entries has been found.
   1.283 +*/
   1.284 +TBool CFatMountCB::XFileCreationHelper::IsNewEntryPosFound() const 
   1.285 +	{
   1.286 +	ASSERT(isInitialised); 
   1.287 +	return isNewEntryPosFound;
   1.288 +	}
   1.289 +
   1.290 +/** 
   1.291 +Check if file name of the new file is a legal dos name.
   1.292 +*/
   1.293 +TBool CFatMountCB::XFileCreationHelper::IsTrgNameLegalDosName() const
   1.294 +	{
   1.295 +	ASSERT(isInitialised); 
   1.296 +	return isTrgNameLegalDosName;
   1.297 +	}
   1.298 +
   1.299 +/** 
   1.300 +Set entry position for new entries to be added.
   1.301 +*/
   1.302 +void CFatMountCB::XFileCreationHelper::SetEntryAddingPos(const TEntryPos& aEntryPos) 
   1.303 +	{
   1.304 +	iEntryAddingPos = aEntryPos;
   1.305 +	}
   1.306 +
   1.307 +/** 
   1.308 +Set condition if position of new entries has been found.
   1.309 +*/
   1.310 +void CFatMountCB::XFileCreationHelper::SetIsNewEntryPosFound(TBool aFound) 
   1.311 +	{
   1.312 +	isNewEntryPosFound = aFound;
   1.313 +	}
   1.314 +
   1.315 +
   1.316 +/**
   1.317 +    Checks for "EOC" for all Fat types
   1.318 +    @param  aCluster FAT table entry (cluster number) to check
   1.319 +    @return ETrue    if aCluster is a EOC for the FAT type being used by CFatMountCB
   1.320 +*/
   1.321 +TBool CFatMountCB::IsEndOfClusterCh(TInt aCluster) const
   1.322 +	{
   1.323 +    ASSERT(iFatEocCode);
   1.324 +
   1.325 +    if((TUint32)aCluster >= iFatEocCode)
   1.326 +        return ETrue;
   1.327 +
   1.328 +    ASSERT((TUint32)aCluster <= iFatEocCode+7);
   1.329 +
   1.330 +	return EFalse;
   1.331 +    }
   1.332 +
   1.333 +/**
   1.334 +    Sets "End of Cluster Chain" value in aCluster depending on the FAT type.
   1.335 +    @param aCluster cluster to set to end of chain marker
   1.336 +*/
   1.337 +void CFatMountCB::SetEndOfClusterCh(TInt &aCluster) const
   1.338 +	{
   1.339 +    ASSERT(iFatEocCode);
   1.340 +    aCluster = iFatEocCode+7;
   1.341 +	}
   1.342 +
   1.343 +
   1.344 +//-------  debug methods
   1.345 +#ifdef  _DEBUG
   1.346 +/**
   1.347 +Debug function indicates whether write fails are active or not, for test
   1.348 +@return ETrue if write fails on or not
   1.349 +*/
   1.350 +TBool CFatMountCB::IsWriteFail()const
   1.351 +	{return(iIsWriteFail);}
   1.352 +/**
   1.353 +Switches write fails on or off, for test
   1.354 +@param aIsWriteFail set true or false to set write fails on or off
   1.355 +*/
   1.356 +void CFatMountCB::SetWriteFail(TBool aIsWriteFail)
   1.357 +	{iIsWriteFail=aIsWriteFail;}
   1.358 +
   1.359 +/** @return number of write fails to occur, for test */
   1.360 +TInt CFatMountCB::WriteFailCount()const
   1.361 +	{return(iWriteFailCount);}
   1.362 +
   1.363 +/**
   1.364 +Set the number of Write fails 
   1.365 +@param aFailCount number of write fails, for test
   1.366 +*/
   1.367 +void CFatMountCB::SetWriteFailCount(TInt aFailCount)
   1.368 +	{iWriteFailCount=aFailCount;}
   1.369 +
   1.370 +/** Decrement the number of write fails, for test */
   1.371 +void CFatMountCB::DecWriteFailCount()
   1.372 +	{--iWriteFailCount;}
   1.373 +
   1.374 +/** @return Error for a write failure, for test */
   1.375 +TInt CFatMountCB::WriteFailError()const
   1.376 +	{return iWriteFailError;}
   1.377 +
   1.378 +/**
   1.379 +Set the write fail error code, for test
   1.380 +@param aErrorValue The Error for a write fails
   1.381 +*/
   1.382 +void CFatMountCB::SetWriteFailError(TInt aErrorValue)
   1.383 +	{iWriteFailError=aErrorValue;}
   1.384 +
   1.385 +#endif
   1.386 +
   1.387 +
   1.388 +
   1.389 +
   1.390 +
   1.391 +//---------------------------------------------------------------------------------------------------------------------------------
   1.392 +// class CFatFormatCB
   1.393 +
   1.394 +/** @return pointer to the owning mount object */
   1.395 +CFatMountCB& CFatFormatCB::FatMount()
   1.396 +	{return *(CFatMountCB*)&Mount();}
   1.397 +
   1.398 +/**
   1.399 +Returns the local drive used by the file systems from the owning mount
   1.400 +@return Pointer to the local drive 
   1.401 +*/
   1.402 +CProxyDrive* CFatFormatCB::LocalDrive()
   1.403 +	{return(FatMount().LocalDrive());}
   1.404 +
   1.405 +
   1.406 +//---------------------------------------------------------------------------------------------------------------------------------
   1.407 +// class CFatFileCB
   1.408 +
   1.409 +/**
   1.410 +Returns the owning mount from file object
   1.411 +
   1.412 +@return pointer to the owning mount object
   1.413 +*/
   1.414 +CFatMountCB& CFatFileCB::FatMount() const
   1.415 +	{return((CFatMountCB&)Mount());}
   1.416 +
   1.417 +/**
   1.418 +Returns the fat table used by the file system for this mount
   1.419 +
   1.420 +@return Refrence to the Fat table owned by the mount
   1.421 +*/
   1.422 +CFatTable& CFatFileCB::FAT()
   1.423 +	{return(FatMount().FAT());}
   1.424 +
   1.425 +/**
   1.426 +Position with in a cluster for a given address
   1.427 +
   1.428 +@param aPos Byte position 
   1.429 +*/
   1.430 +TInt CFatFileCB::ClusterRelativePos(TInt aPos)
   1.431 +	{return(FatMount().ClusterRelativePos(aPos));}
   1.432 +/**
   1.433 +Returns Log2 of cluster size from mount
   1.434 +
   1.435 +@return cluster size
   1.436 +*/
   1.437 +TInt CFatFileCB::ClusterSizeLog2()
   1.438 +	{return(FatMount().ClusterSizeLog2());}
   1.439 +
   1.440 +/*
   1.441 + Note: this replaces SeekIndex() which was only used in sl_mnt
   1.442 + to verify whether the seek index had been created/initialised
   1.443 +*/
   1.444 +inline TBool CFatFileCB::IsSeekIndex() const
   1.445 +{return (iSeekIndex==NULL?(TBool)EFalse:(TBool)ETrue); }
   1.446 +
   1.447 +
   1.448 +//---------------------------------------------------------------------------------------------------------------------------------
   1.449 +// class CFatDirCB
   1.450 +
   1.451 +/**
   1.452 +Returns the owning mount from directory object
   1.453 +
   1.454 +@return pointer to the owning mount object
   1.455 +*/
   1.456 +CFatMountCB& CFatDirCB::FatMount()
   1.457 +	{return((CFatMountCB&)Mount());}
   1.458 +
   1.459 +
   1.460 +
   1.461 +//---------------------------------------------------------------------------------------------------------------------------------
   1.462 +// class CFatTable
   1.463 +
   1.464 +TUint32 CFatTable::FreeClusters() const 
   1.465 +    {
   1.466 +    return iFreeClusters;
   1.467 +    }
   1.468 +
   1.469 +
   1.470 +//---------------------------------------------------------------------------------------------------------------------------------
   1.471 +
   1.472 +inline TFatType CFatTable::FatType() const 
   1.473 +    {
   1.474 +    return iFatType;
   1.475 +    }
   1.476 +
   1.477 +inline TBool CFatTable::IsFat12() const
   1.478 +    {
   1.479 +    return iFatType == EFat12;
   1.480 +    }
   1.481 +
   1.482 +inline TBool CFatTable::IsFat16() const
   1.483 +    {
   1.484 +    return iFatType == EFat16;
   1.485 +    }
   1.486 +
   1.487 +inline TBool CFatTable::IsFat32() const
   1.488 +    {
   1.489 +    return iFatType == EFat32;
   1.490 +    }
   1.491 +
   1.492 +
   1.493 +/**
   1.494 +    Checks for "EOC" for all Fat types
   1.495 +    @param  aCluster FAT table entry (cluster number) to check
   1.496 +    @return ETrue    if aCluster is a EOC for the FAT type being used by CFatMountCB that owns the CFatTable
   1.497 +*/
   1.498 +inline TBool CFatTable::IsEndOfClusterCh(TUint32 aCluster) const
   1.499 +    {
   1.500 +    ASSERT(iFatEocCode);
   1.501 +
   1.502 +    if(aCluster >= iFatEocCode)
   1.503 +        return ETrue;
   1.504 +
   1.505 +    ASSERT((TUint32)aCluster <= iFatEocCode+7);
   1.506 +	return EFalse;
   1.507 +    }
   1.508 +
   1.509 +
   1.510 +/**
   1.511 +@return Maximal number of addresable FAT entries. This value is taken from the owning mount
   1.512 +*/
   1.513 +inline TUint32 CFatTable::MaxEntries() const
   1.514 +    {
   1.515 +        ASSERT(iMaxEntries > 0);
   1.516 +        return iMaxEntries;
   1.517 +    }
   1.518 +
   1.519 +
   1.520 +// class TDriveInterface
   1.521 +TBool TDriveInterface::NotifyUser() const
   1.522 +	{return(iMount->GetNotifyUser());}
   1.523 +
   1.524 +
   1.525 +//----------------------------------------------------------------------------------------------------
   1.526 +// class CRawDisk
   1.527 +
   1.528 +/**
   1.529 +    Get pointer to the directory cache interface. Any client that reads/writes directory entries 
   1.530 +    MUST do it via this interface.
   1.531 +    Default implementation returns NULL
   1.532 +
   1.533 +    @return     pointer to the MWTCacheInterface interface, or NULL if it is not present.
   1.534 +*/
   1.535 +MWTCacheInterface* CRawDisk::DirCacheInterface()
   1.536 +    {
   1.537 +    return NULL;
   1.538 +    }
   1.539 +
   1.540 +//---------------------------------------------------------------------------------------------------------------------------------	
   1.541 +
   1.542 +/**
   1.543 +    Calculate offset of the page starting position in the cluster 
   1.544 +    @param aPos  the current entry position in bytes in the cluster
   1.545 +    @param aPageSzLog2	page size in log2
   1.546 +    @return		the starting position of the page that contains aPos
   1.547 +*/
   1.548 +inline TUint32 CalculatePageOffsetInCluster(TUint32 aPos, TUint aPageSzLog2)
   1.549 +	{
   1.550 +	return (aPos >> aPageSzLog2) << aPageSzLog2;
   1.551 +	}
   1.552 +
   1.553 +#endif //SL_STD_INL
   1.554 +
   1.555 +
   1.556 +
   1.557 +
   1.558 +