⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fat.h

📁 CIRRUS 公司EP93XX系列CPU的WINCE下的BSP
💻 H
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
//------------------------------------------------------------------------------
//
//  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
//  ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
//  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//  PARTICULAR PURPOSE.
//
//------------------------------------------------------------------------------
#ifndef _FAT_H_
#define _FAT_H_

#define READ_BUFFER_START       (SDRAM_VIRTUAL_MEMORY + 0x8000)		// Start and length of read buffer.
#define READ_BUFFER_LENGTH_MAX  0x8000
#define SECTOR_CACHE_START      (SDRAM_VIRTUAL_MEMORY + 0x6900)		// Sound match boot.bib reserved area.

#define SECTOR_SIZE                512		// sector size (in bytes).
#define PARTSIG_SIZE                 2		// partition signature size (in bytes)
#define PARTTBL_SIZE                64		// whole partition table size (in bytes)
#define PARTACTV_FLAG             0x80		// active partition flag
#define MAX_PARTITIONS               4		// total number of partition table entries

//
// Recognized FAT filesystem types.
//
typedef enum
{
	FAT_12 = 0,
	FAT_16,
    FAT_32
} FAT_TYPE;

//
// FAT cluster types.
//
typedef enum
{
	EOF_CLUSTER = 1,
	DATA_CLUSTER,
	BAD_CLUSTER,
	RSVD_CLUSTER
} CLUSTTYPE, *PCLUSTTYPE;

//
// BIOS parameter block structure (part of boot sector).
//

#pragma pack(1)

typedef struct Offset36_FAT16
{
    UCHAR  DriveId16;
    UCHAR  Reserved1;
    UCHAR  ExtRecordSig;
    ULONG  VolSerialNumber;
    UCHAR  VolLabel[11];
    UCHAR  TypeFAT16[8];      // Description only
} tOffset36_FAT16;


#pragma pack(1)

typedef struct Offset36_FAT32
{
    ULONG  SectsPerFAT32;
    USHORT ExtendedFlags;
    UCHAR  FSVersionMajor;
    UCHAR  FSVersionMinor;
    ULONG  RootFirstCluster;
    USHORT FSInfo;
    USHORT BackupBootSect;
    UCHAR  Reserved12[ 12 ];
    UCHAR  DriveId32;
    UCHAR  Reserved32_1;
    UCHAR  ExtRecordSig32;
    ULONG  VolSerialNumber32;
    UCHAR  VolLabel32[11];
    UCHAR  TypeFAT32[8];      // should always be "FAT32"
} tOffset36_FAT32;

#pragma pack(1)

typedef struct BIOSPB_TAG
{
    UCHAR  JumpToBoot[3];
    UCHAR  VersionId[8];  // Not sure that this is located here!
    USHORT BytesPerSect;
    UCHAR  SectsPerClust;   // 1, 2, 4, 8, 16, 32, 64, or 128
    USHORT RsvdSects;
    UCHAR  NumFATs;
    USHORT NumRootEntries;
    USHORT TotalSectors16;  // Non-zero for FAT12 & FAT16 only.
    UCHAR  MediaDesc;
    USHORT SectsPerFAT16;   // sectors in FAT for FAT12 & FAT16 only
    USHORT SectsPerTrack;
    USHORT NumHeads;
    ULONG  NumHiddenSectors;
    ULONG  TotalSectors32;  // Non-zero for FAT32 only
    // Starting at offset 36, FAT12 & FAT16 are different than FAT32.
    UCHAR  Offset36Extension[ sizeof( tOffset36_FAT32 ) ];
} BIOSPB, *PBIOSPB;


