From 8c705b4ad191d7b837cd68ad1664ae7b5a423a8d Mon Sep 17 00:00:00 2001 From: OBattler Date: Tue, 24 Sep 2024 04:32:46 +0200 Subject: [PATCH] Flush on writes to hard disk images, fixes partition creation on the Samsung SPC7700LP-W. --- src/disk/hdd_image.c | 3 +++ src/disk/minivhd/minivhd_io.c | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/src/disk/hdd_image.c b/src/disk/hdd_image.c index f82b2d3f2..7c2618969 100644 --- a/src/disk/hdd_image.c +++ b/src/disk/hdd_image.c @@ -577,6 +577,7 @@ hdd_image_write(uint8_t id, uint32_t sector, uint32_t count, uint8_t *buffer) } num_write = fwrite(buffer, 512, count, hdd_images[id].file); + fflush(hdd_images[id].file); hdd_images[id].pos = sector + num_write; } } @@ -618,6 +619,8 @@ hdd_image_zero(uint8_t id, uint32_t sector, uint32_t count) hdd_images[id].pos = sector + i; fwrite(empty_sector, 512, 1, hdd_images[id].file); } + + fflush(hdd_images[id].file); } } diff --git a/src/disk/minivhd/minivhd_io.c b/src/disk/minivhd/minivhd_io.c index ffc6aba44..1a349dbc4 100644 --- a/src/disk/minivhd/minivhd_io.c +++ b/src/disk/minivhd/minivhd_io.c @@ -89,6 +89,8 @@ mvhd_write_empty_sectors(FILE *f, int sector_count) for (int i = 0; i < sector_count; i++) fwrite(zero_bytes, sizeof zero_bytes, 1, f); + + fflush(f); } /** @@ -141,6 +143,7 @@ write_bat_entry(MVHDMeta *vhdm, int blk) mvhd_fseeko64(vhdm->f, table_offset, SEEK_SET); fwrite(&offset, sizeof offset, 1, vhdm->f); + fflush(vhdm->f); } /** @@ -197,6 +200,8 @@ create_block(MVHDMeta *vhdm, int blk) /* We no longer have a sparse block. Update that BAT! */ vhdm->block_offset[blk] = sect_offset; write_bat_entry(vhdm, blk); + + fflush(vhdm->f); } int @@ -317,6 +322,7 @@ mvhd_fixed_write(MVHDMeta *vhdm, uint32_t offset, int num_sectors, void *in_buff addr = (int64_t)offset * MVHD_SECTOR_SIZE; mvhd_fseeko64(vhdm->f, addr, SEEK_SET); fwrite(in_buff, transfer_sectors * MVHD_SECTOR_SIZE, 1, vhdm->f); + fflush(vhdm->f); return truncated_sectors; } @@ -376,6 +382,8 @@ mvhd_sparse_diff_write(MVHDMeta *vhdm, uint32_t offset, int num_sectors, void *i /* And write the sector bitmap for the last block we visited to disk */ write_curr_sect_bitmap(vhdm); + fflush(vhdm->f); + return truncated_sectors; }