OBS User unknown 2008-07-18 22:25:20 +00:00 committed by Git OBS Bridge
parent dfb2cc30a4
commit f43cd257e0
3 changed files with 153 additions and 1 deletions

139
parted-gpt-mbr-sync.patch Normal file
View File

@ -0,0 +1,139 @@
Index: libparted/labels/gpt.c
===================================================================
--- libparted/labels/gpt.c.orig
+++ libparted/labels/gpt.c
@@ -46,6 +46,8 @@
# define _(String) (String)
#endif /* ENABLE_NLS */
+#define GPT_SYNC_MBR
+
#define EFI_PMBR_OSTYPE_EFI 0xEE
#define MSDOS_MBR_SIGNATURE 0xaa55
@@ -402,6 +404,7 @@ guid_cmp (efi_guid_t left, efi_guid_t ri
return memcmp(&left, &right, sizeof(efi_guid_t));
}
+#ifndef GPT_SYNC_MBR
/* checks if 'mbr' is a protective MBR partition table */
static inline int
_pmbr_is_valid (const LegacyMBR_t* mbr)
@@ -418,6 +421,7 @@ _pmbr_is_valid (const LegacyMBR_t* mbr)
}
return 0;
}
+#endif
static int
gpt_probe (const PedDevice * dev)
@@ -445,6 +449,7 @@ gpt_probe (const PedDevice * dev)
if (!gpt_sig_found)
return 0;
+#ifndef GPT_SYNC_MBR
if (ped_device_read(dev, &legacy_mbr, 0, GPT_HEADER_SECTORS)) {
if (!_pmbr_is_valid (&legacy_mbr)) {
int ex_status = ped_exception_throw (
@@ -463,6 +468,7 @@ gpt_probe (const PedDevice * dev)
return 0;
}
}
+#endif
return 1;
}
@@ -928,15 +934,51 @@ error:
return 0;
}
+#ifdef GPT_SYNC_MBR
+static inline unsigned char
+_part_to_ostype (PedPartition* part)
+{
+ GPTPartitionData* gpt_part_data = part->disk_specific;
+ if (part->fs_type) {
+ if (strncmp (part->fs_type->name, "fat", 3) == 0) return 0xc;
+ if (strncmp (part->fs_type->name, "ntfs", 4) == 0) return 0x7;
+ if (strncmp (part->fs_type->name, "hfs", 3) == 0) return 0xaf;
+ if (strstr (part->fs_type->name, "swap")) return 0x82;
+ }
+ return 0x83; // Everything else is Linux
+}
+
+static inline uint32_t
+_part_32bitmax (uint64_t in)
+{
+ if (in > 0xFFFFFFFFULL)
+ return 0xFFFFFFFF;
+ else
+ return (uint32_t)in;
+}
+#endif
+
#ifndef DISCOVER_ONLY
/* Writes the protective MBR (to keep DOS happy) */
static int
-_write_pmbr (PedDevice * dev)
+_write_pmbr (PedDisk * disk)
{
+ PedDevice * dev = disk->dev;
LegacyMBR_t pmbr;
+#ifdef GPT_SYNC_MBR
+ int i;
+ PedPartition* part = NULL;
+#endif
+#ifdef GPT_SYNC_MBR
+ /* Keep the old MBR as much as possible */
+ ped_device_read(dev, &pmbr, 0, GPT_HEADER_SECTORS);
+ memset(&pmbr.PartitionRecord, 0, sizeof(pmbr.PartitionRecord));
+#else
memset(&pmbr, 0, sizeof(pmbr));
+#endif
pmbr.Signature = PED_CPU_TO_LE16(MSDOS_MBR_SIGNATURE);
+#ifndef GPT_SYNC_MBR
pmbr.PartitionRecord[0].OSType = EFI_PMBR_OSTYPE_EFI;
pmbr.PartitionRecord[0].StartSector = 1;
pmbr.PartitionRecord[0].EndHead = 0xFE;
@@ -947,6 +989,31 @@ _write_pmbr (PedDevice * dev)
pmbr.PartitionRecord[0].SizeInLBA = PED_CPU_TO_LE32(0xFFFFFFFF);
else
pmbr.PartitionRecord[0].SizeInLBA = PED_CPU_TO_LE32(dev->length - 1UL);
+#else
+ /* sync the first 4 GPT entries to MBR primary partitions */
+ for (i=0; i < 4; i++) {
+ part = ped_disk_next_partition (disk, part);
+ if (part == NULL)
+ break;
+ /* we might get a starting garbage partition */
+ if (part->geom.start == 0 || part->type == PED_PARTITION_METADATA || part->type == PED_PARTITION_FREESPACE) {
+ i--;
+ continue;
+ }
+ pmbr.PartitionRecord[i].OSType = _part_to_ostype(part);
+ pmbr.PartitionRecord[i].StartSector = 1;
+ pmbr.PartitionRecord[i].StartHead = 0xFE;
+ pmbr.PartitionRecord[i].StartSector = 0xFF;
+ pmbr.PartitionRecord[i].StartTrack = 0xFF;
+ pmbr.PartitionRecord[i].EndHead = 0xFE;
+ pmbr.PartitionRecord[i].EndSector = 0xFF;
+ pmbr.PartitionRecord[i].EndTrack = 0xFF;
+ pmbr.PartitionRecord[i].StartingLBA = _part_32bitmax(part->geom.start);
+ if(((GPTPartitionData*)part->disk_specific)->boot)
+ pmbr.PartitionRecord[i].BootIndicator = 0x80;
+ pmbr.PartitionRecord[i].SizeInLBA = _part_32bitmax(part->geom.end - part->geom.start);
+ }
+#endif
return ped_device_write (dev, &pmbr, GPT_PMBR_LBA, GPT_PMBR_SECTORS);
}
@@ -1050,7 +1117,7 @@ gpt_write(const PedDisk * disk)
ptes_crc = efi_crc32 (ptes, ptes_size);
/* Write protective MBR */
- if (!_write_pmbr (disk->dev))
+ if (!_write_pmbr (disk))
goto error_free_ptes;
/* Write PTH and PTEs */

