1
我的程序有一个运行initUSB()的循环,然后多次运行writeEssentials()。 initUSB()是一个将USB挂载到目录的函数。 writeEssentials()是一个函数,用于打开一个文件并附加数据,然后关闭该文件。在程序运行期间文件系统转换为只读
在程序初始运行一分钟后,程序会报告文件系统是“只读”的,并会拒绝再写入数据,直到initUSB()再次运行。这发生在天气或不是我fprintf()到文件指针。作为一种临时解决方案,如果writeEssentials()变为只读,它会重新安装驱动器。这很有效,但我宁愿不要每分钟重新安装一次驱动器。
为什么会发生这种情况,我该如何解决这个错误?
该程序在TS-7800上的Debian嵌入式Linux系统上运行。
InitUSB:
int initUSB(){
int i;
FILE * filecheck = fopen(HMITelemCheckFile, "r");
for(i = 0; i < 26; i++) {
char usbMountFromPathTry[256];
char sdanum[5];
strcpy(usbMountFromPathTry, usbMountFromPath);
sprintf(sdanum, "%c1", i+'a');
strcat(usbMountFromPathTry, sdanum);
if(!mount(usbMountFromPathTry, usbMountToPath, "vfat", (long)NULL, NULL)){
printf("Mount successful\n");
return 1;
} else if(!mount(usbMountFromPathTry, usbMountToPath, "vfat", MS_REMOUNT, NULL)){
printf("Mount successful\n");
return 1;
}
printf("Mount error: ");
printf("%s\n", usbMountFromPathTry);
}
printf("Mount ERROR\n");
return 0;
}
writeEssentials():
void writeEssentials(){
FILE * file = fopen(usbMountEssentials, "a+");
fflush(file);
perror("file");
if(file == NULL){
initUSB();
printf("null file\n");
return;
}
fprintf(file, "\n%s, ", getDate());
fprintf(file, "%s, ", getTime());
fprintf(file, "%1.2f, ", getSpeed());
fprintf(file, "%d, ", getRPM());
fprintf(file, "%d, ", getRegen());
fprintf(file, "%d, ", getAirgap());
fprintf(file, "%d, ", getBattery());
fprintf(file, "%.2f, ", *(getADCTemps()+COMPUTER_BOX_TEMP_INDEX));
fprintf(file, "%.2f, ", *(getBMS()+BMS_TEMP_INDEX+(BMS_NUM_VAR*0)));
fprintf(file, "%.2f, ", *(getBMS()+BMS_TEMP_INDEX+(BMS_NUM_VAR*1)));
fprintf(file, "%.2f, ", *(getBMS()+BMS_TEMP_INDEX+(BMS_NUM_VAR*2)));
fprintf(file, "%.2f, ", *(getMPPT()+MPPT_TEMP_INDEX+(MPPT_NUM_VAR*0)));
fprintf(file, "%.2f, ", *(getMPPT()+MPPT_TEMP_INDEX+(MPPT_NUM_VAR*1)));
fprintf(file, "%.2f, ", *(getMPPT()+MPPT_TEMP_INDEX+(MPPT_NUM_VAR*2)));
fprintf(file, "%.2f, ", *(getMPPT()+MPPT_TEMP_INDEX+(MPPT_NUM_VAR*3)));
fprintf(file, "%s, ", getLat());
fprintf(file, "%s, ", getLong());
int i;
for(i = 0; i < getNumErrors(); i++){
//fprintf(file, "%s, ", getErrorText(*(getErrors()+i)));
}
fclose(file);
perror("close file error");
}
这是它是什么,它给了错误'FAT: 文件系统已设置文件系统的恐慌(DEV SDA1) 集群计算厉害(!245 = 244)只读 '所以我跑'fsck的-r/dev/sda1',它现在似乎工作。谢谢! – Reid