FATFS文件系统问题
在看fatfs文件系统的f_mkfs格式化函数时,对它的一些算法不解:
FAT16的情况下:
// 计算fat表占字节数 (n_clst * 2) + 4;
n_fat = (fmt == FS_FAT12) ? (n_clst * 3 + 1) / 2 + 3 : (n_clst * 2) + 4;
n_fat = (n_fat + SS(fs) - 1) / SS(fs); // 应该是计算fat表所占扇区数
n_rsv = 1; // 保留扇区,fat16固定为1
n_dir = (DWORD)N_ROOTDIR * SZ_DIR / SS(fs); // 计算根目录所占扇区数
b_fat = b_vol + n_rsv; /* FAT area start sector */
b_dir = b_fat + n_fat * N_FATS; /* Directory area start sector */
b_data = b_dir + n_dir; /* Data area start sector */
但是fat白皮书中根目录所占扇区数是这样的公式:
RootDirSectors = ((BPB_RootEntCnt * 32) + (BPB_BytsPerSec – 1)) / BPB_BytsPerSec;
不明白的地方:
1、n_fat = (n_fat + SS(fs) - 1) / SS(fs);
计算fat表所占扇区数为什么不是n_fat = n_fat / SS(fs);
2、n_dir = (DWORD)N_ROOTDIR * SZ_DIR / SS(fs);
计算根目录所占扇区数为什么不是 n_dir = ((DWORD)N_ROOTDIR * SZ_DIR + SS(fs) - 1) / SS(fs);
FAT16的情况下:
// 计算fat表占字节数 (n_clst * 2) + 4;
n_fat = (fmt == FS_FAT12) ? (n_clst * 3 + 1) / 2 + 3 : (n_clst * 2) + 4;
n_fat = (n_fat + SS(fs) - 1) / SS(fs); // 应该是计算fat表所占扇区数
n_rsv = 1; // 保留扇区,fat16固定为1
n_dir = (DWORD)N_ROOTDIR * SZ_DIR / SS(fs); // 计算根目录所占扇区数
b_fat = b_vol + n_rsv; /* FAT area start sector */
b_dir = b_fat + n_fat * N_FATS; /* Directory area start sector */
b_data = b_dir + n_dir; /* Data area start sector */
但是fat白皮书中根目录所占扇区数是这样的公式:
RootDirSectors = ((BPB_RootEntCnt * 32) + (BPB_BytsPerSec – 1)) / BPB_BytsPerSec;
不明白的地方:
1、n_fat = (n_fat + SS(fs) - 1) / SS(fs);
计算fat表所占扇区数为什么不是n_fat = n_fat / SS(fs);
2、n_dir = (DWORD)N_ROOTDIR * SZ_DIR / SS(fs);
计算根目录所占扇区数为什么不是 n_dir = ((DWORD)N_ROOTDIR * SZ_DIR + SS(fs) - 1) / SS(fs);
...全文
相关推荐
fatfs.rar_fatfs
fatFS for Stellaris MCU from stellarisware library
FatFs文件系统中文手册
中文手册里面详细介绍了怎么移植文件系统,对API函数也有非常详细的介绍
FATFS文件系统复制文件和文件夹
FATFS文件系统复制文件和文件夹
基于stm32、spi协议的Fatfs文件系统移植(完整源码)
基于stm32、spi协议的Fatfs文件系统移植 博客地址:https://blog.csdn.net/weixin_42653531/article/details/103745344
Fatfs文件系统的源代码
Fatfs 嵌入式Fatfs文件系统的源代码,学习Fatfs系统的原理运作所用。


单片机/工控
