|
@@ -191,6 +191,8 @@ int ringfs_scan(struct ringfs *fs)
|
|
|
/* If there's no IN_USE sector, we start at the first one. */
|
|
|
bool used_seen = false;
|
|
|
|
|
|
+ bool err_sector = true;
|
|
|
+
|
|
|
/* Iterate over sectors. */
|
|
|
for (int sector=0; sector<fs->flash->sector_count; sector++) {
|
|
|
int addr = _sector_address(fs, sector);
|
|
@@ -202,7 +204,15 @@ int ringfs_scan(struct ringfs *fs)
|
|
|
/* Detect partially-formatted partitions. */
|
|
|
if (header.status == SECTOR_FORMATTING) {
|
|
|
DBG printf("ringfs_scan: partially formatted partition\r\n");
|
|
|
- return -1;
|
|
|
+ if(err_sector){
|
|
|
+ err_sector = false;
|
|
|
+ _sector_free(fs, addr);
|
|
|
+ //fs->flash->read(fs->flash, addr, &header, sizeof(header));
|
|
|
+ header.status = SECTOR_FREE;
|
|
|
+ header.version = fs->version;
|
|
|
+ }else{
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/* Detect and fix partially erased sectors. */
|
|
@@ -214,14 +224,32 @@ int ringfs_scan(struct ringfs *fs)
|
|
|
/* Detect corrupted sectors. */
|
|
|
if (header.status != SECTOR_FREE && header.status != SECTOR_IN_USE) {
|
|
|
DBG printf("ringfs_scan: corrupted sector %d\r\n", sector);
|
|
|
- return -1;
|
|
|
+ if(err_sector){
|
|
|
+ err_sector = false;
|
|
|
+ _sector_free(fs, addr);
|
|
|
+ //fs->flash->read(fs->flash, addr, &header, sizeof(header));
|
|
|
+ header.status = SECTOR_FREE;
|
|
|
+ header.version = fs->version;
|
|
|
+ }else{
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/* Detect obsolete versions. We can't do this earlier because the version
|
|
|
* could have been invalid due to a partial erase. */
|
|
|
if (header.version != fs->version) {
|
|
|
- DBG printf("ringfs_scan: incompatible version 0x%08"PRIx32"\r\n", header.version);
|
|
|
- return -1;
|
|
|
+ DBG printf("ringfs_scan: corrupted sector %d\r\n", sector);
|
|
|
+ DBG printf("ringfs_scan: incompatible version 0x%08"PRIx32"\r\n", header.version);
|
|
|
+ if(err_sector){
|
|
|
+ err_sector = false;
|
|
|
+ _sector_free(fs, addr);
|
|
|
+ //fs->flash->read(fs->flash, addr, &header, sizeof(header));
|
|
|
+ DBG printf("ringfs_scan: incompatible version 0x%08"PRIx32"\r\n", header.version);
|
|
|
+ header.status = SECTOR_FREE;
|
|
|
+ header.version = fs->version;
|
|
|
+ }else{
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/* Record the presence of a FREE sector. */
|