os/kernelhwsrv/userlibandfileserver/fileserver/sfat32/sl_bpb32.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 1996-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
// f32\sfat32\sl_bpb32.cpp
sl@0
    15
// Boot sector code, specific for EFat32.fsy
sl@0
    16
// 
sl@0
    17
//
sl@0
    18
sl@0
    19
/**
sl@0
    20
 @file
sl@0
    21
 @internalTechnology
sl@0
    22
*/
sl@0
    23
sl@0
    24
#include "sl_std.h"
sl@0
    25
sl@0
    26
sl@0
    27
//-------------------------------------------------------------------------------------------------------------------
sl@0
    28
sl@0
    29
TFatBootSector::TFatBootSector()
sl@0
    30
{
sl@0
    31
    Initialise();    
sl@0
    32
}
sl@0
    33
sl@0
    34
/** initialises the boot sector data */
sl@0
    35
void TFatBootSector::Initialise()
sl@0
    36
{
sl@0
    37
    Mem::FillZ(this, sizeof(TFatBootSector));
sl@0
    38
}
sl@0
    39
sl@0
    40
//-------------------------------------------------------------------------------------------------------------------
sl@0
    41
sl@0
    42
/**
sl@0
    43
    @return ETrue if the boot sector contents seems to be valid
sl@0
    44
*/
sl@0
    45
TBool TFatBootSector::IsValid() const
sl@0
    46
{
sl@0
    47
    const TFatType fatType = FatType(); //-- it will check SectorsPerCluster etc.
sl@0
    48
sl@0
    49
    if(fatType == EInvalid || ReservedSectors() < 1 || NumberOfFats() < 1)
sl@0
    50
        goto Invalid;
sl@0
    51
        
sl@0
    52
    if(fatType == EFat32)
sl@0
    53
    {
sl@0
    54
        if(VersionNumber()!= 0 || FatSectors()!=0 || FatSectors32()<1 || RootClusterNum()<KFatFirstSearchCluster ||
sl@0
    55
           TotalSectors()!=0 || HugeSectors() <5 || RootDirEntries() !=0)
sl@0
    56
        {
sl@0
    57
            goto Invalid; //-- these values are not compliant with FAT specs
sl@0
    58
        }
sl@0
    59
    }
sl@0
    60
    else //-- FAT12/16
sl@0
    61
    {
sl@0
    62
        if(TotalSectors() >0 && HugeSectors() >0 )
sl@0
    63
            goto Invalid; //-- values clash
sl@0
    64
sl@0
    65
        const TUint32 totSectors = Max(TotalSectors(), HugeSectors());
sl@0
    66
        const TUint32 rootDirStartSec =  ReservedSectors() + FatSectors()*NumberOfFats(); //-- root directory start sector
sl@0
    67
sl@0
    68
        if(FatSectors() < 1 || rootDirStartSec < 3 || RootDirEntries() < 1 || totSectors < 5)
sl@0
    69
            goto Invalid; //-- these values are not compliant with FAT specs
sl@0
    70
    }
sl@0
    71
sl@0
    72
    return ETrue;
sl@0
    73
  
sl@0
    74
  Invalid:
sl@0
    75
    __PRINT(_L("TFatBootSector::IsValid() failed!"));
sl@0
    76
sl@0
    77
    return EFalse;
sl@0
    78
}
sl@0
    79
sl@0
    80
//-------------------------------------------------------------------------------------------------------------------
sl@0
    81
sl@0
    82
/**
sl@0
    83
    Initialize boot sector object from the given bufer. Does not validate the data.
sl@0
    84
    @param  aBuf buffer with data.
sl@0
    85
*/
sl@0
    86
