userlibandfileserver/fileserver/sfat/inc/sl_bpb.h
changeset 0 a41df078684a
child 2 4122176ea935
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 1996-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 // f32\sfat\inc\sl_bpb.h
       
    15 // @file
       
    16 // @internalTechnology
       
    17 // 
       
    18 //
       
    19 
       
    20 
       
    21 #ifndef SL_BPB_H 
       
    22 #define SL_BPB_H
       
    23 
       
    24 
       
    25 #include "filesystem_fat.h"
       
    26 using FileSystem_FAT::TFatSubType;
       
    27 typedef TFatSubType TFatType;
       
    28 
       
    29 
       
    30 const TInt KVolumeLabelSize			=11;    ///< Volume lable size
       
    31 const TInt KFileSysTypeSize			=8;     ///< File system type parameter size
       
    32 const TInt KVendorIdSize			=8;     ///< Vendor ID parameter size
       
    33 const TInt KBootSectorSignature		=0xAA55;///< File system Boot sector signiture
       
    34 
       
    35 const TInt KSizeOfFatBootSector	    =62;    ///< Size in bytes of Boot sector parameter block (BPB), 62 for fat16|12
       
    36 const TInt KFat16VolumeLabelPos     =43;    ///< Position of volume lable in BPB for Fat12/16
       
    37 
       
    38 const TUint32 KBootSectorNum        =0;     ///< Main Boot Sector number (always 0)
       
    39 
       
    40 //-------------------------------------------------------------------------------------------------------------------
       
    41 
       
    42 /**
       
    43 Boot sector parameter block, enables access to all file system parameters.
       
    44 Data is populated at mount time from the BPB sector
       
    45 */
       
    46 class TFatBootSector
       
    47 	{
       
    48 public:
       
    49     //-- simple getters / setters
       
    50 	inline const TPtrC8 VendorId() const;
       
    51 	inline TInt BytesPerSector() const;
       
    52 	inline TInt SectorsPerCluster() const;
       
    53 	inline TInt ReservedSectors() const;
       
    54 	inline TInt NumberOfFats() const;
       
    55 	inline TInt RootDirEntries() const;
       
    56 	inline TInt TotalSectors() const;
       
    57 	inline TUint8 MediaDescriptor() const;
       
    58 	inline TInt FatSectors() const;
       
    59 	inline TInt SectorsPerTrack() const;
       
    60 	inline TInt NumberOfHeads() const;
       
    61 	inline TInt HiddenSectors() const;
       
    62 	inline TInt HugeSectors() const;
       
    63 	inline TInt PhysicalDriveNumber() const;
       
    64 	inline TInt ExtendedBootSignature() const;
       
    65 	inline TUint32 UniqueID() const;
       
    66 	inline const TPtrC8 VolumeLabel() const;
       
    67 	inline const TPtrC8 FileSysType() const;
       
    68 	inline TInt BootSectorSignature() const;
       
    69 
       
    70     inline TUint32 RootClusterNum() const  {return 0;} //-- dummy	
       
    71 	inline TUint16 FSInfoSectorNum() const {return 0;} //-- dummy	
       
    72 	inline TUint16 BkBootRecSector() const {return 0;} //-- dummy	
       
    73 
       
    74 
       
    75 	inline void SetJumpInstruction();
       
    76 	inline void SetVendorID(const TDesC8& aDes);
       
    77 	inline void SetBytesPerSector(TInt aBytesPerSector);
       
    78 	inline void SetSectorsPerCluster(TInt aSectorsPerCluster);
       
    79 	inline void SetReservedSectors(TInt aReservedSectors);
       
    80 	inline void SetNumberOfFats(TInt aNumberOfFats);
       
    81 	inline void SetRootDirEntries(TInt aRootDirEntries);
       
    82 	inline void SetTotalSectors(TInt aTotalSectors);
       
    83 	inline void SetMediaDescriptor(TUint8 aMediaDescriptor);
       
    84 	inline void SetFatSectors(TInt aFatSectors);
       
    85 	inline void SetSectorsPerTrack(TInt aSectorsPerTrack);
       
    86 	inline void SetNumberOfHeads(TInt aNumberOfHeads);
       
    87 	inline void SetHiddenSectors(TUint32 aHiddenSectors);
       
    88 	inline void SetHugeSectors(TUint32 aTotalSectors);
       
    89 	inline void SetPhysicalDriveNumber(TInt aPhysicalDriveNumber);
       
    90 	inline void SetReservedByte(TUint8 aReservedByte);
       
    91 	inline void SetExtendedBootSignature(TInt anExtendedBootSignature);
       
    92 	inline void SetUniqueID(TUint32 anUniqueID);
       
    93 	inline void SetVolumeLabel(const TDesC8& aDes);
       
    94 	inline void SetFileSysType(const TDesC8& aDes);
       
    95 
       
    96 public:
       
    97 
       
    98     TFatBootSector();
       
    99 
       
   100     void Initialise();
       
   101     TBool IsValid() const;
       
   102     TFatType FatType(void) const;
       
   103 	
       
   104     void Internalize(const TDesC8& aBuf);
       
   105     void Externalize(TDes8& aBuf) const;
       
   106 	void PrintDebugInfo() const;
       
   107 
       
   108     //-- more advanced API, works for all FAT types
       
   109     TInt FirstFatSector() const;
       
   110     TInt RootDirStartSector() const;
       
   111 	TInt FirstDataSector() const;
       
   112     
       
   113     TUint32 VolumeTotalSectorNumber() const;
       
   114     TUint32 TotalFatSectors() const;
       
   115     TUint32 RootDirSectors() const;
       
   116 
       
   117 
       
   118 protected:
       
   119     
       
   120     TUint8  iJumpInstruction[3];            ///< +0         Jump instruction used for bootable volumes
       
   121     TUint8  iVendorId[KVendorIdSize];       ///< +3         Vendor ID of the file system that formatted the volume
       
   122     TUint16 iBytesPerSector;                ///< +11/0x0b   Bytes per sector 
       
   123     TUint8  iSectorsPerCluster;             ///< +13/0x0d   Sectors per cluster ratio
       
   124     TUint16 iReservedSectors;               ///< +14/0x0e   Number of reserved sectors on the volume
       
   125     TUint8  iNumberOfFats;                  ///< +16/0x10   Number of Fats on the volume
       
   126     TUint16 iRootDirEntries;	            ///< +17/0x11   Number of entries allowed in the root directory, specific to Fat12/16, zero for FAT32
       
   127     TUint16 iTotalSectors;                  ///< +19/0x13   Total sectors on the volume, zero for FAT32
       
   128     TUint8  iMediaDescriptor;               ///< +12/0x15   Media descriptor
       
   129     TUint16 iFatSectors;                    ///< +22/0x16   Sectors used for the Fat table, zero for FAT32
       
   130     TUint16 iSectorsPerTrack;               ///< +24/0x18   Sectors per track
       
   131     TUint16 iNumberOfHeads;                 ///< +26/0x1a   Number of heads 
       
   132     TUint32 iHiddenSectors;                 ///< +28/0x1c   Number of hidden sectors in the volume
       
   133     TUint32 iHugeSectors;                   ///< +32/0x20   Total sectors in the volume, Used if totalSectors > 65535
       
   134 	//this is (boot sector) offset 36 for FAT12 and 16 but comes after additional FAT36 elements
       
   135 	TUint8 iPhysicalDriveNumber;            ///< +36/0x24   Physical drive number, not used in Symbian OS
       
   136     TUint8 iReserved;                       ///< +37/0x25   Reserved byte
       
   137     TUint8 iExtendedBootSignature;          ///< +38/0x26   Extended boot signiture
       
   138     TUint32 iUniqueID;                      ///< +39/0x27   Unique volume ID
       
   139     TUint8 iVolumeLabel[KVolumeLabelSize];  ///< +43/0x2b   The volume's label
       
   140 	TUint8 iFileSysType[KFileSysTypeSize];  ///< +54/0x36   File system type
       
   141 	};
       
   142 
       
   143 
       
   144 
       
   145 
       
   146 
       
   147 #endif //SL_BPB_H
       
   148