Skip to contentSkip to conversation

fdisk: gpt: write entire first sector

PATCH Applied Davidlohr Bueso 3 participants 3 messages Oct 27, 2012 – Nov 2, 2012 Util-Linux package

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 fdisk: gpt: write entire first sector

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

---
 fdisks/gpt.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
fdisks/gpt.c +5 -2
index 40cadb1..48397f3 100644
@@ -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;
 }
Signature · 1 line
1.7.9.5
Acked-by on v1 1/2
#1 lore raw
Quoted 6 lines · Davidlohr Bueso

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

Quoted 35 lines
---
 fdisks/gpt.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
fdisks/gpt.c +5 -2
index 40cadb1..48397f3 100644
@@ -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;
 }
Signature · 1 line
1.7.9.5

Petr

Signature · 2 lines
Petr Uzel
IRC: ptr_uzl @ freenode