From f70785956d00e758dc4ec7700bb6ffd1ec1891ff Mon Sep 17 00:00:00 2001 From: Akilesh Kailash Date: Wed, 23 Dec 2020 18:43:49 +0000 Subject: [PATCH] hiphi: gpt-utils: FSync after block device writes When markBoolSuccessful is invoked, we update the partition table. These writes should be synced before merge operation is resumed post OTA. If not, any crash before these writes are landed to backing storage will lead to incorrect switching of slots. BUG: 175711601 Test: Verify slot switching correctly after crash when merge in progress Change-Id: I2da9286490d5d063df0c9d4dc491e0fbf28f51bb Signed-off-by: Akilesh Kailash Signed-off-by: sekaiacg Signed-off-by: 7Soldier --- gpt-utils/gpt-utils.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/gpt-utils/gpt-utils.cpp b/gpt-utils/gpt-utils.cpp index d8d97b2..8f2e3d0 100644 --- a/gpt-utils/gpt-utils.cpp +++ b/gpt-utils/gpt-utils.cpp @@ -157,11 +157,18 @@ static int blk_rw(int fd, int rw, int64_t offset, uint8_t *buf, unsigned len) else r = read(fd, buf, len); - if (r < 0) + if (r < 0) { fprintf(stderr, "block dev %s failed: %s\n", rw ? "write" : "read", strerror(errno)); - else - r = 0; + } else { + if (rw) { + r = fsync(fd); + if (r < 0) + fprintf(stderr, "fsync failed: %s\n", strerror(errno)); + } else { + r = 0; + } + } return r; }