From eae82bccebcdea6eb66d572e2fe06b9140ffc529 Mon Sep 17 00:00:00 2001 From: Intel A80486DX2-66 Date: Wed, 27 Dec 2023 21:30:42 +0300 Subject: [PATCH] reverse-ramdisk.c: flush file buffer on each write --- c-programming/reverse-ramdisk.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/c-programming/reverse-ramdisk.c b/c-programming/reverse-ramdisk.c index 0c2e414..4b5b064 100644 --- a/c-programming/reverse-ramdisk.c +++ b/c-programming/reverse-ramdisk.c @@ -9,7 +9,7 @@ production purposes. GCC/Clang/TCC: Compile with -DTEST to set macro TEST as defined, with -DDEBUG to enable debug mode -To-Do: error handling on line 179, function fread() +To-Do: error handling on line 184, function fread() */ #include @@ -154,6 +154,11 @@ int tf_write(int ID, size_t offset, void* data, size_t data_size) { if (bytes_written != data_size) return -1; + if (fdatasync(file) == -1) { + line_fail(-1); + return -1; + } + return 0; }