void TFatBootSector::Internalize(const TDesC8& aBuf)
sl@0
    87
{
sl@0
    88
    ASSERT(aBuf.Size() >= KSizeOfFatBootSector);
sl@0
    89
    
sl@0
    90
    Initialise();
sl@0
    91
    
sl@0
    92
    TInt pos=0;
sl@0
    93
sl@0
    94
    Mem::Copy(&iJumpInstruction, &aBuf[pos],3);     pos+=3; // 0    TUint8 iJumpInstruction[3]
sl@0
    95
    Mem::Copy(&iVendorId,&aBuf[pos],KVendorIdSize); pos+=KVendorIdSize; // 3    TUint8 iVendorId[KVendorIdSize]
sl@0
    96
    Mem::Copy(&iBytesPerSector,&aBuf[pos],2);       pos+=2; // 11   TUint16 iBytesPerSector
sl@0
    97
    Mem::Copy(&iSectorsPerCluster,&aBuf[pos],1);    pos+=1; // 13   TUint8 iSectorsPerCluster   
sl@0
    98
    Mem::Copy(&iReservedSectors,&aBuf[pos],2);      pos+=2; // 14   TUint16 iReservedSectors
sl@0
    99
    Mem::Copy(&iNumberOfFats,&aBuf[pos],1);         pos+=1; // 16   TUint8 iNumberOfFats
sl@0
   100
    Mem::Copy(&iRootDirEntries,&aBuf[pos],2);       pos+=2; // 17   TUint16 iRootDirEntries
sl@0
   101
    Mem::Copy(&iTotalSectors,&aBuf[pos],2);         pos+=2; // 19   TUint16 iTotalSectors
sl@0
   102
    Mem::Copy(&iMediaDescriptor,&aBuf[pos],1);      pos+=1; // 21   TUint8 iMediaDescriptor
sl@0
   103
    Mem::Copy(&iFatSectors,&aBuf[pos],2);           pos+=2; // 22   TUint16 iFatSectors
sl@0
   104
    Mem::Copy(&iSectorsPerTrack,&aBuf[pos],2);      pos+=2; // 24   TUint16 iSectorsPerTrack
sl@0
   105
    Mem::Copy(&iNumberOfHeads,&aBuf[pos],2);        pos+=2; // 26   TUint16 iNumberOfHeads
sl@0
   106
    Mem::Copy(&iHiddenSectors,&aBuf[pos],4);        pos+=4; // 28   TUint32 iHiddenSectors
sl@0
   107
    Mem::Copy(&iHugeSectors,&aBuf[pos],4);          pos+=4; // 32   TUint32 iHugeSectors
sl@0
   108
sl@0
   109
    if(RootDirEntries() == 0) //-- we have FAT32 volume
sl@0
   110
    {
sl@0
   111
        Mem::Copy(&iFatSectors32, &aBuf[pos],4);    pos+=4; // 36 TUint32 iFatSectors32     
sl@0
   112
        Mem::Copy(&iFATFlags, &aBuf[pos],2);        pos+=2; // 40 TUint16 iFATFlags
sl@0
   113
        Mem::Copy(&iVersionNumber, &aBuf[pos],2);   pos+=2; // 42 TUint16 iVersionNumber
sl@0
   114
        Mem::Copy(&iRootClusterNum, &aBuf[pos],4);  pos+=4; // 44 TUint32 iRootClusterNum
sl@0
   115
        Mem::Copy(&iFSInfoSectorNum, &aBuf[pos],2); pos+=2; // 48 TUint16 iFSInfoSectorNum
sl@0
   116
        Mem::Copy(&iBkBootRecSector, &aBuf[pos],2);         // 50 TUint16 iBkBootRecSector
sl@0
   117
        pos+=(2+12);    //extra 12 for the reserved bytes   
sl@0
   118
    }
sl@0
   119
sl@0
   120
    Mem::Copy(&iPhysicalDriveNumber,&aBuf[pos],1);  pos+=1;// 36|64 TUint8 iPhysicalDriveNumber
sl@0
   121
    Mem::Copy(&iReserved,&aBuf[pos],1);             pos+=1;// 37|65 TUint8 iReserved
sl@0
   122
    Mem::Copy(&iExtendedBootSignature,&aBuf[pos],1);pos+=1;// 38|66 TUint8 iExtendedBootSignature
sl@0
   123
    Mem::Copy(&iUniqueID,&aBuf[pos],4);             pos+=4;// 39|67 TUint32 iUniqueID
sl@0
   124
    Mem::Copy(&iVolumeLabel,&aBuf[pos],KVolumeLabelSize);  // 43|71 TUint8 iVolumeLabel[KVolumeLabelSize]
sl@0
   125
    pos+=KVolumeLabelSize;
sl@0
   126
sl@0
   127
    // 54|82    TUint8 iFileSysType[KFileSysTypeSize]
sl@0
   128
    ASSERT(aBuf.Size() >= pos+KFileSysTypeSize);
sl@0
   129
    Mem::Copy(&iFileSysType,&aBuf[pos],KFileSysTypeSize);
sl@0
   130
}
sl@0
   131
