return rc;
}
+static int gpt_read(struct fdisk_context *cxt, off_t offset, void *buf, size_t count)
+{
+ if (offset != lseek(cxt->dev_fd, offset, SEEK_SET))
+ return -errno;
+
+ if (read_all(cxt->dev_fd, buf, count))
+ return -errno;
+
+ DBG(GPT, ul_debug(" read OK [offset=%zu, size=%zu]",
+ (size_t) offset, count));
+ return 0;
+}
+
static int gpt_write(struct fdisk_context *cxt, off_t offset, void *buf, size_t count)
{
if (offset != lseek(cxt->dev_fd, offset, SEEK_SET))
static int gpt_write_pmbr(struct fdisk_context *cxt)
{
struct gpt_legacy_mbr *pmbr;
+ struct gpt_legacy_mbr *current;
+ int rc;
assert(cxt);
assert(cxt->firstsector);
pmbr->partition_record[0].size_in_lba =
cpu_to_le32((uint32_t) (cxt->total_sectors - 1ULL));
+ current = malloc(sizeof(*current));
+ if (!current)
+ goto do_write;
+
+ rc = gpt_read(cxt, GPT_PMBR_LBA * cxt->sector_size,
+ current, cxt->sector_size);
+
+ if (!rc)
+ rc = memcmp(pmbr, current, sizeof(*current));
+
+ free(current);
+
+ if (!rc) {
+ DBG(GPT, ul_debug("Same MBR on disk => don't write it"));
+ return 0;
+ }
+
+ do_write:
/* pMBR covers the first sector (LBA) of the disk */
return gpt_write(cxt, GPT_PMBR_LBA * cxt->sector_size,
pmbr, cxt->sector_size);