os/kernelhwsrv/userlibandfileserver/fileserver/sfat32/filesystem_fat.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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  !! do not change this offset. 
   121         KOffsetNumFATs,     //-- 3  !! do not change this offset. 
   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      __ASSERT_COMPILE(KOffsetSpc == 2);
   145      __ASSERT_COMPILE(KOffsetNumFATs == 3);
   146      
   147      Init();
   148     }
   149 
   150 //------------------------------------------------------------------------------
   151 /** initialises the data structure with default values for all parameters and automatically sets file system name as "FAT" */
   152 void TVolFormatParam_FAT::Init() 
   153     {
   154     TVolFormatParam::Init(); 
   155     TVolFormatParam::SetFileSystemName(KFileSystemName_FAT);
   156     }
   157 
   158 //------------------------------------------------------------------------------
   159 /**
   160     Set desired FAT subtype. 
   161     @param  aSubType specifies FAT12/16/32 subtype. Value 0 means "the file system will decide itself what to use"
   162 */
   163 void TVolFormatParam_FAT::SetFatSubType(TFatSubType aSubType)
   164     {
   165     ASSERT(aSubType == ENotSpecified || aSubType == EFat12 || aSubType == EFat16 || aSubType == EFat32);
   166     SetVal(KOffsetSubType, aSubType);
   167     }
   168 
   169 //------------------------------------------------------------------------------
   170 /**
   171     Set desired FAT subtype using string literals, @see KFSSubType_FAT12, @see KFSSubType_FAT16, @see KFSSubType_FAT32               
   172     @param  aSubType    string descriptor, like "FAT16"
   173 */
   174 void TVolFormatParam_FAT::SetFatSubType(const TDesC& aSubType)
   175     {
   176     TFatSubType fatType = ENotSpecified;
   177 
   178     if(aSubType.CompareF(KFSSubType_FAT12) == 0)
   179         fatType = EFat12;
   180     else if(aSubType.CompareF(KFSSubType_FAT16) == 0)
   181         fatType = EFat16;
   182     else if(aSubType.CompareF(KFSSubType_FAT32) == 0)
   183         fatType = EFat32;
   184     else
   185         { ASSERT(0);}
   186 
   187 
   188         SetFatSubType(fatType);
   189     }
   190 
   191 //------------------------------------------------------------------------------
   192 /** @return FAT sub type value, which is set by SetFatSubType()*/
   193 TFatSubType TVolFormatParam_FAT::FatSubType() const 
   194     {
   195     return (TFatSubType)GetVal(KOffsetSubType);
   196     }
   197 
   198 //------------------------------------------------------------------------------
   199 /**
   200     Set Number of "Sectors per cluster". For valid values see FAT specs.
   201     @param  aSpc    Number of "Sectors per cluster". Value 0 means "the file system will decide itself what to use"       
   202 */
   203 void TVolFormatParam_FAT::SetSectPerCluster(TUint32 aSpc)
   204     {
   205     SetVal(KOffsetSpc, aSpc);
   206     }
   207 
   208 //------------------------------------------------------------------------------
   209 /** @return value previously set by SetSectPerCluster() */
   210 TUint32 TVolFormatParam_FAT::SectPerCluster() const 
   211     {
   212     return GetVal(KOffsetSpc);
   213     }
   214 
   215 //------------------------------------------------------------------------------
   216 /**
   217     Set Number of FAT tables on the volume. The maximum is supported by the FAT FS implementation is 2
   218     @param  aNumFATs    Number of FAT tables. Value 0 means "the file system will decide itself what to use"       
   219 */
   220 void TVolFormatParam_FAT::SetNumFATs(TUint32 aNumFATs) 
   221     {
   222     SetVal(KOffsetNumFATs, aNumFATs);
   223     }
   224 
   225 //------------------------------------------------------------------------------
   226 /** @return value previously set by SetNumFATs() */
   227 TUint32 TVolFormatParam_FAT::NumFATs() const 
   228     {
   229     return GetVal(KOffsetNumFATs);
   230     } 
   231 
   232 //------------------------------------------------------------------------------
   233 /**
   234     Set number of reserved sectors on FAT volume. The file system will validate this parameter before formatting.
   235     @param  aReservedSectors  number of reserved sectors. Value 0 means "the file system will decide itself what to use"       
   236 */
   237 void TVolFormatParam_FAT::SetReservedSectors(TUint32 aReservedSectors)
   238     {
   239     SetVal(KOffsetReservedSec, aReservedSectors);
   240     }
   241 
   242 //------------------------------------------------------------------------------
   243 /** @return value previously set by SetReservedSectors() */
   244 TUint32 TVolFormatParam_FAT::ReservedSectors() const 
   245     {
   246     return GetVal(KOffsetReservedSec);
   247     } 
   248 
   249 
   250 
   251 
   252 //------------------------------------------------------------------------------
   253 
   254 
   255 
   256 }//namespace FileSystem_FAT
   257 
   258 
   259 
   260 
   261 
   262 
   263 #endif //__FILESYSTEM_FAT_H__
   264 
   265 
   266 
   267 
   268 
   269 
   270 
   271 
   272 
   273 
   274 
   275 
   276 
   277 
   278