mirror of
				https://github.com/eledio-devices/thirdparty-littlefs.git
				synced 2025-10-31 16:14:16 +01:00 
			
		
		
		
	If stats file doesn't exist lfs_emubd_create will fail.
This will create default stats file if it doesn't exist.
This commit is contained in:
		
				
					committed by
					
						 Christopher Haster
						Christopher Haster
					
				
			
			
				
	
			
			
			
						parent
						
							3419284689
						
					
				
				
					commit
					6ad544f3f3
				
			| @@ -47,11 +47,15 @@ int lfs_emubd_create(const struct lfs_config *cfg, const char *path) { | |||||||
|  |  | ||||||
|     // Load stats to continue incrementing |     // Load stats to continue incrementing | ||||||
|     snprintf(emu->child, LFS_NAME_MAX, "stats"); |     snprintf(emu->child, LFS_NAME_MAX, "stats"); | ||||||
|  |  | ||||||
|     FILE *f = fopen(emu->path, "r"); |     FILE *f = fopen(emu->path, "r"); | ||||||
|     if (!f) { |     if (!f && errno != ENOENT) { | ||||||
|         return -errno; |         return -errno; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     if (errno == ENOENT) { | ||||||
|  |         memset(&emu->stats, 0x0, sizeof(emu->stats)); | ||||||
|  |     } else { | ||||||
|         size_t res = fread(&emu->stats, sizeof(emu->stats), 1, f); |         size_t res = fread(&emu->stats, sizeof(emu->stats), 1, f); | ||||||
|         if (res < 1) { |         if (res < 1) { | ||||||
|             return -errno; |             return -errno; | ||||||
| @@ -61,6 +65,7 @@ int lfs_emubd_create(const struct lfs_config *cfg, const char *path) { | |||||||
|         if (err) { |         if (err) { | ||||||
|             return -errno; |             return -errno; | ||||||
|         } |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     return 0; |     return 0; | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user