/log 写失败修复:打开模式补 FA_WRITE 位 + 卷探针两击确认 + 自动重格式化自愈 + 错误去重

This commit is contained in:
2026-09-20 03:46:14 +08:00
parent 2bc2dcafeb
commit efe82668b7
4 changed files with 121 additions and 54 deletions
+38 -9
View File
@@ -89,18 +89,47 @@ static int s_append(syslog_id_t id, const char *desc) {
}
memcpy(rec + SYSLOG_DESC_OFFS, desc, dl);
fr = f_open(&f, s_paths[id], FA_OPEN_APPEND);
if (fr != FR_OK) {
DBG_ERROR("open %s fail (%d)", s_paths[id], (int)fr);
return -1;
/* L1 文件级自愈:陈旧/损坏条目 → 丢弃重建、重试一次(与上方容量满重建
* 同一机制);L2 错误去重:持续故障只报第一次,恢复前静默(消除"每次
* 开机同一错误刷屏")。打开模式必须带 FA_WRITE 位:本 FatFs 移植的
* FA_OPEN_APPEND(0x30) 不含 FA_WRITE(0x02),不带写位打开的文件 f_write
* 恒返回 FR_DENIED(7)——2026-09-20 台架实测 /log 写失败 ×5/开机 真根因 */
static uint8_t s_fault_reported[SYSLOG_COUNT];
int rc = 0;
fr = f_open(&f, s_paths[id], FA_WRITE | FA_OPEN_APPEND);
if (fr != FR_OK && (fr == FR_DENIED || fr == FR_INVALID_OBJECT ||
fr == FR_INT_ERR || fr == FR_DISK_ERR ||
fr == FR_NO_FILE || fr == FR_NO_PATH ||
fr == FR_INVALID_NAME || fr == FR_NO_FILESYSTEM)) {
(void)f_unlink(s_paths[id]);
fr = f_open(&f, s_paths[id], FA_WRITE | FA_OPEN_APPEND);
}
fr = f_write(&f, rec, SYSLOG_REC_SIZE, &bw);
(void)f_close(&f);
if (fr != FR_OK || bw != SYSLOG_REC_SIZE) {
if (fr == FR_OK) {
fr = f_write(&f, rec, SYSLOG_REC_SIZE, &bw);
(void)f_close(&f);
if (fr != FR_OK || bw != SYSLOG_REC_SIZE) {
(void)f_unlink(s_paths[id]);
bw = 0u;
fr = f_open(&f, s_paths[id], FA_WRITE | FA_OPEN_APPEND);
if (fr == FR_OK) {
fr = f_write(&f, rec, SYSLOG_REC_SIZE, &bw);
(void)f_close(&f);
}
if (fr != FR_OK || bw != SYSLOG_REC_SIZE) {
rc = -1;
}
}
} else {
rc = -1;
}
if (rc == 0) {
s_fault_reported[id] = 0u;
} else if (s_fault_reported[id] == 0u) {
s_fault_reported[id] = 1u;
DBG_ERROR("write %s fail (%d)", s_paths[id], (int)fr);
return -1;
}
return 0;
return rc;
}
/*