|
发表于 2018-7-27 11:39:20
|
显示全部楼层
15年的贴子,被我找到了,并且帮助我解决了问题,非常感谢!
/* Using fast seek function */
DWORD clmt[SZ_TBL]; /* Cluster link map table buffer */
res = f_open(fp, fname, FA_READ | FA_WRITE); /* Open a file */
res = f_lseek(fp, ofs1); /* This is normal seek (cltbl is nulled on file open) */
fp->cltbl = clmt; /* Enable fast seek function (cltbl != NULL) */
clmt[0] = SZ_TBL; /* Set table size */
res = f_lseek(fp, CREATE_LINKMAP); /* Create CLMT */
...
res = f_lseek(fp, ofs2); /* This is fast seek */
======================分割线:下面是我实际使用时的解决办法==============================
#define SZ_TBL 20
static DataWrite(void)//周期执行函数,周期往文件里写数据
{
static DWORD clmt[SZ_TBL]; /* Cluster link map table buffer */
res = f_open(fp, fname, FA_READ | FA_WRITE); /* Open a file */
if(clmt[0] == 0x00)
{
res = f_lseek(fp, f_sizeof(fp)); /* This is normal seek (cltbl is nulled on file open) */
faddata.cltbl = clmt;
clmt[0] = SZ_TBL;
res = f_lseek(fp,CREATE_LINKMAP);
}
else fp->cltbl = clmt;//每次f_open后,fp->cltbl会变成NULL,所以要把第clmt的地址再次赋值给cltbl
res = f_seek(fp,f_size(fp));
res = f_write(fp,WriteDataBuf,strlen(WriteDataBuf),&bw);
res = f_close(fp);
}
|
|