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