fatfs相关宏定义说明

本文介绍了fat16、fat32和exfat文件系统的DBR(引导记录)结构,包括它们共有的字段以及exfat特有的部分。还讨论了fat16和fat32中的短文件名和长文件名条目,强调长文件名如何由短文件名条目和多个长文件名条目组成。此外,提到了exfat的卷目录条、蔟位图目录条、大写字符文件目录条以及用户文件目录条。最后,简要提及了MBR和PTE结构。

fat16文件系统DBR
在这里插入图片描述
宏定义如下:

#define BS_JmpBoot			0		//跳转指令。3字节。/* x86 jump instruction (3-byte) */
#define BS_OEMName			3		//OEM名称。8字节。/* OEM name (8-byte) */
#define BPB_BytsPerSec		11		//扇区字节数。2字节。/* Sector size [byte] (WORD) */
#define BPB_SecPerClus		13		//每蔟扇区数。1字节。/* Cluster size [sector] (BYTE) */
#define BPB_RsvdSecCnt		14		//保留扇区数。2字节。/* Size of reserved area [sector] (WORD) */
#define BPB_NumFATs			16		//FAT表个数。1字节。/* Number of FATs (BYTE) */
#define BPB_RootEntCnt		17		//FAT32必须为0,FAT12/16为fat表中根目录区域大小。2字节。/* Size of root directory area for FAT [entry] (WORD) */
#define BPB_TotSec16		19		//FAT32必须为0,FAT12/16为卷大小。2字节。/* Volume size (16-bit) [sector] (WORD) */
#define BPB_Media			21		//介质描述符。1字节。/* Media descriptor byte (BYTE) */
#define BPB_FATSz16			22		//FAT32必须为0,FAT12/16为fat表占用的扇区数。2字节。/* FAT size (16-bit) [sector] (WORD) */
#define BPB_SecPerTrk		24		//每磁道扇区数。2字节。/* Number of sectors per track for int13h [sector] (WORD) */
#define BPB_NumHeads		26		//磁头数。2字节。/* Number of heads for int13h (WORD) */
#define BPB_HiddSec			28	//隐藏扇区数,卷在磁盘中的偏移量,用扇区个数表示。/* Volume offset from top of the drive (DWORD) */
#define BPB_TotSec32		32		//总扇区数,单位为扇区。/* Volume size (32-bit) [sector] (DWORD) */
#define BS_DrvNum			36		//BIOS驱动器号/* Physical drive number for int13h (BYTE) */
#define BS_NTres			37		//win nt错误标志。/* WindowsNT error flag (BYTE) */
#define BS_BootSig			38		//扩展引导标志。/* Extended boot signature (BYTE) */
#define BS_VolID			39		//卷序列号。/* Volume serial number (DWORD) */
#define BS_VolLab			43		//卷标。/* Volume label string (8-byte) */
#define BS_FilSysType		54		//文件系统类型字符串。/* Filesystem type string (8-byte) */
#define BS_BootCode			62		//启动代码。448字节。/* Boot code (448-byte) */
#define BS_55AA				510		//签名。/* Signature word (WORD) */

fat32文件系统DBR
在这里插入图片描述
0~35中使用到的字段与fat16一致。

#define BPB_FATSz32			36		//每FAT扇区数。/* FAT32: FAT size [sector] (DWORD) */
#define BPB_ExtFlags32		40		//标记。/* FAT32: Extended flags (WORD) */
#define BPB_FSVer32			42		//版本。/* FAT32: Filesystem version (WORD) */
#define BPB_RootClus32		44		//根目录首蔟号。/* FAT32: Root directory cluster (DWORD) */
#define BPB_FSInfo32		48		//文件系统信息扇区号。/* FAT32: Offset of FSINFO sector (WORD) */
#define BPB_BkBootSec32		50		//DBR备份扇区号。/* FAT32: Offset of backup boot sector (WORD) */
#define BS_DrvNum32			64		//BIOS驱动器号。/* FAT32: Physical drive number for int13h (BYTE) */
#define BS_NTres32			65		//错误标记。/* FAT32: Error flag (BYTE) */
#define BS_BootSig32		66		//扩展引导标志。/* FAT32: Extended boot signature (BYTE) */
#define BS_VolID32			67		//卷序列号。/* FAT32: Volume serial number (DWORD) */
#define BS_VolLab32			71		//卷标。/* FAT32: Volume label string (8-byte) */
#define BS_FilSysType32		82		//文件系统类型字符串。/* FAT32: Filesystem type string (8-byte) */
#define BS_BootCode32		90		//启动代码,420字节。/* FAT32: Boot code (420-byte) */