sl@0
   132
//-------------------------------------------------------------------------------------------------------------------
sl@0
   133
sl@0
   134
/**
sl@0
   135
    Externalize boot sector object to the given data buffer.
sl@0
   136
    @param  aBuf buffer to externalize.
sl@0
   137
*/
sl@0
   138
void TFatBootSector::Externalize(TDes8& aBuf) const
sl@0
   139
{
sl@0
   140
    ASSERT(aBuf.MaxSize() >= KSizeOfFatBootSector);
sl@0
   141
sl@0
   142
    if(aBuf.Size() < KSizeOfFatBootSector)
sl@0
   143
        aBuf.SetLength(KSizeOfFatBootSector);
sl@0
   144
    
sl@0
   145
    TInt pos=0;
sl@0
   146
sl@0
   147
    Mem::Copy(&aBuf[pos],&iJumpInstruction,3);      pos+=3;
sl@0
   148
    Mem::Copy(&aBuf[pos],&iVendorId,KVendorIdSize); pos+=8;
sl@0
   149
    Mem::Copy(&aBuf[pos],&iBytesPerSector,2);       pos+=2;
sl@0
   150
    Mem::Copy(&aBuf[pos],&iSectorsPerCluster,1);    pos+=1;
sl@0
   151
    Mem::Copy(&aBuf[pos],&iReservedSectors,2);      pos+=2;
sl@0
   152
    Mem::Copy(&aBuf[pos],&iNumberOfFats,1);         pos+=1;
sl@0
   153
    Mem::Copy(&aBuf[pos],&iRootDirEntries,2);       pos+=2;
sl@0
   154
    Mem::Copy(&aBuf[pos],&iTotalSectors,2);         pos+=2;
sl@0
   155
    Mem::Copy(&aBuf[pos],&iMediaDescriptor,1);      pos+=1;
sl@0
   156
    Mem::Copy(&aBuf[pos],&iFatSectors,2);           pos+=2;
sl@0
   157
    Mem::Copy(&aBuf[pos],&iSectorsPerTrack,2);      pos+=2;
sl@0
   158
    Mem::Copy(&aBuf[pos],&iNumberOfHeads,2);        pos+=2;
sl@0
   159
    Mem::Copy(&aBuf[pos],&iHiddenSectors,4);        pos+=4;
sl@0
   160
    Mem::Copy(&aBuf[pos],&iHugeSectors,4);          pos+=4;
sl@0
   161
sl@0
   162
    if(iFatSectors == 0)    
sl@0
   163
        {
sl@0
   164
        Mem::Copy(&aBuf[pos], &iFatSectors32,4);    pos+=4;
sl@0
   165
        Mem::Copy(&aBuf[pos], &iFATFlags, 2);       pos+=2;
sl@0
   166
        Mem::Copy(&aBuf[pos], &iVersionNumber, 2);  pos+=2;
sl@0
   167
        Mem::Copy(&aBuf[pos], &iRootClusterNum, 4); pos+=4;
sl@0
   168
        Mem::Copy(&aBuf[pos], &iFSInfoSectorNum, 2);pos+=2;
sl@0
   169
        Mem::Copy(&aBuf[pos], &iBkBootRecSector, 2);pos+=2;
sl@0
   170
sl@0
   171
        //extra 12 for the reserved bytes   
sl@0
   172
        ASSERT(aBuf.Size() >= pos+12);
sl@0
   173
        Mem::FillZ(&aBuf[pos],12);
sl@0
   174
        pos+=12;
sl@0
   175
        }
sl@0
   176
sl@0
   177
    Mem::Copy(&aBuf[pos],&iPhysicalDriveNumber,1);  pos+=1;
sl@0
   178
    Mem::FillZ(&aBuf[pos],1);                       pos+=1;
sl@0
   179
    Mem::Copy(&aBuf[pos],&iExtendedBootSignature,1);pos+=1;
sl@0
   180
    Mem::Copy(&aBuf[pos],&iUniqueID,4);             pos+=4;
sl@0
   181
    
sl@0
   182
    Mem::Copy(&aBuf[pos],&iVolumeLabel,KVolumeLabelSize); 
sl@0
   183
    pos+=KVolumeLabelSize;
sl@0
   184
    
sl@0
   185
    ASSERT(aBuf.MaxSize() >= pos+KFileSysTypeSize);
sl@0
   186
    Mem::Copy(&aBuf[pos],&iFileSysType,KFileSysTypeSize);
sl@0
   187
}
sl@0
   188
