From: Davidlohr Bueso <dave@gnu.org>
To: Karel Zak <kzak@redhat.com>, Petr Uzel <petr.uzel@suse.cz>
Cc: util-linux <util-linux@vger.kernel.org>
Subject: [PATCH 1/2] fdisk: gpt: write entire first sector
Date: Sat, 27 Oct 2012 19:23:36 +0200 [thread overview]
Message-ID: <1351358616.2842.2.camel@offbook> (raw)
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
next reply other threads:[~2012-10-27 17:23 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-27 17:23 Davidlohr Bueso [this message]
2012-11-01 8:49 ` [PATCH 1/2] fdisk: gpt: write entire first sector Petr Uzel
2012-11-02 11:30 ` Karel Zak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1351358616.2842.2.camel@offbook \
--to=dave@gnu.org \
--cc=kzak@redhat.com \
--cc=petr.uzel@suse.cz \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).