From cfd8d2138e9bdbdfed2a59dbf51f232f7fb6bbc6 Mon Sep 17 00:00:00 2001 From: Rod Smith Date: Wed, 26 Feb 2020 19:12:49 -0500 Subject: [PATCH 01/38] Fix minor man page typos (from Debian patch) --- cgdisk.8 | 2 +- sgdisk.8 | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cgdisk.8 b/cgdisk.8 index 003bb61..052fbb2 100644 --- a/cgdisk.8 +++ b/cgdisk.8 @@ -172,7 +172,7 @@ text editor. Available options are as described below. (Note that \fBcgdisk\fR provides a much more limited set of options than its sibling \fBgdisk\fR. If you -need to perform partition table recovery, hybrid MBR modifcation, or other +need to perform partition table recovery, hybrid MBR modification, or other advanced operations, you should consult the \fBgdisk\fR documentation.) .TP diff --git a/sgdisk.8 b/sgdisk.8 index 30bbb2b..cf50009 100644 --- a/sgdisk.8 +++ b/sgdisk.8 @@ -167,7 +167,7 @@ when using this option. The others require a partition number. The \fItoggle\fR options enable you to change the attribute bit value. The \fIset\fR, \fIclear\fR, \fItoggle\fR, and \fIget\fR options work on a bit number; the others work on a hexadecimal bit mask. For example, type -\fBsgdisk -A 4:set:2 /dev/sdc\fR to set the bit 2 attribute (legacy BIOS +\fBsgdisk \-A 4:set:2 /dev/sdc\fR to set the bit 2 attribute (legacy BIOS bootable) on partition 4 on \fI/dev/sdc\fR. .TP @@ -354,7 +354,7 @@ use the first available partition number. Clear out all partition data. This includes GPT header data, all partition definitions, and the protective MBR. Note that this operation will, like most other operations, fail on a damaged disk. If you want to prepare a -disk you know to be damaged for GPT use, you should first wipe it with -Z +disk you know to be damaged for GPT use, you should first wipe it with \-Z and then partition it normally. This option will work even if the disk's original partition table is bad; however, most other options on the same command line will be ignored. @@ -504,7 +504,7 @@ sgdisk, but may with gdisk) .TP .B 8 -Disk replication operation (-R) failed +Disk replication operation (\-R) failed .SH "BUGS" Known bugs and limitations include: -- Gitee From db5727e311c976b4f0665ab122273ebc07bab5f4 Mon Sep 17 00:00:00 2001 From: nl6720 Date: Sat, 11 Apr 2020 09:56:29 +0300 Subject: [PATCH 02/38] Rename the partition type "Freedesktop $BOOT" to "XBOOTLDR partition". This matches the description in the Boot Loader Specification. See also https://github.com/systemd/systemd/issues/14832 . --- parttypes.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/parttypes.cc b/parttypes.cc index 38a49ff..f7b8db0 100644 --- a/parttypes.cc +++ b/parttypes.cc @@ -314,8 +314,8 @@ void PartType::AddAllTypes(void) { // Veracrypt (https://www.veracrypt.fr/en/Home.html) encrypted partition AddType(0xe900, "8C8F8EFF-AC95-4770-814A-21994F2DBC8F", "Veracrypt data"); - // See http://www.freedesktop.org/wiki/Specifications/BootLoaderSpec - AddType(0xea00, "BC13C2FF-59E6-4262-A352-B275FD6F7172", "Freedesktop $BOOT"); + // See https://systemd.io/BOOT_LOADER_SPECIFICATION/ + AddType(0xea00, "BC13C2FF-59E6-4262-A352-B275FD6F7172", "XBOOTLDR partition"); // Type code for Haiku; uses BeOS MBR code as hex code base AddType(0xeb00, "42465331-3BA3-10F1-802A-4861696B7521", "Haiku BFS"); -- Gitee From c03d1105dc6ac3b0bd253d45cec0573fa5dcef46 Mon Sep 17 00:00:00 2001 From: Aaron Bamberger Date: Tue, 11 Aug 2020 14:16:19 -0500 Subject: [PATCH 03/38] Fix missing 64-bit offset types in diskio-unix Most of the types used in the diskio routines are explicitly 64-bit, but there were two usages of off_t, which is a 32-bit value when compiled in a 32-bit userspace. This causes gpt-fdisk to be unable to correctly write partitions on a drive larger than 4GiB when compiled in a 32-bit userspace. This change updates the two usages of off_t to off64_t, which is explicitly 64-bit and allows the program to work as intended. --- diskio-unix.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/diskio-unix.cc b/diskio-unix.cc index d9f8b8d..35a4f5e 100644 --- a/diskio-unix.cc +++ b/diskio-unix.cc @@ -307,7 +307,7 @@ int DiskIO::DiskSync(void) { // Note that seeking beyond the end of the file is NOT detected as a failure! int DiskIO::Seek(uint64_t sector) { int retval = 1; - off_t seekTo, sought; + off64_t seekTo, sought; // If disk isn't open, try to open it.... if (!isOpen) { @@ -424,7 +424,7 @@ int DiskIO::Write(void* buffer, int numBytes) { // return correct values for disk image files. uint64_t DiskIO::DiskSize(int *err) { uint64_t sectors = 0; // size in sectors - off_t bytes = 0; // size in bytes + off64_t bytes = 0; // size in bytes struct stat64 st; int platformFound = 0; #ifdef __sun__ -- Gitee From 81c8bbee46ad6ebacf72eae70ba5147f376205a4 Mon Sep 17 00:00:00 2001 From: Rod Smith Date: Mon, 14 Sep 2020 10:08:18 -0400 Subject: [PATCH 04/38] Fix segfault on some weird data structures --- NEWS | 6 ++++++ gpt.cc | 13 ++++++++++++- support.h | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 54c865e..bac3da3 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,9 @@ +1.0.6 (?/??/2020): +------------------ + +- Fixed bug that could cause segfault if GPT header claimed partition + entries are oversized. + 1.0.5 (2/17/2020): ------------------ diff --git a/gpt.cc b/gpt.cc index fe8e956..1b4e10f 100644 --- a/gpt.cc +++ b/gpt.cc @@ -1041,6 +1041,14 @@ int GPTData::LoadHeader(struct GPTHeader *header, DiskIO & disk, uint64_t sector } // if *crcOk = CheckHeaderCRC(&tempHeader); + if (tempHeader.sizeOfPartitionEntries != sizeof(GPTPart)) { + cerr << "Warning: Partition table header claims that the size of partition table\n"; + cerr << "entries is " << tempHeader.sizeOfPartitionEntries << " bytes, but this program "; + cerr << " supports only " << sizeof(GPTPart) << "-byte entries.\n"; + cerr << "Adjusting accordingly, but partition table may be garbage.\n"; + tempHeader.sizeOfPartitionEntries = sizeof(GPTPart); + } + if (allOK && (numParts != tempHeader.numParts) && *crcOk) { allOK = SetGPTSize(tempHeader.numParts, 0); } @@ -1058,7 +1066,10 @@ int GPTData::LoadPartitionTable(const struct GPTHeader & header, DiskIO & disk, uint32_t sizeOfParts, newCRC; int retval; - if (disk.OpenForRead()) { + if (header.sizeOfPartitionEntries != sizeof(GPTPart)) { + cerr << "Error! GPT header contains invalid partition entry size!\n"; + retval = 0; + } else if (disk.OpenForRead()) { if (sector == 0) { retval = disk.Seek(header.partitionEntriesLBA); } else { diff --git a/support.h b/support.h index 9a79b95..978bfe1 100644 --- a/support.h +++ b/support.h @@ -8,7 +8,7 @@ #ifndef __GPTSUPPORT #define __GPTSUPPORT -#define GPTFDISK_VERSION "1.0.5" +#define GPTFDISK_VERSION "1.0.5.1" #if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined (__APPLE__) // Darwin (Mac OS) & FreeBSD: disk IOCTLs are different, and there is no lseek64 -- Gitee From 617e8a64278d0cb5ebc6aa9820bc725cba28bb20 Mon Sep 17 00:00:00 2001 From: Rod Smith Date: Tue, 12 Jan 2021 19:14:21 -0500 Subject: [PATCH 05/38] Update NEWS file --- NEWS | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index bac3da3..a9ae6be 100644 --- a/NEWS +++ b/NEWS @@ -1,9 +1,11 @@ -1.0.6 (?/??/2020): +1.0.6 (1/12/2021): ------------------ - Fixed bug that could cause segfault if GPT header claimed partition entries are oversized. +- Rename the partition type "Freedesktop $BOOT" to "XBOOTLDR partition". + 1.0.5 (2/17/2020): ------------------ -- Gitee From 6227140ecbf197b706e5f3f48c2d190788960fb1 Mon Sep 17 00:00:00 2001 From: nl6720 Date: Sat, 22 Aug 2020 16:20:14 +0300 Subject: [PATCH 06/38] Add systemd-homed user's home partition type See https://systemd.io/HOME_DIRECTORY/ . --- parttypes.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/parttypes.cc b/parttypes.cc index f7b8db0..f8b2dc1 100644 --- a/parttypes.cc +++ b/parttypes.cc @@ -148,6 +148,8 @@ void PartType::AddAllTypes(void) { AddType(0x830F, "86ED10D5-B607-45BB-8957-D350F23D0571", "Linux IA-64 root verity"); AddType(0x8310, "4D21B016-B534-45C2-A9FB-5C16E091FD2D", "Linux /var"); // Linux /var (auto-mounted by systemd) AddType(0x8311, "7EC6F557-3BC5-4ACA-B293-16EF5DF639D1", "Linux /var/tmp"); // Linux /var/tmp (auto-mounted by systemd) + // https://systemd.io/HOME_DIRECTORY/ + AddType(0x8312, "773F91EF-66D4-49B5-BD83-D683BF40AD16", "Linux user's home"); // used by systemd-homed // Used by Intel Rapid Start technology AddType(0x8400, "D3BFE2DE-3DAF-11DF-BA40-E3A556D89593", "Intel Rapid Start"); -- Gitee From 78bc9d81e2835388c7bfe0f1b576ca45ade309c2 Mon Sep 17 00:00:00 2001 From: nl6720 Date: Fri, 25 Sep 2020 09:51:32 +0300 Subject: [PATCH 07/38] Add Linux /usr and /usr verity partition types See https://systemd.io/DISCOVERABLE_PARTITIONS/ and https://github.com/systemd/systemd/pull/17101 . --- parttypes.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/parttypes.cc b/parttypes.cc index f8b2dc1..ed6dd24 100644 --- a/parttypes.cc +++ b/parttypes.cc @@ -148,6 +148,16 @@ void PartType::AddAllTypes(void) { AddType(0x830F, "86ED10D5-B607-45BB-8957-D350F23D0571", "Linux IA-64 root verity"); AddType(0x8310, "4D21B016-B534-45C2-A9FB-5C16E091FD2D", "Linux /var"); // Linux /var (auto-mounted by systemd) AddType(0x8311, "7EC6F557-3BC5-4ACA-B293-16EF5DF639D1", "Linux /var/tmp"); // Linux /var/tmp (auto-mounted by systemd) + AddType(0x8313, "75250D76-8CC6-458E-BD66-BD47CC81A812", "Linux x86 /usr "); // Linux /usr on x86 (auto-mounted by systemd) + AddType(0x8314, "8484680C-9521-48C6-9C11-B0720656F69E", "Linux x86-64 /usr"); // Linux /usr on x86-64 (auto-mounted by systemd) + AddType(0x8315, "7D0359A3-02B3-4F0A-865C-654403E70625", "Linux ARM32 /usr"); // Linux /usr on 32-bit ARM (auto-mounted by systemd) + AddType(0x8316, "B0E01050-EE5F-4390-949A-9101B17104E9", "Linux ARM64 /usr"); // Linux /usr on 64-bit ARM (auto-mounted by systemd) + AddType(0x8317, "4301D2A6-4E3B-4B2A-BB94-9E0B2C4225EA", "Linux IA-64 /usr"); // Linux /usr on Itanium (auto-mounted by systemd) + AddType(0x8318, "8F461B0D-14EE-4E81-9AA9-049B6FB97ABD", "Linux x86 /usr verity"); + AddType(0x8319, "77FF5F63-E7B6-4633-ACF4-1565B864C0E6", "Linux x86-64 /usr verity"); + AddType(0x831A, "C215D751-7BCD-4649-BE90-6627490A4C05", "Linux ARM32 /usr verity"); + AddType(0x831B, "6E11A4E7-FBCA-4DED-B9E9-E1A512BB664E", "Linux ARM64 /usr verity"); + AddType(0x831C, "6A491E03-3BE7-4545-8E38-83320E0EA880", "Linux IA-64 /usr verity"); // https://systemd.io/HOME_DIRECTORY/ AddType(0x8312, "773F91EF-66D4-49B5-BD83-D683BF40AD16", "Linux user's home"); // used by systemd-homed -- Gitee From ee3abf6f6d109c9ad37193bd710de7c774e37714 Mon Sep 17 00:00:00 2001 From: Rod Smith Date: Wed, 13 Jan 2021 10:08:01 -0500 Subject: [PATCH 08/38] Update version number and dates prior to 1.0.6 release. --- NEWS | 8 +++++++- cgdisk.8 | 4 ++-- current.spec | 8 ++++---- fixparts.8 | 4 ++-- gdisk.8 | 4 ++-- sgdisk.8 | 4 ++-- support.h | 2 +- 7 files changed, 20 insertions(+), 14 deletions(-) diff --git a/NEWS b/NEWS index a9ae6be..3773db7 100644 --- a/NEWS +++ b/NEWS @@ -4,7 +4,13 @@ - Fixed bug that could cause segfault if GPT header claimed partition entries are oversized. -- Rename the partition type "Freedesktop $BOOT" to "XBOOTLDR partition". +- Renamed the partition type "Freedesktop $BOOT" to "XBOOTLDR partition". + +- Added several more Freedesktop partition table type codes (0x8312 through + 0x831C). + +- Fixed type code definition in diskio-unix.cc that prevented 32-bit builds + from correctly handling disks over 4 GiB in size. 1.0.5 (2/17/2020): ------------------ diff --git a/cgdisk.8 b/cgdisk.8 index 052fbb2..6b31295 100644 --- a/cgdisk.8 +++ b/cgdisk.8 @@ -1,6 +1,6 @@ -.\" Copyright 2011-2020 Roderick W. Smith (rodsmith@rodsbooks.com) +.\" Copyright 2011-2021 Roderick W. Smith (rodsmith@rodsbooks.com) .\" May be distributed under the GNU General Public License -.TH "CGDISK" "8" "1.0.5" "Roderick W. Smith" "GPT fdisk Manual" +.TH "CGDISK" "8" "1.0.6" "Roderick W. Smith" "GPT fdisk Manual" .SH "NAME" cgdisk \- Curses-based GUID partition table (GPT) manipulator .SH "SYNOPSIS" diff --git a/current.spec b/current.spec index b473a38..bcbaa7f 100644 --- a/current.spec +++ b/current.spec @@ -1,12 +1,12 @@ Summary: GPT partitioning and MBR repair software Name: gptfdisk -Version: 1.0.5 +Version: 1.0.6 Release: 1%{?dist} License: GPLv2 URL: http://www.rodsbooks.com/gdisk Group: Applications/System -Source: http://www.rodsbooks.com/gdisk/gptfdisk-1.0.5.tar.gz +Source: http://www.rodsbooks.com/gdisk/gptfdisk-1.0.6.tar.gz BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) %description @@ -81,5 +81,5 @@ provides a few additional partition manipulation features. %changelog -* Mon Feb 17 2020 R Smith - 1.0.5 -- Created spec file for 1.0.5 release +* Wed Jan 13 2021 R Smith - 1.0.6 +- Created spec file for 1.0.6 release diff --git a/fixparts.8 b/fixparts.8 index cb23a6c..7522455 100644 --- a/fixparts.8 +++ b/fixparts.8 @@ -1,6 +1,6 @@ -.\" Copyright 2011-2020 Roderick W. Smith (rodsmith@rodsbooks.com) +.\" Copyright 2011-2021 Roderick W. Smith (rodsmith@rodsbooks.com) .\" May be distributed under the GNU General Public License -.TH "FIXPARTS" "8" "1.0.5" "Roderick W. Smith" "FixParts Manual" +.TH "FIXPARTS" "8" "1.0.6" "Roderick W. Smith" "FixParts Manual" .SH "NAME" fixparts \- MBR partition table repair utility .SH "SYNOPSIS" diff --git a/gdisk.8 b/gdisk.8 index cd64c31..c3a088e 100644 --- a/gdisk.8 +++ b/gdisk.8 @@ -1,6 +1,6 @@ -.\" Copyright 2011-2020 Roderick W. Smith (rodsmith@rodsbooks.com) +.\" Copyright 2011-2021 Roderick W. Smith (rodsmith@rodsbooks.com) .\" May be distributed under the GNU General Public License -.TH "GDISK" "8" "1.0.5" "Roderick W. Smith" "GPT fdisk Manual" +.TH "GDISK" "8" "1.0.6" "Roderick W. Smith" "GPT fdisk Manual" .SH "NAME" gdisk \- Interactive GUID partition table (GPT) manipulator .SH "SYNOPSIS" diff --git a/sgdisk.8 b/sgdisk.8 index cf50009..6cfc17e 100644 --- a/sgdisk.8 +++ b/sgdisk.8 @@ -1,6 +1,6 @@ -.\" Copyright 2011-2020 Roderick W. Smith (rodsmith@rodsbooks.com) +.\" Copyright 2011-2021 Roderick W. Smith (rodsmith@rodsbooks.com) .\" May be distributed under the GNU General Public License -.TH "SGDISK" "8" "1.0.5" "Roderick W. Smith" "GPT fdisk Manual" +.TH "SGDISK" "8" "1.0.6" "Roderick W. Smith" "GPT fdisk Manual" .SH "NAME" sgdisk \- Command\-line GUID partition table (GPT) manipulator for Linux and Unix .SH "SYNOPSIS" diff --git a/support.h b/support.h index 978bfe1..25e660a 100644 --- a/support.h +++ b/support.h @@ -8,7 +8,7 @@ #ifndef __GPTSUPPORT #define __GPTSUPPORT -#define GPTFDISK_VERSION "1.0.5.1" +#define GPTFDISK_VERSION "1.0.6" #if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined (__APPLE__) // Darwin (Mac OS) & FreeBSD: disk IOCTLs are different, and there is no lseek64 -- Gitee From f523bbc0c2437fe259aa3aff5e819e24101aee29 Mon Sep 17 00:00:00 2001 From: Rod Smith Date: Wed, 13 Jan 2021 10:29:24 -0500 Subject: [PATCH 09/38] Fix bug that could cause crash if a badly-formatted MBR disk was read. --- basicmbr.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/basicmbr.cc b/basicmbr.cc index dd48706..c266e39 100644 --- a/basicmbr.cc +++ b/basicmbr.cc @@ -290,7 +290,8 @@ int BasicMBRData::ReadLogicalParts(uint64_t extendedStart, int partNum) { if (EbrLocations[i] == offset) { // already read this one; infinite logical partition loop! cerr << "Logical partition infinite loop detected! This is being corrected.\n"; allOK = -1; - partNum -= 1; + if (partNum > 0) //don't go negative + partNum -= 1; } // if } // for EbrLocations[partNum] = offset; -- Gitee From b160f90589abf830a704dc8d1482306bf7fa77cf Mon Sep 17 00:00:00 2001 From: Rod Smith Date: Wed, 13 Jan 2021 10:31:07 -0500 Subject: [PATCH 10/38] update NEWS --- NEWS | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 3773db7..72a2cc3 100644 --- a/NEWS +++ b/NEWS @@ -1,9 +1,12 @@ -1.0.6 (1/12/2021): +1.0.6 (1/13/2021): ------------------ - Fixed bug that could cause segfault if GPT header claimed partition entries are oversized. +- Fixed bug that could cause a crash if a badly-formatted MBR disk was + read. + - Renamed the partition type "Freedesktop $BOOT" to "XBOOTLDR partition". - Added several more Freedesktop partition table type codes (0x8312 through -- Gitee From 273fff5c84288f3c09b32521d1217619e9cc079e Mon Sep 17 00:00:00 2001 From: Rod Smith Date: Wed, 13 Jan 2021 14:33:54 -0500 Subject: [PATCH 11/38] Adjust position of multiple-inclusion protection in .h files --- attributes.h | 6 +++--- basicmbr.h | 6 +++--- bsd.h | 6 +++--- diskio-unix.cc | 4 ++++ gpt.h | 6 +++--- gptcurses.h | 6 +++--- mbr.h | 6 +++--- parttypes.h | 6 +++--- support.h | 6 +++--- 9 files changed, 28 insertions(+), 24 deletions(-) diff --git a/attributes.h b/attributes.h index f6c66ff..6a61b8c 100644 --- a/attributes.h +++ b/attributes.h @@ -1,12 +1,12 @@ /* This program is copyright (c) 2009-2011 by Roderick W. Smith. It is distributed under the terms of the GNU GPL version 2, as detailed in the COPYING file. */ -#include -#include - #ifndef __GPT_ATTRIBUTES #define __GPT_ATTRIBUTES +#include +#include + #define NUM_ATR 64 /* # of attributes -- 64, since it's a 64-bit field */ #define ATR_NAME_SIZE 25 /* maximum size of attribute names */ diff --git a/basicmbr.h b/basicmbr.h index 504e039..f4b0e45 100644 --- a/basicmbr.h +++ b/basicmbr.h @@ -3,14 +3,14 @@ /* This program is copyright (c) 2009-2013 by Roderick W. Smith. It is distributed under the terms of the GNU GPL version 2, as detailed in the COPYING file. */ +#ifndef __BASICMBRSTRUCTS +#define __BASICMBRSTRUCTS + #include #include #include "diskio.h" #include "mbrpart.h" -#ifndef __BASICMBRSTRUCTS -#define __BASICMBRSTRUCTS - #define MBR_SIGNATURE UINT16_C(0xAA55) // Maximum number of MBR partitions diff --git a/bsd.h b/bsd.h index cbd3588..c4b74a4 100644 --- a/bsd.h +++ b/bsd.h @@ -3,14 +3,14 @@ /* This program is copyright (c) 2009 by Roderick W. Smith. It is distributed under the terms of the GNU GPL version 2, as detailed in the COPYING file. */ +#ifndef __BSD_STRUCTS +#define __BSD_STRUCTS + #include #include #include "gptpart.h" #include "diskio.h" -#ifndef __BSD_STRUCTS -#define __BSD_STRUCTS - #define BSD_SIGNATURE UINT32_C(0x82564557) /* BSD disklabel signature ("magic") */ // BSD disklabels can start at offsets of 64 or the sector size -- at least, diff --git a/diskio-unix.cc b/diskio-unix.cc index 35a4f5e..4aefc6f 100644 --- a/diskio-unix.cc +++ b/diskio-unix.cc @@ -37,6 +37,10 @@ using namespace std; +#ifdef __APPLE__ +#define off64_t off_t +#endif + // Returns the official "real" name for a shortened version of same. // Trivial here; more important in Windows void DiskIO::MakeRealName(void) { diff --git a/gpt.h b/gpt.h index a5be961..9ba013b 100644 --- a/gpt.h +++ b/gpt.h @@ -4,6 +4,9 @@ /* This program is copyright (c) 2009-2011 by Roderick W. Smith. It is distributed under the terms of the GNU GPL version 2, as detailed in the COPYING file. */ +#ifndef __GPTSTRUCTS +#define __GPTSTRUCTS + #include #include #include "gptpart.h" @@ -12,9 +15,6 @@ #include "bsd.h" #include "gptpart.h" -#ifndef __GPTSTRUCTS -#define __GPTSTRUCTS - // Default values for sector alignment #define DEFAULT_ALIGNMENT 2048 #define MAX_ALIGNMENT 65536 diff --git a/gptcurses.h b/gptcurses.h index f153de2..a080987 100644 --- a/gptcurses.h +++ b/gptcurses.h @@ -19,14 +19,14 @@ * */ +#ifndef __GPT_CURSES +#define __GPT_CURSES + #include #include #include "gptpart.h" #include "gpt.h" -#ifndef __GPT_CURSES -#define __GPT_CURSES - using namespace std; struct MenuItem { diff --git a/mbr.h b/mbr.h index bbb84ef..21c1d7b 100644 --- a/mbr.h +++ b/mbr.h @@ -3,6 +3,9 @@ /* This program is copyright (c) 2009-2013 by Roderick W. Smith. It is distributed under the terms of the GNU GPL version 2, as detailed in the COPYING file. */ +#ifndef __MBRSTRUCTS +#define __MBRSTRUCTS + #include #include #include "gptpart.h" @@ -10,9 +13,6 @@ #include "diskio.h" #include "basicmbr.h" -#ifndef __MBRSTRUCTS -#define __MBRSTRUCTS - using namespace std; /**************************************** diff --git a/parttypes.h b/parttypes.h index 2b80026..92f3d64 100644 --- a/parttypes.h +++ b/parttypes.h @@ -1,6 +1,9 @@ /* This program is copyright (c) 2009-2018 by Roderick W. Smith. It is distributed under the terms of the GNU GPL version 2, as detailed in the COPYING file. */ +#ifndef __PARTITION_TYPES +#define __PARTITION_TYPES + #include #include #ifdef USE_UTF16 @@ -12,9 +15,6 @@ #include "support.h" #include "guid.h" -#ifndef __PARTITION_TYPES -#define __PARTITION_TYPES - using namespace std; // A partition type diff --git a/support.h b/support.h index 25e660a..d87fe9a 100644 --- a/support.h +++ b/support.h @@ -1,13 +1,13 @@ /* This program is copyright (c) 2009-2018 by Roderick W. Smith. It is distributed under the terms of the GNU GPL version 2, as detailed in the COPYING file. */ +#ifndef __GPTSUPPORT +#define __GPTSUPPORT + #include #include #include -#ifndef __GPTSUPPORT -#define __GPTSUPPORT - #define GPTFDISK_VERSION "1.0.6" #if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined (__APPLE__) -- Gitee From 6180deb472c302c47f4d4acff8f2123d10824364 Mon Sep 17 00:00:00 2001 From: Rod Smith Date: Wed, 13 Jan 2021 17:17:41 -0500 Subject: [PATCH 12/38] Version 1.0.6 release --- Makefile.freebsd | 4 ++-- NEWS | 11 ++++++++--- gptcurses.cc | 2 +- parttypes.cc | 4 ++-- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Makefile.freebsd b/Makefile.freebsd index dace733..4b4b616 100644 --- a/Makefile.freebsd +++ b/Makefile.freebsd @@ -1,5 +1,5 @@ -CC=gcc -CXX=g++ +CC=clang +CXX=clang++ CFLAGS+=-D_FILE_OFFSET_BITS=64 #CXXFLAGS+=-Wall -D_FILE_OFFSET_BITS=64 -D USE_UTF16 -I/usr/local/include CXXFLAGS+=-Wall -D_FILE_OFFSET_BITS=64 -I /usr/local/include diff --git a/NEWS b/NEWS index 72a2cc3..f74bad0 100644 --- a/NEWS +++ b/NEWS @@ -2,10 +2,12 @@ ------------------ - Fixed bug that could cause segfault if GPT header claimed partition - entries are oversized. + entries are oversized. See: + https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-0256 - Fixed bug that could cause a crash if a badly-formatted MBR disk was - read. + read. See: + https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-0308 - Renamed the partition type "Freedesktop $BOOT" to "XBOOTLDR partition". @@ -13,7 +15,10 @@ 0x831C). - Fixed type code definition in diskio-unix.cc that prevented 32-bit builds - from correctly handling disks over 4 GiB in size. + from correctly handling disks over 4 TiB in size. + +- Minor tweaks to get the software to compile on FreeBSD; that seems to have + fallen into disrepair. 1.0.5 (2/17/2020): ------------------ diff --git a/gptcurses.cc b/gptcurses.cc index 1b18cf2..71aa734 100644 --- a/gptcurses.cc +++ b/gptcurses.cc @@ -23,7 +23,7 @@ #include #include #include -#ifdef __APPLE__ +#if defined (__APPLE__) || (__FreeBSD__) #include #else #include diff --git a/parttypes.cc b/parttypes.cc index ed6dd24..231d214 100644 --- a/parttypes.cc +++ b/parttypes.cc @@ -148,6 +148,8 @@ void PartType::AddAllTypes(void) { AddType(0x830F, "86ED10D5-B607-45BB-8957-D350F23D0571", "Linux IA-64 root verity"); AddType(0x8310, "4D21B016-B534-45C2-A9FB-5C16E091FD2D", "Linux /var"); // Linux /var (auto-mounted by systemd) AddType(0x8311, "7EC6F557-3BC5-4ACA-B293-16EF5DF639D1", "Linux /var/tmp"); // Linux /var/tmp (auto-mounted by systemd) + // https://systemd.io/HOME_DIRECTORY/ + AddType(0x8312, "773F91EF-66D4-49B5-BD83-D683BF40AD16", "Linux user's home"); // used by systemd-homed AddType(0x8313, "75250D76-8CC6-458E-BD66-BD47CC81A812", "Linux x86 /usr "); // Linux /usr on x86 (auto-mounted by systemd) AddType(0x8314, "8484680C-9521-48C6-9C11-B0720656F69E", "Linux x86-64 /usr"); // Linux /usr on x86-64 (auto-mounted by systemd) AddType(0x8315, "7D0359A3-02B3-4F0A-865C-654403E70625", "Linux ARM32 /usr"); // Linux /usr on 32-bit ARM (auto-mounted by systemd) @@ -158,8 +160,6 @@ void PartType::AddAllTypes(void) { AddType(0x831A, "C215D751-7BCD-4649-BE90-6627490A4C05", "Linux ARM32 /usr verity"); AddType(0x831B, "6E11A4E7-FBCA-4DED-B9E9-E1A512BB664E", "Linux ARM64 /usr verity"); AddType(0x831C, "6A491E03-3BE7-4545-8E38-83320E0EA880", "Linux IA-64 /usr verity"); - // https://systemd.io/HOME_DIRECTORY/ - AddType(0x8312, "773F91EF-66D4-49B5-BD83-D683BF40AD16", "Linux user's home"); // used by systemd-homed // Used by Intel Rapid Start technology AddType(0x8400, "D3BFE2DE-3DAF-11DF-BA40-E3A556D89593", "Intel Rapid Start"); -- Gitee From f063fe08e424c99f133df18bf9dce49c851bcb0a Mon Sep 17 00:00:00 2001 From: Rod Smith Date: Mon, 1 Feb 2021 10:19:50 -0500 Subject: [PATCH 13/38] Fix spurious warnings of problems on MBR disks --- NEWS | 7 +++++++ gpt.cc | 18 +++++++++++++----- support.h | 2 +- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/NEWS b/NEWS index f74bad0..a7131aa 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,10 @@ +1.0.7 (?/??/2021): +------------------ + +- Fixed bug that caused spurious warnings about the partition table + header claiming an invalid size of partition entries when reading + some MBR disks. + 1.0.6 (1/13/2021): ------------------ diff --git a/gpt.cc b/gpt.cc index 1b4e10f..842dfb1 100644 --- a/gpt.cc +++ b/gpt.cc @@ -1042,11 +1042,19 @@ int GPTData::LoadHeader(struct GPTHeader *header, DiskIO & disk, uint64_t sector *crcOk = CheckHeaderCRC(&tempHeader); if (tempHeader.sizeOfPartitionEntries != sizeof(GPTPart)) { - cerr << "Warning: Partition table header claims that the size of partition table\n"; - cerr << "entries is " << tempHeader.sizeOfPartitionEntries << " bytes, but this program "; - cerr << " supports only " << sizeof(GPTPart) << "-byte entries.\n"; - cerr << "Adjusting accordingly, but partition table may be garbage.\n"; - tempHeader.sizeOfPartitionEntries = sizeof(GPTPart); + // Print the below warning only if the CRC is OK -- but correct the + // problem either way. The warning is printed only on a valid CRC + // because otherwise this warning will display inappropriately when + // reading MBR disks. If the CRC is invalid, then a warning about + // that will be shown later, so the user will still know that + // something is wrong. + if (*crcOk) { + cerr << "Warning: Partition table header claims that the size of partition table\n"; + cerr << "entries is " << tempHeader.sizeOfPartitionEntries << " bytes, but this program "; + cerr << " supports only " << sizeof(GPTPart) << "-byte entries.\n"; + cerr << "Adjusting accordingly, but partition table may be garbage.\n"; + } + tempHeader.sizeOfPartitionEntries = sizeof(GPTPart); } if (allOK && (numParts != tempHeader.numParts) && *crcOk) { diff --git a/support.h b/support.h index d87fe9a..e3e1e12 100644 --- a/support.h +++ b/support.h @@ -8,7 +8,7 @@ #include #include -#define GPTFDISK_VERSION "1.0.6" +#define GPTFDISK_VERSION "1.0.6.1" #if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined (__APPLE__) // Darwin (Mac OS) & FreeBSD: disk IOCTLs are different, and there is no lseek64 -- Gitee From 86dd5fea351a5a55bea26b7622eb85ebd6075a60 Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Sun, 7 Mar 2021 14:46:59 +0000 Subject: [PATCH 14/38] gptpart.cc: Fix double byteswap for big-endian architectures. The data in 'name' was already byteswapped by ReversePartBytes, so byteswapping it again in GetDescription returned each UTF-16BE unit back to UTF-16LE and caused seemingly garbage strings to be printed. --- gptpart.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/gptpart.cc b/gptpart.cc index b4f2698..b268cf0 100644 --- a/gptpart.cc +++ b/gptpart.cc @@ -92,7 +92,6 @@ string GPTPart::GetDescription(void) { size_t pos = 0 ; while ( ( pos < NAME_SIZE ) && ( name[ pos ] != 0 ) ) { uint16_t cp = name[ pos ++ ] ; - if ( ! IsLittleEndian() ) ReverseBytes( & cp , 2 ) ; // first to utf32 uint32_t uni ; if ( cp < 0xd800 || cp > 0xdfff ) { -- Gitee From 0d47132b76b6eb1194093f168ea611d20665eb88 Mon Sep 17 00:00:00 2001 From: Rod Smith Date: Mon, 8 Mar 2021 19:06:27 -0500 Subject: [PATCH 15/38] Adjusted documentation & Makefile.mac for new ARM64 support under macOS --- Makefile.mac | 5 ++-- NEWS | 10 ++++++++ README | 68 ++++++++++++++++++++++++++-------------------------- 3 files changed, 47 insertions(+), 36 deletions(-) diff --git a/Makefile.mac b/Makefile.mac index 09ae409..ea21fa6 100644 --- a/Makefile.mac +++ b/Makefile.mac @@ -1,7 +1,7 @@ CC=gcc CXX=c++ # FATBINFLAGS=-arch x86_64 -arch i386 -mmacosx-version-min=10.9 -FATBINFLAGS=-arch x86_64 -mmacosx-version-min=10.9 +FATBINFLAGS=-arch x86_64 -arch arm64 -mmacosx-version-min=10.9 THINBINFLAGS=-arch x86_64 -mmacosx-version-min=10.9 CFLAGS=$(FATBINFLAGS) -O2 -D_FILE_OFFSET_BITS=64 -g #CXXFLAGS=-O2 -Wall -D_FILE_OFFSET_BITS=64 -D USE_UTF16 -I/opt/local/include -I/usr/local/include -I/opt/local/include -g @@ -21,7 +21,8 @@ gdisk: $(LIB_OBJS) gpttext.o gdisk.o # $(CXX) $(LIB_OBJS) -L/usr/lib -licucore gpttext.o gdisk.o -o gdisk cgdisk: $(LIB_OBJS) cgdisk.o gptcurses.o - $(CXX) $(LIB_OBJS) cgdisk.o gptcurses.o /usr/lib/libncurses.dylib $(LDFLAGS) $(FATBINFLAGS) -o cgdisk + $(CXX) $(LIB_OBJS) cgdisk.o gptcurses.o /usr/local/Cellar/ncurses/6.2/lib/libncurses.dylib $(LDFLAGS) -o cgdisk +# $(CXX) $(LIB_OBJS) cgdisk.o gptcurses.o /usr/lib/libncurses.dylib $(LDFLAGS) -o cgdisk # $(CXX) $(LIB_OBJS) cgdisk.o gptcurses.o $(LDFLAGS) -licucore -lncurses -o cgdisk sgdisk: $(LIB_OBJS) gptcl.o sgdisk.o diff --git a/NEWS b/NEWS index a7131aa..7d29c53 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,16 @@ header claiming an invalid size of partition entries when reading some MBR disks. +- Added ARM64 as an architecture for the Mac builds of gdisk and fixparts. + The official GPT fdisk binaries of these files for macOS are now + "universal" x86-64/ARM64 binaries, so they will run natively on the new M1 + (ARM64) Macs. The sgdisk and cgdisk binaries, though, remain built only + for x86-64, because they rely on libraries that are not easily built in + "universal" form. + +- Fixed double byte swap operation on partition label data on big-endian + CPUs. This resulted in partition names becoming gibberish on such CPUs. + 1.0.6 (1/13/2021): ------------------ diff --git a/README b/README index 8f38a1b..e52dd2c 100644 --- a/README +++ b/README @@ -168,8 +168,8 @@ work; however, I've not done extensive testing of the resulting binaries, beyond checking a few basics. Under Windows, Microsoft Visual C++ 2008 can be used instead. In addition, note these requirements: -* On Linux, FreeBSD, OS X, and Solaris, libuuid must be installed. This is - the standard for Linux and OS X, although you may need to install a +* On Linux, FreeBSD, macOS, and Solaris, libuuid must be installed. This is + the standard for Linux and macOS, although you may need to install a package called uuid-dev or something similar to get the headers. On FreeBSD, the e2fsprogs-libuuid port must be installed. @@ -177,11 +177,11 @@ be used instead. In addition, note these requirements: Unicode partition names, is optional on all platforms except Windows, on which it's not supported. Using this library was required to get proper UTF-16 partition name support in GPT fdisk versions prior to 0.8.9, but - as of that version it should not longer be required. Nonetheless, you can + as of that version it should no longer be required. Nonetheless, you can use it if you're having problems with the new UTF-16 support. This - library is normally installed in Linux and OS X, but you may need to + library is normally installed in Linux and macOS, but you may need to install the development headers (libicu-dev or something similar in - Linux; or the libicu36-dev Fink package in OS X). To compile with ICU + Linux; or the libicu36-dev Fink package in macOS). To compile with ICU support, you must modify the Makefile: Look for commented-out lines that refer to USE_UTF16, -licuuc, -licudata, or -licucore. Uncomment them and comment out the equivalents that lack these lines. @@ -189,17 +189,17 @@ be used instead. In addition, note these requirements: * The cgdisk program requires the ncurses library and its development files (headers). Most Linux distributions install ncurses by default, but you may need to install a package called libncurses5-dev, ncurses-devel, or - something similar to obtain the header files. These files were installed - already on my Mac OS X development system; however, they may have been - installed as dependencies of other programs I've installed. If you're - having problems installing ncurses, you can compile gdisk and/or sgdisk - without cgdisk by specifying only the targets you want to compile to - make. + something similar to obtain the header files. On my macOS development + system, I installed the nurses Homebrew ("brew") package; however, other + Unix-style software repositories are available and may work for you (see + the next item). If you're having problems installing ncurses, you can + compile gdisk and/or sgdisk without cgdisk by specifying only the targets + you want to compile to make. * The sgdisk program requires the popt library and its development files (headers). Most Linux distributions install popt by default, but you may need to install a package called popt-dev, popt-devel, or something - similar to obtain the header files. Mac OS users can find a version of + similar to obtain the header files. MacOS users can find a version of popt for Mac OS from Darwin Ports (http://popt.darwinports.com), MacPorts (https://trac.macports.org/browser/trunk/dports/devel/popt/Portfile), Fink (http://www.finkproject.org), or brew (http://macappstore.org/popt/); @@ -214,35 +214,35 @@ be used instead. In addition, note these requirements: When all the necessary development tools and libraries are installed, you can uncompress the package and type "make" at the command prompt in the -resulting directory. (You may need to type "make -f Makefile.mac" on Mac OS -X, "make -f Makefile.freebsd" on FreeBSD, "make -f Makefile.solaris" on -Solaris, or "make -f Makefile.mingw" to compile using MinGW for Windows.) -You may also need to add header (include) directories or library -directories by setting the CXXFLAGS environment variable or by editing the -Makefile. The result should be program files called gdisk, cgdisk, sgdisk, -and fixparts. Typing "make gdisk", "make cgdisk", "make sgdisk", or "make -fixparts" will compile only the requested programs. You can use these -programs in place or copy the files to a suitable directory, such as -/usr/local/sbin. You can copy the man pages (gdisk.8, cgdisk.8, sgdisk.8, -and fixparts.8) to /usr/local/man/man8 to make them available. +resulting directory. (You must type "make -f Makefile.mac" on macOS, "make +-f Makefile.freebsd" on FreeBSD, "make -f Makefile.solaris" on Solaris, or +"make -f Makefile.mingw" to compile using MinGW for Windows.) You may also +need to add header (include) directories or library directories by setting +the CXXFLAGS environment variable or by editing the Makefile. The result +should be program files called gdisk, cgdisk, sgdisk, and fixparts. Typing +"make gdisk", "make cgdisk", "make sgdisk", or "make fixparts" will compile +only the requested programs. You can use these programs in place or copy the +files to a suitable directory, such as /usr/local/sbin. You can copy the man +pages (gdisk.8, cgdisk.8, sgdisk.8, and fixparts.8) to /usr/local/man/man8 +to make them available. Caveats ------- -THIS SOFTWARE IS BETA SOFTWARE! IF IT WIPES OUT YOUR HARD DISK OR EATS YOUR -CAT, DON'T BLAME ME! To date, I've tested the software on several USB flash -drives, physical hard disks, and virtual disks in the QEMU and VirtualBox -environments. Many others have now used the software on their computers, as -well. I believe all data-corruption bugs to be squashed, but I know full well -that the odds of my missing something are high. This is particularly true for -large (over-2TiB) drives; my only direct testing with such disks is with -virtual QEMU and VirtualBox disks. I've received user reports of success with -RAID arrays over 2TiB in size, though. +DISK PARTITIONING SOFTWARE IS DANGEROUS! Although the GPT fdisk project has +existed since 2009, I do not claim it is entirely bug-free; in fact a glance +at the revision history shows recent bug fixes. I believe all +data-corruption bugs to be squashed, but I know full well that the odds of +my missing something are high. This is particularly true for large +(over-2TiB) drives and use in exotic environments. My main development platform is a system running the 64-bit version of Ubuntu Linux. I've also tested on several other 32- and 64-bit Linux -distributions, Intel-based Mac OS X 10.6 and several later versions, 64-bit -FreeBSD 7.1, and Windows 7 and 10. +distributions, Intel-based macOS 10 and 11, 64-bit FreeBSD 7.1, and Windows +7 and 10. Other environments qualify as "exotic," and even macOS and Windows +are borderline exotic in this context, since I use Linux almost exclusively, +and my impression is that GPT fdisk is far more commonly used on Linux than +in other OSes. Redistribution -------------- -- Gitee From 79977a7e48ad6da9f206005abe3c2553402d8076 Mon Sep 17 00:00:00 2001 From: Rod Smith Date: Wed, 10 Mar 2021 19:42:31 -0500 Subject: [PATCH 16/38] Three new type codes --- NEWS | 7 ++++++- parttypes.cc | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 7d29c53..873338a 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,4 @@ -1.0.7 (?/??/2021): +1.0.7 (3/10/2021): ------------------ - Fixed bug that caused spurious warnings about the partition table @@ -15,6 +15,11 @@ - Fixed double byte swap operation on partition label data on big-endian CPUs. This resulted in partition names becoming gibberish on such CPUs. +- Added three new type codes: + - 0x0701 - Microsoft Storage Replica + - 0x0702 - ArcaOS Type 1 + - 0x8401 - Storage Performance Development Kit (SPDK) block device + 1.0.6 (1/13/2021): ------------------ diff --git a/parttypes.cc b/parttypes.cc index 231d214..838e4bc 100644 --- a/parttypes.cc +++ b/parttypes.cc @@ -83,6 +83,8 @@ void PartType::AddAllTypes(void) { AddType(0x0400, "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7", "Microsoft basic data", 0); // FAT-16 < 32M AddType(0x0600, "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7", "Microsoft basic data", 0); // FAT-16 AddType(0x0700, "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7", "Microsoft basic data", 1); // NTFS (or HPFS) + AddType(0x0701, "558D43C5-A1AC-43C0-AAC8-D1472B2923D1", "Microsoft Storage Replica", 1); + AddType(0x0702, "90B6FF38-B98F-4358-A21F-48F35B4A8AD3", "ArcaOS Type 1", 1); AddType(0x0b00, "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7", "Microsoft basic data", 0); // FAT-32 AddType(0x0c00, "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7", "Microsoft basic data", 0); // FAT-32 LBA AddType(0x0c01, "E3C9E316-0B5C-4DB8-817D-F92DF00215AE", "Microsoft reserved"); @@ -163,6 +165,8 @@ void PartType::AddAllTypes(void) { // Used by Intel Rapid Start technology AddType(0x8400, "D3BFE2DE-3DAF-11DF-BA40-E3A556D89593", "Intel Rapid Start"); + // This is another Intel-associated technology, so I'm keeping it close to the previous one.... + AddType(0x8401, "7C5222BD-8F5D-4087-9C00-BF9843C7B58C", "SPDK block device"); // Type codes for Container Linux (formerly CoreOS; https://coreos.com) AddType(0x8500, "5DFBF5F4-2848-4BAC-AA5E-0D9A20B745A6", "Container Linux /usr"); -- Gitee From 80e66b25922ab78cf987f693bf5477e466b1443a Mon Sep 17 00:00:00 2001 From: Rod Smith Date: Wed, 10 Mar 2021 20:23:37 -0500 Subject: [PATCH 17/38] Version 1.0.7 release --- cgdisk.8 | 2 +- current.spec | 8 ++++---- fixparts.8 | 2 +- gdisk.8 | 2 +- sgdisk.8 | 2 +- support.h | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cgdisk.8 b/cgdisk.8 index 6b31295..af5821e 100644 --- a/cgdisk.8 +++ b/cgdisk.8 @@ -1,6 +1,6 @@ .\" Copyright 2011-2021 Roderick W. Smith (rodsmith@rodsbooks.com) .\" May be distributed under the GNU General Public License -.TH "CGDISK" "8" "1.0.6" "Roderick W. Smith" "GPT fdisk Manual" +.TH "CGDISK" "8" "1.0.7" "Roderick W. Smith" "GPT fdisk Manual" .SH "NAME" cgdisk \- Curses-based GUID partition table (GPT) manipulator .SH "SYNOPSIS" diff --git a/current.spec b/current.spec index bcbaa7f..ffdf002 100644 --- a/current.spec +++ b/current.spec @@ -1,12 +1,12 @@ Summary: GPT partitioning and MBR repair software Name: gptfdisk -Version: 1.0.6 +Version: 1.0.7 Release: 1%{?dist} License: GPLv2 URL: http://www.rodsbooks.com/gdisk Group: Applications/System -Source: http://www.rodsbooks.com/gdisk/gptfdisk-1.0.6.tar.gz +Source: http://www.rodsbooks.com/gdisk/gptfdisk-1.0.7.tar.gz BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) %description @@ -81,5 +81,5 @@ provides a few additional partition manipulation features. %changelog -* Wed Jan 13 2021 R Smith - 1.0.6 -- Created spec file for 1.0.6 release +* Wed Mar 10 2021 R Smith - 1.0.7 +- Created spec file for 1.0.7 release diff --git a/fixparts.8 b/fixparts.8 index 7522455..a81a878 100644 --- a/fixparts.8 +++ b/fixparts.8 @@ -1,6 +1,6 @@ .\" Copyright 2011-2021 Roderick W. Smith (rodsmith@rodsbooks.com) .\" May be distributed under the GNU General Public License -.TH "FIXPARTS" "8" "1.0.6" "Roderick W. Smith" "FixParts Manual" +.TH "FIXPARTS" "8" "1.0.7" "Roderick W. Smith" "FixParts Manual" .SH "NAME" fixparts \- MBR partition table repair utility .SH "SYNOPSIS" diff --git a/gdisk.8 b/gdisk.8 index c3a088e..62f6bd2 100644 --- a/gdisk.8 +++ b/gdisk.8 @@ -1,6 +1,6 @@ .\" Copyright 2011-2021 Roderick W. Smith (rodsmith@rodsbooks.com) .\" May be distributed under the GNU General Public License -.TH "GDISK" "8" "1.0.6" "Roderick W. Smith" "GPT fdisk Manual" +.TH "GDISK" "8" "1.0.7" "Roderick W. Smith" "GPT fdisk Manual" .SH "NAME" gdisk \- Interactive GUID partition table (GPT) manipulator .SH "SYNOPSIS" diff --git a/sgdisk.8 b/sgdisk.8 index 6cfc17e..59a3d3c 100644 --- a/sgdisk.8 +++ b/sgdisk.8 @@ -1,6 +1,6 @@ .\" Copyright 2011-2021 Roderick W. Smith (rodsmith@rodsbooks.com) .\" May be distributed under the GNU General Public License -.TH "SGDISK" "8" "1.0.6" "Roderick W. Smith" "GPT fdisk Manual" +.TH "SGDISK" "8" "1.0.7" "Roderick W. Smith" "GPT fdisk Manual" .SH "NAME" sgdisk \- Command\-line GUID partition table (GPT) manipulator for Linux and Unix .SH "SYNOPSIS" diff --git a/support.h b/support.h index e3e1e12..0d68024 100644 --- a/support.h +++ b/support.h @@ -8,7 +8,7 @@ #include #include -#define GPTFDISK_VERSION "1.0.6.1" +#define GPTFDISK_VERSION "1.0.7" #if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined (__APPLE__) // Darwin (Mac OS) & FreeBSD: disk IOCTLs are different, and there is no lseek64 -- Gitee From eae9f7e2e1470ed2d5bc029180aa2adc88fbc4a7 Mon Sep 17 00:00:00 2001 From: Rod Smith Date: Wed, 17 Mar 2021 21:57:12 -0400 Subject: [PATCH 18/38] Code cleanup based on 'infer' suggestions; mostly just dead stores. One forgotten change --- basicmbr.cc | 12 ++++++------ bsd.cc | 4 ++-- diskio-unix.cc | 2 +- gpt.cc | 6 ++---- gptcurses.cc | 1 - gpttext.cc | 2 +- support.cc | 2 +- 7 files changed, 13 insertions(+), 16 deletions(-) diff --git a/basicmbr.cc b/basicmbr.cc index c266e39..e09b0e9 100644 --- a/basicmbr.cc +++ b/basicmbr.cc @@ -140,7 +140,7 @@ BasicMBRData & BasicMBRData::operator=(const BasicMBRData & orig) { // Read data from MBR. Returns 1 if read was successful (even if the // data isn't a valid MBR), 0 if the read failed. int BasicMBRData::ReadMBRData(const string & deviceFilename) { - int allOK = 1; + int allOK; if (myDisk == NULL) { myDisk = new DiskIO; @@ -355,7 +355,7 @@ int BasicMBRData::ReadLogicalParts(uint64_t extendedStart, int partNum) { // MBR itself and any defined logical partitions, provided there's an // MBR extended partition. int BasicMBRData::WriteMBRData(void) { - int allOK = 1; + int allOK; if (myDisk != NULL) { if (myDisk->OpenForWrite() != 0) { @@ -372,7 +372,7 @@ int BasicMBRData::WriteMBRData(void) { // Save the MBR data to a file. This writes both the // MBR itself and any defined logical partitions. int BasicMBRData::WriteMBRData(DiskIO *theDisk) { - int i, j, partNum, next, allOK = 1, moreLogicals = 0; + int i, j, partNum, next, allOK, moreLogicals = 0; uint64_t extFirstLBA = 0; uint64_t writeEbrTo; // 64-bit because we support extended in 2-4TiB range TempMBR tempMBR; @@ -948,7 +948,7 @@ int BasicMBRData::SpaceBeforeAllLogicals(void) { // primary status. Also does NOT consider partition order; there // can be gaps and it will still be considered legal. int BasicMBRData::IsLegal(void) { - int allOK = 1; + int allOK; allOK = (FindOverlaps() == 0); allOK = (allOK && (NumPrimaries() <= 4)); @@ -1055,7 +1055,7 @@ void BasicMBRData::MakePart(int num, uint64_t start, uint64_t length, int type, // Set the partition's type code. // Returns 1 if successful, 0 if not (invalid partition number) int BasicMBRData::SetPartType(int num, int type) { - int allOK = 1; + int allOK; if ((num >= 0) && (num < MAX_MBR_PARTS)) { if (partitions[num].GetLengthLBA() != UINT32_C(0)) { @@ -1308,7 +1308,7 @@ void BasicMBRData::MakeItLegal(void) { // entries (primary space). // Returns the number of partitions moved. int BasicMBRData::RemoveLogicalsFromFirstFour(void) { - int i, j = 4, numMoved = 0, swapped = 0; + int i, j, numMoved = 0, swapped = 0; MBRPart temp; for (i = 0; i < 4; i++) { diff --git a/bsd.cc b/bsd.cc index f487f18..1ef7c81 100644 --- a/bsd.cc +++ b/bsd.cc @@ -44,7 +44,7 @@ BSDData::~BSDData(void) { // just opens the device file and then calls an overloaded function to do // the bulk of the work. Returns 1 on success, 0 on failure. int BSDData::ReadBSDData(const string & device, uint64_t startSector, uint64_t endSector) { - int allOK = 1; + int allOK; DiskIO myDisk; if (device != "") { @@ -64,7 +64,7 @@ int BSDData::ReadBSDData(const string & device, uint64_t startSector, uint64_t e // Load the BSD disklabel data from an already-opened disk // file, starting with the specified sector number. int BSDData::ReadBSDData(DiskIO *theDisk, uint64_t startSector, uint64_t endSector) { - int allOK = 1; + int allOK; int i, foundSig = 0, bigEnd = 0; int relative = 0; // assume absolute partition sector numbering uint8_t buffer[4096]; // I/O buffer diff --git a/diskio-unix.cc b/diskio-unix.cc index 4aefc6f..7780aeb 100644 --- a/diskio-unix.cc +++ b/diskio-unix.cc @@ -376,7 +376,7 @@ int DiskIO::Read(void* buffer, int numBytes) { // size with the number of bytes read. // Returns the number of bytes written. int DiskIO::Write(void* buffer, int numBytes) { - int blockSize = 512, i, numBlocks, retval = 0; + int blockSize, i, numBlocks, retval = 0; char* tempSpace; // If disk isn't open, try to open it.... diff --git a/gpt.cc b/gpt.cc index 842dfb1..51d482c 100644 --- a/gpt.cc +++ b/gpt.cc @@ -582,7 +582,7 @@ int GPTData::CheckHeaderCRC(struct GPTHeader* header, int warn) { // byte order and then undoes that reversal.) void GPTData::RecomputeCRCs(void) { uint32_t crc, hSize; - int littleEndian = 1; + int littleEndian; // If the header size is bigger than the GPT header data structure, reset it; // otherwise, set both header sizes to whatever the main one is.... @@ -2144,7 +2144,6 @@ int GPTData::Align(uint64_t* sector) { // Check to see that every sector between the earlier one and the // requested one is clear, and that it's not too early.... if (earlier >= mainHeader.firstUsableLBA) { - sectorOK = 1; testSector = earlier; do { sectorOK = IsFree(testSector++); @@ -2157,7 +2156,6 @@ int GPTData::Align(uint64_t* sector) { // If couldn't move the sector earlier, try to move it later instead.... if ((sectorOK != 1) && (later <= mainHeader.lastUsableLBA)) { - sectorOK = 1; testSector = later; do { sectorOK = IsFree(testSector--); @@ -2454,7 +2452,7 @@ void GPTData::SetAlignment(uint32_t n) { // is used on big disks (as safety for Advanced Format drives). // Returns the computed alignment value. uint32_t GPTData::ComputeAlignment(void) { - uint32_t i = 0, found, exponent = 31; + uint32_t i = 0, found, exponent; uint32_t align = DEFAULT_ALIGNMENT; if (blockSize > 0) diff --git a/gptcurses.cc b/gptcurses.cc index 71aa734..1fbaad2 100644 --- a/gptcurses.cc +++ b/gptcurses.cc @@ -437,7 +437,6 @@ void GPTDataCurses::MakeNewPart(void) { move(LINES - 4, 0); clrtobot(); while ((newFirstLBA < currentSpace->firstLBA) || (newFirstLBA > currentSpace->lastLBA)) { - newFirstLBA = currentSpace->firstLBA; move(LINES - 4, 0); clrtoeol(); newFirstLBA = currentSpace->firstLBA; diff --git a/gpttext.cc b/gpttext.cc index ea34444..505f006 100644 --- a/gpttext.cc +++ b/gpttext.cc @@ -251,7 +251,7 @@ void GPTDataTextUI::CreatePartition(void) { } while (IsFree(sector) == 0); lastBlock = sector; - firstFreePart = GPTData::CreatePartition(partNum, firstBlock, lastBlock); + GPTData::CreatePartition(partNum, firstBlock, lastBlock); partitions[partNum].ChangeType(); partitions[partNum].SetDefaultDescription(); } else { diff --git a/support.cc b/support.cc index 88c130b..99fdffe 100644 --- a/support.cc +++ b/support.cc @@ -154,7 +154,7 @@ uint64_t GetSectorNum(uint64_t low, uint64_t high, uint64_t def, uint64_t sSize, // compiled with GCC (and so the value is rejected), whereas when VC++ // is used, the default value is returned. uint64_t IeeeToInt(string inValue, uint64_t sSize, uint64_t low, uint64_t high, uint64_t def) { - uint64_t response = def, bytesPerUnit = 1, mult = 1, divide = 1; + uint64_t response = def, bytesPerUnit, mult = 1, divide = 1; size_t foundAt = 0; char suffix = ' ', plusFlag = ' '; string suffixes = "KMGTPE"; -- Gitee From bc067e719733e0876f673685687eafaae16825db Mon Sep 17 00:00:00 2001 From: Rod Smith Date: Sun, 2 May 2021 17:57:37 -0400 Subject: [PATCH 19/38] Updated e-mail address for contributor Dwight Schauer --- README | 2 +- cgdisk.8 | 2 +- fixparts.8 | 2 +- gdisk.8 | 2 +- sgdisk.8 | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README b/README index e52dd2c..69775eb 100644 --- a/README +++ b/README @@ -270,7 +270,7 @@ Additional code contributors include: - Justin Maggard (justin.maggard@netgear.com) -- Dwight Schauer (dschauer@ti.com) +- Dwight Schauer (das@teegra.net) - Florian Zumbiehl (florz@florz.de) diff --git a/cgdisk.8 b/cgdisk.8 index af5821e..b50e169 100644 --- a/cgdisk.8 +++ b/cgdisk.8 @@ -369,7 +369,7 @@ Contributors: * Justin Maggard (justin.maggard@netgear.com) -* Dwight Schauer (dschauer@gmail.com) +* Dwight Schauer (das@teegra.net) * Florian Zumbiehl (florz@florz.de) diff --git a/fixparts.8 b/fixparts.8 index a81a878..f251f63 100644 --- a/fixparts.8 +++ b/fixparts.8 @@ -258,7 +258,7 @@ Contributors: * Justin Maggard (justin.maggard@netgear.com) -* Dwight Schauer (dschauer@gmail.com) +* Dwight Schauer (das@teegra.net) * Florian Zumbiehl (florz@florz.de) diff --git a/gdisk.8 b/gdisk.8 index 62f6bd2..85b69cb 100644 --- a/gdisk.8 +++ b/gdisk.8 @@ -673,7 +673,7 @@ Contributors: * Justin Maggard (justin.maggard@netgear.com) -* Dwight Schauer (dschauer@gmail.com) +* Dwight Schauer (das@teegra.net) * Florian Zumbiehl (florz@florz.de) diff --git a/sgdisk.8 b/sgdisk.8 index 59a3d3c..ec1243d 100644 --- a/sgdisk.8 +++ b/sgdisk.8 @@ -593,7 +593,7 @@ Contributors: * Justin Maggard (justin.maggard@netgear.com) -* Dwight Schauer (dschauer@gmail.com) +* Dwight Schauer (das@teegra.net) * Florian Zumbiehl (florz@florz.de) -- Gitee From 2a15a246a1d416b17f1b958cc3a9e3e21ee5b839 Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Tue, 8 Jun 2021 15:49:03 +0300 Subject: [PATCH 20/38] gptpart.cc: Minor fix to end comment of GPTPart::ReversePartBytes(void). The end comment was confusingly saying ReverseBytes instead of ReversePartBytes. --- gptpart.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gptpart.cc b/gptpart.cc index b268cf0..81bbcf0 100644 --- a/gptpart.cc +++ b/gptpart.cc @@ -422,7 +422,7 @@ void GPTPart::ReversePartBytes(void) { ReverseBytes(&attributes, 8); for (i = 0; i < NAME_SIZE; i ++ ) ReverseBytes(name + i, 2); -} // GPTPart::ReverseBytes() +} // GPTPart::ReversePartBytes() /**************************************** * Functions requiring user interaction * -- Gitee From fded770b55fdb3a201ad515d785c17ac35705652 Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Tue, 8 Jun 2021 16:11:21 +0300 Subject: [PATCH 21/38] gptpart.cc: Remove byteswap commands in GPTPart::SetName(const string&). The byteswapping done in GPTPart::SetName(const string&) was reversed later when GPTPart::ReversePartBytes() was called. The intended design seems to have been to keep the fields in native endianness until just before the partition is written to disk when all the GPTPart data is byteswapped all at once with a call to GPTPart::ReversePartBytes(). However this was defeated by leaving the original byteswaps in there and effectively the name was swapped back to the native-endian form. For big endian systems this meant that a UTF-16BE string was written to disk, violating the specification and causing interoperability problems. Fixed by removing these inline byteswaps in GPTPart::SetName(const string&). --- gptpart.cc | 3 --- 1 file changed, 3 deletions(-) diff --git a/gptpart.cc b/gptpart.cc index 81bbcf0..841140a 100644 --- a/gptpart.cc +++ b/gptpart.cc @@ -242,7 +242,6 @@ void GPTPart::SetName(const string & theName) { // then to utf16le if ( uni < 0x10000 ) { name[ pos ] = (uint16_t) uni ; - if ( ! IsLittleEndian() ) ReverseBytes( name + pos , 2 ) ; pos ++ ; } // if else { @@ -252,10 +251,8 @@ void GPTPart::SetName(const string & theName) { } // if uni -= 0x10000 ; name[ pos ] = (uint16_t)( uni >> 10 ) | 0xd800 ; - if ( ! IsLittleEndian() ) ReverseBytes( name + pos , 2 ) ; pos ++ ; name[ pos ] = (uint16_t)( uni & 0x3ff ) | 0xdc00 ; - if ( ! IsLittleEndian() ) ReverseBytes( name + pos , 2 ) ; pos ++ ; } } // for -- Gitee From 08be8933a9a55d4e919875bf4df4a3ed0a4b514e Mon Sep 17 00:00:00 2001 From: Rod Smith Date: Tue, 8 Jun 2021 09:38:07 -0400 Subject: [PATCH 22/38] Added info to NEWS about latest commits. --- NEWS | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/NEWS b/NEWS index 873338a..023e1d1 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,11 @@ +1.0.8 (?/??/2021): +------------------ + +- Fixed double byte swap operation on writes of partition label data on + big-endian systems; this is in addition to the double byte swap fix on + reading partition label data fixed in 1.0.7. (Thanks to Erik Larsson for + both fixes.) + 1.0.7 (3/10/2021): ------------------ -- Gitee From 331ad9c795e4db7d09e8141979f809e4f5815319 Mon Sep 17 00:00:00 2001 From: Rod Smith Date: Tue, 8 Jun 2021 15:23:02 -0400 Subject: [PATCH 23/38] Add ability to reverse byte order of partition names to gdisk and sgdisk --- NEWS | 11 ++++++++++- gdisk.8 | 8 ++++++++ gptcl.cc | 11 +++++++++++ gptpart.cc | 10 +++++++--- gptpart.h | 1 + gpttext.cc | 20 ++++++++++++++++++++ gpttext.h | 1 + sgdisk.8 | 8 ++++++++ 8 files changed, 66 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index 023e1d1..bd6696c 100644 --- a/NEWS +++ b/NEWS @@ -1,11 +1,20 @@ 1.0.8 (?/??/2021): ------------------ -- Fixed double byte swap operation on writes of partition label data on +- Fixed double byte swap operation on writes of partition name data on big-endian systems; this is in addition to the double byte swap fix on reading partition label data fixed in 1.0.7. (Thanks to Erik Larsson for both fixes.) +- Added feature to gdisk and sgdisk to enable swapping the byte order of + partition names, so as to correct disks already affected by the preceding + bug. This option is 'b' on the experts' menu in gdisk and + -b/--byte-swap-name in sgdisk. This seems advanced/obscure enough that I + don't want to clutter cgdisk's menu with this option, so I haven't added + it there. + +- Trivial code cleanup. + 1.0.7 (3/10/2021): ------------------ diff --git a/gdisk.8 b/gdisk.8 index 85b69cb..7f7a949 100644 --- a/gdisk.8 +++ b/gdisk.8 @@ -419,6 +419,14 @@ set features for each partition. \fBgdisk\fR supports four attributes: aren't translated into anything useful. In practice, most OSes seem to ignore these attributes. +.TP +.B b +Swap the byte order for the name of the specified partition. Some +partitioning tools, including GPT fdisk 1.0.7 and earlier, can write the +partition name in the wrong byte order on big-endian computers, such as the +IBM s390 mainframes and PowerPC-based Macs. This feature corrects this +problem. + .TP .B c Change partition GUID. You can enter a custom unique GUID for a partition diff --git a/gptcl.cc b/gptcl.cc index 2304091..65a99e9 100644 --- a/gptcl.cc +++ b/gptcl.cc @@ -64,6 +64,7 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) { GPTData secondDevice; int opt, numOptions = 0, saveData = 0, neverSaveData = 0; int partNum = 0, newPartNum = -1, saveNonGPT = 1, retval = 0, pretend = 0; + int byteSwapPartNum = 0; uint64_t low, high, startSector, endSector, sSize, mainTableLBA; uint64_t temp; // temporary variable; free to use in any case char *device; @@ -76,6 +77,7 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) { "list|[partnum:show|or|nand|xor|=|set|clear|toggle|get[:bitnum|hexbitmask]]"}, {"set-alignment", 'a', POPT_ARG_INT, &alignment, 'a', "set sector alignment", "value"}, {"backup", 'b', POPT_ARG_STRING, &backupFile, 'b', "backup GPT to file", "file"}, + {"byte-swap-name", 'B', POPT_ARG_INT, &byteSwapPartNum, 'B', "byte-swap partition's name", "partnum"}, {"change-name", 'c', POPT_ARG_STRING, &partName, 'c', "change partition's name", "partnum:name"}, {"recompute-chs", 'C', POPT_ARG_NONE, NULL, 'C', "recompute CHS values in protective/hybrid MBR", ""}, {"delete", 'd', POPT_ARG_INT, &deletePartNum, 'd', "delete a partition", "partnum"}, @@ -191,6 +193,15 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) { case 'a': SetAlignment(alignment); break; + case 'B': + if (IsUsedPartNum(byteSwapPartNum - 1)) { + partitions[byteSwapPartNum - 1].ReverseNameBytes(); + cout << "Changed partition " << byteSwapPartNum << "'s name to " + << partitions[byteSwapPartNum - 1].GetDescription() << "\n"; + JustLooking(0); + saveData = 1; + } + break; case 'b': SaveGPTBackup(backupFile); free(backupFile); diff --git a/gptpart.cc b/gptpart.cc index 841140a..b83254d 100644 --- a/gptpart.cc +++ b/gptpart.cc @@ -412,14 +412,18 @@ int GPTPart::DoTheyOverlap(const GPTPart & other) { // Reverse the bytes of integral data types and of the UTF-16LE name; // used on big-endian systems. void GPTPart::ReversePartBytes(void) { - int i; - ReverseBytes(&firstLBA, 8); ReverseBytes(&lastLBA, 8); ReverseBytes(&attributes, 8); + ReverseNameBytes(); +} // GPTPart::ReversePartBytes() + +void GPTPart::ReverseNameBytes(void) { + int i; + for (i = 0; i < NAME_SIZE; i ++ ) ReverseBytes(name + i, 2); -} // GPTPart::ReversePartBytes() +} // GPTPart::ReverseNameBytes() /**************************************** * Functions requiring user interaction * diff --git a/gptpart.h b/gptpart.h index fac514e..51bfb38 100644 --- a/gptpart.h +++ b/gptpart.h @@ -94,6 +94,7 @@ class GPTPart { void BlankPartition(void); // empty partition of data int DoTheyOverlap(const GPTPart & other); // returns 1 if there's overlap void ReversePartBytes(void); // reverse byte order of all integer fields + void ReverseNameBytes(void); // reverse byte order of partition's name field // Functions requiring user interaction void ChangeType(void); // Change the type code diff --git a/gpttext.cc b/gpttext.cc index 505f006..b1d9361 100644 --- a/gpttext.cc +++ b/gpttext.cc @@ -341,6 +341,22 @@ int GPTDataTextUI::SetName(uint32_t partNum) { return retval; } // GPTDataTextUI::SetName() +// Enable the user to byte-swap the name of the partition. Used to correct +// partition names damaged by incorrect byte order, as could be created by +// GPT fdisk 1.0.7 and earlier on big-endian systems, and perhaps other tools. +void GPTDataTextUI::ReverseName(uint32_t partNum) { + int swapBytes; + + cout << "Current name is: " << partitions[partNum].GetDescription() << "\n"; + partitions[partNum].ReverseNameBytes(); + cout << "Byte-swapped name is: " << partitions[partNum].GetDescription() << "\n"; + cout << "Do you want to byte-swap the name? "; + swapBytes = (GetYN() == 'Y'); + // Already swapped for display, so undo if necessary.... + if (!swapBytes) + partitions[partNum].ReverseNameBytes(); +} // GPTDataTextUI::ReverseName() + // Ask user for two partition numbers and swap them in the table. Note that // this just reorders table entries; it doesn't adjust partition layout on // the disk. @@ -799,6 +815,9 @@ void GPTDataTextUI::ExpertsMenu(string filename) { else cout << "No partitions\n"; break; + case 'b': case 'B': + ReverseName(GetPartNum()); + break; case 'c': case 'C': ChangeUniqueGuid(); break; @@ -896,6 +915,7 @@ void GPTDataTextUI::ExpertsMenu(string filename) { void GPTDataTextUI::ShowExpertCommands(void) { cout << "a\tset attributes\n"; + cout << "b\tbyte-swap a partition's name\n"; cout << "c\tchange partition GUID\n"; cout << "d\tdisplay the sector alignment value\n"; cout << "e\trelocate backup data structures to the end of the disk\n"; diff --git a/gpttext.h b/gpttext.h index afe4651..6bd22cf 100644 --- a/gpttext.h +++ b/gpttext.h @@ -49,6 +49,7 @@ class GPTDataTextUI : public GPTData { void ChangeUniqueGuid(void); void SetAttributes(uint32_t partNum); int SetName(uint32_t partNum); + void ReverseName(uint32_t partNum); int SwapPartitions(void); int DestroyGPTwPrompt(void); // Returns 1 if user proceeds void ShowDetails(void); diff --git a/sgdisk.8 b/sgdisk.8 index ec1243d..ca2eb21 100644 --- a/sgdisk.8 +++ b/sgdisk.8 @@ -182,6 +182,14 @@ backup will reflect your changes. If the GPT data structures are damaged, the backup may not accurately reflect the damaged state; instead, they will reflect GPT fdisk's first\-pass interpretation of the GPT. +.TP +.B \-B, \-\-byte\-swap\-name=partnum +Swap the byte order for the name of the specified partition. Some +partitioning tools, including GPT fdisk 1.0.7 and earlier, can write the +partition name in the wrong byte order on big-endian computers, such as the +IBM s390 mainframes and PowerPC-based Macs. This feature corrects this +problem. + .TP .B \-c, \-\-change\-name=partnum:name Change the GPT name of a partition. This name is encoded as a UTF\-16 -- Gitee From 64d07975feb14205b40628eb9a1a36e45987a2e4 Mon Sep 17 00:00:00 2001 From: Rod Smith Date: Wed, 9 Jun 2021 09:23:56 -0400 Subject: [PATCH 24/38] Expand some options in sgdisk man page. --- sgdisk.8 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sgdisk.8 b/sgdisk.8 index ca2eb21..a41c6df 100644 --- a/sgdisk.8 +++ b/sgdisk.8 @@ -347,7 +347,8 @@ sector. A start or end value of 0 specifies the default value, which is the start of the largest available block for the start sector and the end of the same block for the end sector. A partnum value of 0 causes the program to use the first available partition number. Subsequent uses of the -\fI\-A\fR, \fI\-c\fR, \fI\-t\fR, and \fI\-u\fR options may also use +\fI\-A\fR (\fI\-\-attributes\fR), \fI\-c\fR (\fI\-\-change\-name\fR), \fI\-t\fR +(\fI\-\-typecode\fR), and \fI\-u\fR (\fI\-\-partition\-guid\fR) options may also use \fI0\fR to refer to the same partition. .TP -- Gitee From 236f26bd6dc19968e69a4ccf8f1c7d1e048dc691 Mon Sep 17 00:00:00 2001 From: Rod Smith Date: Wed, 9 Jun 2021 09:57:33 -0400 Subject: [PATCH 25/38] Added type code for Barebox boot loader --- NEWS | 3 +++ parttypes.cc | 3 +++ 2 files changed, 6 insertions(+) diff --git a/NEWS b/NEWS index bd6696c..cdbfbe4 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,9 @@ don't want to clutter cgdisk's menu with this option, so I haven't added it there. +- Added type code for the Barebox boot loader (0xbb00; + 4778ED65-BF42-45FA-9C5B-287A1DC4AAB1). + - Trivial code cleanup. 1.0.7 (3/10/2021): diff --git a/parttypes.cc b/parttypes.cc index 838e4bc..a56f5ef 100644 --- a/parttypes.cc +++ b/parttypes.cc @@ -300,6 +300,9 @@ void PartType::AddAllTypes(void) { // QNX Power-Safe (QNX6) AddType(0xb300, "CEF5A9AD-73BC-4601-89F3-CDEEEEE321A1", "QNX6 Power-Safe"); + // Barebox boot loader; see https://barebox.org/doc/latest/user/state.html?highlight=guid#sd-emmc-and-ata + AddType(0xbb00, "4778ED65-BF42-45FA-9C5B-287A1DC4AAB1", "Barebox boot loader"); + // Acronis Secure Zone AddType(0xbc00, "0311FC50-01CA-4725-AD77-9ADBB20ACE98", "Acronis Secure Zone"); -- Gitee From 1ae2f1769fec6311810a0981669d33b9b20a45e6 Mon Sep 17 00:00:00 2001 From: Rod Smith Date: Wed, 9 Jun 2021 20:13:13 -0400 Subject: [PATCH 26/38] Version 1.0.8 release --- NEWS | 4 ++-- cgdisk.8 | 2 +- current.spec | 8 ++++---- fixparts.8 | 2 +- gdisk.8 | 2 +- sgdisk.8 | 2 +- support.h | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/NEWS b/NEWS index cdbfbe4..18f6f21 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,5 @@ -1.0.8 (?/??/2021): ------------------- +1.0.8 (6/9/2021): +----------------- - Fixed double byte swap operation on writes of partition name data on big-endian systems; this is in addition to the double byte swap fix on diff --git a/cgdisk.8 b/cgdisk.8 index b50e169..998b8f4 100644 --- a/cgdisk.8 +++ b/cgdisk.8 @@ -1,6 +1,6 @@ .\" Copyright 2011-2021 Roderick W. Smith (rodsmith@rodsbooks.com) .\" May be distributed under the GNU General Public License -.TH "CGDISK" "8" "1.0.7" "Roderick W. Smith" "GPT fdisk Manual" +.TH "CGDISK" "8" "1.0.8" "Roderick W. Smith" "GPT fdisk Manual" .SH "NAME" cgdisk \- Curses-based GUID partition table (GPT) manipulator .SH "SYNOPSIS" diff --git a/current.spec b/current.spec index ffdf002..bb963b1 100644 --- a/current.spec +++ b/current.spec @@ -1,12 +1,12 @@ Summary: GPT partitioning and MBR repair software Name: gptfdisk -Version: 1.0.7 +Version: 1.0.8 Release: 1%{?dist} License: GPLv2 URL: http://www.rodsbooks.com/gdisk Group: Applications/System -Source: http://www.rodsbooks.com/gdisk/gptfdisk-1.0.7.tar.gz +Source: http://www.rodsbooks.com/gdisk/gptfdisk-1.0.8.tar.gz BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) %description @@ -81,5 +81,5 @@ provides a few additional partition manipulation features. %changelog -* Wed Mar 10 2021 R Smith - 1.0.7 -- Created spec file for 1.0.7 release +* Wed Jun 9 2021 R Smith - 1.0.8 +- Created spec file for 1.0.8 release diff --git a/fixparts.8 b/fixparts.8 index f251f63..4002ea5 100644 --- a/fixparts.8 +++ b/fixparts.8 @@ -1,6 +1,6 @@ .\" Copyright 2011-2021 Roderick W. Smith (rodsmith@rodsbooks.com) .\" May be distributed under the GNU General Public License -.TH "FIXPARTS" "8" "1.0.7" "Roderick W. Smith" "FixParts Manual" +.TH "FIXPARTS" "8" "1.0.8" "Roderick W. Smith" "FixParts Manual" .SH "NAME" fixparts \- MBR partition table repair utility .SH "SYNOPSIS" diff --git a/gdisk.8 b/gdisk.8 index 7f7a949..50bc6c6 100644 --- a/gdisk.8 +++ b/gdisk.8 @@ -1,6 +1,6 @@ .\" Copyright 2011-2021 Roderick W. Smith (rodsmith@rodsbooks.com) .\" May be distributed under the GNU General Public License -.TH "GDISK" "8" "1.0.7" "Roderick W. Smith" "GPT fdisk Manual" +.TH "GDISK" "8" "1.0.8" "Roderick W. Smith" "GPT fdisk Manual" .SH "NAME" gdisk \- Interactive GUID partition table (GPT) manipulator .SH "SYNOPSIS" diff --git a/sgdisk.8 b/sgdisk.8 index a41c6df..c878348 100644 --- a/sgdisk.8 +++ b/sgdisk.8 @@ -1,6 +1,6 @@ .\" Copyright 2011-2021 Roderick W. Smith (rodsmith@rodsbooks.com) .\" May be distributed under the GNU General Public License -.TH "SGDISK" "8" "1.0.7" "Roderick W. Smith" "GPT fdisk Manual" +.TH "SGDISK" "8" "1.0.8" "Roderick W. Smith" "GPT fdisk Manual" .SH "NAME" sgdisk \- Command\-line GUID partition table (GPT) manipulator for Linux and Unix .SH "SYNOPSIS" diff --git a/support.h b/support.h index 0d68024..3648c4e 100644 --- a/support.h +++ b/support.h @@ -8,7 +8,7 @@ #include #include -#define GPTFDISK_VERSION "1.0.7" +#define GPTFDISK_VERSION "1.0.8" #if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined (__APPLE__) // Darwin (Mac OS) & FreeBSD: disk IOCTLs are different, and there is no lseek64 -- Gitee From 1e084b3ac2ec8b4b448c2290ed4fa88e4c4212c4 Mon Sep 17 00:00:00 2001 From: Rod Smith Date: Sat, 9 Oct 2021 15:52:16 -0400 Subject: [PATCH 27/38] Remove stray debugging code --- NEWS | 6 ++++++ gptcl.cc | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 18f6f21..4009a5b 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,9 @@ +1.0.9 (?/?/2021): +----------------- + +- Removed stray debugging code that caused "partNum is {x}" to be printed + when changing a partition's name with sgdisk (-c/--change-name). + 1.0.8 (6/9/2021): ----------------- diff --git a/gptcl.cc b/gptcl.cc index 65a99e9..ef7156e 100644 --- a/gptcl.cc +++ b/gptcl.cc @@ -212,7 +212,6 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) { partNum = (int) GetInt(partName, 1) - 1; if (partNum < 0) partNum = newPartNum; - cout << "partNum is " << partNum << "\n"; if ((partNum >= 0) && (partNum < (int) GetNumParts())) { name = GetString(partName, 2); if (SetName(partNum, (UnicodeString) name.c_str())) { -- Gitee From 43b3df969cbbf3da0c043afdc9939da97bbd8d68 Mon Sep 17 00:00:00 2001 From: Rod Smith Date: Sat, 9 Oct 2021 18:40:30 -0400 Subject: [PATCH 28/38] Removed another stray debugging message --- gptcl.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/gptcl.cc b/gptcl.cc index ef7156e..2e75db7 100644 --- a/gptcl.cc +++ b/gptcl.cc @@ -207,7 +207,6 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) { free(backupFile); break; case 'c': - cout << "Setting name!\n"; JustLooking(0); partNum = (int) GetInt(partName, 1) - 1; if (partNum < 0) -- Gitee From fd60f743628e16180daf3b1719974fa4dadf8f90 Mon Sep 17 00:00:00 2001 From: Rod Smith Date: Sat, 29 Jan 2022 10:51:02 -0500 Subject: [PATCH 29/38] Add end-alignment feature. --- NEWS | 10 +++++++++- cgdisk.8 | 9 +++++++-- gdisk.8 | 16 +++++++++++----- gpt.cc | 34 ++++++++++++++++++++++++++-------- gpt.h | 4 ++-- gptcl.cc | 15 ++++++++++----- gptcl.h | 3 ++- gptcurses.cc | 19 ++++++++++++++----- gpttext.cc | 36 +++++++++++++++++++++++++++++------- gpttext.h | 3 ++- sgdisk.8 | 19 +++++++++++++++++-- support.cc | 40 +++++++++------------------------------- support.h | 7 +++---- 13 files changed, 141 insertions(+), 74 deletions(-) diff --git a/NEWS b/NEWS index 4009a5b..201eff8 100644 --- a/NEWS +++ b/NEWS @@ -1,9 +1,17 @@ -1.0.9 (?/?/2021): +1.0.9 (?/?/2022): ----------------- - Removed stray debugging code that caused "partNum is {x}" to be printed when changing a partition's name with sgdisk (-c/--change-name). +- Added support for aligning partitions' end points, as well as their start + points. This support affects the default partition size when using 'n' in + gdisk; it affects the default partition size in cgdisk; and it's activated + by the new '-I' option in sgdisk. See the programs' respective man pages + for details. This feature is intended to help with LUKS2 encryption, which + reacts badly to partitions that are not sized as exact multiples of the + encryption block size. + 1.0.8 (6/9/2021): ----------------- diff --git a/cgdisk.8 b/cgdisk.8 index 998b8f4..0b51fc1 100644 --- a/cgdisk.8 +++ b/cgdisk.8 @@ -186,8 +186,13 @@ new disks, GPT fdisk attempts to align partitions on 1 MiB boundaries performance for all of these disk types. On pre\-partitioned disks, GPT fdisk attempts to identify the alignment value used on that disk, but will set 8-sector alignment on disks larger than 300 GB even if lesser alignment -values are detected. In either case, it can be changed by using this -option. +values are detected. In either case, it can be changed by using this option. +The alignment value also affects the default end sector value when creating +a new partition; it will be aligned to one less than a multiple of the +alignment value, when possible. This should keep partitions a multiple of +the alignment value in size. Some disk encryption tools require partitions +to be sized to some value, typically 4096 bytes, so the default alignment of +1 MiB works well for them. .TP .B Backup diff --git a/gdisk.8 b/gdisk.8 index 50bc6c6..75a3e82 100644 --- a/gdisk.8 +++ b/gdisk.8 @@ -210,7 +210,8 @@ default start sector, or \fI\fB\-200M\fR\fR to specify a point 200MiB before the last available sector. Pressing the Enter key with no input specifies the default value, which is the start of the largest available block for the start sector and the end of the same block for the end -sector. +sector. Default start and end points may be adjusted to optimize partition +alignment. .TP .B o @@ -491,13 +492,18 @@ Change the sector alignment value. Disks with more logical sectors per physical sectors (such as modern Advanced Format drives), some RAID configurations, and many SSD devices, can suffer performance problems if partitions are not aligned properly for their internal data structures. On -new disks, GPT fdisk attempts to align partitions on 1 MiB boundaries -(2048\-sectors on disks with 512-byte sectors) by default, which optimizes +new disks, GPT fdisk attempts to align partitions on 1 MiB boundaries (2048 +sectors on disks with 512-byte sectors) by default, which optimizes performance for all of these disk types. On pre\-partitioned disks, GPT fdisk attempts to identify the alignment value used on that disk, but will set 8-sector alignment on disks larger than 300 GB even if lesser alignment -values are detected. In either case, it can be changed by using this -option. +values are detected. In either case, it can be changed by using this option. +The alignment value also affects the default end sector value when creating +a new partition; it will be aligned to one less than a multiple of the +alignment value, if possible. This should keep partitions a multiple of the +alignment value in size. Some disk encryption tools require partitions to be +sized to some value, typically 4096 bytes, so the default alignment of 1 MiB +works well for them. .TP .B m diff --git a/gpt.cc b/gpt.cc index 51d482c..5ccc5c5 100644 --- a/gpt.cc +++ b/gpt.cc @@ -3,7 +3,7 @@ /* By Rod Smith, initial coding January to February, 2009 */ -/* This program is copyright (c) 2009-2018 by Roderick W. Smith. It is distributed +/* This program is copyright (c) 2009-2022 by Roderick W. Smith. It is distributed under the terms of the GNU GPL version 2, as detailed in the COPYING file. */ #define __STDC_LIMIT_MACROS @@ -410,6 +410,11 @@ int GPTData::Verify(void) { << "in degraded performance on some modern (2009 and later) hard disks.\n"; alignProbs++; } // if + if ((partitions[i].IsUsed()) && ((partitions[i].GetLastLBA() + 1) % testAlignment) != 0) { + cout << "\nCaution: Partition " << i + 1 << " doesn't end on a " + << testAlignment << "-sector boundary. This may\nresult " + << "in problems with some disk encryption tools.\n"; + } // if } // for if (alignProbs > 0) cout << "\nConsult http://www.ibm.com/developerworks/linux/library/l-4kb-sector-disks/\n" @@ -2334,18 +2339,28 @@ uint64_t GPTData::FindLastAvailable(void) { } // GPTData::FindLastAvailable() // Find the last available block in the free space pointed to by start. -uint64_t GPTData::FindLastInFree(uint64_t start) { - uint64_t nearestStart; +// If align == true, returns the last sector that's aligned on the +// system alignment value (unless that's less than the start value); +// if align == false, returns the last available block regardless of +// alignment. (The align variable is set to false by default.) +uint64_t GPTData::FindLastInFree(uint64_t start, bool align) { + uint64_t nearestEnd, endPlus; uint32_t i; - nearestStart = mainHeader.lastUsableLBA; + nearestEnd = mainHeader.lastUsableLBA; for (i = 0; i < numParts; i++) { - if ((nearestStart > partitions[i].GetFirstLBA()) && + if ((nearestEnd > partitions[i].GetFirstLBA()) && (partitions[i].GetFirstLBA() > start)) { - nearestStart = partitions[i].GetFirstLBA() - 1; + nearestEnd = partitions[i].GetFirstLBA() - 1; } // if } // for - return (nearestStart); + if (align) { + endPlus = nearestEnd + 1; + if (Align(&endPlus) && IsFree(endPlus - 1) && (endPlus > start)) { + nearestEnd = endPlus - 1; + } // if + } // if + return (nearestEnd); } // GPTData::FindLastInFree() // Finds the total number of free blocks, the number of segments in which @@ -2422,7 +2437,10 @@ int GPTData::IsUsedPartNum(uint32_t partNum) { ***********************************************************/ // Set partition alignment value; partitions will begin on multiples of -// the specified value +// the specified value, and the default end values will be set so that +// partition sizes are multiples of this value in cgdisk and gdisk, too. +// (In sgdisk, end-alignment is done only if the '-I' command-line option +// is used.) void GPTData::SetAlignment(uint32_t n) { if (n > 0) { sectorAlignment = n; diff --git a/gpt.h b/gpt.h index 9ba013b..cf05f59 100644 --- a/gpt.h +++ b/gpt.h @@ -1,7 +1,7 @@ /* gpt.h -- GPT and data structure definitions, types, and functions */ -/* This program is copyright (c) 2009-2011 by Roderick W. Smith. It is distributed +/* This program is copyright (c) 2009-2022 by Roderick W. Smith. It is distributed under the terms of the GNU GPL version 2, as detailed in the COPYING file. */ #ifndef __GPTSTRUCTS @@ -185,7 +185,7 @@ public: uint64_t FindFirstUsedLBA(void); uint64_t FindFirstInLargest(void); uint64_t FindLastAvailable(); - uint64_t FindLastInFree(uint64_t start); + uint64_t FindLastInFree(uint64_t start, bool align = false); uint64_t FindFreeBlocks(uint32_t *numSegments, uint64_t *largestSegment); int IsFree(uint64_t sector, uint32_t *partNum = NULL); int IsFreePartNum(uint32_t partNum); diff --git a/gptcl.cc b/gptcl.cc index 2e75db7..3995093 100644 --- a/gptcl.cc +++ b/gptcl.cc @@ -1,7 +1,7 @@ /* Implementation of GPTData class derivative with popt-based command line processing - Copyright (C) 2010-2014 Roderick W. Smith + Copyright (C) 2010-2022 Roderick W. Smith This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -30,6 +30,7 @@ GPTDataCL::GPTDataCL(void) { attributeOperation = backupFile = partName = hybrids = newPartInfo = NULL; mbrParts = twoParts = outDevice = typeCode = partGUID = diskGUID = NULL; alignment = DEFAULT_ALIGNMENT; + alignEnd = false; deletePartNum = infoPartNum = largestPartNum = bsdPartNum = 0; tableSize = GPT_SIZE; } // GPTDataCL constructor @@ -90,6 +91,7 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) { {"randomize-guids", 'G', POPT_ARG_NONE, NULL, 'G', "randomize disk and partition GUIDs", ""}, {"hybrid", 'h', POPT_ARG_STRING, &hybrids, 'h', "create hybrid MBR", "partnum[:partnum...][:EE]"}, {"info", 'i', POPT_ARG_INT, &infoPartNum, 'i', "show detailed information on partition", "partnum"}, + {"align-end", 'I', POPT_ARG_NONE, NULL, 'I', "align partition end points", ""}, {"move-main-table", 'j', POPT_ARG_INT, &mainTableLBA, 'j', "adjust the location of the main partition table", "sector"}, {"load-backup", 'l', POPT_ARG_STRING, &backupFile, 'l', "load GPT backup from file", "file"}, {"list-types", 'L', POPT_ARG_NONE, NULL, 'L', "list known partition types", ""}, @@ -272,6 +274,9 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) { case 'i': ShowPartDetails(infoPartNum - 1); break; + case 'I': + alignEnd = true; + break; case 'j': if (MoveMainTable(mainTableLBA)) { JustLooking(0); @@ -307,9 +312,9 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) { newPartNum = FindFirstFreePart(); low = FindFirstInLargest(); Align(&low); - high = FindLastInFree(low); - startSector = IeeeToInt(GetString(newPartInfo, 2), sSize, low, high, low); - endSector = IeeeToInt(GetString(newPartInfo, 3), sSize, startSector, high, high); + high = FindLastInFree(low, alignEnd); + startSector = IeeeToInt(GetString(newPartInfo, 2), sSize, low, high, sectorAlignment, low); + endSector = IeeeToInt(GetString(newPartInfo, 3), sSize, startSector, high, sectorAlignment, high); if (CreatePartition(newPartNum, startSector, endSector)) { saveData = 1; } else { @@ -323,7 +328,7 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) { JustLooking(0); startSector = FindFirstInLargest(); Align(&startSector); - endSector = FindLastInFree(startSector); + endSector = FindLastInFree(startSector, alignEnd); if (largestPartNum <= 0) largestPartNum = FindFirstFreePart() + 1; if (CreatePartition(largestPartNum - 1, startSector, endSector)) { diff --git a/gptcl.h b/gptcl.h index 610ca5f..183b846 100644 --- a/gptcl.h +++ b/gptcl.h @@ -1,7 +1,7 @@ /* Implementation of GPTData class derivative with popt-based command line processing - Copyright (C) 2010-2013 Roderick W. Smith + Copyright (C) 2010-2022 Roderick W. Smith This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -34,6 +34,7 @@ class GPTDataCL : public GPTData { char *newPartInfo, *mbrParts, *twoParts, *outDevice, *typeCode; char *partGUID, *diskGUID; int alignment, deletePartNum, infoPartNum, largestPartNum, bsdPartNum; + bool alignEnd; uint32_t tableSize; poptContext poptCon; diff --git a/gptcurses.cc b/gptcurses.cc index 1fbaad2..2ffcf4f 100644 --- a/gptcurses.cc +++ b/gptcurses.cc @@ -1,7 +1,7 @@ /* * Implementation of GPTData class derivative with curses-based text-mode * interaction - * Copyright (C) 2011-2018 Roderick W. Smith + * Copyright (C) 2011-2022 Roderick W. Smith * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -430,12 +430,18 @@ void GPTDataCurses::Verify(void) { // Create a new partition in the space pointed to by currentSpace. void GPTDataCurses::MakeNewPart(void) { - uint64_t size, newFirstLBA = 0, newLastLBA = 0; + uint64_t size, newFirstLBA = 0, newLastLBA = 0, lastAligned; int partNum; char inLine[80]; move(LINES - 4, 0); clrtobot(); + lastAligned = currentSpace->lastLBA + 1; + Align(&lastAligned); + lastAligned--; + // Discard end-alignment attempt if it's giving us an invalid end point.... + if (!IsFree(lastAligned)) + lastAligned = currentSpace->lastLBA; while ((newFirstLBA < currentSpace->firstLBA) || (newFirstLBA > currentSpace->lastLBA)) { move(LINES - 4, 0); clrtoeol(); @@ -445,10 +451,13 @@ void GPTDataCurses::MakeNewPart(void) { echo(); getnstr(inLine, 79); noecho(); - newFirstLBA = IeeeToInt(inLine, blockSize, currentSpace->firstLBA, currentSpace->lastLBA, newFirstLBA); + newFirstLBA = IeeeToInt(inLine, blockSize, currentSpace->firstLBA, currentSpace->lastLBA, sectorAlignment, newFirstLBA); Align(&newFirstLBA); } // while - size = currentSpace->lastLBA - newFirstLBA + 1; + if (newFirstLBA > lastAligned) + size = currentSpace->lastLBA - newFirstLBA + 1; + else + size = lastAligned - newFirstLBA + 1; while ((newLastLBA > currentSpace->lastLBA) || (newLastLBA < newFirstLBA)) { move(LINES - 3, 0); clrtoeol(); @@ -456,7 +465,7 @@ void GPTDataCurses::MakeNewPart(void) { echo(); getnstr(inLine, 79); noecho(); - newLastLBA = newFirstLBA + IeeeToInt(inLine, blockSize, 1, size, size) - 1; + newLastLBA = newFirstLBA + IeeeToInt(inLine, blockSize, 1, size, sectorAlignment, size) - 1; } // while partNum = FindFirstFreePart(); if (CreatePartition(partNum, newFirstLBA, newLastLBA)) { // created OK; set type code & name.... diff --git a/gpttext.cc b/gpttext.cc index b1d9361..170a169 100644 --- a/gpttext.cc +++ b/gpttext.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2010-2018 + Copyright (C) 2010-2022 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -199,7 +199,7 @@ void GPTDataTextUI::MoveMainTable(void) { // Interactively create a partition void GPTDataTextUI::CreatePartition(void) { - uint64_t firstBlock, firstInLargest, lastBlock, sector, origSector; + uint64_t firstBlock, firstInLargest, lastBlock, sector, origSector, lastAligned; uint32_t firstFreePart = 0; ostringstream prompt1, prompt2, prompt3; int partNum; @@ -229,7 +229,7 @@ void GPTDataTextUI::CreatePartition(void) { prompt2 << "First sector (" << firstBlock << "-" << lastBlock << ", default = " << firstInLargest << ") or {+-}size{KMGTP}: "; do { - sector = GetSectorNum(firstBlock, lastBlock, firstInLargest, blockSize, prompt2.str()); + sector = GetSectorNum(firstBlock, lastBlock, firstInLargest, prompt2.str()); } while (IsFree(sector) == 0); origSector = sector; if (Align(§or)) { @@ -239,15 +239,15 @@ void GPTDataTextUI::CreatePartition(void) { if (!beQuiet) cout << "Use 'l' on the experts' menu to adjust alignment\n"; } // if - // Align(§or); // Align sector to correct multiple firstBlock = sector; // Get last block for new partitions... - lastBlock = FindLastInFree(firstBlock); + lastBlock = FindLastInFree(firstBlock, false); + lastAligned = FindLastInFree(firstBlock, true); prompt3 << "Last sector (" << firstBlock << "-" << lastBlock << ", default = " - << lastBlock << ") or {+-}size{KMGTP}: "; + << lastAligned << ") or {+-}size{KMGTP}: "; do { - sector = GetSectorNum(firstBlock, lastBlock, lastBlock, blockSize, prompt3.str()); + sector = GetSectorNum(firstBlock, lastBlock, lastAligned, prompt3.str()); } while (IsFree(sector) == 0); lastBlock = sector; @@ -548,6 +548,28 @@ int GPTDataTextUI::XFormToMBR(void) { return protectiveMBR.DoMenu(); } // GPTDataTextUI::XFormToMBR() +// Obtains a sector number, between low and high, from the +// user, accepting values prefixed by "+" to add sectors to low, +// or the same with "K", "M", "G", "T", or "P" as suffixes to add +// kibibytes, mebibytes, gibibytes, tebibytes, or pebibytes, +// respectively. If a "-" prefix is used, use the high value minus +// the user-specified number of sectors (or KiB, MiB, etc.). Use the +// def value as the default if the user just hits Enter. +uint64_t GPTDataTextUI::GetSectorNum(uint64_t low, uint64_t high, uint64_t def, + const string & prompt) { + uint64_t response; + char line[255]; + + do { + cout << prompt; + cin.getline(line, 255); + if (!cin.good()) + exit(5); + response = IeeeToInt(line, blockSize, low, high, sectorAlignment, def); + } while ((response < low) || (response > high)); + return response; +} // GPTDataTextUI::GetSectorNum() + /****************************************************** * * * Display informational messages for the user.... * diff --git a/gpttext.h b/gpttext.h index 6bd22cf..36a17f9 100644 --- a/gpttext.h +++ b/gpttext.h @@ -1,6 +1,6 @@ /* Implementation of GPTData class derivative with basic text-mode interaction - Copyright (C) 2010-2018 Roderick W. Smith + Copyright (C) 2010-2022 Roderick W. Smith This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -55,6 +55,7 @@ class GPTDataTextUI : public GPTData { void ShowDetails(void); void MakeHybrid(void); int XFormToMBR(void); // convert GPT to MBR, wiping GPT afterwards. Returns 1 if successful + uint64_t GetSectorNum(uint64_t low, uint64_t high, uint64_t def, const string & prompt); // An informational function.... void WarnAboutIffyMBRPart(int partNum); diff --git a/sgdisk.8 b/sgdisk.8 index c878348..23fc943 100644 --- a/sgdisk.8 +++ b/sgdisk.8 @@ -154,7 +154,10 @@ to sectors that are multiples of this value, which defaults to 1 MiB (2048 on disks with 512-byte sectors) on freshly formatted disks. This alignment value is necessary to obtain optimum performance with Western Digital Advanced Format and similar drives with larger physical than logical sector -sizes, with some types of RAID arrays, and with SSD devices. +sizes, with some types of RAID arrays, and with SSD devices. When the +\fI\-I\fR option is used, this same alignment value is used to determine +partition end points; but partitions end at one less than a multiple of this +value, to keep the partition length a multiple of this value. .TP .B \-A, \-\-attributes=list|[partnum:show|or|nand|xor|=|set|clear|toggle|get[:bitnum|hexbitmask]] @@ -280,7 +283,7 @@ is usually correct for Windows partitions. If the active/bootable flag should be set, you must do so in another program, such as \fBfdisk\fR. The \fBgdisk\fR program offers additional hybrid MBR creation options. -.TP +.TP .B \-i, \-\-info=partnum Show detailed partition information. The summary information produced by the \fI\-p\fR command necessarily omits many details, such as the partition's @@ -288,6 +291,18 @@ unique GUID and the translation of \fBsgdisk\fR's internal partition type code to a plain type name. The \fI\-i\fR option displays this information for a single partition. +.TP +.B \-I, \-\-align\-end +When possible, align the end points of partitions to one less than a +multiple of the alignment value. When both start and end points are aligned, +partitions should be multiples of the alignment value in size, which is +necessary for some partition encryption tools to function correctly. This +option applies to all partitions created \fBafter\fR this option on the +command line. Note that this alignment is not always possible; for instance, +if the free space at the end of a disk is less than the alignment value, +with the current final partition being aligned, and if \fBsgdisk\fR is asked +to create a partition in that space, then it will \fBnot\fR be end\-aligned. + .TP .B \-j, \-\-adjust\-main\-table=sector Adjust the location of the main partition table. This value is normally 2, diff --git a/support.cc b/support.cc index 99fdffe..0d3bd6f 100644 --- a/support.cc +++ b/support.cc @@ -3,7 +3,7 @@ // Primarily by Rod Smith, February 2009, but with a few functions // copied from other sources (see attributions below). -/* This program is copyright (c) 2009-2018 by Roderick W. Smith. It is distributed +/* This program is copyright (c) 2009-2022 by Roderick W. Smith. It is distributed under the terms of the GNU GPL version 2, as detailed in the COPYING file. */ #define __STDC_LIMIT_MACROS @@ -113,34 +113,11 @@ char GetYN(void) { return response; } // GetYN(void) -// Obtains a sector number, between low and high, from the -// user, accepting values prefixed by "+" to add sectors to low, -// or the same with "K", "M", "G", "T", or "P" as suffixes to add -// kilobytes, megabytes, gigabytes, terabytes, or petabytes, -// respectively. If a "-" prefix is used, use the high value minus -// the user-specified number of sectors (or KiB, MiB, etc.). Use the -// def value as the default if the user just hits Enter. The sSize is -// the sector size of the device. -uint64_t GetSectorNum(uint64_t low, uint64_t high, uint64_t def, uint64_t sSize, - const string & prompt) { - uint64_t response; - char line[255]; - - do { - cout << prompt; - cin.getline(line, 255); - if (!cin.good()) - exit(5); - response = IeeeToInt(line, sSize, low, high, def); - } while ((response < low) || (response > high)); - return response; -} // GetSectorNum() - // Convert an IEEE-1541-2002 value (K, M, G, T, P, or E) to its equivalent in // number of sectors. If no units are appended, interprets as the number // of sectors; otherwise, interprets as number of specified units and // converts to sectors. For instance, with 512-byte sectors, "1K" converts -// to 2. If value includes a "+", adds low and subtracts 1; if SIValue +// to 2. If value includes a "+", adds low and subtracts 1; if inValue // inclues a "-", subtracts from high. If IeeeValue is empty, returns def. // Returns final sector value. In case inValue is invalid, returns 0 (a // sector value that's always in use on GPT and therefore invalid); and if @@ -153,7 +130,7 @@ uint64_t GetSectorNum(uint64_t low, uint64_t high, uint64_t def, uint64_t sSize, // 0 values. The result is that IeeeToInt() returns UINT64_MAX when // compiled with GCC (and so the value is rejected), whereas when VC++ // is used, the default value is returned. -uint64_t IeeeToInt(string inValue, uint64_t sSize, uint64_t low, uint64_t high, uint64_t def) { +uint64_t IeeeToInt(string inValue, uint64_t sSize, uint64_t low, uint64_t high, uint32_t sectorAlignment, uint64_t def) { uint64_t response = def, bytesPerUnit, mult = 1, divide = 1; size_t foundAt = 0; char suffix = ' ', plusFlag = ' '; @@ -208,11 +185,12 @@ uint64_t IeeeToInt(string inValue, uint64_t sSize, uint64_t low, uint64_t high, } // if/elseif if (plusFlag == '+') { - // Recompute response based on low part of range (if default == high - // value, which should be the case when prompting for the end of a - // range) or the defaut value (if default != high, which should be - // the case for the first sector of a partition). - if (def == high) { + // Recompute response based on low part of range (if default is within + // sectorAlignment sectors of high, which should be the case when + // prompting for the end of a range) or the defaut value (if default is + // further away from the high value, which should be the case for the + // first sector of a partition). + if ((high - def) < sectorAlignment) { if (response > 0) response--; if (response > (UINT64_MAX - low)) diff --git a/support.h b/support.h index 3648c4e..a61ddf4 100644 --- a/support.h +++ b/support.h @@ -1,4 +1,4 @@ -/* This program is copyright (c) 2009-2018 by Roderick W. Smith. It is distributed +/* This program is copyright (c) 2009-2022 by Roderick W. Smith. It is distributed under the terms of the GNU GPL version 2, as detailed in the COPYING file. */ #ifndef __GPTSUPPORT @@ -8,7 +8,7 @@ #include #include -#define GPTFDISK_VERSION "1.0.8" +#define GPTFDISK_VERSION "1.0.8.2" #if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined (__APPLE__) // Darwin (Mac OS) & FreeBSD: disk IOCTLs are different, and there is no lseek64 @@ -74,8 +74,7 @@ using namespace std; string ReadString(void); uint64_t GetNumber(uint64_t low, uint64_t high, uint64_t def, const string & prompt); char GetYN(void); -uint64_t GetSectorNum(uint64_t low, uint64_t high, uint64_t def, uint64_t sSize, const std::string& prompt); -uint64_t IeeeToInt(string IeeeValue, uint64_t sSize, uint64_t low, uint64_t high, uint64_t def = 0); +uint64_t IeeeToInt(string IeeeValue, uint64_t sSize, uint64_t low, uint64_t high, uint32_t sectorAlignment, uint64_t def = 0); string BytesToIeee(uint64_t size, uint32_t sectorSize); unsigned char StrToHex(const string & input, unsigned int position); int IsHex(string input); // Returns 1 if input can be hexadecimal number.... -- Gitee From edc67b66dbd09bf9a905bb5f1eddd1c19c2df294 Mon Sep 17 00:00:00 2001 From: Rod Smith Date: Sun, 10 Apr 2022 09:28:08 -0400 Subject: [PATCH 30/38] Patch set from Bin Meng to clean up some code & support building sgdisk for Windows --- Makefile | 17 +++--- Makefile.freebsd | 22 ++++---- Makefile.mac | 22 +++----- Makefile.mingw | 29 +++++----- Makefile.mingw64 | 28 +++++----- README.Windows | 135 +++++++++++++++++++++++++++++++++-------------- attributes.h | 10 ++-- basicmbr.h | 12 ++--- bsd.h | 5 +- crc32.cc | 2 +- diskio.h | 16 +++--- gdisk.cc | 2 + gpt.h | 20 ++++--- gptcl.cc | 4 +- gptcl.h | 10 ++-- gptcurses.cc | 4 +- gptcurses.h | 10 ++-- gptpart.cc | 11 ++-- gptpart.h | 6 +-- gpttext.h | 12 ++--- guid.h | 12 ++--- mbr.h | 4 +- mbrpart.h | 2 - parttypes.h | 16 +++--- support.h | 18 +++---- 25 files changed, 225 insertions(+), 204 deletions(-) diff --git a/Makefile b/Makefile index 0d7309c..7ecab54 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ -CFLAGS+=-D_FILE_OFFSET_BITS=64 -#CXXFLAGS+=-Wall -D_FILE_OFFSET_BITS=64 -D USE_UTF16 -CXXFLAGS+=-Wall -D_FILE_OFFSET_BITS=64 +#CXXFLAGS+=-O2 -Wall -D_FILE_OFFSET_BITS=64 -D USE_UTF16 +CXXFLAGS+=-O2 -Wall -D_FILE_OFFSET_BITS=64 LDFLAGS+= +LDLIBS+=-luuid #-licuio -licuuc LIB_NAMES=crc32 support guid gptpart mbrpart basicmbr mbr gpt bsd parttypes attributes diskio diskio-unix MBR_LIBS=support diskio diskio-unix basicmbr mbrpart LIB_OBJS=$(LIB_NAMES:=.o) @@ -12,19 +12,16 @@ DEPEND= makedepend $(CXXFLAGS) all: cgdisk gdisk sgdisk fixparts gdisk: $(LIB_OBJS) gdisk.o gpttext.o - $(CXX) $(LIB_OBJS) gdisk.o gpttext.o $(LDFLAGS) -luuid $(LDLIBS) -o gdisk -# $(CXX) $(LIB_OBJS) gdisk.o gpttext.o $(LDFLAGS) -licuio -licuuc -luuid -o gdisk + $(CXX) $(LIB_OBJS) gdisk.o gpttext.o $(LDFLAGS) $(LDLIBS) -o gdisk cgdisk: $(LIB_OBJS) cgdisk.o gptcurses.o - $(CXX) $(LIB_OBJS) cgdisk.o gptcurses.o $(LDFLAGS) -luuid -lncursesw $(LDLIBS) -o cgdisk -# $(CXX) $(LIB_OBJS) cgdisk.o gptcurses.o $(LDFLAGS) -licuio -licuuc -luuid -lncurses -o cgdisk + $(CXX) $(LIB_OBJS) cgdisk.o gptcurses.o $(LDFLAGS) $(LDLIBS) -lncursesw -o cgdisk sgdisk: $(LIB_OBJS) sgdisk.o gptcl.o - $(CXX) $(LIB_OBJS) sgdisk.o gptcl.o $(LDFLAGS) -luuid -lpopt $(LDLIBS) -o sgdisk -# $(CXX) $(LIB_OBJS) sgdisk.o gptcl.o $(LDFLAGS) -licuio -licuuc -luuid -lpopt -o sgdisk + $(CXX) $(LIB_OBJS) sgdisk.o gptcl.o $(LDFLAGS) $(LDLIBS) -lpopt -o sgdisk fixparts: $(MBR_LIB_OBJS) fixparts.o - $(CXX) $(MBR_LIB_OBJS) fixparts.o $(LDFLAGS) $(LDLIBS) -o fixparts + $(CXX) $(MBR_LIB_OBJS) fixparts.o $(LDFLAGS) -o fixparts test: ./gdisk_test.sh diff --git a/Makefile.freebsd b/Makefile.freebsd index 4b4b616..7223f2d 100644 --- a/Makefile.freebsd +++ b/Makefile.freebsd @@ -1,9 +1,8 @@ -CC=clang CXX=clang++ -CFLAGS+=-D_FILE_OFFSET_BITS=64 -#CXXFLAGS+=-Wall -D_FILE_OFFSET_BITS=64 -D USE_UTF16 -I/usr/local/include -CXXFLAGS+=-Wall -D_FILE_OFFSET_BITS=64 -I /usr/local/include -LDFLAGS+= +#CXXFLAGS+=-O2 -Wall -D_FILE_OFFSET_BITS=64 -D USE_UTF16 -I/usr/local/include +CXXFLAGS+=-O2 -Wall -D_FILE_OFFSET_BITS=64 -I /usr/local/include +LDFLAGS+=-L/usr/local/lib +LDLIBS+=-luuid #-licuio LIB_NAMES=crc32 support guid gptpart mbrpart basicmbr mbr gpt bsd parttypes attributes diskio diskio-unix MBR_LIBS=support diskio diskio-unix basicmbr mbrpart LIB_OBJS=$(LIB_NAMES:=.o) @@ -14,25 +13,22 @@ DEPEND= makedepend $(CXXFLAGS) all: gdisk cgdisk sgdisk fixparts gdisk: $(LIB_OBJS) gdisk.o gpttext.o -# $(CXX) $(LIB_OBJS) gdisk.o gpttext.o -L/usr/local/lib $(LDFLAGS) -licuio -luuid -o gdisk - $(CXX) $(LIB_OBJS) gdisk.o gpttext.o -L/usr/local/lib $(LDFLAGS) -luuid -o gdisk + $(CXX) $(LIB_OBJS) gdisk.o gpttext.o $(LDFLAGS) $(LDLIBS) -o gdisk cgdisk: $(LIB_OBJS) cgdisk.o gptcurses.o -# $(CXX) $(LIB_OBJS) cgdisk.o gptcurses.o -L/usr/local/lib $(LDFLAGS) -licuio -luuid -lncurses -o cgdisk - $(CXX) $(LIB_OBJS) cgdisk.o gptcurses.o -L/usr/local/lib $(LDFLAGS) -luuid -lncurses -o cgdisk + $(CXX) $(LIB_OBJS) cgdisk.o gptcurses.o $(LDFLAGS) $(LDLIBS) -lncurses -o cgdisk sgdisk: $(LIB_OBJS) sgdisk.o gptcl.o -# $(CXX) $(LIB_OBJS) sgdisk.o gptcl.o -L/usr/local/lib $(LDFLAGS) -luuid -licuio -lpopt -o sgdisk - $(CXX) $(LIB_OBJS) sgdisk.o gptcl.o -L/usr/local/lib $(LDFLAGS) -luuid -lpopt -o sgdisk + $(CXX) $(LIB_OBJS) sgdisk.o gptcl.o $(LDFLAGS) $(LDLIBS) -lpopt -o sgdisk fixparts: $(MBR_LIB_OBJS) fixparts.o - $(CXX) $(MBR_LIB_OBJS) fixparts.o -L/usr/local/lib $(LDFLAGS) -o fixparts + $(CXX) $(MBR_LIB_OBJS) fixparts.o $(LDFLAGS) -o fixparts lint: #no pre-reqs lint $(SRCS) clean: #no pre-reqs - rm -f core *.o *~ gdisk sgdisk + rm -f core *.o *~ gdisk cgdisk sgdisk fixparts # what are the source dependencies depend: $(SRCS) diff --git a/Makefile.mac b/Makefile.mac index ea21fa6..91a281c 100644 --- a/Makefile.mac +++ b/Makefile.mac @@ -1,11 +1,11 @@ -CC=gcc CXX=c++ # FATBINFLAGS=-arch x86_64 -arch i386 -mmacosx-version-min=10.9 FATBINFLAGS=-arch x86_64 -arch arm64 -mmacosx-version-min=10.9 THINBINFLAGS=-arch x86_64 -mmacosx-version-min=10.9 -CFLAGS=$(FATBINFLAGS) -O2 -D_FILE_OFFSET_BITS=64 -g -#CXXFLAGS=-O2 -Wall -D_FILE_OFFSET_BITS=64 -D USE_UTF16 -I/opt/local/include -I/usr/local/include -I/opt/local/include -g -CXXFLAGS=$(FATBINFLAGS) -O2 -Wall -D_FILE_OFFSET_BITS=64 -stdlib=libc++ -I/opt/local/include -I /usr/local/include -I/opt/local/include -g +#CXXFLAGS=-O2 -Wall -D_FILE_OFFSET_BITS=64 -D USE_UTF16 -I/opt/local/include -I/usr/local/include -I/opt/local/include +CXXFLAGS=$(FATBINFLAGS) -O2 -Wall -D_FILE_OFFSET_BITS=64 -stdlib=libc++ -I/opt/local/include -I /usr/local/include -I/opt/local/include +LDFLAGS+= +LDLIBS+= #-licucore LIB_NAMES=crc32 support guid gptpart mbrpart basicmbr mbr gpt bsd parttypes attributes diskio diskio-unix MBR_LIBS=support diskio diskio-unix basicmbr mbrpart #LIB_SRCS=$(NAMES:=.cc) @@ -17,25 +17,17 @@ DEPEND= makedepend $(CFLAGS) all: gdisk sgdisk cgdisk fixparts gdisk: $(LIB_OBJS) gpttext.o gdisk.o - $(CXX) $(LIB_OBJS) gpttext.o gdisk.o $(FATBINFLAGS) -o gdisk -# $(CXX) $(LIB_OBJS) -L/usr/lib -licucore gpttext.o gdisk.o -o gdisk + $(CXX) $(LIB_OBJS) gpttext.o gdisk.o $(FATBINFLAGS) $(LDFLAGS) $(LDLIBS) -o gdisk cgdisk: $(LIB_OBJS) cgdisk.o gptcurses.o - $(CXX) $(LIB_OBJS) cgdisk.o gptcurses.o /usr/local/Cellar/ncurses/6.2/lib/libncurses.dylib $(LDFLAGS) -o cgdisk -# $(CXX) $(LIB_OBJS) cgdisk.o gptcurses.o /usr/lib/libncurses.dylib $(LDFLAGS) -o cgdisk -# $(CXX) $(LIB_OBJS) cgdisk.o gptcurses.o $(LDFLAGS) -licucore -lncurses -o cgdisk + $(CXX) $(LIB_OBJS) cgdisk.o gptcurses.o $(LDFLAGS) $(LDLIBS) /usr/local/Cellar/ncurses/6.2/lib/libncurses.dylib -o cgdisk sgdisk: $(LIB_OBJS) gptcl.o sgdisk.o -# $(CXX) $(LIB_OBJS) gptcl.o sgdisk.o /opt/local/lib/libiconv.a /opt/local/lib/libintl.a /opt/local/lib/libpopt.a $(FATBINFLAGS) -o sgdisk - $(CXX) $(LIB_OBJS) gptcl.o sgdisk.o -L/usr/local/lib -lpopt $(THINBINFLAGS) -o sgdisk -# $(CXX) $(LIB_OBJS) gptcl.o sgdisk.o -L/sw/lib -licucore -lpopt -o sgdisk + $(CXX) $(LIB_OBJS) gptcl.o sgdisk.o $(LDFLAGS) -L/usr/local/lib $(LDLIBS) -lpopt $(THINBINFLAGS) -o sgdisk fixparts: $(MBR_LIB_OBJS) fixparts.o $(CXX) $(MBR_LIB_OBJS) fixparts.o $(LDFLAGS) $(FATBINFLAGS) -o fixparts -testguid: $(LIB_OBJS) testguid.o - $(CXX) $(LIB_OBJS) testguid.o -o testguid - lint: #no pre-reqs lint $(SRCS) diff --git a/Makefile.mingw b/Makefile.mingw index acfff64..2ed228a 100644 --- a/Makefile.mingw +++ b/Makefile.mingw @@ -1,9 +1,9 @@ -CC=/usr/bin/i686-w64-mingw32-gcc -CXX=/usr/bin/i686-w64-mingw32-g++ -STRIP=/usr/bin/i686-w64-mingw32-strip -CFLAGS=-O2 -Wall -static -static-libgcc -static-libstdc++ -D_FILE_OFFSET_BITS=64 -g -CXXFLAGS=-O2 -Wall -static -static-libgcc -static-libstdc++ -D_FILE_OFFSET_BITS=64 -g -#CXXFLAGS=-O2 -Wall -D_FILE_OFFSET_BITS=64 -I /usr/local/include -I/opt/local/include -g +CXX=i686-w64-mingw32-g++ +STRIP=i686-w64-mingw32-strip +CXXFLAGS=-O2 -Wall -D_FILE_OFFSET_BITS=64 -static -static-libgcc -static-libstdc++ +#CXXFLAGS=-O2 -Wall -D_FILE_OFFSET_BITS=64 -I /usr/local/include -I/opt/local/include +LDFLAGS+=-static -static-libgcc -static-libstdc++ +LDLIBS+=-lrpcrt4 LIB_NAMES=guid gptpart bsd parttypes attributes crc32 mbrpart basicmbr mbr gpt support diskio diskio-windows MBR_LIBS=support diskio diskio-windows basicmbr mbrpart LIB_SRCS=$(NAMES:=.cc) @@ -12,25 +12,28 @@ MBR_LIB_OBJS=$(MBR_LIBS:=.o) LIB_HEADERS=$(LIB_NAMES:=.h) DEPEND= makedepend $(CFLAGS) -all: gdisk fixparts +all: gdisk sgdisk fixparts gdisk: $(LIB_OBJS) gdisk.o gpttext.o - $(CXX) $(CXXFLAGS) $(LIB_OBJS) gdisk.o gpttext.o -lrpcrt4 -static-libgcc -o gdisk32.exe + $(CXX) $(LIB_OBJS) gdisk.o gpttext.o $(LDFLAGS) $(LDLIBS) -o gdisk32.exe -sgdisk: $(LIB_OBJS) sgdisk.o - $(CXX) $(CXXFLAGS) $(LIB_OBJS) sgdisk.o -lpopt -static-libgcc -o sgdisk32.exe +cgdisk: $(LIB_OBJS) cgdisk.o gptcurses.o + $(CXX) $(LIB_OBJS) cgdisk.o gptcurses.o $(LDFLAGS) $(LDLIBS) -lncursesw -o cgdisk32.exe + +sgdisk: $(LIB_OBJS) sgdisk.o gptcl.o + $(CXX) $(LIB_OBJS) sgdisk.o gptcl.o $(LDFLAGS) $(LDLIBS) -lpopt -lintl -liconv -o sgdisk32.exe fixparts: $(MBR_LIB_OBJS) fixparts.o - $(CXX) $(CXXFLAGS) $(MBR_LIB_OBJS) fixparts.o $(LDFLAGS) -static-libgcc -o fixparts32.exe + $(CXX) $(MBR_LIB_OBJS) fixparts.o $(LDFLAGS) -o fixparts32.exe lint: #no pre-reqs lint $(SRCS) clean: #no pre-reqs - rm -f core *.o *~ gdisk.exe sgdisk.exe + rm -f core *.o *~ gdisk32.exe cgdisk32.exe sgdisk32.exe fixparts32.exe strip: #no pre-reqs - $(STRIP) gdisk32.exe fixparts32.exe + $(STRIP) gdisk32.exe cgdisk32.exe sgdisk32.exe fixparts32.exe # what are the source dependencies depend: $(SRCS) diff --git a/Makefile.mingw64 b/Makefile.mingw64 index 7e4b32b..3070a42 100644 --- a/Makefile.mingw64 +++ b/Makefile.mingw64 @@ -1,9 +1,9 @@ -CC=/usr/bin/x86_64-w64-mingw32-gcc -CXX=/usr/bin/x86_64-w64-mingw32-g++ -STRIP=/usr/bin/x86_64-w64-mingw32-strip -CFLAGS=-O2 -Wall -static -static-libgcc -static-libstdc++ -D_FILE_OFFSET_BITS=64 -g -CXXFLAGS=-O2 -Wall -static -static-libgcc -static-libstdc++ -D_FILE_OFFSET_BITS=64 -g +CXX=x86_64-w64-mingw32-g++ +STRIP=x86_64-w64-mingw32-strip +CXXFLAGS=-O2 -Wall -D_FILE_OFFSET_BITS=64 -g #CXXFLAGS=-O2 -Wall -D_FILE_OFFSET_BITS=64 -I /usr/local/include -I/opt/local/include -g +LDFLAGS+=-static -static-libgcc -static-libstdc++ +LDLIBS+=-lrpcrt4 LIB_NAMES=guid gptpart bsd parttypes attributes crc32 mbrpart basicmbr mbr gpt support diskio diskio-windows MBR_LIBS=support diskio diskio-windows basicmbr mbrpart LIB_SRCS=$(NAMES:=.cc) @@ -12,25 +12,29 @@ MBR_LIB_OBJS=$(MBR_LIBS:=.o) LIB_HEADERS=$(LIB_NAMES:=.h) DEPEND= makedepend $(CFLAGS) -all: gdisk fixparts +# Note: cgdisk is buildable in Windows, but not in Ubuntu 20.04 or 22.04 +all: gdisk sgdisk fixparts gdisk: $(LIB_OBJS) gdisk.o gpttext.o - $(CXX) $(CXXFLAGS) $(LIB_OBJS) gdisk.o gpttext.o -lrpcrt4 -static-libgcc -o gdisk64.exe + $(CXX) $(LIB_OBJS) gdisk.o gpttext.o $(LDFLAGS) $(LDLIBS) -o gdisk64.exe -sgdisk: $(LIB_OBJS) sgdisk.o - $(CXX) $(CXXFLAGS) $(LIB_OBJS) sgdisk.o -lpopt -static-libgcc -o sgdisk64.exe +cgdisk: $(LIB_OBJS) cgdisk.o gptcurses.o + $(CXX) $(LIB_OBJS) cgdisk.o gptcurses.o $(LDFLAGS) $(LDLIBS) -lncursesw -o cgdisk64.exe + +sgdisk: $(LIB_OBJS) sgdisk.o gptcl.o + $(CXX) $(LIB_OBJS) sgdisk.o gptcl.o $(LDFLAGS) $(LDLIBS) -lpopt -lintl -liconv -o sgdisk64.exe fixparts: $(MBR_LIB_OBJS) fixparts.o - $(CXX) $(CXXFLAGS) $(MBR_LIB_OBJS) fixparts.o $(LDFLAGS) -static-libgcc -o fixparts64.exe + $(CXX) $(MBR_LIB_OBJS) fixparts.o $(LDFLAGS) -o fixparts64.exe lint: #no pre-reqs lint $(SRCS) clean: #no pre-reqs - rm -f core *.o *~ gdisk64.exe sgdisk64.exe + rm -f core *.o *~ gdisk64.exe cgdisk64.exe sgdisk64.exe fixparts64.exe strip: #no pre-reqs - $(STRIP) gdisk64.exe fixparts64.exe + $(STRIP) gdisk64.exe cgdisk64.exe sgdisk64.exe fixparts64.exe # what are the source dependencies depend: $(SRCS) diff --git a/README.Windows b/README.Windows index 3f49023..275b56d 100644 --- a/README.Windows +++ b/README.Windows @@ -28,12 +28,8 @@ Windows Use Notes The Windows version of GPT fdisk was added with version 0.6.2 of the package. The Windows binary package includes the gdisk.exe interactive -text-mode program file but no equivalent to the sgdisk program that's -available with Linux, FreeBSD, and OS X builds. In theory, an sgdisk.exe -for Windows could be built if the popt library were installed. I've not -attempted to do this myself, though. If you care to try, check -http://gnuwin32.sourceforge.net/packages/popt.htm for information on popt -for Windows. +text-mode program file as well as the sgdisk program that's available +with Linux, FreeBSD, and OS X builds. Beginning with version 0.8.10, I'm distributing both 32-bit and 64-bit binaries, which include the strings "32" or "64" in their names. The 32-bit @@ -47,10 +43,11 @@ certain partition table problems that can be created by buggy partitioning software. Windows seems to be unfazed by most such problems, but I've not done an extensive survey of Windows partitioning tools on this score. -To install the programs, copy the gdisk32.exe and fixparts32.exe (or -gdisk64.exe and fixparts64.exe) program files to any directory on your -path, such as C:\Windows. Alternatively, you can change to the program's -directory or type its complete path whenever you use it. +To install the programs, copy the gdisk32.exe, cgdisk32.exe, sgdisk32.exe +and fixparts32.exe (or gdisk64.exe, cgdisk64.exe, sgdisk64.exe and +fixparts64.exe) program files to any directory on your path, such as +C:\Windows. Alternatively, you can change to the program's directory or type +its complete path whenever you use it. To use the programs, first launch a Command Prompt as the Administrator. To do this, locate the Command Prompt program icon, right-click it, and select @@ -74,17 +71,18 @@ This command is equivalent to the earlier one -- it edits the partition table on the first physical disk. Change the number at the end of the device name to change the disk edited. -If you pass the "-l" option to gdisk.exe in addition to the disk -identifier, the program displays the current partition table information -and then exits. This use entails no risk to MBR disks, since the program -never writes data back to the disk when used in this way. +If you pass the "-l" option to gdisk64.exe in addition to the disk +identifier, the program displays the current partition table information and +then exits. (Alternatively, you can pass "-p" to sgdisk64.exe.) This use +entails no risk to MBR disks, since the program never writes data back to +the disk when used in this way. -As noted above, editing the first disk with GPT fdisk is usually a Bad -Idea. An exception would be if your system uses an Extensible Firmware -Interface (EFI) and already boots from a GPT disk. It's safer to edit -non-boot disks, which usually have numbers of 1 and above, but only if you -run a version of Windows with GPT support. For more information on Windows' -support of GPT, see Microsoft's Web page on the topic: +As noted above, editing the first disk with GPT fdisk is a Bad Idea on older +BIOS-based computers. Newer computers typically use an Extensible Firmware +Interface (EFI) and boot from GPT disks. It's safer to edit non-boot disks, +which usually have numbers of 1 and above, but only if you run a version of +Windows with GPT support. For more information on Windows' support of GPT, +see Microsoft's Web page on the topic: http://www.microsoft.com/whdc/device/storage/GPT_FAQ.mspx @@ -103,34 +101,91 @@ Source Code and Compilation Issues I have successfully compiled GPT fdisk using three different Windows compilers: -- MinGW (http://www.mingw.org), and in particular its Linux-hosted - cross-compiler -- Under Ubuntu Linux, the Makefile.mingw and - Makefile.mingw64 files enable compilation of the software via MinGW. - (Type "make -f Makefile.mingw" to compile 32-bit binaries, and "make -f - Makefile.mingw64" to compile 64-bit binaries.) If you try to compile - using another compiler or even using MinGW under Windows or another Linux - variety, you may need to adjust the Makefile.mingw options. +- MinGW (https://www.mingw-w64.org/), using either a Linux-hosted + cross-compiler or under Windows using the original MinGW or MSYS2 + (https://www.msys2.org). This is my only GPT fdisk development environment + for Windows in 2022. - Microsoft Visual C++ 2008 Express (http://www.microsoft.com/express/Windows/) -- This compiler requires a third-party stdint.h file (I used the one from - http://msinttypes.googlecode.com/svn/trunk/stdint.h), but it otherwise - works fine. A project is easily created by adding all the *.h files and - all the *.cc files except diskio-unix.cc, sgdisk.cc, and whichever - program file you intend to NOT build (gdisk.cc or fixparts.cc). + http://web.archive.org/web/20130317001712/http://msinttypes.googlecode.com/svn/trunk/stdint.h), + but it otherwise worked fine the last time I tried it. A project is easily + created by adding all the *.h files and all the *.cc files except + diskio-unix.cc, sgdisk.cc, and whichever program file you intend to NOT + build (gdisk.cc or fixparts.cc). - Microsoft Visual C++ 2010 Express -- This compiler works much like the 2008 version, although I didn't need to add a third-party stdint.h file. -The MinGW compiler produces much larger executables than do the MS -compilers. The resulting binaries seem to work equally well, but my testing -has been minimal. - -I've also attempted to compile the code with OpenWatcom 1.8, but this -attempt failed, mostly because the compiler can't yet handle iostream -output on standard C++ strings. OpenWatcom also seems to have incorrectly -set the value of UINT32_MAX as if uint32_t values were 64-bit integers. -This alone won't cause the compile to fail, but it would create bugs. +Although I used Microsoft Visual C++ in the past, I haven't tried using +these compilers recently and so I can't promise they would work today (in +2022). If you modify GPT fdisk to get it to compile under another compiler, I welcome submission of patches. + +The following instructions focus on use of MinGW to compile GPT fdisk for +Windows. + +My primary development environment is Ubuntu Linux, using the MinGW +cross-compiler. This system can compile the gdisk and fixparts binaries with +no need for additional libraries; after installing MinGW (via the +g++-mingw-w64 package in Ubuntu, or the equivalent in another distribution), +you can type "make -f Makefile.mingw" to compile 32-bit binaries, and "make +-f Makefile.mingw64" to compile 64-bit binaries. + +If you use Windows, your best bet is likely to be to install the MSYS2 +package (https://www.msys2.org). This package provides MinGW and a package +management system based on pacman (used by Arch Linux) for installing +additional libraries. To install the libraries needed to compile sgdisk and +cgdisk, type "pacman -S mingw-w64-x86_64-popt mingw-w64-x86_64-gettext +mingw-w64-x86_64-ncurses" if you want to compile 64-bit binaries; change +'x86_64' to 'i686' for 32-bit packages. This command will install the popt +library needed by sgdisk and the ncurses library needed by cgdisk, along +with gettext, which is needed by popt. With these libraries installed, you +should be able to compile all four Linux programs -- gdisk, cgdisk, sgdisk, +and fixparts. + +If you want to compile sgdisk for Windows under Linux, you can do so; +however, you must copy the relevant header and library files from a Windows +installation to Linux. Specifically, you must copy: + + Windows File Linux Directory + ------------ --------------- + /mingw64/include/popt.h /usr/x86_64-w64-mingw32/include/ + /mingw64/lib/libpopt.a /usr/x86_64-w64-mingw32/lib/ + /mingw64/lib/libintl.a /usr/x86_64-w64-mingw32/lib/ + /mingw64/lib/libiconv.a /usr/x86_64-w64-mingw32/lib/ + +For 32-bit binaries, change /mingw64 to /mingw32 on the Windows source and +x86_64-w64-mingw32 to i686-w64-mingw32 on the Linux destination. + +In theory, you should be able to do something similar to compile cgdisk. The +relevant files are: + + Windows File Linux Directory + ------------ --------------- + /mingw64/include/ncursesw/curses.h /usr/x86_64-w64-mingw32/include/ncursesw/ + /mingw64/include/ncursesw/ncurses.h /usr/x86_64-w64-mingw32/include/ncursesw/ + /mingw64/include/ncursesw/ncurses_dll.h /usr/x86_64-w64-mingw32/include/ncursesw/ + /mingw64/include/ncursesw/unctrl.h /usr/x86_64-w64-mingw32/include/ncursesw/ + /mingw64/lib/libncurses.a /usr/x86_64-w64-mingw32/lib/ + +In practice, this has not worked for me; the compilation fails with a +complaint about an undefined reference to 'nanosleep'. My guess is that the +ncurses version installed in Windows is too new to work with the MinGW +libraries in Ubuntu (20.04 or 22.04). It's conceivable it would work with +another distribution, though. + +In any event, the Makefile.mingw and Makefile.mingw64 files contain targets +for all four programs; however, because of the problem building cgdisk in +Linux, that program is omitted from the "all" target. It can still be built +explicitly, though, as in: + +make -f Makefile.mingw64 cgdisk + +The Makefiles are configured to create statically-linked binaries so as to +simplify installation of the binaries. If you want smaller binaries, you can +remove the various static options from the relevant Makefile. You can also +strip the binaries ("make -f Makefile.mingw64 strip") to remove unused code. diff --git a/attributes.h b/attributes.h index 6a61b8c..5eb57e3 100644 --- a/attributes.h +++ b/attributes.h @@ -10,11 +10,9 @@ #define NUM_ATR 64 /* # of attributes -- 64, since it's a 64-bit field */ #define ATR_NAME_SIZE 25 /* maximum size of attribute names */ -using namespace std; - class Attributes { protected: - static string atNames[NUM_ATR]; + static std::string atNames[NUM_ATR]; static int numAttrs; void Setup(void); uint64_t attributes; @@ -30,12 +28,12 @@ public: void ShowAttributes(const uint32_t partNum); void ChangeAttributes(void); - bool OperateOnAttributes(const uint32_t partNum, const string& attributeOperator, const string& attributeBits); + bool OperateOnAttributes(const uint32_t partNum, const std::string& attributeOperator, const std::string& attributeBits); - static const string& GetAttributeName(const uint32_t bitNum) {return atNames [bitNum];} + static const std::string& GetAttributeName(const uint32_t bitNum) {return atNames [bitNum];} static void ListAttributes(void); }; // class Attributes -ostream & operator<<(ostream & os, const Attributes & data); +std::ostream & operator<<(std::ostream & os, const Attributes & data); #endif diff --git a/basicmbr.h b/basicmbr.h index f4b0e45..696f826 100644 --- a/basicmbr.h +++ b/basicmbr.h @@ -16,8 +16,6 @@ // Maximum number of MBR partitions #define MAX_MBR_PARTS 128 -using namespace std; - /**************************************** * * * MBRData class and related structures * @@ -57,23 +55,23 @@ protected: uint32_t numSecspTrack; // number of sectors per track, in CHS scheme DiskIO* myDisk; int canDeleteMyDisk; - string device; + std::string device; MBRValidity state; MBRPart* GetPartition(int i); // Return primary or logical partition public: BasicMBRData(void); - BasicMBRData(string deviceFilename); + BasicMBRData(std::string deviceFilename); BasicMBRData(const BasicMBRData &); ~BasicMBRData(void); BasicMBRData & operator=(const BasicMBRData & orig); // File I/O functions... - int ReadMBRData(const string & deviceFilename); + int ReadMBRData(const std::string & deviceFilename); int ReadMBRData(DiskIO * theDisk, int checkBlockSize = 1); int ReadLogicalParts(uint64_t extendedStart, int partNum); int WriteMBRData(void); int WriteMBRData(DiskIO *theDisk); - int WriteMBRData(const string & deviceFilename); + int WriteMBRData(const std::string & deviceFilename); int WriteMBRData(struct TempMBR & mbr, DiskIO *theDisk, uint64_t sector); void DiskSync(void) {myDisk->DiskSync();} void SetDisk(DiskIO *theDisk); @@ -147,7 +145,7 @@ public: uint64_t GetLength(int i); // User interaction functions.... - int DoMenu(const string& prompt = "\nMBR command (? for help): "); + int DoMenu(const std::string& prompt = "\nMBR command (? for help): "); void ShowCommands(void); }; // class BasicMBRData diff --git a/bsd.h b/bsd.h index c4b74a4..e042b7b 100644 --- a/bsd.h +++ b/bsd.h @@ -30,9 +30,6 @@ // memory errors will occur. #define MAX_BSD_PARTS 64 - -using namespace std; - /**************************************** * * * BSDData class and related structures * @@ -75,7 +72,7 @@ class BSDData { public: BSDData(void); ~BSDData(void); - int ReadBSDData(const string & deviceFilename, uint64_t startSector, uint64_t endSector); + int ReadBSDData(const std::string & deviceFilename, uint64_t startSector, uint64_t endSector); int ReadBSDData(DiskIO *myDisk, uint64_t startSector, uint64_t endSector); void ReverseMetaBytes(void); void DisplayBSDData(void); diff --git a/crc32.cc b/crc32.cc index d253dd9..5eca100 100644 --- a/crc32.cc +++ b/crc32.cc @@ -31,7 +31,7 @@ uint32_t crc_tab[256]; */ uint32_t chksum_crc32 (unsigned char *block, unsigned int length) { - register unsigned long crc; + unsigned long crc; unsigned long i; crc = 0xFFFFFFFF; diff --git a/diskio.h b/diskio.h index 0bdaba4..b5c2ecc 100644 --- a/diskio.h +++ b/diskio.h @@ -37,8 +37,6 @@ #include "support.h" //#include "parttypes.h" -using namespace std; - /*************************************** * * * DiskIO class and related structures * @@ -47,9 +45,9 @@ using namespace std; class DiskIO { protected: - string userFilename; - string realFilename; - string modelName; + std::string userFilename; + std::string realFilename; + std::string modelName; int isOpen; int openForWrite; #ifdef _WIN32 @@ -62,9 +60,9 @@ class DiskIO { ~DiskIO(void); void MakeRealName(void); - int OpenForRead(const string & filename); + int OpenForRead(const std::string & filename); int OpenForRead(void); - int OpenForWrite(const string & filename); + int OpenForWrite(const std::string & filename); int OpenForWrite(void); void Close(); int Seek(uint64_t sector); @@ -73,12 +71,12 @@ class DiskIO { int DiskSync(void); // resync disk caches to use new partitions int GetBlockSize(void); int GetPhysBlockSize(void); - string GetModel(void) {return modelName;} + std::string GetModel(void) {return modelName;} uint32_t GetNumHeads(void); uint32_t GetNumSecsPerTrack(void); int IsOpen(void) {return isOpen;} int IsOpenForWrite(void) {return openForWrite;} - string GetName(void) const {return realFilename;} + std::string GetName(void) const {return realFilename;} uint64_t DiskSize(int* err); }; // class DiskIO diff --git a/gdisk.cc b/gdisk.cc index 5f85498..c9443bd 100644 --- a/gdisk.cc +++ b/gdisk.cc @@ -11,6 +11,8 @@ #include #include "gpttext.h" +using namespace std; + int main(int argc, char* argv[]) { GPTDataTextUI theGPT; string device = ""; diff --git a/gpt.h b/gpt.h index cf05f59..5d19372 100644 --- a/gpt.h +++ b/gpt.h @@ -24,8 +24,6 @@ // smallest Advanced Format drive I know of is 320GB in size #define SMALLEST_ADVANCED_FORMAT UINT64_C(585937500) -using namespace std; - /**************************************** * * * GPTData class and related structures * @@ -67,7 +65,7 @@ protected: uint32_t numParts; // # of partitions the table can hold struct GPTHeader secondHeader; MBRData protectiveMBR; - string device; // device filename + std::string device; // device filename DiskIO myDisk; uint32_t blockSize; // device logical block size uint32_t physBlockSize; // device physical block size (or 0 if it can't be determined) @@ -93,7 +91,7 @@ public: // Basic necessary functions.... GPTData(void); GPTData(const GPTData &); - GPTData(string deviceFilename); + GPTData(std::string deviceFilename); virtual ~GPTData(void); GPTData & operator=(const GPTData & orig); @@ -111,18 +109,18 @@ public: int FindInsanePartitions(void); // Load or save data from/to disk - int SetDisk(const string & deviceFilename); + int SetDisk(const std::string & deviceFilename); DiskIO* GetDisk(void) {return &myDisk;} - int LoadMBR(const string & f) {return protectiveMBR.ReadMBRData(f);} + int LoadMBR(const std::string & f) {return protectiveMBR.ReadMBRData(f);} int WriteProtectiveMBR(void) {return protectiveMBR.WriteMBRData(&myDisk);} void PartitionScan(void); - int LoadPartitions(const string & deviceFilename); + int LoadPartitions(const std::string & deviceFilename); int ForceLoadGPTData(void); int LoadMainTable(void); int LoadSecondTableAsMain(void); int SaveGPTData(int quiet = 0); - int SaveGPTBackup(const string & filename); - int LoadGPTBackup(const string & filename); + int SaveGPTBackup(const std::string & filename); + int LoadGPTBackup(const std::string & filename); int SaveMBR(void); int DestroyGPT(void); int DestroyMBR(void); @@ -204,9 +202,9 @@ public: void ReversePartitionBytes(); // for endianness // Attributes functions - int ManageAttributes(int partNum, const string & command, const string & bits); + int ManageAttributes(int partNum, const std::string & command, const std::string & bits); void ShowAttributes(const uint32_t partNum); - void GetAttribute(const uint32_t partNum, const string& attributeBits); + void GetAttribute(const uint32_t partNum, const std::string& attributeBits); }; // class GPTData diff --git a/gptcl.cc b/gptcl.cc index 3995093..34c9421 100644 --- a/gptcl.cc +++ b/gptcl.cc @@ -26,6 +26,8 @@ #include #include "gptcl.h" +using namespace std; + GPTDataCL::GPTDataCL(void) { attributeOperation = backupFile = partName = hybrids = newPartInfo = NULL; mbrParts = twoParts = outDevice = typeCode = partGUID = diskGUID = NULL; @@ -504,7 +506,7 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) { // Create a hybrid or regular MBR from GPT data structures int GPTDataCL::BuildMBR(char* argument, int isHybrid) { int numParts, allOK = 1, i, origPartNum; - int eeLast, mbrNum = 0; + int eeLast = 0, mbrNum = 0; MBRPart newPart; BasicMBRData newMBR; diff --git a/gptcl.h b/gptcl.h index 183b846..57d3f5d 100644 --- a/gptcl.h +++ b/gptcl.h @@ -25,8 +25,6 @@ #include "gpt.h" #include -using namespace std; - class GPTDataCL : public GPTData { protected: // Following are variables associated with popt parameters.... @@ -41,14 +39,14 @@ class GPTDataCL : public GPTData { int BuildMBR(char* argument, int isHybrid); public: GPTDataCL(void); - GPTDataCL(string filename); + GPTDataCL(std::string filename); ~GPTDataCL(void); - void LoadBackupFile(string backupFile, int &saveData, int &neverSaveData); + void LoadBackupFile(std::string backupFile, int &saveData, int &neverSaveData); int DoOptions(int argc, char* argv[]); }; // class GPTDataCL int CountColons(char* argument); -uint64_t GetInt(const string & argument, int itemNum); -string GetString(string argument, int itemNum); +uint64_t GetInt(const std::string & argument, int itemNum); +std::string GetString(std::string argument, int itemNum); #endif diff --git a/gptcurses.cc b/gptcurses.cc index 2ffcf4f..08b4257 100644 --- a/gptcurses.cc +++ b/gptcurses.cc @@ -90,7 +90,7 @@ void GPTDataCurses::EmptySpaces(void) { // unpartitioned space on the disk. // Returns the number of Spaces created. int GPTDataCurses::MakeSpacesFromParts(void) { - uint i; + uint32_t i; Space *tempSpace; EmptySpaces(); @@ -608,7 +608,7 @@ void GPTDataCurses::MoveSelection(int delta) { // Show user's options. Refers to currentSpace to determine which options to show. // Highlights the option with the key selectedKey; or a default if that's invalid. void GPTDataCurses::DisplayOptions(char selectedKey) { - uint i, j = 0, firstLine, numPerLine; + uint64_t i, j = 0, firstLine, numPerLine; string optionName, optionDesc = ""; if (currentSpace != NULL) { diff --git a/gptcurses.h b/gptcurses.h index a080987..8d2ecaf 100644 --- a/gptcurses.h +++ b/gptcurses.h @@ -27,12 +27,10 @@ #include "gptpart.h" #include "gpt.h" -using namespace std; - struct MenuItem { int key; // Keyboard shortcut - string name; // Item name; 8 characters - string desc; // Description + std::string name; // Item name; 8 characters + std::string desc; // Description }; static struct MenuItem menuMain[] = { @@ -81,7 +79,7 @@ protected: Space *lastSpace; Space *currentSpace; int currentSpaceNum; - string whichOptions; + std::string whichOptions; char currentKey; int numSpaces; int displayType; @@ -130,7 +128,7 @@ public: void ClearLine(int lineNum); void ClearBottom(void); void PromptToContinue(void); -void Report(string theText); +void Report(std::string theText); void ShowTypes(void); #endif diff --git a/gptpart.cc b/gptpart.cc index b83254d..5fe7b5a 100644 --- a/gptpart.cc +++ b/gptpart.cc @@ -15,17 +15,16 @@ #define __STDC_LIMIT_MACROS #define __STDC_CONSTANT_MACROS -#ifdef USE_UTF16 -#include -#else -#define UnicodeString string -#endif - #include #include #include #include "gptpart.h" #include "attributes.h" +#ifdef USE_UTF16 +#include +#else +#define UnicodeString std::string +#endif using namespace std; diff --git a/gptpart.h b/gptpart.h index 51bfb38..ede8139 100644 --- a/gptpart.h +++ b/gptpart.h @@ -23,8 +23,6 @@ #include "guid.h" #include "attributes.h" -using namespace std; - // Values returned by GPTPart::IsSizedForMBR() #define MBR_SIZED_GOOD 0 /* Whole partition under 2^32 sectors */ #define MBR_SIZED_IFFY 1 /* Partition starts under 2^32 & is less than 2^32, but ends over 2^32 */ @@ -59,7 +57,7 @@ class GPTPart { // Simple data retrieval: PartType & GetType(void) {return partitionType;} uint16_t GetHexType(void) const; - string GetTypeName(void); + std::string GetTypeName(void); UnicodeString GetUTypeName(void); const GUIDData GetUniqueGUID(void) const {return uniqueGUID;} uint64_t GetFirstLBA(void) const {return firstLBA;} @@ -80,7 +78,7 @@ class GPTPart { void SetLastLBA(uint64_t l) {lastLBA = l;} void SetAttributes(uint64_t a) {attributes = a;} void SetAttributes(void) {attributes.ChangeAttributes();} - void SetName(const string & theName); + void SetName(const std::string & theName); #ifdef USE_UTF16 void SetName(const UnicodeString & theName); #endif diff --git a/gpttext.h b/gpttext.h index 36a17f9..32e2f88 100644 --- a/gpttext.h +++ b/gpttext.h @@ -23,13 +23,11 @@ #include "gpt.h" -using namespace std; - class GPTDataTextUI : public GPTData { protected: public: GPTDataTextUI(void); - GPTDataTextUI(string filename); + GPTDataTextUI(std::string filename); ~GPTDataTextUI(void); // This one needs to be explicitly defined, even though it does nothing new.... @@ -55,17 +53,17 @@ class GPTDataTextUI : public GPTData { void ShowDetails(void); void MakeHybrid(void); int XFormToMBR(void); // convert GPT to MBR, wiping GPT afterwards. Returns 1 if successful - uint64_t GetSectorNum(uint64_t low, uint64_t high, uint64_t def, const string & prompt); + uint64_t GetSectorNum(uint64_t low, uint64_t high, uint64_t def, const std::string & prompt); // An informational function.... void WarnAboutIffyMBRPart(int partNum); // Main menu functions - void MainMenu(string filename); + void MainMenu(std::string filename); void ShowCommands(void); - void ExpertsMenu(string filename); + void ExpertsMenu(std::string filename); void ShowExpertCommands(void); - void RecoveryMenu(string filename); + void RecoveryMenu(std::string filename); void ShowRecoveryCommands(void); }; // class GPTDataTextUI diff --git a/guid.h b/guid.h index 229d5bd..515a75d 100644 --- a/guid.h +++ b/guid.h @@ -30,8 +30,6 @@ typedef unsigned char my_uuid_t[16]; typedef uuid_t my_uuid_t; #endif -using namespace std; - // Note: This class's data size is critical. If data elements must be added, // it will be necessary to modify various GPT classes to compensate. class GUIDData { @@ -39,17 +37,17 @@ class GUIDData { static bool firstInstance; protected: my_uuid_t uuidData; - string DeleteSpaces(string s); + std::string DeleteSpaces(std::string s); public: GUIDData(void); GUIDData(const GUIDData & orig); - GUIDData(const string & orig); + GUIDData(const std::string & orig); GUIDData(const char * orig); ~GUIDData(void); // Data assignment operators.... GUIDData & operator=(const GUIDData & orig); - GUIDData & operator=(const string & orig); + GUIDData & operator=(const std::string & orig); GUIDData & operator=(const char * orig); void Zero(void); void Randomize(void); @@ -59,9 +57,9 @@ class GUIDData { int operator!=(const GUIDData & orig) const; // Data retrieval.... - string AsString(void) const; + std::string AsString(void) const; }; // class GUIDData -ostream & operator<<(ostream & os, const GUIDData & data); +std::ostream & operator<<(std::ostream & os, const GUIDData & data); #endif diff --git a/mbr.h b/mbr.h index 21c1d7b..3eea775 100644 --- a/mbr.h +++ b/mbr.h @@ -13,8 +13,6 @@ #include "diskio.h" #include "basicmbr.h" -using namespace std; - /**************************************** * * * MBRData class and related structures * @@ -26,7 +24,7 @@ class MBRData : public BasicMBRData { protected: public: MBRData(void) {} - MBRData(string deviceFilename) : BasicMBRData(deviceFilename) {} + MBRData(std::string deviceFilename) : BasicMBRData(deviceFilename) {} MBRData & operator=(const BasicMBRData & orig); ~MBRData(void); diff --git a/mbrpart.h b/mbrpart.h index 0de365f..6c7b21a 100644 --- a/mbrpart.h +++ b/mbrpart.h @@ -32,8 +32,6 @@ #define EBR 4 /* sector is used as an EBR or MBR */ #define INVALID 8 /* sector number is too large for disk */ -using namespace std; - // Data for a single MBR partition record // Note that firstSector and lastSector are in CHS addressing, which // splits the bits up in a weird way. diff --git a/parttypes.h b/parttypes.h index 92f3d64..4e1d968 100644 --- a/parttypes.h +++ b/parttypes.h @@ -6,16 +6,14 @@ #include #include +#include +#include "support.h" +#include "guid.h" #ifdef USE_UTF16 #include #else -#define UnicodeString string +#define UnicodeString std::string #endif -#include -#include "support.h" -#include "guid.h" - -using namespace std; // A partition type struct AType { @@ -24,7 +22,7 @@ struct AType { // codes required by GPT uint16_t MBRType; GUIDData GUIDType; - string name; + std::string name; int display; // 1 to show to users as available type, 0 not to AType* next; }; // struct AType @@ -48,7 +46,7 @@ public: int AddType(uint16_t mbrType, const char * guidData, const char * name, int toDisplay = 1); // New assignment operators.... - PartType & operator=(const string & orig); + PartType & operator=(const std::string & orig); PartType & operator=(const char * orig); // Assignment operators based on base class.... @@ -58,7 +56,7 @@ public: PartType & operator=(uint16_t ID); // Use MBR type code times 0x0100 to assign GUID // Retrieve transformed GUID data based on type code matches - string TypeName(void) const; + std::string TypeName(void) const; UnicodeString UTypeName(void) const; uint16_t GetHexType() const; diff --git a/support.h b/support.h index a61ddf4..3930ee4 100644 --- a/support.h +++ b/support.h @@ -8,7 +8,7 @@ #include #include -#define GPTFDISK_VERSION "1.0.8.2" +#define GPTFDISK_VERSION "1.0.8.3" #if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined (__APPLE__) // Darwin (Mac OS) & FreeBSD: disk IOCTLs are different, and there is no lseek64 @@ -69,18 +69,16 @@ #define GPT_RESERVED 420 #define NAME_SIZE 36 // GPT allows 36 UTF-16LE code units for a name in a 128 byte partition entry -using namespace std; - -string ReadString(void); -uint64_t GetNumber(uint64_t low, uint64_t high, uint64_t def, const string & prompt); +std::string ReadString(void); +uint64_t GetNumber(uint64_t low, uint64_t high, uint64_t def, const std::string & prompt); char GetYN(void); -uint64_t IeeeToInt(string IeeeValue, uint64_t sSize, uint64_t low, uint64_t high, uint32_t sectorAlignment, uint64_t def = 0); -string BytesToIeee(uint64_t size, uint32_t sectorSize); -unsigned char StrToHex(const string & input, unsigned int position); -int IsHex(string input); // Returns 1 if input can be hexadecimal number.... +uint64_t IeeeToInt(std::string IeeeValue, uint64_t sSize, uint64_t low, uint64_t high, uint32_t sectorAlignment, uint64_t def = 0); +std::string BytesToIeee(uint64_t size, uint32_t sectorSize); +unsigned char StrToHex(const std::string & input, unsigned int position); +int IsHex(std::string input); // Returns 1 if input can be hexadecimal number.... int IsLittleEndian(void); // Returns 1 if CPU is little-endian, 0 if it's big-endian void ReverseBytes(void* theValue, int numBytes); // Reverses byte-order of theValue void WinWarning(void); -string ToLower(const string& input); +std::string ToLower(const std::string& input); #endif -- Gitee From 4be26d7228a5dadfd04488618f08a29f0c67dd8c Mon Sep 17 00:00:00 2001 From: Rod Smith Date: Sun, 10 Apr 2022 09:55:48 -0400 Subject: [PATCH 31/38] Fix build problem with recent ncurses versions --- gptcurses.cc | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/gptcurses.cc b/gptcurses.cc index 08b4257..c5fe24e 100644 --- a/gptcurses.cc +++ b/gptcurses.cc @@ -239,22 +239,22 @@ Space* GPTDataCurses::ShowSpace(int spaceNum, int lineNum) { ClearLine(lineNum); if (space->partNum == -1) { // space is empty move(lineNum, 12); - printw(BytesToIeee((space->lastLBA - space->firstLBA + 1), blockSize).c_str()); + printw("%s", BytesToIeee((space->lastLBA - space->firstLBA + 1), blockSize).c_str()); move(lineNum, 24); printw("free space"); } else { // space holds a partition move(lineNum, 3); printw("%d", space->partNum + 1); move(lineNum, 12); - printw(BytesToIeee((space->lastLBA - space->firstLBA + 1), blockSize).c_str()); + printw("%s", BytesToIeee((space->lastLBA - space->firstLBA + 1), blockSize).c_str()); move(lineNum, 24); - printw(space->origPart->GetTypeName().c_str()); + printw("%s", space->origPart->GetTypeName().c_str()); move(lineNum, 50); #ifdef USE_UTF16 space->origPart->GetDescription().extract(0, 39, temp, 39); printw(temp); #else - printw(space->origPart->GetDescription().c_str()); + printw("%s", space->origPart->GetDescription().c_str()); #endif } // if/else } // if @@ -271,10 +271,10 @@ int GPTDataCurses::DisplayParts(int selected) { move(lineNum++, 0); theLine = "Part. # Size Partition Type Partition Name"; - printw(theLine.c_str()); + printw("%s", theLine.c_str()); move(lineNum++, 0); theLine = "----------------------------------------------------------------"; - printw(theLine.c_str()); + printw("%s", theLine.c_str()); numToShow = LINES - RESERVED_TOP - RESERVED_BOTTOM; pageNum = selected / numToShow; for (i = pageNum * numToShow; i <= (pageNum + 1) * numToShow - 1; i++) { @@ -645,7 +645,7 @@ void GPTDataCurses::DisplayOptions(char selectedKey) { } // if/else } // for move(LINES - 1, (COLS - optionDesc.length()) / 2); - printw(optionDesc.c_str()); + printw("%s", optionDesc.c_str()); currentKey = selectedKey; } // if } // GPTDataCurses::DisplayOptions() @@ -757,11 +757,11 @@ void GPTDataCurses::DrawMenu(void) { clear(); move(0, (COLS - title.length()) / 2); - printw(title.c_str()); + printw("%s", title.c_str()); move(2, (COLS - drive.length()) / 2); - printw(drive.c_str()); + printw("%s", drive.c_str()); move(3, (COLS - size.str().length()) / 2); - printw(size.str().c_str()); + printw("%s", size.str().c_str()); DisplayParts(currentSpaceNum); } // DrawMenu @@ -811,7 +811,7 @@ void PromptToContinue(void) { void Report(string theText) { clear(); move(0, 0); - printw(theText.c_str()); + printw("%s", theText.c_str()); move(LINES - 2, (COLS - 29) / 2); printw("Press any key to continue...."); cbreak(); -- Gitee From 6b7486db9927a1b3f6dd9cc84dff54c33a8aef8c Mon Sep 17 00:00:00 2001 From: Rod Smith Date: Sun, 10 Apr 2022 10:25:41 -0400 Subject: [PATCH 32/38] Abort load of too-small disk image --- gpt.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/gpt.cc b/gpt.cc index 5ccc5c5..848340b 100644 --- a/gpt.cc +++ b/gpt.cc @@ -886,8 +886,16 @@ int GPTData::LoadPartitions(const string & deviceFilename) { break; } // switch - if (allOK) + if (allOK) { CheckGPTSize(); + // Below is unlikely to happen on real disks, but could happen if + // the user is manipulating a truncated image file.... + if (diskSize <= GetTableSizeInSectors() * 2 + 3) { + allOK = 0; + cout << "Disk is too small to hold GPT data (" << diskSize + << " sectors)! Aborting!\n"; + } + } myDisk.Close(); ComputeAlignment(); } else { -- Gitee From d37658e3503d9722400bdc11ba1764786042aca8 Mon Sep 17 00:00:00 2001 From: Rod Smith Date: Sun, 10 Apr 2022 10:28:50 -0400 Subject: [PATCH 33/38] Updated NEWS file for recent merges. --- NEWS | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/NEWS b/NEWS index 201eff8..b797010 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,13 @@ reacts badly to partitions that are not sized as exact multiples of the encryption block size. +- Added check for too-small disks (most likely to be an issue when trying + to use a too-small disk image); program now aborts if this happens. + +- Added the ability to build sgdisk and cgdisk for Windows. + +- Fixed build problems with recent versions of ncurses. + 1.0.8 (6/9/2021): ----------------- -- Gitee From 8ff360f49eda175142e01d46edbb494cfebe309d Mon Sep 17 00:00:00 2001 From: Rod Smith Date: Sun, 10 Apr 2022 11:09:19 -0400 Subject: [PATCH 34/38] Fix valgrind complaint --- gpt.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gpt.cc b/gpt.cc index 848340b..76cd9ad 100644 --- a/gpt.cc +++ b/gpt.cc @@ -80,6 +80,7 @@ GPTData::GPTData(void) { beQuiet = 0; whichWasUsed = use_new; mainHeader.numParts = 0; + mainHeader.lastUsableLBA = 0; numParts = 0; SetGPTSize(NUM_GPT_ENTRIES); // Initialize CRC functions... @@ -143,6 +144,7 @@ GPTData::GPTData(string filename) { beQuiet = 0; whichWasUsed = use_new; mainHeader.numParts = 0; + mainHeader.lastUsableLBA = 0; numParts = 0; // Initialize CRC functions... chksum_crc32gentab(); -- Gitee From b056f3860ad587c01ed9e2a0bae6cc3ba8d41535 Mon Sep 17 00:00:00 2001 From: Rod Smith Date: Sun, 10 Apr 2022 12:57:41 -0400 Subject: [PATCH 35/38] Fix bug that caused cgdisk to report incorrect partition attributes. --- NEWS | 2 ++ gptcurses.cc | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index b797010..b2c1eb3 100644 --- a/NEWS +++ b/NEWS @@ -19,6 +19,8 @@ - Fixed build problems with recent versions of ncurses. +- Fixed bug that caused cgdisk to report incorrect partition attributes. + 1.0.8 (6/9/2021): ----------------- diff --git a/gptcurses.cc b/gptcurses.cc index c5fe24e..8b0ae91 100644 --- a/gptcurses.cc +++ b/gptcurses.cc @@ -339,7 +339,7 @@ void GPTDataCurses::ShowInfo(int partNum) { BytesToIeee(partitions[partNum].GetLastLBA(), blockSize).c_str()); size = partitions[partNum].GetLastLBA() - partitions[partNum].GetFirstLBA() + 1; printw("Partition size: %lld sectors (%s)\n", size, BytesToIeee(size, blockSize).c_str()); - printw("Attribute flags: %016x\n", partitions[partNum].GetAttributes().GetAttributes()); + printw("Attribute flags: %016llx\n", partitions[partNum].GetAttributes().GetAttributes()); #ifdef USE_UTF16 partitions[partNum].GetDescription().extract(0, NAME_SIZE , temp, NAME_SIZE ); printw("Partition name: '%s'\n", temp); -- Gitee From 122b58ad82f1a144226d262c87241ee035ed1aff Mon Sep 17 00:00:00 2001 From: Rod Smith Date: Tue, 12 Apr 2022 18:11:23 -0400 Subject: [PATCH 36/38] Introduction of unified (multi-OS) Makefile Forgot something! --- Makefile | 147 +++++++++++++++++++++++++++++++++++++++++++++++-- Makefile.linux | 46 ++++++++++++++++ NEWS | 5 ++ README | 44 +++++++++------ README.Windows | 27 ++++----- 5 files changed, 233 insertions(+), 36 deletions(-) create mode 100644 Makefile.linux diff --git a/Makefile b/Makefile index 7ecab54..f7943d2 100644 --- a/Makefile +++ b/Makefile @@ -1,27 +1,159 @@ +# Makefile for GPT fdisk + +# This program is licensed under the terms of the GNU GPL, version 2, +# or (at your option) any later version. +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# This is a consolidated Makefile for Linux, FreeBSD, Solaris (untested), +# macOS, and Windows (x86_64 and i686). + +# Builds for host OS by default; pass TARGET={target_os} to cross-compile, +# where {target_os} is one of linux, freebsd, solaris, macos, win32, or win64. +# Appropriate cross-compiler support must be installed, of course, and build +# options below may need to be changed. + +# DETECTED_OS is used both to set certain options for the build +# environment and to determine the default TARGET if it's not +# otherwise specified. +DETECTED_OS := $(shell uname -s) + +ifeq ($(origin TARGET),undefined) + $(info TARGET is not set; trying to determine target based on host OS....) + $(info Detected OS is $(DETECTED_OS)) + ifeq ($(DETECTED_OS),Linux) + # Note: TARGET is set to "linux", but this is never tested, since it's + # the default. + TARGET=linux + else ifeq ($(DETECTED_OS),Darwin) + TARGET=macos + else ifeq ($(DETECTED_OS),MINGW64_NT-10.0-19042) + # Works for my MSYS2 installation, but seems awfully version-specific + # Also, uname may not exist in some Windows environments. + TARGET=windows + else ifeq ($(DETECTED_OS),FreeBSD) + TARGET=freebsd + else ifeq ($(DETECTED_OS),SunOS) + TARGET=solaris + endif +endif + +# A second way to detect Windows.... +ifeq ($(origin TARGET),undefined) + ifeq ($(OS),Windows_NT) + TARGET=windows + endif +endif + +# For Windows, we need to know the bit depth, too +ifeq ($(TARGET),windows) + ARCH=$(shell uname -m) + $(info ARCH is $(ARCH)) + ifeq ($(ARCH),x86_64) + TARGET=win64 + else ifeq ($(ARCH),i686) + TARGET=win32 + else + # In theory, there could be ARM versions, but we aren't set up for them yet; + # also, default to win64 in case uname doesn't exist on the system + TARGET=win64 + endif +endif + +$(info Build target is $(TARGET)) + +# Default/Linux settings.... #CXXFLAGS+=-O2 -Wall -D_FILE_OFFSET_BITS=64 -D USE_UTF16 +STRIP?=strip CXXFLAGS+=-O2 -Wall -D_FILE_OFFSET_BITS=64 LDFLAGS+= LDLIBS+=-luuid #-licuio -licuuc +FATBINFLAGS= +THINBINFLAGS= +SGDISK_LDLIBS=-lpopt +CGDISK_LDLIBS=-lncursesw LIB_NAMES=crc32 support guid gptpart mbrpart basicmbr mbr gpt bsd parttypes attributes diskio diskio-unix MBR_LIBS=support diskio diskio-unix basicmbr mbrpart +ALL=gdisk cgdisk sgdisk fixparts +FN_EXTENSION= + +# Settings for non-Linux OSes.... +ifeq ($(TARGET),win64) + CXX=x86_64-w64-mingw32-g++ + ifeq ($(DETECTED_OS),Linux) + STRIP=x86_64-w64-mingw32-strip + else + STRIP=strip + endif + CXXFLAGS=-O2 -Wall -D_FILE_OFFSET_BITS=64 -static -static-libgcc -static-libstdc++ + #CXXFLAGS=-O2 -Wall -D_FILE_OFFSET_BITS=64 -I /usr/local/include -I/opt/local/include -g + LDFLAGS+=-static -static-libgcc -static-libstdc++ + LDLIBS+=-lrpcrt4 + SGDISK_LDLIBS=-lpopt -lintl -liconv + LIB_NAMES=guid gptpart bsd parttypes attributes crc32 mbrpart basicmbr mbr gpt support diskio diskio-windows + MBR_LIBS=support diskio diskio-windows basicmbr mbrpart + FN_EXTENSION=64.exe + ifeq ($(DETECTED_OS),Linux) + # Omit cgdisk when building under Linux for Windows because it doesn't + # work on my system + ALL=gdisk sgdisk fixparts + endif +else ifeq ($(TARGET),win32) + CXX=i686-w64-mingw32-g++ + ifeq ($(DETECTED_OS),Linux) + STRIP=i686-w64-mingw32-strip + else + STRIP=strip + endif + CXXFLAGS=-O2 -Wall -D_FILE_OFFSET_BITS=64 -static -static-libgcc -static-libstdc++ + #CXXFLAGS=-O2 -Wall -D_FILE_OFFSET_BITS=64 -I /usr/local/include -I/opt/local/include + LDFLAGS+=-static -static-libgcc -static-libstdc++ + LDLIBS+=-lrpcrt4 + SGDISK_LDLIBS=-lpopt -lintl -liconv + LIB_NAMES=guid gptpart bsd parttypes attributes crc32 mbrpart basicmbr mbr gpt support diskio diskio-windows + MBR_LIBS=support diskio diskio-windows basicmbr mbrpart + FN_EXTENSION=32.exe + ifeq ($(DETECTED_OS),Linux) + # Omit cgdisk when building for Windows under Linux because it doesn't + # work on my system + ALL=gdisk sgdisk fixparts + endif +else ifeq ($(TARGET),freebsd) + CXX=clang++ + CXXFLAGS+=-O2 -Wall -D_FILE_OFFSET_BITS=64 -I /usr/local/include + LDFLAGS+=-L/usr/local/lib + LDLIBS+=-luuid #-licuio +else ifeq ($(TARGET),macos) + FATBINFLAGS=-arch x86_64 -arch arm64 -mmacosx-version-min=10.9 + THINBINFLAGS=-arch x86_64 -mmacosx-version-min=10.9 + CXXFLAGS=$(FATBINFLAGS) -O2 -Wall -D_FILE_OFFSET_BITS=64 -stdlib=libc++ -I/opt/local/include -I /usr/local/include -I/opt/local/include + LDLIBS= #-licucore + CGDISK_LDLIBS=/usr/local/Cellar/ncurses/6.2/lib/libncurses.dylib +else ifeq ($(TARGET),solaris) + CXXFLAGS+=-Wall -D_FILE_OFFSET_BITS=64 -I/usr/include/ncurses + LDFLAGS+=-L/lib -licuio -licuuc -luuid +endif + +# More default settings, for all OSes.... LIB_OBJS=$(LIB_NAMES:=.o) MBR_LIB_OBJS=$(MBR_LIBS:=.o) LIB_HEADERS=$(LIB_NAMES:=.h) DEPEND= makedepend $(CXXFLAGS) +ALL_EXE=$(ALL:=$(FN_EXTENSION)) -all: cgdisk gdisk sgdisk fixparts +all: $(ALL) gdisk: $(LIB_OBJS) gdisk.o gpttext.o - $(CXX) $(LIB_OBJS) gdisk.o gpttext.o $(LDFLAGS) $(LDLIBS) -o gdisk + $(CXX) $(LIB_OBJS) gdisk.o gpttext.o $(LDFLAGS) $(LDLIBS) $(FATBINFLAGS) -o gdisk$(FN_EXTENSION) cgdisk: $(LIB_OBJS) cgdisk.o gptcurses.o - $(CXX) $(LIB_OBJS) cgdisk.o gptcurses.o $(LDFLAGS) $(LDLIBS) -lncursesw -o cgdisk + $(CXX) $(LIB_OBJS) cgdisk.o gptcurses.o $(LDFLAGS) $(LDLIBS) $(CGDISK_LDLIBS) -o cgdisk$(FN_EXTENSION) sgdisk: $(LIB_OBJS) sgdisk.o gptcl.o - $(CXX) $(LIB_OBJS) sgdisk.o gptcl.o $(LDFLAGS) $(LDLIBS) -lpopt -o sgdisk + $(CXX) $(LIB_OBJS) sgdisk.o gptcl.o $(LDFLAGS) $(LDLIBS) $(SGDISK_LDLIBS) $(THINBINFLAGS) -o sgdisk$(FN_EXTENSION) fixparts: $(MBR_LIB_OBJS) fixparts.o - $(CXX) $(MBR_LIB_OBJS) fixparts.o $(LDFLAGS) -o fixparts + $(CXX) $(MBR_LIB_OBJS) fixparts.o $(LDFLAGS) $(FATBINFLAGS) -o fixparts$(FN_EXTENSION) test: ./gdisk_test.sh @@ -30,7 +162,10 @@ lint: #no pre-reqs lint $(SRCS) clean: #no pre-reqs - rm -f core *.o *~ gdisk sgdisk cgdisk fixparts + rm -f core *.o *~ $(ALL_EXE) + +strip: #no pre-reqs + $(STRIP) $(ALL_EXE) # what are the source dependencies depend: $(SRCS) diff --git a/Makefile.linux b/Makefile.linux new file mode 100644 index 0000000..0d7309c --- /dev/null +++ b/Makefile.linux @@ -0,0 +1,46 @@ +CFLAGS+=-D_FILE_OFFSET_BITS=64 +#CXXFLAGS+=-Wall -D_FILE_OFFSET_BITS=64 -D USE_UTF16 +CXXFLAGS+=-Wall -D_FILE_OFFSET_BITS=64 +LDFLAGS+= +LIB_NAMES=crc32 support guid gptpart mbrpart basicmbr mbr gpt bsd parttypes attributes diskio diskio-unix +MBR_LIBS=support diskio diskio-unix basicmbr mbrpart +LIB_OBJS=$(LIB_NAMES:=.o) +MBR_LIB_OBJS=$(MBR_LIBS:=.o) +LIB_HEADERS=$(LIB_NAMES:=.h) +DEPEND= makedepend $(CXXFLAGS) + +all: cgdisk gdisk sgdisk fixparts + +gdisk: $(LIB_OBJS) gdisk.o gpttext.o + $(CXX) $(LIB_OBJS) gdisk.o gpttext.o $(LDFLAGS) -luuid $(LDLIBS) -o gdisk +# $(CXX) $(LIB_OBJS) gdisk.o gpttext.o $(LDFLAGS) -licuio -licuuc -luuid -o gdisk + +cgdisk: $(LIB_OBJS) cgdisk.o gptcurses.o + $(CXX) $(LIB_OBJS) cgdisk.o gptcurses.o $(LDFLAGS) -luuid -lncursesw $(LDLIBS) -o cgdisk +# $(CXX) $(LIB_OBJS) cgdisk.o gptcurses.o $(LDFLAGS) -licuio -licuuc -luuid -lncurses -o cgdisk + +sgdisk: $(LIB_OBJS) sgdisk.o gptcl.o + $(CXX) $(LIB_OBJS) sgdisk.o gptcl.o $(LDFLAGS) -luuid -lpopt $(LDLIBS) -o sgdisk +# $(CXX) $(LIB_OBJS) sgdisk.o gptcl.o $(LDFLAGS) -licuio -licuuc -luuid -lpopt -o sgdisk + +fixparts: $(MBR_LIB_OBJS) fixparts.o + $(CXX) $(MBR_LIB_OBJS) fixparts.o $(LDFLAGS) $(LDLIBS) -o fixparts + +test: + ./gdisk_test.sh + +lint: #no pre-reqs + lint $(SRCS) + +clean: #no pre-reqs + rm -f core *.o *~ gdisk sgdisk cgdisk fixparts + +# what are the source dependencies +depend: $(SRCS) + $(DEPEND) $(SRCS) + +$(OBJS): + $(CRITICAL_CXX_FLAGS) + +# makedepend dependencies below -- type "makedepend *.cc" to regenerate.... +# DO NOT DELETE diff --git a/NEWS b/NEWS index b2c1eb3..d54b96b 100644 --- a/NEWS +++ b/NEWS @@ -21,6 +21,11 @@ - Fixed bug that caused cgdisk to report incorrect partition attributes. +- Consolidated Makefiles for Linux, FreeBSD, Solaris, macOS, and Windows + (32- and 64-bit). The old OS-specific Makefiles remain in case the new + consolidated Makefile has problems, but the old ones are deprecated. + (The Solaris support in the new Makefile is untested.) + 1.0.8 (6/9/2021): ----------------- diff --git a/README b/README index 69775eb..157abb8 100644 --- a/README +++ b/README @@ -161,12 +161,12 @@ features of FixParts require elaboration: Installing ---------- -To compile GPT fdisk, you must have appropriate development tools -installed, most notably the GNU Compiler Collection (GCC) and its g++ -compiler for C++. I've also tested compilation with Clang, which seems to -work; however, I've not done extensive testing of the resulting binaries, -beyond checking a few basics. Under Windows, Microsoft Visual C++ 2008 can -be used instead. In addition, note these requirements: +To compile GPT fdisk, you must have appropriate development tools installed, +most notably the GNU Compiler Collection (GCC) and its g++ compiler for C++. +I've also tested compilation with Clang, which seems to work; however, I've +not done extensive testing of the resulting binaries, beyond checking a few +basics. See the README.Windows files for additional notes on compiling the +software for Windows. In addition, note these requirements: * On Linux, FreeBSD, macOS, and Solaris, libuuid must be installed. This is the standard for Linux and macOS, although you may need to install a @@ -214,17 +214,27 @@ be used instead. In addition, note these requirements: When all the necessary development tools and libraries are installed, you can uncompress the package and type "make" at the command prompt in the -resulting directory. (You must type "make -f Makefile.mac" on macOS, "make --f Makefile.freebsd" on FreeBSD, "make -f Makefile.solaris" on Solaris, or -"make -f Makefile.mingw" to compile using MinGW for Windows.) You may also -need to add header (include) directories or library directories by setting -the CXXFLAGS environment variable or by editing the Makefile. The result -should be program files called gdisk, cgdisk, sgdisk, and fixparts. Typing -"make gdisk", "make cgdisk", "make sgdisk", or "make fixparts" will compile -only the requested programs. You can use these programs in place or copy the -files to a suitable directory, such as /usr/local/sbin. You can copy the man -pages (gdisk.8, cgdisk.8, sgdisk.8, and fixparts.8) to /usr/local/man/man8 -to make them available. +resulting directory. (Beginning with version 1.0.9, GPT fdisk provides a +consolidated Makefile for all supported OSes. Earlier versions used +OS-specific Makefiles, such as Makefile.mac and Makefile.freebsd, which are +still provided, but are deprecated.) You must use GNU make (gmake on +FreeBSD) with this Makefile. You may also need to add header (include) +directories or library directories by setting the CXXFLAGS environment +variable or by editing the Makefile. The result should be program files +called gdisk, cgdisk, sgdisk, and fixparts (or variants with "32.exe" or +"64.exe" added for Windows binaries). Typing "make gdisk", "make cgdisk", +"make sgdisk", or "make fixparts" will compile only the requested programs. +You can use these programs in place or copy the files to a suitable +directory, such as /usr/local/sbin. You can copy the man pages (gdisk.8, +cgdisk.8, sgdisk.8, and fixparts.8) to /usr/local/man/man8 to make them +available. + +Cross-compiling is possible, but is not well-tested, except for compiling +Windows binaries on Linux. (See README.Windows for details.) To +cross-compile, specify the TARGET environment variable when launching make, +as in "TARGET=win64 make" to compile for 64-bit (x86-64, X64, AMD64) Windows +on a non-Windows platform. Supported TARGET values are linux, freebsd, +solaris, macos, win32, and win64. Caveats ------- diff --git a/README.Windows b/README.Windows index 275b56d..d13bce3 100644 --- a/README.Windows +++ b/README.Windows @@ -132,8 +132,12 @@ My primary development environment is Ubuntu Linux, using the MinGW cross-compiler. This system can compile the gdisk and fixparts binaries with no need for additional libraries; after installing MinGW (via the g++-mingw-w64 package in Ubuntu, or the equivalent in another distribution), -you can type "make -f Makefile.mingw" to compile 32-bit binaries, and "make --f Makefile.mingw64" to compile 64-bit binaries. +you can type "TARGET=win32 make" to compile 32-bit binaries, and +"TARGET=win64 make" to compile 64-bit binaries. This will attempt to build +gdisk, sgdisk, and fixparts; but the sgdisk build will fail until you +install the popt libraries, as described shortly. You can build the other +binaries by specifying them, as in "TARGET=win64 make gdisk" to build the +64-bit gdisk binary alone. If you use Windows, your best bet is likely to be to install the MSYS2 package (https://www.msys2.org). This package provides MinGW and a package @@ -145,7 +149,11 @@ mingw-w64-x86_64-ncurses" if you want to compile 64-bit binaries; change library needed by sgdisk and the ncurses library needed by cgdisk, along with gettext, which is needed by popt. With these libraries installed, you should be able to compile all four Linux programs -- gdisk, cgdisk, sgdisk, -and fixparts. +and fixparts. Typing "make" alone in the MSYS2 shell should build all four +programs for the host architecture (x86-64 or i686); to compile for the +other architecture, you must specify it with a "TARGET=" specification, as +under Linux. (The Makefile does not currently support ARM64 targets for +Windows.) If you want to compile sgdisk for Windows under Linux, you can do so; however, you must copy the relevant header and library files from a Windows @@ -178,14 +186,7 @@ ncurses version installed in Windows is too new to work with the MinGW libraries in Ubuntu (20.04 or 22.04). It's conceivable it would work with another distribution, though. -In any event, the Makefile.mingw and Makefile.mingw64 files contain targets -for all four programs; however, because of the problem building cgdisk in -Linux, that program is omitted from the "all" target. It can still be built -explicitly, though, as in: - -make -f Makefile.mingw64 cgdisk - -The Makefiles are configured to create statically-linked binaries so as to +The Makefile is configured to create statically-linked binaries so as to simplify installation of the binaries. If you want smaller binaries, you can -remove the various static options from the relevant Makefile. You can also -strip the binaries ("make -f Makefile.mingw64 strip") to remove unused code. +remove the various static options from the Makefile. You can also strip the +binaries ("make strip") to remove unused code. -- Gitee From 075f3fe2a0e63dc8b705b0d1dc30f70636dd2e39 Mon Sep 17 00:00:00 2001 From: Rod Smith Date: Tue, 12 Apr 2022 19:00:23 -0400 Subject: [PATCH 37/38] Added several new partition type codes --- NEWS | 10 ++++++++++ parttypes.cc | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/NEWS b/NEWS index d54b96b..b5ebc03 100644 --- a/NEWS +++ b/NEWS @@ -17,6 +17,16 @@ - Added the ability to build sgdisk and cgdisk for Windows. +- Added new type codes: + * FreeBSD nandfs (0xa506) + * Apple APFS Pre-Boot (0xaf0b) + * Apple APFS Recovery (0xaf0c) + * ChromeOS firmware (0x7f03) + * ChromeOS mini-OS (0x7f04) + * ChromeOS hibernate (0x7f05) + * U-Boot boot loader (0xb000) + * 27 (!) codes for Fuchsia (0xf100 to 0xf11a) + - Fixed build problems with recent versions of ncurses. - Fixed bug that caused cgdisk to report incorrect partition attributes. diff --git a/parttypes.cc b/parttypes.cc index a56f5ef..82ad37f 100644 --- a/parttypes.cc +++ b/parttypes.cc @@ -127,6 +127,9 @@ void PartType::AddAllTypes(void) { AddType(0x7f00, "FE3A2A5D-4F32-41A7-B725-ACCC3285A309", "ChromeOS kernel"); AddType(0x7f01, "3CB8E202-3B7E-47DD-8A3C-7FF2A13CFCEC", "ChromeOS root"); AddType(0x7f02, "2E0A753D-9E48-43B0-8337-B15192CB1B5E", "ChromeOS reserved"); + AddType(0x7f03, "CAB6E88E-ABF3-4102-A07A-D4BB9BE3C1D3", "ChromeOS firmware"); + AddType(0x7f04, "09845860-705F-4BB5-B16C-8A8A099CAF52", "ChromeOS mini-OS"); + AddType(0x7f05, "3F0F8318-F146-4E6B-8222-C28C8F02E0D5", "ChromeOS hibernate"); // Linux-specific partition types.... AddType(0x8200, "0657FD6D-A4AB-43C4-84E5-0933C84B4F4F", "Linux swap"); // Linux swap (or Solaris on MBR) @@ -258,6 +261,7 @@ void PartType::AddAllTypes(void) { AddType(0xa503, "516E7CB6-6ECF-11D6-8FF8-00022D09712B", "FreeBSD UFS"); AddType(0xa504, "516E7CBA-6ECF-11D6-8FF8-00022D09712B", "FreeBSD ZFS"); AddType(0xa505, "516E7CB8-6ECF-11D6-8FF8-00022D09712B", "FreeBSD Vinum/RAID"); + AddType(0xa506, "74BA7DD9-A689-11E1-BD04-00E081286ACF", "FreeBSD nandfs"); // Midnight BSD partition types.... AddType(0xa580, "85D5E45A-237C-11E1-B4B3-E89A8F7FC3A7", "Midnight BSD data"); @@ -296,6 +300,12 @@ void PartType::AddAllTypes(void) { AddType(0xaf08, "FA709C7E-65B1-4593-BFD5-E71D61DE9B02", "Apple SoftRAID Volume"); AddType(0xaf09, "BBBA6DF5-F46F-4A89-8F59-8765B2727503", "Apple SoftRAID Cache"); AddType(0xaf0a, "7C3457EF-0000-11AA-AA11-00306543ECAC", "Apple APFS"); + AddType(0xaf0b, "69646961-6700-11AA-AA11-00306543ECAC", "Apple APFS Pre-Boot"); + AddType(0xaf0c, "52637672-7900-11AA-AA11-00306543ECAC", "Apple APFS Recovery"); + + // U-Boot boot loader; see https://lists.denx.de/pipermail/u-boot/2020-November/432928.html + // and https://source.denx.de/u-boot/u-boot/-/blob/v2021.07/include/part_efi.h#L59-61 + AddType(0xb000, "3DE21764-95BD-54BD-A5C3-4ABE786F38A8", "U-Boot boot loader"); // QNX Power-Safe (QNX6) AddType(0xb300, "CEF5A9AD-73BC-4601-89F3-CDEEEEE321A1", "QNX6 Power-Safe"); @@ -348,6 +358,35 @@ void PartType::AddAllTypes(void) { AddType(0xef01, "024DEE41-33E7-11D3-9D69-0008C781F39F", "MBR partition scheme"); // Used to nest MBR in GPT AddType(0xef02, "21686148-6449-6E6F-744E-656564454649", "BIOS boot partition"); // Used by GRUB + // Fuscia OS code; see https://cs.opensource.google/fuchsia/fuchsia/+/main:zircon/system/public/zircon/hw/gpt.h + AddType(0xf100, "FE8A2634-5E2E-46BA-99E3-3A192091A350", "Fuchsia boot loader (slot A/B/R)"); + AddType(0xf101, "D9FD4535-106C-4CEC-8D37-DFC020CA87CB", "Fuchsia durable mutable encrypted system data"); + AddType(0xf102, "A409E16B-78AA-4ACC-995C-302352621A41", "Fuchsia durable mutable boot loader"); + AddType(0xf103, "F95D940E-CABA-4578-9B93-BB6C90F29D3E", "Fuchsia factory ro system data"); + AddType(0xf104, "10B8DBAA-D2BF-42A9-98C6-A7C5DB3701E7", "Fuchsia factory ro bootloader data"); + AddType(0xf105, "49FD7CB8-DF15-4E73-B9D9-992070127F0F", "Fuchsia Volume Manager"); + AddType(0xf106, "421A8BFC-85D9-4D85-ACDA-B64EEC0133E9", "Fuchsia verified boot metadata (slot A/B/R)"); + AddType(0xf107, "9B37FFF6-2E58-466A-983A-F7926D0B04E0", "Fuchsia Zircon boot image (slot A/B/R)"); + AddType(0xf108, "C12A7328-F81F-11D2-BA4B-00A0C93EC93B", "Fuchsia ESP"); + AddType(0xf109, "606B000B-B7C7-4653-A7D5-B737332C899D", "Fuchsia System"); + AddType(0xf10a, "08185F0C-892D-428A-A789-DBEEC8F55E6A", "Fuchsia Data"); + AddType(0xf10b, "48435546-4953-2041-494E-5354414C4C52", "Fuchsia Install"); + AddType(0xf10c, "2967380E-134C-4CBB-B6DA-17E7CE1CA45D", "Fuchsia Blob"); + AddType(0xf10d, "41D0E340-57E3-954E-8C1E-17ECAC44CFF5", "Fuchsia FVM"); + AddType(0xf10e, "DE30CC86-1F4A-4A31-93C4-66F147D33E05", "Fuchsia Zircon boot image (slot A)"); + AddType(0xf10f, "23CC04DF-C278-4CE7-8471-897D1A4BCDF7", "Fuchsia Zircon boot image (slot B)"); + AddType(0xf110, "A0E5CF57-2DEF-46BE-A80C-A2067C37CD49", "Fuchsia Zircon boot image (slot R)"); + AddType(0xf111, "4E5E989E-4C86-11E8-A15B-480FCF35F8E6", "Fuchsia sys-config"); + AddType(0xf112, "5A3A90BE-4C86-11E8-A15B-480FCF35F8E6", "Fuchsia factory-config"); + AddType(0xf113, "5ECE94FE-4C86-11E8-A15B-480FCF35F8E6", "Fuchsia bootloader"); + AddType(0xf114, "8B94D043-30BE-4871-9DFA-D69556E8C1F3", "Fuchsia guid-test"); + AddType(0xf115, "A13B4D9A-EC5F-11E8-97D8-6C3BE52705BF", "Fuchsia verified boot metadata (A)"); + AddType(0xf116, "A288ABF2-EC5F-11E8-97D8-6C3BE52705BF", "Fuchsia verified boot metadata (B)"); + AddType(0xf117, "6A2460C3-CD11-4E8B-80A8-12CCE268ED0A", "Fuchsia verified boot metadata (R)"); + AddType(0xf118, "1D75395D-F2C6-476B-A8B7-45CC1C97B476", "Fuchsia misc"); + AddType(0xf119, "900B0FC5-90CD-4D4F-84F9-9F8ED579DB88", "Fuchsia emmc-boot1"); + AddType(0xf11a, "B2B2E8D1-7C10-4EBC-A2D0-4614568260AD", "Fuchsia emmc-boot2"); + // Ceph type codes; see https://github.com/ceph/ceph/blob/9bcc42a3e6b08521694b5c0228b2c6ed7b3d312e/src/ceph-disk#L76-L81 // and Wikipedia AddType(0xf800, "4FBD7E29-9D25-41B8-AFD0-062C0CEFF05D", "Ceph OSD"); // Ceph Object Storage Daemon -- Gitee From 1d46f3723bc25f5598266f7d9a3548af3cee0c77 Mon Sep 17 00:00:00 2001 From: Rod Smith Date: Thu, 14 Apr 2022 20:01:30 -0400 Subject: [PATCH 38/38] GPT fdisk version 1.0.9 --- Makefile | 3 ++- NEWS | 4 ++-- cgdisk.8 | 4 ++-- current.spec | 8 ++++---- fixparts.8 | 4 ++-- gdisk.8 | 4 ++-- parttypes.cc | 2 +- sgdisk.8 | 4 ++-- support.h | 2 +- 9 files changed, 18 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index f7943d2..af9701c 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ # Makefile for GPT fdisk +# Copyright (c) 2022 by Rod Smith # This program is licensed under the terms of the GNU GPL, version 2, # or (at your option) any later version. # You should have received a copy of the GNU General Public License @@ -63,8 +64,8 @@ endif $(info Build target is $(TARGET)) # Default/Linux settings.... -#CXXFLAGS+=-O2 -Wall -D_FILE_OFFSET_BITS=64 -D USE_UTF16 STRIP?=strip +#CXXFLAGS+=-O2 -Wall -D_FILE_OFFSET_BITS=64 -D USE_UTF16 CXXFLAGS+=-O2 -Wall -D_FILE_OFFSET_BITS=64 LDFLAGS+= LDLIBS+=-luuid #-licuio -licuuc diff --git a/NEWS b/NEWS index b5ebc03..c7add56 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,5 @@ -1.0.9 (?/?/2022): ------------------ +1.0.9 (4/14/2022): +------------------ - Removed stray debugging code that caused "partNum is {x}" to be printed when changing a partition's name with sgdisk (-c/--change-name). diff --git a/cgdisk.8 b/cgdisk.8 index 0b51fc1..e3b5cb4 100644 --- a/cgdisk.8 +++ b/cgdisk.8 @@ -1,6 +1,6 @@ -.\" Copyright 2011-2021 Roderick W. Smith (rodsmith@rodsbooks.com) +.\" Copyright 2011-2022 Roderick W. Smith (rodsmith@rodsbooks.com) .\" May be distributed under the GNU General Public License -.TH "CGDISK" "8" "1.0.8" "Roderick W. Smith" "GPT fdisk Manual" +.TH "CGDISK" "8" "1.0.9" "Roderick W. Smith" "GPT fdisk Manual" .SH "NAME" cgdisk \- Curses-based GUID partition table (GPT) manipulator .SH "SYNOPSIS" diff --git a/current.spec b/current.spec index bb963b1..a912894 100644 --- a/current.spec +++ b/current.spec @@ -1,12 +1,12 @@ Summary: GPT partitioning and MBR repair software Name: gptfdisk -Version: 1.0.8 +Version: 1.0.9 Release: 1%{?dist} License: GPLv2 URL: http://www.rodsbooks.com/gdisk Group: Applications/System -Source: http://www.rodsbooks.com/gdisk/gptfdisk-1.0.8.tar.gz +Source: http://www.rodsbooks.com/gdisk/gptfdisk-1.0.9.tar.gz BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) %description @@ -81,5 +81,5 @@ provides a few additional partition manipulation features. %changelog -* Wed Jun 9 2021 R Smith - 1.0.8 -- Created spec file for 1.0.8 release +* Thu Apr 14 2022 R Smith - 1.0.9 +- Created spec file for 1.0.9 release diff --git a/fixparts.8 b/fixparts.8 index 4002ea5..da7462a 100644 --- a/fixparts.8 +++ b/fixparts.8 @@ -1,6 +1,6 @@ -.\" Copyright 2011-2021 Roderick W. Smith (rodsmith@rodsbooks.com) +.\" Copyright 2011-2022 Roderick W. Smith (rodsmith@rodsbooks.com) .\" May be distributed under the GNU General Public License -.TH "FIXPARTS" "8" "1.0.8" "Roderick W. Smith" "FixParts Manual" +.TH "FIXPARTS" "8" "1.0.9" "Roderick W. Smith" "FixParts Manual" .SH "NAME" fixparts \- MBR partition table repair utility .SH "SYNOPSIS" diff --git a/gdisk.8 b/gdisk.8 index 75a3e82..b826b89 100644 --- a/gdisk.8 +++ b/gdisk.8 @@ -1,6 +1,6 @@ -.\" Copyright 2011-2021 Roderick W. Smith (rodsmith@rodsbooks.com) +.\" Copyright 2011-2022 Roderick W. Smith (rodsmith@rodsbooks.com) .\" May be distributed under the GNU General Public License -.TH "GDISK" "8" "1.0.8" "Roderick W. Smith" "GPT fdisk Manual" +.TH "GDISK" "8" "1.0.9" "Roderick W. Smith" "GPT fdisk Manual" .SH "NAME" gdisk \- Interactive GUID partition table (GPT) manipulator .SH "SYNOPSIS" diff --git a/parttypes.cc b/parttypes.cc index 82ad37f..b2f5a35 100644 --- a/parttypes.cc +++ b/parttypes.cc @@ -358,7 +358,7 @@ void PartType::AddAllTypes(void) { AddType(0xef01, "024DEE41-33E7-11D3-9D69-0008C781F39F", "MBR partition scheme"); // Used to nest MBR in GPT AddType(0xef02, "21686148-6449-6E6F-744E-656564454649", "BIOS boot partition"); // Used by GRUB - // Fuscia OS code; see https://cs.opensource.google/fuchsia/fuchsia/+/main:zircon/system/public/zircon/hw/gpt.h + // Fuscia OS codes; see https://cs.opensource.google/fuchsia/fuchsia/+/main:zircon/system/public/zircon/hw/gpt.h AddType(0xf100, "FE8A2634-5E2E-46BA-99E3-3A192091A350", "Fuchsia boot loader (slot A/B/R)"); AddType(0xf101, "D9FD4535-106C-4CEC-8D37-DFC020CA87CB", "Fuchsia durable mutable encrypted system data"); AddType(0xf102, "A409E16B-78AA-4ACC-995C-302352621A41", "Fuchsia durable mutable boot loader"); diff --git a/sgdisk.8 b/sgdisk.8 index 23fc943..b966a13 100644 --- a/sgdisk.8 +++ b/sgdisk.8 @@ -1,6 +1,6 @@ -.\" Copyright 2011-2021 Roderick W. Smith (rodsmith@rodsbooks.com) +.\" Copyright 2011-2022 Roderick W. Smith (rodsmith@rodsbooks.com) .\" May be distributed under the GNU General Public License -.TH "SGDISK" "8" "1.0.8" "Roderick W. Smith" "GPT fdisk Manual" +.TH "SGDISK" "8" "1.0.9" "Roderick W. Smith" "GPT fdisk Manual" .SH "NAME" sgdisk \- Command\-line GUID partition table (GPT) manipulator for Linux and Unix .SH "SYNOPSIS" diff --git a/support.h b/support.h index 3930ee4..8ba9ad1 100644 --- a/support.h +++ b/support.h @@ -8,7 +8,7 @@ #include #include -#define GPTFDISK_VERSION "1.0.8.3" +#define GPTFDISK_VERSION "1.0.9" #if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined (__APPLE__) // Darwin (Mac OS) & FreeBSD: disk IOCTLs are different, and there is no lseek64 -- Gitee