sl@0
   189
//-------------------------------------------------------------------------------------------------------------------
sl@0
   190
sl@0
   191
#ifdef _DEBUG
sl@0
   192
/** replaces all non-printable characters in a buffer with spaces */
sl@0
   193
static void FixDes(TDes& aDes)
sl@0
   194
{
sl@0
   195
    for(TInt i=0; i< aDes.Length(); ++i)
sl@0
   196
    {
sl@0
   197
        TChar ch=aDes[i];
sl@0
   198
        if(!ch.IsPrint())
sl@0
   199
            aDes[i]=' ';    
sl@0
   200
    }
sl@0
   201
}
sl@0
   202
#endif
sl@0
   203
sl@0
   204
sl@0
   205
/** 
sl@0
   206
    Print out the boot sector info.
sl@0
   207
*/
sl@0
   208
void TFatBootSector::PrintDebugInfo() const
sl@0
   209
{
sl@0
   210
#ifdef _DEBUG
sl@0
   211
    __PRINT(_L("\n"));
sl@0
   212
    __PRINT(_L("======== BootSector info: ======="));
sl@0
   213
sl@0
   214
    TBuf<40> buf;
sl@0
   215
    buf.Copy(FileSysType()); FixDes(buf);    
sl@0
   216
    __PRINT1(_L("FAT type:%S"), &buf);
sl@0
   217
sl@0
   218
    buf.Copy(VendorId()); FixDes(buf);    
sl@0
   219
    __PRINT1(_L("Vendor ID:%S"), &buf);
sl@0
   220
sl@0
   221
    __PRINT1(_L("BytesPerSector:%d"),BytesPerSector());
sl@0
   222
    __PRINT1(_L("SectorsPerCluster:%d"),SectorsPerCluster());
sl@0
   223
    __PRINT1(_L("ReservedSectors:%d"),ReservedSectors());
sl@0
   224
    __PRINT1(_L("NumberOfFats:%d"),NumberOfFats());
sl@0
   225
    __PRINT1(_L("RootDirEntries:%d"),RootDirEntries());
sl@0
   226
    __PRINT1(_L("Total Sectors:%d"),TotalSectors());
sl@0
   227
    __PRINT1(_L("MediaDescriptor:0x%x"),MediaDescriptor());
sl@0
   228
    __PRINT1(_L("FatSectors:%d"),FatSectors());
sl@0
   229
    __PRINT1(_L("SectorsPerTrack:%d"),SectorsPerTrack());
sl@0
   230
    __PRINT1(_L("NumberOfHeads:%d"),NumberOfHeads());
sl@0
   231
    __PRINT1(_L("HugeSectors:%d"),HugeSectors());
sl@0
   232
    __PRINT1(_L("Fat32 Sectors:%d"),FatSectors32());
sl@0
   233
    __PRINT1(_L("Fat32 Flags:%d"),FATFlags());
sl@0
   234
    __PRINT1(_L("Fat32 Version Number:%d"),VersionNumber());
sl@0
   235
    __PRINT1(_L("Root Cluster Number:%d"),RootClusterNum());
sl@0
   236
    __PRINT1(_L("FSInfo Sector Number:%d"),FSInfoSectorNum());
sl@0
   237
    __PRINT1(_L("Backup Boot Rec Sector Number:%d"),BkBootRecSector());
sl@0
   238
    __PRINT1(_L("PhysicalDriveNumber:%d"),PhysicalDriveNumber());
sl@0
   239
    __PRINT1(_L("ExtendedBootSignature:%d"),ExtendedBootSignature());
sl@0
   240
    __PRINT1(_L("UniqueID:0x%x"),UniqueID());
sl@0
   241
    
sl@0
   242
    buf.Copy(VolumeLabel()); FixDes(buf);    
sl@0
   243
    __PRINT1(_L("VolumeLabel:%S"), &buf);
sl@0
   244
sl@0
   245
    __PRINT(_L("=============================\n"));
sl@0
   246
#endif
sl@0
   247
}
sl@0
   248
