新手上路
- 积分
- 29
- 金钱
- 29
- 注册时间
- 2019-7-30
- 在线时间
- 5 小时
|
1金钱
近期项目中发现一个问题,设备不知何故,flash空间被占满,导致无法写入新内容,只能格式化恢复,但是记录文件就全部丢了。flash的容量是8M,平时需要写入的文件总大小在50K左右,用完就删除,使用时再次写入。
拿到过一个出问题的flash,读出根目录只有我需要写的那几个文件,总大小32K左右,删除其中一个文件后,确实也只释放了被删掉文件的空间大小。
求助各位大佬,空间突然被写满的原因在哪?
写文件函数如下:
u8 write_file(const TCHAR *path,DWORD offset,u8 *buf,u16 len)
{
u8 res=0xFF,nRetry=0;
LED3=LED_ON;
// f_mount(0, &fss); //初始化必须mount
while(res!=FR_OK)
{
if(offset==0)
{
res = f_open( &file , path , FA_CREATE_ALWAYS | FA_WRITE );
}
else
{
res = f_open( &file , path , FA_OPEN_ALWAYS | FA_WRITE );
f_lseek(&file, f_size(&file));
}
if ( res != FR_OK )
{
nRetry++;
sprintf(disinfo,"%d,%d",res,nRetry);
Display_InfoMode("w_open",disinfo);
while((GPIO_ReadInputDataBit(KEY1_GPIO_Port, KEY1_Pin) == 1)||(GPIO_ReadInputDataBit(KEY2_GPIO_Port, KEY2_Pin) == 1));
delay_ms(100);
}
}
/* 将缓冲区的数据写到文件中 */
res=0xFF,nRetry=0;
while(res!=FR_OK)
{
res = f_write(&file, buf, len, &br);
if ( res != FR_OK )
{
nRetry++;
sprintf(disinfo,"%d,%d",res,nRetry);
Display_InfoMode("w_write",disinfo);
while((GPIO_ReadInputDataBit(KEY1_GPIO_Port, KEY1_Pin) == 1)||(GPIO_ReadInputDataBit(KEY2_GPIO_Port, KEY2_Pin) == 1));
delay_ms(100);
}
}
res=0xFF,nRetry=0;
while(res!=FR_OK)
{
res = f_sync(&file);
if ( res != FR_OK )
{
nRetry++;
sprintf(disinfo,"%d,%d",res,nRetry);
Display_InfoMode("w_sync",disinfo);
while((GPIO_ReadInputDataBit(KEY1_GPIO_Port, KEY1_Pin) == 1)||(GPIO_ReadInputDataBit(KEY2_GPIO_Port, KEY2_Pin) == 1));
delay_ms(100);
}
}
res=0xFF,nRetry=0;
while(res!=FR_OK)
{
res = f_close(&file);
if ( res != FR_OK )
{
nRetry++;
sprintf(disinfo,"%d,%d",res,nRetry);
Display_InfoMode("w_close",disinfo);
while((GPIO_ReadInputDataBit(KEY1_GPIO_Port, KEY1_Pin) == 1)||(GPIO_ReadInputDataBit(KEY2_GPIO_Port, KEY2_Pin) == 1));
delay_ms(100);
}
}
LED3=LED_OFF;
// else
// {
// debug_out( "\r\n occur error the error code is %d \r\n",res );
// }
// debug_out("end write file\r\n");
return res;
}
|
|