From 339082886f0d18e4d1d9bf099f509f9de528279b Mon Sep 17 00:00:00 2001 From: Thomas Friedel Date: Mon, 16 Mar 2026 15:59:29 +0100 Subject: [PATCH 1/2] Add flush call to fx_media_format Adds a call to the I/O driver with FX_DRIVER_FLUSH to fx_media_format() before uninitializing the driver. Fixes Issue #88 --- common/src/fx_media_format.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/common/src/fx_media_format.c b/common/src/fx_media_format.c index a1863e0..b06e955 100644 --- a/common/src/fx_media_format.c +++ b/common/src/fx_media_format.c @@ -669,6 +669,26 @@ UINT sectors_per_fat, f, s; } } +#ifndef FX_MEDIA_STATISTICS_DISABLE + /* Increment the number of driver flush requests. */ + media_ptr -> fx_media_driver_flush_requests++; +#endif + + /* Build the "flush" I/O driver request. */ + media_ptr -> fx_media_driver_request = FX_DRIVER_FLUSH; + media_ptr -> fx_media_driver_status = FX_IO_ERROR; + + /* If trace is enabled, insert this event into the trace buffer. */ + FX_TRACE_IN_LINE_INSERT(FX_TRACE_INTERNAL_IO_DRIVER_FLUSH, media_ptr, 0, 0, 0, FX_TRACE_INTERNAL_EVENTS, 0, 0) + + /* Call the specified I/O driver with the flush request. */ + (media_ptr -> fx_media_driver_entry) (media_ptr); + + if (media_ptr -> fx_media_driver_status != FX_SUCCESS) + { + return(media_ptr -> fx_media_driver_status); + } + /* Build the "uninitialize" I/O driver request. */ media_ptr -> fx_media_driver_request = FX_DRIVER_UNINIT; media_ptr -> fx_media_driver_status = FX_IO_ERROR; From edc2427de65b937339c7d80a9f6a8f42eb371900 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Desbiens?= Date: Tue, 2 Jun 2026 11:42:41 -0400 Subject: [PATCH 2/2] Fixed flush call in fx_media_format to mirror fx_media_close pattern - Added blank line after #ifndef FX_MEDIA_STATISTICS_DISABLE for style consistency - Used local driver variable instead of media_ptr->fx_media_driver_entry - Removed early return on flush failure so FX_DRIVER_UNINIT is always called after FX_DRIVER_INIT, preventing driver resource leaks Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- common/src/fx_media_format.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/common/src/fx_media_format.c b/common/src/fx_media_format.c index b06e955..108245e 100644 --- a/common/src/fx_media_format.c +++ b/common/src/fx_media_format.c @@ -670,6 +670,7 @@ UINT sectors_per_fat, f, s; } #ifndef FX_MEDIA_STATISTICS_DISABLE + /* Increment the number of driver flush requests. */ media_ptr -> fx_media_driver_flush_requests++; #endif @@ -682,12 +683,7 @@ UINT sectors_per_fat, f, s; FX_TRACE_IN_LINE_INSERT(FX_TRACE_INTERNAL_IO_DRIVER_FLUSH, media_ptr, 0, 0, 0, FX_TRACE_INTERNAL_EVENTS, 0, 0) /* Call the specified I/O driver with the flush request. */ - (media_ptr -> fx_media_driver_entry) (media_ptr); - - if (media_ptr -> fx_media_driver_status != FX_SUCCESS) - { - return(media_ptr -> fx_media_driver_status); - } + (driver)(media_ptr); /* Build the "uninitialize" I/O driver request. */ media_ptr -> fx_media_driver_request = FX_DRIVER_UNINIT;