baseintegtests/baseintegrationtest/testsuites/fat32/inc/sl_bpb1.h
changeset 0 a41df078684a
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 //
       
    15 
       
    16 #ifndef SL_BPB1_H
       
    17 #define SL_BPB1_H
       
    18 
       
    19 #include <f32fsys.h>
       
    20 #include <f32ver.h>
       
    21 #include <f32dbg.h>
       
    22 #include <e32svr.h>
       
    23 
       
    24 #pragma warning (disable:4103) //  : used #pragma pack to change alignment
       
    25 
       
    26 static const TInt KFatDirNameSize=11;
       
    27 static const TInt KFatDirReservedSize=10;
       
    28 static const TInt KVolumeLabelSize=11;
       
    29 static const TInt KFileSysTypeSize=8;
       
    30 static const TInt KVendorIdSize=8;
       
    31 static const TInt KVFatEntryAttribute=0x0F;
       
    32 static const TInt KBootSectorSignature=0xAA55;
       
    33 
       
    34 class TFatDirEntry;
       
    35 enum TFault
       
    36 	{
       
    37 	EVFatNoLongName,
       
    38 	EFatChkDskFailed,
       
    39 	EFatBadParameter,
       
    40 	EFatCacheBadRead,
       
    41 	EFatCacheNotFatSector,
       
    42 	EFatBadLocalDrive,
       
    43 	EFatBadBootSectorParameter,
       
    44 	EFatBadDirEntryParameter,
       
    45 	EFatAddClusterNotLastInList,
       
    46 	EFatBadEntryValue,
       
    47 	EFatBadClusterValue,
       
    48 	EFatBadStdFormatName,
       
    49 	EFatBadDosFormatName,
       
    50 	EFatCorrupt,
       
    51 	EFatChkDskBitListOverFlow,
       
    52 	EFatChkDskIndexOverFlow,
       
    53 	EFatChkDskIllegalClusterNumber,
       
    54 	EFatChkDskClusterAlreadyInUse,
       
    55 	EFatChkDskBadCluster,
       
    56 	EFatChkDskInvalidEntrySize,
       
    57 	EFatDesTooBig,
       
    58 	EFatFilePosBeyondEnd,
       
    59 	EFatFileSeekIndexTooSmall,
       
    60 	EFatFileSeekIndexTooSmall2,
       
    61 	EFatDataAllocBadSeg,
       
    62 	EFatFileSystemBadMemory,
       
    63 	EFatFileSystemCreate1,
       
    64 	EFatFileSystemCreate2,
       
    65 	EFatFileSystemCreate3,
       
    66 	ECacheAllocatorSetMax,
       
    67 	EFatLruCacheBadGranularity,
       
    68 	EFatFixedCacheBadGranularity,
       
    69 	EFatFixedCacheBadCall,
       
    70 	EFatRawReadTooBig,
       
    71 	EFatRawWriteTooBig,
       
    72 	EWinsBadRamDriveRead,
       
    73 	EWinsBadRamDriveWrite,
       
    74 	EFatReadUidFailed,
       
    75 	ELruCacheFlushNotSupported
       
    76 	};
       
    77 
       
    78 struct SFatDirEntry
       
    79 	{
       
    80     TUint8 iName[KFatDirNameSize];
       
    81     TUint8 iAttributes;
       
    82     TUint8 iReserved[KFatDirReservedSize];
       
    83     TUint16 iTime;
       
    84     TUint16 iDate;
       
    85     TUint16 iStartCluster;
       
    86     TUint32 iSize;
       
    87 	};	
       
    88 #define pDir ((SFatDirEntry*)&iData[0])
       
    89 
       
    90 //
       
    91 typedef TBuf8<KFatDirNameSize> TShortName;
       
    92 //
       
    93 const TInt KSizeOfFatBootSector=62;
       
    94 const TInt KSizeOfFatDirEntry=32;
       
    95 class TFatBootSector
       
    96 	{
       
    97 public:
       
    98 	inline const TPtrC8 VendorId() const;
       
    99 	inline TInt BytesPerSector() const{return iBytesPerSector;}
       
   100 	inline TInt SectorsPerCluster() const{return iSectorsPerCluster;}
       
   101 	inline TInt ReservedSectors() const {return iReservedSectors;};
       
   102 	inline TInt NumberOfFats() const {return iNumberOfFats;}
       
   103 	inline TInt RootDirEntries() const{return iRootDirEntries;}
       
   104 	inline TInt TotalSectors() const{return iTotalSectors;}
       
   105 	inline TUint8 MediaDescriptor() const {return iMediaDescriptor;}
       
   106 	inline TInt FatSectors() const {return iFatSectors;}
       
   107 	inline TInt SectorsPerTrack() const {return iSectorsPerTrack;}
       
   108 	inline TInt NumberOfHeads() const{return iNumberOfHeads;}
       
   109 	inline TInt HiddenSectors() const {return iHiddenSectors;}
       
   110 	inline TInt HugeSectors() const{return iHugeSectors;}
       
   111 	inline TInt PhysicalDriveNumber() const;
       
   112 	inline TInt ExtendedBootSignature() const;
       
   113 	inline TUint32 UniqueID() const;
       
   114 	inline const TPtrC8 VolumeLabel() const;
       
   115 	inline const TPtrC8 FileSysType() const {return TPtrC8(iFileSysType,KFileSysTypeSize);}
       
   116 	inline TInt BootSectorSignature() const;
       
   117 	inline void SetJumpInstruction();
       
   118 	inline void SetVendorID(const TDesC8& aDes);
       
   119 	inline void SetBytesPerSector(TInt aBytesPerSector);
       
   120 	inline void SetSectorsPerCluster(TInt aSectorsPerCluster);
       
   121 	inline void SetReservedSectors(TInt aReservedSectors);
       
   122 	inline void SetNumberOfFats(TInt aNumberOfFats);
       
   123 	inline void SetRootDirEntries(TInt aRootDirEntries);
       
   124 	inline void SetTotalSectors(TInt aTotalSectors);
       
   125 	inline void SetMediaDescriptor(TUint8 aMediaDescriptor);
       
   126 	inline void SetFatSectors(TInt aFatSectors);
       
   127 	inline void SetSectorsPerTrack(TInt aSectorsPerTrack);
       
   128 	inline void SetNumberOfHeads(TInt aNumberOfHeads);
       
   129 	inline void SetHiddenSectors(TUint32 aHiddenSectors);
       
   130 	inline void SetHugeSectors(TUint32 aTotalSectors);
       
   131 	inline void SetPhysicalDriveNumber(TInt aPhysicalDriveNumber);
       
   132 	inline void SetReservedByte(TUint8 aReservedByte);
       
   133 	inline void SetExtendedBootSignature(TInt anExtendedBootSignature);
       
   134 	inline void SetUniqueID(TUint32 anUniqueID);
       
   135 	inline void SetVolumeLabel(const TDesC8& aDes);
       
   136 	inline void SetFileSysType(const TDesC8& aDes);
       
   137 	
       
   138 public:
       
   139 	inline TBool Is16BitFat() {return(FileSysType()==_L8("FAT16   "));}
       
   140 	TInt FirstFatSectorPos()
       
   141 	{
       
   142 	return(ReservedSectors()*BytesPerSector());
       
   143 	}
       
   144 	inline TInt RootDirStartSector();
       
   145 	inline TInt FirstFreeSector();
       
   146 public:
       
   147     TUint8  iJumpInstruction[3];        ///< Jump instruction used for bootable volumes
       
   148     TUint8  iVendorId[KVendorIdSize];   ///< Vendor ID of the file system that formatted the volume
       
   149     TUint16 iBytesPerSector;            ///< Bytes per sector 
       
   150     TUint8  iSectorsPerCluster;         ///< Sectors per cluster ratio
       
   151     TUint16 iReservedSectors;           ///< Number of reserved sectors on the volume
       
   152     TUint8  iNumberOfFats;              ///< Number of Fats on the volume
       
   153     TUint16 iRootDirEntries;	        ///< Number of entries allowed in the root directory, specific to Fat12/16, zero for FAT32
       
   154     TUint16 iTotalSectors;              ///< Total sectors on the volume, zero for FAT32
       
   155     TUint8  iMediaDescriptor;           ///< Media descriptor
       
   156     TUint16 iFatSectors;                ///< Sectors used for the Fat table, zero for FAT32
       
   157     TUint16 iSectorsPerTrack;           ///< Sectors per track
       
   158     TUint16 iNumberOfHeads;             ///< Number of heads 
       
   159     TUint32 iHiddenSectors;             ///< Number of hidden sectors in the volume
       
   160     TUint32 iHugeSectors;               ///< Total sectors in the volume, Used if totalSectors > 65535
       
   161 	TUint32	iFatSectors32;              ///< Start of additional elements @ offset 36 for FAT32, Sectors in Fat table for 32 bit volume
       
   162 	TUint16 iFATFlags;                  ///< Fat flags
       
   163 	TUint16	iVersionNumber;		        ///< Version number of the file system
       
   164 	TUint32 iRootClusterNum;            ///< Cluster number of the root directory
       
   165 	TUint16 iFSInfoSectorNum;           ///< Sector number containing the FSIInfo structure
       
   166 	TUint16 iBkBootRecSector;           ///< Backup boot sector
       
   167 	TUint8	iReserved2[12];             ///< Reserved space, End of Fat32 Only parameters section
       
   168 	TUint8  iPhysicalDriveNumber;       ///< Physical drive number, not used in Symbian OS
       
   169     TUint8  iReserved;                  ///< Reserved byte
       
   170     TUint8  iExtendedBootSignature;     ///< Extended boot signiture
       
   171     TUint32 iUniqueID;                  ///< Unique volume ID
       
   172     TUint8  iVolumeLabel[KVolumeLabelSize];  ///< 	The volume's label
       
   173 	TUint8  iFileSysType[KFileSysTypeSize];  ///< 	File system type
       
   174 	};
       
   175 	
       
   176 void Fault(TAny* aTestStep,TFault anError);
       
   177 GLREF_C TBool IsPowerOfTwo(TInt aNum);
       
   178 GLREF_C TInt Log2(TInt aNum);
       
   179 GLREF_C TTime DosTimeToTTime(TInt aDosTime,TInt aDosDate);
       
   180 GLREF_C TInt DosTimeFromTTime(const TTime& aTime);
       
   181 GLREF_C TInt DosDateFromTTime(const TTime& aTime);
       
   182 
       
   183 class TFatDirEntry
       
   184 	{
       
   185 public:
       
   186 	const TPtrC8 Name() const
       
   187 	{return TPtrC8((TUint8*)&(pDir->iName),11);
       
   188 	}
       
   189 	TInt Attributes() const 
       
   190 	{
       
   191 	return pDir->iAttributes;
       
   192 	}
       
   193 	inline TTime Time() const;
       
   194 	TInt StartCluster() const
       
   195 	{
       
   196 	return pDir->iStartCluster;
       
   197 	}
       
   198 	inline TUint32 Size() const;
       
   199 	TBool IsErased() const
       
   200 	{
       
   201 	return (TBool)(iData[0]==0xe5);
       
   202 	}
       
   203 	inline TBool IsCurrentDirectory() const;
       
   204 	inline TBool IsParentDirectory() const;
       
   205 	TBool IsEndOfDirectory() const 
       
   206 	{
       
   207 	return (TBool)(iData[0]==0x00);
       
   208 	}
       
   209 	TBool IsGarbage() const;
       
   210 	inline void SetName(const TDesC8& aDes);
       
   211 	inline void SetAttributes(TInt anAtt);
       
   212 	inline void SetTime(const TTime& aTime);
       
   213 	void SetStartCluster(TInt aStartCluster)
       
   214 	{
       
   215 	__ASSERT_DEBUG(!(aStartCluster&~KMaxTUint16),Fault( this,EFatBadDirEntryParameter));
       
   216 	pDir->iStartCluster=(TUint16)aStartCluster;
       
   217 	}
       
   218 	inline void SetSize(TUint32 aFilesize);
       
   219 	inline void SetErased();
       
   220 	inline void SetCurrentDirectory();
       
   221 	inline void SetParentDirectory();
       
   222 	inline void SetEndOfDirectory();
       
   223 	inline void ZeroReserved();
       
   224 public:
       
   225 	void InitializeRootEntry();
       
   226 	void InitializeAsVFat(TUint8 aCheckSum);
       
   227 	void SetVFatEntry(const TDesC& aName,TInt aRemainderLen);
       
   228 	void ReadVFatEntry(TDes16& aVBuf);
       
   229 	inline TBool IsLongNameStart() const;
       
   230 	TBool IsVFatEntry() const 
       
   231 	{
       
   232 	return (TBool)(Attributes()==0x0F && IsEndOfDirectory()==EFalse);
       
   233 	}
       
   234 	inline TInt NumFollowing() const;
       
   235 public:
       
   236 	TUint8 iData[KSizeOfFatDirEntry];
       
   237 	};
       
   238 
       
   239 #endif // SL_BPB1_H