1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/userlibandfileserver/fileserver/sfat32/filesystem_fat.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,278 @@
1.4 +// Copyright (c) 1995-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 +//
1.18 +// Public header file for "FAT" file system. Contains this file system name and optional file system - specific declarations.
1.19 +//
1.20 +//
1.21 +//
1.22 +
1.23 +
1.24 +/**
1.25 + @file
1.26 + @publishedAll
1.27 + @released
1.28 +*/
1.29 +
1.30 +#if !defined(__FILESYSTEM_FAT_H__)
1.31 +#define __FILESYSTEM_FAT_H__
1.32 +
1.33 +
1.34 +#if !defined(__F32FILE_H__)
1.35 +#include <f32file.h>
1.36 +#endif
1.37 +
1.38 +
1.39 +
1.40 +/**
1.41 + FAT filesystem name, which shall be provided to RFs::MountFileSystem() and is returned by RFs::FileSystemName() if
1.42 + this file system is mounted on the drive. The literal is case-insensitive.
1.43 + @see RFs::MountFileSystem()
1.44 + @see RFs::FileSystemName()
1.45 +*/
1.46 +_LIT(KFileSystemName_FAT, "FAT");
1.47 +
1.48 +/**
1.49 + FAT file system subtypes, literal values. These values are returned by RFs::FileSystemSubType().
1.50 + The literals are case-insensitive.
1.51 + File sytem "FAT" mounted on the drive can be one of the FAT12/FAT16/FAT32
1.52 +
1.53 + @see RFs::::FileSystemSubType()
1.54 +*/
1.55 +_LIT(KFSSubType_FAT12, "FAT12"); ///< corresponds to FAT12
1.56 +_LIT(KFSSubType_FAT16, "FAT16"); ///< corresponds to FAT16
1.57 +_LIT(KFSSubType_FAT32, "FAT32"); ///< corresponds to FAT32
1.58 +
1.59 +//------------------------------------------------------------------------------
1.60 +
1.61 +namespace FileSystem_FAT
1.62 +{
1.63 +
1.64 + /** Numeric representation of FAT file system sub types */
1.65 + enum TFatSubType
1.66 + {
1.67 + EInvalid = 0, ///< invalid terminal value
1.68 + ENotSpecified = 0, ///< not specified
1.69 +
1.70 + EFat12 = 12, ///< corresponds to FAT12
1.71 + EFat16 = 16, ///< corresponds to FAT16
1.72 + EFat32 = 32 ///< corresponds to FAT32
1.73 + };
1.74 +
1.75 +
1.76 +const TUint64 KMaxSupportedFatFileSize = 0xFFFFFFFF; ///< theoretical maximum file size supported by all FAT filesystems (4GB-1)
1.77 +
1.78 +//------------------------------------------------------------------------------
1.79 +
1.80 +/**
1.81 + This class describes specific parameters for formatting volume with FAT file system.
1.82 + The parameters are: FAT sub type (FAT12/16/32), Number of Sectors per cluster, Number of FAT tables, Number of reserved sectors.
1.83 + All parameters are optional and if not set, it is up to the file system implementation to decide values.
1.84 +
1.85 + This class package (TVolFormatParam_FATBuf) shall be passed to the RFormat::Open() as "Special format information"
1.86 +
1.87 + Please note that the parameters may have invalid combinations and it is not always possible to format volume with the specified
1.88 + FAT sub type, like FAT12. In this case RFormat::Open() will return corresponding error code (the concrete code depends on file system implementation).
1.89 +
1.90 + RFormat::Open() does not modify any data in this structure.
1.91 +
1.92 + @see TVolFormatParam_FATBuf
1.93 + @see RFormat::Open()
1.94 +*/
1.95 +class TVolFormatParam_FAT : public TVolFormatParam
1.96 +{
1.97 + public:
1.98 + inline TVolFormatParam_FAT();
1.99 + inline void Init();
1.100 +
1.101 + inline void SetFatSubType(TFatSubType aSubType);
1.102 + inline void SetFatSubType(const TDesC& aSubType);
1.103 + inline TFatSubType FatSubType() const;
1.104 + //--
1.105 + inline void SetSectPerCluster(TUint32 aSpc);
1.106 + inline TUint32 SectPerCluster() const;
1.107 + //--
1.108 + inline void SetNumFATs(TUint32 aNumFATs);
1.109 + inline TUint32 NumFATs() const;
1.110 +
1.111 + //--
1.112 + inline void SetReservedSectors(TUint32 aReservedSectors);
1.113 + inline TUint32 ReservedSectors() const;
1.114 +
1.115 +
1.116 + private:
1.117 + void SetFileSystemName(const TDesC& aFsName);
1.118 +
1.119 + enum ///< offsets of the data units in parent class container
1.120 + {
1.121 + KOffsetSubType =0, //-- 0
1.122 + KOffsetReservedSec, //-- 1
1.123 + KOffsetSpc, //-- 2 !! do not change this offset.
1.124 + KOffsetNumFATs, //-- 3 !! do not change this offset.
1.125 +
1.126 + };
1.127 +
1.128 +}; //TVolFormatParam_FAT
1.129 +
1.130 +
1.131 +/**
1.132 + TVolFormatParam_FAT package buffer to be passed to RFormat::Open().
1.133 + @see TVolFormatParam_FAT
1.134 + @see RFormat::Open()
1.135 +*/
1.136 +typedef TPckgBuf<TVolFormatParam_FAT> TVolFormatParam_FATBuf;
1.137 +
1.138 +
1.139 +
1.140 +//------------------------------------------------------------------------------
1.141 +//-- inline functions
1.142 +//------------------------------------------------------------------------------
1.143 +
1.144 +TVolFormatParam_FAT::TVolFormatParam_FAT() : TVolFormatParam()
1.145 + {
1.146 + __ASSERT_COMPILE(sizeof(TVolFormatParam_FAT) == sizeof(TVolFormatParam));
1.147 + __ASSERT_COMPILE(KOffsetSpc == 2);
1.148 + __ASSERT_COMPILE(KOffsetNumFATs == 3);
1.149 +
1.150 + Init();
1.151 + }
1.152 +
1.153 +//------------------------------------------------------------------------------
1.154 +/** initialises the data structure with default values for all parameters and automatically sets file system name as "FAT" */
1.155 +void TVolFormatParam_FAT::Init()
1.156 + {
1.157 + TVolFormatParam::Init();
1.158 + TVolFormatParam::SetFileSystemName(KFileSystemName_FAT);
1.159 + }
1.160 +
1.161 +//------------------------------------------------------------------------------
1.162 +/**
1.163 + Set desired FAT subtype.
1.164 + @param aSubType specifies FAT12/16/32 subtype. Value 0 means "the file system will decide itself what to use"
1.165 +*/
1.166 +void TVolFormatParam_FAT::SetFatSubType(TFatSubType aSubType)
1.167 + {
1.168 + ASSERT(aSubType == ENotSpecified || aSubType == EFat12 || aSubType == EFat16 || aSubType == EFat32);
1.169 + SetVal(KOffsetSubType, aSubType);
1.170 + }
1.171 +
1.172 +//------------------------------------------------------------------------------
1.173 +/**
1.174 + Set desired FAT subtype using string literals, @see KFSSubType_FAT12, @see KFSSubType_FAT16, @see KFSSubType_FAT32
1.175 + @param aSubType string descriptor, like "FAT16"
1.176 +*/
1.177 +void TVolFormatParam_FAT::SetFatSubType(const TDesC& aSubType)
1.178 + {
1.179 + TFatSubType fatType = ENotSpecified;
1.180 +
1.181 + if(aSubType.CompareF(KFSSubType_FAT12) == 0)
1.182 + fatType = EFat12;
1.183 + else if(aSubType.CompareF(KFSSubType_FAT16) == 0)
1.184 + fatType = EFat16;
1.185 + else if(aSubType.CompareF(KFSSubType_FAT32) == 0)
1.186 + fatType = EFat32;
1.187 + else
1.188 + { ASSERT(0);}
1.189 +
1.190 +
1.191 + SetFatSubType(fatType);
1.192 + }
1.193 +
1.194 +//------------------------------------------------------------------------------
1.195 +/** @return FAT sub type value, which is set by SetFatSubType()*/
1.196 +TFatSubType TVolFormatParam_FAT::FatSubType() const
1.197 + {
1.198 + return (TFatSubType)GetVal(KOffsetSubType);
1.199 + }
1.200 +
1.201 +//------------------------------------------------------------------------------
1.202 +/**
1.203 + Set Number of "Sectors per cluster". For valid values see FAT specs.
1.204 + @param aSpc Number of "Sectors per cluster". Value 0 means "the file system will decide itself what to use"
1.205 +*/
1.206 +void TVolFormatParam_FAT::SetSectPerCluster(TUint32 aSpc)
1.207 + {
1.208 + SetVal(KOffsetSpc, aSpc);
1.209 + }
1.210 +
1.211 +//------------------------------------------------------------------------------
1.212 +/** @return value previously set by SetSectPerCluster() */
1.213 +TUint32 TVolFormatParam_FAT::SectPerCluster() const
1.214 + {
1.215 + return GetVal(KOffsetSpc);
1.216 + }
1.217 +
1.218 +//------------------------------------------------------------------------------
1.219 +/**
1.220 + Set Number of FAT tables on the volume. The maximum is supported by the FAT FS implementation is 2
1.221 + @param aNumFATs Number of FAT tables. Value 0 means "the file system will decide itself what to use"
1.222 +*/
1.223 +void TVolFormatParam_FAT::SetNumFATs(TUint32 aNumFATs)
1.224 + {
1.225 + SetVal(KOffsetNumFATs, aNumFATs);
1.226 + }
1.227 +
1.228 +//------------------------------------------------------------------------------
1.229 +/** @return value previously set by SetNumFATs() */
1.230 +TUint32 TVolFormatParam_FAT::NumFATs() const
1.231 + {
1.232 + return GetVal(KOffsetNumFATs);
1.233 + }
1.234 +
1.235 +//------------------------------------------------------------------------------
1.236 +/**
1.237 + Set number of reserved sectors on FAT volume. The file system will validate this parameter before formatting.
1.238 + @param aReservedSectors number of reserved sectors. Value 0 means "the file system will decide itself what to use"
1.239 +*/
1.240 +void TVolFormatParam_FAT::SetReservedSectors(TUint32 aReservedSectors)
1.241 + {
1.242 + SetVal(KOffsetReservedSec, aReservedSectors);
1.243 + }
1.244 +
1.245 +//------------------------------------------------------------------------------
1.246 +/** @return value previously set by SetReservedSectors() */
1.247 +TUint32 TVolFormatParam_FAT::ReservedSectors() const
1.248 + {
1.249 + return GetVal(KOffsetReservedSec);
1.250 + }
1.251 +
1.252 +
1.253 +
1.254 +
1.255 +//------------------------------------------------------------------------------
1.256 +
1.257 +
1.258 +
1.259 +}//namespace FileSystem_FAT
1.260 +
1.261 +
1.262 +
1.263 +
1.264 +
1.265 +
1.266 +#endif //__FILESYSTEM_FAT_H__
1.267 +
1.268 +
1.269 +
1.270 +
1.271 +
1.272 +
1.273 +
1.274 +
1.275 +
1.276 +
1.277 +
1.278 +
1.279 +
1.280 +
1.281 +