Upgrade gptfdisk to d292ff36a3
Change 2c2deeb032 is reverted in this
merge. Because it conflicts with upstream option "move-main-table".
Change-Id: I2c1cb67a95139879333a430eb0e8b34f6b396c32
This commit is contained in:
6
METADATA
6
METADATA
@@ -9,10 +9,10 @@ third_party {
|
||||
type: GIT
|
||||
value: "https://git.code.sf.net/p/gptfdisk/code"
|
||||
}
|
||||
version: "a920398fa393f9d6301b32b191bc01e086ab8bc8"
|
||||
version: "d292ff36a3b350115835c62462911c3d8721704f"
|
||||
last_upgrade_date {
|
||||
year: 2015
|
||||
year: 2020
|
||||
month: 2
|
||||
day: 20
|
||||
day: 10
|
||||
}
|
||||
}
|
||||
|
||||
14
Makefile
14
Makefile
@@ -1,5 +1,3 @@
|
||||
CC=gcc
|
||||
CXX=g++
|
||||
CFLAGS+=-D_FILE_OFFSET_BITS=64
|
||||
#CXXFLAGS+=-Wall -D_FILE_OFFSET_BITS=64 -D USE_UTF16
|
||||
CXXFLAGS+=-Wall -D_FILE_OFFSET_BITS=64
|
||||
@@ -14,19 +12,22 @@ DEPEND= makedepend $(CXXFLAGS)
|
||||
all: cgdisk gdisk sgdisk fixparts
|
||||
|
||||
gdisk: $(LIB_OBJS) gdisk.o gpttext.o
|
||||
$(CXX) $(LIB_OBJS) gdisk.o gpttext.o $(LDFLAGS) -luuid -o gdisk
|
||||
$(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 -o cgdisk
|
||||
$(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 -o sgdisk
|
||||
$(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) -o fixparts
|
||||
$(CXX) $(MBR_LIB_OBJS) fixparts.o $(LDFLAGS) $(LDLIBS) -o fixparts
|
||||
|
||||
test:
|
||||
./gdisk_test.sh
|
||||
|
||||
lint: #no pre-reqs
|
||||
lint $(SRCS)
|
||||
@@ -41,4 +42,5 @@ depend: $(SRCS)
|
||||
$(OBJS):
|
||||
$(CRITICAL_CXX_FLAGS)
|
||||
|
||||
# makedepend dependencies below -- type "makedepend *.cc" to regenerate....
|
||||
# DO NOT DELETE
|
||||
|
||||
21
Makefile.mac
21
Makefile.mac
@@ -1,8 +1,10 @@
|
||||
CC=gcc
|
||||
CXX=g++
|
||||
CFLAGS=-O2 -D_FILE_OFFSET_BITS=64 -g
|
||||
#CXXFLAGS=-O2 -Wall -D_FILE_OFFSET_BITS=64 -D USE_UTF16 -I/sw/include -I/usr/local/include -I/opt/local/include -g
|
||||
CXXFLAGS=-O2 -Wall -D_FILE_OFFSET_BITS=64 -I/sw/include -I /usr/local/include -I/opt/local/include -g
|
||||
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
|
||||
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)
|
||||
@@ -14,19 +16,20 @@ DEPEND= makedepend $(CFLAGS)
|
||||
all: gdisk sgdisk cgdisk fixparts
|
||||
|
||||
gdisk: $(LIB_OBJS) gpttext.o gdisk.o
|
||||
$(CXX) $(LIB_OBJS) gpttext.o gdisk.o -o gdisk
|
||||
$(CXX) $(LIB_OBJS) gpttext.o gdisk.o $(FATBINFLAGS) -o gdisk
|
||||
# $(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 $(LDFLAGS) -lncurses -o cgdisk
|
||||
$(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
|
||||
|
||||
sgdisk: $(LIB_OBJS) gptcl.o sgdisk.o
|
||||
$(CXX) $(LIB_OBJS) gptcl.o sgdisk.o -L/sw/lib -lpopt -o sgdisk
|
||||
# $(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
|
||||
|
||||
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
|
||||
|
||||
testguid: $(LIB_OBJS) testguid.o
|
||||
$(CXX) $(LIB_OBJS) testguid.o -o testguid
|
||||
@@ -35,7 +38,7 @@ lint: #no pre-reqs
|
||||
lint $(SRCS)
|
||||
|
||||
clean: #no pre-reqs
|
||||
rm -f core *.o *~ gdisk sgdisk
|
||||
rm -f core *.o *~ gdisk sgdisk cgdisk fixparts
|
||||
|
||||
# what are the source dependencies
|
||||
depend: $(SRCS)
|
||||
|
||||
222
NEWS
222
NEWS
@@ -1,6 +1,224 @@
|
||||
0.8.11 (?/?/2014):
|
||||
1.0.5 (?/?/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.
|
||||
|
||||
1.0.4 (7/5/2018):
|
||||
-----------------
|
||||
|
||||
- Added some explicit copy constructors and made some other tweaks to avoid
|
||||
compiler warnings.
|
||||
|
||||
- The macOS binary for sgdisk is now a pure 64-bit build; I'm no longer
|
||||
supporting 32-bit builds of sgdisk. The gdisk and cgdisk binaries remain
|
||||
"fat" 32-/64-bit builds. The reason for dropping the 32-bit support from
|
||||
sgdisk is that I've re-built my macOS development system, and I had
|
||||
trouble building a "fat" binary with the fresh install of the popt
|
||||
libraries upon which sgdisk relies. 32-bit support for the other binaries
|
||||
is now officially deprecated, too.
|
||||
|
||||
- Added search feature to partition type list functions ("L" on main menu of
|
||||
gdisk and "L" when entered in response to the "Hex code or GUID" prompt in
|
||||
gdisk and sgdisk). This feature filters the partition type list to those
|
||||
which include the search term in their GPT fdisk descriptions. For
|
||||
instance, typing "Linux" shows only partitions with "Linux" in their
|
||||
descriptions. Note that the search/filter is case-sensitive. If <Enter> is
|
||||
pressed, no filter is applied.
|
||||
|
||||
- Change to Makefile.mac to use standard libncurses rather than a 3rd-party
|
||||
version; should help with cgdisk compatibility.
|
||||
|
||||
- Minor bug fix in alignment of internal data structures.
|
||||
|
||||
- Minor bug fix in handling of damaged disks. Also, GPT fdisk now reports
|
||||
more information on what data structures are damaged when a damaged disk
|
||||
is detected.
|
||||
|
||||
- Added type code for Apple APFS (7C3457EF-0000-11AA-AA11-00306543ECAC,
|
||||
0xaf0a).
|
||||
|
||||
- Added type code for Atari TOS basic data (0xa200,
|
||||
734E5AFE-F61A-11E6-BC64-92361F002671).
|
||||
|
||||
- Added type codes for Linux dm-crypt (0x8308,
|
||||
7FFEC5C9-2D00-49B7-8941-3EA10A5586B7) and LUKS (0x8309,
|
||||
CA7D7CCB-63ED-4C53-861C-1742536059CC) partitions.
|
||||
|
||||
- Added 18 Ceph partition type codes.
|
||||
|
||||
- Added 52 (yes, 52!) Android partition type codes.
|
||||
|
||||
- Changed "Creating new GPT entries" message to read "Creating new
|
||||
GPT entries in memory" because the latter is clearer, particularly when
|
||||
using sgdisk with a non-destructive option, like "-p".
|
||||
|
||||
1.0.3 (7/27/2017):
|
||||
------------------
|
||||
|
||||
- Fixed a major bug that caused invalid partition tables to be generated
|
||||
when creating a new partition table (that is, partitioning a blank disk or
|
||||
converting from MBR).
|
||||
|
||||
1.0.2 (7/26/2017):
|
||||
------------------
|
||||
|
||||
- On Linux, the p/-p/--print command now shows the disk's model name, as
|
||||
reported in /sys/block/sda/device/model (or equivalent filenames for other
|
||||
disks). This feature does not yet work on other platforms, on which the
|
||||
model name line is omitted from the output. This line is also not shown
|
||||
when accessing disk image files, even on Linux.
|
||||
|
||||
- GPT fdisk can now report both the physical and logical sector sizes of
|
||||
disks, but only on 2.6.32 and later Linux kernels. The verify feature now
|
||||
uses the larger of the set alignment and physical/logical block sizes for
|
||||
testing alignment, and setting alignment to something other than an exact
|
||||
multiple of the ratio of the physical to logical block size results in a
|
||||
warning.
|
||||
|
||||
- Addition of new verification checks, mostly (but not exclusively) related
|
||||
to the new j/-j/--move-main-table option.
|
||||
|
||||
- Added new option: 'j' on the experts' menu in gdisk;
|
||||
'-j/--move-main-table={sector}' in sgdisk. This option enables relocating
|
||||
the main partition table from sector 2 (the default location) to somewhere
|
||||
else on the disk. The main reason I know of to do this is if the disk is
|
||||
to be used with a system-on-chip (SoC) computer, some of which require the
|
||||
boot loader to be located at sector 2. If you pass this option the default
|
||||
value of 2, it has the effect of reducing the padding placed between the
|
||||
main partition table and the first usable sector value created by the
|
||||
Linux fdisk tool.
|
||||
|
||||
- Updated man pages with new recommendations for ESP and BIOS Boot Partition
|
||||
sizes.
|
||||
|
||||
- Added four type codes (AF06 through AF09) for Apple SoftRAID (Status,
|
||||
Scratch, Volume, and Cache).
|
||||
|
||||
- Added two type codes for the Open Network Install Environment (ONIE):
|
||||
0xe100 (7412F7D5-A156-4B13-81DC-867174929325) and 0xe101
|
||||
(D4E6E2CD-4469-46F3-B5CB-1BFF57AFC149).
|
||||
|
||||
- Added thirteen type codes for Android partitions (0xa000 through
|
||||
0xa00c).
|
||||
|
||||
- Added type code for QNX6 (aka QNX Power-Safe) filesystem: 0xb300, for
|
||||
CEF5A9AD-73BC-4601-89F3-CDEEEEE321A1.
|
||||
|
||||
- Removed stray debug message ("REALLY setting name!") from sgdisk,
|
||||
when setting new name via -c option.
|
||||
|
||||
1.0.1 (10/18/2015):
|
||||
-------------------
|
||||
|
||||
- Created uninstall-fixparts and uninstall-gdisk scripts for OS X. As the
|
||||
names imply, these scripts remove the files installed by the fixparts and
|
||||
gdisk packages, respectively.
|
||||
|
||||
- Fixed bug that caused -N/--largest-new option to sgdisk to fail when
|
||||
fed a "0" option.
|
||||
|
||||
- Fixed bug that caused input glitches in EFI version of gdisk.
|
||||
|
||||
- Fixed bug that caused sgdisk to not return an appropriate error code
|
||||
when it encountered a write error when saving changes.
|
||||
|
||||
- Fixed bug that caused cgdisk's "Info" display to under-report the
|
||||
partition's size by one sector.
|
||||
|
||||
- OS X 10.11 includes new security features that prevent GPT fdisk from
|
||||
working unless these features are disabled. To do so, you must boot to a
|
||||
Recovery HD system, open a Terminal, type "csrutil disable", and reboot
|
||||
into the normal system. You can re-enable the security features by
|
||||
repeating the process, but specify "enable" rather than "disable". I've
|
||||
added a message pointing users to a Web page explaining how to disable
|
||||
this feature when gdisk detects that it can't write to the disk under OS
|
||||
X. If you know of a way around this (including code changes to gdisk),
|
||||
please contact me.
|
||||
|
||||
- I've updated the OS X installation location from the Unix-standard
|
||||
/usr/sbin (and related locations for documentation) to /usr/local/bin
|
||||
(and related locations for documentation). This is Just Plain Crazy from
|
||||
a Unix point of view, but Apple has to be Apple and do things just a
|
||||
little bit differently.
|
||||
|
||||
- I've updated my OS X environment to OS X 10.11 and LLVM 7.0.0. This has
|
||||
also meant installing fresh versions of popt and ncurses from MacPorts,
|
||||
which may require upgrading popt to get sgdisk working on some systems.
|
||||
(gdisk, cgdisk, and fixparts should continue to work normally on all
|
||||
systems.) The OS X binaries are now "fat" (32- and 64-bit) versions,
|
||||
which should have no noticeable effect unless you have a Mac with broken
|
||||
32-bit support, in which case the binaries will now work.
|
||||
|
||||
- Changed the default name of 0xab00 partitions from "Apple boot" to
|
||||
"Recovery HD", since the latter is the name that Apple gives these
|
||||
partitions. Also, I discovered through painful experience that OS X
|
||||
flakes out and won't boot if the name is something other than "Recovery
|
||||
HD", so it really has to have the right name!
|
||||
|
||||
- Changed the OpenBSD type codes (0xa600 and 0xa601): 0xa600 is now
|
||||
824CC7A0-36A8-11E3-890A-952519AD3F61 (OpenBSD disklabel) and 0xa601 is
|
||||
now gone. Previously, 0xa600 was 516E7CB4-6ECF-11D6-8FF8-00022D09712B, a
|
||||
duplicate of the FreeBSD disklabel, and 0xa601 was
|
||||
824CC7A0-36A8-11E3-890A-952519AD3F61. OpenBSD is now officially
|
||||
supporting 824CC7A0-36A8-11E3-890A-952519AD3F61 as a disklabel type,
|
||||
though. It's unclear what, if anything, OpenBSD will use for
|
||||
non-disklabel type codes at the moment.
|
||||
|
||||
- Added GUID 0311FC50-01CA-4725-AD77-9ADBB20ACE98 (0xbc00) for
|
||||
Acronis Secure Zone backup partitions.
|
||||
|
||||
- Fixed bug that caused random crashes on ppc64el systems (and perhaps
|
||||
others).
|
||||
|
||||
- Added GUID C91818F9-8025-47AF-89D2-F030D7000C2C (0x3900) for Plan 9.
|
||||
|
||||
- Added GUID 69DAD710-2CE4-4E3C-B16C-21A1D49ABED3 (0x8307) for 32-bit ARM
|
||||
Linux root (/) partition, as per the Freedesktop.org Discoverable
|
||||
Partition Spec
|
||||
(http://www.freedesktop.org/wiki/Specifications/DiscoverablePartitionsSpec/).
|
||||
|
||||
- Edited man pages to clarify that default alignment is to 1MiB boundaries;
|
||||
this translates to 2048 sectors on disks with 512-byte sectors, but it
|
||||
will be something else on disks with other sector sizes.
|
||||
|
||||
- Changed behavior of -z/--zap and -Z/--zap-all options to sgdisk so that
|
||||
if a subsequent command causes changes, they'll be written to disk.
|
||||
Previously, doing something like "sgdisk --zap-all --clear /dev/sdd"
|
||||
would wipe the disk but not create a partition table; to create a blank
|
||||
table you'd need to do "sgdisk --zap-all --clear --mbrtogpt /dev/sdd",
|
||||
which is a bit odd and counter-intuitive, to the point of arguably being
|
||||
a bug.
|
||||
|
||||
1.0.0 (3/16/2015):
|
||||
------------------
|
||||
|
||||
- I'm now building a binary package of gdisk_x64.efi, using the UEFI GPT
|
||||
fdisk package.
|
||||
|
||||
- Added partition type for OpenBSD data
|
||||
(824CC7A0-36A8-11E3-890A-952519AD3F61/0xa601). Also mapped 0xa600 to the
|
||||
FreeBSD disklabel type code (516E7CB4-6ECF-11D6-8FF8-00022D09712B). I'm
|
||||
not sure that's 100% correct, but since I can't find references to an
|
||||
OpenBSD disklabel GPT type code, it seems the best choice at the moment.
|
||||
|
||||
- Added partition type for Windows Storage Spaces
|
||||
(E75CAF8F-F680-4CEE-AFA3-B001E56EFC2D/0x4202)
|
||||
|
||||
- Added -O/--print-mbr option to sgdisk, enabling easier display of MBR
|
||||
data structures without invoking gdisk.
|
||||
|
||||
- Updated warning message: "EBR describes a logical partition" now reads
|
||||
"EBR points to an EBR," which is more technically correct.
|
||||
|
||||
- Altered warning displayed when run from Windows on non-GPT disk, because
|
||||
Windows on UEFI-based systems is becoming more common.
|
||||
|
||||
- Fixed spurious "1" return value in gdisk.
|
||||
|
||||
- Small code changes to support compilation as EFI application with the
|
||||
UEFI GPT fdisk library
|
||||
(http://sourceforge.net/projects/uefigptfdisk/?source=directory)
|
||||
@@ -9,7 +227,7 @@
|
||||
(https://github.com/ceph/ceph/blob/9bcc42a3e6b08521694b5c0228b2c6ed7b3d312e/src/ceph-disk#L76-L81):
|
||||
4FBD7E29-9D25-41B8-AFD0-062C0CEFF05D/0xf800 (Ceph OSD),
|
||||
4FBD7E29-9D25-41B8-AFD0-5EC00CEFF05D/0xf801 (Ceph dm-crypt OSD),
|
||||
BFBFAFE7-A34F-448A-9A5B-6213EB736C22/0xf802 (Ceph journal),
|
||||
45B0969E-9B03-4F30-B4C6-B4B80CEFF106/0xf802 (Ceph journal),
|
||||
45B0969E-9B03-4F30-B4C6-5EC00CEFF106/0xf803 (Ceph dm-crypt journal),
|
||||
89C57F98-2FE5-4DC0-89C1-F3AD0CEFF2BE/0xf804 (Ceph disk in creation), and
|
||||
89C57F98-2FE5-4DC0-89C1-5EC00CEFF2BE/0xf805 (Ceph dm-crypt disk in
|
||||
|
||||
340
NOTICE
340
NOTICE
@@ -1,340 +0,0 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Library General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
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
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Library General
|
||||
Public License instead of this License.
|
||||
18
README
18
README
@@ -200,11 +200,13 @@ be used instead. In addition, note these requirements:
|
||||
(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
|
||||
popt for Mac OS from Darwin Ports (http://popt.darwinports.com) or Fink
|
||||
(http://www.finkproject.org); however, you'll first need to install
|
||||
DarwinPorts or Fink (instructions exist on the relevant projects' pages).
|
||||
Alternatively, you can compile gdisk and/or cgdisk alone, without sgdisk;
|
||||
gdisk doesn't require popt.
|
||||
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.
|
||||
|
||||
When all the necessary development tools and libraries are installed, you
|
||||
can uncompress the package and type "make" at the command prompt in the
|
||||
@@ -234,9 +236,9 @@ virtual QEMU and VirtualBox disks. I've received user reports of success with
|
||||
RAID arrays over 2TiB in size, though.
|
||||
|
||||
My main development platform is a system running the 64-bit version of
|
||||
Gentoo Linux. I've also tested on several other 32- and 64-bit Linux
|
||||
distributions, Intel-based Mac OS X 10.5 and 10.6, 64-bit FreeBSD 7.1, and
|
||||
Windows 7.
|
||||
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.
|
||||
|
||||
Redistribution
|
||||
--------------
|
||||
|
||||
132
README-efi.txt
Normal file
132
README-efi.txt
Normal file
@@ -0,0 +1,132 @@
|
||||
README for EFI version of GPT fdisk
|
||||
===================================
|
||||
|
||||
GPT fdisk for EFI is a binary build of gdisk to run as a pre-boot EFI
|
||||
application. It's OS-independent and may be used to check or recover
|
||||
partition tables before installing or booting an OS. It may be used to
|
||||
overcome boot problems caused by partition table damage or to prepare a
|
||||
partition table prior to installing an OS.
|
||||
|
||||
Installing GPT fdisk for EFI
|
||||
----------------------------
|
||||
|
||||
The contents of this archive are:
|
||||
|
||||
- COPYING -- The GNU GPL
|
||||
- gdisk.html -- The gdisk man page, in HTML form
|
||||
- gdisk_x64.efi -- The gdisk binary, built for EFI (x86-64 CPU)
|
||||
- NEWS -- The GPT fdisk changelog
|
||||
- README-efi.txt -- This file
|
||||
- refind.cer -- The rEFInd public key, .cer (DER) form
|
||||
- refind.crt -- The rEFInd public key, .crt form
|
||||
|
||||
The gdisk_x64.efi binary included here is built using the UEFI GPT fdisk
|
||||
library (https://sourceforge.net/p/uefigptfdisk/), which is a beta-level
|
||||
partial C++ library for UEFI. To use it, you must copy it to your EFI
|
||||
System Partition (ESP) or some other EFI-accessible location. Under Linux,
|
||||
the ESP is usually one of the first two or three partitions on /dev/sda.
|
||||
Under OS X, it's usually the first partition on /dev/disk0 (that is,
|
||||
/dev/disk0s1). Under Windows, you can mount it to S: by typing "mountvol S:
|
||||
/S" in an Administrator command prompt. In any of these cases, the
|
||||
recommended location for gdisk_x64.efi is the EFI/tools directory on the
|
||||
ESP. In that location, my rEFInd boot manager will detect the gdisk binary
|
||||
and create a menu option to launch it. If you don't use rEFInd, you can
|
||||
launch the program using an EFI shell, register it as a boot program with
|
||||
your firmware, or configure your boot manager (GRUB, gummiboot, etc.) to
|
||||
launch it. Note that boot LOADERS, such as SYSLINUX and ELILO, can't launch
|
||||
gdisk.
|
||||
|
||||
Alternatively, you can create a USB flash drive that will launch gdisk when
|
||||
you boot from it. To do so, create a FAT filesystem on a partition on a USB
|
||||
flash drive and copy gdisk_x64.efi to it as EFI/BOOT/bootx64.efi. (You'll
|
||||
need to create the EFI/BOOT directory.) Some systems may require the FAT
|
||||
filesystem to be flagged as an ESP (with a type code of EF00 in gdisk). You
|
||||
can use your firmware's built-in boot manager to boot from the USB flash
|
||||
drive. Some such boot managers present two options for booting USB flash
|
||||
drives. If yours does this, select the option that includes the string
|
||||
"UEFI" in the description.
|
||||
|
||||
The gdisk_x64.efi binary is signed with the rEFInd Secure Boot key. Thus,
|
||||
if you're launching a rEFInd that I've compiled and distributed myself,
|
||||
gdisk should launch, too. If you're *NOT* running rEFInd but ARE using
|
||||
Shim, you'll need to add the refind.cer file to your MOK list by using the
|
||||
MokManager utility. If you're using Secure Boot and you've signed rEFInd
|
||||
yourself, you'll need to sign gdisk_x64.efi yourself, too. Note that the
|
||||
rEFInd PPA distributes unsigned binaries and signs them with a local key
|
||||
stored in /etc/refind/keys. To copy and sign the gdisk_x64.efi binary, you
|
||||
should type (as root or using sudo):
|
||||
|
||||
sbsign --key /etc/refind.d/keys/refind_local.key \
|
||||
--cert /etc/refind.d/keys/refind.crt \
|
||||
--output /boot/efi/EFI/tooks/gdisk_x64.efi ./gdisk_x64.efi
|
||||
|
||||
This command assumes you have local rEFInd keys stored in the locations
|
||||
created by the rEFInd installation script. Substitute your own keys if
|
||||
you've built them in some other way. Some distributions don't provide the
|
||||
sbsign binary, so you may need to build it yourself. See the following page
|
||||
for details:
|
||||
|
||||
https://git.kernel.org/cgit/linux/kernel/git/jejb/sbsigntools.git/
|
||||
|
||||
Note that you do *NOT* need to sign gdisk if your computer doesn't use
|
||||
Secure Boot or if you've disabled this feature.
|
||||
|
||||
Using gdisk for EFI
|
||||
-------------------
|
||||
|
||||
The EFI version of gdisk is basically the same as using the Linux, OS X, or
|
||||
other OS versions. One exception is that you do not specify a disk device
|
||||
on the command line; gdisk for EFI instead displays a list of devices when
|
||||
you launch and enables you to select one, as in:
|
||||
|
||||
List of hard disks found:
|
||||
1: Disk EFI_HANDLE(3EB5DD98): 108423424 sectors, 51.7 GiB
|
||||
Acpi(PNP0A03,0)/Pci(1|1)/Ata(Primary,Master)
|
||||
2: Disk EFI_HANDLE(3EB58289): 105456768 sectors, 50.3 GiB
|
||||
Acpi(PNP0A03,0)/Pci(D|0)?
|
||||
|
||||
Disk number (1-2): 2
|
||||
|
||||
Once you've selected your disk, it should operate in much the same way as
|
||||
any other version of gdisk. (See the next section, though!) Some programs,
|
||||
including my rEFInd boot manager, complain about the changed partition
|
||||
table, even if you've made no changes. If you run into problems using other
|
||||
programs or launching an OS immediately after running gdisk, reboot; that
|
||||
should cause the firmware to re-load its partition table.
|
||||
|
||||
Caveats
|
||||
-------
|
||||
|
||||
I've tested gdisk_x64.efi on several systems. It's worked fine for me on 4
|
||||
of 6 computers (5 of 7, counting VirtualBox). Two systems gave me problems,
|
||||
though:
|
||||
|
||||
* gdisk presented a never-ending list of options (as if receiving a
|
||||
never-ending string of "?" or other unrecognized command characters) on a
|
||||
2014 MacBook Air.
|
||||
* A computer based on an Intel DG43NB motherboard rebooted as soon as I
|
||||
launched gdisk.
|
||||
|
||||
Both computers have relatively old EFIs. (Despite its newness, the Mac has
|
||||
a 1.10 EFI, as do all Macs, to the best of my knowledge.) Most of the
|
||||
computers that worked had 2.31 EFIs, although one had a 2.10 EFI.
|
||||
|
||||
The bottom line is that I can't guarantee that this binary will work on all
|
||||
computers. It's conceivable that recompiling gdisk with the latest version
|
||||
of the UEFI GPT fdisk library will help. Also, I haven't compiled a 32-bit
|
||||
version, so if you have a 32-bit EFI, you'll have to compile it yourself or
|
||||
do without.
|
||||
|
||||
References
|
||||
----------
|
||||
|
||||
The following sites have useful additional information:
|
||||
|
||||
UEFI GPT fdisk:
|
||||
https://sourceforge.net/projects/uefigptfdisk/
|
||||
|
||||
sbsigntools git repository:
|
||||
https://git.kernel.org/cgit/linux/kernel/git/jejb/sbsigntools.git/
|
||||
|
||||
rEFInd:
|
||||
http://www.rodsbooks.com/refind/
|
||||
88
basicmbr.cc
88
basicmbr.cc
@@ -45,6 +45,36 @@ BasicMBRData::BasicMBRData(void) {
|
||||
EmptyMBR();
|
||||
} // BasicMBRData default constructor
|
||||
|
||||
BasicMBRData::BasicMBRData(const BasicMBRData & orig) {
|
||||
int i;
|
||||
|
||||
if (&orig != this) {
|
||||
memcpy(code, orig.code, 440);
|
||||
diskSignature = orig.diskSignature;
|
||||
nulls = orig.nulls;
|
||||
MBRSignature = orig.MBRSignature;
|
||||
blockSize = orig.blockSize;
|
||||
diskSize = orig.diskSize;
|
||||
numHeads = orig.numHeads;
|
||||
numSecspTrack = orig.numSecspTrack;
|
||||
canDeleteMyDisk = orig.canDeleteMyDisk;
|
||||
device = orig.device;
|
||||
state = orig.state;
|
||||
|
||||
myDisk = new DiskIO;
|
||||
if (myDisk == NULL) {
|
||||
cerr << "Unable to allocate memory in BasicMBRData copy constructor! Terminating!\n";
|
||||
exit(1);
|
||||
} // if
|
||||
if (orig.myDisk != NULL)
|
||||
myDisk->OpenForRead(orig.myDisk->GetName());
|
||||
|
||||
for (i = 0; i < MAX_MBR_PARTS; i++) {
|
||||
partitions[i] = orig.partitions[i];
|
||||
} // for
|
||||
} // if
|
||||
} // BasicMBRData copy constructor
|
||||
|
||||
BasicMBRData::BasicMBRData(string filename) {
|
||||
blockSize = SECTOR_SIZE;
|
||||
diskSize = 0;
|
||||
@@ -75,29 +105,31 @@ BasicMBRData::~BasicMBRData(void) {
|
||||
BasicMBRData & BasicMBRData::operator=(const BasicMBRData & orig) {
|
||||
int i;
|
||||
|
||||
memcpy(code, orig.code, 440);
|
||||
diskSignature = orig.diskSignature;
|
||||
nulls = orig.nulls;
|
||||
MBRSignature = orig.MBRSignature;
|
||||
blockSize = orig.blockSize;
|
||||
diskSize = orig.diskSize;
|
||||
numHeads = orig.numHeads;
|
||||
numSecspTrack = orig.numSecspTrack;
|
||||
canDeleteMyDisk = orig.canDeleteMyDisk;
|
||||
device = orig.device;
|
||||
state = orig.state;
|
||||
if (&orig != this) {
|
||||
memcpy(code, orig.code, 440);
|
||||
diskSignature = orig.diskSignature;
|
||||
nulls = orig.nulls;
|
||||
MBRSignature = orig.MBRSignature;
|
||||
blockSize = orig.blockSize;
|
||||
diskSize = orig.diskSize;
|
||||
numHeads = orig.numHeads;
|
||||
numSecspTrack = orig.numSecspTrack;
|
||||
canDeleteMyDisk = orig.canDeleteMyDisk;
|
||||
device = orig.device;
|
||||
state = orig.state;
|
||||
|
||||
myDisk = new DiskIO;
|
||||
if (myDisk == NULL) {
|
||||
cerr << "Unable to allocate memory in BasicMBRData::operator=()! Terminating!\n";
|
||||
exit(1);
|
||||
myDisk = new DiskIO;
|
||||
if (myDisk == NULL) {
|
||||
cerr << "Unable to allocate memory in BasicMBRData::operator=()! Terminating!\n";
|
||||
exit(1);
|
||||
} // if
|
||||
if (orig.myDisk != NULL)
|
||||
myDisk->OpenForRead(orig.myDisk->GetName());
|
||||
|
||||
for (i = 0; i < MAX_MBR_PARTS; i++) {
|
||||
partitions[i] = orig.partitions[i];
|
||||
} // for
|
||||
} // if
|
||||
if (orig.myDisk != NULL)
|
||||
myDisk->OpenForRead(orig.myDisk->GetName());
|
||||
|
||||
for (i = 0; i < MAX_MBR_PARTS; i++) {
|
||||
partitions[i] = orig.partitions[i];
|
||||
} // for
|
||||
return *this;
|
||||
} // BasicMBRData::operator=()
|
||||
|
||||
@@ -298,7 +330,7 @@ int BasicMBRData::ReadLogicalParts(uint64_t extendedStart, int partNum) {
|
||||
// the logical partition when this is the case....
|
||||
ebrType = ebr.partitions[0].partitionType;
|
||||
if ((ebrType == 0x05) || (ebrType == 0x0f) || (ebrType == 0x85)) {
|
||||
cout << "EBR describes a logical partition!\n";
|
||||
cout << "EBR points to an EBR!\n";
|
||||
offset = extendedStart + ebr.partitions[0].firstLBA;
|
||||
} else {
|
||||
// Copy over the basic data....
|
||||
@@ -1499,11 +1531,11 @@ uint64_t BasicMBRData::GetFirstSector(int i) {
|
||||
uint64_t retval;
|
||||
|
||||
thePart = GetPartition(i);
|
||||
if (thePart != NULL) {
|
||||
if (thePart != NULL)
|
||||
retval = thePart->GetStartLBA();
|
||||
} else
|
||||
else
|
||||
retval = UINT32_C(0);
|
||||
return retval;
|
||||
return retval;
|
||||
} // BasicMBRData::GetFirstSector()
|
||||
|
||||
uint64_t BasicMBRData::GetLength(int i) {
|
||||
@@ -1511,11 +1543,11 @@ uint64_t BasicMBRData::GetLength(int i) {
|
||||
uint64_t retval;
|
||||
|
||||
thePart = GetPartition(i);
|
||||
if (thePart != NULL) {
|
||||
if (thePart != NULL)
|
||||
retval = thePart->GetLengthLBA();
|
||||
} else
|
||||
else
|
||||
retval = UINT64_C(0);
|
||||
return retval;
|
||||
return retval;
|
||||
} // BasicMBRData::GetLength()
|
||||
|
||||
/***********************
|
||||
|
||||
@@ -34,6 +34,7 @@ struct TempMBR {
|
||||
struct MBRRecord partitions[4];
|
||||
uint16_t MBRSignature;
|
||||
}; // struct TempMBR
|
||||
#pragma pack ()
|
||||
|
||||
// Possible states of the MBR
|
||||
enum MBRValidity {invalid, gpt, hybrid, mbr};
|
||||
@@ -62,6 +63,7 @@ protected:
|
||||
public:
|
||||
BasicMBRData(void);
|
||||
BasicMBRData(string deviceFilename);
|
||||
BasicMBRData(const BasicMBRData &);
|
||||
~BasicMBRData(void);
|
||||
BasicMBRData & operator=(const BasicMBRData & orig);
|
||||
|
||||
|
||||
1
bsd.h
1
bsd.h
@@ -89,5 +89,6 @@ class BSDData {
|
||||
int GetNumParts(void);
|
||||
GPTPart AsGPT(int i); // Return BSD part. as GPT part.
|
||||
}; // struct MBRData
|
||||
#pragma pack ()
|
||||
|
||||
#endif
|
||||
|
||||
44
cgdisk.8
44
cgdisk.8
@@ -1,6 +1,6 @@
|
||||
.\" Copyright 2011-2013 Roderick W. Smith (rodsmith@rodsbooks.com)
|
||||
.\" Copyright 2011-2018 Roderick W. Smith (rodsmith@rodsbooks.com)
|
||||
.\" May be distributed under the GNU General Public License
|
||||
.TH "CGDISK" "8" "0.8.10" "Roderick W. Smith" "GPT fdisk Manual"
|
||||
.TH "CGDISK" "8" "1.0.4" "Roderick W. Smith" "GPT fdisk Manual"
|
||||
.SH "NAME"
|
||||
cgdisk \- Curses-based GUID partition table (GPT) manipulator
|
||||
.SH "SYNOPSIS"
|
||||
@@ -181,12 +181,13 @@ Change the sector alignment value. Disks with more logical sectors than
|
||||
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 2048\-sector (1MiB)
|
||||
boundaries 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.
|
||||
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.
|
||||
|
||||
.TP
|
||||
.B Backup
|
||||
@@ -261,6 +262,10 @@ Change a single partition's type code. You enter the type code using a
|
||||
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
|
||||
descriptions that include the string \fILinux\fR. This search is performed
|
||||
case\-sensitively.
|
||||
|
||||
.TP
|
||||
.B Verify
|
||||
@@ -276,10 +281,7 @@ Write data. Use this command to save your changes.
|
||||
|
||||
.SH "BUGS"
|
||||
|
||||
As of March 2014 (version 0.8.10), \fBcgdisk\fR should be considered
|
||||
beta software. Although the underlying partition manipulation code is much
|
||||
older, the \fBcgdisk\fR ncurses user interface is brand new with GPT fdisk
|
||||
version 0.8.0. Known bugs and limitations include:
|
||||
Known bugs and limitations include:
|
||||
|
||||
.TP
|
||||
.B *
|
||||
@@ -367,20 +369,20 @@ Contributors:
|
||||
|
||||
* Justin Maggard (justin.maggard@netgear.com)
|
||||
|
||||
* Dwight Schauer (dschauer@ti.com)
|
||||
* Dwight Schauer (dschauer@gmail.com)
|
||||
|
||||
* Florian Zumbiehl (florz@florz.de)
|
||||
|
||||
|
||||
.SH "SEE ALSO"
|
||||
\fBcfdisk (8)\fR,
|
||||
\fBfdisk (8)\fR,
|
||||
\fBgdisk (8)\fR,
|
||||
\fBmkfs (8)\fR,
|
||||
\fBparted (8)\fR,
|
||||
\fBsfdisk (8)\fR
|
||||
\fBsgdisk (8)\fR
|
||||
\fBfixparts (8)\fR
|
||||
.BR cfdisk (8),
|
||||
.BR fdisk (8),
|
||||
.BR gdisk (8),
|
||||
.BR mkfs (8),
|
||||
.BR parted (8),
|
||||
.BR sfdisk (8),
|
||||
.BR sgdisk (8),
|
||||
.BR fixparts (8).
|
||||
|
||||
\fIhttp://en.wikipedia.org/wiki/GUID_Partition_Table\fR
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
Summary: GPT partitioning and MBR repair software
|
||||
Name: gptfdisk
|
||||
Version: 0.8.10
|
||||
Version: 1.0.4
|
||||
|
||||
Release: 1%{?dist}
|
||||
License: GPLv2
|
||||
URL: http://www.rodsbooks.com/gdisk
|
||||
Group: Applications/System
|
||||
Source: http://www.rodsbooks.com/gdisk/gptfdisk-0.8.10.tar.gz
|
||||
Source: http://www.rodsbooks.com/gdisk/gptfdisk-1.0.4.tar.gz
|
||||
BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
|
||||
|
||||
%description
|
||||
@@ -81,5 +81,5 @@ provides a few additional partition manipulation features.
|
||||
|
||||
|
||||
%changelog
|
||||
* Sun Mar 2 2014 R Smith <rodsmith@rodsbooks.com> - 0.8.10
|
||||
- Created spec file for 0.8.10 release
|
||||
* Thu Jul 5 2018 R Smith <rodsmith@rodsbooks.com> - 1.0.4
|
||||
- Created spec file for 1.0.4 release
|
||||
|
||||
@@ -32,6 +32,8 @@
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
#include "diskio.h"
|
||||
|
||||
@@ -68,6 +70,7 @@ int DiskIO::OpenForRead(void) {
|
||||
cerr << "The specified file does not exist!\n";
|
||||
realFilename = "";
|
||||
userFilename = "";
|
||||
modelName = "";
|
||||
isOpen = 0;
|
||||
openForWrite = 0;
|
||||
} else {
|
||||
@@ -76,7 +79,8 @@ int DiskIO::OpenForRead(void) {
|
||||
if (fstat64(fd, &st) == 0) {
|
||||
if (S_ISDIR(st.st_mode))
|
||||
cerr << "The specified path is a directory!\n";
|
||||
#if !defined(__FreeBSD__) && !defined(__APPLE__)
|
||||
#if !(defined(__FreeBSD__) || defined(__FreeBSD_kernel__)) \
|
||||
&& !defined(__APPLE__)
|
||||
else if (S_ISCHR(st.st_mode))
|
||||
cerr << "The specified path is a character device!\n";
|
||||
#endif
|
||||
@@ -87,6 +91,16 @@ int DiskIO::OpenForRead(void) {
|
||||
else
|
||||
isOpen = 1;
|
||||
} // if (fstat64()...)
|
||||
#if defined(__linux__) && !defined(EFI)
|
||||
if (isOpen && realFilename.substr(0,4) == "/dev") {
|
||||
ostringstream modelNameFilename;
|
||||
modelNameFilename << "/sys/block" << realFilename.substr(4,512) << "/device/model";
|
||||
ifstream modelNameFile(modelNameFilename.str().c_str());
|
||||
if (modelNameFile.is_open()) {
|
||||
getline(modelNameFile, modelName);
|
||||
} // if
|
||||
} // if
|
||||
#endif
|
||||
} // if/else
|
||||
} // if
|
||||
|
||||
@@ -178,6 +192,27 @@ int DiskIO::GetBlockSize(void) {
|
||||
return (blockSize);
|
||||
} // DiskIO::GetBlockSize()
|
||||
|
||||
// Returns the physical block size of the device, if possible. If this is
|
||||
// not supported, or if an error occurs, this function returns 0.
|
||||
// TODO: Get this working in more OSes than Linux.
|
||||
int DiskIO::GetPhysBlockSize(void) {
|
||||
int err = -1, physBlockSize = 0;
|
||||
|
||||
// If disk isn't open, try to open it....
|
||||
if (!isOpen) {
|
||||
OpenForRead();
|
||||
} // if
|
||||
|
||||
if (isOpen) {
|
||||
#if defined __linux__ && !defined(EFI)
|
||||
err = ioctl(fd, BLKPBSZGET, &physBlockSize);
|
||||
#endif
|
||||
} // if (isOpen)
|
||||
if (err == -1)
|
||||
physBlockSize = 0;
|
||||
return (physBlockSize);
|
||||
} // DiskIO::GetPhysBlockSize(void)
|
||||
|
||||
// Returns the number of heads, according to the kernel, or 255 if the
|
||||
// correct value can't be determined.
|
||||
uint32_t DiskIO::GetNumHeads(void) {
|
||||
@@ -255,7 +290,8 @@ int DiskIO::DiskSync(void) {
|
||||
i = ioctl(fd, BLKRRPART);
|
||||
if (i) {
|
||||
cout << "Warning: The kernel is still using the old partition table.\n"
|
||||
<< "The new table will be used at the next reboot.\n";
|
||||
<< "The new table will be used at the next reboot or after you\n"
|
||||
<< "run partprobe(8) or kpartx(8)\n";
|
||||
} else {
|
||||
retval = 1;
|
||||
} // if/else
|
||||
|
||||
@@ -144,6 +144,13 @@ int DiskIO::GetBlockSize(void) {
|
||||
return (blockSize);
|
||||
} // DiskIO::GetBlockSize()
|
||||
|
||||
// In theory, returns the physical block size. In practice, this is only
|
||||
// supported in Linux, as of yet.
|
||||
// TODO: Get this working in Windows.
|
||||
int DiskIO::GetPhysBlockSize(void) {
|
||||
return 0;
|
||||
} // DiskIO::GetPhysBlockSize()
|
||||
|
||||
// Returns the number of heads, according to the kernel, or 255 if the
|
||||
// correct value can't be determined.
|
||||
uint32_t DiskIO::GetNumHeads(void) {
|
||||
|
||||
@@ -43,6 +43,7 @@ using namespace std;
|
||||
DiskIO::DiskIO(void) {
|
||||
userFilename = "";
|
||||
realFilename = "";
|
||||
modelName = "";
|
||||
isOpen = 0;
|
||||
openForWrite = 0;
|
||||
} // constructor
|
||||
|
||||
3
diskio.h
3
diskio.h
@@ -49,6 +49,7 @@ class DiskIO {
|
||||
protected:
|
||||
string userFilename;
|
||||
string realFilename;
|
||||
string modelName;
|
||||
int isOpen;
|
||||
int openForWrite;
|
||||
#ifdef _WIN32
|
||||
@@ -71,6 +72,8 @@ class DiskIO {
|
||||
int Write(void* buffer, int numBytes);
|
||||
int DiskSync(void); // resync disk caches to use new partitions
|
||||
int GetBlockSize(void);
|
||||
int GetPhysBlockSize(void);
|
||||
string GetModel(void) {return modelName;}
|
||||
uint32_t GetNumHeads(void);
|
||||
uint32_t GetNumSecsPerTrack(void);
|
||||
int IsOpen(void) {return isOpen;}
|
||||
|
||||
25
fixparts.8
25
fixparts.8
@@ -1,6 +1,6 @@
|
||||
.\" Copyright 2011-2013 Roderick W. Smith (rodsmith@rodsbooks.com)
|
||||
.\" Copyright 2011-2018 Roderick W. Smith (rodsmith@rodsbooks.com)
|
||||
.\" May be distributed under the GNU General Public License
|
||||
.TH "FIXPARTS" "8" "0.8.10" "Roderick W. Smith" "FixParts Manual"
|
||||
.TH "FIXPARTS" "8" "1.0.4" "Roderick W. Smith" "FixParts Manual"
|
||||
.SH "NAME"
|
||||
fixparts \- MBR partition table repair utility
|
||||
.SH "SYNOPSIS"
|
||||
@@ -202,8 +202,7 @@ see a summary of available options.
|
||||
.PP
|
||||
|
||||
.SH "BUGS"
|
||||
As of March 2014 (version 0.8.10), \fBfixparts\fR
|
||||
should be considered beta software. Known bugs and limitations include:
|
||||
Known bugs and limitations include:
|
||||
|
||||
.TP
|
||||
.B *
|
||||
@@ -259,20 +258,20 @@ Contributors:
|
||||
|
||||
* Justin Maggard (justin.maggard@netgear.com)
|
||||
|
||||
* Dwight Schauer (dschauer@ti.com)
|
||||
* Dwight Schauer (dschauer@gmail.com)
|
||||
|
||||
* Florian Zumbiehl (florz@florz.de)
|
||||
|
||||
|
||||
.SH "SEE ALSO"
|
||||
\fBcfdisk (8)\fR,
|
||||
\fBcgdisk (8)\fR,
|
||||
\fBfdisk (8)\fR,
|
||||
\fBmkfs (8)\fR,
|
||||
\fBparted (8)\fR,
|
||||
\fBsfdisk (8)\fR
|
||||
\fBgdisk (8)\fR
|
||||
\fBsgdisk (8)\fR
|
||||
.BR cfdisk (8),
|
||||
.BR cgdisk (8),
|
||||
.BR fdisk (8),
|
||||
.BR mkfs (8),
|
||||
.BR parted (8),
|
||||
.BR sfdisk (8),
|
||||
.BR gdisk (8),
|
||||
.BR sgdisk (8).
|
||||
|
||||
\fIhttp://en.wikipedia.org/wiki/Master_boot_record\fR
|
||||
|
||||
|
||||
81
gdisk.8
81
gdisk.8
@@ -1,6 +1,6 @@
|
||||
.\" Copyright 2011-2013 Roderick W. Smith (rodsmith@rodsbooks.com)
|
||||
.\" Copyright 2011-2018 Roderick W. Smith (rodsmith@rodsbooks.com)
|
||||
.\" May be distributed under the GNU General Public License
|
||||
.TH "GDISK" "8" "0.8.10" "Roderick W. Smith" "GPT fdisk Manual"
|
||||
.TH "GDISK" "8" "1.0.4" "Roderick W. Smith" "GPT fdisk Manual"
|
||||
.SH "NAME"
|
||||
gdisk \- Interactive GUID partition table (GPT) manipulator
|
||||
.SH "SYNOPSIS"
|
||||
@@ -91,11 +91,12 @@ and in whatever sizes are desired.
|
||||
|
||||
.TP
|
||||
.B *
|
||||
Boot disks for EFI\-based systems require an \fIEFI System
|
||||
Partition\fR (\fBgdisk\fR internal code 0xEF00) formatted as FAT\-32.
|
||||
The recommended size of this partition is between 100 and 300 MiB.
|
||||
Boot\-related files are stored here. (Note that GNU Parted identifies
|
||||
such partitions as having the "boot flag" set.)
|
||||
Boot disks for EFI\-based systems require an \fIEFI System Partition\fR
|
||||
(\fBgdisk\fR internal code 0xEF00) formatted as FAT\-32. I recommended
|
||||
making this partition 550 MiB. (Smaller ESPs are common, but some EFIs have
|
||||
flaky FAT drivers that necessitate a larger partition for reliable
|
||||
operation.) Boot\-related files are stored here. (Note that GNU Parted
|
||||
identifies such partitions as having the "boot flag" set.)
|
||||
|
||||
.TP
|
||||
.B *
|
||||
@@ -103,8 +104,8 @@ Some boot loaders for BIOS\-based systems make use of a \fIBIOS Boot
|
||||
Partition\fR (\fBgdisk\fR internal code 0xEF02), in which the secondary
|
||||
boot loader is stored, possibly without the benefit of a filesystem. (GRUB2
|
||||
may optionally use such a partition.) This partition can typically be quite
|
||||
small (roughly 32 to 200 KiB), but you should consult your boot loader
|
||||
documentation for details.
|
||||
small (roughly 32 to 200 KiB, although 1 MiB is more common in practice),
|
||||
but you should consult your boot loader documentation for details.
|
||||
|
||||
.TP
|
||||
.B *
|
||||
@@ -184,16 +185,19 @@ related to their equivalent MBR codes. Specifically, the MBR code is
|
||||
multiplied by hexadecimal 0x0100. For instance, the code for Linux swap
|
||||
space in MBR is 0x82, and it's 0x8200 in \fBgdisk\fR. A one\-to\-one
|
||||
correspondence is impossible, though. Most notably, the codes for all
|
||||
varieties of FAT and NTFS partition correspond to a single GPT code
|
||||
(entered as 0x0700 in \fBsgdisk\fR). Some OSes use a single MBR code but
|
||||
employ many 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.
|
||||
varieties of FAT and NTFS partition correspond to a single GPT code (entered
|
||||
as 0x0700 in \fBgdisk\fR). Some OSes use a single MBR code but employ many
|
||||
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
|
||||
codes with descriptions that include the string \fILinux\fR. This search is
|
||||
performed case\-sensitively.
|
||||
|
||||
.TP
|
||||
.B n
|
||||
Create a new partition. This command is modelled after the equivalent
|
||||
Create a new partition. This command is modeled after the equivalent
|
||||
\fBfdisk\fR option, although some differences exist. You enter a partition
|
||||
number, starting sector, and an ending sector. Both start and end sectors
|
||||
can be specified in absolute terms as sector numbers or as positions
|
||||
@@ -212,7 +216,8 @@ sector.
|
||||
.B o
|
||||
Clear out all partition data. This includes GPT header data,
|
||||
all partition definitions, and the protective MBR. The sector alignment
|
||||
is reset to the default (2048 sectors, or 1MB).
|
||||
is reset to the default (1 MiB, or 2048 sectors on a disk with 512-byte
|
||||
sectors).
|
||||
|
||||
.TP
|
||||
.B p
|
||||
@@ -464,18 +469,27 @@ boot.
|
||||
Show detailed partition information. This option is identical to the 'i'
|
||||
option on the main menu.
|
||||
|
||||
.TP
|
||||
.B j
|
||||
Adjust the location of the main partition table. This value is normally 2,
|
||||
but it may need to be increased in some cases, such as when a
|
||||
system\-on\-chip (SoC) is hard\-coded to read boot code from sector 2. I
|
||||
recommend against adjusting this value unless doing so is absolutely
|
||||
necessary.
|
||||
|
||||
.TP
|
||||
.B l
|
||||
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 2048\-sector (1MiB)
|
||||
boundaries 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.
|
||||
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.
|
||||
|
||||
.TP
|
||||
.B m
|
||||
@@ -561,8 +575,7 @@ entering data. When only one option is possible, \fBgdisk\fR
|
||||
usually bypasses the prompt entirely.
|
||||
|
||||
.SH "BUGS"
|
||||
As of March 2014 (version 0.8.10), \fBgdisk\fR
|
||||
should be considered beta software. Known bugs and limitations include:
|
||||
Known bugs and limitations include:
|
||||
|
||||
.TP
|
||||
.B *
|
||||
@@ -660,20 +673,20 @@ Contributors:
|
||||
|
||||
* Justin Maggard (justin.maggard@netgear.com)
|
||||
|
||||
* Dwight Schauer (dschauer@ti.com)
|
||||
* Dwight Schauer (dschauer@gmail.com)
|
||||
|
||||
* Florian Zumbiehl (florz@florz.de)
|
||||
|
||||
|
||||
.SH "SEE ALSO"
|
||||
\fBcfdisk (8)\fR,
|
||||
\fBcgdisk (8)\fR,
|
||||
\fBfdisk (8)\fR,
|
||||
\fBmkfs (8)\fR,
|
||||
\fBparted (8)\fR,
|
||||
\fBsfdisk (8)\fR
|
||||
\fBsgdisk (8)\fR
|
||||
\fBfixparts (8)\fR
|
||||
.BR cfdisk (8),
|
||||
.BR cgdisk (8),
|
||||
.BR fdisk (8),
|
||||
.BR mkfs (8),
|
||||
.BR parted (8),
|
||||
.BR sfdisk (8),
|
||||
.BR sgdisk (8),
|
||||
.BR fixparts (8).
|
||||
|
||||
\fIhttp://en.wikipedia.org/wiki/GUID_Partition_Table\fR
|
||||
|
||||
|
||||
@@ -115,9 +115,23 @@ Y
|
||||
w
|
||||
Y
|
||||
EOF
|
||||
|
||||
ret=$?
|
||||
if [ $ret -ne 0 ]
|
||||
then
|
||||
pretty_print "FAILED" "gdisk return $ret when creating partition table"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
sgdisk)
|
||||
$SGDISK_BIN $TEMP_DISK -${OPT_CLEAR}
|
||||
|
||||
ret=$?
|
||||
if [ $ret -ne 0 ]
|
||||
then
|
||||
pretty_print "FAILED" "sgdisk return $ret when creating partition table"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
@@ -147,7 +161,7 @@ EOF
|
||||
;;
|
||||
|
||||
sgdisk)
|
||||
$SGDISK_BIN $TEMP_DISK -${OPT_NEW} 1 -${OPT_CHANGE_NAME} 1:"${TEST_PART_DEFAULT_NAME}"
|
||||
$SGDISK_BIN $TEMP_DISK -${OPT_NEW} 1 -${OPT_CHANGE_NAME} 1:"${TEST_PART_DEFAULT_NAME}" -${OPT_CHANGE_TYPE} 1:$TEST_PART_TYPE
|
||||
;;
|
||||
esac
|
||||
|
||||
@@ -311,6 +325,7 @@ EOF
|
||||
pretty_print "SUCCESS" "GUID of disk has been sucessfully changed"
|
||||
else
|
||||
pretty_print "FAILED" "GUID of disk is the same as the previous one"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -353,7 +368,7 @@ EOF
|
||||
###################################
|
||||
|
||||
# create a file to simulate a real device
|
||||
dd if=/dev/zero of=$TEMP_DISK bs=1024 count=$TEMP_DISK_SIZE
|
||||
dd if=/dev/zero of=$TEMP_DISK bs=1024 count=$TEMP_DISK_SIZE > /dev/null 2>&1
|
||||
|
||||
if [ -s $TEMP_DISK ]
|
||||
then
|
||||
|
||||
257
gpt.cc
257
gpt.cc
@@ -3,7 +3,7 @@
|
||||
|
||||
/* By Rod Smith, initial coding January to February, 2009 */
|
||||
|
||||
/* This program is copyright (c) 2009-2013 by Roderick W. Smith. It is distributed
|
||||
/* 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. */
|
||||
|
||||
#define __STDC_LIMIT_MACROS
|
||||
@@ -66,12 +66,12 @@ static inline uint32_t log2_32(uint32_t v) {
|
||||
// Default constructor
|
||||
GPTData::GPTData(void) {
|
||||
blockSize = SECTOR_SIZE; // set a default
|
||||
physBlockSize = 0; // 0 = can't be determined
|
||||
diskSize = 0;
|
||||
partitions = NULL;
|
||||
state = gpt_valid;
|
||||
device = "";
|
||||
justLooking = 0;
|
||||
syncing = 1;
|
||||
mainCrcOk = 0;
|
||||
secondCrcOk = 0;
|
||||
mainPartsCrcOk = 0;
|
||||
@@ -88,6 +88,45 @@ GPTData::GPTData(void) {
|
||||
chksum_crc32gentab();
|
||||
} // GPTData default constructor
|
||||
|
||||
GPTData::GPTData(const GPTData & orig) {
|
||||
uint32_t i;
|
||||
|
||||
if (&orig != this) {
|
||||
mainHeader = orig.mainHeader;
|
||||
numParts = orig.numParts;
|
||||
secondHeader = orig.secondHeader;
|
||||
protectiveMBR = orig.protectiveMBR;
|
||||
device = orig.device;
|
||||
blockSize = orig.blockSize;
|
||||
physBlockSize = orig.physBlockSize;
|
||||
diskSize = orig.diskSize;
|
||||
state = orig.state;
|
||||
justLooking = orig.justLooking;
|
||||
mainCrcOk = orig.mainCrcOk;
|
||||
secondCrcOk = orig.secondCrcOk;
|
||||
mainPartsCrcOk = orig.mainPartsCrcOk;
|
||||
secondPartsCrcOk = orig.secondPartsCrcOk;
|
||||
apmFound = orig.apmFound;
|
||||
bsdFound = orig.bsdFound;
|
||||
sectorAlignment = orig.sectorAlignment;
|
||||
beQuiet = orig.beQuiet;
|
||||
whichWasUsed = orig.whichWasUsed;
|
||||
|
||||
myDisk.OpenForRead(orig.myDisk.GetName());
|
||||
|
||||
delete[] partitions;
|
||||
partitions = new GPTPart [numParts];
|
||||
if (partitions == NULL) {
|
||||
cerr << "Error! Could not allocate memory for partitions in GPTData::operator=()!\n"
|
||||
<< "Terminating!\n";
|
||||
exit(1);
|
||||
} // if
|
||||
for (i = 0; i < numParts; i++) {
|
||||
partitions[i] = orig.partitions[i];
|
||||
} // for
|
||||
} // if
|
||||
} // GPTData copy constructor
|
||||
|
||||
// The following constructor loads GPT data from a device file
|
||||
GPTData::GPTData(string filename) {
|
||||
blockSize = SECTOR_SIZE; // set a default
|
||||
@@ -96,7 +135,6 @@ GPTData::GPTData(string filename) {
|
||||
state = gpt_invalid;
|
||||
device = "";
|
||||
justLooking = 0;
|
||||
syncing = 1;
|
||||
mainCrcOk = 0;
|
||||
secondCrcOk = 0;
|
||||
mainPartsCrcOk = 0;
|
||||
@@ -123,38 +161,40 @@ GPTData::~GPTData(void) {
|
||||
GPTData & GPTData::operator=(const GPTData & orig) {
|
||||
uint32_t i;
|
||||
|
||||
mainHeader = orig.mainHeader;
|
||||
numParts = orig.numParts;
|
||||
secondHeader = orig.secondHeader;
|
||||
protectiveMBR = orig.protectiveMBR;
|
||||
device = orig.device;
|
||||
blockSize = orig.blockSize;
|
||||
diskSize = orig.diskSize;
|
||||
state = orig.state;
|
||||
justLooking = orig.justLooking;
|
||||
syncing = orig.syncing;
|
||||
mainCrcOk = orig.mainCrcOk;
|
||||
secondCrcOk = orig.secondCrcOk;
|
||||
mainPartsCrcOk = orig.mainPartsCrcOk;
|
||||
secondPartsCrcOk = orig.secondPartsCrcOk;
|
||||
apmFound = orig.apmFound;
|
||||
bsdFound = orig.bsdFound;
|
||||
sectorAlignment = orig.sectorAlignment;
|
||||
beQuiet = orig.beQuiet;
|
||||
whichWasUsed = orig.whichWasUsed;
|
||||
if (&orig != this) {
|
||||
mainHeader = orig.mainHeader;
|
||||
numParts = orig.numParts;
|
||||
secondHeader = orig.secondHeader;
|
||||
protectiveMBR = orig.protectiveMBR;
|
||||
device = orig.device;
|
||||
blockSize = orig.blockSize;
|
||||
physBlockSize = orig.physBlockSize;
|
||||
diskSize = orig.diskSize;
|
||||
state = orig.state;
|
||||
justLooking = orig.justLooking;
|
||||
mainCrcOk = orig.mainCrcOk;
|
||||
secondCrcOk = orig.secondCrcOk;
|
||||
mainPartsCrcOk = orig.mainPartsCrcOk;
|
||||
secondPartsCrcOk = orig.secondPartsCrcOk;
|
||||
apmFound = orig.apmFound;
|
||||
bsdFound = orig.bsdFound;
|
||||
sectorAlignment = orig.sectorAlignment;
|
||||
beQuiet = orig.beQuiet;
|
||||
whichWasUsed = orig.whichWasUsed;
|
||||
|
||||
myDisk.OpenForRead(orig.myDisk.GetName());
|
||||
myDisk.OpenForRead(orig.myDisk.GetName());
|
||||
|
||||
delete[] partitions;
|
||||
partitions = new GPTPart [numParts];
|
||||
if (partitions == NULL) {
|
||||
cerr << "Error! Could not allocate memory for partitions in GPTData::operator=()!\n"
|
||||
<< "Terminating!\n";
|
||||
exit(1);
|
||||
delete[] partitions;
|
||||
partitions = new GPTPart [numParts];
|
||||
if (partitions == NULL) {
|
||||
cerr << "Error! Could not allocate memory for partitions in GPTData::operator=()!\n"
|
||||
<< "Terminating!\n";
|
||||
exit(1);
|
||||
} // if
|
||||
for (i = 0; i < numParts; i++) {
|
||||
partitions[i] = orig.partitions[i];
|
||||
} // for
|
||||
} // if
|
||||
for (i = 0; i < numParts; i++) {
|
||||
partitions[i] = orig.partitions[i];
|
||||
} // for
|
||||
|
||||
return *this;
|
||||
} // GPTData::operator=()
|
||||
@@ -171,7 +211,7 @@ GPTData & GPTData::operator=(const GPTData & orig) {
|
||||
// problems identified.
|
||||
int GPTData::Verify(void) {
|
||||
int problems = 0, alignProbs = 0;
|
||||
uint32_t i, numSegments;
|
||||
uint32_t i, numSegments, testAlignment = sectorAlignment;
|
||||
uint64_t totalFree, largestSegment;
|
||||
|
||||
// First, check for CRC errors in the GPT data....
|
||||
@@ -281,6 +321,45 @@ int GPTData::Verify(void) {
|
||||
<< "The 'e' option on the experts' menu may fix this problem.\n";
|
||||
} // if
|
||||
|
||||
// Check the main and backup partition tables for overlap with things and unusual gaps
|
||||
if (mainHeader.partitionEntriesLBA + GetTableSizeInSectors() > mainHeader.firstUsableLBA) {
|
||||
problems++;
|
||||
cout << "\nProblem: Main partition table extends past the first usable LBA.\n"
|
||||
<< "Using 'j' on the experts' menu may enable fixing this problem.\n";
|
||||
} // if
|
||||
if (mainHeader.partitionEntriesLBA < 2) {
|
||||
problems++;
|
||||
cout << "\nProblem: Main partition table appears impossibly early on the disk.\n"
|
||||
<< "Using 'j' on the experts' menu may enable fixing this problem.\n";
|
||||
} // if
|
||||
if (secondHeader.partitionEntriesLBA + GetTableSizeInSectors() > secondHeader.currentLBA) {
|
||||
problems++;
|
||||
cout << "\nProblem: The backup partition table overlaps the backup header.\n"
|
||||
<< "Using 'e' on the experts' menu may fix this problem.\n";
|
||||
} // if
|
||||
if (mainHeader.partitionEntriesLBA != 2) {
|
||||
cout << "\nWarning: There is a gap between the main metadata (sector 1) and the main\n"
|
||||
<< "partition table (sector " << mainHeader.partitionEntriesLBA
|
||||
<< "). This is helpful in some exotic configurations,\n"
|
||||
<< "but is generally ill-advised. Using 'j' on the experts' menu can adjust this\n"
|
||||
<< "gap.\n";
|
||||
} // if
|
||||
if (mainHeader.partitionEntriesLBA + GetTableSizeInSectors() != mainHeader.firstUsableLBA) {
|
||||
cout << "\nWarning: There is a gap between the main partition table (ending sector "
|
||||
<< mainHeader.partitionEntriesLBA + GetTableSizeInSectors() - 1 << ")\n"
|
||||
<< "and the first usable sector (" << mainHeader.firstUsableLBA << "). This is helpful in some exotic configurations,\n"
|
||||
<< "but is unusual. The util-linux fdisk program often creates disks like this.\n"
|
||||
<< "Using 'j' on the experts' menu can adjust this gap.\n";
|
||||
} // if
|
||||
|
||||
if (mainHeader.sizeOfPartitionEntries * mainHeader.numParts < 16384) {
|
||||
cout << "\nWarning: The size of the partition table (" << mainHeader.sizeOfPartitionEntries * mainHeader.numParts
|
||||
<< " bytes) is less than the minimum\n"
|
||||
<< "required by the GPT specification. Most OSes and tools seem to work fine on\n"
|
||||
<< "such disks, but this is a violation of the GPT specification and so may cause\n"
|
||||
<< "problems.\n";
|
||||
} // if
|
||||
|
||||
if ((mainHeader.lastUsableLBA >= diskSize) || (mainHeader.lastUsableLBA > mainHeader.backupLBA)) {
|
||||
problems++;
|
||||
cout << "\nProblem: GPT claims the disk is larger than it is! (Claimed last usable\n"
|
||||
@@ -321,10 +400,15 @@ int GPTData::Verify(void) {
|
||||
|
||||
// Check that partitions are aligned on proper boundaries (for WD Advanced
|
||||
// Format and similar disks)....
|
||||
if ((physBlockSize != 0) && (blockSize != 0))
|
||||
testAlignment = physBlockSize / blockSize;
|
||||
testAlignment = max(testAlignment, sectorAlignment);
|
||||
if (testAlignment == 0) // Should not happen; just being paranoid.
|
||||
testAlignment = sectorAlignment;
|
||||
for (i = 0; i < numParts; i++) {
|
||||
if ((partitions[i].IsUsed()) && (partitions[i].GetFirstLBA() % sectorAlignment) != 0) {
|
||||
if ((partitions[i].IsUsed()) && (partitions[i].GetFirstLBA() % testAlignment) != 0) {
|
||||
cout << "\nCaution: Partition " << i + 1 << " doesn't begin on a "
|
||||
<< sectorAlignment << "-sector boundary. This may\nresult "
|
||||
<< testAlignment << "-sector boundary. This may\nresult "
|
||||
<< "in degraded performance on some modern (2009 and later) hard disks.\n";
|
||||
alignProbs++;
|
||||
} // if
|
||||
@@ -557,8 +641,8 @@ void GPTData::RebuildMainHeader(void) {
|
||||
mainHeader.firstUsableLBA = secondHeader.firstUsableLBA;
|
||||
mainHeader.lastUsableLBA = secondHeader.lastUsableLBA;
|
||||
mainHeader.diskGUID = secondHeader.diskGUID;
|
||||
mainHeader.partitionEntriesLBA = UINT64_C(2);
|
||||
mainHeader.numParts = secondHeader.numParts;
|
||||
mainHeader.partitionEntriesLBA = secondHeader.firstUsableLBA - GetTableSizeInSectors();
|
||||
mainHeader.sizeOfPartitionEntries = secondHeader.sizeOfPartitionEntries;
|
||||
mainHeader.partitionEntriesCRC = secondHeader.partitionEntriesCRC;
|
||||
memcpy(mainHeader.reserved2, secondHeader.reserved2, sizeof(mainHeader.reserved2));
|
||||
@@ -663,7 +747,7 @@ int GPTData::FindInsanePartitions(void) {
|
||||
} // if
|
||||
if (partitions[i].GetLastLBA() >= diskSize) {
|
||||
problems++;
|
||||
cout << "\nProblem: partition " << i + 1 << " is too big for the disk.\n";
|
||||
cout << "\nProblem: partition " << i + 1 << " is too big for the disk.\n";
|
||||
} // if
|
||||
} // if
|
||||
} // for
|
||||
@@ -688,6 +772,7 @@ int GPTData::SetDisk(const string & deviceFilename) {
|
||||
// store disk information....
|
||||
diskSize = myDisk.DiskSize(&err);
|
||||
blockSize = (uint32_t) myDisk.GetBlockSize();
|
||||
physBlockSize = (uint32_t) myDisk.GetPhysBlockSize();
|
||||
} // if
|
||||
protectiveMBR.SetDisk(&myDisk);
|
||||
protectiveMBR.SetDiskSize(diskSize);
|
||||
@@ -753,7 +838,12 @@ int GPTData::LoadPartitions(const string & deviceFilename) {
|
||||
<< "'sysctl kern.geom.debugflags=16' at a shell prompt, and re-running this\n"
|
||||
<< "program.\n";
|
||||
#endif
|
||||
cout << "\n";
|
||||
#if defined (__APPLE__)
|
||||
cout << "You may need to deactivate System Integrity Protection to use this program. See\n"
|
||||
<< "https://www.quora.com/How-do-I-turn-off-the-rootless-in-OS-X-El-Capitan-10-11\n"
|
||||
<< "for more information.\n";
|
||||
#endif
|
||||
cout << "\n";
|
||||
} // if
|
||||
myDisk.Close(); // Close and re-open read-only in case of bugs
|
||||
} else allOK = 0; // if
|
||||
@@ -762,6 +852,7 @@ int GPTData::LoadPartitions(const string & deviceFilename) {
|
||||
// store disk information....
|
||||
diskSize = myDisk.DiskSize(&err);
|
||||
blockSize = (uint32_t) myDisk.GetBlockSize();
|
||||
physBlockSize = (uint32_t) myDisk.GetPhysBlockSize();
|
||||
device = deviceFilename;
|
||||
PartitionScan(); // Check for partition types, load GPT, & print summary
|
||||
|
||||
@@ -851,9 +942,8 @@ int GPTData::ForceLoadGPTData(void) {
|
||||
} // if/else/if
|
||||
|
||||
// Figure out which partition table to load....
|
||||
// Load the main partition table, since either its header's CRC is OK or the
|
||||
// backup header's CRC is not OK....
|
||||
if (mainCrcOk || !secondCrcOk) {
|
||||
// Load the main partition table, if its header's CRC is OK
|
||||
if (validHeaders != 2) {
|
||||
if (LoadMainTable() == 0)
|
||||
allOK = 0;
|
||||
} else { // bad main header CRC and backup header CRC is OK
|
||||
@@ -887,9 +977,27 @@ int GPTData::ForceLoadGPTData(void) {
|
||||
} // if */
|
||||
|
||||
// Check for valid CRCs and warn if there are problems
|
||||
if ((mainCrcOk == 0) || (secondCrcOk == 0) || (mainPartsCrcOk == 0) ||
|
||||
if ((validHeaders != 3) || (mainPartsCrcOk == 0) ||
|
||||
(secondPartsCrcOk == 0)) {
|
||||
cerr << "Warning! One or more CRCs don't match. You should repair the disk!\n\n";
|
||||
cerr << "Warning! One or more CRCs don't match. You should repair the disk!\n";
|
||||
// Show detail status of header and table
|
||||
if (validHeaders & 0x1)
|
||||
cerr << "Main header: OK\n";
|
||||
else
|
||||
cerr << "Main header: ERROR\n";
|
||||
if (validHeaders & 0x2)
|
||||
cerr << "Backup header: OK\n";
|
||||
else
|
||||
cerr << "Backup header: ERROR\n";
|
||||
if (mainPartsCrcOk)
|
||||
cerr << "Main partition table: OK\n";
|
||||
else
|
||||
cerr << "Main partition table: ERROR\n";
|
||||
if (secondPartsCrcOk)
|
||||
cerr << "Backup partition table: OK\n";
|
||||
else
|
||||
cerr << "Backup partition table: ERROR\n";
|
||||
cerr << "\n";
|
||||
state = gpt_corrupt;
|
||||
} // if
|
||||
} else {
|
||||
@@ -1147,7 +1255,7 @@ int GPTData::SaveGPTData(int quiet) {
|
||||
// original partition table from its cache. OTOH, such restoration might be
|
||||
// desirable if the error occurs later; but that seems unlikely unless the initial
|
||||
// write fails....
|
||||
if (syncIt && syncing)
|
||||
if (syncIt)
|
||||
myDisk.DiskSync();
|
||||
|
||||
if (allOK) { // writes completed OK
|
||||
@@ -1379,9 +1487,7 @@ int GPTData::DestroyGPT(void) {
|
||||
allOK = 0;
|
||||
} // if
|
||||
} // if
|
||||
if (syncing) {
|
||||
myDisk.DiskSync();
|
||||
}
|
||||
myDisk.DiskSync();
|
||||
myDisk.Close();
|
||||
cout << "GPT data structures destroyed! You may now partition the disk using fdisk or\n"
|
||||
<< "other utilities.\n";
|
||||
@@ -1440,9 +1546,16 @@ void GPTData::DisplayGPTData(void) {
|
||||
|
||||
cout << "Disk " << device << ": " << diskSize << " sectors, "
|
||||
<< BytesToIeee(diskSize, blockSize) << "\n";
|
||||
cout << "Logical sector size: " << blockSize << " bytes\n";
|
||||
if (myDisk.GetModel() != "")
|
||||
cout << "Model: " << myDisk.GetModel() << "\n";
|
||||
if (physBlockSize > 0)
|
||||
cout << "Sector size (logical/physical): " << blockSize << "/" << physBlockSize << " bytes\n";
|
||||
else
|
||||
cout << "Sector size (logical): " << blockSize << " bytes\n";
|
||||
cout << "Disk identifier (GUID): " << mainHeader.diskGUID << "\n";
|
||||
cout << "Partition table holds up to " << numParts << " entries\n";
|
||||
cout << "Main partition table begins at sector " << mainHeader.partitionEntriesLBA
|
||||
<< " and ends at sector " << mainHeader.partitionEntriesLBA + GetTableSizeInSectors() - 1 << "\n";
|
||||
cout << "First usable sector is " << mainHeader.firstUsableLBA
|
||||
<< ", last usable sector is " << mainHeader.lastUsableLBA << "\n";
|
||||
totalFree = FindFreeBlocks(&i, &temp);
|
||||
@@ -1540,7 +1653,7 @@ WhichToUse GPTData::UseWhichPartitions(void) {
|
||||
} // if GPT corrupt
|
||||
|
||||
if (which == use_new)
|
||||
cout << "Creating new GPT entries.\n";
|
||||
cout << "Creating new GPT entries in memory.\n";
|
||||
|
||||
return which;
|
||||
} // UseWhichPartitions()
|
||||
@@ -1734,7 +1847,7 @@ int GPTData::SetGPTSize(uint32_t numEntries, int fillGPTSectors) {
|
||||
partitions = newParts;
|
||||
} // if/else existing partitions
|
||||
numParts = numEntries;
|
||||
mainHeader.firstUsableLBA = ((numEntries * GPT_SIZE) / blockSize) + (((numEntries * GPT_SIZE) % blockSize) != 0) + 2 ;
|
||||
mainHeader.firstUsableLBA = GetTableSizeInSectors() + mainHeader.partitionEntriesLBA;
|
||||
secondHeader.firstUsableLBA = mainHeader.firstUsableLBA;
|
||||
MoveSecondHeaderToEnd();
|
||||
if (diskSize > 0)
|
||||
@@ -1749,6 +1862,23 @@ int GPTData::SetGPTSize(uint32_t numEntries, int fillGPTSectors) {
|
||||
return (allOK);
|
||||
} // GPTData::SetGPTSize()
|
||||
|
||||
// Change the start sector for the main partition table.
|
||||
// Returns 1 on success, 0 on failure
|
||||
int GPTData::MoveMainTable(uint64_t pteSector) {
|
||||
uint64_t pteSize = GetTableSizeInSectors();
|
||||
int retval = 1;
|
||||
|
||||
if ((pteSector >= 2) && ((pteSector + pteSize) <= FindFirstUsedLBA())) {
|
||||
mainHeader.partitionEntriesLBA = pteSector;
|
||||
mainHeader.firstUsableLBA = pteSector + pteSize;
|
||||
RebuildSecondHeader();
|
||||
} else {
|
||||
cerr << "Unable to set the main partition table's location to " << pteSector << "!\n";
|
||||
retval = 0;
|
||||
} // if/else
|
||||
return retval;
|
||||
} // GPTData::MoveMainTable()
|
||||
|
||||
// Blank the partition array
|
||||
void GPTData::BlankPartitions(void) {
|
||||
uint32_t i;
|
||||
@@ -1854,6 +1984,7 @@ int GPTData::ClearGPTData(void) {
|
||||
mainHeader.currentLBA = UINT64_C(1);
|
||||
mainHeader.partitionEntriesLBA = (uint64_t) 2;
|
||||
mainHeader.sizeOfPartitionEntries = GPT_SIZE;
|
||||
mainHeader.firstUsableLBA = GetTableSizeInSectors() + mainHeader.partitionEntriesLBA;
|
||||
for (i = 0; i < GPT_RESERVED; i++) {
|
||||
mainHeader.reserved2[i] = '\0';
|
||||
} // for
|
||||
@@ -2123,6 +2254,20 @@ uint64_t GPTData::FindFirstAvailable(uint64_t start) {
|
||||
return (first);
|
||||
} // GPTData::FindFirstAvailable()
|
||||
|
||||
// Returns the LBA of the start of the first partition on the disk (by
|
||||
// sector number), or 0 if there are no partitions defined.
|
||||
uint64_t GPTData::FindFirstUsedLBA(void) {
|
||||
uint32_t i;
|
||||
uint64_t firstFound = UINT64_MAX;
|
||||
|
||||
for (i = 0; i < numParts; i++) {
|
||||
if ((partitions[i].IsUsed()) && (partitions[i].GetFirstLBA() < firstFound)) {
|
||||
firstFound = partitions[i].GetFirstLBA();
|
||||
} // if
|
||||
} // for
|
||||
return firstFound;
|
||||
} // GPTData::FindFirstUsedLBA()
|
||||
|
||||
// Finds the first available sector in the largest block of unallocated
|
||||
// space on the disk. Returns 0 if there are no available blocks left
|
||||
uint64_t GPTData::FindFirstInLargest(void) {
|
||||
@@ -2264,10 +2409,18 @@ int GPTData::IsUsedPartNum(uint32_t partNum) {
|
||||
// Set partition alignment value; partitions will begin on multiples of
|
||||
// the specified value
|
||||
void GPTData::SetAlignment(uint32_t n) {
|
||||
if (n > 0)
|
||||
if (n > 0) {
|
||||
sectorAlignment = n;
|
||||
else
|
||||
if ((physBlockSize > 0) && (n % (physBlockSize / blockSize) != 0)) {
|
||||
cout << "Warning: Setting alignment to a value that does not match the disk's\n"
|
||||
<< "physical block size! Performance degradation may result!\n"
|
||||
<< "Physical block size = " << physBlockSize << "\n"
|
||||
<< "Logical block size = " << blockSize << "\n"
|
||||
<< "Optimal alignment = " << physBlockSize / blockSize << " or multiples thereof.\n";
|
||||
} // if
|
||||
} else {
|
||||
cerr << "Attempt to set partition alignment to 0!\n";
|
||||
} // if/else
|
||||
} // GPTData::SetAlignment()
|
||||
|
||||
// Compute sector alignment based on the current partitions (if any). Each
|
||||
|
||||
13
gpt.h
13
gpt.h
@@ -57,6 +57,7 @@ struct GPTHeader {
|
||||
uint32_t partitionEntriesCRC;
|
||||
unsigned char reserved2[GPT_RESERVED];
|
||||
}; // struct GPTHeader
|
||||
#pragma pack ()
|
||||
|
||||
// Data in GPT format
|
||||
class GPTData {
|
||||
@@ -68,11 +69,11 @@ protected:
|
||||
MBRData protectiveMBR;
|
||||
string device; // device filename
|
||||
DiskIO myDisk;
|
||||
uint32_t blockSize; // device block size
|
||||
uint64_t diskSize; // size of device, in blocks
|
||||
uint32_t blockSize; // device logical block size
|
||||
uint32_t physBlockSize; // device physical block size (or 0 if it can't be determined)
|
||||
uint64_t diskSize; // size of device, in logical blocks
|
||||
GPTValidity state; // is GPT valid?
|
||||
int justLooking; // Set to 1 if program launched with "-l" or if read-only
|
||||
bool syncing; // Set to true if we should sync and reload the partition table
|
||||
int mainCrcOk;
|
||||
int secondCrcOk;
|
||||
int mainPartsCrcOk;
|
||||
@@ -91,6 +92,7 @@ protected:
|
||||
public:
|
||||
// Basic necessary functions....
|
||||
GPTData(void);
|
||||
GPTData(const GPTData &);
|
||||
GPTData(string deviceFilename);
|
||||
virtual ~GPTData(void);
|
||||
GPTData & operator=(const GPTData & orig);
|
||||
@@ -141,6 +143,7 @@ public:
|
||||
|
||||
// Adjust GPT structures WITHOUT user interaction...
|
||||
int SetGPTSize(uint32_t numEntries, int fillGPTSectors = 1);
|
||||
int MoveMainTable(uint64_t pteSector);
|
||||
void BlankPartitions(void);
|
||||
int DeletePartition(uint32_t partNum);
|
||||
uint32_t CreatePartition(uint32_t partNum, uint64_t startSector, uint64_t endSector);
|
||||
@@ -163,6 +166,8 @@ public:
|
||||
int GetPartRange(uint32_t* low, uint32_t* high);
|
||||
int FindFirstFreePart(void);
|
||||
uint32_t GetNumParts(void) {return mainHeader.numParts;}
|
||||
uint64_t GetTableSizeInSectors(void) {return (((numParts * GPT_SIZE) / blockSize) +
|
||||
(((numParts * GPT_SIZE) % blockSize) != 0)); }
|
||||
uint64_t GetMainHeaderLBA(void) {return mainHeader.currentLBA;}
|
||||
uint64_t GetSecondHeaderLBA(void) {return secondHeader.currentLBA;}
|
||||
uint64_t GetMainPartsLBA(void) {return mainHeader.partitionEntriesLBA;}
|
||||
@@ -177,6 +182,7 @@ public:
|
||||
|
||||
// Find information about free space
|
||||
uint64_t FindFirstAvailable(uint64_t start = 0);
|
||||
uint64_t FindFirstUsedLBA(void);
|
||||
uint64_t FindFirstInLargest(void);
|
||||
uint64_t FindLastAvailable();
|
||||
uint64_t FindLastInFree(uint64_t start);
|
||||
@@ -190,7 +196,6 @@ public:
|
||||
uint32_t ComputeAlignment(void); // Set alignment based on current partitions
|
||||
uint32_t GetAlignment(void) {return sectorAlignment;}
|
||||
void JustLooking(int i = 1) {justLooking = i;}
|
||||
void TurnOffSyncing() {syncing = 0;}
|
||||
void BeQuiet(int i = 1) {beQuiet = i;}
|
||||
WhichToUse WhichWasUsed(void) {return whichWasUsed;}
|
||||
|
||||
|
||||
58
gptcl.cc
58
gptcl.cc
@@ -63,7 +63,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;
|
||||
uint64_t low, high, startSector, endSector, sSize;
|
||||
uint64_t low, high, startSector, endSector, sSize, mainTableLBA;
|
||||
uint64_t temp; // temporary variable; free to use in any case
|
||||
char *device;
|
||||
string cmd, typeGUID, name;
|
||||
@@ -71,7 +71,8 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
|
||||
|
||||
struct poptOption theOptions[] =
|
||||
{
|
||||
{"attributes", 'A', POPT_ARG_STRING, &attributeOperation, 'A', "operate on partition attributes", "list|[partnum:show|or|nand|xor|=|set|clear|toggle|get[:bitnum|hexbitmask]]"},
|
||||
{"attributes", 'A', POPT_ARG_STRING, &attributeOperation, 'A', "operate on partition attributes",
|
||||
"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"},
|
||||
{"change-name", 'c', POPT_ARG_STRING, &partName, 'c', "change partition's name", "partnum:name"},
|
||||
@@ -84,15 +85,16 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
|
||||
{"first-aligned-in-largest", 'F', POPT_ARG_NONE, NULL, 'F', "show start of the largest free block, aligned", ""},
|
||||
{"mbrtogpt", 'g', POPT_ARG_NONE, NULL, 'g', "convert MBR to GPT", ""},
|
||||
{"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...]"},
|
||||
{"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"},
|
||||
{"skip-sync", 'j', POPT_ARG_NONE, NULL, 'j', "Don't atempt to sync and update the parittion table", ""},
|
||||
{"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", ""},
|
||||
{"gpttombr", 'm', POPT_ARG_STRING, &mbrParts, 'm', "convert GPT to MBR", "partnum[:partnum...]"},
|
||||
{"new", 'n', POPT_ARG_STRING, &newPartInfo, 'n', "create new partition", "partnum:start:end"},
|
||||
{"largest-new", 'N', POPT_ARG_INT, &largestPartNum, 'N', "create largest possible new partition", "partnum"},
|
||||
{"clear", 'o', POPT_ARG_NONE, NULL, 'o', "clear partition table", ""},
|
||||
{"print-mbr", 'O', POPT_ARG_NONE, NULL, 'O', "print MBR partition table", ""},
|
||||
{"print", 'p', POPT_ARG_NONE, NULL, 'p', "print partition table", ""},
|
||||
{"pretend", 'P', POPT_ARG_NONE, NULL, 'P', "make changes in memory, but don't write them", ""},
|
||||
{"transpose", 'r', POPT_ARG_STRING, &twoParts, 'r', "transpose two partitions", "partnum:partnum"},
|
||||
@@ -155,7 +157,7 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
|
||||
if (LoadPartitions((string) device)) {
|
||||
if ((WhichWasUsed() == use_mbr) || (WhichWasUsed() == use_bsd))
|
||||
saveNonGPT = 0; // flag so we don't overwrite unless directed to do so
|
||||
sSize = GetBlockSize();
|
||||
sSize = GetBlockSize();
|
||||
while ((opt = poptGetNextOpt(poptCon)) > 0) {
|
||||
switch (opt) {
|
||||
case 'A': {
|
||||
@@ -200,7 +202,6 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
|
||||
partNum = newPartNum;
|
||||
cout << "partNum is " << partNum << "\n";
|
||||
if ((partNum >= 0) && (partNum < (int) GetNumParts())) {
|
||||
cout << "REALLY setting name!\n";
|
||||
name = GetString(partName, 2);
|
||||
if (SetName(partNum, (UnicodeString) name.c_str())) {
|
||||
saveData = 1;
|
||||
@@ -262,8 +263,13 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
|
||||
ShowPartDetails(infoPartNum - 1);
|
||||
break;
|
||||
case 'j':
|
||||
TurnOffSyncing();
|
||||
break;
|
||||
if (MoveMainTable(mainTableLBA)) {
|
||||
JustLooking(0);
|
||||
saveData = 1;
|
||||
} else {
|
||||
neverSaveData = 1;
|
||||
} // if/else
|
||||
break;
|
||||
case 'l':
|
||||
LoadBackupFile(backupFile, saveData, neverSaveData);
|
||||
free(backupFile);
|
||||
@@ -308,8 +314,8 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
|
||||
startSector = FindFirstInLargest();
|
||||
Align(&startSector);
|
||||
endSector = FindLastInFree(startSector);
|
||||
if (largestPartNum < 0)
|
||||
largestPartNum = FindFirstFreePart();
|
||||
if (largestPartNum <= 0)
|
||||
largestPartNum = FindFirstFreePart() + 1;
|
||||
if (CreatePartition(largestPartNum - 1, startSector, endSector)) {
|
||||
saveData = 1;
|
||||
} else {
|
||||
@@ -323,6 +329,9 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
|
||||
ClearGPTData();
|
||||
saveData = 1;
|
||||
break;
|
||||
case 'O':
|
||||
DisplayMBRData();
|
||||
break;
|
||||
case 'p':
|
||||
DisplayGPTData();
|
||||
break;
|
||||
@@ -408,7 +417,7 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
|
||||
if (!pretend) {
|
||||
DestroyGPT();
|
||||
} // if
|
||||
saveNonGPT = 0;
|
||||
saveNonGPT = 1;
|
||||
saveData = 0;
|
||||
break;
|
||||
case 'Z':
|
||||
@@ -416,7 +425,7 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
|
||||
DestroyGPT();
|
||||
DestroyMBR();
|
||||
} // if
|
||||
saveNonGPT = 0;
|
||||
saveNonGPT = 1;
|
||||
saveData = 0;
|
||||
break;
|
||||
default:
|
||||
@@ -450,7 +459,7 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
|
||||
if (!pretend) {
|
||||
DestroyGPT();
|
||||
} // if
|
||||
saveNonGPT = 0;
|
||||
saveNonGPT = 1;
|
||||
saveData = 0;
|
||||
break;
|
||||
case 'Z':
|
||||
@@ -458,7 +467,7 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
|
||||
DestroyGPT();
|
||||
DestroyMBR();
|
||||
} // if
|
||||
saveNonGPT = 0;
|
||||
saveNonGPT = 1;
|
||||
saveData = 0;
|
||||
break;
|
||||
} // switch
|
||||
@@ -466,7 +475,8 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
|
||||
retval = 2;
|
||||
} // if/else loaded OK
|
||||
if ((saveData) && (!neverSaveData) && (saveNonGPT) && (!pretend)) {
|
||||
SaveGPTData(1);
|
||||
if (!SaveGPTData(1))
|
||||
retval = 4;
|
||||
}
|
||||
if (saveData && (!saveNonGPT)) {
|
||||
cout << "Non-GPT disk; not saving changes. Use -g to override.\n";
|
||||
@@ -484,16 +494,25 @@ 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;
|
||||
MBRPart newPart;
|
||||
BasicMBRData newMBR;
|
||||
|
||||
if (argument != NULL) {
|
||||
numParts = CountColons(argument) + 1;
|
||||
if (isHybrid) {
|
||||
eeLast = GetString(argument, numParts) == "EE";
|
||||
if (eeLast) {
|
||||
numParts--;
|
||||
}
|
||||
}
|
||||
|
||||
if (numParts <= (4 - isHybrid)) {
|
||||
newMBR.SetDisk(GetDisk());
|
||||
for (i = 0; i < numParts; i++) {
|
||||
origPartNum = GetInt(argument, i + 1) - 1;
|
||||
if (IsUsedPartNum(origPartNum) && (partitions[origPartNum].IsSizedForMBR() == MBR_SIZED_GOOD)) {
|
||||
mbrNum = i + (isHybrid && ! eeLast);
|
||||
newPart.SetInclusion(PRIMARY);
|
||||
newPart.SetLocation(operator[](origPartNum).GetFirstLBA(),
|
||||
operator[](origPartNum).GetLengthLBA());
|
||||
@@ -504,18 +523,23 @@ int GPTDataCL::BuildMBR(char* argument, int isHybrid) {
|
||||
if (typeRaw.count(origPartNum) == 1) {
|
||||
newPart.SetType(typeRaw[origPartNum]);
|
||||
}
|
||||
newMBR.AddPart(i + isHybrid, newPart);
|
||||
newMBR.AddPart(mbrNum, newPart);
|
||||
} else {
|
||||
cerr << "Original partition " << origPartNum + 1 << " does not exist or is too big! Aborting operation!\n";
|
||||
allOK = 0;
|
||||
} // if/else
|
||||
} // for
|
||||
if (isHybrid) {
|
||||
if (eeLast) {
|
||||
mbrNum = i;
|
||||
} else {
|
||||
mbrNum = 0;
|
||||
}
|
||||
newPart.SetInclusion(PRIMARY);
|
||||
newPart.SetLocation(1, newMBR.FindLastInFree(1));
|
||||
newPart.SetStatus(0);
|
||||
newPart.SetType(0xEE);
|
||||
newMBR.AddPart(0, newPart);
|
||||
newMBR.AddPart(mbrNum, newPart);
|
||||
} // if
|
||||
if (allOK)
|
||||
SetProtectiveMBR(newMBR);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Implementation of GPTData class derivative with curses-based text-mode
|
||||
* interaction
|
||||
* Copyright (C) 2011-2013 Roderick W. Smith
|
||||
* Copyright (C) 2011-2018 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
|
||||
@@ -19,6 +19,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <clocale>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
@@ -332,7 +333,7 @@ void GPTDataCurses::ShowInfo(int partNum) {
|
||||
BytesToIeee(partitions[partNum].GetFirstLBA(), blockSize).c_str());
|
||||
printw("Last sector: %lld (at %s)\n", partitions[partNum].GetLastLBA(),
|
||||
BytesToIeee(partitions[partNum].GetLastLBA(), blockSize).c_str());
|
||||
size = partitions[partNum].GetLastLBA() - partitions[partNum].GetFirstLBA();
|
||||
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());
|
||||
#ifdef USE_UTF16
|
||||
@@ -394,6 +395,7 @@ void GPTDataCurses::ChangeType(int partNum) {
|
||||
// Sets the partition alignment value
|
||||
void GPTDataCurses::SetAlignment(void) {
|
||||
int alignment;
|
||||
char conversion_specifier[] = "%d";
|
||||
|
||||
move(LINES - 4, 0);
|
||||
clrtobot();
|
||||
@@ -402,7 +404,7 @@ void GPTDataCurses::SetAlignment(void) {
|
||||
move(LINES - 3, 0);
|
||||
printw("Type new alignment value, in sectors: ");
|
||||
echo();
|
||||
scanw("%d", &alignment);
|
||||
scanw(conversion_specifier, &alignment);
|
||||
noecho();
|
||||
} while ((alignment == 0) || (alignment > MAX_ALIGNMENT));
|
||||
GPTData::SetAlignment(alignment);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Implementation of GPTData class derivative with curses-based text-mode
|
||||
* interaction
|
||||
* Copyright (C) 2011-2013 Roderick W. Smith
|
||||
* Copyright (C) 2011-2018 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
|
||||
|
||||
11
gptpart.cc
11
gptpart.cc
@@ -4,7 +4,7 @@
|
||||
// Description: Class to implement a SINGLE GPT partition
|
||||
//
|
||||
//
|
||||
// Author: Rod Smith <rodsmith@rodsbooks.com>, (C) 2009-2013
|
||||
// Author: Rod Smith <rodsmith@rodsbooks.com>, (C) 2009-2018
|
||||
//
|
||||
// Copyright: See COPYING file that comes with this distribution
|
||||
//
|
||||
@@ -40,6 +40,15 @@ GPTPart::GPTPart(void) {
|
||||
memset(name, 0, NAME_SIZE * sizeof(name[0]) );
|
||||
} // Default constructor
|
||||
|
||||
GPTPart::GPTPart(const GPTPart & orig) {
|
||||
partitionType = orig.partitionType;
|
||||
uniqueGUID = orig.uniqueGUID;
|
||||
firstLBA = orig.firstLBA;
|
||||
lastLBA = orig.lastLBA;
|
||||
attributes = orig.attributes;
|
||||
memcpy(name, orig.name, NAME_SIZE * sizeof( name[ 0 ] ) );
|
||||
} // Copy constructor
|
||||
|
||||
GPTPart::~GPTPart(void) {
|
||||
} // destructor
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ class GPTPart {
|
||||
uint16_t name[NAME_SIZE];
|
||||
public:
|
||||
GPTPart(void);
|
||||
GPTPart(const GPTPart &);
|
||||
~GPTPart(void);
|
||||
|
||||
// Simple data retrieval:
|
||||
|
||||
27
gpttext.cc
27
gpttext.cc
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 2010-2013 <Roderick W. Smith>
|
||||
Copyright (C) 2010-2018 <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
|
||||
@@ -132,7 +132,7 @@ int GPTDataTextUI::XFormDisklabel(void) {
|
||||
numDone = GPTData::XFormDisklabel(partNum);
|
||||
|
||||
return numDone;
|
||||
} // GPTData::XFormDisklabel(void)
|
||||
} // GPTDataTextUI::XFormDisklabel(void)
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
@@ -179,6 +179,24 @@ void GPTDataTextUI::ResizePartitionTable(void) {
|
||||
SetGPTSize(newSize);
|
||||
} // GPTDataTextUI::ResizePartitionTable()
|
||||
|
||||
// Move the main partition table (to enable some SoC boot loaders to place
|
||||
// code at sector 2, for instance).
|
||||
void GPTDataTextUI::MoveMainTable(void) {
|
||||
uint64_t newStart, pteSize = GetTableSizeInSectors();
|
||||
uint64_t maxValue = FindFirstUsedLBA() - pteSize;
|
||||
ostringstream prompt;
|
||||
|
||||
cout << "Currently, main partition table begins at sector " << mainHeader.partitionEntriesLBA
|
||||
<< " and ends at sector " << mainHeader.partitionEntriesLBA + pteSize - 1 << "\n";
|
||||
prompt << "Enter new starting location (2 to " << maxValue << "; default is 2; 1 to abort): ";
|
||||
newStart = GetNumber(1, maxValue, 2, prompt.str());
|
||||
if (newStart != 1) {
|
||||
GPTData::MoveMainTable(newStart);
|
||||
} else {
|
||||
cout << "Aborting change!\n";
|
||||
} // if
|
||||
} // GPTDataTextUI::MoveMainTable()
|
||||
|
||||
// Interactively create a partition
|
||||
void GPTDataTextUI::CreatePartition(void) {
|
||||
uint64_t firstBlock, firstInLargest, lastBlock, sector, origSector;
|
||||
@@ -811,6 +829,9 @@ void GPTDataTextUI::ExpertsMenu(string filename) {
|
||||
case 'i': case 'I':
|
||||
ShowDetails();
|
||||
break;
|
||||
case 'j': case 'J':
|
||||
MoveMainTable();
|
||||
break;
|
||||
case 'l': case 'L':
|
||||
prompt.seekp(0);
|
||||
prompt << "Enter the sector alignment value (1-" << MAX_ALIGNMENT << ", default = "
|
||||
@@ -878,9 +899,11 @@ void GPTDataTextUI::ShowExpertCommands(void) {
|
||||
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";
|
||||
cout << "f\trandomize disk and partition unique GUIDs\n";
|
||||
cout << "g\tchange disk GUID\n";
|
||||
cout << "h\trecompute CHS values in protective/hybrid MBR\n";
|
||||
cout << "i\tshow detailed information on a partition\n";
|
||||
cout << "j\tmove the main partition table\n";
|
||||
cout << "l\tset the sector alignment value\n";
|
||||
cout << "m\treturn to main menu\n";
|
||||
cout << "n\tcreate a new protective MBR\n";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Implementation of GPTData class derivative with basic text-mode interaction
|
||||
Copyright (C) 2010-2013 Roderick W. Smith
|
||||
Copyright (C) 2010-2018 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
|
||||
@@ -42,6 +42,7 @@ class GPTDataTextUI : public GPTData {
|
||||
// Request information from the user (& possibly do something with it)
|
||||
uint32_t GetPartNum(void);
|
||||
void ResizePartitionTable(void);
|
||||
void MoveMainTable(void);
|
||||
void CreatePartition(void);
|
||||
void DeletePartition(void);
|
||||
void ChangePartType(void);
|
||||
|
||||
7
mbr.cc
7
mbr.cc
@@ -30,11 +30,8 @@ using namespace std;
|
||||
* *
|
||||
****************************************/
|
||||
|
||||
/* // Assignment operator -- copy entire set of MBR data.
|
||||
MBRData & MBRData::operator=(const MBRData & orig) {
|
||||
BasicMBRData::operator=(orig);
|
||||
return *this;
|
||||
} // MBRData::operator=() */
|
||||
MBRData::~MBRData(void) {
|
||||
} // MBRData destructor
|
||||
|
||||
// Assignment operator -- copy entire set of MBR data.
|
||||
MBRData & MBRData::operator=(const BasicMBRData & orig) {
|
||||
|
||||
1
mbr.h
1
mbr.h
@@ -28,6 +28,7 @@ public:
|
||||
MBRData(void) {}
|
||||
MBRData(string deviceFilename) : BasicMBRData(deviceFilename) {}
|
||||
MBRData & operator=(const BasicMBRData & orig);
|
||||
~MBRData(void);
|
||||
|
||||
// Functions to create, delete, or change partitions
|
||||
// Pass EmptyMBR 1 to clear the boot loader code, 0 to leave it intact
|
||||
|
||||
@@ -50,6 +50,7 @@ struct MBRRecord {
|
||||
uint32_t firstLBA; // see above
|
||||
uint32_t lengthLBA;
|
||||
}; // struct MBRRecord
|
||||
#pragma pack ()
|
||||
|
||||
class MBRPart {
|
||||
protected:
|
||||
|
||||
163
parttypes.cc
163
parttypes.cc
@@ -2,7 +2,7 @@
|
||||
// Class to manage partition type codes -- a slight variant on MBR type
|
||||
// codes, GUID type codes, and associated names.
|
||||
|
||||
/* This program is copyright (c) 2009-2014 by Roderick W. Smith. It is distributed
|
||||
/* 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. */
|
||||
|
||||
#define __STDC_LIMIT_MACROS
|
||||
@@ -22,6 +22,10 @@ int PartType::numInstances = 0;
|
||||
AType* PartType::allTypes = NULL;
|
||||
AType* PartType::lastType = NULL;
|
||||
|
||||
#define SCREEN_WIDTH 80
|
||||
#define NUM_COLUMNS 2
|
||||
#define DESC_LENGTH (SCREEN_WIDTH - (6 * NUM_COLUMNS)) / NUM_COLUMNS
|
||||
|
||||
// Constructor. Its main task is to initialize the data list, but only
|
||||
// if this is the first instance, since it's a static linked list.
|
||||
// Partition type codes are MBR type codes multiplied by 0x0100, with
|
||||
@@ -95,16 +99,20 @@ void PartType::AddAllTypes(void) {
|
||||
|
||||
// Open Network Install Environment (ONIE) specific types.
|
||||
// See http://www.onie.org/ and
|
||||
// https://github.com/onie/onie/blob/master/rootconf/x86_64/sysroot-lib-onie/onie-blkdev-common
|
||||
// https://github.com/opencomputeproject/onie/blob/master/patches/gptfdisk/add-onie-partition-types.patch
|
||||
AddType(0x3000, "7412F7D5-A156-4B13-81DC-867174929325", "ONIE boot");
|
||||
AddType(0x3001, "D4E6E2CD-4469-46F3-B5CB-1BFF57AFC149", "ONIE config");
|
||||
|
||||
// Plan 9; see http://man.cat-v.org/9front/8/prep
|
||||
AddType(0x3900, "C91818F9-8025-47AF-89D2-F030D7000C2C", "Plan 9");
|
||||
|
||||
// PowerPC reference platform boot partition
|
||||
AddType(0x4100, "9E1A2D38-C612-4316-AA26-8B49521E5A8B", "PowerPC PReP boot");
|
||||
|
||||
// Windows LDM ("dynamic disk") types
|
||||
AddType(0x4200, "AF9B60A0-1431-4F62-BC68-3311714A69AD", "Windows LDM data"); // Logical disk manager
|
||||
AddType(0x4201, "5808C8AA-7E8F-42E0-85D2-E1E90434CFB3", "Windows LDM metadata"); // Logical disk manager
|
||||
AddType(0x4202, "E75CAF8F-F680-4CEE-AFA3-B001E56EFC2D", "Windows Storage Spaces"); // A newer LDM-type setup
|
||||
|
||||
// An oddball IBM filesystem....
|
||||
AddType(0x7501, "37AFFC90-EF7D-4E96-91C3-2D7AE055B174", "IBM GPFS"); // General Parallel File System (GPFS)
|
||||
@@ -123,13 +131,24 @@ void PartType::AddAllTypes(void) {
|
||||
AddType(0x8200, "0657FD6D-A4AB-43C4-84E5-0933C84B4F4F", "Linux swap"); // Linux swap (or Solaris on MBR)
|
||||
AddType(0x8300, "0FC63DAF-8483-4772-8E79-3D69D8477DE4", "Linux filesystem"); // Linux native
|
||||
AddType(0x8301, "8DA63339-0007-60C0-C436-083AC8230908", "Linux reserved");
|
||||
// See http://www.freedesktop.org/software/systemd/man/systemd-gpt-auto-generator.html
|
||||
// and http://www.freedesktop.org/wiki/Specifications/DiscoverablePartitionsSpec/
|
||||
// See https://www.freedesktop.org/software/systemd/man/systemd-gpt-auto-generator.html
|
||||
// and https://systemd.io/DISCOVERABLE_PARTITIONS
|
||||
AddType(0x8302, "933AC7E1-2EB4-4F13-B844-0E14E2AEF915", "Linux /home"); // Linux /home (auto-mounted by systemd)
|
||||
AddType(0x8303, "44479540-F297-41B2-9AF7-D131D5F0458A", "Linux x86 root (/)"); // Linux / on x86 (auto-mounted by systemd)
|
||||
AddType(0x8304, "4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709", "Linux x86-64 root (/)"); // Linux / on x86-64 (auto-mounted by systemd)
|
||||
AddType(0x8305, "B921B045-1DF0-41C3-AF44-4C6F280D3FAE", "Linux ARM64 root (/)"); // Linux / on 64-bit ARM (auto-mounted by systemd)
|
||||
AddType(0x8306, "3B8F8425-20E0-4F3B-907F-1A25A76F98E8", "Linux /srv"); // Linux /srv (auto-mounted by systemd)
|
||||
AddType(0x8307, "69DAD710-2CE4-4E3C-B16C-21A1D49ABED3", "Linux ARM32 root (/)"); // Linux / on 32-bit ARM (auto-mounted by systemd)
|
||||
AddType(0x8308, "7FFEC5C9-2D00-49B7-8941-3EA10A5586B7", "Linux dm-crypt");
|
||||
AddType(0x8309, "CA7D7CCB-63ED-4C53-861C-1742536059CC", "Linux LUKS");
|
||||
AddType(0x830A, "993D8D3D-F80E-4225-855A-9DAF8ED7EA97", "Linux IA-64 root (/)"); // Linux / on Itanium (auto-mounted by systemd)
|
||||
AddType(0x830B, "D13C5D3B-B5D1-422A-B29F-9454FDC89D76", "Linux x86 root verity");
|
||||
AddType(0x830C, "2C7357ED-EBD2-46D9-AEC1-23D437EC2BF5", "Linux x86-64 root verity");
|
||||
AddType(0x830D, "7386CDF2-203C-47A9-A498-F2ECCE45A2D6", "Linux ARM32 root verity");
|
||||
AddType(0x830E, "DF3300CE-D69F-4C92-978C-9BFB0F38D820", "Linux ARM64 root verity");
|
||||
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)
|
||||
|
||||
// Used by Intel Rapid Start technology
|
||||
AddType(0x8400, "D3BFE2DE-3DAF-11DF-BA40-E3A556D89593", "Intel Rapid Start");
|
||||
@@ -137,6 +156,78 @@ void PartType::AddAllTypes(void) {
|
||||
// Another Linux type code....
|
||||
AddType(0x8e00, "E6D6D379-F507-44C2-A23C-238F2A3DF928", "Linux LVM");
|
||||
|
||||
// Android type codes....
|
||||
// from Wikipedia, https://gist.github.com/culots/704afd126dec2f45c22d0c9d42cb7fab,
|
||||
// and my own Android devices' partition tables
|
||||
AddType(0xa000, "2568845D-2332-4675-BC39-8FA5A4748D15", "Android bootloader");
|
||||
AddType(0xa001, "114EAFFE-1552-4022-B26E-9B053604CF84", "Android bootloader 2");
|
||||
AddType(0xa002, "49A4D17F-93A3-45C1-A0DE-F50B2EBE2599", "Android boot 1");
|
||||
AddType(0xa003, "4177C722-9E92-4AAB-8644-43502BFD5506", "Android recovery 1");
|
||||
AddType(0xa004, "EF32A33B-A409-486C-9141-9FFB711F6266", "Android misc");
|
||||
AddType(0xa005, "20AC26BE-20B7-11E3-84C5-6CFDB94711E9", "Android metadata");
|
||||
AddType(0xa006, "38F428E6-D326-425D-9140-6E0EA133647C", "Android system 1");
|
||||
AddType(0xa007, "A893EF21-E428-470A-9E55-0668FD91A2D9", "Android cache");
|
||||
AddType(0xa008, "DC76DDA9-5AC1-491C-AF42-A82591580C0D", "Android data");
|
||||
AddType(0xa009, "EBC597D0-2053-4B15-8B64-E0AAC75F4DB1", "Android persistent");
|
||||
AddType(0xa00a, "8F68CC74-C5E5-48DA-BE91-A0C8C15E9C80", "Android factory");
|
||||
AddType(0xa00b, "767941D0-2085-11E3-AD3B-6CFDB94711E9", "Android fastboot/tertiary");
|
||||
AddType(0xa00c, "AC6D7924-EB71-4DF8-B48D-E267B27148FF", "Android OEM");
|
||||
AddType(0xa00d, "C5A0AEEC-13EA-11E5-A1B1-001E67CA0C3C", "Android vendor");
|
||||
AddType(0xa00e, "BD59408B-4514-490D-BF12-9878D963F378", "Android config");
|
||||
AddType(0xa00f, "9FDAA6EF-4B3F-40D2-BA8D-BFF16BFB887B", "Android factory (alt)");
|
||||
AddType(0xa010, "19A710A2-B3CA-11E4-B026-10604B889DCF", "Android meta");
|
||||
AddType(0xa011, "193D1EA4-B3CA-11E4-B075-10604B889DCF", "Android EXT");
|
||||
AddType(0xa012, "DEA0BA2C-CBDD-4805-B4F9-F428251C3E98", "Android SBL1");
|
||||
AddType(0xa013, "8C6B52AD-8A9E-4398-AD09-AE916E53AE2D", "Android SBL2");
|
||||
AddType(0xa014, "05E044DF-92F1-4325-B69E-374A82E97D6E", "Android SBL3");
|
||||
AddType(0xa015, "400FFDCD-22E0-47E7-9A23-F16ED9382388", "Android APPSBL");
|
||||
AddType(0xa016, "A053AA7F-40B8-4B1C-BA08-2F68AC71A4F4", "Android QSEE/tz");
|
||||
AddType(0xa017, "E1A6A689-0C8D-4CC6-B4E8-55A4320FBD8A", "Android QHEE/hyp");
|
||||
AddType(0xa018, "098DF793-D712-413D-9D4E-89D711772228", "Android RPM");
|
||||
AddType(0xa019, "D4E0D938-B7FA-48C1-9D21-BC5ED5C4B203", "Android WDOG debug/sdi");
|
||||
AddType(0xa01a, "20A0C19C-286A-42FA-9CE7-F64C3226A794", "Android DDR");
|
||||
AddType(0xa01b, "A19F205F-CCD8-4B6D-8F1E-2D9BC24CFFB1", "Android CDT");
|
||||
AddType(0xa01c, "66C9B323-F7FC-48B6-BF96-6F32E335A428", "Android RAM dump");
|
||||
AddType(0xa01d, "303E6AC3-AF15-4C54-9E9B-D9A8FBECF401", "Android SEC");
|
||||
AddType(0xa01e, "C00EEF24-7709-43D6-9799-DD2B411E7A3C", "Android PMIC");
|
||||
AddType(0xa01f, "82ACC91F-357C-4A68-9C8F-689E1B1A23A1", "Android misc 1");
|
||||
AddType(0xa020, "E2802D54-0545-E8A1-A1E8-C7A3E245ACD4", "Android misc 2");
|
||||
AddType(0xa021, "65ADDCF4-0C5C-4D9A-AC2D-D90B5CBFCD03", "Android device info");
|
||||
AddType(0xa022, "E6E98DA2-E22A-4D12-AB33-169E7DEAA507", "Android APDP");
|
||||
AddType(0xa023, "ED9E8101-05FA-46B7-82AA-8D58770D200B", "Android MSADP");
|
||||
AddType(0xa024, "11406F35-1173-4869-807B-27DF71802812", "Android DPO");
|
||||
AddType(0xa025, "9D72D4E4-9958-42DA-AC26-BEA7A90B0434", "Android recovery 2");
|
||||
AddType(0xa026, "6C95E238-E343-4BA8-B489-8681ED22AD0B", "Android persist");
|
||||
AddType(0xa027, "EBBEADAF-22C9-E33B-8F5D-0E81686A68CB", "Android modem ST1");
|
||||
AddType(0xa028, "0A288B1F-22C9-E33B-8F5D-0E81686A68CB", "Android modem ST2");
|
||||
AddType(0xa029, "57B90A16-22C9-E33B-8F5D-0E81686A68CB", "Android FSC");
|
||||
AddType(0xa02a, "638FF8E2-22C9-E33B-8F5D-0E81686A68CB", "Android FSG 1");
|
||||
AddType(0xa02b, "2013373E-1AC4-4131-BFD8-B6A7AC638772", "Android FSG 2");
|
||||
AddType(0xa02c, "2C86E742-745E-4FDD-BFD8-B6A7AC638772", "Android SSD");
|
||||
AddType(0xa02d, "DE7D4029-0F5B-41C8-AE7E-F6C023A02B33", "Android keystore");
|
||||
AddType(0xa02e, "323EF595-AF7A-4AFA-8060-97BE72841BB9", "Android encrypt");
|
||||
AddType(0xa02f, "45864011-CF89-46E6-A445-85262E065604", "Android EKSST");
|
||||
AddType(0xa030, "8ED8AE95-597F-4C8A-A5BD-A7FF8E4DFAA9", "Android RCT");
|
||||
AddType(0xa031, "DF24E5ED-8C96-4B86-B00B-79667DC6DE11", "Android spare1");
|
||||
AddType(0xa032, "7C29D3AD-78B9-452E-9DEB-D098D542F092", "Android spare2");
|
||||
AddType(0xa033, "379D107E-229E-499D-AD4F-61F5BCF87BD4", "Android spare3");
|
||||
AddType(0xa034, "0DEA65E5-A676-4CDF-823C-77568B577ED5", "Android spare4");
|
||||
AddType(0xa035, "4627AE27-CFEF-48A1-88FE-99C3509ADE26", "Android raw resources");
|
||||
AddType(0xa036, "20117F86-E985-4357-B9EE-374BC1D8487D", "Android boot 2");
|
||||
AddType(0xa037, "86A7CB80-84E1-408C-99AB-694F1A410FC7", "Android FOTA");
|
||||
AddType(0xa038, "97D7B011-54DA-4835-B3C4-917AD6E73D74", "Android system 2");
|
||||
AddType(0xa039, "5594C694-C871-4B5F-90B1-690A6F68E0F7", "Android cache");
|
||||
AddType(0xa03a, "1B81E7E6-F50D-419B-A739-2AEEF8DA3335", "Android user data");
|
||||
AddType(0xa03b, "98523EC6-90FE-4C67-B50A-0FC59ED6F56D", "LG (Android) advanced flasher");
|
||||
AddType(0xa03c, "2644BCC0-F36A-4792-9533-1738BED53EE3", "Android PG1FS");
|
||||
AddType(0xa03d, "DD7C91E9-38C9-45C5-8A12-4A80F7E14057", "Android PG2FS");
|
||||
AddType(0xa03e, "7696D5B6-43FD-4664-A228-C563C4A1E8CC", "Android board info");
|
||||
AddType(0xa03f, "0D802D54-058D-4A20-AD2D-C7A362CEACD4", "Android MFG");
|
||||
AddType(0xa040, "10A0C19C-516A-5444-5CE3-664C3226A794", "Android limits");
|
||||
|
||||
// Atari TOS partition type
|
||||
AddType(0xa200, "734E5AFE-F61A-11E6-BC64-92361F002671", "Atari TOS basic data");
|
||||
|
||||
// FreeBSD partition types....
|
||||
// Note: Rather than extract FreeBSD disklabel data, convert FreeBSD
|
||||
// partitions in-place, and let FreeBSD sort out the details....
|
||||
@@ -155,6 +246,9 @@ void PartType::AddAllTypes(void) {
|
||||
AddType(0xa584, "85D5E45D-237C-11E1-B4B3-E89A8F7FC3A7", "Midnight BSD ZFS");
|
||||
AddType(0xa585, "85D5E45C-237C-11E1-B4B3-E89A8F7FC3A7", "Midnight BSD Vinum");
|
||||
|
||||
// OpenBSD partition type....
|
||||
AddType(0xa600, "824CC7A0-36A8-11E3-890A-952519AD3F61", "OpenBSD disklabel");
|
||||
|
||||
// A MacOS partition type, separated from others by NetBSD partition types...
|
||||
AddType(0xa800, "55465300-0000-11AA-AA11-00306543ECAC", "Apple UFS"); // Mac OS X
|
||||
|
||||
@@ -169,13 +263,24 @@ void PartType::AddAllTypes(void) {
|
||||
AddType(0xa906, "49F48DAA-B10E-11DC-B99B-0019D1879648", "NetBSD RAID");
|
||||
|
||||
// Mac OS partition types (See also 0xa800, above)....
|
||||
AddType(0xab00, "426F6F74-0000-11AA-AA11-00306543ECAC", "Apple boot");
|
||||
AddType(0xab00, "426F6F74-0000-11AA-AA11-00306543ECAC", "Recovery HD");
|
||||
AddType(0xaf00, "48465300-0000-11AA-AA11-00306543ECAC", "Apple HFS/HFS+");
|
||||
AddType(0xaf01, "52414944-0000-11AA-AA11-00306543ECAC", "Apple RAID");
|
||||
AddType(0xaf02, "52414944-5F4F-11AA-AA11-00306543ECAC", "Apple RAID offline");
|
||||
AddType(0xaf03, "4C616265-6C00-11AA-AA11-00306543ECAC", "Apple label");
|
||||
AddType(0xaf04, "5265636F-7665-11AA-AA11-00306543ECAC", "AppleTV recovery");
|
||||
AddType(0xaf05, "53746F72-6167-11AA-AA11-00306543ECAC", "Apple Core Storage");
|
||||
AddType(0xaf06, "B6FA30DA-92D2-4A9A-96F1-871EC6486200", "Apple SoftRAID Status");
|
||||
AddType(0xaf07, "2E313465-19B9-463F-8126-8A7993773801", "Apple SoftRAID Scratch");
|
||||
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");
|
||||
|
||||
// QNX Power-Safe (QNX6)
|
||||
AddType(0xb300, "CEF5A9AD-73BC-4601-89F3-CDEEEEE321A1", "QNX6 Power-Safe");
|
||||
|
||||
// Acronis Secure Zone
|
||||
AddType(0xbc00, "0311FC50-01CA-4725-AD77-9ADBB20ACE98", "Acronis Secure Zone");
|
||||
|
||||
// Solaris partition types (one of which is shared with MacOS)
|
||||
AddType(0xbe00, "6A82CB45-1DD2-11B2-99A6-080020736631", "Solaris boot");
|
||||
@@ -197,6 +302,10 @@ void PartType::AddAllTypes(void) {
|
||||
AddType(0xc001, "75894C1E-3AEB-11D3-B7C1-7B03A0000000", "HP-UX data");
|
||||
AddType(0xc002, "E2A1E728-32E3-11D6-A682-7B03A0000000", "HP-UX service");
|
||||
|
||||
// Open Network Install Environment (ONIE) partitions....
|
||||
AddType(0xe100, "7412F7D5-A156-4B13-81DC-867174929325", "ONIE boot");
|
||||
AddType(0xe101, "D4E6E2CD-4469-46F3-B5CB-1BFF57AFC149", "ONIE config");
|
||||
|
||||
// See http://www.freedesktop.org/wiki/Specifications/BootLoaderSpec
|
||||
AddType(0xea00, "BC13C2FF-59E6-4262-A352-B275FD6F7172", "Freedesktop $BOOT");
|
||||
|
||||
@@ -208,17 +317,36 @@ void PartType::AddAllTypes(void) {
|
||||
AddType(0xed01, "BFBFAFE7-A34F-448A-9A5B-6213EB736C22", "Lenovo system partition");
|
||||
|
||||
// EFI system and related partitions
|
||||
AddType(0xef00, "C12A7328-F81F-11D2-BA4B-00A0C93EC93B", "EFI System"); // Parted identifies these as having the "boot flag" set
|
||||
AddType(0xef00, "C12A7328-F81F-11D2-BA4B-00A0C93EC93B", "EFI system partition"); // Parted identifies these as having the "boot flag" set
|
||||
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
|
||||
|
||||
// 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
|
||||
AddType(0xf801, "4FBD7E29-9D25-41B8-AFD0-5EC00CEFF05D", "Ceph dm-crypt OSD"); // Ceph Object Storage Daemon (encrypted)
|
||||
AddType(0xf802, "BFBFAFE7-A34F-448A-9A5B-6213EB736C22", "Ceph journal");
|
||||
AddType(0xf802, "45B0969E-9B03-4F30-B4C6-B4B80CEFF106", "Ceph journal");
|
||||
AddType(0xf803, "45B0969E-9B03-4F30-B4C6-5EC00CEFF106", "Ceph dm-crypt journal");
|
||||
AddType(0xf804, "89C57F98-2FE5-4DC0-89C1-F3AD0CEFF2BE", "Ceph disk in creation");
|
||||
AddType(0xf805, "89C57F98-2FE5-4DC0-89C1-5EC00CEFF2BE", "Ceph dm-crypt disk in creation");
|
||||
AddType(0xf806, "CAFECAFE-9B03-4F30-B4C6-B4B80CEFF106", "Ceph block");
|
||||
AddType(0xf807, "30CD0809-C2B2-499C-8879-2D6B78529876", "Ceph block DB");
|
||||
AddType(0xf808, "5CE17FCE-4087-4169-B7FF-056CC58473F9", "Ceph block write-ahead log");
|
||||
AddType(0xf809, "FB3AABF9-D25F-47CC-BF5E-721D1816496B", "Ceph lockbox for dm-crypt keys");
|
||||
AddType(0xf80a, "4FBD7E29-8AE0-4982-BF9D-5A8D867AF560", "Ceph multipath OSD");
|
||||
AddType(0xf80b, "45B0969E-8AE0-4982-BF9D-5A8D867AF560", "Ceph multipath journal");
|
||||
AddType(0xf80c, "CAFECAFE-8AE0-4982-BF9D-5A8D867AF560", "Ceph multipath block 1");
|
||||
AddType(0xf80d, "7F4A666A-16F3-47A2-8445-152EF4D03F6C", "Ceph multipath block 2");
|
||||
AddType(0xf80e, "EC6D6385-E346-45DC-BE91-DA2A7C8B3261", "Ceph multipath block DB");
|
||||
AddType(0xf80f, "01B41E1B-002A-453C-9F17-88793989FF8F", "Ceph multipath block write-ahead log");
|
||||
AddType(0xf810, "CAFECAFE-9B03-4F30-B4C6-5EC00CEFF106", "Ceph dm-crypt block");
|
||||
AddType(0xf811, "93B0052D-02D9-4D8A-A43B-33A3EE4DFBC3", "Ceph dm-crypt block DB");
|
||||
AddType(0xf812, "306E8683-4FE2-4330-B7C0-00A917C16966", "Ceph dm-crypt block write-ahead log");
|
||||
AddType(0xf813, "45B0969E-9B03-4F30-B4C6-35865CEFF106", "Ceph dm-crypt LUKS journal");
|
||||
AddType(0xf814, "CAFECAFE-9B03-4F30-B4C6-35865CEFF106", "Ceph dm-crypt LUKS block");
|
||||
AddType(0xf815, "166418DA-C469-4022-ADF4-B30AFD37F176", "Ceph dm-crypt LUKS block DB");
|
||||
AddType(0xf816, "86A32090-3647-40B9-BBBD-38D8C573AA86", "Ceph dm-crypt LUKS block write-ahead log");
|
||||
AddType(0xf817, "4FBD7E29-9D25-41B8-AFD0-35865CEFF05D", "Ceph dm-crypt LUKS OSD");
|
||||
|
||||
// VMWare ESX partition types codes
|
||||
AddType(0xfb00, "AA31E02A-400F-11DB-9590-000C2911D1B8", "VMWare VMFS");
|
||||
@@ -381,23 +509,32 @@ uint16_t PartType::GetHexType() const {
|
||||
// it stops at under 80 columns; on narrower displays, lines will wrap
|
||||
// in an ugly way. The maxLines value is the maximum number of lines
|
||||
// to display before prompting to continue, or 0 (or a negative value)
|
||||
// for no limit.
|
||||
// for no limit. If (maxLines > 0), this function will prompt for a
|
||||
// substring to search for in the partition type description, so it's
|
||||
// imperative that maxLines be set to 0 in non-interactive contexts
|
||||
// (namely, sgdisk).
|
||||
void PartType::ShowAllTypes(int maxLines) const {
|
||||
int colCount = 1, lineCount = 1;
|
||||
size_t i;
|
||||
AType* thisType = allTypes;
|
||||
string line;
|
||||
string line, matchString = "";
|
||||
size_t found;
|
||||
|
||||
cout.unsetf(ios::uppercase);
|
||||
if (maxLines > 0) {
|
||||
cout << "Type search string, or <Enter> to show all codes: ";
|
||||
matchString = ReadString();
|
||||
} // if
|
||||
while (thisType != NULL) {
|
||||
if (thisType->display == 1) { // show it
|
||||
found = thisType->name.find(matchString);
|
||||
if ((thisType->display == 1) && (found != string::npos)) { // show it
|
||||
cout.fill('0');
|
||||
cout.width(4);
|
||||
cout << hex << thisType->MBRType << " ";
|
||||
cout << thisType->name.substr(0, 20);
|
||||
for (i = 0; i < (20 - (thisType->name.substr(0, 20).length())); i++)
|
||||
cout << thisType->name.substr(0, DESC_LENGTH);
|
||||
for (i = 0; i < (DESC_LENGTH - (thisType->name.substr(0, DESC_LENGTH).length())); i++)
|
||||
cout << " ";
|
||||
if ((colCount % 3) == 0) {
|
||||
if ((colCount % NUM_COLUMNS) == 0) {
|
||||
if (thisType->next) {
|
||||
cout << "\n";
|
||||
if ((maxLines > 0) && (lineCount++ % maxLines) == 0) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* This program is copyright (c) 2009-2013 by Roderick W. Smith. It is distributed
|
||||
/* 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. */
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
103
sgdisk.8
103
sgdisk.8
@@ -1,6 +1,6 @@
|
||||
.\" Copyright 2011-2013 Roderick W. Smith (rodsmith@rodsbooks.com)
|
||||
.\" Copyright 2011-2018 Roderick W. Smith (rodsmith@rodsbooks.com)
|
||||
.\" May be distributed under the GNU General Public License
|
||||
.TH "SGDISK" "8" "0.8.10" "Roderick W. Smith" "GPT fdisk Manual"
|
||||
.TH "SGDISK" "8" "1.0.4" "Roderick W. Smith" "GPT fdisk Manual"
|
||||
.SH "NAME"
|
||||
sgdisk \- Command\-line GUID partition table (GPT) manipulator for Linux and Unix
|
||||
.SH "SYNOPSIS"
|
||||
@@ -87,19 +87,21 @@ and in whatever sizes are desired.
|
||||
|
||||
.TP
|
||||
.B *
|
||||
Boot disks for EFI\-based systems require an \fIEFI System
|
||||
Partition\fR (\fBsgdisk\fR internal code 0xEF00) formatted as FAT\-32.
|
||||
The recommended size of this partition is between 100 and 300 MiB.
|
||||
Boot\-related files are stored here. (Note that GNU Parted identifies
|
||||
such partitions as having the "boot flag" set.)
|
||||
Boot disks for EFI\-based systems require an \fIEFI System Partition\fR
|
||||
(\fBgdisk\fR internal code 0xEF00) formatted as FAT\-32. I recommended
|
||||
making this partition 550 MiB. (Smaller ESPs are common, but some EFIs have
|
||||
flaky FAT drivers that necessitate a larger partition for reliable
|
||||
operation.) Boot\-related files are stored here. (Note that GNU Parted
|
||||
identifies such partitions as having the "boot flag" set.)
|
||||
|
||||
.TP
|
||||
.B *
|
||||
Some boot loaders for BIOS\-based systems make use of a \fIBIOS Boot
|
||||
Partition\fR (\fBsgdisk\fR internal code 0xEF02), in which the secondary
|
||||
boot loader is stored, possibly without the benefit of a filesystem. This
|
||||
partition can typically be quite small (roughly 32 to 200 KiB), but you
|
||||
should consult your boot loader documentation for details.
|
||||
Partition\fR (\fBgdisk\fR internal code 0xEF02), in which the secondary
|
||||
boot loader is stored, possibly without the benefit of a filesystem. (GRUB2
|
||||
may optionally use such a partition.) This partition can typically be quite
|
||||
small (roughly 32 to 200 KiB, although 1 MiB is more common in practice),
|
||||
but you should consult your boot loader documentation for details.
|
||||
|
||||
.TP
|
||||
.B *
|
||||
@@ -148,11 +150,11 @@ sibling. Options available in \fBsgdisk\fR are:
|
||||
.TP
|
||||
.B \-a, \-\-set\-alignment=value
|
||||
Set the sector alignment multiple. GPT fdisk aligns the start of partitions
|
||||
to sectors that are multiples of this value, which defaults to 2048 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.
|
||||
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.
|
||||
|
||||
.TP
|
||||
.B \-A, \-\-attributes=list|[partnum:show|or|nand|xor|=|set|clear|toggle|get[:bitnum|hexbitmask]]
|
||||
@@ -217,7 +219,7 @@ of the sector value reported by this option. You can change the alignment value
|
||||
with the \-a option.
|
||||
|
||||
.TP
|
||||
.B e, \-\-move\-second\-header
|
||||
.B \-e, \-\-move\-second\-header
|
||||
Move backup GPT data structures to the end of the disk. Use this option if
|
||||
you've added disks to a RAID array, thus creating a virtual disk with space
|
||||
that follows the backup GPT data structures. This command moves the backup
|
||||
@@ -262,13 +264,13 @@ in order to render all GUIDs once again unique.
|
||||
.TP
|
||||
.B \-h, \-\-hybrid
|
||||
Create a hybrid MBR. This option takes from one to three partition numbers,
|
||||
separated by colons, as arguments. The created hybrid MBR places an EFI GPT
|
||||
(type 0xEE) partition first in the table, followed by the partition(s) you
|
||||
specify. Their type codes are based on the GPT fdisk type codes divided by
|
||||
0x0100, which 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.
|
||||
separated by colons, as arguments. You may optionally specify a final partition
|
||||
"EE" to indicate that the EFI GPT (type 0xEE) should be placed last in the table,
|
||||
otherwise it will be placed first, followed by the partition(s) you specify.
|
||||
Their type codes are based on the GPT fdisk type codes divided by 0x0100, which
|
||||
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
|
||||
.B \-i, \-\-info=partnum
|
||||
@@ -278,6 +280,14 @@ 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 \-j, \-\-adjust\-main\-table=sector
|
||||
Adjust the location of the main partition table. This value is normally 2,
|
||||
but it may need to be increased in some cases, such as when a
|
||||
system\-on\-chip (SoC) is hard\-coded to read boot code from sector 2. I
|
||||
recommend against adjusting this value unless doing so is absolutely
|
||||
necessary.
|
||||
|
||||
.TP
|
||||
.B \-l, \-\-load\-backup=file
|
||||
Load partition data from a backup file. This option is the reverse of the
|
||||
@@ -335,10 +345,7 @@ to use the first available partition number. Subsequent uses of the
|
||||
.TP
|
||||
.B \-N, \-\-largest\-new=num
|
||||
Create a new partition that fills the largest available block of space on
|
||||
the disk. Note that if used on a completely blank disk, this is likely to
|
||||
result in a sector-moved warning, since the first available sector
|
||||
(normally 34) doesn't fall on a 2048-sector boundary (the default for
|
||||
alignment). You can use the \fI\-a\fR (\fI\-\-set\-alignment\fR) option to
|
||||
the disk. You can use the \fI\-a\fR (\fI\-\-set\-alignment\fR) option to
|
||||
adjust the alignment, if desired. A num value of 0 causes the program to
|
||||
use the first available partition number.
|
||||
|
||||
@@ -352,12 +359,20 @@ 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.
|
||||
|
||||
.TP
|
||||
.B \-O, \-\-print\-mbr
|
||||
Display basic \fIMBR\fR partition summary data. This includes partition
|
||||
numbers, starting and ending sector numbers, partition sizes, MBR partition
|
||||
types codes, and partition names. This option is useful mainly for
|
||||
diagnosing partition table problems, particularly on disks with hybrid
|
||||
MBRs.
|
||||
|
||||
.TP
|
||||
.B \-p, \-\-print
|
||||
Display basic partition summary data. This includes partition
|
||||
numbers, starting and ending sector numbers, partition sizes,
|
||||
\fBsgdisk\fR's partition types codes, and partition names. For
|
||||
additional information, use the \fI\-i\fR (\fI\-\-info\fR) option.
|
||||
Display basic GPT partition summary data. This includes partition numbers,
|
||||
starting and ending sector numbers, partition sizes, \fBsgdisk\fR's
|
||||
partition types codes, and partition names. For additional information, use
|
||||
the \fI\-i\fR (\fI\-\-info\fR) option.
|
||||
|
||||
.TP
|
||||
.B \-P, \-\-pretend
|
||||
@@ -475,7 +490,8 @@ An error occurred while reading the partition table
|
||||
|
||||
.TP
|
||||
.B 3
|
||||
Non\-GPT disk detected and no \fI\-g\fR option
|
||||
Non\-GPT disk detected and no \fI\-g\fR option, but operation requires a
|
||||
write action
|
||||
|
||||
.TP
|
||||
.B 4
|
||||
@@ -491,8 +507,7 @@ sgdisk, but may with gdisk)
|
||||
Disk replication operation (-R) failed
|
||||
|
||||
.SH "BUGS"
|
||||
As of March 2014 (version 0.8.10), \fBsgdisk\fR
|
||||
should be considered beta software. Known bugs and limitations include:
|
||||
Known bugs and limitations include:
|
||||
|
||||
.TP
|
||||
.B *
|
||||
@@ -578,20 +593,20 @@ Contributors:
|
||||
|
||||
* Justin Maggard (justin.maggard@netgear.com)
|
||||
|
||||
* Dwight Schauer (dschauer@ti.com)
|
||||
* Dwight Schauer (dschauer@gmail.com)
|
||||
|
||||
* Florian Zumbiehl (florz@florz.de)
|
||||
|
||||
|
||||
.SH "SEE ALSO"
|
||||
\fBcfdisk (8)\fR,
|
||||
\fBcgdisk (8)\fR,
|
||||
\fBfdisk (8)\fR,
|
||||
\fBgdisk (8)\fR,
|
||||
\fBmkfs (8)\fR,
|
||||
\fBparted (8)\fR,
|
||||
\fBsfdisk (8)\fR
|
||||
\fBfixparts (8)\fR
|
||||
.BR cfdisk (8),
|
||||
.BR cgdisk (8),
|
||||
.BR fdisk (8),
|
||||
.BR gdisk (8),
|
||||
.BR mkfs (8),
|
||||
.BR parted (8),
|
||||
.BR sfdisk (8),
|
||||
.BR fixparts (8).
|
||||
|
||||
\fIhttp://en.wikipedia.org/wiki/GUID_Partition_Table\fR
|
||||
|
||||
|
||||
37
support.cc
37
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-2013 by Roderick W. Smith. It is distributed
|
||||
/* 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. */
|
||||
|
||||
#define __STDC_LIMIT_MACROS
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <inttypes.h>
|
||||
#include <sstream>
|
||||
#include "support.h"
|
||||
|
||||
@@ -36,31 +37,51 @@ using namespace std;
|
||||
// Reads a string from stdin, returning it as a C++-style string.
|
||||
// Note that the returned string will NOT include the carriage return
|
||||
// entered by the user.
|
||||
#ifdef EFI
|
||||
extern int __sscanf( const char * str , const char * format , ... ) ;
|
||||
string ReadString(void) {
|
||||
string inString;
|
||||
char efiString[256];
|
||||
int stringLength;
|
||||
|
||||
if (fgets(efiString, 255, stdin) != NULL) {
|
||||
stringLength = strlen(efiString);
|
||||
if ((stringLength > 0) && (efiString[stringLength - 1] == '\n'))
|
||||
efiString[stringLength - 1] = '\0';
|
||||
inString = efiString;
|
||||
} else {
|
||||
inString = "";
|
||||
}
|
||||
return inString;
|
||||
} // ReadString()
|
||||
#else
|
||||
string ReadString(void) {
|
||||
string inString;
|
||||
|
||||
cout << flush;
|
||||
getline(cin, inString);
|
||||
if (!cin.good())
|
||||
exit(5);
|
||||
return inString;
|
||||
} // ReadString()
|
||||
#endif
|
||||
|
||||
// Get a numeric value from the user, between low and high (inclusive).
|
||||
// Keeps looping until the user enters a value within that range.
|
||||
// If user provides no input, def (default value) is returned.
|
||||
// (If def is outside of the low-high range, an explicit response
|
||||
// is required.)
|
||||
int GetNumber(int low, int high, int def, const string & prompt) {
|
||||
int response, num;
|
||||
uint64_t GetNumber(uint64_t low, uint64_t high, uint64_t def, const string & prompt) {
|
||||
uint64_t response, num;
|
||||
char line[255];
|
||||
|
||||
if (low != high) { // bother only if low and high differ...
|
||||
do {
|
||||
cout << prompt;
|
||||
cout << prompt << flush;
|
||||
cin.getline(line, 255);
|
||||
if (!cin.good())
|
||||
exit(5);
|
||||
num = sscanf(line, "%d", &response);
|
||||
num = sscanf(line, "%" SCNu64, &response);
|
||||
if (num == 1) { // user provided a response
|
||||
if ((response < low) || (response > high))
|
||||
cout << "Value out of range\n";
|
||||
@@ -84,7 +105,7 @@ char GetYN(void) {
|
||||
do {
|
||||
if ( again ) { cout << "Your option? " ; }
|
||||
again = 1 ;
|
||||
cout << "(Y/N): ";
|
||||
cout << "(Y/N): " << flush;
|
||||
line = ReadString();
|
||||
response = toupper(line[0]);
|
||||
} while ((response != 'Y') && (response != 'N'));
|
||||
@@ -134,7 +155,7 @@ uint64_t GetSectorNum(uint64_t low, uint64_t high, uint64_t def, uint64_t sSize,
|
||||
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;
|
||||
size_t foundAt = 0;
|
||||
char suffix, plusFlag = ' ';
|
||||
char suffix = ' ', plusFlag = ' ';
|
||||
string suffixes = "KMGTPE";
|
||||
int badInput = 0; // flag bad input; once this goes to 1, other values are irrelevant
|
||||
|
||||
@@ -227,7 +248,7 @@ string BytesToIeee(uint64_t size, uint32_t sectorSize) {
|
||||
uint64_t sizeInIeee;
|
||||
uint64_t previousIeee;
|
||||
float decimalIeee;
|
||||
uint index = 0;
|
||||
uint64_t index = 0;
|
||||
string units, prefixes = " KMGTPEZ";
|
||||
ostringstream theValue;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* This program is copyright (c) 2009-2013 by Roderick W. Smith. It is distributed
|
||||
/* 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. */
|
||||
|
||||
#include <stdint.h>
|
||||
@@ -8,7 +8,7 @@
|
||||
#ifndef __GPTSUPPORT
|
||||
#define __GPTSUPPORT
|
||||
|
||||
#define GPTFDISK_VERSION "0.8.10.2"
|
||||
#define GPTFDISK_VERSION "1.0.4"
|
||||
|
||||
#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined (__APPLE__)
|
||||
// Darwin (Mac OS) & FreeBSD: disk IOCTLs are different, and there is no lseek64
|
||||
@@ -72,7 +72,7 @@
|
||||
using namespace std;
|
||||
|
||||
string ReadString(void);
|
||||
int GetNumber(int low, int high, int def, const string & prompt);
|
||||
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);
|
||||
|
||||
24
uninstall-fixparts
Executable file
24
uninstall-fixparts
Executable file
@@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script to uninstall FixParts from OS X
|
||||
|
||||
OSName=`uname -s`
|
||||
if [[ $OSName != 'Darwin' ]] ; then
|
||||
echo "This script is useful only under OS X! Exiting!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Remove from pre-1.0.1 locations
|
||||
rm -f /usr/sbin/fixparts
|
||||
rm -rf /usr/share/doc/fixparts
|
||||
rm -f /usr/share/man/man8/fixparts.8
|
||||
|
||||
# Remove from 1.0.1 (and later) locations
|
||||
rm -f /usr/local/bin/fixparts
|
||||
rm -rf /usr/local/doc/fixparts
|
||||
rm -f /usr/local/man/man8/fixparts.8
|
||||
|
||||
echo "All FixParts program files successfully removed!"
|
||||
|
||||
# And finally, erase this script itself....
|
||||
rm -f /usr/local/bin/uninstall-fixparts
|
||||
32
uninstall-gdisk
Executable file
32
uninstall-gdisk
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script to uninstall GPT fdisk from OS X
|
||||
|
||||
OSName=`uname -s`
|
||||
if [[ $OSName != 'Darwin' ]] ; then
|
||||
echo "This script is useful only under OS X! Exiting!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Remove from pre-1.0.1 locations
|
||||
rm -f /usr/sbin/gdisk
|
||||
rm -f /usr/sbin/sgdisk
|
||||
rm -f /usr/sbin/cgdisk
|
||||
rm -rf /usr/share/doc/gdisk/
|
||||
rm -f /usr/share/man/man8/gdisk.8
|
||||
rm -f /usr/share/man/man8/sgdisk.8
|
||||
rm -f /usr/share/man/man8/cgdisk.8
|
||||
|
||||
# Remove from 1.0.1 (and later) locations
|
||||
rm -f /usr/local/bin/gdisk
|
||||
rm -f /usr/local/bin/sgdisk
|
||||
rm -f /usr/local/bin/cgdisk
|
||||
rm -rf /usr/local/doc/gdisk
|
||||
rm -f /usr/local/man/man8/gdisk.8
|
||||
rm -f /usr/local/man/man8/sgdisk.8
|
||||
rm -f /usr/local/man/man8/cgdisk.8
|
||||
|
||||
echo "All GPT fdisk program files successfully removed!"
|
||||
|
||||
# And finally, erase this script itself....
|
||||
rm -f /usr/local/bin/uninstall-gdisk
|
||||
Reference in New Issue
Block a user