File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -2526,7 +2526,7 @@ FRESULT f_write (
2526
2526
UINT wcnt, cc;
2527
2527
const BYTE *wbuff = (const BYTE *)buff;
2528
2528
BYTE csect;
2529
-
2529
+ bool need_sync = false ;
2530
2530
2531
2531
*bw = 0 ; /* Clear write byte counter */
2532
2532
@@ -2559,6 +2559,13 @@ FRESULT f_write (
2559
2559
if (clst == 1 ) ABORT (fp->fs , FR_INT_ERR);
2560
2560
if (clst == 0xFFFFFFFF ) ABORT (fp->fs , FR_DISK_ERR);
2561
2561
fp->clust = clst; /* Update current cluster */
2562
+
2563
+ #ifdef FLUSH_ON_NEW_CLUSTER
2564
+ // We do not need to flush for the first cluster
2565
+ if (fp->fptr != 0 ) {
2566
+ need_sync = true ;
2567
+ }
2568
+ #endif
2562
2569
}
2563
2570
#if _FS_TINY
2564
2571
if (fp->fs ->winsect == fp->dsect && move_window (fp->fs , 0 )) /* Write-back sector cache */
@@ -2591,6 +2598,9 @@ FRESULT f_write (
2591
2598
}
2592
2599
#endif
2593
2600
wcnt = SS (fp->fs ) * cc; /* Number of bytes transferred */
2601
+ #ifdef FLUSH_ON_NEW_SECTOR
2602
+ need_sync = true ;
2603
+ #endif
2594
2604
continue ;
2595
2605
}
2596
2606
#if _FS_TINY
@@ -2623,6 +2633,10 @@ FRESULT f_write (
2623
2633
if (fp->fptr > fp->fsize ) fp->fsize = fp->fptr ; /* Update file size if needed */
2624
2634
fp->flag |= FA__WRITTEN; /* Set file change flag */
2625
2635
2636
+ if (need_sync) {
2637
+ f_sync (fp);
2638
+ }
2639
+
2626
2640
LEAVE_FF (fp->fs , FR_OK);
2627
2641
}
2628
2642
Original file line number Diff line number Diff line change 187
187
/* To enable file lock control feature, set _FS_LOCK to 1 or greater.
188
188
The value defines how many files can be opened simultaneously. */
189
189
190
+ #define FLUSH_ON_NEW_CLUSTER 0 /* Sync the file on every new cluster */
191
+ #define FLUSH_ON_NEW_SECTOR 1 /* Sync the file on every new sector */
192
+ /* Only one of these two defines needs to be set to 1. If both are set to 0
193
+ the file is only sync when closed.
194
+ Clusters are group of sectors (eg: 8 sectors). Flushing on new cluster means
195
+ it would be less often than flushing on new sector. Sectors are generally
196
+ 512 Bytes long. */
190
197
191
198
#endif /* _FFCONFIG */
You can’t perform that action at this time.
0 commit comments