diff --git a/devicemodel/hw/platform/rpmb/rpmb_sim.c b/devicemodel/hw/platform/rpmb/rpmb_sim.c index 5c4f3e589..f8e0e4ae4 100644 --- a/devicemodel/hw/platform/rpmb/rpmb_sim.c +++ b/devicemodel/hw/platform/rpmb/rpmb_sim.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -168,10 +169,17 @@ static int file_write(FILE *fp, const void *buf, size_t size, off_t offset) return -1; } + /* The flow of file writing sync should be: + C lib caches--->fflush--->disk caches--->fsync--->disk */ if (fflush(fp) < 0) { return -1; } + if (fsync(fileno(fp)) < 0) { + DPRINTF(("%s: fsync failed\n", __func__)); + return -1; + } + return rc; }