partitioning: pass along reference to parent when uninitializing.
* Fixes problems with setting the partition name after uninitializing a partition in DriveSetup. Previously, UninitializeJob() was followed by SetStringJob(), but the kernel was updating the change counter for the parent partition when uninitializing a partition, leading to SetStringJob() having an incorrect change counter for the parent partition. Now the parent change counter will be correct when SetStringJob() runs.
This commit is contained in:
@@ -397,7 +397,8 @@ extern status_t _kern_initialize_partition(partition_id partitionID,
|
||||
const char *name, const char *parameters,
|
||||
size_t parametersSize);
|
||||
extern status_t _kern_uninitialize_partition(partition_id partitionID,
|
||||
int32 changeCounter);
|
||||
int32 changeCounter, partition_id parentID,
|
||||
int32 parentChangeCounter);
|
||||
extern status_t _kern_create_child_partition(partition_id partitionID,
|
||||
int32 changeCounter, off_t offset, off_t size, const char *type,
|
||||
const char *parameters, size_t parametersSize,
|
||||
|
||||
@@ -109,13 +109,16 @@ class AutoLockerPartitionRegistration {
|
||||
public:
|
||||
inline bool Lock(KPartition *partition)
|
||||
{
|
||||
if (partition == NULL)
|
||||
return true;
|
||||
partition->Register();
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void Unlock(KPartition *partition)
|
||||
{
|
||||
partition->Unregister();
|
||||
if (partition != NULL)
|
||||
partition->Unregister();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -77,7 +77,8 @@ status_t _user_initialize_partition(partition_id partitionID,
|
||||
int32* changeCounter, const char* diskSystemName,
|
||||
const char* name, const char* parameters);
|
||||
status_t _user_uninitialize_partition(partition_id partitionID,
|
||||
int32* changeCounter);
|
||||
int32* changeCounter, partition_id parentID,
|
||||
int32* parentChangeCounter);
|
||||
|
||||
status_t _user_create_child_partition(partition_id partitionID,
|
||||
int32* changeCounter, off_t offset, off_t size,
|
||||
|
||||
@@ -617,7 +617,8 @@ extern status_t _kern_initialize_partition(partition_id partitionID,
|
||||
int32* changeCounter, const char* diskSystemName,
|
||||
const char* name, const char* parameters);
|
||||
extern status_t _kern_uninitialize_partition(partition_id partitionID,
|
||||
int32* changeCounter);
|
||||
int32* changeCounter, partition_id parentID,
|
||||
int32* parentChangeCounter);
|
||||
extern status_t _kern_create_child_partition(partition_id partitionID,
|
||||
int32* changeCounter, off_t offset, off_t size,
|
||||
const char* type, const char* name,
|
||||
|
||||
@@ -374,7 +374,8 @@ _kern_initialize_partition(partition_id partitionID, int32 changeCounter,
|
||||
|
||||
|
||||
status_t
|
||||
_kern_uninitialize_partition(partition_id partitionID, int32 changeCounter)
|
||||
_kern_uninitialize_partition(partition_id partitionID, int32 changeCounter,
|
||||
partition_id parentID, int32 parentChangeCounter)
|
||||
{
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
@@ -523,7 +523,15 @@ DiskDeviceJobGenerator::_GenerateUninitializeJob(BPartition* partition)
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
|
||||
return _AddJob(new(nothrow) UninitializeJob(reference));
|
||||
BPartition* parent = partition->Parent();
|
||||
PartitionReference* parentReference = NULL;
|
||||
if (parent != NULL) {
|
||||
error = _GetPartitionReference(parent, parentReference);
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
}
|
||||
|
||||
return _AddJob(new(nothrow) UninitializeJob(reference, parentReference));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -11,8 +11,9 @@
|
||||
|
||||
|
||||
// constructor
|
||||
UninitializeJob::UninitializeJob(PartitionReference* partition)
|
||||
: DiskDeviceJob(partition)
|
||||
UninitializeJob::UninitializeJob(PartitionReference* partition,
|
||||
PartitionReference* parent)
|
||||
: DiskDeviceJob(parent, partition)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -27,14 +28,20 @@ UninitializeJob::~UninitializeJob()
|
||||
status_t
|
||||
UninitializeJob::Do()
|
||||
{
|
||||
int32 changeCounter = fPartition->ChangeCounter();
|
||||
status_t error = _kern_uninitialize_partition(fPartition->PartitionID(),
|
||||
&changeCounter);
|
||||
bool haveParent = fPartition != NULL;
|
||||
int32 changeCounter = fChild->ChangeCounter();
|
||||
int32 parentChangeCounter = haveParent ? fPartition->ChangeCounter() : 0;
|
||||
partition_id parentID = haveParent ? fPartition->PartitionID() : -1;
|
||||
|
||||
status_t error = _kern_uninitialize_partition(fChild->PartitionID(),
|
||||
&changeCounter, parentID, &parentChangeCounter);
|
||||
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
|
||||
fPartition->SetChangeCounter(changeCounter);
|
||||
fChild->SetChangeCounter(changeCounter);
|
||||
if (haveParent)
|
||||
fPartition->SetChangeCounter(parentChangeCounter);
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,8 @@ namespace BPrivate {
|
||||
class UninitializeJob : public DiskDeviceJob {
|
||||
public:
|
||||
|
||||
UninitializeJob(PartitionReference* partition);
|
||||
UninitializeJob(PartitionReference* partition,
|
||||
PartitionReference* parent = NULL);
|
||||
virtual ~UninitializeJob();
|
||||
|
||||
virtual status_t Do();
|
||||
|
||||
@@ -1218,14 +1218,20 @@ _user_initialize_partition(partition_id partitionID, int32* _changeCounter,
|
||||
|
||||
|
||||
status_t
|
||||
_user_uninitialize_partition(partition_id partitionID, int32* _changeCounter)
|
||||
_user_uninitialize_partition(partition_id partitionID, int32* _changeCounter,
|
||||
partition_id parentID, int32* _parentChangeCounter)
|
||||
{
|
||||
// copy parameters in
|
||||
int32 changeCounter;
|
||||
int32 parentChangeCounter;
|
||||
bool haveParent = parentID >= 0;
|
||||
|
||||
status_t error;
|
||||
if ((error = copy_from_user_value(changeCounter, _changeCounter)) != B_OK)
|
||||
return error;
|
||||
if (haveParent && (error = copy_from_user_value(parentChangeCounter,
|
||||
_parentChangeCounter)) != B_OK)
|
||||
return error;
|
||||
|
||||
// get the partition
|
||||
KDiskDeviceManager* manager = KDiskDeviceManager::Default();
|
||||
@@ -1237,9 +1243,18 @@ _user_uninitialize_partition(partition_id partitionID, int32* _changeCounter)
|
||||
PartitionRegistrar registrar2(partition->Device(), true);
|
||||
DeviceWriteLocker locker(partition->Device(), true);
|
||||
|
||||
// register parent
|
||||
KPartition* parent = NULL;
|
||||
if (haveParent)
|
||||
parent = manager->RegisterPartition(parentID);
|
||||
|
||||
PartitionRegistrar registrar3(parent, true);
|
||||
|
||||
// check change counter
|
||||
if (changeCounter != partition->ChangeCounter())
|
||||
return B_BAD_VALUE;
|
||||
if (haveParent && parentChangeCounter != parent->ChangeCounter())
|
||||
return B_BAD_VALUE;
|
||||
|
||||
// the partition must be initialized
|
||||
if (!partition->DiskSystem())
|
||||
@@ -1275,6 +1290,9 @@ _user_uninitialize_partition(partition_id partitionID, int32* _changeCounter)
|
||||
error = copy_to_user_value(_changeCounter, partition->ChangeCounter());
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
if (haveParent && (error = copy_to_user_value(_parentChangeCounter,
|
||||
parent->ChangeCounter())) != B_OK)
|
||||
return error;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user