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

📄 fat.h

📁 檔案系統FAT讀寫USB pen driver sample code
💻 H
字号:
typedef struct _MBR_BLOCK {    //主引导区结构体
  INT8 Res[454];
  unsigned long StartSector;     //起始簇
  unsigned long TotalSector;    //簇的总数
  INT8 Res1[50];
} MBR_BLOCK,* PMBR_BLOCK;

typedef struct _BPB_BLOCK {
  INT8 BS_jmpBoo[3];
  INT8 BS_OEMName[8];
  INT16 BPB_BytesPerSec;   //每扇区字节数
  INT8 BPB_SecPerClus;       //每簇扇区数
  INT8 BPB_RsvdSecCn[2];   //保留区域中的保留扇区数
  INT8 BPB_NumFATs;         //此卷中FAT结构的分数
  INT16 BPB_RootEntCnt;     //对于FAT12和FAT16卷,此域中为根目录项数(每个项长度为32字节)
  INT16 BPB_TotSec16;       //此域为存储卷上的扇区总数
  INT8 BPB_Media;
  INT16 BPB_FATSz16;
  INT16 BPB_SecPerTrk;
  INT16 BPB_NumHeads;
  unsigned long BPB_HiddSec;
  unsigned long BPB_TotSec32;
  INT8 BS_DrvNum;
  INT8 BS_Reserved1;
  INT8 BS_BootSig;
  INT8 BS_VolID[4];
  INT8 BS_VolLab[11];
  INT8 BS_FilSysType[8];
  INT8 ExecutableCode[448];
  INT8 Marker[2];         //分区结束标志
} BPB_BLOCK,* PBPB_BLOCK;

typedef struct _SYS_INFO_BLOCK{
  unsigned long StartSector;
  unsigned long TotalSector;
  //INT8 BS_jmpBoo[3];
  //INT8 BS_OEMName[8];
  INT16 BPB_BytesPerSec;
  INT8 BPB_SecPerClus;
  //INT8 BPB_RsvdSecCn[2];
  INT8 BPB_NumFATs;
  INT16 BPB_RootEntCnt;
  INT16 BPB_TotSec16;
  INT8 BPB_Media;
  INT16 BPB_FATSz16;
  INT16 BPB_SecPerTrk;
  INT16 BPB_NumHeads;
  unsigned long BPB_HiddSec;
  unsigned long BPB_TotSec32;
  INT8 BS_DrvNum;
  //INT8 BS_Reserved1;
  INT8 BS_BootSig;
  INT8 BS_VolID[4];
  INT8 BS_VolLab[11];
  INT8 BS_FilSysType[8];
  //INT8 ExecutableCode[448];
  //INT8 Marker[2];
  ///////////////////////////////
  unsigned long FatStartSector;
  unsigned long RootStartSector;
  //unsigned long DataStartSector;
  unsigned long FirstDataSector;
  //unsigned long FirstSectorofCluster;
} SYS_INFO_BLOCK,* PSYS_INFO_BLOCK;

typedef struct _FILE_INFO{  //文件句柄 结构体
  unsigned char bFileOpen;
  unsigned int StartCluster;       //文件的起始簇
  unsigned long LengthInByte;  //文件字节长度
  unsigned int ClusterPointer;   //扇区指针
  unsigned long SectorPointer;  //簇指针
  unsigned int OffsetofSector;
  unsigned char SectorofCluster;
  unsigned long pointer;
  unsigned int	FatSectorPointer;
} FILE_INFO, * PFILE_INFO;

typedef struct _FREE_FAT_INFO{
  unsigned long SectorNum;
  unsigned int OffsetofSector;
  unsigned long OldSectorNum;
} FREE_FAT_INFO, * PFREE_FAT_INFO;

typedef struct _DIR_INFO{   //目录项结构,根目录区(Root Directory Region)
	unsigned char name[8];    // 文件名
	unsigned char extension[3]; // 文件类型,扩展名
	unsigned char attribute;   // 文件属性
	unsigned char Reserved[10];// 保留
	unsigned int lastUpdateDate;  // 上次更新时间
	unsigned int lastUpdateTime;// 上次更新日期
	unsigned int startCluster;    // 起始簇号
	unsigned long length;     // 文件大小,文件长度
} DIR_INFO,* PDIR_INFO;

unsigned long FirstSectorofCluster(unsigned int n);
unsigned int ThisFatSecNum(unsigned int clusterNum);
unsigned int ThisFatEntOffset(unsigned int clusterNum);
unsigned int GetNextClusterNum(unsigned int clusterNum);
unsigned int GetClusterNumFromSectorNum(unsigned long sectorNum);
//unsigned long GetSecNumFromPointer(void);
unsigned char GoToPointer(unsigned long pointer);
unsigned int GetFreeCusterNum(void);
unsigned int CreateClusterLink(unsigned int currentCluster);
unsigned char DeleteClusterLink(unsigned int clusterNum);
void UpdateFat(unsigned long sectorNum);

⌨️ 快捷键说明

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