View File

@ -1,3 +1,10 @@
-------------------------------------------------------------------
Fri Jul 18 10:03:52 CEST 2008 - agraf@suse.de
- add GPT sync, so whenever the GPT is modified, fake MBR entries
for the first 4 partitions will be created. This fixes booting
from disks > 2TB and makes booting a Mac possible (bnc#220839)
-------------------------------------------------------------------
Tue Jul 8 12:08:30 CEST 2008 - puzel@suse.cz

View File

@ -18,7 +18,7 @@ License: GPL v2 or later
Group: System/Filesystems
Summary: GNU partitioner
Version: 1.8.8
Release: 50
Release: 53
Source0: %{name}-%{version}.tar.bz2
Patch: always-resize-part.dif
Patch1: parted-type.patch
@ -35,6 +35,7 @@ Patch12: gnulib.diff
Patch51: parted.tty.patch
Patch52: parted.no-O_DIRECT.patch
Patch53: largest_partition_number.patch
Patch54: parted-gpt-mbr-sync.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-build
Url: http://www.gnu.org/software/parted/
PreReq: %install_info_prereq
@ -87,6 +88,7 @@ Authors:
%patch51 -p1
%patch52 -p1
%patch53 -p1
%patch54
%build
AUTOPOINT=true autoreconf --force --install
@ -130,6 +132,10 @@ rm -rf "$RPM_BUILD_ROOT"
%{_libdir}/*.so
%changelog
* Fri Jul 18 2008 agraf@suse.de
- add GPT sync, so whenever the GPT is modified, fake MBR entries
for the first 4 partitions will be created. This fixes booting
from disks > 2TB and makes booting a Mac possible (bnc#220839)
* Tue Jul 08 2008 puzel@suse.cz
- added largest_partition_number.patch
* fixes computation of largest partition number (bnc#397210)