sl@0
   249
//-------------------------------------------------------------------------------------------------------------------
sl@0
   250
sl@0
   251
/**
sl@0
   252
    Determine FAT type according to the information from boot sector, see FAT32 specs.
sl@0
   253
    @return  FAT type. 
sl@0
   254
*/
sl@0
   255
TFatType TFatBootSector::FatType(void) const
sl@0
   256
    {
sl@0
   257
sl@0
   258
    //-- check iBytesPerSector validity; it shall be one of: 512,1024,2048,4096
sl@0
   259
    if(!IsPowerOf2(iBytesPerSector) || iBytesPerSector < 512 ||  iBytesPerSector > 4096)
sl@0
   260
        return EInvalid; //-- invalid iBytesPerSector value
sl@0
   261
sl@0
   262
    //-- check iSectorsPerCluster validity, it shall be one of: 1,2,4,8...128
sl@0
   263
    if(!IsPowerOf2(iSectorsPerCluster) || iSectorsPerCluster > 128)
sl@0
   264
        return EInvalid; //-- invalid iSectorsPerCluster value
sl@0
   265
sl@0
   266
    const TUint32 rootDirSectors = (iRootDirEntries*KSizeOfFatDirEntry + (iBytesPerSector-1)) / iBytesPerSector;
sl@0
   267
    const TUint32 fatSz = iFatSectors ? iFatSectors : iFatSectors32;
sl@0
   268
    const TUint32 totSec = iTotalSectors ? iTotalSectors : iHugeSectors;
sl@0
   269
    const TUint32 dataSec = totSec - (iReservedSectors + (iNumberOfFats * fatSz) + rootDirSectors);
sl@0
   270
    const TUint32 clusterCnt = dataSec / iSectorsPerCluster;
sl@0
   271
sl@0
   272
    //-- magic. see FAT specs for details.
sl@0
   273
    if(clusterCnt < 4085)
sl@0
   274
        return EFat12;
sl@0
   275
    else if(clusterCnt < 65525)
sl@0
   276
        return EFat16;
sl@0
   277
    else
sl@0
   278
        return EFat32;
sl@0
   279
sl@0
   280
    }
sl@0
   281
sl@0
   282
sl@0
   283
sl@0
   284
/** @return The first Fat sector number */
sl@0
   285
TInt TFatBootSector::FirstFatSector() const
sl@0
   286
{
sl@0
   287
    __ASSERT_DEBUG(IsValid(), Fault(EFatBadBootSectorParameter));
sl@0
   288
    return ReservedSectors();
sl@0
   289
}
sl@0
   290
sl@0
   291
/**
sl@0
   292
    @return Number of sectors in root directory. 0 for FAT32
sl@0
   293
*/
sl@0
   294
TUint32 TFatBootSector::RootDirSectors() const
sl@0
   295
{
sl@0
   296
    __ASSERT_DEBUG(IsValid(), Fault(EFatBadBootSectorParameter));
sl@0
   297
    return ( (RootDirEntries()*KSizeOfFatDirEntry + (BytesPerSector()-1)) / BytesPerSector() );
sl@0
   298
}
sl@0
   299
