Commit 72e81a3f authored by Guillaume Delacour's avatar Guillaume Delacour

Imported Upstream version 0.8.10

parent 8fe59f55
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
#CXXFLAGS+=-Wall -D_FILE_OFFSET_BITS=64 -D USE_UTF16
CXXFLAGS+=-Wall -D_FILE_OFFSET_BITS=64
LDFLAGS+=
LIB_NAMES=crc32 support guid gptpart mbrpart basicmbr mbr gpt bsd parttypes attributes diskio diskio-unix
MBR_LIBS=support diskio diskio-unix basicmbr mbrpart
......@@ -14,16 +14,16 @@ DEPEND= makedepend $(CXXFLAGS)
all: cgdisk gdisk sgdisk fixparts
gdisk: $(LIB_OBJS) gdisk.o gpttext.o
# $(CXX) $(LIB_OBJS) gdisk.o gpttext.o $(LDFLAGS) -luuid -o gdisk
$(CXX) $(LIB_OBJS) gdisk.o gpttext.o $(LDFLAGS) -licuio -licuuc -luuid -o gdisk
$(CXX) $(LIB_OBJS) gdisk.o gpttext.o $(LDFLAGS) -luuid -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 -lncurses -o cgdisk
$(CXX) $(LIB_OBJS) cgdisk.o gptcurses.o $(LDFLAGS) -licuio -licuuc -luuid -lncurses -o cgdisk
$(CXX) $(LIB_OBJS) cgdisk.o gptcurses.o $(LDFLAGS) -luuid -lncursesw -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) -licuio -licuuc -luuid -lpopt -o sgdisk
$(CXX) $(LIB_OBJS) sgdisk.o gptcl.o $(LDFLAGS) -luuid -lpopt -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
......
CC=gcc
CXX=g++
CFLAGS+=-D_FILE_OFFSET_BITS=64
CXXFLAGS+=-Wall -D_FILE_OFFSET_BITS=64 -D USE_UTF16 -I/usr/local/include
#CXXFLAGS+=-Wall -D_FILE_OFFSET_BITS=64 -I /usr/local/include
#CXXFLAGS+=-Wall -D_FILE_OFFSET_BITS=64 -D USE_UTF16 -I/usr/local/include
CXXFLAGS+=-Wall -D_FILE_OFFSET_BITS=64 -I /usr/local/include
LDFLAGS+=
LIB_NAMES=crc32 support guid gptpart mbrpart basicmbr mbr gpt bsd parttypes attributes diskio diskio-unix
MBR_LIBS=support diskio diskio-unix basicmbr mbrpart
......@@ -14,16 +14,16 @@ DEPEND= makedepend $(CXXFLAGS)
all: gdisk cgdisk sgdisk fixparts
gdisk: $(LIB_OBJS) gdisk.o gpttext.o
$(CXX) $(LIB_OBJS) gdisk.o gpttext.o -L/usr/local/lib $(LDFLAGS) -licuio -luuid -o gdisk
# $(CXX) $(LIB_OBJS) gdisk.o gpttext.o -L/usr/local/lib $(LDFLAGS) -luuid -o gdisk
# $(CXX) $(LIB_OBJS) gdisk.o gpttext.o -L/usr/local/lib $(LDFLAGS) -licuio -luuid -o gdisk
$(CXX) $(LIB_OBJS) gdisk.o gpttext.o -L/usr/local/lib $(LDFLAGS) -luuid -o gdisk
cgdisk: $(LIB_OBJS) cgdisk.o gptcurses.o
$(CXX) $(LIB_OBJS) cgdisk.o gptcurses.o -L/usr/local/lib $(LDFLAGS) -licuio -luuid -lncurses -o cgdisk
# $(CXX) $(LIB_OBJS) cgdisk.o gptcurses.o -L/usr/local/lib $(LDFLAGS) -luuid -lncurses -o cgdisk
# $(CXX) $(LIB_OBJS) cgdisk.o gptcurses.o -L/usr/local/lib $(LDFLAGS) -licuio -luuid -lncurses -o cgdisk
$(CXX) $(LIB_OBJS) cgdisk.o gptcurses.o -L/usr/local/lib $(LDFLAGS) -luuid -lncurses -o cgdisk
sgdisk: $(LIB_OBJS) sgdisk.o gptcl.o
$(CXX) $(LIB_OBJS) sgdisk.o gptcl.o -L/usr/local/lib $(LDFLAGS) -luuid -licuio -lpopt -o sgdisk
# $(CXX) $(LIB_OBJS) sgdisk.o gptcl.o -L/usr/local/lib $(LDFLAGS) -luuid -lpopt -o sgdisk
# $(CXX) $(LIB_OBJS) sgdisk.o gptcl.o -L/usr/local/lib $(LDFLAGS) -luuid -licuio -lpopt -o sgdisk
$(CXX) $(LIB_OBJS) sgdisk.o gptcl.o -L/usr/local/lib $(LDFLAGS) -luuid -lpopt -o sgdisk
fixparts: $(MBR_LIB_OBJS) fixparts.o
$(CXX) $(MBR_LIB_OBJS) fixparts.o -L/usr/local/lib $(LDFLAGS) -o fixparts
......
CC=/usr/bin/i686-pc-mingw32-gcc
CXX=/usr/bin/i686-pc-mingw32-g++
STRIP=/usr/bin/i686-pc-mingw32-strip
CFLAGS=-O2 -D_FILE_OFFSET_BITS=64 -g
CXXFLAGS=-O2 -Wall -D_FILE_OFFSET_BITS=64 -g
CC=/usr/bin/i686-w64-mingw32-gcc
CXX=/usr/bin/i686-w64-mingw32-g++
STRIP=/usr/bin/i686-w64-mingw32-strip
CFLAGS=-O2 -Wall -static -static-libgcc -static-libstdc++ -D_FILE_OFFSET_BITS=64 -g
CXXFLAGS=-O2 -Wall -static -static-libgcc -static-libstdc++ -D_FILE_OFFSET_BITS=64 -g
#CXXFLAGS=-O2 -Wall -D_FILE_OFFSET_BITS=64 -I /usr/local/include -I/opt/local/include -g
LIB_NAMES=guid gptpart bsd parttypes attributes crc32 mbrpart basicmbr mbr gpt support diskio diskio-windows
MBR_LIBS=support diskio diskio-windows basicmbr mbrpart
......@@ -15,13 +15,13 @@ DEPEND= makedepend $(CFLAGS)
all: gdisk fixparts
gdisk: $(LIB_OBJS) gdisk.o gpttext.o
$(CXX) $(LIB_OBJS) gdisk.o gpttext.o -lrpcrt4 -static-libgcc -o gdisk.exe
$(CXX) $(CXXFLAGS) $(LIB_OBJS) gdisk.o gpttext.o -lrpcrt4 -static-libgcc -o gdisk32.exe
sgdisk: $(LIB_OBJS) sgdisk.o
$(CXX) $(LIB_OBJS) sgdisk.o -lpopt -static-libgcc -o sgdisk.exe
$(CXX) $(CXXFLAGS) $(LIB_OBJS) sgdisk.o -lpopt -static-libgcc -o sgdisk32.exe
fixparts: $(MBR_LIB_OBJS) fixparts.o
$(CXX) $(MBR_LIB_OBJS) fixparts.o $(LDFLAGS) -static-libgcc -o fixparts.exe
$(CXX) $(CXXFLAGS) $(MBR_LIB_OBJS) fixparts.o $(LDFLAGS) -static-libgcc -o fixparts32.exe
lint: #no pre-reqs
lint $(SRCS)
......@@ -30,7 +30,7 @@ clean: #no pre-reqs
rm -f core *.o *~ gdisk.exe sgdisk.exe
strip: #no pre-reqs
$(STRIP) gdisk.exe fixparts.exe
$(STRIP) gdisk32.exe fixparts32.exe
# what are the source dependencies
depend: $(SRCS)
......
0.8.10 (3/2/2014):
------------------
- Added feature to sgdisk's -A/--attributes, -c/--change-name,
-t/--typecode, and -u/--partition-guid commands: If a -n/--new option
with "0" as the partition number precedes these options on the command
line, passin "0" as the partition number to the following options causes
them to use the newly-created partition. For instance, "sgdisk -n
0:0:+550M -t 0:EF00 /dev/sda" creates a new partition with a type code of
EF00. (Previous versions would ignore the "-t 0:EF00" option.)
- Fixed bug that caused incorrect partition number to be displayed by
sgdisk in error messages when the user specified a non-existent partition
for inclusion in a hybrid MBR or conversion to a conventional MBR.
- Fixed new (in 0.8.9) bug that caused a failure to create more than one
hybridized partition when creating a hybrid MBR.
- Fixed bug that caused gdisk and sgdisk to create hybridized partitions
that ended at or above the 2^32 sector point with incorrect end values.
The behavior now varies between gdisk and sgdisk: gdisk now creates
hybrid partitions that begin below 2^32 sectors and that are smaller than
2^32 sectors, since this is technically legal; but gdisk displays a
warning, because some OSes (such as DOS, Windows XP, OS/2, and BeOS)
misbehave with such partitions. AFAIK, only Linux, FreeBSD, and Windows 7
work properly with such partitions. Because of this fact and because
sgdisk is a more automated tool, it's stricter in how it handles things:
It refuses to create a hybrid partition if the original ends at or above
the 2^32 sector mark.
0.8.9 (2/17/2014):
------------------
- Removed dependency on libicu for UTF-16 support.
- Fixed spurious "0xEE partition doesn't start on sector 1" warning in
FixParts (and perhaps in other programs under some circumstances).
- Added GPT regeneration command to GPT-destruction options ('z' in gdisk,
-z and -Z options to sgdisk). This is done to avoid wiping out data
mid-disk that might not be backup GPT data structures, which could
otherwise occur if a RAID array was resized in certain ways.
- Added check for an oversized 0xEE protective partition. The program now
auto-repairs this condition on loading if the GPT data seem otherwise
valid. This is done because I've been receiving reports of some disks
(possibly from some OEM Windows 8 loads) that violate the GPT spec in
this way, and gdisk was reporting write errors when saving data.
- If the GPT data seem to be damaged in some way or if the disk seems to
be a hybrid MBR and if the MBR partition(s) don't fit on the disk, the
verify (v) function now warns of this condition, and writing the disk if
it exists also displays a more specific error message about the problem.
- Added new type codes (3000, 7412F7D5-A156-4B13-81DC-867174929325 and
3001, D4E6E2CD-4469-46F3-B5CB-1BFF57AFC149) for Open Network Install
Environment (ONIE) boot and config partitions, respectively.
- Added new type ccde (ED01, BFBFAFE7-A34F-448A-9A5B-6213EB736C22), for
Lenovo's ESP-like partition.
0.8.8 (10/14/2013):
------------_------
-------------------
- Fixed bug that could cause segfault when passing an invalid partition
number to sgdisk's -i/--info command.
......
......@@ -174,17 +174,17 @@ be used instead. In addition, note these requirements:
FreeBSD, the e2fsprogs-libuuid port must be installed.
* The ICU library (http://site.icu-project.org), which provides support for
Unicode partition names, is recommended on all
platforms except Windows. This library is normally installed in Linux and
OS X, but you may need to install the development headers (libicu-dev or
something similar in Linux; or the libicu36-dev Fink package in OS X). To
compile without ICU support, you must modify the Makefile: Remove the
"-D USE_UTF16" part from the CXXFLAGS line and remove references to
-licuio, -licuuc, -licudata, and -licucore (details vary between
platforms) from the compilation options. Suitable lines are present, but
commented out, in the Makefile, Makefile.solaris, Makefile.freebsd files.
Because of problems with ICU under OS X, the Makefile.mac file doesn't
build against ICU by default.
Unicode partition names, is optional on all platforms except Windows, on
which it's not supported. Using this library was required to get proper
UTF-16 partition name support in GPT fdisk versions prior to 0.8.9, but
as of that version it should not longer be required. Nonetheless, you can
use it if you're having problems with the new UTF-16 support. This
library is normally installed in Linux and OS X, but you may need to
install the development headers (libicu-dev or something similar in
Linux; or the libicu36-dev Fink package in OS X). To compile with ICU
support, you must modify the Makefile: Look for commented-out lines that
refer to USE_UTF16, -licuuc, -licudata, or -licucore. Uncomment them and
comment out the equivalents that lack these lines.
* The cgdisk program requires the ncurses library and its development files
(headers). Most Linux distributions install ncurses by default, but you
......
......@@ -671,7 +671,7 @@ int BasicMBRData::LBAtoCHS(uint64_t lba, uint8_t * chs) {
done = 1;
} // if
// If LBA value is too large for CHS, max out CHS values....
if ((!done) && (lba >= (numHeads * numSecspTrack * MAX_CYLINDERS))) {
if ((!done) && (lba >= ((uint64_t) numHeads * numSecspTrack * MAX_CYLINDERS))) {
chs[0] = 254;
chs[1] = chs[2] = 255;
done = 1;
......@@ -726,7 +726,7 @@ int BasicMBRData::FindOverlaps(void) {
if (numEE > 1)
cout << "\nCaution: More than one 0xEE MBR partition found. This can cause problems\n"
<< "in some OSes.\n";
if (!ProtectiveOnOne)
if (!ProtectiveOnOne && (numEE > 0))
cout << "\nWarning: 0xEE partition doesn't start on sector 1. This can cause "
<< "problems\nin some OSes.\n";
......@@ -1223,7 +1223,7 @@ void BasicMBRData::MaximizePrimaries() {
// Remove primary partitions in excess of 4, starting with the later ones,
// in terms of the array location....
void BasicMBRData::TrimPrimaries(void) {
int numToDelete, i = MAX_MBR_PARTS;
int numToDelete, i = MAX_MBR_PARTS - 1;
numToDelete = NumPrimaries() - 4;
while ((numToDelete > 0) && (i >= 0)) {
......
.\" Copyright 2011-2013 Roderick W. Smith (rodsmith@rodsbooks.com)
.\" May be distributed under the GNU General Public License
.TH "CGDISK" "8" "0.8.8" "Roderick W. Smith" "GPT fdisk Manual"
.TH "CGDISK" "8" "0.8.10" "Roderick W. Smith" "GPT fdisk Manual"
.SH "NAME"
cgdisk \- Curses-based GUID partition table (GPT) manipulator
.SH "SYNOPSIS"
......@@ -276,7 +276,7 @@ Write data. Use this command to save your changes.
.SH "BUGS"
As of October 2013 (version 0.8.8), \fBcgdisk\fR should be considered
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:
......
......@@ -75,4 +75,5 @@ int main(int argc, char *argv[]) {
} else {
Report("Could not load partitions from '" + device + "'! Aborting!");
} // if/else
return 0;
} // main
......@@ -3,7 +3,7 @@ Content-type: text/html
<HTML><HEAD><TITLE>Manpage of CGDISK</TITLE>
</HEAD><BODY>
<H1>CGDISK</H1>
Section: GPT fdisk Manual (8)<BR>Updated: 0.8.8<BR><A HREF="#index">Index</A>
Section: GPT fdisk Manual (8)<BR>Updated: 0.8.10<BR><A HREF="#index">Index</A>
<A HREF="http://localhost/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
......@@ -330,7 +330,7 @@ Write data. Use this command to save your changes.
<H2>BUGS</H2>
<P>
As of October 2013 (version 0.8.8), <B>cgdisk</B> should be considered
As of March 2014 (version 0.8.10), <B>cgdisk</B> should be considered
beta software. Although the underlying partition manipulation code is much
older, the <B>cgdisk</B> ncurses user interface is brand new with GPT fdisk
version 0.8.0. Known bugs and limitations include:
......@@ -480,6 +480,6 @@ available from Rod Smith.
This document was created by
<A HREF="http://localhost/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 16:05:45 GMT, October 14, 2013
Time: 17:57:37 GMT, March 02, 2014
</BODY>
</HTML>
Summary: GPT partitioning and MBR repair software
Name: gptfdisk
Version: 0.8.8
Version: 0.8.10
Release: 1%{?dist}
License: GPLv2
URL: http://www.rodsbooks.com/gdisk
Group: Applications/System
Source: http://www.rodsbooks.com/gdisk/gptfdisk-0.8.8.tar.gz
Source: http://www.rodsbooks.com/gdisk/gptfdisk-0.8.10.tar.gz
BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
%description
......@@ -80,5 +81,5 @@ provides a few additional partition manipulation features.
%changelog
* Mon Oct 14 2013 R Smith <rodsmith@rodsbooks.com> - 0.8.8
- Created spec file for 0.8.8 release
* Sun Mar 2 2014 R Smith <rodsmith@rodsbooks.com> - 0.8.10
- Created spec file for 0.8.10 release
.\" Copyright 2011-2013 Roderick W. Smith (rodsmith@rodsbooks.com)
.\" May be distributed under the GNU General Public License
.TH "FIXPARTS" "8" "0.8.8" "Roderick W. Smith" "FixParts Manual"
.TH "FIXPARTS" "8" "0.8.10" "Roderick W. Smith" "FixParts Manual"
.SH "NAME"
fixparts \- MBR partition table repair utility
.SH "SYNOPSIS"
......@@ -202,7 +202,7 @@ see a summary of available options.
.PP
.SH "BUGS"
As of October 2013 (version 0.8.8), \fBfixparts\fR
As of March 2014 (version 0.8.10), \fBfixparts\fR
should be considered beta software. Known bugs and limitations include:
.TP
......
......@@ -3,7 +3,7 @@ Content-type: text/html
<HTML><HEAD><TITLE>Manpage of FIXPARTS</TITLE>
</HEAD><BODY>
<H1>FIXPARTS</H1>
Section: FixParts Manual (8)<BR>Updated: 0.8.8<BR><A HREF="#index">Index</A>
Section: FixParts Manual (8)<BR>Updated: 0.8.10<BR><A HREF="#index">Index</A>
<A HREF="http://localhost/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
......@@ -245,7 +245,7 @@ see a summary of available options.
<A NAME="lbAF">&nbsp;</A>
<H2>BUGS</H2>
As of October 2013 (version 0.8.8), <B>fixparts</B>
As of March 2014 (version 0.8.10), <B>fixparts</B>
should be considered beta software. Known bugs and limitations include:
<P>
<DL COMPACT>
......@@ -357,6 +357,6 @@ available from Rod Smith.
This document was created by
<A HREF="http://localhost/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 16:05:45 GMT, October 14, 2013
Time: 17:57:37 GMT, March 02, 2014
</BODY>
</HTML>
.\" Copyright 2011-2013 Roderick W. Smith (rodsmith@rodsbooks.com)
.\" May be distributed under the GNU General Public License
.TH "GDISK" "8" "0.8.8" "Roderick W. Smith" "GPT fdisk Manual"
.TH "GDISK" "8" "0.8.10" "Roderick W. Smith" "GPT fdisk Manual"
.SH "NAME"
gdisk \- Interactive GUID partition table (GPT) manipulator
.SH "SYNOPSIS"
......@@ -335,7 +335,7 @@ OSes, or those that can't boot from a GPT disk, to access up to three of
the partitions on the disk by creating MBR entries for them. Note that
these hybrid MBR entries can easily go out of sync with the GPT entries,
particularly when hybrid\-unaware GPT utilities are used to edit the disk.
Thus, you may need to recreate the hybrid MBR if you use such tools. Unlike
Thus, you may need to re\-create the hybrid MBR if you use such tools. Unlike
the 'g' option, this option does not support converting any partitions into
MBR logical partitions.
......@@ -561,7 +561,7 @@ entering data. When only one option is possible, \fBgdisk\fR
usually bypasses the prompt entirely.
.SH "BUGS"
As of October 2013 (version 0.8.8), \fBgdisk\fR
As of March 2014 (version 0.8.10), \fBgdisk\fR
should be considered beta software. Known bugs and limitations include:
.TP
......
......@@ -58,4 +58,5 @@ int main(int argc, char* argv[]) {
cerr << "Usage: " << argv[0] << " [-l] device_file\n";
break;
} // switch
} // main
\ No newline at end of file
return 1 ;
} // main
......@@ -3,7 +3,7 @@ Content-type: text/html
<HTML><HEAD><TITLE>Manpage of GDISK</TITLE>
</HEAD><BODY>
<H1>GDISK</H1>
Section: GPT fdisk Manual (8)<BR>Updated: 0.8.8<BR><A HREF="#index">Index</A>
Section: GPT fdisk Manual (8)<BR>Updated: 0.8.10<BR><A HREF="#index">Index</A>
<A HREF="http://localhost/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
......@@ -391,7 +391,7 @@ OSes, or those that can't boot from a GPT disk, to access up to three of
the partitions on the disk by creating MBR entries for them. Note that
these hybrid MBR entries can easily go out of sync with the GPT entries,
particularly when hybrid-unaware GPT utilities are used to edit the disk.
Thus, you may need to recreate the hybrid MBR if you use such tools. Unlike
Thus, you may need to re-create the hybrid MBR if you use such tools. Unlike
the 'g' option, this option does not support converting any partitions into
MBR logical partitions.
<P>
......@@ -656,7 +656,7 @@ usually bypasses the prompt entirely.
<A NAME="lbAF">&nbsp;</A>
<H2>BUGS</H2>
As of October 2013 (version 0.8.8), <B>gdisk</B>
As of March 2014 (version 0.8.10), <B>gdisk</B>
should be considered beta software. Known bugs and limitations include:
<P>
<DL COMPACT>
......@@ -816,6 +816,6 @@ available from Rod Smith.
This document was created by
<A HREF="http://localhost/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 16:05:45 GMT, October 14, 2013
Time: 17:57:37 GMT, March 02, 2014
</BODY>
</HTML>
......@@ -291,6 +291,12 @@ int GPTData::Verify(void) {
// Verify that partitions don't run into GPT data areas....
problems += CheckGPTSize();
if (!protectiveMBR.DoTheyFit()) {
cout << "\nPartition(s) in the protective MBR are too big for the disk! Creating a\n"
<< "fresh protective or hybrid MBR is recommended.\n";
problems++;
}
// Check that partitions are aligned on proper boundaries (for WD Advanced
// Format and similar disks)....
for (i = 0; i < numParts; i++) {
......@@ -681,6 +687,15 @@ void GPTData::PartitionScan(void) {
// Load the GPT data, whether or not it's valid
ForceLoadGPTData();
// Some tools create a 0xEE partition that's too big. If this is detected,
// normalize it....
if ((state == gpt_valid) && !protectiveMBR.DoTheyFit() && (protectiveMBR.GetValidity() == gpt)) {
if (!beQuiet) {
cerr << "\aThe protective MBR's 0xEE partition is oversized! Auto-repairing.\n\n";
} // if
protectiveMBR.MakeProtectiveMBR();
} // if
if (!beQuiet) {
cout << "Partition table scan:\n";
protectiveMBR.ShowState();
......@@ -1056,6 +1071,12 @@ int GPTData::SaveGPTData(int quiet) {
cerr << "Aborting write operation!\n";
} // if
// Check that protective MBR fits, and warn if it doesn't....
if (!protectiveMBR.DoTheyFit()) {
cerr << "\nPartition(s) in the protective MBR are too big for the disk! Creating a\n"
<< "fresh protective or hybrid MBR is recommended.\n";
}
// Check for mismatched MBR and GPT data, but let it pass if found
// (function displays warning message)
FindHybridMismatches();
......@@ -1293,6 +1314,7 @@ int GPTData::DestroyGPT(void) {
uint8_t* emptyTable;
memset(blankSector, 0, sizeof(blankSector));
ClearGPTData();
if (myDisk.OpenForWrite()) {
if (!myDisk.Seek(mainHeader.currentLBA))
......@@ -2417,7 +2439,7 @@ int SizesOK(void) {
allOK = 0;
} // if
if (sizeof(PartType) != 16) {
cerr << "PartType is " << sizeof(GUIDData) << " bytes, should be 16 bytes; aborting!\n";
cerr << "PartType is " << sizeof(PartType) << " bytes, should be 16 bytes; aborting!\n";
allOK = 0;
} // if
return (allOK);
......
/*
Implementation of GPTData class derivative with popt-based command
line processing
Copyright (C) 2010-2013 Roderick W. Smith
Copyright (C) 2010-2014 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
......@@ -63,7 +63,7 @@ void GPTDataCL::LoadBackupFile(string backupFile, int &saveData, int &neverSaveD
int GPTDataCL::DoOptions(int argc, char* argv[]) {
GPTData secondDevice;
int opt, numOptions = 0, saveData = 0, neverSaveData = 0;
int partNum = 0, saveNonGPT = 1, retval = 0, pretend = 0;
int partNum = 0, newPartNum = -1, saveNonGPT = 1, retval = 0, pretend = 0;
uint64_t low, high, startSector, endSector, sSize;
uint64_t temp; // temporary variable; free to use in any case
char *device;
......@@ -122,7 +122,7 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
// Do one loop through the options to find the device filename and deal
// with options that don't require a device filename, to flag destructive
// (o, z, or Z) options, and to flag presence of an
// (o, z, or Z) options, and to flag presence of a --pretend/-P option
while ((opt = poptGetNextOpt(poptCon)) > 0) {
switch (opt) {
case 'A':
......@@ -161,6 +161,8 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
case 'A': {
if (cmd != "list") {
partNum = (int) GetInt(attributeOperation, 1) - 1;
if (partNum < 0)
partNum = newPartNum;
if ((partNum >= 0) && (partNum < (int) GetNumParts())) {
switch (ManageAttributes(partNum, GetString(attributeOperation, 2),
GetString(attributeOperation, 3))) {
......@@ -191,9 +193,14 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
free(backupFile);
break;
case 'c':
cout << "Setting name!\n";
JustLooking(0);
partNum = (int) GetInt(partName, 1) - 1;
if (partNum < 0)
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;
......@@ -276,19 +283,19 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
break;
case 'n':
JustLooking(0);
partNum = (int) GetInt(newPartInfo, 1) - 1;
if (partNum < 0)
partNum = FindFirstFreePart();
newPartNum = (int) GetInt(newPartInfo, 1) - 1;
if (newPartNum < 0)
newPartNum = FindFirstFreePart();
low = FindFirstInLargest();
Align(&low);
high = FindLastInFree(low);
startSector = IeeeToInt(GetString(newPartInfo, 2), sSize, low, high, low);
endSector = IeeeToInt(GetString(newPartInfo, 3), sSize, startSector, high, high);
if (CreatePartition(partNum, startSector, endSector)) {
if (CreatePartition(newPartNum, startSector, endSector)) {
saveData = 1;
} else {
cerr << "Could not create partition " << partNum + 1 << " from "
<< startSector << " to " << endSector << "\n";
cerr << "Could not create partition " << newPartNum + 1 << " from "
<< startSector << " to " << endSector << "\n";
neverSaveData = 1;
} // if/else
free(newPartInfo);
......@@ -351,6 +358,8 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
case 't':
JustLooking(0);
partNum = (int) GetInt(typeCode, 1) - 1;
if (partNum < 0)
partNum = newPartNum;
if ((partNum >= 0) && (partNum < (int) GetNumParts())) {
typeHelper = GetString(typeCode, 2);
if ((typeHelper != (GUIDData) "00000000-0000-0000-0000-000000000000") &&
......@@ -373,6 +382,8 @@ int GPTDataCL::DoOptions(int argc, char* argv[]) {
JustLooking(0);
saveData = 1;
partNum = (int) GetInt(partGUID, 1) - 1;
if (partNum < 0)
partNum = newPartNum;
if ((partNum >= 0) && (partNum < (int) GetNumParts())) {
SetPartitionGUID(partNum, GetString(partGUID, 2).c_str());
}
......@@ -467,14 +478,14 @@ int GPTDataCL::BuildMBR(char* argument, int isHybrid) {
int numParts, allOK = 1, i, origPartNum;
MBRPart newPart;
BasicMBRData newMBR;
if (argument != NULL) {
numParts = CountColons(argument) + 1;
if (numParts <= (4 - isHybrid)) {
newMBR.SetDisk(GetDisk());
for (i = 0; i < numParts; i++) {
origPartNum = GetInt(argument, i + 1) - 1;
if (IsUsedPartNum(origPartNum)) {
if (IsUsedPartNum(origPartNum) && (partitions[origPartNum].IsSizedForMBR() == MBR_SIZED_GOOD)) {
newPart.SetInclusion(PRIMARY);
newPart.SetLocation(operator[](origPartNum).GetFirstLBA(),
operator[](origPartNum).GetLengthLBA());
......@@ -482,7 +493,7 @@ int GPTDataCL::BuildMBR(char* argument, int isHybrid) {
newPart.SetType((uint8_t)(operator[](origPartNum).GetHexType() / 0x0100));
newMBR.AddPart(i + isHybrid, newPart);
} else {
cerr << "Partition " << origPartNum << " does not exist! Aborting operation!\n";
cerr << "Original partition " << origPartNum + 1 << " does not exist or is too big! Aborting operation!\n";
allOK = 0;
} // if/else
} // for
......@@ -493,7 +504,8 @@ int GPTDataCL::BuildMBR(char* argument, int isHybrid) {
newPart.SetType(0xEE);
newMBR.AddPart(0, newPart);
} // if
SetProtectiveMBR(newMBR);
if (allOK)
SetProtectiveMBR(newMBR);
} else allOK = 0;
} else allOK = 0;
if (!allOK)
......
......@@ -39,6 +39,7 @@ GPTDataCurses::GPTDataCurses(void) {
if (numInstances > 0) {
refresh();
} else {
setlocale( LC_ALL , "" );
initscr();
cbreak();
noecho();
......@@ -318,7 +319,7 @@ void GPTDataCurses::DeletePartition(int partNum) {
void GPTDataCurses::ShowInfo(int partNum) {
uint64_t size;
#ifdef USE_UTF16
char temp[NAME_SIZE / 2 + 1];
char temp[NAME_SIZE + 1];
#endif
clear();
......@@ -335,7 +336,7 @@ void GPTDataCurses::ShowInfo(int partNum) {
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
partitions[partNum].GetDescription().extract(0, NAME_SIZE / 2, temp, NAME_SIZE / 2);
partitions[partNum].GetDescription().extract(0, NAME_SIZE , temp, NAME_SIZE );
printw("Partition name: '%s'\n", temp);
#else
printw("Partition name: '%s'\n", partitions[partNum].GetDescription().c_str());
......@@ -345,21 +346,21 @@ void GPTDataCurses::ShowInfo(int partNum) {
// Prompt for and change a partition's name....
void GPTDataCurses::ChangeName(int partNum) {
char temp[NAME_SIZE / 2 + 1];
char temp[NAME_SIZE + 1];
if (ValidPartNum(partNum)) {
move(LINES - 4, 0);
clrtobot();
move(LINES - 4, 0);
#ifdef USE_UTF16
partitions[partNum].GetDescription().extract(0, NAME_SIZE / 2, temp, NAME_SIZE / 2);
partitions[partNum].GetDescription().extract(0, NAME_SIZE , temp, NAME_SIZE );
printw("Current partition name is '%s'\n", temp);
#else
printw("Current partition name is '%s'\n", partitions[partNum].GetDescription().c_str());
#endif
printw("Enter new partition name, or <Enter> to use the current name:\n");
echo();
getnstr(temp, NAME_SIZE / 2);
getnstr(temp, NAME_SIZE );
partitions[partNum].SetName((string) temp);
noecho();
} // if
......
......@@ -35,7 +35,7 @@ GPTPart::GPTPart(void) {
firstLBA = 0;
lastLBA = 0;
attributes = 0;
memset(name, 0, NAME_SIZE);
memset(name, 0, NAME_SIZE * sizeof(name[0]) );
} // Default constructor
GPTPart::~GPTPart(void) {
......@@ -52,11 +52,13 @@ string GPTPart::GetTypeName(void) {
return partitionType.TypeName();
} // GPTPart::GetNameType()
#ifdef USE_UTF16
// Return a Unicode description of the partition type (e.g., "Linux/Windows
// data" or "Linux swap").
UnicodeString GPTPart::GetUTypeName(void) {
return partitionType.UTypeName();
} // GPTPart::GetNameType()
#endif
// Compute and return the partition's length (or 0 if the end is incorrectly
// set before the beginning).
......@@ -74,18 +76,61 @@ UnicodeString GPTPart::GetDescription(void) {
return (UChar*) name;
} // GPTPart::GetDescription()
#else
// Return partition's name field, converted to a C++ ASCII string
// Return partition's name field, converted to a C++ UTF-8 string
string GPTPart::GetDescription(void) {
string theName;
int i = 0;
theName = "";
while ((i < NAME_SIZE) && (name[i] != '\0')) {
theName += name[i];
i+=2;
} // while
return theName;
} // GPTPart::GetDescription() (Windows version)
// convert name to utf32 then to utf8
string utf8 ;
size_t pos = 0 ;
while ( ( pos < NAME_SIZE ) && ( name[ pos ] != 0 ) ) {
uint16_t cp = name[ pos ++ ] ;
if ( ! IsLittleEndian() ) ReverseBytes( & cp , 2 ) ;
// first to utf32
uint32_t uni ;
if ( cp < 0xd800 || cp > 0xdfff ) {
uni = cp ;
} // if
else if ( cp < 0xdc00 ) {
// lead surrogate
uni = ( (uint32_t)( cp & 0x3ff ) ) << 10 ;
if ( pos >= NAME_SIZE ) {
// missing trail surrogate, name[] is invalid
break ;
} // if
cp = name[ pos ++ ] ;
if ( cp < 0xdc00 || cp > 0xdfff ) {
// invalid trail surrogate, name[] is invalid
break ;
} // if
// trail surrogate
uni |= cp & 0x3ff ;
uni += 0x10000 ;
} // if
else {
// unexpected trail surrogate, name[] is invalid
break ;
} // if
// then to utf8
if ( uni < 0x80 ) {
utf8 += (char) uni ;
} // if
else if ( uni < 0x800 ) {
utf8 += (char) ( 0xc0 | ( uni >> 6 ) ) ;
utf8 += (char) ( 0x80 | ( uni & 0x3f ) ) ;
} // if
else if ( uni < 0x10000 ) {
utf8 += (char) ( 0xe0 | ( uni >> 12 ) ) ;
utf8 += (char) ( 0x80 | ( ( uni >> 6 ) &