diff --git a/src/apps/drivesetup/DiskView.cpp b/src/apps/drivesetup/DiskView.cpp index 4a63ca3b8a..279c1f3b1c 100644 --- a/src/apps/drivesetup/DiskView.cpp +++ b/src/apps/drivesetup/DiskView.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -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("", 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( - 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(item->View()); + if (sibling && sibling->Offset() > view->Offset()) + break; + insertIndex++; + } + return insertIndex; + } typedef HashKey32 PartitionKey; typedef HashMap 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(); } diff --git a/src/apps/drivesetup/MainWindow.cpp b/src/apps/drivesetup/MainWindow.cpp index 11666bb182..ff73b745e2 100644 --- a/src/apps/drivesetup/MainWindow.cpp +++ b/src/apps/drivesetup/MainWindow.cpp @@ -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)); } }