From b406d9a2e947bcf1a1b3e28e026cf74579e6723ad6e83aa3641de0f8f7b49d4f Mon Sep 17 00:00:00 2001 From: Petr Uzel Date: Sat, 19 Sep 2015 17:56:08 +0000 Subject: [PATCH] Accepting request 330325 from home:favogt:branches:Base:System gpt_sync_mbr_alloc didn't initialize AlternateLBA properly, so it tried to seek to -32. This updates parted-gpt-mbr-sync.patch by making gpt_sync_mbr_alloc a copy of gpt_alloc with just minor modifications. Fixes bsc#945068. OBS-URL: https://build.opensuse.org/request/show/330325 OBS-URL: https://build.opensuse.org/package/show/Base:System/parted?expand=0&rev=115 --- parted-gpt-mbr-sync.patch | 36 +++++++++++++++++++++++++----------- parted.changes | 6 ++++++ 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/parted-gpt-mbr-sync.patch b/parted-gpt-mbr-sync.patch index 7bf83c5..2ed322a 100644 --- a/parted-gpt-mbr-sync.patch +++ b/parted-gpt-mbr-sync.patch @@ -86,7 +86,7 @@ Index: parted-3.2/libparted/labels/gpt.c static PedDisk * gpt_alloc (const PedDevice *dev) { -@@ -553,6 +609,36 @@ error: +@@ -553,6 +609,50 @@ error: } static PedDisk * @@ -99,18 +99,32 @@ Index: parted-3.2/libparted/labels/gpt.c + disk = _ped_disk_alloc ((PedDevice *) dev, &gpt_sync_mbr_disk_type); + if (!disk) + goto error; -+ disk->disk_specific = gpt_disk_data = ped_malloc (sizeof (GPTDiskData)); -+ if (!disk->disk_specific) -+ goto error_free_disk; + + data_start = 2 + GPT_DEFAULT_PARTITION_ENTRY_ARRAY_SIZE / dev->sector_size; + data_end = dev->length - 2 + - GPT_DEFAULT_PARTITION_ENTRY_ARRAY_SIZE / dev->sector_size; ++ ++ /* If the device is too small to accommodate GPT headers and one data ++ sector, reject it. */ ++ if (data_end < data_start) ++ { ++ ped_exception_throw (PED_EXCEPTION_ERROR, ++ PED_EXCEPTION_OK, ++ _("device is too small for GPT")); ++ goto error_free_disk; ++ } ++ ++ disk->disk_specific = gpt_disk_data = ped_malloc (sizeof (GPTDiskData)); ++ if (!disk->disk_specific) ++ goto error_free_disk; ++ ++ gpt_disk_data->AlternateLBA = dev->length - 1; + ped_geometry_init (&gpt_disk_data->data_area, dev, data_start, + data_end - data_start + 1); + gpt_disk_data->entry_count = GPT_DEFAULT_PARTITION_ENTRIES; + uuid_generate ((unsigned char *) &gpt_disk_data->uuid); + swap_uuid_and_efi_guid ((unsigned char *) (&gpt_disk_data->uuid)); ++ gpt_disk_data->pmbr_boot = 0; + return disk; + +error_free_disk: @@ -123,7 +137,7 @@ Index: parted-3.2/libparted/labels/gpt.c gpt_duplicate (const PedDisk *disk) { PedDisk *new_disk; -@@ -963,7 +1049,7 @@ gpt_read (PedDisk *disk) +@@ -963,7 +1063,7 @@ gpt_read (PedDisk *disk) /* motivation: let the user decide about the pmbr... during ped_disk_probe(), they probably didn't get a choice... */ @@ -132,7 +146,7 @@ Index: parted-3.2/libparted/labels/gpt.c goto error; GuidPartitionTableHeader_t *gpt = NULL; -@@ -1120,11 +1206,59 @@ error: +@@ -1120,11 +1220,59 @@ error: return 0; } @@ -193,7 +207,7 @@ Index: parted-3.2/libparted/labels/gpt.c /* The UEFI spec is not clear about what to do with the following elements of the Protective MBR (pmbr): BootCode (0-440B), UniqueMBRSignature (440B-444B) and Unknown (444B-446B). -@@ -1138,6 +1272,8 @@ _write_pmbr (PedDevice *dev, bool pmbr_b +@@ -1138,6 +1286,8 @@ _write_pmbr (PedDevice *dev, bool pmbr_b memset (pmbr->PartitionRecord, 0, sizeof pmbr->PartitionRecord); pmbr->Signature = PED_CPU_TO_LE16 (MSDOS_MBR_SIGNATURE); @@ -202,7 +216,7 @@ Index: parted-3.2/libparted/labels/gpt.c pmbr->PartitionRecord[0].OSType = EFI_PMBR_OSTYPE_EFI; pmbr->PartitionRecord[0].StartSector = 1; pmbr->PartitionRecord[0].EndHead = 0xFE; -@@ -1150,6 +1286,60 @@ _write_pmbr (PedDevice *dev, bool pmbr_b +@@ -1150,6 +1300,60 @@ _write_pmbr (PedDevice *dev, bool pmbr_b pmbr->PartitionRecord[0].SizeInLBA = PED_CPU_TO_LE32 (dev->length - 1UL); if (pmbr_boot) pmbr->PartitionRecord[0].BootIndicator = 0x80; @@ -263,7 +277,7 @@ Index: parted-3.2/libparted/labels/gpt.c int write_ok = ped_device_write (dev, pmbr, GPT_PMBR_LBA, GPT_PMBR_SECTORS); -@@ -1269,7 +1459,7 @@ gpt_write (const PedDisk *disk) +@@ -1269,7 +1473,7 @@ gpt_write (const PedDisk *disk) ptes_crc = efi_crc32 (ptes, ptes_bytes); /* Write protective MBR */ @@ -272,7 +286,7 @@ Index: parted-3.2/libparted/labels/gpt.c goto error_free_ptes; /* Write PTH and PTEs */ -@@ -2034,6 +2224,38 @@ static PedDiskOps gpt_disk_ops = +@@ -2034,6 +2238,38 @@ static PedDiskOps gpt_disk_ops = PT_op_function_initializers (gpt) }; @@ -311,7 +325,7 @@ Index: parted-3.2/libparted/labels/gpt.c static PedDiskType gpt_disk_type = { next: NULL, -@@ -2042,16 +2264,26 @@ static PedDiskType gpt_disk_type = +@@ -2042,16 +2278,26 @@ static PedDiskType gpt_disk_type = features: PED_DISK_TYPE_PARTITION_NAME }; diff --git a/parted.changes b/parted.changes index 9f455cb..b125e4a 100644 --- a/parted.changes +++ b/parted.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Thu Sep 10 09:18:30 UTC 2015 - fvogt@suse.com + +- Update parted-gpt-mbr-sync.patch to fix bsc#945068 + Basically just a copy of gpt_alloc with minor modifications now + ------------------------------------------------------------------- Tue May 26 11:21:37 UTC 2015 - puzel@suse.com