fat文件系统中,根目录中存储目录条,每个目录条占用32个字节。含义如下:
在fat文件系统中,这种为短文件名(8+3)目录条信息。
指定根目录条目、文件首蔟号,配置文件的首蔟号
#if !FF_FS_READONLY//不是只读
//配置文件存储的首蔟号
static void st_clust (
FATFS* fs, //文件对象。/* Pointer to the fs object */
BYTE* dir, //目录条目。/* Pointer to the key entry */
DWORD cl //蔟号。/* Value to be set */
)
{
st_word(dir + DIR_FstClusLO, (WORD)cl);//写低16位蔟号
if (fs->fs_type == FS_FAT32) {
//对于fat32文件系统,写高16位蔟号
st_word(dir + DIR_FstClusHI, (WORD)(cl >> 16));
}
}
#endif
根据指定的目录条,返回文件所在蔟号
//返回短目录条目中文件蔟号
static DWORD ld_clust ( /* Returns the top cluster value of the SFN entry */
FATFS* fs, //指向文件系统对象。/* Pointer to the fs object */
const BYTE* dir //指向目录条目。/* Pointer to the key entry */
)
{
DWORD cl;
//dir + DIR_FstClusLO:指向目录条目中的文件所在蔟号(低16位)
//ld_word获取2个字节蔟号
//如果是fat32文件系统,则再获取两个字节文件所在蔟号(高16位)
cl = ld_word(dir + DIR_FstClusLO);//DIR_FstClusLO:26
if (fs->fs_type == FS_FAT32) {
cl |= (DWORD)ld_word(dir + DIR_FstClusHI) << 16;//DIR_FstClusHI:20
}
return cl;
}
长文件名结构信息:
创建一个根目录条目中长文件名条目。
给出长文件名字符串、条目指针、长文件名的序号、短文件名的校验和
//创建一个长文件名
static void put_lfn (
const WCHAR* lfn,//长文件名。 /* Pointer to the LFN */
BYTE* dir