exfat文件系统DBR
在这里插入图片描述

#define BPB_ZeroedEx		11		//保留,必须为0。/* exFAT: MBZ field (53-byte) */
#define BPB_VolOfsEx		64		//分区的起始扇区号(隐藏扇区数)。/* exFAT: Volume offset from top of the drive [sector] (QWORD) */
#define BPB_TotSecEx		72		//分区总扇区数。/* exFAT: Volume size [sector] (QWORD) */
#define BPB_FatOfsEx		80		//FAT表起始扇区号(从DBR到FAT表的扇区个数)。/* exFAT: FAT offset from top of the volume [sector] (DWORD) */
#define BPB_FatSzEx			84		//FAT表扇区数。/* exFAT: FAT size [sector] (DWORD) */
#define BPB_DataOfsEx		88		//首蔟起始扇区号(数据区)。/* exFAT: Data offset from top of the volume [sector] (DWORD) */
#define BPB_NumClusEx		92		//总蔟数。/* exFAT: Number of clusters (DWORD) */
#define BPB_RootClusEx		96		//根目录首蔟。/* exFAT: Root directory start cluster (DWORD) */
#define BPB_VolIDEx			100		//卷序列号。/* exFAT: Volume serial number (DWORD) */
#define BPB_FSVerEx			104		//文件系统版本。/* exFAT: Filesystem version (WORD) */
#define BPB_VolFlagEx		106		//卷标志。/* exFAT: Volume flags (WORD) */
#define BPB_BytsPerSecEx	108		//每扇区字节数描述,2的幂。/* exFAT: Log2 of sector size in unit of byte (BYTE) */
#define BPB_SecPerClusEx	109		//每蔟扇区数描述,2的幂。/* exFAT: Log2 of cluster size in unit of sector (BYTE) */
#define BPB_NumFATsEx		110		//fat表个数。/* exFAT: Number of FATs (BYTE) */
#define BPB_DrvNumEx		111		//驱动标记。/* exFAT: Physical drive number for int13h (BYTE) */
#define BPB_PercInUseEx		112		//使用百分比。/* exFAT: Percent in use (BYTE) */
#define BPB_RsvdEx			113		//保留。/* exFAT: Reserved (7-byte) */
#define BS_BootCodeEx		120		//启动代码。/* exFAT: Boot code (390-byte) */

fat16和fat32文件系统中短文件名条目
在这里插入图片描述

#define DIR_Name			0		//短文件名,11字节。/* Short file name (11-byte) */
#define DIR_Attr			11		//属性。/* Attribute (BYTE) */
#define DIR_NTres			12		//小写字母标记。/* Lower case flag (BYTE) */
#define DIR_CrtTime10		13		//创建时间,单位10ms。/* Created time sub-second (BYTE) */
#define DIR_CrtTime			14		//创建时间。/* Created time (DWORD) */
#define DIR_LstAccDate		18		//最后访问日期。/* Last accessed date (WORD) */
#define DIR_FstClusHI		20		//高16bit首蔟。/* Higher 16-bit of first cluster (WORD) */
#define DIR_ModTime			22		//修改时间。/* Modified time (DWORD) */
#define DIR_FstClusLO		26		//低16bit首蔟。/* Lower 16-bit of first cluster (WORD) */
#define DIR_FileSize		28		//文件大小。/* File size (DWORD) */

fat16和fat32文件系统中长文件名:
在这里插入图片描述
注意:长文件名文件目录条目存储:短文件名条目+多个长文件名条目。

#define LDIR_Ord			0		//长文件名序号和标志/* LFN: LFN order and LLE flag (BYTE) */
#define LDIR_Attr			11		//长文件名属性。/* LFN: LFN attribute (BYTE) */
#define LDIR_Type			12		//长文件名条目类型。/* LFN: Entry type (BYTE) */
#define LDIR_Chksum			13		//短文件名校验和。/* LFN: Checksum of the SFN (BYTE) */
#define LDIR_FstClusLO		26		//长文件名条目中,该字段必须为0。/* LFN: MBZ field (WORD) */

exfat文件系统卷目录条:
在这里插入图片描述

