Exemplo n.º 1
0
status_t
_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 = copy_from_user_value(changeCounter, _changeCounter);
	if (haveParent && error == B_OK)
		error = copy_from_user_value(parentChangeCounter, _parentChangeCounter);
	if (error != B_OK)
		return error;

	// get the partition
	KDiskDeviceManager* manager = KDiskDeviceManager::Default();
	KPartition* partition = manager->WriteLockPartition(partitionID);
	if (partition == NULL)
		return B_ENTRY_NOT_FOUND;

	PartitionRegistrar registrar1(partition, true);
	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() == NULL)
		return B_BAD_VALUE;

	// check busy
	if (!partition->CheckAndMarkBusy(true))
		return B_BUSY;

	if (partition->IsMounted() || partition->IsChildMounted())
		return B_BAD_VALUE;

	KDiskSystem* diskSystem = partition->DiskSystem();

	locker.Unlock();

	// Let the disk system uninitialize the partition. This operation is not
	// mandatory. If implemented, it will destroy the on-disk structures, so
	// that the disk system cannot accidentally identify the partition later on.
	if (diskSystem != NULL)
		diskSystem->Uninitialize(partition, DUMMY_JOB_ID);

	// re-lock and uninitialize the partition object
	locker.Lock();
	error = partition->UninitializeContents(true);

	partition->UnmarkBusy(true);

	if (error != B_OK)
		return error;

	// return change counter
	error = copy_to_user_value(_changeCounter, partition->ChangeCounter());
	if (haveParent && error == B_OK)
		error = copy_to_user_value(_parentChangeCounter, parent->ChangeCounter());
	return error;
}