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

commit da79ee2f8268506dd5d8e22edf20ca20a24f5dbe
Author: James Buren <[email protected]>
Date:   Sun Aug 26 19:14:17 2012 -0500

add function for calculating usable sector count

diff --git a/Device.hh b/Device.hh
index d2c9b12..58604c7 100644
--- a/Device.hh
+++ b/Device.hh
@@ -16,13 +16,13 @@ public:
static vector <Device> probeAll();
bool read(const string &path);
bool write();
-  unsigned long long sizeToSectors(unsigned long long size) { return size / 
_sectorsize; }
-  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:
+  unsigned long long sizeToSectors(unsigned long long size) { return size / 
_sectorsize; }
+  unsigned long long sectorsToSize(unsigned long long sectors) { return 
sectors * _sectorsize; }
unsigned long long alignUp(unsigned long long sector)
{
if((sector % _alignment) == 0)
@@ -37,6 +37,25 @@ private:

return sector - (sector % _alignment);
}
+  unsigned long long getUsableSectors()
+  {
+    unsigned long long reserved = 0;
+
+    // Set the raw size reserved for partition table.
+    if(_table->getLabelType() == "dos")
+      reserved = 512;
+    else if(_table->getLabelType() == "gpt")
+      reserved = 512 + 16384;
+
+    // Now, round it up to the closest sector.
+    if((reserved % _sectorsize) != 0)
+      reserved += _sectorsize - (reserved % _sectorsize);
+
+    // Now, convert it to a sector count.
+    reserved = sizeToSectors(reserved);
+
+    return _sectors - reserved;
+  }
string _path;
unsigned long long _sectorsize;
unsigned long long _alignment;
_______________________________________________
Frugalware-git mailing list
[email protected]
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to