Version 0.6.0 release; adds support for >512-byte sectors, sgdisk
program.
This commit is contained in:
4
Makefile
4
Makefile
@@ -1,7 +1,7 @@
|
||||
CC=gcc
|
||||
CXX=g++
|
||||
CFLAGS=-O2 -D_FILE_OFFSET_BITS=64 -g
|
||||
CXXFLAGS=-O2 -Wuninitialized -Wreturn-type -D_FILE_OFFSET_BITS=64 -I/opt/local/include -g
|
||||
CXXFLAGS=-O2 -Wuninitialized -Wreturn-type -D_FILE_OFFSET_BITS=64 -I /usr/local/include -I/opt/local/include -g
|
||||
LIB_NAMES=crc32 support gptpart mbr gpt bsd parttypes attributes
|
||||
LIB_SRCS=$(NAMES:=.cc)
|
||||
LIB_OBJS=$(LIB_NAMES:=.o)
|
||||
@@ -17,7 +17,7 @@ gdisk: $(LIB_OBJS) gdisk.o
|
||||
$(CXX) $(LIB_OBJS) gdisk.o -o gdisk
|
||||
|
||||
sgdisk: $(LIB_OBJS) sgdisk.o
|
||||
$(CXX) $(LIB_OBJS) sgdisk.o -L/opt/local/lib -lpopt -o sgdisk
|
||||
$(CXX) $(LIB_OBJS) sgdisk.o -L/opt/local/lib -L/usr/local/lib -lpopt -o sgdisk
|
||||
|
||||
wipegpt: $(LIB_OBJS) wipegpt.o
|
||||
$(CXX) $(LIB_OBJS) wipegpt.o -o wipegpt
|
||||
|
||||
36
README
36
README
@@ -7,8 +7,8 @@ Introduction
|
||||
This software is intended as a (somewhat) fdisk-workalike program for
|
||||
GPT-partitioned disks. Although libparted and programs that use it (GNU
|
||||
Parted, gparted, etc.) provide the ability to handle GPT disks, they have
|
||||
certain limitations that gdisk overcomes. Specific advantages of gdisk
|
||||
include:
|
||||
certain limitations that gdisk overcomes. Specific advantages of gdisk and
|
||||
sgdisk include:
|
||||
|
||||
* The ability to convert MBR-partitioned disks in-place to GPT format,
|
||||
without losing data
|
||||
@@ -25,7 +25,7 @@ include:
|
||||
disk
|
||||
|
||||
* A user interface that's familiar to long-time users of Linux
|
||||
fdisk
|
||||
fdisk (gdisk only)
|
||||
|
||||
* The MBR boot loader code is left alone (GNU Parted tends to
|
||||
wipe it out with every change)
|
||||
@@ -33,25 +33,31 @@ include:
|
||||
* The ability to create a hybrid MBR, which permits GPT-unaware
|
||||
OSes to access up to three GPT partitions on the disk
|
||||
|
||||
Of course, gdisk isn't without its limitations. Most notably, it lacks the
|
||||
filesystem awareness and filesystem-related features of GNU Parted. You
|
||||
Of course, GPT fdisk isn't without its limitations. Most notably, it lacks
|
||||
the filesystem awareness and filesystem-related features of GNU Parted. You
|
||||
can't resize a partition's filesystem or create a partition with a
|
||||
filesystem already in place with gdisk, for instance. There's no GUI
|
||||
version of gdisk.
|
||||
|
||||
The GPT fdisk package provides two program files: the interactive text-mode
|
||||
gdisk and the command-line-driven sgdisk. The former is intended for use in
|
||||
manually partitioning disks or changing partitioning details; the latter is
|
||||
intended for use in scripts to help automate tasks such as disk cloning or
|
||||
preparing multiple disks for Linux installation.
|
||||
|
||||
Installing
|
||||
----------
|
||||
|
||||
To compile gdisk, you must have appropriate development tools installed,
|
||||
most notably the GNU Compiler Collection (GCC) and its g++ compiler for
|
||||
C++. The sgdisk program also requires the popt library and its development
|
||||
files (headers). Most Linux distributions install popt by default, but you
|
||||
may need to install a package called popt-dev, popt-devel, or something
|
||||
similar to obtain the development libraries. Mac OS users can find a version
|
||||
of popt for Mac OS from http://popt.darwinports.com; however, you'll first
|
||||
need to install DarwinPorts (instructions exist on the preceding page).
|
||||
Alternatively, you can compile gdisk alone, without sgdisk; gdisk doesn't
|
||||
require popt.
|
||||
To compile GPT fdisk, you must have appropriate development tools
|
||||
installed, most notably the GNU Compiler Collection (GCC) and its g++
|
||||
compiler for C++. The sgdisk program also requires the popt library and its
|
||||
development files (headers). Most Linux distributions install popt by
|
||||
default, but you may need to install a package called popt-dev, popt-devel,
|
||||
or something similar to obtain the header files. Mac OS users can find a
|
||||
version of popt for Mac OS from http://popt.darwinports.com; however,
|
||||
you'll first need to install DarwinPorts (instructions exist on the
|
||||
preceding page). Alternatively, you can compile gdisk 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
|
||||
|
||||
2
gdisk.cc
2
gdisk.cc
@@ -28,7 +28,7 @@ int main(int argc, char* argv[]) {
|
||||
int doMore = 1;
|
||||
char* device = NULL;
|
||||
|
||||
printf("GPT fdisk (gdisk) version 0.5.4-pre1\n\n");
|
||||
printf("GPT fdisk (gdisk) version %s\n\n", GPTFDISK_VERSION);
|
||||
|
||||
if (argc == 2) { // basic usage
|
||||
if (SizesOK()) {
|
||||
|
||||
21
gpt.cc
21
gpt.cc
@@ -74,7 +74,8 @@ GPTData::GPTData(char* filename) {
|
||||
whichWasUsed = use_new;
|
||||
srand((unsigned int) time(NULL));
|
||||
mainHeader.numParts = 0;
|
||||
LoadPartitions(filename);
|
||||
if (!LoadPartitions(filename))
|
||||
exit(2);
|
||||
} // GPTData(char* filename) constructor
|
||||
|
||||
// Destructor
|
||||
@@ -573,6 +574,10 @@ int GPTData::LoadPartitions(char* deviceFilename) {
|
||||
ClearGPTData();
|
||||
protectiveMBR.MakeProtectiveMBR();
|
||||
break;
|
||||
case use_abort:
|
||||
allOK = 0;
|
||||
printf("Aborting because of invalid partition data!\n");
|
||||
break;
|
||||
} // switch
|
||||
|
||||
// Now find the first and last sectors used by partitions...
|
||||
@@ -586,8 +591,8 @@ int GPTData::LoadPartitions(char* deviceFilename) {
|
||||
if (partitions[i].GetLastLBA() > lastBlock)
|
||||
lastBlock = partitions[i].GetLastLBA();
|
||||
} // for
|
||||
} // if
|
||||
CheckGPTSize();
|
||||
} // if
|
||||
} else {
|
||||
allOK = 0;
|
||||
fprintf(stderr, "Problem opening %s for reading! Error is %d\n",
|
||||
@@ -1427,12 +1432,14 @@ WhichToUse GPTData::UseWhichPartitions(void) {
|
||||
} // if
|
||||
|
||||
if ((state == gpt_valid) && (mbrState == gpt)) {
|
||||
printf("Found valid GPT with protective MBR; using GPT.\n");
|
||||
which = use_gpt;
|
||||
if (!beQuiet)
|
||||
printf("Found valid GPT with protective MBR; using GPT.\n");
|
||||
} // if
|
||||
if ((state == gpt_valid) && (mbrState == hybrid)) {
|
||||
printf("Found valid GPT with hybrid MBR; using GPT.\n");
|
||||
which = use_gpt;
|
||||
if (!beQuiet)
|
||||
printf("Found valid GPT with hybrid MBR; using GPT.\n");
|
||||
} // if
|
||||
if ((state == gpt_valid) && (mbrState == invalid)) {
|
||||
printf("\aFound valid GPT with corrupt MBR; using GPT and will create new\nprotective MBR on save.\n");
|
||||
@@ -1440,6 +1447,7 @@ WhichToUse GPTData::UseWhichPartitions(void) {
|
||||
protectiveMBR.MakeProtectiveMBR();
|
||||
} // if
|
||||
if ((state == gpt_valid) && (mbrState == mbr)) {
|
||||
if (!beQuiet) {
|
||||
printf("Found valid MBR and GPT. Which do you want to use?\n");
|
||||
answer = GetNumber(1, 3, 2, (char*) " 1 - MBR\n 2 - GPT\n 3 - Create blank GPT\n\nYour answer: ");
|
||||
if (answer == 1) {
|
||||
@@ -1449,11 +1457,15 @@ WhichToUse GPTData::UseWhichPartitions(void) {
|
||||
protectiveMBR.MakeProtectiveMBR();
|
||||
printf("Using GPT and creating fresh protective MBR.\n");
|
||||
} else which = use_new;
|
||||
} else which = use_abort;
|
||||
} // if
|
||||
|
||||
// Nasty decisions here -- GPT is present, but corrupt (bad CRCs or other
|
||||
// problems)
|
||||
if (state == gpt_corrupt) {
|
||||
if (beQuiet) {
|
||||
which = use_abort;
|
||||
} else {
|
||||
if ((mbrState == mbr) || (mbrState == hybrid)) {
|
||||
printf("Found valid MBR and corrupt GPT. Which do you want to use? (Using the\n"
|
||||
"GPT MAY permit recovery of GPT data.)\n");
|
||||
@@ -1478,6 +1490,7 @@ WhichToUse GPTData::UseWhichPartitions(void) {
|
||||
"****************************************************************************\n");
|
||||
which = use_gpt;
|
||||
} // if/else/else
|
||||
} // else (beQuiet)
|
||||
} // if (corrupt GPT)
|
||||
|
||||
if (which == use_new)
|
||||
|
||||
3
gpt.h
3
gpt.h
@@ -16,6 +16,7 @@
|
||||
#ifndef __GPTSTRUCTS
|
||||
#define __GPTSTRUCTS
|
||||
|
||||
#define GPTFDISK_VERSION "0.6.0"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -29,7 +30,7 @@ using namespace std;
|
||||
enum GPTValidity {gpt_valid, gpt_corrupt, gpt_invalid};
|
||||
|
||||
// Which set of partition data to use
|
||||
enum WhichToUse {use_gpt, use_mbr, use_bsd, use_new};
|
||||
enum WhichToUse {use_gpt, use_mbr, use_bsd, use_new, use_abort};
|
||||
|
||||
// Header (first 512 bytes) of GPT table
|
||||
#pragma pack(1)
|
||||
|
||||
8
sgdisk.8
8
sgdisk.8
@@ -206,9 +206,9 @@ sectors are available, this function returns the value 0.
|
||||
|
||||
.TP
|
||||
.B \-g, \-\-mbrtogpt
|
||||
Convert an MBR disk to a GPT disk. As a safety measure, use of this option
|
||||
is required on MBR or BSD disklabel disks if you intend to save your changes,
|
||||
in order to prevent accidentally damaging such disks.
|
||||
Convert an MBR or BSD disklabel disk to a GPT disk. As a safety measure, use of
|
||||
this option is required on MBR or BSD disklabel disks if you intend to save your
|
||||
changes, in order to prevent accidentally damaging such disks.
|
||||
|
||||
.TP
|
||||
.B \-i, \-\-info=partnum
|
||||
@@ -342,7 +342,7 @@ Normal program execution
|
||||
Too few arguments
|
||||
|
||||
.TP
|
||||
.B 4
|
||||
.B 2
|
||||
An error occurred while reading the partition table
|
||||
|
||||
.TP
|
||||
|
||||
Reference in New Issue
Block a user