Example #1
0
// DeleteChild
status_t
BPartition::DeleteChild(int32 index)
{
	if (!fDelegate)
		return B_NO_INIT;
	BPartition* child = ChildAt(index);
	if (!child || child->Parent() != this)
		return B_BAD_VALUE;

	return fDelegate->DeleteChild(child->fDelegate);
}
Example #2
0
			virtual bool
			Visit(BPartition* partition, int32 level)
			{
				if (fOnlyOnDeviceID >= 0) {
					// only mount partitions on the given device id
					// or if the partition ID is already matched
					BPartition* device = partition;
					while (device->Parent() != NULL) {
						if (device->ID() == fOnlyOnDeviceID) {
							// we are happy
							break;
						}
						device = device->Parent();
					}
					if (device->ID() != fOnlyOnDeviceID)
						return false;
				}

				mount_mode mode = !fInitialRescan
					&& partition->Device()->IsRemovableMedia()
					? fRemovableMode : fNormalMode;
				if (mode == kNoVolumes
					|| partition->IsMounted()
					|| !partition->ContainsFileSystem())
					return false;

				BPath path;
				if (partition->GetPath(&path) != B_OK)
					return false;

				if (mode == kRestorePreviousVolumes) {
					// mount all volumes that were stored in the settings file
					const char *volumeName = NULL;
					if (partition->ContentName() == NULL
						|| fPrevious.FindString(path.Path(), &volumeName)
							!= B_OK
						|| strcmp(volumeName, partition->ContentName()))
						return false;
				} else if (mode == kOnlyBFSVolumes) {
					if (partition->ContentType() == NULL
						|| strcmp(partition->ContentType(), kPartitionTypeBFS))
						return false;
				}

				uint32 mountFlags;
				if (!fInitialRescan) {
					// Ask the user about mount flags if this is not the
					// initial scan.
					if (!_SuggestMountFlags(partition, &mountFlags))
						return false;
				} else {
					BString mountFlagsKey(path.Path());
					mountFlagsKey << kMountFlagsKeyExtension;
					if (fPrevious.FindInt32(mountFlagsKey.String(),
							(int32*)&mountFlags) < B_OK) {
						mountFlags = 0;
					}
				}

				if (partition->Mount(NULL, mountFlags) != B_OK) {
					// TODO: Error to syslog
				}
				return false;
			}
Example #3
0
void
MainWindow::_Delete(BDiskDevice* disk, partition_id selectedPartition)
{
	if (!disk || selectedPartition < 0) {
		_DisplayPartitionError(B_TRANSLATE("You need to select a partition "
			"entry from the list."));
		return;
	}

	if (disk->IsReadOnly()) {
		_DisplayPartitionError(B_TRANSLATE("The selected disk is read-only."));
		return;
	}

	BPartition* partition = disk->FindDescendant(selectedPartition);
	if (!partition) {
		_DisplayPartitionError(B_TRANSLATE("Unable to find the selected "
			"partition by ID."));
		return;
	}

	BPartition* parent = partition->Parent();
	if (!parent) {
		_DisplayPartitionError(B_TRANSLATE("The currently selected partition "
			"does not have a parent partition."));
		return;
	}

	ModificationPreparer modificationPreparer(disk);
	status_t ret = modificationPreparer.ModificationStatus();
	if (ret != B_OK) {
		_DisplayPartitionError(B_TRANSLATE("There was an error preparing the "
			"disk for modifications."), NULL, ret);
		return;
	}

	if (!parent->CanDeleteChild(partition->Index())) {
		_DisplayPartitionError(
			B_TRANSLATE("Cannot delete the selected partition."));
		return;
	}

	// Warn the user one more time...
	BAlert* alert = new BAlert("final notice", B_TRANSLATE("Are you sure you "
		"want to delete the selected partition?\n\n"
		"All data on the partition will be irretrievably lost if you "
		"do so!"), B_TRANSLATE("Delete partition"), B_TRANSLATE("Cancel"), NULL,
		B_WIDTH_FROM_WIDEST, B_WARNING_ALERT);
	int32 choice = alert->Go();

	if (choice == 1)
		return;

	ret = parent->DeleteChild(partition->Index());
	if (ret != B_OK) {
		_DisplayPartitionError(
			B_TRANSLATE("Could not delete the selected partition."));
		return;
	}

	ret = modificationPreparer.CommitModifications();

	if (ret != B_OK) {
		_DisplayPartitionError(B_TRANSLATE("Failed to delete the partition. "
			"No changes have been written to disk."));
		return;
	}

	_ScanDrives();
	fDiskView->ForceUpdate();
}