The modification preparations were not properly maintained which could
cause all kinds of trouble when finally trying to initialize a partition. In various situations, the disk would already be prepared for modifications in which case PrepareModifications() will return an error when called again. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26462 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -447,8 +447,9 @@ DiskView::_UpdateLayout()
|
|||||||
// TODO: cancelling modifications here is of course undesired
|
// TODO: cancelling modifications here is of course undesired
|
||||||
// once we hold off the real modifications until an explicit
|
// once we hold off the real modifications until an explicit
|
||||||
// command to write them to disk...
|
// command to write them to disk...
|
||||||
fDisk->PrepareModifications();
|
bool prepared = fDisk->PrepareModifications() == B_OK;
|
||||||
fDisk->VisitEachDescendant(fPartitionLayout);
|
fDisk->VisitEachDescendant(fPartitionLayout);
|
||||||
|
if (prepared)
|
||||||
fDisk->CancelModifications();
|
fDisk->CancelModifications();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ public:
|
|||||||
: fPartitionList(list)
|
: fPartitionList(list)
|
||||||
, fDiskCount(diskCount)
|
, fDiskCount(diskCount)
|
||||||
, fSpaceIDMap(spaceIDMap)
|
, fSpaceIDMap(spaceIDMap)
|
||||||
|
, fLastPreparedDevice(NULL)
|
||||||
{
|
{
|
||||||
fDiskCount = 0;
|
fDiskCount = 0;
|
||||||
fSpaceIDMap.Clear();
|
fSpaceIDMap.Clear();
|
||||||
@@ -51,6 +52,11 @@ public:
|
|||||||
delete row;
|
delete row;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
~ListPopulatorVisitor()
|
||||||
|
{
|
||||||
|
if (fLastPreparedDevice)
|
||||||
|
fLastPreparedDevice->CancelModifications();
|
||||||
|
}
|
||||||
|
|
||||||
virtual bool Visit(BDiskDevice* device)
|
virtual bool Visit(BDiskDevice* device)
|
||||||
{
|
{
|
||||||
@@ -58,7 +64,12 @@ public:
|
|||||||
// if we don't prepare the device for modifications,
|
// if we don't prepare the device for modifications,
|
||||||
// we cannot get information about available empty
|
// we cannot get information about available empty
|
||||||
// regions on the device or child partitions
|
// regions on the device or child partitions
|
||||||
device->PrepareModifications();
|
if (fLastPreparedDevice) {
|
||||||
|
fLastPreparedDevice->CancelModifications();
|
||||||
|
fLastPreparedDevice = NULL;
|
||||||
|
}
|
||||||
|
if (device->PrepareModifications() == B_OK)
|
||||||
|
fLastPreparedDevice = device;
|
||||||
_AddPartition(device);
|
_AddPartition(device);
|
||||||
return false; // Don't stop yet!
|
return false; // Don't stop yet!
|
||||||
}
|
}
|
||||||
@@ -98,6 +109,7 @@ private:
|
|||||||
PartitionListView* fPartitionList;
|
PartitionListView* fPartitionList;
|
||||||
int32& fDiskCount;
|
int32& fDiskCount;
|
||||||
SpaceIDMap& fSpaceIDMap;
|
SpaceIDMap& fSpaceIDMap;
|
||||||
|
BDiskDevice* fLastPreparedDevice;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -493,7 +505,6 @@ fSurfaceTestMI->SetEnabled(false);
|
|||||||
parentPartition = disk->FindDescendant(parentID);
|
parentPartition = disk->FindDescendant(parentID);
|
||||||
|
|
||||||
if (parentPartition) {
|
if (parentPartition) {
|
||||||
disk->PrepareModifications();
|
|
||||||
fCreateMenu->SetEnabled(true);
|
fCreateMenu->SetEnabled(true);
|
||||||
BString supportedChildType;
|
BString supportedChildType;
|
||||||
int32 cookie = 0;
|
int32 cookie = 0;
|
||||||
@@ -511,7 +522,6 @@ disk->PrepareModifications();
|
|||||||
if (fCreateMenu->CountItems() == 0)
|
if (fCreateMenu->CountItems() == 0)
|
||||||
fprintf(stderr, "Failed to get supported child types: %s\n",
|
fprintf(stderr, "Failed to get supported child types: %s\n",
|
||||||
strerror(ret));
|
strerror(ret));
|
||||||
disk->CancelModifications();
|
|
||||||
} else {
|
} else {
|
||||||
fCreateMenu->SetEnabled(false);
|
fCreateMenu->SetEnabled(false);
|
||||||
}
|
}
|
||||||
@@ -648,6 +658,34 @@ MainWindow::_MountAll()
|
|||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
class ModificationPreparer {
|
||||||
|
public:
|
||||||
|
ModificationPreparer(BDiskDevice* disk)
|
||||||
|
: fDisk(disk)
|
||||||
|
, fModificationStatus(fDisk->PrepareModifications())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
~ModificationPreparer()
|
||||||
|
{
|
||||||
|
if (fModificationStatus == B_OK)
|
||||||
|
fDisk->CancelModifications();
|
||||||
|
}
|
||||||
|
status_t ModificationStatus() const
|
||||||
|
{
|
||||||
|
return fModificationStatus;
|
||||||
|
}
|
||||||
|
status_t CommitModifications()
|
||||||
|
{
|
||||||
|
status_t ret = fDisk->CommitModifications();
|
||||||
|
if (ret == B_OK)
|
||||||
|
fModificationStatus = B_ERROR;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
BDiskDevice* fDisk;
|
||||||
|
status_t fModificationStatus;
|
||||||
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
MainWindow::_Initialize(BDiskDevice* disk, partition_id selectedPartition,
|
MainWindow::_Initialize(BDiskDevice* disk, partition_id selectedPartition,
|
||||||
@@ -716,7 +754,8 @@ MainWindow::_Initialize(BDiskDevice* disk, partition_id selectedPartition,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t ret = disk->PrepareModifications();
|
ModificationPreparer modificationPreparer(disk);
|
||||||
|
status_t ret = modificationPreparer.ModificationStatus();
|
||||||
if (ret != B_OK) {
|
if (ret != B_OK) {
|
||||||
_DisplayPartitionError("There was an error preparing the "
|
_DisplayPartitionError("There was an error preparing the "
|
||||||
"disk for modifications.", NULL, ret);
|
"disk for modifications.", NULL, ret);
|
||||||
@@ -766,7 +805,7 @@ MainWindow::_Initialize(BDiskDevice* disk, partition_id selectedPartition,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// commit
|
// commit
|
||||||
ret = disk->CommitModifications();
|
ret = modificationPreparer.CommitModifications();
|
||||||
if (ret == B_OK) {
|
if (ret == B_OK) {
|
||||||
_DisplayPartitionError("The partition %s has been successfully "
|
_DisplayPartitionError("The partition %s has been successfully "
|
||||||
"initialized.\n", partition);
|
"initialized.\n", partition);
|
||||||
|
|||||||
Reference in New Issue
Block a user