Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=fwsetup-ng.git;a=commitdiff;h=5239ec8e2eeab744c51ea9c5b14276e570e1e8fa
commit 5239ec8e2eeab744c51ea9c5b14276e570e1e8fa Author: James Buren <[email protected]> Date: Tue Aug 21 15:29:00 2012 -0500 add write to gpt partition table diff --git a/GptPartitionTable.cc b/GptPartitionTable.cc index 0cfaccb..34fb633 100644 --- a/GptPartitionTable.cc +++ b/GptPartitionTable.cc @@ -4,11 +4,16 @@ #include <stdio.h> #include <string.h> #include <limits.h> +#include <sstream> #include "GptPartition.hh" #include "GptPartitionTable.hh" #define MAX_PARTITIONS 128 +using std::stringstream; +using std::dec; +using std::hex; + static string get_gpt_label_uuid(const string &path) { string cmd; @@ -139,6 +144,36 @@ bail: bool GptPartitionTable::write(const string &path) { + stringstream cmd; + size_t i = 0; + GptPartition *part = 0; + + if(_table.empty()) + return false; + + cmd << "sgdisk --clear --disk-guid='" << (_uuid.empty() ? "R" : _uuid.c_str()) << "'"; + + while(i < _table.size()) + { + part = (GptPartition *) _table.at(i); + + cmd << dec; + + cmd << " --new=" << part->getNumber() << ":" << part->getStart() << ":" << part->getEnd(); + + cmd << " --change-name=" << part->getNumber() << ":'" << part->getName() << "'"; + + cmd << " --partition-guid=" << part->getNumber() << ":'" << (part->getUUID().empty() ? "R" : part->getUUID().c_str()) << "'"; + + cmd << " --typecode=" << part->getNumber() << ":'" << part->getType() << "'"; + + cmd << " --attributes=" << part->getNumber() << ":=:0x" << hex << part->getFlags(); + + ++i; + } + + cmd << " " << path; + return true; } _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
