make sure not to return false when isSectorBase() is called more than once.

make the heuristic to determine if a partition table is sector aligned a little
less dumb.

svn path=/trunk/extragear/sysadmin/partitionmanager/; revision=1140829
This commit is contained in:
Volker Lanz 2010-06-21 15:49:53 +00:00
parent a509ad8ee4
commit fe6f80379a
4 changed files with 13 additions and 9 deletions

View File

@ -435,7 +435,7 @@ bool PartitionTable::tableTypeIsReadOnly(TableType l)
if its Partitions begin at sectors evenly divisable by Config::sectorAlignment().
@return true if is sector aligned, otherwise false
*/
bool PartitionTable::isSectorBased() const
bool PartitionTable::isSectorBased(const Device& d) const
{
if (type() == PartitionTable::msdos)
{
@ -443,17 +443,21 @@ bool PartitionTable::isSectorBased() const
if (numPrimaries() == 0)
return !Config::useCylinderAlignment();
quint32 numCylinderAligned = 0;
quint32 numSectorAligned = 0;
// if not all partitions start at a point evenly divisable by sectorAlignment it's
// a cylinder-aligned msdos partition table
foreach(const Partition* p, children())
if (p->firstSector() % Config::sectorAlignment() != 0)
return false;
if (p->firstSector() % Config::sectorAlignment() == 0)
numSectorAligned++;
else if (p->firstSector() % d.cylinderSize() == 0)
numCylinderAligned++;
// must be sector aligned
return true;
return numSectorAligned >= numCylinderAligned;
}
return false;
return type() == PartitionTable::msdos_sectorbased;
}
void PartitionTable::setType(const Device& d, TableType t)

View File

@ -126,7 +126,7 @@ class LIBPARTITIONMANAGERPRIVATE_EXPORT PartitionTable : public PartitionNode
void updateUnallocated(const Device& d);
void insertUnallocated(const Device& d, PartitionNode* p, qint64 start) const;
bool isSectorBased() const;
bool isSectorBased(const Device& d) const;
static QList<Flag> flagList();
static QString flagName(Flag f);

View File

@ -912,7 +912,7 @@ void MainWindow::onImportPartitionTable()
Log(Log::warning) << i18nc("@info/plain", "Could not parse line %1 from import file. Ignoring it.", lineNo);
}
if (ptable->type() == PartitionTable::msdos && ptable->isSectorBased())
if (ptable->type() == PartitionTable::msdos && ptable->isSectorBased(device))
ptable->setType(device, PartitionTable::msdos_sectorbased);
}

View File

@ -366,7 +366,7 @@ void LibPartedBackend::scanDevicePartitions(PedDevice*, Device& d, PedDisk* pedD
d.partitionTable()->updateUnallocated(d);
if (d.partitionTable()->isSectorBased())
if (d.partitionTable()->isSectorBased(d))
d.partitionTable()->setType(d, PartitionTable::msdos_sectorbased);
foreach(const Partition* part, partitions)