在线时间302 小时
UID179403
ST金币1436
蝴蝶豆62
注册时间2015-1-9
该用户从未签到
金牌会员
- 最后登录
- 2021-12-18
|
发表于 2019-5-23 15:54:25
|
显示全部楼层
FRESULT result;
FATFS fs; /* File system object for flash disk logical drive */
FIL fil; /* File object */
FILINFO fno;
char spath[4]; /* SFLASH logical drive path */
BYTE work[FF_MAX_SS];
uint32_t br, bw;
typedef struct _filesystem_info_t
{
int total_space;
int free_space;
} filesystem_info;
filesystem_info fatfs_info;
filesystem_info fatfs_get_info(uint8_t *drv)
{
FATFS *fs;
uint8_t res;
DWORD fre_clust=0, fre_sect=0, tot_sect=0;
filesystem_info info;
memset(&info, 0x0, sizeof(filesystem_info));
res = f_getfree((const TCHAR*)drv, &fre_clust, &fs);
if(res==0)
{
tot_sect = (fs->n_fatent - 2) * fs->csize;
fre_sect = fre_clust * fs->csize;
if(tot_sect<20480)
{
info.total_space = tot_sect>>1;
info.free_space = fre_sect>>1;
}
else
{
info.total_space = tot_sect>>11;
info.free_space = fre_sect>>11;
}
}
return info;
}
void uctsk_lua_init(void)
{
FATFS_LinkDriver( &SFLASH_Driver, spath );
f_mount( &fs, (TCHAR const*) spath, 0 );
fatfs_info = fatfs_get_info( (uint8_t*) spath );
if ( fatfs_info.total_space == 0 || fatfs_info.free_space <= 0x100 )//0x1BC0
{
f_mkfs ( (TCHAR const*) spath, FM_ANY, 0, work, sizeof(work));
fatfs_info = fatfs_get_info( (uint8_t*) spath );
}
FATFS_UnLinkDriver( spath );
}
以上是我使用的,可以参考 |
评分
-
查看全部评分
|