* 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:
@@ -11,6 +11,7 @@
|
|||||||
#include <DiskDeviceVisitor.h>
|
#include <DiskDeviceVisitor.h>
|
||||||
#include <GroupLayout.h>
|
#include <GroupLayout.h>
|
||||||
#include <HashMap.h>
|
#include <HashMap.h>
|
||||||
|
#include <LayoutItem.h>
|
||||||
#include <PartitioningInfo.h>
|
#include <PartitioningInfo.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
|
||||||
@@ -225,7 +226,7 @@ public:
|
|||||||
view->SetSelected(id == fSelectedPartition);
|
view->SetSelected(id == fSelectedPartition);
|
||||||
PartitionView* parent = fViewMap.Get(partition->Parent()->ID());
|
PartitionView* parent = fViewMap.Get(partition->Parent()->ID());
|
||||||
BGroupLayout* layout = parent->GroupLayout();
|
BGroupLayout* layout = parent->GroupLayout();
|
||||||
layout->AddView(view, scale);
|
layout->AddView(_FindInsertIndex(view, layout), view, scale);
|
||||||
|
|
||||||
fViewMap.Put(partition->ID(), view);
|
fViewMap.Put(partition->ID(), view);
|
||||||
_AddSpaces(partition, view);
|
_AddSpaces(partition, view);
|
||||||
@@ -269,23 +270,30 @@ public:
|
|||||||
info.GetPartitionableSpaceAt(i, &offset, &size) >= B_OK;
|
info.GetPartitionableSpaceAt(i, &offset, &size) >= B_OK;
|
||||||
i++) {
|
i++) {
|
||||||
double scale = (double)size / parentSize;
|
double scale = (double)size / parentSize;
|
||||||
PartitionView* view = new PartitionView("Empty", scale,
|
PartitionView* view = new PartitionView("<empty>", scale,
|
||||||
offset, parentView->Level() + 1, -2);
|
offset, parentView->Level() + 1, -2);
|
||||||
|
|
||||||
BGroupLayout* layout = parentView->GroupLayout();
|
BGroupLayout* layout = parentView->GroupLayout();
|
||||||
int32 count = parentView->CountChildren();
|
layout->AddView(_FindInsertIndex(view, layout), view, scale);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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 HashKey32<partition_id> PartitionKey;
|
||||||
typedef HashMap<PartitionKey, PartitionView* > PartitionViewMap;
|
typedef HashMap<PartitionKey, PartitionView* > PartitionViewMap;
|
||||||
@@ -421,8 +429,17 @@ DiskView::_UpdateLayout()
|
|||||||
|
|
||||||
fPartitionLayout->Unset();
|
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->VisitEachDescendant(fPartitionLayout);
|
||||||
|
fDisk->CancelModifications();
|
||||||
|
}
|
||||||
|
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,10 @@ public:
|
|||||||
virtual bool Visit(BDiskDevice* device)
|
virtual bool Visit(BDiskDevice* device)
|
||||||
{
|
{
|
||||||
fDiskCount++;
|
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);
|
_AddPartition(device);
|
||||||
return false; // Don't stop yet!
|
return false; // Don't stop yet!
|
||||||
}
|
}
|
||||||
@@ -68,7 +72,8 @@ private:
|
|||||||
|
|
||||||
// add any available space on it
|
// add any available space on it
|
||||||
BPartitioningInfo info;
|
BPartitioningInfo info;
|
||||||
if (partition->GetPartitioningInfo(&info) >= B_OK) {
|
status_t ret = partition->GetPartitioningInfo(&info);
|
||||||
|
if (ret >= B_OK) {
|
||||||
off_t offset;
|
off_t offset;
|
||||||
off_t size;
|
off_t size;
|
||||||
for (int32 i = 0;
|
for (int32 i = 0;
|
||||||
@@ -76,6 +81,9 @@ private:
|
|||||||
i++) {
|
i++) {
|
||||||
fPartitionList->AddSpace(partition->ID(), offset, size);
|
fPartitionList->AddSpace(partition->ID(), offset, size);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "failed to get partitioning info: %s\n",
|
||||||
|
strerror(ret));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user