Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=fwsetup-ng.git;a=commitdiff;h=b68e0c07f460aab9d47dd4345efc5523b5f6ab99

commit b68e0c07f460aab9d47dd4345efc5523b5f6ab99
Author: James Buren <[email protected]>
Date:   Sat Aug 18 20:06:41 2012 -0500

add DosPartitionTable class

diff --git a/DosPartitionTable.cc b/DosPartitionTable.cc
new file mode 100644
index 0000000..c1792a7
--- /dev/null
+++ b/DosPartitionTable.cc
@@ -0,0 +1,78 @@
+#include <blkid.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include "DosPartition.hh"
+#include "DosPartitionTable.hh"
+
+bool DosPartitionTable::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;
+  DosPartition 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)) != "dos")
+    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(partition));
+
+    part.setActive((blkid_partition_get_flags(partition) == 0x80) ? true : 
false);
+
+    table[i++] = part;
+  }
+
+  _label = label;
+
+  _table = table;
+
+  rv = true;
+
+bail:
+
+  if(fd != -1)
+    close(fd);
+
+  if(probe != 0)
+    blkid_free_probe(probe);
+
+  return rv;
+}
+
+bool DosPartitionTable::write(const string &path)
+{
+  return true;
+}
diff --git a/DosPartitionTable.hh b/DosPartitionTable.hh
new file mode 100644
index 0000000..3e76242
--- /dev/null
+++ b/DosPartitionTable.hh
@@ -0,0 +1,12 @@
+#pragma once
+
+#include "PartitionTable.hh"
+
+class DosPartitionTable : 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

Reply via email to