Started with the implementation of partitioning support.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2801 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
#include <DiskDeviceVisitor.h>
|
#include <DiskDeviceVisitor.h>
|
||||||
#include <disk_scanner.h>
|
#include <disk_scanner.h>
|
||||||
#include <ObjectList.h>
|
#include <ObjectList.h>
|
||||||
#include <Point.h>
|
#include <Rect.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
|
||||||
class BDiskDevice;
|
class BDiskDevice;
|
||||||
@@ -47,11 +47,11 @@ public:
|
|||||||
|
|
||||||
status_t GetPartitioningParameters(const char *partitioningSystem,
|
status_t GetPartitioningParameters(const char *partitioningSystem,
|
||||||
BString *parameters,
|
BString *parameters,
|
||||||
BPoint dialogCenter = BPoint(-1, -1),
|
BRect dialogCenter = BRect(),
|
||||||
bool *cancelled = NULL);
|
bool *cancelled = NULL);
|
||||||
status_t Partition(const char *partitioningSystem, const char *parameters);
|
status_t Partition(const char *partitioningSystem, const char *parameters);
|
||||||
status_t Partition(const char *partitioningSystem,
|
status_t Partition(const char *partitioningSystem,
|
||||||
BPoint dialogCenter = BPoint(-1, -1),
|
BRect dialogCenter = BRect(),
|
||||||
bool *cancelled = NULL);
|
bool *cancelled = NULL);
|
||||||
|
|
||||||
static status_t GetPartitioningSystemList(BObjectList<BString> *list);
|
static status_t GetPartitioningSystemList(BObjectList<BString> *list);
|
||||||
|
|||||||
@@ -3,14 +3,20 @@
|
|||||||
// by the OpenBeOS license.
|
// by the OpenBeOS license.
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
#include <new.h>
|
#include <new.h>
|
||||||
|
|
||||||
#include <Session.h>
|
#include <Session.h>
|
||||||
#include <DiskDevice.h>
|
#include <DiskDevice.h>
|
||||||
#include <DiskDevicePrivate.h>
|
#include <DiskDevicePrivate.h>
|
||||||
|
#include <DiskDeviceRoster.h>
|
||||||
|
#include <DiskScannerAddOn.h>
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <Partition.h>
|
#include <Partition.h>
|
||||||
|
|
||||||
|
#include "AddOnImage.h"
|
||||||
|
#include "PartitioningDialog.h"
|
||||||
|
|
||||||
/*! \class BSession
|
/*! \class BSession
|
||||||
\brief A BSession object represent a session and provides a lot of
|
\brief A BSession object represent a session and provides a lot of
|
||||||
methods to retrieve information about it and some to manipulate it.
|
methods to retrieve information about it and some to manipulate it.
|
||||||
@@ -238,8 +244,8 @@ BSession::PartitionWithID(int32 id)
|
|||||||
asked for.
|
asked for.
|
||||||
\param parameters Pointer to a pre-allocated BString to be set to the
|
\param parameters Pointer to a pre-allocated BString to be set to the
|
||||||
parameters the user has specified.
|
parameters the user has specified.
|
||||||
\param dialogCenter The point at which to center the dialog. If omitted,
|
\param dialogCenter The rectangle over which to center the dialog. If
|
||||||
the dialog is displayed centered to the screen.
|
omitted, the dialog is displayed centered to the screen.
|
||||||
\param cancelled Pointer to a pre-allocated bool to be set to \c true, if
|
\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
|
the dialog has been cancelled by the user, or to \c false
|
||||||
otherwise. May be \c NULL.
|
otherwise. May be \c NULL.
|
||||||
@@ -251,10 +257,82 @@ BSession::PartitionWithID(int32 id)
|
|||||||
*/
|
*/
|
||||||
status_t
|
status_t
|
||||||
BSession::GetPartitioningParameters(const char *partitioningSystem,
|
BSession::GetPartitioningParameters(const char *partitioningSystem,
|
||||||
BString *parameters, BPoint dialogCenter,
|
BString *parameters, BRect dialogCenter,
|
||||||
bool *cancelled)
|
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
|
// Partition
|
||||||
@@ -286,8 +364,8 @@ BSession::Partition(const char *partitioningSystem, const char *parameters)
|
|||||||
|
|
||||||
\param partitioningSystem The partitioning system to be used for
|
\param partitioningSystem The partitioning system to be used for
|
||||||
partitioning.
|
partitioning.
|
||||||
\param dialogCenter The point at which to center the dialog. If omitted,
|
\param dialogCenter The rectangle over which to center the dialog. If
|
||||||
the dialog is displayed centered to the screen.
|
omitted, the dialog is displayed centered to the screen.
|
||||||
\param cancelled Pointer to a pre-allocated bool to be set to \c true, if
|
\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
|
the dialog has been cancelled by the user, or to \c false
|
||||||
otherwise. May be \c NULL.
|
otherwise. May be \c NULL.
|
||||||
@@ -299,30 +377,20 @@ BSession::Partition(const char *partitioningSystem, const char *parameters)
|
|||||||
- another error code
|
- another error code
|
||||||
*/
|
*/
|
||||||
status_t
|
status_t
|
||||||
BSession::Partition(const char *partitioningSystem, BPoint dialogCenter,
|
BSession::Partition(const char *partitioningSystem, BRect dialogCenter,
|
||||||
bool *cancelled)
|
bool *cancelled)
|
||||||
{
|
{
|
||||||
return B_ERROR; // not implemented
|
status_t error = (partitioningSystem ? B_OK : B_BAD_VALUE);
|
||||||
}
|
// get the parameters
|
||||||
|
BString parameters;
|
||||||
// GetPartitioningSystemList
|
if (error == B_OK) {
|
||||||
/*! \brief Returns a list of all partitioning systems that can be used for
|
error = GetPartitioningParameters(partitioningSystem, ¶meters,
|
||||||
partitioning.
|
dialogCenter, cancelled);
|
||||||
|
}
|
||||||
The names of the partioning systems are added as BString objects to the
|
// do the partitioning
|
||||||
supplied list. The caller takes over ownership of the return BString
|
if (error == B_OK)
|
||||||
objects and is responsible for deleteing them.
|
error = Partition(partitioningSystem, parameters.String());
|
||||||
|
return error;
|
||||||
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<BString> *list)
|
|
||||||
{
|
|
||||||
return B_ERROR; // not implemented
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
|
|||||||
Reference in New Issue
Block a user