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

📄 fat.h

📁 FAT32文件系统
💻 H
字号:
#ifndef	_FAT_H
#define	_FAT_H
#include	"reader.h"
struct FATBpb
{
	unsigned char	jumpBoot[3];
	unsigned char	OEMName[8];
	UInt16			BytsPerSec;
	unsigned char	SecPerClus;
	UInt16			RsvdSecCnt;
	unsigned char	NumFATs;
	UInt16			RootEntCnt;
	UInt32			TotSec;
	unsigned char	Media;
	UInt16			FATSz;
	UInt16			SecPerTrk;
	UInt16			NumHeads;
	UInt32			HiddSec;
	unsigned char	DrvNum;
	UInt32			VolID;
	unsigned char	BootSig;
	unsigned char	VolLable[11];
	unsigned char	FilSysType[8];
	UInt16			ExtFlag;
	UInt16			FSVer;
	UInt32			RootClus;
	UInt16			FSInfo;
	UInt16			BkBootSec;
};

struct FATFdt
{
	unsigned char	Name[11];
	unsigned char	Attr;
	unsigned char	NTRes;
	unsigned char	CrtTimeTenth;
	UInt16			CrtTime;
	UInt16			CrtDate;
	UInt16			LstAccDate;
	UInt32			FstClus;
	UInt16			WrtTime;
	UInt16			WrtDate;
	UInt32			FileSize;
	unsigned char LongName[256];
};
struct FATDriverMessage
{
	UInt16	SecPerClus;
	UInt16	NumFATs;
	UInt32	Fat1Addr;
	UInt32	FATSz;
	UInt32	RootAddr;
	UInt32	DataAddr;
	UInt32	TotSec;
	UInt32	MaxClusNum;
	UInt32	Capacity;
	UInt32	Cluster;
	unsigned char *ClusterBuf;
	UInt32	fat;
	unsigned char FatBuf[512];
};
struct FATDirectoryMessage
{
	UInt32	Cluster;			//当前访问到的簇
	UInt32	Offset;				//当前访问的fdt的偏移量
	UInt32	FatherOffset;		//其FDT在父目录中的偏移量
	UInt32	FatherCluster;		//其FDT在父目录中的簇号
	UInt32	FatherFstClus;		//父目录的首簇号
	struct FATFdt	Child;		//当前访问到的目录的项属性
	struct FATFdt	Folder;		//本目录的一些属性
};
struct FATFileMessage
{
	UInt32	FatherFstClus;	//父目录的首簇号
	UInt32	FatherOffset;	//其FDT在父目录中的偏移量
	UInt32	FatherCluster;	//其FDT在父目录中的簇号
	struct FATFdt	file;	//本文件的一些属性
	UInt32	Cluster;		//当前访问到的簇
	UInt32	ptr;			//当前访问到的簇内偏移量
};

extern UInt16 FAT_GetInt16(unsigned char *pBuf);
extern UInt32 FAT_GetInt32(unsigned char *pBuf);
extern void FAT_SetInt16(unsigned char *pBuf,UInt16 value);
extern void FAT_SetInt32(unsigned char *pBuf,UInt32 value);