//所有exfat目录条第一个字节
#define XDIR_Type			0		//exfat目录类型。/* exFAT: Type of exFAT directory entry (BYTE) */

//卷目录条
#define XDIR_NumLabel		1		//exfat卷标字符数。/* exFAT: Number of volume label characters (BYTE) */
#define XDIR_Label			2		//exfat卷标。/* exFAT: Volume label (11-WORD) */

exfat文件系统蔟位图目录条:
在这里插入图片描述

exfat文件系统大写字符文件目录条:
在这里插入图片描述


//大写转换表目录条
#define XDIR_CaseSum		4		//exfat大写转换表校验和/* exFAT: Sum of case conversion table (DWORD) */
#define XDIR_NumSec			1		//exfat附属目录项数。/* exFAT: Number of secondary entries (BYTE) */

exfat32用户文件目录条:
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

//文件目录条
#define XDIR_SetSum			2		//exfat检验和。/* exFAT: Sum of the set of directory entries (WORD) */
#define XDIR_Attr			4		//exfat文件属性。/* exFAT: File attribute (WORD) */
#define XDIR_CrtTime		8		//exfat文件创建时间。/* exFAT: Created time (DWORD) */
#define XDIR_ModTime		12		//exfat文件修改时间。/* exFAT: Modified time (DWORD) */
#define XDIR_AccTime		16		//exfat文件最后访问时间。/* exFAT: Last accessed time (DWORD) */
#define XDIR_CrtTime10		20		//exfat文件创建时间,精确至10ms。/* exFAT: Created time subsecond (BYTE) */
#define XDIR_ModTime10		21		//exfat文件最后修改时间,精确至10ms。/* exFAT: Modified time subsecond (BYTE) */
#define XDIR_CrtTZ			22		//exfat创建时间时区差,间隔15分钟。/* exFAT: Created timezone (BYTE) */
#define XDIR_ModTZ			23		//exfat最后修改时间时区差,间隔15分钟。/* exFAT: Modified timezone (BYTE) */
#define XDIR_AccTZ			24		//exfat最后访问时间时区差,间隔15分钟。/* exFAT: Last accessed timezone (BYTE) */
#define XDIR_GenFlags		33		//exfat第二个条目标志。/* exFAT: General secondary flags (BYTE) */
#define XDIR_NumName		35		//exfat文件名字符数。/* exFAT: Number of file name characters (BYTE) */
#define XDIR_NameHash		36		//exfat文件名hash值。/* exFAT: Hash of file name (WORD) */
#define XDIR_ValidFileSize	40		//exfat文件大小。/* exFAT: Valid file size (QWORD) */
#define XDIR_FstClus		52		//exfat文件首蔟。/* exFAT: First cluster of the file data (DWORD) */
#define XDIR_FileSize		56		//exfat文件大小。/* exFAT: File/Directory size (QWORD) */

MBR结构:
在这里插入图片描述
PTE结构说明
在这里插入图片描述

#define MBR_Table			446		//MBR中主引导程序代码,占用446字节,也是DPT的偏移量。/* MBR: Offset of partition table in the MBR */
#define SZ_PTE				16		//MBR中分区条目大小,一个分区使用16字节来表示。/* MBR: Size of a partition table entry */
#define PTE_Boot			0		//引导标志,0x00表示非活动分区,0x80为活动分区,一个磁盘只能有一个活动分区。/* MBR PTE: Boot indicator */
#define PTE_StHead			1		//分区的起始磁头号。/* MBR PTE: Start head */
#define PTE_StSec			2		//分区的起始扇区号(每个磁道分成多个扇区,并对扇区进行了编号)。/* MBR。 PTE: Start sector */
#define PTE_StCyl			3		//分区的起始柱面(磁道号)。/* MBR PTE: Start cylinder */
#define PTE_System			4		//分区类型/* MBR PTE: System ID */
#define PTE_EdHead			5		//分区的结束磁头号。/* MBR PTE: End head */
#define PTE_EdSec			6		//分区的结束扇区号。/* MBR PTE: End sector */
#define PTE_EdCyl			7		//分区的结束柱面(磁道号)。/* MBR PTE: End cylinder */
#define PTE_StLba			8		//起始扇区数,从磁盘最开始到当前分区的扇区个数。/* MBR PTE: Start in LBA */
#define PTE_SizLba			12		//当前分区占用的扇区个数。/* MBR PTE: Size in LBA */
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值