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

commit d117bcaae6a732330488e5286fa46c18220eff2c
Author: James Buren <r...@frugalware.org>
Date:   Sun Aug 26 15:45:47 2012 -0500

add initial newpartition code

diff --git a/Device.cc b/Device.cc
index 7c27d2d..a103f9c 100644
--- a/Device.cc
+++ b/Device.cc
@@ -225,4 +225,54 @@ void Device::newPartitionTable(const string &label)
_table = new DosPartitionTable();
}

+Partition *Device::newPartition(unsigned long long size)
+{
+  unsigned long long sectors = 0;
+  string label;
+  size_t last = 0;
+  Partition *part = 0;
+  Partition *lastpart = 0;
+
+  // Check for a sane state.
+  if(!_initialized || size == 0 || _table == 0)
+    return 0;
+
+  sectors = sectorsToSize(size);
+
+  label = _table->getLabelType();
+
+  last = _table->getTableSize();
+
+  // Initial checks for resource limits.
+  if(sectors > _sectors || (label == "dos" && (last+1) > 60) || (label == 
"gpt" && (last+1) > 128))
+    return 0;
+
+  part = _table->newPartition();
+
+  if(last == 0)
+  {
+    part->setNumber(1);
+
+    part->setStart(_alignment);
+
+    part->setEnd(_alignment + size - 1);
+
+    part->setSectors(size);
+  }
+  else
+  {
+    lastpart = _table->getPartition(last - 1);
+
+    part->setNumber(lastpart->getNumber() + 1);
+
+    part->setStart(lastpart->getEnd() + 1);
+
+    part->setEnd(lastpart->getEnd() + 1 + size);
+
+    part->setSectors(size);
+  }
+
+  return part;
+}
+
// -%- strip: yes; add-newline: yes; use-tabs: no; indent-width: 2; tab-width: 
2; -%-
diff --git a/Device.hh b/Device.hh
index 450daf8..7c477ec 100644
--- a/Device.hh
+++ b/Device.hh
@@ -19,6 +19,7 @@ public:
unsigned long long sectorsToSize(unsigned long long sectors) { return sectors * 
_sectorsize; }
string getLabelType() { return (_table != 0) ? _table->getLabelType() : 
"unknown"; }
void newPartitionTable(const string &label);
+  Partition *newPartition(unsigned long long size);

private:
string _path;
_______________________________________________
Frugalware-git mailing list
Frugalware-git@frugalware.org
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to