@@ -281,8 +281,10 @@ RETCODE adfFileSeek ( struct AdfFile * const file,
281
281
return RC_OK ;
282
282
}
283
283
284
- if ( file -> writeMode )
284
+ if ( file -> writeMode && file -> currentDataBlockChanged ) {
285
285
adfFileFlush ( file );
286
+ file -> currentDataBlockChanged = FALSE;
287
+ }
286
288
287
289
if ( pos == 0 )
288
290
return adfFileSeekStart ( file );
@@ -422,6 +424,7 @@ struct AdfFile * adfFileOpen ( struct AdfVolume * const vol,
422
424
file -> currentExt = NULL ;
423
425
file -> nDataBlock = 0 ;
424
426
file -> curDataPtr = 0 ;
427
+ file -> currentDataBlockChanged = FALSE;
425
428
426
429
if ( mode_read ) {
427
430
memcpy ( file -> fileHdr , & entry , sizeof ( struct bFileHeaderBlock ) );
@@ -527,6 +530,7 @@ uint32_t adfFileRead ( struct AdfFile * const file,
527
530
return bytesRead ;
528
531
}
529
532
file -> posInDataBlk = 0 ;
533
+ file -> currentDataBlockChanged = FALSE;
530
534
}
531
535
532
536
unsigned size = min ( n - bytesRead , blockSize - file -> posInDataBlk );
@@ -656,7 +660,9 @@ uint32_t adfFileWrite ( struct AdfFile * const file,
656
660
657
661
if ( file -> pos == file -> fileHdr -> byteSize ) { // at EOF ?
658
662
// ... create a new block
659
- if ( adfFileCreateNextBlock ( file ) == -1 ) {
663
+ RETCODE rc = adfFileCreateNextBlock ( file );
664
+ file -> currentDataBlockChanged = FALSE;
665
+ if ( rc == -1 ) {
660
666
/* bug found by Rikard */
661
667
adfEnv .wFct ( "adfWritefile : no more free sectors available" );
662
668
//file->curDataPtr = 0; // invalidate data ptr
@@ -667,7 +673,10 @@ uint32_t adfFileWrite ( struct AdfFile * const file,
667
673
// inside the existing data (at the end of a data block )
668
674
669
675
// write the block stored currently in the memory
670
- adfFileFlush ( file ); // to optimize (?)
676
+ if ( file -> currentDataBlockChanged ) {
677
+ adfFileFlush ( file ); // to optimize (?)
678
+ file -> currentDataBlockChanged = FALSE;
679
+ }
671
680
672
681
// - and read the next block
673
682
RETCODE rc = adfFileReadNextBlock ( file );
@@ -689,6 +698,7 @@ uint32_t adfFileWrite ( struct AdfFile * const file,
689
698
file -> pos += size ;
690
699
bytesWritten += size ;
691
700
file -> posInDataBlk += size ;
701
+ file -> currentDataBlockChanged = TRUE;
692
702
693
703
// update file size in the header
694
704
file -> fileHdr -> byteSize = max ( file -> fileHdr -> byteSize ,
0 commit comments