sl@0
   300
sl@0
   301
/** @return Start sector number of the root directory */
sl@0
   302
TInt TFatBootSector::RootDirStartSector()  const
sl@0
   303
{
sl@0
   304
    __ASSERT_DEBUG(IsValid(), Fault(EFatBadBootSectorParameter));
sl@0
   305
sl@0
   306
    const TUint32 firstNonFatSec = ReservedSectors() + TotalFatSectors()*NumberOfFats();
sl@0
   307
sl@0
   308
    if(FatType() == EFat32)
sl@0
   309
    {//-- FAT32 root dir is a file, calculate the position by it's 1st cluster number. FAT[0]+FAT[1] are reserved.
sl@0
   310
        return (firstNonFatSec + (RootClusterNum()-KFatFirstSearchCluster) * SectorsPerCluster());
sl@0
   311
    }
sl@0
   312
    else
sl@0
   313
    {//-- FAT12/16 root dir starts just after the FATs
sl@0
   314
        return firstNonFatSec;
sl@0
   315
    }
sl@0
   316
}
sl@0
   317
sl@0
   318
sl@0
   319
/** @return first data sector number. for FAT32 it includes the root directory */
sl@0
   320
TInt TFatBootSector::FirstDataSector() const
sl@0
   321
{
sl@0
   322
    return( ReservedSectors() + NumberOfFats()*TotalFatSectors() + RootDirSectors() );
sl@0
   323
}
sl@0
   324
sl@0
   325
/** @return FAT-type independent sector count on the volume */
sl@0
   326
TUint32 TFatBootSector::VolumeTotalSectorNumber() const
sl@0
   327
{
sl@0
   328
    __ASSERT_DEBUG(IsValid(), Fault(EFatBadBootSectorParameter));
sl@0
   329
    return TotalSectors() >0 ? (TUint32)TotalSectors() : (TUint32)HugeSectors();
sl@0
   330
}
sl@0
   331
sl@0
   332
/** @return FAT-type independent number of sectors in one FAT */
sl@0
   333
TUint32 TFatBootSector::TotalFatSectors() const
sl@0
   334
{
sl@0
   335
    __ASSERT_DEBUG(IsValid(), Fault(EFatBadBootSectorParameter));
sl@0
   336
    return FatSectors() >0 ? (TUint32)FatSectors() : FatSectors32();
sl@0
   337
}
sl@0
   338
sl@0
   339
sl@0
   340
sl@0
   341
sl@0
   342
//-------------------------------------------------------------------------------------------------------------------
sl@0
   343
sl@0
   344
const TUint32   KLeadSignature      = 0x41615252; ///< FSInfo Lead signiture value
sl@0
   345
const TUint32   KStructureSignature = 0x61417272; ///< FSInfo Structure signiture value
sl@0
   346
const TUint32   KTrailingSignature  = 0xAA550000; ///< FSInfo Trailing signiture
sl@0
   347
sl@0
   348
TFSInfo::TFSInfo()
sl@0
   349
{
sl@0
   350
    Initialise();
sl@0
   351
}
sl@0
   352
//-------------------------------------------------------------------------------------------------------------------
sl@0
   353
sl@0
   354
/** Initialise the data */
sl@0
   355
void TFSInfo::Initialise()  
sl@0
   356
{
sl@0
   357
    Mem::FillZ(this, sizeof(TFSInfo));
sl@0
   358
sl@0
   359
    iLeadSig      = KLeadSignature; 
sl@0
   360
    iStructureSig = KStructureSignature;
sl@0
   361
    iTrainlingSig = KTrailingSignature;
sl@0
   362
}
sl@0
   363
sl@0
   364
//-------------------------------------------------------------------------------------------------------------------
sl@0
   365
sl@0
   366
/**
sl@0
   367
    @return ETrue if FSInfo sector contents seems to be valid
sl@0
   368
*/
sl@0
   369
