From 21ddbea48de35c226e5641d4fe05b0b0f2f86732 Mon Sep 17 00:00:00 2001 From: Tom Marshall Date: Tue, 23 Jul 2019 15:18:15 -0700 Subject: [PATCH] gptfdisk: include gptcl.h after sgdisk.h This fixes alignment issues with struct sgdisk_partition when used outside sgdisk (eg. in recovery). Also push/pop the pack decls in header files to further fix the issue. Change-Id: If10799ea443ad6870a53494925b4032abb32c542 --- basicmbr.h | 3 +++ bsd.h | 3 +++ gpt.h | 3 +++ mbrpart.h | 3 +++ sgdisk.cc | 2 +- 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/basicmbr.h b/basicmbr.h index 696f826..8db61cd 100644 --- a/basicmbr.h +++ b/basicmbr.h @@ -24,6 +24,7 @@ // A 512-byte data structure into which the MBR can be loaded in one // go. Also used when loading logical partitions. +#pragma pack(push) #pragma pack(1) struct TempMBR { uint8_t code[440]; @@ -149,4 +150,6 @@ public: void ShowCommands(void); }; // class BasicMBRData +#pragma pack(pop) + #endif diff --git a/bsd.h b/bsd.h index e042b7b..b9d5374 100644 --- a/bsd.h +++ b/bsd.h @@ -54,6 +54,7 @@ struct BSDRecord { // the partition table // Full data in tweaked BSD format // For some reason this has to be packed or MS Visual C++'s debugger complains // about memory errors whenever a BSDData variable is destroyed. +#pragma pack(push) #pragma pack (8) class BSDData { protected: @@ -88,4 +89,6 @@ class BSDData { }; // struct MBRData #pragma pack () +#pragma pack(pop) + #endif diff --git a/gpt.h b/gpt.h index 6e1e0bb..a1ff47f 100644 --- a/gpt.h +++ b/gpt.h @@ -37,6 +37,7 @@ enum GPTValidity {gpt_valid, gpt_corrupt, gpt_invalid}; enum WhichToUse {use_gpt, use_mbr, use_bsd, use_new, use_abort}; // Header (first 512 bytes) of GPT table +#pragma pack(push) #pragma pack(1) struct GPTHeader { uint64_t signature; @@ -212,4 +213,6 @@ public: // Function prototypes.... int SizesOK(void); +#pragma pack(pop) + #endif diff --git a/mbrpart.h b/mbrpart.h index 6c7b21a..b889f3d 100644 --- a/mbrpart.h +++ b/mbrpart.h @@ -39,6 +39,7 @@ // On read of logical entries, it's relative to the EBR record for that // partition. When writing EBR records, it's relative to the extended // partition's start. +#pragma pack(push) #pragma pack(1) struct MBRRecord { uint8_t status; @@ -108,4 +109,6 @@ public: void ShowData(int isGpt); }; // MBRPart +#pragma pack(pop) + #endif // MBRPART_H diff --git a/sgdisk.cc b/sgdisk.cc index feebc0d..ccd4480 100644 --- a/sgdisk.cc +++ b/sgdisk.cc @@ -16,11 +16,11 @@ #include #include #include -#include "gptcl.h" #include #include #include "sgdisk.h" +#include "gptcl.h" using namespace std;