Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=fwsetup-ng.git;a=commitdiff;h=67bc61b7cdc3b93816b676e43c8580a54306cfcf
commit 67bc61b7cdc3b93816b676e43c8580a54306cfcf Author: James Buren <[email protected]> Date: Sat Aug 18 22:07:07 2012 -0500 add partition table for GPT diff --git a/GptPartitionTable.cc b/GptPartitionTable.cc new file mode 100644 index 0000000..818b597 --- /dev/null +++ b/GptPartitionTable.cc @@ -0,0 +1,86 @@ +#include <blkid.h> +#include <fcntl.h> +#include <unistd.h> +#include "GptPartition.hh" +#include "GptPartitionTable.hh" + +#define MAX_PARTITIONS 128 + +bool GptPartitionTable::read(const string &path) +{ + int fd = -1; + blkid_probe probe = 0; + blkid_partlist partlist = 0; + blkid_parttable parttable = 0; + string label; + vector <Partition> table; + int i = 0; + int j = 0; + blkid_partition partition = 0; + GptPartition part; + bool rv = false; + + if((fd = open(path.c_str(),O_RDONLY)) == -1) + goto bail; + + if((probe = blkid_new_probe()) == 0) + goto bail; + + if(blkid_probe_set_device(probe,fd,0,0) == -1) + goto bail; + + if((partlist = blkid_probe_get_partitions(probe)) == 0) + goto bail; + + if((parttable = blkid_partlist_get_table(partlist)) == 0) + goto bail; + + if((label = blkid_parttable_get_type(parttable)) != "gpt") + goto bail; + + j = blkid_partlist_numof_partitions(partlist); + + while(i < j && (partition = blkid_partlist_get_partition(partlist,i)) != 0) + { + part.setNumber(blkid_partition_get_partno(partition)); + + part.setStart(blkid_partition_get_start(partition)); + + part.setEnd(blkid_partition_get_start(partition) + blkid_partition_get_size(partition) - 1); + + part.setSectors(blkid_partition_get_size(partition)); + + part.setType(blkid_partition_get_type_string(partition)); + + part.setName(blkid_partition_get_name(partition)); + + part.setUUID(blkid_partition_get_uuid(partition)); + + part.setFlags(blkid_partition_get_flags(partition)); + + table.push_back(part); + + ++i; + } + + _label = label; + + _table = table; + + rv = true; + +bail: + + if(fd != -1) + close(fd); + + if(probe != 0) + blkid_free_probe(probe); + + return rv; +} + +bool GptPartitionTable::write(const string &path) +{ + return true; +} diff --git a/GptPartitionTable.hh b/GptPartitionTable.hh new file mode 100644 index 0000000..67d3bc8 --- /dev/null +++ b/GptPartitionTable.hh @@ -0,0 +1,12 @@ +#pragma once + +#include "PartitionTable.hh" + +class GptPartitionTable : public PartitionTable +{ + +public: + virtual bool read(const string &path); + virtual bool write(const string &path); + +}; \ No newline at end of file _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