extern PDriver Fat_OpenDriver(PDisk pDisk,UInt32 PartitionPos);
extern PDirectory	Fat_OpenDirectory(PDriver pDriver,UInt32 DirectoryMark);
//功能:打开一个已经存在的文件.将一个目录id转换为一个目录对象.
//入口:分区对象,目录id.
//出口:新的目录对象.
extern UInt32	Fat_Create(PDirectory pDirectory);
//功能:在某目录创建一个新的子目录
//入口:父目录标记,子目录名称.
//出口:子目录对象.
extern UInt32	Fat_SearchFirst(PDirectory pDirectory);
//功能:查找某目录下的第一个子目录项(不算.. .)
//入口:父目录对象
//出口:目录项类型(文件或者子目录),目录项标记.0表示没有任何文件和子目录
extern UInt32	Fat_SearchNext(PDirectory pDirectory);
//功能:查找某目录下的下一个子目录项(不算.. .)
//入口:父目录对象
//出口:目录项类型(文件或者子目录),目录项标记.0表示已经查到结束.
extern UInt32	Fat_SearchPrev(PDirectory pDirectory);
//功能:查找某目录下的上一个子目录项(不算.. .)
//入口:父目录对象
//出口:目录项类型(文件或者子目录),目录项标记.0表示已经查到第一个.
extern UInt32	Fat_GotoAny(PDirectory pDirectory,UInt32 num);
//功能:查找某目录下第上一个子目录项(不算.. .)
//入口:父目录对象,第几个目录项.
//出口:目录项类型(文件或者子目录),目录项标记.0不存在.
extern UInt32	Fat_SearchName(PDirectory pDirectory,unsigned char *FileName);
//功能:查找某目录下是否存在某目录项.
//入口:父目录对象,文件名称
//出口:目录项类型(文件或者子目录),目录项标记.0不存在.
extern UInt32	Fat_GetFileNum(PDirectory pDirectory);
//功能:查找某目录下存在多少个文件.
//入口:父目录对象
//出口:文件个数.
extern UInt32	Fat_GetDirectoryNum(PDirectory pDirectory);
//功能:查找某目录下存在多少个子目录.
//入口:父目录对象
//出口:子目录个数.
extern UInt32	Fat_GetChildNum(PDirectory pDirectory);
//功能:查找某目录下存在多少个目录项(包括文件).
//入口:父目录对象
//出口:子目录和文件个数和.
extern void	Fat_RenameDirectory(PDirectory pDirectory,unsigned char*FileName);
//功能:重新命名一个目录
//入口:目录对象
//出口:无.(今后根据需要添加,比如操作不成功等.所有void都与此同)
extern void	Fat_RenameFile(PFile pFile,unsigned char*FileName);
//功能:重新命名一个文件.
//入口:文件对象.
//出口:无
extern void	Fat_ModifyDirectoryAttr(PDirectory pDirectory);
//功能:重新命名一个目录
//入口:目录对象
//出口:无.(今后根据需要添加,比如操作不成功等.所有void都与此同)
extern void	Fat_ModifyFileAttr(PFile pFile);
//功能:重新命名一个文件.
//入口:文件对象.
//出口:无

extern void	Fat_DeleteDirectory(PDirectory pDirectory);	
//功能:删除一个目录
//入口:目录对象
//出口:无.
extern PFile	Fat_OpenFile(PDirectory pDirectory,UInt32 FileMark);
//功能:打开一个已经存在的文件.
//入口:目录对象,文件标记.
//出口:文件对象.
extern PFile	Fat_CreateFile(PDirectory pDirectory,unsigned char *FileName);
//功能:创建一个新文件.
//入口:目录对象.
//出口:文件对象.
extern signed int	Fat_GetChar(PFile pFile);
//功能:从文件中读取一个字符.
//入口:文件对象(已经存在的文件).
//出口:输出字符.(0~255 以外就表示文件末尾)
extern void	Fat_PutChar(PFile pFile,unsigned char ch);
//功能:将一个字符写入文件.
//入口:文件对象(新建方式).
//出口:无
extern void	Fat_ReadFile(PFile pFile,unsigned char *buf,UInt32	size);
//功能:从文件中读取一块数据.
//入口:文件对象(已经存在的文件),数据长度和缓冲区.
//出口:无
extern void	Fat_WriteFile(PFile pFile,unsigned char *buf,UInt32 size);
//功能:向文件中写入一块数据.
//入口:文件对象(新建方式),数据长度和缓冲区.
//出口:无

extern void	Fat_DeleteFile(PFile pFile);
//功能:删除一个文件.
//入口:文件对象.
//出口:无
extern void	Fat_CloseFile(PFile pFile);
//功能:关闭一个文件,释放文件对象.
//入口:文件对象.
//出口:无
extern void	Fat_Seek(PFile pFile,UInt32 pos,U8 mode);
//功能:将文件读指针定位到某处.
//入口:文件对象,位偏移置,mode:FILE_END,FILE_BEGIN,FILE_CUR.
//出口:无
#endif	

⌨️ 快捷键说明

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