diff --git a/Android.bp b/Android.bp
index d0178f8..ec1c354 100644
--- a/Android.bp
+++ b/Android.bp
@@ -33,6 +33,7 @@ cc_defaults {
name: "gptfdisk_default_flags",
cflags: [
"-Wno-unused-parameter",
+ "-Wno-macro-redefined",
"-Wno-pragma-pack",
"-Werror",
"-fPIC",
diff --git a/METADATA b/METADATA
index e53a6a6..8dd14f1 100644
--- a/METADATA
+++ b/METADATA
@@ -1,3 +1,7 @@
+# This project was upgraded with external_updater.
+# Usage: tools/external_updater/updater.sh update gptfdisk
+# For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md
+
name: "gptfdisk"
description: "This package includes the source code for four related disk partitioning programs."
third_party {
@@ -9,11 +13,11 @@ third_party {
type: GIT
value: "https://git.code.sf.net/p/gptfdisk/code"
}
- version: "d292ff36a3b350115835c62462911c3d8721704f"
+ version: "cb4bf320748f701a0ed835d4a410f2960f1ce0bd"
license_type: RESTRICTED
last_upgrade_date {
- year: 2020
- month: 2
- day: 10
+ year: 2023
+ month: 3
+ day: 15
}
}
diff --git a/Makefile b/Makefile
index 0d7309c..af9701c 100644
--- a/Makefile
+++ b/Makefile
@@ -1,30 +1,160 @@
-CFLAGS+=-D_FILE_OFFSET_BITS=64
-#CXXFLAGS+=-Wall -D_FILE_OFFSET_BITS=64 -D USE_UTF16
-CXXFLAGS+=-Wall -D_FILE_OFFSET_BITS=64
+# 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
+# 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....
+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
+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) -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) $(FATBINFLAGS) -o gdisk$(FN_EXTENSION)
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) $(CGDISK_LDLIBS) -o cgdisk$(FN_EXTENSION)
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) $(SGDISK_LDLIBS) $(THINBINFLAGS) -o sgdisk$(FN_EXTENSION)
fixparts: $(MBR_LIB_OBJS) fixparts.o
- $(CXX) $(MBR_LIB_OBJS) fixparts.o $(LDFLAGS) $(LDLIBS) -o fixparts
+ $(CXX) $(MBR_LIB_OBJS) fixparts.o $(LDFLAGS) $(FATBINFLAGS) -o fixparts$(FN_EXTENSION)
test:
./gdisk_test.sh
@@ -33,7 +163,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.freebsd b/Makefile.freebsd
index dace733..7223f2d 100644
--- a/Makefile.freebsd
+++ b/Makefile.freebsd
@@ -1,9 +1,8 @@
-CC=gcc
-CXX=g++
-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+=
+CXX=clang++
+#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.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/Makefile.mac b/Makefile.mac
index 27f95b7..91a281c 100644
--- a/Makefile.mac
+++ b/Makefile.mac
@@ -1,10 +1,11 @@
-CC=gcc
-CXX=clang++
-FATBINFLAGS=-arch x86_64 -arch i386 -mmacosx-version-min=10.4
-THINBINFLAGS=-arch x86_64 -mmacosx-version-min=10.4
-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 -I/opt/local/include -I /usr/local/include -I/opt/local/include -g
+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
+#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)
@@ -16,24 +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/lib/libncurses.dylib $(LDFLAGS) $(FATBINFLAGS) -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/NEWS b/NEWS
index ff54c6c..29d99e3 100644
--- a/NEWS
+++ b/NEWS
@@ -1,12 +1,176 @@
-1.0.5 (?/?/2020):
+1.0.10 (?/??/2023):
+-------------------
+
+- Fixed problem that caused sgdisk to crash with errors about being unable
+ to read the disk's partition table when compiled with the latest popt
+ (commit 740, which is pre-release as I type; presumably version 1.19 and
+ later once released).
+
+- Updated guid.cc to deal with minor change in libuuid.
+
+- Fixed potential NULL derefernce bug in sgdisk. Thanks to Damian Kurek
+ for this fix.
+
+- The partition number of "0" can now be used to reference newly-created
+ partitions when the --largest-new=0 option to sgdisk is used. Thanks to
+ David Joaquín Shourabi Porcel for this improvement.
+
+- Make explicit casts in gptcurses.cc to eliminate compiler warnings about
+ mis-matched types in printw() statements.
+
+- Minor code cleanup based on valgrind analysis.
+
+- In previous versions, rEFInd accepted only integer values for partition
+ start points, end points, and sizes, and it interpreted decimal values
+ incorrectly. That is, if you typed "+9.5G" as the partition end point,
+ you'd end up with something just 9 sectors in size. This version now
+ truncates decimal numbers to their integral values, so you'd get a 9 GiB
+ partition instead.
+
+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).
+
+- 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.
+
+- 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.
+
+- 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.
+
+- 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):
-----------------
+- 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.
+
+- Added type code for the Barebox boot loader (0xbb00;
+ 4778ED65-BF42-45FA-9C5B-287A1DC4AAB1).
+
+- Trivial code cleanup.
+
+1.0.7 (3/10/2021):
+------------------
+
+- Fixed bug that caused spurious warnings about the partition table
+ 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.
+
+- 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):
+------------------
+
+- Fixed bug that could cause segfault if GPT header claimed partition
+ 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. See:
+ https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-0308
+
+- 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 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):
+------------------
+
- Fixed typos and minor formatting issues in man pages
- Changed number of columns in type code output ("sgdisk -L" and equivalents
in gdisk and cgdisk) from 3 to 2, since some descriptions are long enough
that they're ambiguous with three columns.
+- Makefile change: Add $(LDLIBS) support to enable clean static builds (for
+ libintl).
+
+- You can now put the 0xEE partition last in a hybrid MBR using sgdisk.
+ (Previously, this was possible with gdisk but not with sgdisk.) See the
+ sgdisk man page for details.
+
+- Added numerous type codes for Container Linux, Veracrypt, and
+ Freedesktop.org's Discoverable Partitions Specification
+
+- Partition type name searches are now case-insensitive.
+
+- It's now possible to quit out of partition type name searches by typing
+ "q".
+
+- When changing a partition type code, the default is now the current
+ type code, not a platform-specific type code.
+
+- The UEFI GPT fdisk project
+ (https://sourceforge.net/projects/uefigptfdisk/) hasn't been updated since
+ 2016, and is now broken; binaries don't compile with modern GCC
+ toolchains, and even when dropping back to Ubuntu 14.04, which worked for
+ GPT fdisk 1.0.4, the resulting binary hangs on launch. Therefore, I'm
+ dropping support for the EFI build of gdisk, at least unless and until
+ UEFI GPT fdisk is fixed.
+
+- Apple no longer supports building i386 or "fat" binaries in XCode (or if
+ they do, they're making it hard), so I've removed that support. GPT fdisk
+ macOS binaries are now x86-64 only. Similarly, building now seems to
+ require macOS 10.9 or later, so that's now the minimum macOS version. I've
+ also re-built my Mac build environment and tweaked Makefile.mac
+ appropriately.
+
1.0.4 (7/5/2018):
-----------------
diff --git a/README b/README
index f1a091d..157abb8 100644
--- a/README
+++ b/README
@@ -161,15 +161,15 @@ 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, 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,56 +189,70 @@ 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/);
however, you'll first need to install the relevant environment
- (instructions exist on the relevant projects' pages). Alternatively, you
- can compile gdisk and/or cgdisk alone, without sgdisk; gdisk doesn't
- require popt.
+ (instructions exist on the relevant projects' pages). When I re-built my
+ Mac build environment in February of 2020, I found that brew was, by far,
+ the easiest of these to install. Some of the others seem to have been
+ abandoned, but I didn't investigate thoroughly. I'm leaving the references
+ in case they might be useful in the future. Instead of installing one of
+ These ports, you can compile gdisk and/or cgdisk alone, without sgdisk;
+ gdisk and cgdisk don't require popt.
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. (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
-------
-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
--------------
@@ -266,7 +280,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/README.Windows b/README.Windows
index 3f49023..d13bce3 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,92 @@ 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 "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
+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. 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
+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.
+
+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 Makefile. You can also strip the
+binaries ("make strip") to remove unused code.
diff --git a/attributes.cc b/attributes.cc
index bbd5aad..f3cd585 100644
--- a/attributes.cc
+++ b/attributes.cc
@@ -7,9 +7,7 @@
under the terms of the GNU GPL version 2, as detailed in the COPYING file. */
#define __STDC_LIMIT_MACROS
-#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
-#endif
#include
#include
diff --git a/attributes.h b/attributes.h
index f6c66ff..5eb57e3 100644
--- a/attributes.h
+++ b/attributes.h
@@ -1,20 +1,18 @@
/* 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 */
-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.cc b/basicmbr.cc
index e9ac5c5..e09b0e9 100644
--- a/basicmbr.cc
+++ b/basicmbr.cc
@@ -7,9 +7,7 @@
under the terms of the GNU GPL version 2, as detailed in the COPYING file. */
#define __STDC_LIMIT_MACROS
-#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
-#endif
#include
#include
@@ -142,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;
@@ -292,8 +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;
- if(partNum > 0) //don't go negative
- partNum -= 1;
+ if (partNum > 0) //don't go negative
+ partNum -= 1;
} // if
} // for
EbrLocations[partNum] = offset;
@@ -357,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) {
@@ -374,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;
@@ -950,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));
@@ -1057,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)) {
@@ -1310,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/basicmbr.h b/basicmbr.h
index 504e039..696f826 100644
--- a/basicmbr.h
+++ b/basicmbr.h
@@ -3,21 +3,19 @@
/* 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
#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.cc b/bsd.cc
index 59557c2..1ef7c81 100644
--- a/bsd.cc
+++ b/bsd.cc
@@ -7,9 +7,7 @@
under the terms of the GNU GPL version 2, as detailed in the COPYING file. */
#define __STDC_LIMIT_MACROS
-#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
-#endif
#include
//#include
@@ -46,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 != "") {
@@ -66,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/bsd.h b/bsd.h
index cbd3588..e042b7b 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,
@@ -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/cgdisk.8 b/cgdisk.8
index 3dbddff..bc83d4b 100644
--- a/cgdisk.8
+++ b/cgdisk.8
@@ -1,6 +1,6 @@
-.\" Copyright 2011-2018 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.4" "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"
@@ -25,7 +25,7 @@ disks.
For information on MBR vs. GPT, as well as GPT terminology and structure,
see the extended GPT fdisk documentation at
-\fIhttp://www.rodsbooks.com/gdisk/\fR or consult Wikipedia.
+\fIhttps://www.rodsbooks.com/gdisk/\fR or consult Wikipedia.
The \fBcgdisk\fR program employs a user interface similar to that of Linux's
\fBcfdisk\fR, but \fBcgdisk\fR modifies GPT partitions. It also has the
@@ -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
@@ -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
@@ -263,9 +268,9 @@ two\-byte hexadecimal number. You may also enter a GUID directly, if you
have one and \fBcgdisk\fR doesn't know it. If you don't know the type code
for your partition, you can type \fBL\fR to see a list of known type codes.
The type code list may optionally be filtered by a search string; for
-instance, entering \fI\fBLinux\fR\fR shows only partition type codes with
+instance, entering \fI\fBlinux\fR\fR shows only partition type codes with
descriptions that include the string \fILinux\fR. This search is performed
-case\-sensitively.
+case\-insensitively.
.TP
.B Verify
@@ -369,7 +374,7 @@ Contributors:
* Justin Maggard (justin.maggard@netgear.com)
-* Dwight Schauer (dschauer@gmail.com)
+* Dwight Schauer (das@teegra.net)
* Florian Zumbiehl (florz@florz.de)
@@ -384,11 +389,11 @@ Contributors:
.BR sgdisk (8),
.BR fixparts (8).
-\fIhttp://en.wikipedia.org/wiki/GUID_Partition_Table\fR
+\fIhttps://en.wikipedia.org/wiki/GUID_Partition_Table\fR
-\fIhttp://developer.apple.com/technotes/tn2006/tn2166.html\fR
+\fIhttps://developer.apple.com/technotes/tn2006/tn2166.html\fR
-\fIhttp://www.rodsbooks.com/gdisk/\fR
+\fIhttps://www.rodsbooks.com/gdisk/\fR
.SH "AVAILABILITY"
The \fBcgdisk\fR command is part of the \fIGPT fdisk\fR package and is
diff --git a/current.spec b/current.spec
index e61a0ae..a912894 100644
--- a/current.spec
+++ b/current.spec
@@ -1,12 +1,12 @@
Summary: GPT partitioning and MBR repair software
Name: gptfdisk
-Version: 1.0.4
+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.4.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
-* Thu Jul 5 2018 R Smith - 1.0.4
-- Created spec file for 1.0.4 release
+* Thu Apr 14 2022 R Smith - 1.0.9
+- Created spec file for 1.0.9 release
diff --git a/diskio-unix.cc b/diskio-unix.cc
index 6d3e5b1..0897c56 100644
--- a/diskio-unix.cc
+++ b/diskio-unix.cc
@@ -13,9 +13,7 @@
// under the terms of the GNU GPL version 2, as detailed in the COPYING file.
#define __STDC_LIMIT_MACROS
-#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
-#endif
#include
#include
@@ -39,6 +37,14 @@
using namespace std;
+#if defined(__APPLE__) || defined(__linux__)
+#define off64_t off_t
+#define stat64 stat
+#define fstat64 fstat
+#define lstat64 lstat
+#define lseek64 lseek
+#endif
+
// Returns the official "real" name for a shortened version of same.
// Trivial here; more important in Windows
void DiskIO::MakeRealName(void) {
@@ -374,7 +380,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....
@@ -426,7 +432,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__
diff --git a/diskio.cc b/diskio.cc
index 7a89d09..556138e 100644
--- a/diskio.cc
+++ b/diskio.cc
@@ -13,9 +13,7 @@
// under the terms of the GNU GPL version 2, as detailed in the COPYING file.
#define __STDC_LIMIT_MACROS
-#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
-#endif
#ifdef _WIN32
#include
diff --git a/diskio.h b/diskio.h
index 8521b8e..dec56ad 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
@@ -70,9 +68,9 @@ class DiskIO {
#ifdef ENABLE_HEAP_DISKIO
int OpenForRead(const unsigned char* data, size_t size);
#endif
- 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);
@@ -81,12 +79,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/fixparts.8 b/fixparts.8
index 9857b24..25d05ad 100644
--- a/fixparts.8
+++ b/fixparts.8
@@ -1,6 +1,6 @@
-.\" Copyright 2011-2018 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.4" "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"
@@ -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)
@@ -273,9 +273,9 @@ Contributors:
.BR gdisk (8),
.BR sgdisk (8).
-\fIhttp://en.wikipedia.org/wiki/Master_boot_record\fR
+\fIhttps://en.wikipedia.org/wiki/Master_boot_record\fR
-\fIhttp://www.rodsbooks.com/fixparts/\fR
+\fIhttps://www.rodsbooks.com/fixparts/\fR
.SH "AVAILABILITY"
The \fBfixparts\fR command is part of the \fIGPT fdisk\fR package and is
diff --git a/gdisk.8 b/gdisk.8
index dfdaa2c..8c9929b 100644
--- a/gdisk.8
+++ b/gdisk.8
@@ -1,6 +1,6 @@
-.\" Copyright 2011-2018 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.4" "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"
@@ -27,7 +27,7 @@ recovery options require you to understand the distinctions between the
main and backup data, as well as between the GPT headers and the partition
tables. For information on MBR vs. GPT, as well as GPT terminology and
structure, see the extended \fBgdisk\fR documentation at
-\fIhttp://www.rodsbooks.com/gdisk/\fR or consult Wikipedia.
+\fIhttps://www.rodsbooks.com/gdisk/\fR or consult Wikipedia.
The \fBgdisk\fR program employs a user interface similar to that of Linux's
\fBfdisk\fR, but \fBgdisk\fR modifies GPT partitions. It also has the
@@ -191,9 +191,9 @@ more codes in GPT. For these, \fBgdisk\fR adds code numbers sequentially,
such as 0xa500 for a FreeBSD disklabel, 0xa501 for FreeBSD boot, 0xa502 for
FreeBSD swap, and so on. Note that these two\-byte codes are unique to
\fBgdisk\fR. The type code list may optionally be filtered by a search
-string; for instance, entering \fI\fBLinux\fR\fR shows only partition type
+string; for instance, entering \fI\fBlinux\fR\fR shows only partition type
codes with descriptions that include the string \fILinux\fR. This search is
-performed case\-sensitively.
+performed case\-insensitively.
.TP
.B n
@@ -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
@@ -419,6 +420,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
@@ -483,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
@@ -673,7 +687,7 @@ Contributors:
* Justin Maggard (justin.maggard@netgear.com)
-* Dwight Schauer (dschauer@gmail.com)
+* Dwight Schauer (das@teegra.net)
* Florian Zumbiehl (florz@florz.de)
@@ -688,11 +702,11 @@ Contributors:
.BR sgdisk (8),
.BR fixparts (8).
-\fIhttp://en.wikipedia.org/wiki/GUID_Partition_Table\fR
+\fIhttps://en.wikipedia.org/wiki/GUID_Partition_Table\fR
-\fIhttp://developer.apple.com/technotes/tn2006/tn2166.html\fR
+\fIhttps://developer.apple.com/technotes/tn2006/tn2166.html\fR
-\fIhttp://www.rodsbooks.com/gdisk/\fR
+\fIhttps://www.rodsbooks.com/gdisk/\fR
.SH "AVAILABILITY"
The \fBgdisk\fR command is part of the \fIGPT fdisk\fR package and is
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.cc b/gpt.cc
index 8ab6975..e8e0878 100644
--- a/gpt.cc
+++ b/gpt.cc
@@ -3,13 +3,11 @@
/* 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
-#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
-#endif
#include
#include
@@ -82,6 +80,8 @@ GPTData::GPTData(void) {
beQuiet = 0;
whichWasUsed = use_new;
mainHeader.numParts = 0;
+ mainHeader.firstUsableLBA = 0;
+ mainHeader.lastUsableLBA = 0;
numParts = 0;
SetGPTSize(NUM_GPT_ENTRIES);
// Initialize CRC functions...
@@ -145,6 +145,7 @@ GPTData::GPTData(string filename) {
beQuiet = 0;
whichWasUsed = use_new;
mainHeader.numParts = 0;
+ mainHeader.lastUsableLBA = 0;
numParts = 0;
// Initialize CRC functions...
chksum_crc32gentab();
@@ -412,6 +413,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"
@@ -584,7 +590,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....
@@ -888,8 +894,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 {
@@ -1048,6 +1062,22 @@ int GPTData::LoadHeader(struct GPTHeader *header, DiskIO & disk, uint64_t sector
} // if
*crcOk = CheckHeaderCRC(&tempHeader);
+ if (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) {
allOK = SetGPTSize(tempHeader.numParts, 0);
}
@@ -2135,7 +2165,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++);
@@ -2148,7 +2177,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--);
@@ -2327,18 +2355,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
@@ -2415,7 +2453,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;
@@ -2445,7 +2486,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/gpt.h b/gpt.h
index 0712a1f..6e1e0bb 100644
--- a/gpt.h
+++ b/gpt.h
@@ -1,9 +1,12 @@
/* 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
+#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
@@ -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,19 +109,19 @@ public:
int FindInsanePartitions(void);
// Load or save data from/to disk
- int SetDisk(const string & deviceFilename);
+ int SetDisk(const std::string & deviceFilename);
int SetDisk(const DiskIO & disk);
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);
@@ -186,7 +184,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);
@@ -205,9 +203,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 cb1701d..8162868 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
@@ -25,10 +25,13 @@
#include
#include "gptcl.h"
+using namespace std;
+
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
@@ -63,6 +66,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;
@@ -75,6 +79,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"},
@@ -87,6 +92,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", ""},
@@ -149,9 +155,10 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
// Assume first non-option argument is the device filename....
device = (char*) poptGetArg(poptCon);
- poptResetContext(poptCon);
if (device != NULL) {
+ device = strdup(device);
+ poptResetContext(poptCon);
JustLooking(); // reset as necessary
BeQuiet(); // Tell called functions to be less verbose & interactive
if (LoadPartitions((string) device)) {
@@ -190,17 +197,24 @@ 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);
break;
case 'c':
- cout << "Setting name!\n";
JustLooking(0);
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())) {
@@ -262,6 +276,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);
@@ -297,9 +314,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 {
@@ -313,9 +330,11 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
JustLooking(0);
startSector = FindFirstInLargest();
Align(&startSector);
- endSector = FindLastInFree(startSector);
- if (largestPartNum <= 0)
+ endSector = FindLastInFree(startSector, alignEnd);
+ if (largestPartNum <= 0) {
largestPartNum = FindFirstFreePart() + 1;
+ newPartNum = largestPartNum - 1;
+ }
if (CreatePartition(largestPartNum - 1, startSector, endSector)) {
saveData = 1;
} else {
@@ -379,7 +398,7 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
typeRaw[partNum] = StrToHex(raw, 0);
}
typeHelper = GetString(typeCode, 2);
- if ((typeHelper != (GUIDData) "00000000-0000-0000-0000-000000000000") &&
+ if ((typeHelper != PartType::unusedPartType) &&
(ChangePartType(partNum, typeHelper))) {
saveData = 1;
} else {
@@ -486,6 +505,7 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
cerr << "Error encountered; not saving changes.\n";
retval = 4;
} // if
+ free(device);
} // if (device != NULL)
poptFreeContext(poptCon);
return retval;
@@ -494,7 +514,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 d8fa9ff..b937430 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
@@ -26,8 +26,6 @@
#include
#include