Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=fwsetup-ng.git;a=commitdiff;h=45b93fa73954fbabef223e023c64fc77f344cb32
commit 45b93fa73954fbabef223e023c64fc77f344cb32 Author: James Buren <[email protected]> Date: Sun Aug 26 15:20:51 2012 -0500 change device internals to cache only logical sector size and use alignment multiple for aligning partitions on physical boundaries. needed for 4K, 128K, etc alignment. also, fix a small glitch in newPartitionTable() diff --git a/Device.cc b/Device.cc index 172be28..7c27d2d 100644 --- a/Device.cc +++ b/Device.cc @@ -5,6 +5,7 @@ #include <unistd.h> #include <string.h> #include <linux/major.h> +#include "Utility.hh" #include "DosPartitionTable.hh" #include "GptPartitionTable.hh" #include "Device.hh" @@ -64,11 +65,9 @@ static inline bool isVirtioDisk(const struct stat &st) Device::Device() { - _lsectorsize = 0; + _sectorsize = 0; - _psectorsize = 0; - - _alignratio = 0; + _alignment = 0; _sectors = 0; @@ -121,9 +120,8 @@ bool Device::read(const string &path) int fd = -1; blkid_probe probe = 0; blkid_topology topology = 0; - unsigned long long lsectorsize = 0; - unsigned long long psectorsize = 0; - unsigned long long alignratio = 0; + unsigned long long sectorsize = 0; + unsigned long long alignment = 0; blkid_loff_t size = 0; unsigned long long sectors = 0; struct stat st; @@ -149,18 +147,16 @@ bool Device::read(const string &path) if((topology = blkid_probe_get_topology(probe)) == 0) goto bail; - lsectorsize = blkid_topology_get_logical_sector_size(topology); - - psectorsize = blkid_topology_get_physical_sector_size(topology); + sectorsize = blkid_topology_get_logical_sector_size(topology); - alignratio = psectorsize / lsectorsize; + alignment = MEBIBYTE / sectorsize; size = blkid_probe_get_size(probe); - sectors = size / lsectorsize; + sectors = size / sectorsize; // Now, perform some sanity checks on the topology data. - if(lsectorsize == 0 || psectorsize == 0 || (psectorsize % lsectorsize) != 0 || size <= 0 || (size % lsectorsize) != 0) + if(sectorsize == 0 || (MEBIBYTE % sectorsize) != 0 || size <= 0 || (size % sectorsize) != 0) goto bail; // Read the device's stats. @@ -193,11 +189,9 @@ bool Device::read(const string &path) _path = path; - _lsectorsize = lsectorsize; - - _psectorsize = psectorsize; + _sectorsize = sectorsize; - _alignratio = alignratio; + _alignment = alignment; _sectors = sectors; @@ -225,9 +219,9 @@ void Device::newPartitionTable(const string &label) delete _table; - if(_table == "dos") + if(label == "dos") _table = new DosPartitionTable(); - else if(_table == "gpt") + else if(label == "gpt") _table = new DosPartitionTable(); } diff --git a/Device.hh b/Device.hh index af88f15..450daf8 100644 --- a/Device.hh +++ b/Device.hh @@ -15,16 +15,15 @@ public: ~Device(); static vector <Device> probeAll(); bool read(const string &path); - unsigned long long sizeToSectors(unsigned long long size) { return size / _lsectorsize; } - unsigned long long sectorsToSize(unsigned long long sectors) { return sectors * _lsectorsize; } + 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); private: string _path; - unsigned long long _lsectorsize; - unsigned long long _psectorsize; - unsigned long long _alignratio; + unsigned long long _sectorsize; + unsigned long long _alignment; unsigned long long _sectors; bool _disk; PartitionTable *_table; _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
