userlibandfileserver/fileserver/sfat/filesystem_fat.h
changeset 0 a41df078684a
child 15 4122176ea935
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 1995-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 //
       
    15 // Public header file for "FAT" file system. Contains this file system name and optional file system - specific declarations.
       
    16 //
       
    17 //
       
    18 //
       
    19 
       
    20 
       
    21 /**
       
    22  @file
       
    23  @publishedAll
       
    24  @released
       
    25 */
       
    26 
       
    27 #if !defined(__FILESYSTEM_FAT_H__)
       
    28 #define __FILESYSTEM_FAT_H__
       
    29 
       
    30 
       
    31 #if !defined(__F32FILE_H__)
       
    32 #include <f32file.h>
       
    33 #endif
       
    34 
       
    35 
       
    36 
       
    37 /**
       
    38     FAT filesystem name, which shall be provided to RFs::MountFileSystem() and is returned by RFs::FileSystemName() if 
       
    39     this file system is mounted on the drive. The literal is case-insensitive.
       
    40     @see RFs::MountFileSystem()
       
    41     @see RFs::FileSystemName()
       
    42 */
       
    43 _LIT(KFileSystemName_FAT, "FAT");
       
    44 
       
    45 /**
       
    46     FAT file system subtypes, literal values. These values are returned by RFs::FileSystemSubType().
       
    47     The literals are case-insensitive.
       
    48     File sytem "FAT" mounted on the drive can be one of the FAT12/FAT16/FAT32
       
    49 
       
    50     @see RFs::::FileSystemSubType()
       
    51 */
       
    52 _LIT(KFSSubType_FAT12, "FAT12"); ///< corresponds to FAT12
       
    53 _LIT(KFSSubType_FAT16, "FAT16"); ///< corresponds to FAT16   
       
    54 _LIT(KFSSubType_FAT32, "FAT32"); ///< corresponds to FAT32
       
    55 
       
    56 //------------------------------------------------------------------------------
       
    57 
       
    58 namespace FileSystem_FAT
       
    59 {
       
    60 
       
    61     /** Numeric representation of FAT file system sub types */
       
    62     enum TFatSubType
       
    63         {
       
    64         EInvalid = 0,       ///< invalid terminal value
       
    65         ENotSpecified = 0,  ///< not specified
       
    66 
       
    67         EFat12  = 12,   ///< corresponds to FAT12
       
    68         EFat16  = 16,   ///< corresponds to FAT16
       
    69         EFat32  = 32    ///< corresponds to FAT32
       
    70         };
       
    71 
       
    72 
       
    73 const TUint64 KMaxSupportedFatFileSize = 0xFFFFFFFF; ///< theoretical maximum file size supported by all FAT filesystems (4GB-1)
       
    74 
       
    75 //------------------------------------------------------------------------------
       
    76 
       
    77 /** 
       
    78     This class describes specific parameters for formatting volume with FAT file system.
       
    79     The parameters are: FAT sub type (FAT12/16/32), Number of Sectors per cluster, Number of FAT tables, Number of reserved sectors.
       
    80     All parameters are optional and if not set, it is up to the file system implementation to decide values.
       
    81 
       
    82     This class package (TVolFormatParam_FATBuf) shall be passed to the RFormat::Open() as "Special format information"
       
    83 
       
    84     Please note that the parameters may have invalid combinations and it is not always possible to format volume with the specified
       
    85     FAT sub type, like FAT12. In this case RFormat::Open() will return corresponding error code (the concrete code depends on file system implementation).
       
    86 
       
    87     RFormat::Open() does not modify any data in this structure.
       
    88 
       
    89     @see TVolFormatParam_FATBuf
       
    90     @see RFormat::Open()
       
    91 */ 
       
    92 class TVolFormatParam_FAT : public TVolFormatParam
       
    93 {
       
    94  public:    
       
    95     inline TVolFormatParam_FAT();
       
    96     inline void Init();
       
    97 
       
    98     inline void SetFatSubType(TFatSubType aSubType);
       
    99     inline void SetFatSubType(const TDesC& aSubType);
       
   100     inline TFatSubType FatSubType() const;
       
   101     //--
       
   102     inline void SetSectPerCluster(TUint32 aSpc);
       
   103     inline TUint32 SectPerCluster() const;
       
   104     //--
       
   105     inline void SetNumFATs(TUint32 aNumFATs);
       
   106     inline TUint32 NumFATs() const;
       
   107 
       
   108     //--
       
   109     inline void SetReservedSectors(TUint32 aReservedSectors);
       
   110     inline TUint32 ReservedSectors() const;
       
   111 
       
   112 
       
   113  private:
       
   114     void SetFileSystemName(const TDesC& aFsName);
       
   115     
       
   116     enum ///< offsets of the data units in parent class container
       
   117         {
       
   118         KOffsetSubType =0,  //-- 0
       
   119         KOffsetReservedSec, //-- 1
       
   120         KOffsetSpc,         //-- 2
       
   121         KOffsetNumFATs,     //-- 3
       
   122         
       
   123         };
       
   124 
       
   125 }; //TVolFormatParam_FAT
       
   126 
       
   127 
       
   128 /**
       
   129     TVolFormatParam_FAT package buffer to be passed to RFormat::Open().
       
   130     @see TVolFormatParam_FAT
       
   131     @see RFormat::Open()
       
   132 */ 
       
   133 typedef TPckgBuf<TVolFormatParam_FAT> TVolFormatParam_FATBuf;
       
   134 
       
   135 
       
   136 
       
   137 //------------------------------------------------------------------------------
       
   138 //-- inline functions 
       
   139 //------------------------------------------------------------------------------
       
   140 
       
   141 TVolFormatParam_FAT::TVolFormatParam_FAT() : TVolFormatParam() 
       
   142     {
       
   143      __ASSERT_COMPILE(sizeof(TVolFormatParam_FAT) == sizeof(TVolFormatParam));
       
   144      Init();
       
   145     }
       
   146 
       
   147 //------------------------------------------------------------------------------
       
   148 /** initialises the data structure with default values for all parameters and automatically sets file system name as "FAT" */
       
   149 void TVolFormatParam_FAT::Init() 
       
   150     {
       
   151     TVolFormatParam::Init(); 
       
   152     TVolFormatParam::SetFileSystemName(KFileSystemName_FAT);
       
   153     }
       
   154 
       
   155 //------------------------------------------------------------------------------
       
   156 /**
       
   157     Set desired FAT subtype. 
       
   158     @param  aSubType specifies FAT12/16/32 subtype. Value 0 means "the file system will decide itself what to use"
       
   159 */
       
   160 void TVolFormatParam_FAT::SetFatSubType(TFatSubType aSubType)
       
   161     {
       
   162     ASSERT(aSubType == ENotSpecified || aSubType == EFat12 || aSubType == EFat16 || aSubType == EFat32);
       
   163     SetVal(KOffsetSubType, aSubType);
       
   164     }
       
   165 
       
   166 //------------------------------------------------------------------------------
       
   167 /**
       
   168     Set desired FAT subtype using string literals, @see KFSSubType_FAT12, @see KFSSubType_FAT16, @see KFSSubType_FAT32               
       
   169     @param  aSubType    string descriptor, like "FAT16"
       
   170 */
       
   171 void TVolFormatParam_FAT::SetFatSubType(const TDesC& aSubType)
       
   172     {
       
   173     TFatSubType fatType = ENotSpecified;
       
   174 
       
   175     if(aSubType.CompareF(KFSSubType_FAT12) == 0)
       
   176         fatType = EFat12;
       
   177     else if(aSubType.CompareF(KFSSubType_FAT16) == 0)
       
   178         fatType = EFat16;
       
   179     else if(aSubType.CompareF(KFSSubType_FAT32) == 0)
       
   180         fatType = EFat32;
       
   181     else
       
   182         { ASSERT(0);}
       
   183 
       
   184 
       
   185         SetFatSubType(fatType);
       
   186     }
       
   187 
       
   188 //------------------------------------------------------------------------------
       
   189 /** @return FAT sub type value, which is set by SetFatSubType()*/
       
   190 TFatSubType TVolFormatParam_FAT::FatSubType() const 
       
   191     {
       
   192     return (TFatSubType)GetVal(KOffsetSubType);
       
   193     }
       
   194 
       
   195 //------------------------------------------------------------------------------
       
   196 /**
       
   197     Set Number of "Sectors per cluster". For valid values see FAT specs.
       
   198     @param  aSpc    Number of "Sectors per cluster". Value 0 means "the file system will decide itself what to use"       
       
   199 */
       
   200 void TVolFormatParam_FAT::SetSectPerCluster(TUint32 aSpc)
       
   201     {
       
   202     SetVal(KOffsetSpc, aSpc);
       
   203     }
       
   204 
       
   205 //------------------------------------------------------------------------------
       
   206 /** @return value previously set by SetSectPerCluster() */
       
   207 TUint32 TVolFormatParam_FAT::SectPerCluster() const 
       
   208     {
       
   209     return GetVal(KOffsetSpc);
       
   210     }
       
   211 
       
   212 //------------------------------------------------------------------------------
       
   213 /**
       
   214     Set Number of FAT tables on the volume. The maximum is supported by the FAT FS implementation is 2
       
   215     @param  aNumFATs    Number of FAT tables. Value 0 means "the file system will decide itself what to use"       
       
   216 */
       
   217 void TVolFormatParam_FAT::SetNumFATs(TUint32 aNumFATs) 
       
   218     {
       
   219     SetVal(KOffsetNumFATs, aNumFATs);
       
   220     }
       
   221 
       
   222 //------------------------------------------------------------------------------
       
   223 /** @return value previously set by SetNumFATs() */
       
   224 TUint32 TVolFormatParam_FAT::NumFATs() const 
       
   225     {
       
   226     return GetVal(KOffsetNumFATs);
       
   227     } 
       
   228 
       
   229 //------------------------------------------------------------------------------
       
   230 /**
       
   231     Set number of reserved sectors on FAT volume. The file system will validate this parameter before formatting.
       
   232     @param  aReservedSectors  number of reserved sectors. Value 0 means "the file system will decide itself what to use"       
       
   233 */
       
   234 void TVolFormatParam_FAT::SetReservedSectors(TUint32 aReservedSectors)
       
   235     {
       
   236     SetVal(KOffsetReservedSec, aReservedSectors);
       
   237     }
       
   238 
       
   239 //------------------------------------------------------------------------------
       
   240 /** @return value previously set by SetReservedSectors() */
       
   241 TUint32 TVolFormatParam_FAT::ReservedSectors() const 
       
   242     {
       
   243     return GetVal(KOffsetReservedSec);
       
   244     } 
       
   245 
       
   246 
       
   247 
       
   248 
       
   249 //------------------------------------------------------------------------------
       
   250 
       
   251 
       
   252 
       
   253 }//namespace FileSystem_FAT
       
   254 
       
   255 
       
   256 
       
   257 
       
   258 
       
   259 
       
   260 #endif //__FILESYSTEM_FAT_H__
       
   261 
       
   262 
       
   263 
       
   264 
       
   265 
       
   266 
       
   267 
       
   268 
       
   269 
       
   270 
       
   271 
       
   272 
       
   273 
       
   274 
       
   275