* To be able to call BPartition::GetPartitioningIngo(), you need to call

PrepareModifications() on the parent BDiskDevice first. Hm. I should
  probably reorganize things a bit.
* Selecting these empty spaces is still not supported.
* Fixed inserting empty spaces in the DiskView at the correct index.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23812 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2008-02-01 18:02:04 +00:00
parent 56d794d68e
commit 8d2c63c703
2 changed files with 39 additions and 14 deletions
+30 -13
View File
@@ -11,6 +11,7 @@
#include <DiskDeviceVisitor.h>
#include <GroupLayout.h>
#include <HashMap.h>
#include <LayoutItem.h>
#include <PartitioningInfo.h>
#include <String.h>
@@ -225,7 +226,7 @@ public:
view->SetSelected(id == fSelectedPartition);
PartitionView* parent = fViewMap.Get(partition->Parent()->ID());
BGroupLayout* layout = parent->GroupLayout();
layout->AddView(view, scale);
layout->AddView(_FindInsertIndex(view, layout), view, scale);
fViewMap.Put(partition->ID(), view);
_AddSpaces(partition, view);
@@ -269,23 +270,30 @@ public:
info.GetPartitionableSpaceAt(i, &offset, &size) >= B_OK;
i++) {
double scale = (double)size / parentSize;
PartitionView* view = new PartitionView("Empty", scale,
PartitionView* view = new PartitionView("<empty>", scale,
offset, parentView->Level() + 1, -2);
BGroupLayout* layout = parentView->GroupLayout();
int32 count = parentView->CountChildren();
int32 insertIndex = 0;
for (int32 j = 0; j < count; j++) {
PartitionView* sibling = dynamic_cast<PartitionView*>(
parentView->ChildAt(j));
if (sibling && sibling->Offset() > offset)
break;
insertIndex++;
}
layout->AddView(view, scale);
layout->AddView(_FindInsertIndex(view, layout), view, scale);
}
}
}
int32 _FindInsertIndex(PartitionView* view, BGroupLayout* layout) const
{
int32 insertIndex = 0;
int32 count = layout->CountItems();
for (int32 i = 0; i < count; i++) {
BLayoutItem* item = layout->ItemAt(i);
if (!item)
break;
PartitionView* sibling
= dynamic_cast<PartitionView*>(item->View());
if (sibling && sibling->Offset() > view->Offset())
break;
insertIndex++;
}
return insertIndex;
}
typedef HashKey32<partition_id> PartitionKey;
typedef HashMap<PartitionKey, PartitionView* > PartitionViewMap;
@@ -421,8 +429,17 @@ DiskView::_UpdateLayout()
fPartitionLayout->Unset();
if (fDisk)
if (fDisk) {
// we need to prepare the disk for modifications, otherwise
// we cannot get information about available spaces on the
// device or any of its child partitions
// TODO: cancelling modifications here is of course undesired
// once we hold off the real modifications until an explicit
// command to write them to disk...
fDisk->PrepareModifications();
fDisk->VisitEachDescendant(fPartitionLayout);
fDisk->CancelModifications();
}
Invalidate();
}
+9 -1
View File
@@ -50,6 +50,10 @@ public:
virtual bool Visit(BDiskDevice* device)
{
fDiskCount++;
// if we don't prepare the device for modifications,
// we cannot get information about available empty
// regions on the device or child partitions
device->PrepareModifications();
_AddPartition(device);
return false; // Don't stop yet!
}
@@ -68,7 +72,8 @@ private:
// add any available space on it
BPartitioningInfo info;
if (partition->GetPartitioningInfo(&info) >= B_OK) {
status_t ret = partition->GetPartitioningInfo(&info);
if (ret >= B_OK) {
off_t offset;
off_t size;
for (int32 i = 0;
@@ -76,6 +81,9 @@ private:
i++) {
fPartitionList->AddSpace(partition->ID(), offset, size);
}
} else {
fprintf(stderr, "failed to get partitioning info: %s\n",
strerror(ret));
}
}