]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: gpt: write entire first sector
authorDavidlohr Bueso <dave@gnu.org>
Sat, 27 Oct 2012 17:23:36 +0000 (19:23 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 2 Nov 2012 11:25:47 +0000 (12:25 +0100)
We were writing only 1 byte in LBA0, and GPT requires dealing with an entire
sector. This bug wasn't affecting when dealing with already existing devices
with GPT as we weren't writing an important part of the first sector, thus
leaving it unchanged. Also use write_all() wrapper from all-io.h

Acked-by: Petr Uzel <petr.uzel@suse.cz>
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
fdisks/gpt.c

index 40cadb1cdc853ca368a5a16a41bcd09b97cb0f6f..48397f31354231d99f9b738e9b08ae011040711c 100644 (file)
@@ -44,6 +44,7 @@
 #include "blkdev.h"
 #include "bitops.h"
 #include "strutils.h"
+#include "all-io.h"
 
 #define GPT_HEADER_SIGNATURE 0x5452415020494645LL /* EFI PART */
 #define GPT_HEADER_REVISION_V1_02 0x00010200
@@ -1057,8 +1058,10 @@ static int gpt_write_pmbr(struct fdisk_context *cxt)
        if (offset != lseek(cxt->dev_fd, offset, SEEK_SET))
                goto fail;
 
-       if (1 == write(cxt->dev_fd, pmbr, 1))
-               return 0;
+       /* pMBR covers the first sector (LBA) of the disk */
+       if (write_all(cxt->dev_fd, pmbr, cxt->sector_size))
+               goto fail;
+       return 0;
 fail:
        return -errno;
 }