mirror of
				https://github.com/eledio-devices/thirdparty-littlefs.git
				synced 2025-10-31 00:32:38 +01:00 
			
		
		
		
	Tweaked lfs_file_flush to still flush caches when build under LFS_READONLY
A slight varation to the fix from ondrap
This commit is contained in:
		
							
								
								
									
										14
									
								
								lfs.c
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								lfs.c
									
									
									
									
									
								
							| @@ -2730,19 +2730,15 @@ static int lfs_file_outline(lfs_t *lfs, lfs_file_t *file) { | |||||||
| } | } | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| static void lfs_file_invalidate_reading_flag(lfs_t *lfs, lfs_file_t *file) { | static int lfs_file_flush(lfs_t *lfs, lfs_file_t *file) { | ||||||
|     if (file->flags & LFS_F_READING) { |     if (file->flags & LFS_F_READING) { | ||||||
|         if (!(file->flags & LFS_F_INLINE)) { |         if (!(file->flags & LFS_F_INLINE)) { | ||||||
|             lfs_cache_drop(lfs, &file->cache); |             lfs_cache_drop(lfs, &file->cache); | ||||||
|         } |         } | ||||||
|         file->flags &= ~LFS_F_READING; |         file->flags &= ~LFS_F_READING; | ||||||
|     } |     } | ||||||
| } |  | ||||||
|  |  | ||||||
| #ifndef LFS_READONLY | #ifndef LFS_READONLY | ||||||
| static int lfs_file_flush(lfs_t *lfs, lfs_file_t *file) { |  | ||||||
|     lfs_file_invalidate_reading_flag(lfs, file); |  | ||||||
|  |  | ||||||
|     if (file->flags & LFS_F_WRITING) { |     if (file->flags & LFS_F_WRITING) { | ||||||
|         lfs_off_t pos = file->pos; |         lfs_off_t pos = file->pos; | ||||||
|  |  | ||||||
| @@ -2809,10 +2805,10 @@ relocate: | |||||||
|  |  | ||||||
|         file->pos = pos; |         file->pos = pos; | ||||||
|     } |     } | ||||||
|  | #endif | ||||||
|  |  | ||||||
|     return 0; |     return 0; | ||||||
| } | } | ||||||
| #endif |  | ||||||
|  |  | ||||||
| #ifndef LFS_READONLY | #ifndef LFS_READONLY | ||||||
| static int lfs_file_rawsync(lfs_t *lfs, lfs_file_t *file) { | static int lfs_file_rawsync(lfs_t *lfs, lfs_file_t *file) { | ||||||
| @@ -3085,17 +3081,11 @@ static lfs_soff_t lfs_file_rawseek(lfs_t *lfs, lfs_file_t *file, | |||||||
|         return npos; |         return npos; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| #ifndef LFS_READONLY |  | ||||||
|     // write out everything beforehand, may be noop if rdonly |     // write out everything beforehand, may be noop if rdonly | ||||||
|     int err = lfs_file_flush(lfs, file); |     int err = lfs_file_flush(lfs, file); | ||||||
|     if (err) { |     if (err) { | ||||||
|         return err; |         return err; | ||||||
|     } |     } | ||||||
| #else |  | ||||||
|     // Seek doesn't update cache parameters properly. |  | ||||||
|     // It has to be invalidated otherwise next read will return incorrect values. |  | ||||||
|     lfs_file_invalidate_reading_flag(lfs,file); |  | ||||||
| #endif |  | ||||||
|  |  | ||||||
|     // update pos |     // update pos | ||||||
|     file->pos = npos; |     file->pos = npos; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user