Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=fwsetup-ng.git;a=commitdiff;h=bb7822c7df2d2d37025a4613e25764223b44ab8a
commit bb7822c7df2d2d37025a4613e25764223b44ab8a Author: James Buren <[email protected]> Date: Tue Aug 28 00:28:47 2012 -0500 add some size -> string functions to Device class diff --git a/Device.hh b/Device.hh index d12d205..903dff8 100644 --- a/Device.hh +++ b/Device.hh @@ -2,6 +2,7 @@ #include <string> #include <vector> +#include "Utility.hh" #include "PartitionTable.hh" using std::string; @@ -18,11 +19,39 @@ public: bool read(const string &path); bool write(); string getPath() { return _path; } - unsigned long long getSize() { return sectorsToSize(_sectors); } + string getSizeString() { return sizeToString(sectorsToSize(_sectors)); } + string getUnusedSizeString() + { + unsigned long long usable_sectors = 0; + size_t last = 0; + unsigned long long size = 0; + Partition *lastpart = 0; + + if(_table == 0) + return "0BiB"; + + usable_sectors = getUsableSectors(); + + last = _table->getTableSize(); + + if(last == 0) + { + size = sectorsToSize(usable_sectors); + } + else + { + lastpart = getPartition(last - 1); + + size = sectorsToSize(usable_sectors - lastpart->getSectors()); + } + + return sizeToString(size); + } bool isDisk() { return _disk; } string getLabelType() { return (_table != 0) ? _table->getLabelType() : "unknown"; } size_t getTableSize() { return (_table != 0) ? _table->getTableSize() : 0; } Partition *getPartition(size_t n) { return (_table != 0) ? _table->getPartition(n) : 0; } + string sectorsToSizeString(unsigned long long sectors) { return sizeToString(sectorsToSize(sectors)); } void newPartitionTable(const string &label); Partition *newPartition(unsigned long long size); Partition *newExtendedPartition(); _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
