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

📄 fat.h

📁 arm(s3c440b)读写u盘源程序
💻 H
字号:
#ifndef _FAT_H
#define _FAT_H

#include "DataType.h"
// file attribute 
#define ATTR_READ_ONLY	0x01
#define ATTR_HIDDEN		0x02
#define ATTR_SYSTEM		0x04
#define ATTR_VOLUME_ID	0x08
#define ATTR_DIRECTORY	0x10
#define ATTR_ARCHIVE	0x20
typedef struct _BPB_BLOCK {
	BYTE BS_jmpBoo[3];
	BYTE BS_OEMName[8];
	WORD BPB_BytesPerSec;
	BYTE BPB_SecPerClus;
	BYTE BPB_RsvdSecCn[2];
	BYTE BPB_NumFATs;
	WORD BPB_RootEntCnt;
	WORD BPB_TotSec16;
	BYTE BPB_Media;
	WORD BPB_FATSz16;
	WORD BPB_SecPerTrk;
	WORD BPB_NumHeads;
	DWORD BPB_HiddSec;
	DWORD BPB_TotSec32;
	union{
			struct{
			BYTE BS_DrvNum;		// offset: 36
			BYTE BS_Reserved1;
			BYTE BS_BootSig;
			BYTE BS_VolID[4];
			BYTE BS_VolLab[11];
			BYTE BS_FilSysType[8];	// offset: 54
			}FAT16;
			struct{
			DWORD	BPB_FATSz32;
			WORD	BPB_ExtFlags;
			WORD	BPB_FSVer;
			DWORD	BPB_RootClus;
			WORD	BPB_FSInfo;
			WORD	BPB_BkBootSec;
			BYTE	res[12];
			BYTE	BS_DrvNum;
			BYTE	res1;
			BYTE	BS_BootSig;
			BYTE	BS_VoilD[4];
			BYTE	BS_VoilLab[11];
			BYTE	BS_FilSysType[8];
			}FAT32;	
		}FAT;	
	BYTE ExecutableCode[420];
	BYTE Marker[2];

} BPB_BLOCK,*PBPB_BLOCK;
//Simple BPB control block
typedef struct _BPB {
	BYTE  SecPerClus;
	WORD  BytesPerSec;
	WORD  RsvdSecCnt;
	WORD  RootEntCnt;
	DWORD FATSz;
	DWORD FatStartSector;
	DWORD RootStartSector;
	DWORD RootClusterNum;
	DWORD FSI_Free_Count;
	DWORD FSI_Nxt_Free; 
	DWORD FirstDataSector;

}BPB_INFO,*pBPB_INFO;
//目录结构
typedef struct{
	char DIR_Name[11];
	BYTE DIR_Attr;
	BYTE DIR_NTRes;
	BYTE DIR_CrtTimeTenth;
	WORD DIR_CrtTime;
	WORD DIR_CrtDate;
	WORD DIR_LstAccDate;
	WORD DIR_FstClusHI;
	WORD DIR_WrtTime;
	WORD DIR_WrtDate;
	WORD DIR_FstClusLO;
	DWORD DIR_FileSize;

}DIR_STRUCT, * PDIR_STRUCT;
//file information 
typedef struct _FILE
{	
	BYTE	bOpen;
	BYTE	FileName[256];
	DWORD	StartCluster;
	DWORD	LengthInByte;
	DWORD	ClusterPointer;
    DWORD	SectorPointer;
    WORD	OffsetofSector;
//    BYTE	SectorofCluster;
//    DWORD	pointer;
//    DWORD	FatSectorPointer;
	DWORD   DirSector;
	BYTE    DirNumOffSet;
	DWORD    Readpointer;
}FILE_INFO,*pFILE_INFO;
#define MAXDIRDEPTH 10//最多为10层目录
// dir information
typedef struct _DIR
{
	DWORD Link[MAXDIRDEPTH];	
	DWORD StartSector;
	DWORD StartCluster;
	DWORD ParentStartCluster;	
	BYTE  DepthIndex;
	BYTE  bRootDir;

}DIR_INFO,*pDIR_INFO;
//FAT32的信息
typedef struct _FSINFO_BLOCK{
	BYTE res1[488];
	DWORD FSI_Free_Count;
	DWORD FSI_Nxt_Free;
	BYTE  FSI_Reserved2[12];
	DWORD FSI_TrailSig;
}FSINFO_BLOCK, *PFSINFO_BLOCK;
//****************************************************************************
//Functions;
//****************************************************************************
BYTE InitFsys(void);
DWORD GetNextCluster(DWORD ClusterNum);
DWORD ClusterToSec(DWORD ClusterNum);
DWORD SecToCluster(DWORD SectorNum);
DWORD SeekSector(DWORD Sector, const char dirname[11],struct _FILE *file);
DWORD LinkClusterNum(DWORD ClusterNum,WORD nCluster);
DWORD SeekEmptyCluster(void);
BYTE  DeleteClusterList(DWORD ClusterNum);
BYTE  UpdateFat(void);
#endif

⌨️ 快捷键说明

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