From c3815c8e898afd58695fe85f0be049fb634bd1e3 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sat, 22 Feb 2003 23:52:15 +0000 Subject: [PATCH] Started with the implementation of partitioning support. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2801 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/storage/Session.h | 6 +- src/kits/storage/Session.cpp | 124 +++++++++++++++++++++++------- 2 files changed, 99 insertions(+), 31 deletions(-) diff --git a/headers/private/storage/Session.h b/headers/private/storage/Session.h index 797c484852..c6d0437449 100644 --- a/headers/private/storage/Session.h +++ b/headers/private/storage/Session.h @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include class BDiskDevice; @@ -47,11 +47,11 @@ public: status_t GetPartitioningParameters(const char *partitioningSystem, BString *parameters, - BPoint dialogCenter = BPoint(-1, -1), + BRect dialogCenter = BRect(), bool *cancelled = NULL); status_t Partition(const char *partitioningSystem, const char *parameters); status_t Partition(const char *partitioningSystem, - BPoint dialogCenter = BPoint(-1, -1), + BRect dialogCenter = BRect(), bool *cancelled = NULL); static status_t GetPartitioningSystemList(BObjectList *list); diff --git a/src/kits/storage/Session.cpp b/src/kits/storage/Session.cpp index f80bdaff5f..bb91194338 100644 --- a/src/kits/storage/Session.cpp +++ b/src/kits/storage/Session.cpp @@ -3,14 +3,20 @@ // by the OpenBeOS license. //--------------------------------------------------------------------- +#include #include #include #include #include +#include +#include #include #include +#include "AddOnImage.h" +#include "PartitioningDialog.h" + /*! \class BSession \brief A BSession object represent a session and provides a lot of methods to retrieve information about it and some to manipulate it. @@ -238,8 +244,8 @@ BSession::PartitionWithID(int32 id) asked for. \param parameters Pointer to a pre-allocated BString to be set to the parameters the user has specified. - \param dialogCenter The point at which to center the dialog. If omitted, - the dialog is displayed centered to the screen. + \param dialogCenter The rectangle over which to center the dialog. If + omitted, the dialog is displayed centered to the screen. \param cancelled Pointer to a pre-allocated bool to be set to \c true, if the dialog has been cancelled by the user, or to \c false otherwise. May be \c NULL. @@ -251,10 +257,82 @@ BSession::PartitionWithID(int32 id) */ status_t BSession::GetPartitioningParameters(const char *partitioningSystem, - BString *parameters, BPoint dialogCenter, + BString *parameters, BRect dialogCenter, bool *cancelled) { - return B_ERROR; // not implemented + status_t error = (partitioningSystem && parameters ? B_OK : B_BAD_VALUE); + // get the add-on + AddOnImage image; + BDiskScannerPartitionAddOn *addOn = NULL; + if (error == B_OK) { + error = BDiskDeviceRoster::_LoadPartitionAddOn(partitioningSystem, + &image, &addOn); + } + // open the device + int deviceFD = -1; + if (error == B_OK) { + deviceFD = open(Device()->Path(), O_RDONLY); + if (deviceFD < 0) + error = errno; + } + // get the default parameters + char *allocatedBuffer = NULL; + char localBuffer[256]; + char *defaultParams = NULL; + if (error == B_OK) { + // try a small buffer on stack + defaultParams = localBuffer; + size_t bufferSize = sizeof(localBuffer); + size_t actualSize = 0; + error = get_partitioning_parameters(deviceFD, Index(), + partitioningSystem, defaultParams, + bufferSize, &actualSize); + if (error == B_OK && actualSize > bufferSize) { + // stack buffer was too small, allocate one on the heap + allocatedBuffer = new(nothrow) char[actualSize]; + if (allocatedBuffer) { + defaultParams = allocatedBuffer; + bufferSize = actualSize; + error = get_partitioning_parameters(deviceFD, Index(), + partitioningSystem, + defaultParams, bufferSize, + &actualSize); + if (error == B_OK && actualSize > bufferSize) + error = B_ERROR; + } else + error = B_NO_MEMORY; + } + } + // close the device + if (deviceFD >= 0) + close(deviceFD); + // get an editor + BDiskScannerParameterEditor *editor = NULL; + if (error == B_OK) { + editor = addOn->CreateEditor(this, defaultParams); + if (!editor) + error = B_ERROR; + } + // create and run the editing dialog + PartitioningDialog *dialog = NULL; + if (error == B_OK) { + dialog = new (nothrow) PartitioningDialog(dialogCenter); + if (dialog) + error = dialog->Go(editor, cancelled); + else + error = B_NO_MEMORY; + } + // get the parameters + if (error == B_OK) + error = editor->GetParameters(parameters); + // cleanup + if (allocatedBuffer) + delete allocatedBuffer; + if (editor) + delete editor; + if (addOn) + delete addOn; + return error; } // Partition @@ -286,8 +364,8 @@ BSession::Partition(const char *partitioningSystem, const char *parameters) \param partitioningSystem The partitioning system to be used for partitioning. - \param dialogCenter The point at which to center the dialog. If omitted, - the dialog is displayed centered to the screen. + \param dialogCenter The rectangle over which to center the dialog. If + omitted, the dialog is displayed centered to the screen. \param cancelled Pointer to a pre-allocated bool to be set to \c true, if the dialog has been cancelled by the user, or to \c false otherwise. May be \c NULL. @@ -299,30 +377,20 @@ BSession::Partition(const char *partitioningSystem, const char *parameters) - another error code */ status_t -BSession::Partition(const char *partitioningSystem, BPoint dialogCenter, +BSession::Partition(const char *partitioningSystem, BRect dialogCenter, bool *cancelled) { - return B_ERROR; // not implemented -} - -// GetPartitioningSystemList -/*! \brief Returns a list of all partitioning systems that can be used for - partitioning. - - The names of the partioning systems are added as BString objects to the - supplied list. The caller takes over ownership of the return BString - objects and is responsible for deleteing them. - - Any of returned names can be passed to Partition(). - - \param list Pointer to a pre-allocated BObjectList the names of the - partitioning systems shall be added to. - \return \c B_OK, if everything went fine, another error code otherwise. -*/ -status_t -BSession::GetPartitioningSystemList(BObjectList *list) -{ - return B_ERROR; // not implemented + status_t error = (partitioningSystem ? B_OK : B_BAD_VALUE); + // get the parameters + BString parameters; + if (error == B_OK) { + error = GetPartitioningParameters(partitioningSystem, ¶meters, + dialogCenter, cancelled); + } + // do the partitioning + if (error == B_OK) + error = Partition(partitioningSystem, parameters.String()); + return error; } // constructor