util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] fdisk: gpt: write entire first sector
@ 2012-10-27 17:23 Davidlohr Bueso
  2012-11-01  8:49 ` Petr Uzel
  2012-11-02 11:30 ` Karel Zak
  0 siblings, 2 replies; 3+ messages in thread
From: Davidlohr Bueso @ 2012-10-27 17:23 UTC (permalink / raw)
  To: Karel Zak, Petr Uzel; +Cc: util-linux

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

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
---
 fdisks/gpt.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/fdisks/gpt.c b/fdisks/gpt.c
index 40cadb1..48397f3 100644
--- a/fdisks/gpt.c
+++ b/fdisks/gpt.c
@@ -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;
 }
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-11-02 11:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-27 17:23 [PATCH 1/2] fdisk: gpt: write entire first sector Davidlohr Bueso
2012-11-01  8:49 ` Petr Uzel
2012-11-02 11:30 ` Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).