From 58c4e79708d84a1020a94b17929699435bbdd3fb Mon Sep 17 00:00:00 2001 From: Tom Marshall Date: Sat, 18 Apr 2015 09:37:31 -0700 Subject: [PATCH] Re-read the partition table before and after write Note we re-read before save to ensure that the block device is not in use. --- gpt.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/gpt.c b/gpt.c index c5f534f..59fafd6 100644 --- a/gpt.c +++ b/gpt.c @@ -362,6 +362,12 @@ int gpt_write(const struct gpt *gpt) return -1; } + rc = ioctl(fd, BLKRRPART); + if (rc != 0) { + fprintf(stderr, "failed to re-read partition table\n"); + return -1; + } + memcpy(&hdr, &gpt->header, sizeof(hdr)); hdr.ptbl_crc = 0; @@ -430,6 +436,12 @@ int gpt_write(const struct gpt *gpt) } } + rc = ioctl(fd, BLKRRPART); + if (rc != 0) { + fprintf(stderr, "failed to re-read partition table\n"); + return -1; + } + close(fd); return 0;