typedef struct
{
	FAT_TYPE	FATType;			// FAT filesystem type (12, 16, or 32).
    ULONG       FATLBA;				// LBA start of FAT (first)
    ULONG       RootDirLBA;			// LBA start of root directory
    ULONG       RootDirCluster;     // Cluster start of root directory
    ULONG       DataStartLBA;		// LBA start of data area
    UCHAR       SectsPerClust;
    UCHAR       NumFATs;
    USHORT      NumRootEntries;
    USHORT      ReservedSects;
    ULONG       NumHiddenSectors;
    UCHAR       DriveId;
    USHORT      BytesPerSect;
    USHORT      NumHeads;
    USHORT      SectsPerTrack;
    ULONG       RootDirSectors;
    ULONG       SectorsPerFAT;
    ULONG       TotalSectors;
    ULONG       DataRegionSectors;
    ULONG       CountOfClusters;
    USHORT      phy_cyls;
    USHORT      phy_heads;
    USHORT      phy_sectspertrk;
    BOOL        bLBAMode;
} t_FAT_PARMS;


// Directory file attributes...
//
#define FAT_ATTR_READ_ONLY      0x01
#define FAT_ATTR_HIDDEN         0x02
#define FAT_ATTR_SYSTEM         0x04
#define FAT_ATTR_VOLUME_ID      0x08

#define FAT_ATTR_LONG_NAME      (FAT_ATTR_READ_ONLY | FAT_ATTR_HIDDEN | FAT_ATTR_SYSTEM | FAT_ATTR_VOLUME_ID)
                                
#define FAT_ATTR_DIRECTORY      0x10
#define FAT_ATTR_ARCHIVE        0x20                                


//
// FAT directory entry structure.
//
#pragma pack(1)

typedef struct
{
    UCHAR  FileName[8];
    UCHAR  FileExt[3];
    UCHAR  FATTr;
    UCHAR  NT_Reserved;
    UCHAR  Create10thOfSecs;
    USHORT CreateTime;
    USHORT CreateDate;
    USHORT LastAccessDate;
    USHORT FirstClusterHigh;    // High word of this entries first cluster
                                // Always 0 for a FAT12 or FAT16 volume.
    USHORT LModTime;
    USHORT LModDate;
    USHORT FirstClusterLow;
    ULONG  FileSize;
} DIRENTRY, *PDIRENTRY;


#pragma pack(1)

typedef struct
{
    UCHAR ucCylinder;
    UCHAR ucHead;
    UCHAR ucSector;
} CHS_ENTRY, *pCHS_ENTRY;

//
// FAT directory entry structure.
//
#pragma pack(1)

typedef struct
{
    UCHAR       ucBootFlag;
    CHS_ENTRY   CHSBegin;       // CHS location of start of partition
    UCHAR       ucPartitionType;
    UCHAR       CHSEnd;         // CHS location of end of partition
    ULONG       startLBA;       // LBA location of start of partition
    ULONG       numSectors;     // number of sectors in partition
} PARTITION_ENTRY, *pPARTITION_ENTRY;


//////////////////////////////////////////
//
// BIN image and record headers
//
#pragma pack(1)

typedef struct	// Image header (one per BIN image)
{
    CHAR SyncBytes[7];
    ULONG ImageAddr;
    ULONG ImageLen;
} IMAGEHDR, *PIMAGEHDR;

#pragma pack(1)
typedef struct   // Record header (one per section in image)
{
    ULONG RecordAddr;
    ULONG RecordLen;
    ULONG RecordChksum;
} RECORDHDR, *PRECORDHDR;

//
// Function prototypes
//
BOOL InitFAT(ULONG uFirstPartitionLBA);
ULONG OpenFile(PCHAR pFileName);
void CloseFile(void);
BOOL lReadFile(PUCHAR pAddress, ULONG Length);

//
// Structure used to keep track of file properties.
//
typedef struct
{
    ULONG FileSize;
	ULONG FirstCluster;
	ULONG CurrentCluster;
	ULONG NumContigClusters;
    PUCHAR pCurReadBuffAddr;
	ULONG NumReadBuffBytes;
    ULONG pTotalReadByte;
} FILEINFO, *PFILEINFO;

#pragma pack()

BOOL InitFAT(ULONG uFirstPartitionLBA);
ULONG OpenFile(PCHAR pFileName);



#endif	// _FAT_H_

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -