Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=fwsetup-ng.git;a=commitdiff;h=849cbb34ed3abb6421800e9be8fa3fce230ea6a9
commit 849cbb34ed3abb6421800e9be8fa3fce230ea6a9 Author: James Buren <[email protected]> Date: Sat Aug 18 22:25:47 2012 -0500 also retrieve GPT label UUID diff --git a/GptPartitionTable.cc b/GptPartitionTable.cc index 818b597..fd10ef0 100644 --- a/GptPartitionTable.cc +++ b/GptPartitionTable.cc @@ -1,11 +1,43 @@ #include <blkid.h> #include <fcntl.h> #include <unistd.h> +#include <stdio.h> +#include <string.h> +#include <limits.h> #include "GptPartition.hh" #include "GptPartitionTable.hh" #define MAX_PARTITIONS 128 +static string get_gpt_label_uuid(const string &path) +{ + string cmd; + FILE *in = 0; + char line[LINE_MAX] = {0}; + char *p = 0; + + cmd = "sgdisk -p " + path + " 2> /dev/null | sed -rn 's|^Disk identifier \\(GUID\\): ([0-9a-zA-Z-]+)$|\\1|p' 2> /dev/null"; + + if((in = popen(cmd.c_str(),"r")) == 0) + return ""; + + if(fgets(line,sizeof(line),in) == 0) + { + pclose(in); + return ""; + } + + if(pclose(in) == -1) + return ""; + + p = strchr(line,'\n'); + + if(p != 0) + *p = 0; + + return line; +} + bool GptPartitionTable::read(const string &path) { int fd = -1; @@ -13,13 +45,14 @@ bool GptPartitionTable::read(const string &path) blkid_partlist partlist = 0; blkid_parttable parttable = 0; string label; + string uuid; 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; @@ -38,33 +71,38 @@ bool GptPartitionTable::read(const string &path) if((label = blkid_parttable_get_type(parttable)) != "gpt") goto bail; + if((uuid = get_gpt_label_uuid(path)) == "") + 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; + _uuid = uuid; + _table = table; rv = true; @@ -73,7 +111,7 @@ bail: if(fd != -1) close(fd); - + if(probe != 0) blkid_free_probe(probe); @@ -84,3 +122,5 @@ bool GptPartitionTable::write(const string &path) { return true; } + +// -%- strip: yes; add-newline: yes; use-tabs: no; indent-width: 2; tab-width: 2; -%- diff --git a/GptPartitionTable.hh b/GptPartitionTable.hh index 67d3bc8..c54815e 100644 --- a/GptPartitionTable.hh +++ b/GptPartitionTable.hh @@ -9,4 +9,7 @@ public: virtual bool read(const string &path); virtual bool write(const string &path); +protected: + string _uuid; + }; \ No newline at end of file _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
