balbekova 7 years ago
parent
commit
0420247d23
2 changed files with 41 additions and 9 deletions
  1. 9 5
      modules/log/log.c
  2. 32 4
      modules/log/ringfs.c

+ 9 - 5
modules/log/log.c

@@ -114,7 +114,7 @@ void log_task(void* params)
 	for(;;){
 		flUpdateLog = true;
 		vTaskDelay(LOG_TIME);
-	/*	vTaskDelay(50);
+		/*vTaskDelay(50);
 		log_event_data(LOG_SYSTEM_BOOT, "Администратор");
 		log_add(")215.7;215.7;220.5;000;50.1;2.30;25.0;00000001;");*/
 	}
@@ -129,16 +129,20 @@ void log_init(bool format) {
 	ringfs_flash.sector_count = spi_flash_desc.sector_count/2 - LOG_FLASH_SECTOR_OFFSET;
 
 	ringfs_init(&fs, &ringfs_flash, LOG_ENTRY_VERSION, sizeof(log_entry_t));
-	if (format || ringfs_scan(&fs) != 0)
+	if (format || ringfs_scan(&fs) != 0){
+		printf("FAT1 false\r\n");
 		ringfs_format(&fs);
-
+	}
+	DBG printf("FAT1 true\r\n");
 	ringfs_flash2.sector_size = spi_flash_desc.sector_size;
 	ringfs_flash2.sector_count = spi_flash_desc.sector_count/2 - LOG_FLASH_SECTOR_OFFSET;
 
 	ringfs_init(&fs2, &ringfs_flash2, LOG_ENTRY_VERSION, sizeof(log_entry_t));
-	if (format || ringfs_scan(&fs2) != 0)
+	if (format || ringfs_scan(&fs2) != 0){
+		DBG printf("FAT2 false\r\n");
 		ringfs_format(&fs2);
-
+	}
+	DBG printf("FAT2 true\r\n");
 	fLogInit = true;
 
 	log_mutex = xSemaphoreCreateMutex();

+ 32 - 4
modules/log/ringfs.c

@@ -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. */