fatfs是支持多个分区的,但当SD读卡器插入到windows中时却只能认出第1个分区,windows认为可移动闪存设备只有一个分区(注意,移动硬盘除外)。正好可以利用这个特性,在SD卡中使用隐藏分区。例如将SD分为两个分区,第1个分区开放给用户,第2个分区保存一些内部数据。
要在fatfs中使用两个分区,需要配置:
#define _DRIVES 2
/* Number of logical drives to be used. This affects the size of internal table. */
#define _MULTI_PARTITION 1
/* When _MULTI_PARTITION is set to 0, each logical drive is bound to same
/ physical drive number and can mount only 1st primaly partition. When it is
/ set to 1, each logical drive can mount a partition listed in Drives[]. */
并需要添加:
const PARTITION Drives[] =
{
{0, 0},
{0, 1}
};
读写第1个分区时:
res = f_mount(0, &fs);
res = f_opendir (&dirs,“0:”);
读写第2个分区时:
res = f_mount(1, &fs);
res = f_opendir (&dirs,“1:”);