TBool TFSInfo::IsValid() const
sl@0
   370
{
sl@0
   371
    return (iLeadSig == KLeadSignature && iStructureSig == KStructureSignature && iTrainlingSig == KTrailingSignature);
sl@0
   372
}
sl@0
   373
sl@0
   374
//-------------------------------------------------------------------------------------------------------------------
sl@0
   375
sl@0
   376
/**
sl@0
   377
    Initialize FSInfo sector object from the given bufer. Does not validate the data.
sl@0
   378
    @param  aBuf buffer with data.
sl@0
   379
*/
sl@0
   380
void TFSInfo::Internalize(const TDesC8& aBuf)
sl@0
   381
{
sl@0
   382
    ASSERT((TUint32)aBuf.Size() >= KSizeOfFSInfo);
sl@0
   383
sl@0
   384
    TInt pos=0;
sl@0
   385
sl@0
   386
    Mem::Copy(&iLeadSig, &aBuf[pos],4);      pos+=(KFSInfoReserved1Size+4);
sl@0
   387
    Mem::Copy(&iStructureSig, &aBuf[pos],4); pos+=4;
sl@0
   388
    Mem::Copy(&iFreeCount,&aBuf[pos],4);     pos+=4;
sl@0
   389
    Mem::Copy(&iNextFree,&aBuf[pos],4);      pos+=(4+KFSInfoReserved2Size);
sl@0
   390
    Mem::Copy(&iTrainlingSig,&aBuf[pos],4);
sl@0
   391
}
sl@0
   392
sl@0
   393
//-------------------------------------------------------------------------------------------------------------------
sl@0
   394
sl@0
   395
/**
sl@0
   396
    Externalize FSInfo sector object to the given data buffer.
sl@0
   397
    @param  aBuf buffer to externalize.
sl@0
   398
*/
sl@0
   399
void TFSInfo::Externalize(TDes8& aBuf) const
sl@0
   400
{
sl@0
   401
    ASSERT((TUint32)aBuf.MaxSize() >= KSizeOfFSInfo);
sl@0
   402
    
sl@0
   403
    aBuf.SetLength(KSizeOfFSInfo);
sl@0
   404
    aBuf.FillZ();
sl@0
   405
    
sl@0
   406
    TInt pos=0;
sl@0
   407
sl@0
   408
    Mem::Copy(&aBuf[pos],&KLeadSignature,4);        pos+=4; 
sl@0
   409
                                                    pos+=KFSInfoReserved1Size;
sl@0
   410
    Mem::Copy(&aBuf[pos],&KStructureSignature,4);   pos+=4;
sl@0
   411
    Mem::Copy(&aBuf[pos],&iFreeCount,4);            pos+=4;
sl@0
   412
    Mem::Copy(&aBuf[pos],&iNextFree,4);             pos+=4;
sl@0
   413
                                                    pos+=KFSInfoReserved2Size;
sl@0
   414
    Mem::Copy(&aBuf[pos],&KTrailingSignature,4);
sl@0
   415
}
sl@0
   416
sl@0
   417
//-------------------------------------------------------------------------------------------------------------------
sl@0
   418
sl@0
   419
/** 
sl@0
   420
    Print out the FSInfo sector info.
sl@0
   421
*/
sl@0
   422
void TFSInfo::PrintDebugInfo() const
sl@0
   423
{
sl@0
   424
    __PRINT(_L("\n==== FSInfoSector : ===="));
sl@0
   425
    __PRINT1(_L("FSI_LeadSig:   0x%x"),iLeadSig);
sl@0
   426
    __PRINT1(_L("FSI_StrucSig:  0x%x"),iStructureSig);
sl@0
   427
    __PRINT1(_L("FSI_FreeCount: 0x%x"),iFreeCount);
sl@0
   428
    __PRINT1(_L("FSI_NxtFree:   0x%x"),iNextFree);
sl@0
   429
    __PRINT1(_L("FSI_TrailSig:  0x%x"),iTrainlingSig);
sl@0
   430
    __PRINT(_L("========================\n"));
sl@0
   431
}
sl@0
   432
sl@0
   433
sl@0
   434
sl@0
   435