* Style cleanup.

* Moved method documentation from headers to source files.
* Fixed small problems (memory leaks, unsafe string duplication,...).
* Added TODOs where I spotted problems.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21721 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2007-07-27 16:32:47 +00:00
parent e098680c08
commit d86af8ce27
35 changed files with 1124 additions and 862 deletions
@@ -1,5 +1,11 @@
// KDiskDeviceJob.h /*
* Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold <[email protected]>
* Lubos Kulic
*/
#ifndef _K_DISK_DEVICE_JOB_H #ifndef _K_DISK_DEVICE_JOB_H
#define _K_DISK_DEVICE_JOB_H #define _K_DISK_DEVICE_JOB_H
@@ -15,39 +21,20 @@ class KDiskDeviceJobQueue;
/** /**
* Represents some action executed on the disk device. * Represents some action executed on the disk device.
*
* -
*/ */
class KDiskDeviceJob { class KDiskDeviceJob {
public: public:
/**
* Creates a new job
*
* \param type actual type of the job (see DiskDeviceDefs.h for details)
* \param partitionID the partition/device on which the action should be executed
* \param scopeID partition/device which is the highest in the hierarchy (i.e. closest
* to the root) that can be affected by the action
* - every descendant of this partition is marked busy and all ancestors are marked descendant-
busy
*/
KDiskDeviceJob(uint32 type, partition_id partitionID, KDiskDeviceJob(uint32 type, partition_id partitionID,
partition_id scopeID = -1); partition_id scopeID = -1);
virtual ~KDiskDeviceJob(); virtual ~KDiskDeviceJob();
/**
* Unique identification of the job
*/
disk_job_id ID() const; disk_job_id ID() const;
void SetJobQueue(KDiskDeviceJobQueue *queue); void SetJobQueue(KDiskDeviceJobQueue *queue);
KDiskDeviceJobQueue *JobQueue() const; KDiskDeviceJobQueue *JobQueue() const;
/**
* Gets actual type of the action
*/
uint32 Type() const; uint32 Type() const;
void SetStatus(uint32 status); void SetStatus(uint32 status);
uint32 Status() const; uint32 Status() const;
@@ -81,21 +68,6 @@ public:
status_t GetInfo(user_disk_device_job_info *info); status_t GetInfo(user_disk_device_job_info *info);
status_t GetProgressInfo(disk_device_job_progress_info *info); status_t GetProgressInfo(disk_device_job_progress_info *info);
/**
* Do the actual work of the job.
*
* - is supposed to be implemented in descendants
* - doesn't have any parameter - every operation needs different ones -> they're passed
* to the constructor
* - the implementations will
* - check the parameters given in constructor (e.g. if given partition exists...)
* - check whether the partition has needed disk system (its own or parent - depends
* on the operation)
* - using the disk system, validate the operation for given params
* - finally execute the action
*
* \return B_OK when everything went OK, some error otherwise
*/
virtual status_t Do() = 0; virtual status_t Do() = 0;
private: private:
@@ -116,27 +88,10 @@ private:
static disk_job_id fNextID; static disk_job_id fNextID;
private:
/**
* Visitor which checks if every descendant of given partition is busy or descendant-busy
*/
struct IsNotBusyVisitor : KPartitionVisitor {
virtual bool VisitPre(KPartition * partition);
};
IsNotBusyVisitor fNotBusyVisitor;
protected: protected:
//some stuff useful for all descendants // some stuff useful for all descendants
/** bool IsPartitionNotBusy(KPartition* partition);
* Checks if there's any descendant which is not busy/descendant-busy.
*
* - the condition of busy descendant is common for many disk device operations ->
* many jobs can use this
*
* \param partition the root of checked subtree of the whole partition hieararchy
*/
bool isPartitionNotBusy( KPartition * partition );
}; };
@@ -1,5 +1,10 @@
// KDiskSystem.h /*
* Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold <[email protected]>
*/
#ifndef _K_DISK_DEVICE_SYSTEM_H #ifndef _K_DISK_DEVICE_SYSTEM_H
#define _K_DISK_DEVICE_SYSTEM_H #define _K_DISK_DEVICE_SYSTEM_H
@@ -13,7 +18,7 @@ namespace DiskDevice {
class KDiskDeviceJob; class KDiskDeviceJob;
class KPartition; class KPartition;
/// \brief Common ancestor for disk system add-on wrappers //! \brief Common ancestor for disk system add-on wrappers
class KDiskSystem { class KDiskSystem {
public: public:
KDiskSystem(const char *name); KDiskSystem(const char *name);
@@ -1,8 +1,13 @@
// KFileSystem.h /*
// * Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
// KFileSystem implements the KDiskSystem interface for file systems. * Distributed under the terms of the MIT License.
// It works with the FS API. *
* Authors:
* Ingo Weinhold <[email protected]>
*
* KFileSystem implements the KDiskSystem interface for file systems.
* It works with the FS API.
*/
#ifndef _K_FILE_DISK_DEVICE_SYSTEM_H #ifndef _K_FILE_DISK_DEVICE_SYSTEM_H
#define _K_FILE_DISK_DEVICE_SYSTEM_H #define _K_FILE_DISK_DEVICE_SYSTEM_H
@@ -13,7 +18,7 @@ struct file_system_module_info;
namespace BPrivate { namespace BPrivate {
namespace DiskDevice { namespace DiskDevice {
/// \brief Wrapper for the C interface of a filesystem add-on. //! \brief Wrapper for the C interface of a filesystem add-on.
class KFileSystem : public KDiskSystem { class KFileSystem : public KDiskSystem {
public: public:
KFileSystem(const char *name); KFileSystem(const char *name);
@@ -1,5 +1,10 @@
// KPartition.h /*
* Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold <[email protected]>
*/
#ifndef _K_DISK_DEVICE_PARTITION_H #ifndef _K_DISK_DEVICE_PARTITION_H
#define _K_DISK_DEVICE_PARTITION_H #define _K_DISK_DEVICE_PARTITION_H
@@ -21,7 +26,7 @@ class KPath;
class KPhysicalPartition; class KPhysicalPartition;
class KShadowPartition; class KShadowPartition;
/// \brief Class representing a single partition. //! \brief Class representing a single partition.
class KPartition { class KPartition {
public: public:
KPartition(partition_id id = -1); KPartition(partition_id id = -1);
@@ -1,5 +1,10 @@
// KPartitioningSystem.h /*
* Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold <[email protected]>
*/
#ifndef _K_PARTITIONING_DISK_DEVICE_SYSTEM_H #ifndef _K_PARTITIONING_DISK_DEVICE_SYSTEM_H
#define _K_PARTITIONING_DISK_DEVICE_SYSTEM_H #define _K_PARTITIONING_DISK_DEVICE_SYSTEM_H
@@ -24,9 +29,9 @@ public:
// Scanning // Scanning
/// Try to identify a given partition //! Try to identify a given partition
virtual float Identify(KPartition *partition, void **cookie); virtual float Identify(KPartition *partition, void **cookie);
/// Scan the partition //! Scan the partition
virtual status_t Scan(KPartition *partition, void *cookie); virtual status_t Scan(KPartition *partition, void *cookie);
virtual void FreeIdentifyCookie(KPartition *partition, void *cookie); virtual void FreeIdentifyCookie(KPartition *partition, void *cookie);
virtual void FreeCookie(KPartition *partition); virtual void FreeCookie(KPartition *partition);
@@ -34,132 +39,132 @@ public:
// Querying // Querying
/// Check whether the add-on supports repairing this partition. //! Check whether the add-on supports repairing this partition.
virtual bool SupportsRepairing(KPartition *partition, bool checkOnly, virtual bool SupportsRepairing(KPartition *partition, bool checkOnly,
bool *whileMounted); bool *whileMounted);
/// Check whether the add-on supports resizing this partition. //! Check whether the add-on supports resizing this partition.
virtual bool SupportsResizing(KPartition *partition, bool *whileMounted); virtual bool SupportsResizing(KPartition *partition, bool *whileMounted);
/// Check whether the add-on supports resizing children of this partition. //! Check whether the add-on supports resizing children of this partition.
virtual bool SupportsResizingChild(KPartition *child); virtual bool SupportsResizingChild(KPartition *child);
/// Check whether the add-on supports moving this partition. //! Check whether the add-on supports moving this partition.
virtual bool SupportsMoving(KPartition *partition, bool *isNoOp); virtual bool SupportsMoving(KPartition *partition, bool *isNoOp);
/// Check whether the add-on supports moving children of this partition. //! Check whether the add-on supports moving children of this partition.
virtual bool SupportsMovingChild(KPartition *child); virtual bool SupportsMovingChild(KPartition *child);
/// Check whether the add-on supports setting name of this partition. //! Check whether the add-on supports setting name of this partition.
virtual bool SupportsSettingName(KPartition *partition); virtual bool SupportsSettingName(KPartition *partition);
/// Check whether the add-on supports setting name to content of this partition. //! Check whether the add-on supports setting name to content of this partition.
virtual bool SupportsSettingContentName(KPartition *partition, virtual bool SupportsSettingContentName(KPartition *partition,
bool *whileMounted); bool *whileMounted);
/// Check whether the add-on supports setting type of this partition. //! Check whether the add-on supports setting type of this partition.
virtual bool SupportsSettingType(KPartition *partition); virtual bool SupportsSettingType(KPartition *partition);
/// Check whether the add-on supports setting parameters of this partition. //! Check whether the add-on supports setting parameters of this partition.
virtual bool SupportsSettingParameters(KPartition *partition); virtual bool SupportsSettingParameters(KPartition *partition);
/// Check whether the add-on supports setting parameters to content of this partition. //! Check whether the add-on supports setting parameters to content of this partition.
virtual bool SupportsSettingContentParameters(KPartition *partition, virtual bool SupportsSettingContentParameters(KPartition *partition,
bool *whileMounted); bool *whileMounted);
/// Check whether the add-on supports initializing this partition. //! Check whether the add-on supports initializing this partition.
virtual bool SupportsInitializing(KPartition *partition); virtual bool SupportsInitializing(KPartition *partition);
/// Check whether the add-on supports initializing a child of this partition. //! Check whether the add-on supports initializing a child of this partition.
virtual bool SupportsInitializingChild(KPartition *child, virtual bool SupportsInitializingChild(KPartition *child,
const char *diskSystem); const char *diskSystem);
/// Check whether the add-on supports creating children of this partition. //! Check whether the add-on supports creating children of this partition.
virtual bool SupportsCreatingChild(KPartition *partition); virtual bool SupportsCreatingChild(KPartition *partition);
/// Check whether the add-on supports deleting children of this partition. //! Check whether the add-on supports deleting children of this partition.
virtual bool SupportsDeletingChild(KPartition *child); virtual bool SupportsDeletingChild(KPartition *child);
/// Check whether the add-on is a subsystem for a given partition. //! Check whether the add-on is a subsystem for a given partition.
virtual bool IsSubSystemFor(KPartition *partition); virtual bool IsSubSystemFor(KPartition *partition);
/// Validates parameters for resizing a partition //! Validates parameters for resizing a partition
virtual bool ValidateResize(KPartition *partition, off_t *size); virtual bool ValidateResize(KPartition *partition, off_t *size);
/// Validates parameters for resizing a child partition //! Validates parameters for resizing a child partition
virtual bool ValidateResizeChild(KPartition *child, off_t *size); virtual bool ValidateResizeChild(KPartition *child, off_t *size);
/// Validates parameters for moving a partition //! Validates parameters for moving a partition
virtual bool ValidateMove(KPartition *partition, off_t *start); virtual bool ValidateMove(KPartition *partition, off_t *start);
/// Validates parameters for moving a child partition //! Validates parameters for moving a child partition
virtual bool ValidateMoveChild(KPartition *child, off_t *start); virtual bool ValidateMoveChild(KPartition *child, off_t *start);
/// Validates parameters for setting name of a partition //! Validates parameters for setting name of a partition
virtual bool ValidateSetName(KPartition *partition, char *name); virtual bool ValidateSetName(KPartition *partition, char *name);
/// Validates parameters for setting name to content of a partition //! Validates parameters for setting name to content of a partition
virtual bool ValidateSetContentName(KPartition *partition, char *name); virtual bool ValidateSetContentName(KPartition *partition, char *name);
/// Validates parameters for setting type of a partition //! Validates parameters for setting type of a partition
virtual bool ValidateSetType(KPartition *partition, const char *type); virtual bool ValidateSetType(KPartition *partition, const char *type);
/// Validates parameters for setting parameters of a partition //! Validates parameters for setting parameters of a partition
virtual bool ValidateSetParameters(KPartition *partition, virtual bool ValidateSetParameters(KPartition *partition,
const char *parameters); const char *parameters);
/// Validates parameters for setting parameters to content of a partition //! Validates parameters for setting parameters to content of a partition
virtual bool ValidateSetContentParameters(KPartition *parameters, virtual bool ValidateSetContentParameters(KPartition *parameters,
const char *parameters); const char *parameters);
/// Validates parameters for initializing a partition //! Validates parameters for initializing a partition
virtual bool ValidateInitialize(KPartition *partition, char *name, virtual bool ValidateInitialize(KPartition *partition, char *name,
const char *parameters); const char *parameters);
/// Validates parameters for creating child of a partition //! Validates parameters for creating child of a partition
virtual bool ValidateCreateChild(KPartition *partition, off_t *start, virtual bool ValidateCreateChild(KPartition *partition, off_t *start,
off_t *size, const char *type, off_t *size, const char *type,
const char *parameters, int32 *index); const char *parameters, int32 *index);
/// Counts partitionable spaces on a partition //! Counts partitionable spaces on a partition
virtual int32 CountPartitionableSpaces(KPartition *partition); virtual int32 CountPartitionableSpaces(KPartition *partition);
/// Retrieves a list of partitionable spaces on a partition //! Retrieves a list of partitionable spaces on a partition
virtual status_t GetPartitionableSpaces(KPartition *partition, virtual status_t GetPartitionableSpaces(KPartition *partition,
partitionable_space_data *buffer, partitionable_space_data *buffer,
int32 count, int32 count,
int32 *actualCount = NULL); int32 *actualCount = NULL);
/// Iterates through supported partition types //! Iterates through supported partition types
virtual status_t GetNextSupportedType(KPartition *partition, int32 *cookie, virtual status_t GetNextSupportedType(KPartition *partition, int32 *cookie,
char *type); char *type);
/// Translates the "pretty" content type to an internal type //! Translates the "pretty" content type to an internal type
virtual status_t GetTypeForContentType(const char *contentType, virtual status_t GetTypeForContentType(const char *contentType,
char *type); char *type);
// Shadow partition modification // Shadow partition modification
/// Calls for additional modifications when shadow partition is changed //! Calls for additional modifications when shadow partition is changed
virtual status_t ShadowPartitionChanged(KPartition *partition, virtual status_t ShadowPartitionChanged(KPartition *partition,
uint32 operation); uint32 operation);
// Writing // Writing
/// Repairs a partition //! Repairs a partition
virtual status_t Repair(KPartition *partition, bool checkOnly, virtual status_t Repair(KPartition *partition, bool checkOnly,
KDiskDeviceJob *job); KDiskDeviceJob *job);
/// Resizes a partition //! Resizes a partition
virtual status_t Resize(KPartition *partition, off_t size, virtual status_t Resize(KPartition *partition, off_t size,
KDiskDeviceJob *job); KDiskDeviceJob *job);
/// Resizes child of a partition //! Resizes child of a partition
virtual status_t ResizeChild(KPartition *child, off_t size, virtual status_t ResizeChild(KPartition *child, off_t size,
KDiskDeviceJob *job); KDiskDeviceJob *job);
/// Moves a partition //! Moves a partition
virtual status_t Move(KPartition *partition, off_t offset, virtual status_t Move(KPartition *partition, off_t offset,
KDiskDeviceJob *job); KDiskDeviceJob *job);
/// Moves child of a partition //! Moves child of a partition
virtual status_t MoveChild(KPartition *child, off_t offset, virtual status_t MoveChild(KPartition *child, off_t offset,
KDiskDeviceJob *job); KDiskDeviceJob *job);
/// Sets name to a partition //! Sets name of a partition
virtual status_t SetName(KPartition *partition, char *name, virtual status_t SetName(KPartition *partition, char *name,
KDiskDeviceJob *job); KDiskDeviceJob *job);
/// Sets name to content of a partition //! Sets name of the content of a partition
virtual status_t SetContentName(KPartition *partition, char *name, virtual status_t SetContentName(KPartition *partition, char *name,
KDiskDeviceJob *job); KDiskDeviceJob *job);
/// Sets type of a partition //! Sets type of a partition
virtual status_t SetType(KPartition *partition, char *type, virtual status_t SetType(KPartition *partition, char *type,
KDiskDeviceJob *job); KDiskDeviceJob *job);
/// Sets parameters of a partition //! Sets parameters of a partition
virtual status_t SetParameters(KPartition *partition, virtual status_t SetParameters(KPartition *partition,
const char *parameters, const char *parameters,
KDiskDeviceJob *job); KDiskDeviceJob *job);
/// Sets parameters to content of a partition //! Sets parameters to content of a partition
virtual status_t SetContentParameters(KPartition *partition, virtual status_t SetContentParameters(KPartition *partition,
const char *parameters, const char *parameters,
KDiskDeviceJob *job); KDiskDeviceJob *job);
/// Creates a child partition //! Creates a child partition
virtual status_t CreateChild(KPartition *partition, off_t offset, virtual status_t CreateChild(KPartition *partition, off_t offset,
off_t size, const char *type, off_t size, const char *type,
const char *parameters, KDiskDeviceJob *job, const char *parameters, KDiskDeviceJob *job,
KPartition **child = NULL, KPartition **child = NULL,
partition_id childID = -1); partition_id childID = -1);
/// Deletes a child partition //! Deletes a child partition
virtual status_t DeleteChild(KPartition *child, KDiskDeviceJob *job); virtual status_t DeleteChild(KPartition *child, KDiskDeviceJob *job);
/// Initializes a partition with this partitioning system //! Initializes a partition with this partitioning system
virtual status_t Initialize(KPartition *partition, const char *name, virtual status_t Initialize(KPartition *partition, const char *name,
const char *parameters, KDiskDeviceJob *job); const char *parameters, KDiskDeviceJob *job);
@@ -1,5 +1,10 @@
// KPartition.h /*
* Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold <[email protected]>
*/
#ifndef _K_DISK_DEVICE_PHYSICAL_PARTITION_H #ifndef _K_DISK_DEVICE_PHYSICAL_PARTITION_H
#define _K_DISK_DEVICE_PHYSICAL_PARTITION_H #define _K_DISK_DEVICE_PHYSICAL_PARTITION_H
@@ -12,7 +17,7 @@ class KDiskDevice;
class KDiskSystem; class KDiskSystem;
class KShadowPartition; class KShadowPartition;
/// \brief Class representing an existing partition. //! \brief Class representing an existing partition.
class KPhysicalPartition : public KPartition { class KPhysicalPartition : public KPartition {
public: public:
KPhysicalPartition(partition_id id = -1); KPhysicalPartition(partition_id id = -1);
@@ -1,5 +1,10 @@
// KPartition.h /*
* Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold <[email protected]>
*/
#ifndef _K_DISK_DEVICE_SHADOW_PARTITION_H #ifndef _K_DISK_DEVICE_SHADOW_PARTITION_H
#define _K_DISK_DEVICE_SHADOW_PARTITION_H #define _K_DISK_DEVICE_SHADOW_PARTITION_H
@@ -11,9 +16,10 @@ namespace DiskDevice {
class KPhysicalPartition; class KPhysicalPartition;
/// \brief Class representing a shadow of an existing partition. /*! \brief Class representing a shadow of an existing partition.
///
/// See \ref path_kernel_structures for more information. See \ref path_kernel_structures for more information.
*/
class KShadowPartition : public KPartition, private KPartitionListener { class KShadowPartition : public KPartition, private KPartitionListener {
public: public:
KShadowPartition(KPhysicalPartition *physicalPartition); KShadowPartition(KPhysicalPartition *physicalPartition);
@@ -1,4 +1,11 @@
// KDiskDeviceJob.cpp /*
* Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold <[email protected]>
* Lubos Kulic <[email protected]>
*/
#include <stdio.h> #include <stdio.h>
@@ -14,6 +21,17 @@
#define OUT dprintf #define OUT dprintf
// constructor // constructor
/**
Creates a new job
\param type actual type of the job (see DiskDeviceDefs.h for details)
\param partitionID the partition/device on which the action should be
executed
\param scopeID partition/device which is the highest in the hierarchy (i.e.
closest to the root) that can be affected by the action - every
descendant of this partition is marked busy and all ancestors are marked
descendant-busy
*/
KDiskDeviceJob::KDiskDeviceJob(uint32 type, partition_id partitionID, KDiskDeviceJob::KDiskDeviceJob(uint32 type, partition_id partitionID,
partition_id scopeID) partition_id scopeID)
: fID(_NextID()), : fID(_NextID()),
@@ -233,6 +251,23 @@ KDiskDeviceJob::GetProgressInfo(disk_device_job_progress_info *info)
return B_OK; return B_OK;
} }
/** \fn status_t KDiskDevice::Do()
Do the actual work of the job.
- is supposed to be implemented in descendants
- doesn't have any parameter - every operation needs different ones
-> they're passed to the constructor
- the implementations will
- check the parameters given in constructor (e.g. if given partition
exists...)
- check whether the partition has needed disk system (its own or
parent - depends on the operation)
- using the disk system, validate the operation for given params
- finally execute the action
\return B_OK when everything went OK, some error otherwise
*/
// _NextID // _NextID
disk_job_id disk_job_id
KDiskDeviceJob::_NextID() KDiskDeviceJob::_NextID()
@@ -244,16 +279,29 @@ KDiskDeviceJob::_NextID()
disk_job_id KDiskDeviceJob::fNextID = 0; disk_job_id KDiskDeviceJob::fNextID = 0;
// IsNotBusyVisitor /**
bool KDiskDeviceJob::IsNotBusyVisitor::VisitPre( KPartition * partition ) { Checks if there's any descendant which is not busy/descendant-busy.
return !(partition->IsBusy() || partition->IsDescendantBusy());
}
- the condition of busy descendant is common for many disk device operations ->
many jobs can use this
bool KDiskDeviceJob::isPartitionNotBusy( KPartition * partition ) { \param partition the root of checked subtree of the whole partition
hierarchy
*/
bool
KDiskDeviceJob::IsPartitionNotBusy(KPartition* partition)
{
if( !partition ) { if( !partition ) {
return false; return false;
} }
return partition->VisitEachDescendant(&fNotBusyVisitor); struct IsNotBusyVisitor : KPartitionVisitor {
virtual bool VisitPre(KPartition* partition)
{
return !(partition->IsBusy() || partition->IsDescendantBusy());
}
};
IsNotBusyVisitor notBusyVisitor;
return partition->VisitEachDescendant(&notBusyVisitor);
} }
@@ -1,11 +1,12 @@
/* /*
* Copyright 2004-2006, Haiku, Inc. All rights reserved. * Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
* Copyright 2003-2004, Ingo Weinhold, [email protected]. All rights reserved.
*
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold <[email protected]>
* Lubos Kulic <[email protected]>
*/ */
#include <util/kernel_cpp.h> #include <util/kernel_cpp.h>
#include "KDiskDeviceJob.h" #include "KDiskDeviceJob.h"
@@ -24,6 +25,7 @@
#include "KSetTypeJob.h" #include "KSetTypeJob.h"
#include "KUninitializeJob.h" #include "KUninitializeJob.h"
using namespace std; using namespace std;
@@ -61,8 +63,9 @@ KDiskDeviceJobFactory::CreateResizeJob(partition_id parentID,
KDiskDeviceJob * KDiskDeviceJob *
KDiskDeviceJobFactory::CreateMoveJob(partition_id parentID, partition_id partitionID, KDiskDeviceJobFactory::CreateMoveJob(partition_id parentID,
off_t offset, const partition_id *contentsToMove, int32 contentsToMoveCount) partition_id partitionID, off_t offset, const partition_id *contentsToMove,
int32 contentsToMoveCount)
{ {
// TODO: this is wierd, what in hell are contentsToMove etc? // TODO: this is wierd, what in hell are contentsToMove etc?
return new(nothrow) KMoveJob(parentID, partitionID, offset); return new(nothrow) KMoveJob(parentID, partitionID, offset);
@@ -113,7 +116,8 @@ KDiskDeviceJob *
KDiskDeviceJobFactory::CreateInitializeJob(partition_id partitionID, KDiskDeviceJobFactory::CreateInitializeJob(partition_id partitionID,
disk_system_id diskSystemID, const char *name, const char *parameters) disk_system_id diskSystemID, const char *name, const char *parameters)
{ {
return new(nothrow) KInitializeJob(partitionID, diskSystemID, name, parameters); return new(nothrow) KInitializeJob(partitionID, diskSystemID, name,
parameters);
} }
@@ -129,7 +133,8 @@ KDiskDeviceJobFactory::CreateCreateChildJob(partition_id partitionID,
partition_id childID, off_t offset, off_t size, const char *type, partition_id childID, off_t offset, off_t size, const char *type,
const char *parameters) const char *parameters)
{ {
return new(nothrow) KCreateChildJob(partitionID, childID, offset, size, type, parameters); return new(nothrow) KCreateChildJob(partitionID, childID, offset, size,
type, parameters);
} }
@@ -1,3 +1,12 @@
/*
* Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold <[email protected]>
* Lubos Kulic <[email protected]>
*/
/** \file KPartitioningSystem.cpp /** \file KPartitioningSystem.cpp
* *
* \brief Implementation of \ref KPartitioningSystem class * \brief Implementation of \ref KPartitioningSystem class
@@ -15,6 +24,7 @@
#include <KPartition.h> #include <KPartition.h>
#include <KPartitioningSystem.h> #include <KPartitioningSystem.h>
// constructor // constructor
KPartitioningSystem::KPartitioningSystem(const char *name) KPartitioningSystem::KPartitioningSystem(const char *name)
: KDiskSystem(name), : KDiskSystem(name),
@@ -44,6 +54,7 @@ KPartitioningSystem::Init()
} }
// Identify // Identify
//! Try to identify a given partition
float float
KPartitioningSystem::Identify(KPartition *partition, void **cookie) KPartitioningSystem::Identify(KPartition *partition, void **cookie)
{ {
@@ -59,6 +70,7 @@ KPartitioningSystem::Identify(KPartition *partition, void **cookie)
} }
// Scan // Scan
//! Scan the partition
status_t status_t
KPartitioningSystem::Scan(KPartition *partition, void *cookie) KPartitioningSystem::Scan(KPartition *partition, void *cookie)
{ {
@@ -108,6 +120,7 @@ KPartitioningSystem::FreeContentCookie(KPartition *partition)
} }
// SupportsRepairing // SupportsRepairing
//! Check whether the add-on supports repairing this partition.
bool bool
KPartitioningSystem::SupportsRepairing(KPartition *partition, bool checkOnly, KPartitioningSystem::SupportsRepairing(KPartition *partition, bool checkOnly,
bool *whileMounted) bool *whileMounted)
@@ -126,9 +139,9 @@ KPartitioningSystem::SupportsRepairing(KPartition *partition, bool checkOnly,
} }
// SupportsResizing // SupportsResizing
//! Check whether the add-on supports resizing this partition.
bool bool
KPartitioningSystem::SupportsResizing(KPartition *partition, KPartitioningSystem::SupportsResizing(KPartition *partition, bool *whileMounted)
bool *whileMounted)
{ {
bool _whileMounted = false; bool _whileMounted = false;
if (!whileMounted) if (!whileMounted)
@@ -143,17 +156,18 @@ KPartitioningSystem::SupportsResizing(KPartition *partition,
} }
// SupportsResizingChild // SupportsResizingChild
//! Check whether the add-on supports resizing children of this partition.
bool bool
KPartitioningSystem::SupportsResizingChild(KPartition *child) KPartitioningSystem::SupportsResizingChild(KPartition *child)
{ {
return (child && child->Parent() && child->ParentDiskSystem() == this return (child && child->Parent() && child->ParentDiskSystem() == this
&& fModule && fModule->supports_resizing_child && fModule && fModule->supports_resizing_child
&& fModule->supports_resizing_child( && fModule->supports_resizing_child(child->Parent()->PartitionData(),
child->Parent()->PartitionData(),
child->PartitionData())); child->PartitionData()));
} }
// SupportsMoving // SupportsMoving
//! Check whether the add-on supports moving this partition.
bool bool
KPartitioningSystem::SupportsMoving(KPartition *partition, bool *isNoOp) KPartitioningSystem::SupportsMoving(KPartition *partition, bool *isNoOp)
{ {
@@ -168,6 +182,7 @@ KPartitioningSystem::SupportsMoving(KPartition *partition, bool *isNoOp)
} }
// SupportsMovingChild // SupportsMovingChild
//! Check whether the add-on supports moving children of this partition.
bool bool
KPartitioningSystem::SupportsMovingChild(KPartition *child) KPartitioningSystem::SupportsMovingChild(KPartition *child)
{ {
@@ -178,6 +193,7 @@ KPartitioningSystem::SupportsMovingChild(KPartition *child)
} }
// SupportsSettingName // SupportsSettingName
//! Check whether the add-on supports setting name of this partition.
bool bool
KPartitioningSystem::SupportsSettingName(KPartition *partition) KPartitioningSystem::SupportsSettingName(KPartition *partition)
{ {
@@ -187,6 +203,9 @@ KPartitioningSystem::SupportsSettingName(KPartition *partition)
} }
// SupportsSettingContentName // SupportsSettingContentName
/*! Check whether the add-on supports setting name of the content of this
partition.
*/
bool bool
KPartitioningSystem::SupportsSettingContentName(KPartition *partition, KPartitioningSystem::SupportsSettingContentName(KPartition *partition,
bool *whileMounted) bool *whileMounted)
@@ -205,6 +224,7 @@ KPartitioningSystem::SupportsSettingContentName(KPartition *partition,
} }
// SupportsSettingType // SupportsSettingType
//! Check whether the add-on supports setting type of this partition.
bool bool
KPartitioningSystem::SupportsSettingType(KPartition *partition) KPartitioningSystem::SupportsSettingType(KPartition *partition)
{ {
@@ -214,16 +234,19 @@ KPartitioningSystem::SupportsSettingType(KPartition *partition)
} }
// SupportsSettingParameters // SupportsSettingParameters
//! Check whether the add-on supports setting parameters of this partition.
bool bool
KPartitioningSystem::SupportsSettingParameters(KPartition *partition) KPartitioningSystem::SupportsSettingParameters(KPartition *partition)
{ {
return (partition && partition->ParentDiskSystem() == this return (partition && partition->ParentDiskSystem() == this
&& fModule && fModule->supports_setting_parameters && fModule && fModule->supports_setting_parameters
&& fModule->supports_setting_parameters( && fModule->supports_setting_parameters(partition->PartitionData()));
partition->PartitionData()));
} }
// SupportsSettingContentParameters // SupportsSettingContentParameters
/*! Check whether the add-on supports setting parameters of the content of this
partition.
*/
bool bool
KPartitioningSystem::SupportsSettingContentParameters(KPartition *partition, KPartitioningSystem::SupportsSettingContentParameters(KPartition *partition,
bool *whileMounted) bool *whileMounted)
@@ -242,6 +265,7 @@ KPartitioningSystem::SupportsSettingContentParameters(KPartition *partition,
} }
// SupportsInitializing // SupportsInitializing
//! Check whether the add-on supports initializing this partition.
bool bool
KPartitioningSystem::SupportsInitializing(KPartition *partition) KPartitioningSystem::SupportsInitializing(KPartition *partition)
{ {
@@ -250,6 +274,7 @@ KPartitioningSystem::SupportsInitializing(KPartition *partition)
} }
// SupportsInitializingChild // SupportsInitializingChild
//! Check whether the add-on supports initializing a child of this partition.
bool bool
KPartitioningSystem::SupportsInitializingChild(KPartition *child, KPartitioningSystem::SupportsInitializingChild(KPartition *child,
const char *diskSystem) const char *diskSystem)
@@ -261,6 +286,7 @@ KPartitioningSystem::SupportsInitializingChild(KPartition *child,
} }
// SupportsCreatingChild // SupportsCreatingChild
//! Check whether the add-on supports creating children of this partition.
bool bool
KPartitioningSystem::SupportsCreatingChild(KPartition *partition) KPartitioningSystem::SupportsCreatingChild(KPartition *partition)
{ {
@@ -270,16 +296,18 @@ KPartitioningSystem::SupportsCreatingChild(KPartition *partition)
} }
// SupportsDeletingChild // SupportsDeletingChild
//! Check whether the add-on supports deleting children of this partition.
bool bool
KPartitioningSystem::SupportsDeletingChild(KPartition *child) KPartitioningSystem::SupportsDeletingChild(KPartition *child)
{ {
return (child && child->Parent() && child->ParentDiskSystem() == this return (child && child->Parent() && child->ParentDiskSystem() == this
&& fModule && fModule->supports_deleting_child && fModule && fModule->supports_deleting_child
&& fModule->supports_deleting_child( && fModule->supports_deleting_child(child->Parent()->PartitionData(),
child->Parent()->PartitionData(), child->PartitionData())); child->PartitionData()));
} }
// IsSubSystemFor // IsSubSystemFor
//! Check whether the add-on is a subsystem for a given partition.
bool bool
KPartitioningSystem::IsSubSystemFor(KPartition *partition) KPartitioningSystem::IsSubSystemFor(KPartition *partition)
{ {
@@ -288,6 +316,7 @@ KPartitioningSystem::IsSubSystemFor(KPartition *partition)
} }
// ValidateResize // ValidateResize
//! Validates parameters for resizing a partition
bool bool
KPartitioningSystem::ValidateResize(KPartition *partition, off_t *size) KPartitioningSystem::ValidateResize(KPartition *partition, off_t *size)
{ {
@@ -297,6 +326,7 @@ KPartitioningSystem::ValidateResize(KPartition *partition, off_t *size)
} }
// ValidateResizeChild // ValidateResizeChild
//! Validates parameters for resizing a child partition
bool bool
KPartitioningSystem::ValidateResizeChild(KPartition *child, off_t *size) KPartitioningSystem::ValidateResizeChild(KPartition *child, off_t *size)
{ {
@@ -308,6 +338,7 @@ KPartitioningSystem::ValidateResizeChild(KPartition *child, off_t *size)
} }
// ValidateMove // ValidateMove
//! Validates parameters for moving a partition
bool bool
KPartitioningSystem::ValidateMove(KPartition *partition, off_t *start) KPartitioningSystem::ValidateMove(KPartition *partition, off_t *start)
{ {
@@ -317,6 +348,7 @@ KPartitioningSystem::ValidateMove(KPartition *partition, off_t *start)
} }
// ValidateMoveChild // ValidateMoveChild
//! Validates parameters for moving a child partition
bool bool
KPartitioningSystem::ValidateMoveChild(KPartition *child, off_t *start) KPartitioningSystem::ValidateMoveChild(KPartition *child, off_t *start)
{ {
@@ -328,6 +360,7 @@ KPartitioningSystem::ValidateMoveChild(KPartition *child, off_t *start)
} }
// ValidateSetName // ValidateSetName
//! Validates parameters for setting name of a partition
bool bool
KPartitioningSystem::ValidateSetName(KPartition *partition, char *name) KPartitioningSystem::ValidateSetName(KPartition *partition, char *name)
{ {
@@ -338,6 +371,7 @@ KPartitioningSystem::ValidateSetName(KPartition *partition, char *name)
} }
// ValidateSetContentName // ValidateSetContentName
//! Validates parameters for setting name of the content of a partition
bool bool
KPartitioningSystem::ValidateSetContentName(KPartition *partition, char *name) KPartitioningSystem::ValidateSetContentName(KPartition *partition, char *name)
{ {
@@ -348,6 +382,7 @@ KPartitioningSystem::ValidateSetContentName(KPartition *partition, char *name)
} }
// ValidateSetType // ValidateSetType
//! Validates parameters for setting type of a partition
bool bool
KPartitioningSystem::ValidateSetType(KPartition *partition, const char *type) KPartitioningSystem::ValidateSetType(KPartition *partition, const char *type)
{ {
@@ -357,6 +392,7 @@ KPartitioningSystem::ValidateSetType(KPartition *partition, const char *type)
} }
// ValidateSetParameters // ValidateSetParameters
//! Validates parameters for setting parameters of a partition
bool bool
KPartitioningSystem::ValidateSetParameters(KPartition *partition, KPartitioningSystem::ValidateSetParameters(KPartition *partition,
const char *parameters) const char *parameters)
@@ -368,6 +404,7 @@ KPartitioningSystem::ValidateSetParameters(KPartition *partition,
} }
// ValidateSetContentParameters // ValidateSetContentParameters
//! Validates parameters for setting parameters of the content of a partition
bool bool
KPartitioningSystem::ValidateSetContentParameters(KPartition *partition, KPartitioningSystem::ValidateSetContentParameters(KPartition *partition,
const char *parameters) const char *parameters)
@@ -379,6 +416,7 @@ KPartitioningSystem::ValidateSetContentParameters(KPartition *partition,
} }
// ValidateInitialize // ValidateInitialize
//! Validates parameters for initializing a partition
bool bool
KPartitioningSystem::ValidateInitialize(KPartition *partition, char *name, KPartitioningSystem::ValidateInitialize(KPartition *partition, char *name,
const char *parameters) const char *parameters)
@@ -389,10 +427,10 @@ KPartitioningSystem::ValidateInitialize(KPartition *partition, char *name,
} }
// ValidateCreateChild // ValidateCreateChild
//! Validates parameters for creating child of a partition
bool bool
KPartitioningSystem::ValidateCreateChild(KPartition *partition, off_t *start, KPartitioningSystem::ValidateCreateChild(KPartition *partition, off_t *start,
off_t *size, const char *type, off_t *size, const char *type, const char *parameters, int32 *index)
const char *parameters, int32 *index)
{ {
int32 _index = 0; int32 _index = 0;
if (!index) if (!index)
@@ -400,12 +438,12 @@ KPartitioningSystem::ValidateCreateChild(KPartition *partition, off_t *start,
return (partition && start && size && type return (partition && start && size && type
&& partition->DiskSystem() == this && fModule && partition->DiskSystem() == this && fModule
&& fModule->validate_create_child && fModule->validate_create_child
&& fModule->validate_create_child(partition->PartitionData(), && fModule->validate_create_child(partition->PartitionData(), start,
start, size, type, parameters, size, type, parameters, index));
index));
} }
// CountPartitionableSpaces // CountPartitionableSpaces
//! Counts partitionable spaces on a partition
int32 int32
KPartitioningSystem::CountPartitionableSpaces(KPartition *partition) KPartitioningSystem::CountPartitionableSpaces(KPartition *partition)
{ {
@@ -422,10 +460,10 @@ KPartitioningSystem::CountPartitionableSpaces(KPartition *partition)
} }
// GetPartitionableSpaces // GetPartitionableSpaces
//! Retrieves a list of partitionable spaces on a partition
status_t status_t
KPartitioningSystem::GetPartitionableSpaces(KPartition *partition, KPartitioningSystem::GetPartitionableSpaces(KPartition *partition,
partitionable_space_data *buffer, partitionable_space_data *buffer, int32 count, int32 *actualCount)
int32 count, int32 *actualCount)
{ {
if (!partition || partition->DiskSystem() != this || count > 0 && !buffer if (!partition || partition->DiskSystem() != this || count > 0 && !buffer
|| !actualCount || !fModule) { || !actualCount || !fModule) {
@@ -440,6 +478,7 @@ KPartitioningSystem::GetPartitionableSpaces(KPartition *partition,
} }
// GetNextSupportedType // GetNextSupportedType
//! Iterates through supported partition types
status_t status_t
KPartitioningSystem::GetNextSupportedType(KPartition *partition, int32 *cookie, KPartitioningSystem::GetNextSupportedType(KPartition *partition, int32 *cookie,
char *type) char *type)
@@ -455,6 +494,7 @@ KPartitioningSystem::GetNextSupportedType(KPartition *partition, int32 *cookie,
} }
// GetTypeForContentType // GetTypeForContentType
//! Translates the "pretty" content type to an internal type
status_t status_t
KPartitioningSystem::GetTypeForContentType(const char *contentType, char *type) KPartitioningSystem::GetTypeForContentType(const char *contentType, char *type)
{ {
@@ -466,6 +506,7 @@ KPartitioningSystem::GetTypeForContentType(const char *contentType, char *type)
} }
// ShadowPartitionChanged // ShadowPartitionChanged
//! Calls for additional modifications when shadow partition is changed
status_t status_t
KPartitioningSystem::ShadowPartitionChanged(KPartition *partition, KPartitioningSystem::ShadowPartitionChanged(KPartition *partition,
uint32 operation) uint32 operation)
@@ -482,6 +523,7 @@ KPartitioningSystem::ShadowPartitionChanged(KPartition *partition,
} }
// Repair // Repair
//! Repairs a partition
status_t status_t
KPartitioningSystem::Repair(KPartition *partition, bool checkOnly, KPartitioningSystem::Repair(KPartition *partition, bool checkOnly,
KDiskDeviceJob *job) KDiskDeviceJob *job)
@@ -491,6 +533,7 @@ KPartitioningSystem::Repair(KPartition *partition, bool checkOnly,
} }
// Resize // Resize
//! Resizes a partition
status_t status_t
KPartitioningSystem::Resize(KPartition *partition, off_t size, KPartitioningSystem::Resize(KPartition *partition, off_t size,
KDiskDeviceJob *job) KDiskDeviceJob *job)
@@ -500,6 +543,7 @@ KPartitioningSystem::Resize(KPartition *partition, off_t size,
return B_BAD_VALUE; return B_BAD_VALUE;
if (!fModule->resize) if (!fModule->resize)
return B_ENTRY_NOT_FOUND; return B_ENTRY_NOT_FOUND;
// lock partition and open partition device // lock partition and open partition device
KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KDiskDeviceManager *manager = KDiskDeviceManager::Default();
KPartition *_partition = manager->WriteLockPartition(partition->ID()); KPartition *_partition = manager->WriteLockPartition(partition->ID());
@@ -516,14 +560,17 @@ KPartitioningSystem::Resize(KPartition *partition, off_t size,
if (result != B_OK) if (result != B_OK)
return result; return result;
} }
// let the module do its job // let the module do its job
status_t result = fModule->resize(fd, partition->ID(), size, job->ID()); status_t result = fModule->resize(fd, partition->ID(), size, job->ID());
// cleanup and return // cleanup and return
close(fd); close(fd);
return result; return result;
} }
// ResizeChild // ResizeChild
//! Resizes child of a partition
status_t status_t
KPartitioningSystem::ResizeChild(KPartition *child, off_t size, KPartitioningSystem::ResizeChild(KPartition *child, off_t size,
KDiskDeviceJob *job) KDiskDeviceJob *job)
@@ -533,6 +580,7 @@ KPartitioningSystem::ResizeChild(KPartition *child, off_t size,
return B_BAD_VALUE; return B_BAD_VALUE;
if (!fModule->resize_child) if (!fModule->resize_child)
return B_ENTRY_NOT_FOUND; return B_ENTRY_NOT_FOUND;
// lock partition and open (parent) partition device // lock partition and open (parent) partition device
KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KDiskDeviceManager *manager = KDiskDeviceManager::Default();
KPartition *_partition = manager->WriteLockPartition(child->ID()); KPartition *_partition = manager->WriteLockPartition(child->ID());
@@ -550,14 +598,17 @@ KPartitioningSystem::ResizeChild(KPartition *child, off_t size,
if (result != B_OK) if (result != B_OK)
return result; return result;
} }
// let the module do its job // let the module do its job
status_t result = fModule->resize_child(fd, child->ID(), size, job->ID()); status_t result = fModule->resize_child(fd, child->ID(), size, job->ID());
// cleanup and return // cleanup and return
close(fd); close(fd);
return result; return result;
} }
// Move // Move
//! Moves a partition
status_t status_t
KPartitioningSystem::Move(KPartition *partition, off_t offset, KPartitioningSystem::Move(KPartition *partition, off_t offset,
KDiskDeviceJob *job) KDiskDeviceJob *job)
@@ -567,6 +618,7 @@ KPartitioningSystem::Move(KPartition *partition, off_t offset,
return B_BAD_VALUE; return B_BAD_VALUE;
if (!fModule->move) if (!fModule->move)
return B_ENTRY_NOT_FOUND; return B_ENTRY_NOT_FOUND;
// lock partition and open partition device // lock partition and open partition device
KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KDiskDeviceManager *manager = KDiskDeviceManager::Default();
KPartition *_partition = manager->WriteLockPartition(partition->ID()); KPartition *_partition = manager->WriteLockPartition(partition->ID());
@@ -583,14 +635,17 @@ KPartitioningSystem::Move(KPartition *partition, off_t offset,
if (result != B_OK) if (result != B_OK)
return result; return result;
} }
// let the module do its job // let the module do its job
status_t result = fModule->move(fd, partition->ID(), offset, job->ID()); status_t result = fModule->move(fd, partition->ID(), offset, job->ID());
// cleanup and return // cleanup and return
close(fd); close(fd);
return result; return result;
} }
// MoveChild // MoveChild
//! Moves child of a partition
status_t status_t
KPartitioningSystem::MoveChild(KPartition *child, off_t offset, KPartitioningSystem::MoveChild(KPartition *child, off_t offset,
KDiskDeviceJob *job) KDiskDeviceJob *job)
@@ -600,6 +655,7 @@ KPartitioningSystem::MoveChild(KPartition *child, off_t offset,
return B_BAD_VALUE; return B_BAD_VALUE;
if (!fModule->move_child) if (!fModule->move_child)
return B_ENTRY_NOT_FOUND; return B_ENTRY_NOT_FOUND;
// lock partition and open (parent) partition device // lock partition and open (parent) partition device
KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KDiskDeviceManager *manager = KDiskDeviceManager::Default();
KPartition *_partition = manager->WriteLockPartition(child->ID()); KPartition *_partition = manager->WriteLockPartition(child->ID());
@@ -617,14 +673,18 @@ KPartitioningSystem::MoveChild(KPartition *child, off_t offset,
if (result != B_OK) if (result != B_OK)
return result; return result;
} }
// let the module do its job // let the module do its job
status_t result = fModule->move_child(fd, child->Parent()->ID(), child->ID(), offset, job->ID()); status_t result = fModule->move_child(fd, child->Parent()->ID(),
child->ID(), offset, job->ID());
// cleanup and return // cleanup and return
close(fd); close(fd);
return result; return result;
} }
// SetName // SetName
//! Sets name of a partition
status_t status_t
KPartitioningSystem::SetName(KPartition *partition, char *name, KPartitioningSystem::SetName(KPartition *partition, char *name,
KDiskDeviceJob *job) KDiskDeviceJob *job)
@@ -634,6 +694,7 @@ KPartitioningSystem::SetName(KPartition *partition, char *name,
return B_BAD_VALUE; return B_BAD_VALUE;
if (!fModule->set_name) if (!fModule->set_name)
return B_ENTRY_NOT_FOUND; return B_ENTRY_NOT_FOUND;
// lock partition and open partition device // lock partition and open partition device
KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KDiskDeviceManager *manager = KDiskDeviceManager::Default();
KPartition *_partition = manager->WriteLockPartition(partition->ID()); KPartition *_partition = manager->WriteLockPartition(partition->ID());
@@ -650,14 +711,17 @@ KPartitioningSystem::SetName(KPartition *partition, char *name,
if (result != B_OK) if (result != B_OK)
return result; return result;
} }
// let the module do its job // let the module do its job
status_t result = fModule->set_name(fd, partition->ID(), name, job->ID()); status_t result = fModule->set_name(fd, partition->ID(), name, job->ID());
// cleanup and return // cleanup and return
close(fd); close(fd);
return result; return result;
} }
// SetContentName // SetContentName
//! Sets name of the content of a partition
status_t status_t
KPartitioningSystem::SetContentName(KPartition *partition, char *name, KPartitioningSystem::SetContentName(KPartition *partition, char *name,
KDiskDeviceJob *job) KDiskDeviceJob *job)
@@ -667,6 +731,7 @@ KPartitioningSystem::SetContentName(KPartition *partition, char *name,
return B_BAD_VALUE; return B_BAD_VALUE;
if (!fModule->set_content_name) if (!fModule->set_content_name)
return B_ENTRY_NOT_FOUND; return B_ENTRY_NOT_FOUND;
// lock partition and open partition device // lock partition and open partition device
KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KDiskDeviceManager *manager = KDiskDeviceManager::Default();
KPartition *_partition = manager->WriteLockPartition(partition->ID()); KPartition *_partition = manager->WriteLockPartition(partition->ID());
@@ -683,14 +748,18 @@ KPartitioningSystem::SetContentName(KPartition *partition, char *name,
if (result != B_OK) if (result != B_OK)
return result; return result;
} }
// let the module do its job // let the module do its job
status_t result = fModule->set_content_name(fd, partition->ID(), name, job->ID()); status_t result = fModule->set_content_name(fd, partition->ID(), name,
job->ID());
// cleanup and return // cleanup and return
close(fd); close(fd);
return result; return result;
} }
// SetType // SetType
//! Sets type of a partition
status_t status_t
KPartitioningSystem::SetType(KPartition *partition, char *type, KPartitioningSystem::SetType(KPartition *partition, char *type,
KDiskDeviceJob *job) KDiskDeviceJob *job)
@@ -700,6 +769,7 @@ KPartitioningSystem::SetType(KPartition *partition, char *type,
return B_BAD_VALUE; return B_BAD_VALUE;
if (!fModule->set_type) if (!fModule->set_type)
return B_ENTRY_NOT_FOUND; return B_ENTRY_NOT_FOUND;
// lock partition and open partition device // lock partition and open partition device
KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KDiskDeviceManager *manager = KDiskDeviceManager::Default();
KPartition *_partition = manager->WriteLockPartition(partition->ID()); KPartition *_partition = manager->WriteLockPartition(partition->ID());
@@ -716,14 +786,17 @@ KPartitioningSystem::SetType(KPartition *partition, char *type,
if (result != B_OK) if (result != B_OK)
return result; return result;
} }
// let the module do its job // let the module do its job
status_t result = fModule->set_type(fd, partition->ID(), type, job->ID()); status_t result = fModule->set_type(fd, partition->ID(), type, job->ID());
// cleanup and return // cleanup and return
close(fd); close(fd);
return result; return result;
} }
// SetParameters // SetParameters
//! Sets parameters of a partition
status_t status_t
KPartitioningSystem::SetParameters(KPartition *partition, KPartitioningSystem::SetParameters(KPartition *partition,
const char *parameters, KDiskDeviceJob *job) const char *parameters, KDiskDeviceJob *job)
@@ -733,6 +806,7 @@ KPartitioningSystem::SetParameters(KPartition *partition,
return B_BAD_VALUE; return B_BAD_VALUE;
if (!fModule->set_parameters) if (!fModule->set_parameters)
return B_ENTRY_NOT_FOUND; return B_ENTRY_NOT_FOUND;
// lock partition and open partition device // lock partition and open partition device
KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KDiskDeviceManager *manager = KDiskDeviceManager::Default();
KPartition *_partition = manager->WriteLockPartition(partition->ID()); KPartition *_partition = manager->WriteLockPartition(partition->ID());
@@ -749,24 +823,28 @@ KPartitioningSystem::SetParameters(KPartition *partition,
if (result != B_OK) if (result != B_OK)
return result; return result;
} }
// let the module do its job // let the module do its job
status_t result = fModule->set_parameters(fd, partition->ID(), parameters, job->ID()); status_t result = fModule->set_parameters(fd, partition->ID(), parameters,
job->ID());
// cleanup and return // cleanup and return
close(fd); close(fd);
return result; return result;
} }
// SetContentParameters // SetContentParameters
//! Sets parameters of the content of a partition
status_t status_t
KPartitioningSystem::SetContentParameters(KPartition *partition, KPartitioningSystem::SetContentParameters(KPartition *partition,
const char *parameters, const char *parameters, KDiskDeviceJob *job)
KDiskDeviceJob *job)
{ {
// check parameters // check parameters
if (!partition || !job || !parameters) if (!partition || !job || !parameters)
return B_BAD_VALUE; return B_BAD_VALUE;
if (!fModule->set_content_parameters) if (!fModule->set_content_parameters)
return B_ENTRY_NOT_FOUND; return B_ENTRY_NOT_FOUND;
// lock partition and open partition device // lock partition and open partition device
KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KDiskDeviceManager *manager = KDiskDeviceManager::Default();
KPartition *_partition = manager->WriteLockPartition(partition->ID()); KPartition *_partition = manager->WriteLockPartition(partition->ID());
@@ -783,14 +861,18 @@ KPartitioningSystem::SetContentParameters(KPartition *partition,
if (result != B_OK) if (result != B_OK)
return result; return result;
} }
// let the module do its job // let the module do its job
status_t result = fModule->set_content_parameters(fd, partition->ID(), parameters, job->ID()); status_t result = fModule->set_content_parameters(fd, partition->ID(),
parameters, job->ID());
// cleanup and return // cleanup and return
close(fd); close(fd);
return result; return result;
} }
// Initialize // Initialize
//! Initializes a partition with this partitioning system
status_t status_t
KPartitioningSystem::Initialize(KPartition *partition, const char *name, KPartitioningSystem::Initialize(KPartition *partition, const char *name,
const char *parameters, KDiskDeviceJob *job) const char *parameters, KDiskDeviceJob *job)
@@ -800,6 +882,7 @@ KPartitioningSystem::Initialize(KPartition *partition, const char *name,
return B_BAD_VALUE; return B_BAD_VALUE;
if (!fModule->initialize) if (!fModule->initialize)
return B_ENTRY_NOT_FOUND; return B_ENTRY_NOT_FOUND;
// lock partition and open partition device // lock partition and open partition device
KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KDiskDeviceManager *manager = KDiskDeviceManager::Default();
KPartition *_partition = manager->WriteLockPartition(partition->ID()); KPartition *_partition = manager->WriteLockPartition(partition->ID());
@@ -816,18 +899,21 @@ KPartitioningSystem::Initialize(KPartition *partition, const char *name,
if (result != B_OK) if (result != B_OK)
return result; return result;
} }
// let the module do its job // let the module do its job
status_t result = fModule->initialize(fd, partition->ID(), name, parameters, job->ID()); status_t result = fModule->initialize(fd, partition->ID(), name, parameters,
job->ID());
// cleanup and return // cleanup and return
close(fd); close(fd);
return result; return result;
} }
// CreateChild // CreateChild
//! Creates a child partition
status_t status_t
KPartitioningSystem::CreateChild(KPartition *partition, off_t offset, KPartitioningSystem::CreateChild(KPartition *partition, off_t offset,
off_t size, const char *type, off_t size, const char *type, const char *parameters, KDiskDeviceJob *job,
const char *parameters, KDiskDeviceJob *job,
KPartition **child, partition_id childID) KPartition **child, partition_id childID)
{ {
// check parameters // check parameters
@@ -835,6 +921,7 @@ KPartitioningSystem::CreateChild(KPartition *partition, off_t offset,
return B_BAD_VALUE; return B_BAD_VALUE;
if (!fModule->create_child) if (!fModule->create_child)
return B_ENTRY_NOT_FOUND; return B_ENTRY_NOT_FOUND;
// lock partition and open partition device // lock partition and open partition device
KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KDiskDeviceManager *manager = KDiskDeviceManager::Default();
KPartition *_partition = manager->WriteLockPartition(partition->ID()); KPartition *_partition = manager->WriteLockPartition(partition->ID());
@@ -851,6 +938,7 @@ KPartitioningSystem::CreateChild(KPartition *partition, off_t offset,
if (result != B_OK) if (result != B_OK)
return result; return result;
} }
// let the module do its job // let the module do its job
status_t result = fModule->create_child(fd, partition->ID(), offset, size, status_t result = fModule->create_child(fd, partition->ID(), offset, size,
type, parameters, job->ID(), &childID); type, parameters, job->ID(), &childID);
@@ -864,6 +952,7 @@ KPartitioningSystem::CreateChild(KPartition *partition, off_t offset,
} }
// DeleteChild // DeleteChild
//! Deletes a child partition
status_t status_t
KPartitioningSystem::DeleteChild(KPartition *child, KDiskDeviceJob *job) KPartitioningSystem::DeleteChild(KPartition *child, KDiskDeviceJob *job)
{ {
@@ -889,4 +978,3 @@ KPartitioningSystem::UnloadModule()
fModule = NULL; fModule = NULL;
} }
} }
@@ -973,7 +973,7 @@ _user_validate_initialize_partition(partition_id partitionID,
diskSystemName, name, parameters); diskSystemName, name, parameters);
} }
if (!error) if (!error)
error = ddm_strlcpy(name, _name, B_DISK_DEVICE_NAME_LENGTH); error = ddm_strlcpy(_name, name, B_DISK_DEVICE_NAME_LENGTH);
free(parameters); free(parameters);
return error; return error;
} }
@@ -1,8 +1,14 @@
// KCreateChildJob.cpp /*
* Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold <[email protected]>
* Lubos Kulic <[email protected]>
*/
#include "KCreateChildJob.h" #include "KCreateChildJob.h"
#include <KernelExport.h> #include <KernelExport.h>
#include <DiskDeviceDefs.h> #include <DiskDeviceDefs.h>
#include <KDiskDevice.h> #include <KDiskDevice.h>
@@ -16,99 +22,108 @@
#include "ddm_operation_validation.h" #include "ddm_operation_validation.h"
/**
Creates the job.
KCreateChildJob::KCreateChildJob(partition_id partition, partition_id child, off_t offset, \param partition whose children should we create
off_t size, const char *type, const char *parameters) \param child new child ID
: KDiskDeviceJob( B_DISK_DEVICE_JOB_CREATE, partition, partition ), \param offset where the child should start
fChildID( child ), fOffset( offset ), fSize( size ), \param size size of the new child
fType ( !type ? NULL : strcpy ( new char[strlen(type)+1], type ) ), \param parameters additional parameters for the operation
fParameters( !parameters ? NULL : strcpy( new char[strlen(parameters)+1], parameters ) ) */
KCreateChildJob::KCreateChildJob(partition_id partition, partition_id child,
off_t offset, off_t size, const char *type, const char *parameters)
: KDiskDeviceJob(B_DISK_DEVICE_JOB_CREATE, partition, partition),
fChildID(child),
fOffset(offset),
fSize(size),
fType (!type ? NULL : strdup(type)),
fParameters(!parameters ? NULL : strdup(parameters))
{ {
SetDescription( "creating child of the partition" ); SetDescription( "creating child of the partition" );
} }
KCreateChildJob::~KCreateChildJob() {}
KCreateChildJob::~KCreateChildJob()
{
free(fType);
free(fParameters);
}
/** /**
* Do the actual creation * Do the actual creation
* *
* \note in time of calling the \c KDiskSystem function for creating child, the partition is NOT locked * \note in time of calling the \c KDiskSystem function for creating child, the partition is NOT locked
*/ */
status_t KCreateChildJob::Do() { status_t
KDiskDeviceManager * manager = KDiskDeviceManager::Default(); KCreateChildJob::Do()
{
KDiskDeviceManager* manager = KDiskDeviceManager::Default();
KPartition * partition = manager->WriteLockPartition( PartitionID() ); KPartition* partition = manager->WriteLockPartition(PartitionID());
if( partition ) { if (partition) {
PartitionRegistrar registrar(partition, true); PartitionRegistrar registrar(partition, true);
PartitionRegistrar deviceRegistrar(partition->Device(), true); PartitionRegistrar deviceRegistrar(partition->Device(), true);
DeviceWriteLocker locker(partition->Device(), true); DeviceWriteLocker locker(partition->Device(), true);
if (!partition->DiskSystem()) { if (!partition->DiskSystem()) {
SetErrorMessage("Partition has no disk system!"); SetErrorMessage("Partition has no disk system!");
return B_BAD_VALUE; return B_BAD_VALUE;
} }
// all descendants should be marked busy/descendant busy // all descendants should be marked busy/descendant busy
if ( isPartitionNotBusy( partition ) ) { if (IsPartitionNotBusy(partition)) {
SetErrorMessage("Can't create child of non-busy partition!"); SetErrorMessage("Can't create child of non-busy partition!");
return B_ERROR; return B_ERROR;
} }
KPartition* childPartition = manager->WriteLockPartition(fChildID);
KPartition * childPartition = manager->WriteLockPartition( fChildID ); if (!childPartition) {
if( !childPartition ) { // TODO
//TODO
} }
off_t newOffset = fOffset; off_t newOffset = fOffset;
off_t newSize = fSize; off_t newSize = fSize;
status_t validationResult = validate_create_child_partition(
status_t validation_result = validate_create_child_partition (
partition, partition->ChangeCounter(), partition, partition->ChangeCounter(),
&newOffset, &fSize, fType, &newOffset, &fSize, fType,
fParameters, NULL, false fParameters, NULL, false);
);
if( validation_result != B_OK ) { if (validationResult != B_OK) {
SetErrorMessage( "Validating of creating new child failed!" ); SetErrorMessage("Validating of creating new child failed!");
return validation_result; return validationResult;
} }
if( newOffset != fOffset ) { if (newOffset != fOffset) {
SetErrorMessage( "Requested offset is not valid." ); SetErrorMessage("Requested offset is not valid.");
return B_ERROR; return B_ERROR;
} }
if( newSize != fSize ) { if (newSize != fSize) {
SetErrorMessage( "Requested size is not valid" ); SetErrorMessage("Requested size is not valid");
} }
KDiskSystem *diskSystem = partition->DiskSystem(); KDiskSystem *diskSystem = partition->DiskSystem();
DiskSystemLoader loader(diskSystem); DiskSystemLoader loader(diskSystem);
KPartition * newChild = 0; KPartition *newChild = 0;
locker.Unlock(); locker.Unlock();
status_t create_result = diskSystem->CreateChild( status_t createResult = diskSystem->CreateChild(partition, newOffset,
partition, newOffset, newSize, fType, newSize, fType, fParameters, this, &newChild, fChildID);
fParameters, this, &newChild, fChildID );
if( create_result != B_OK ) { if (createResult != B_OK) {
SetErrorMessage( "Creating new partition child failed!" ); SetErrorMessage("Creating new partition child failed!");
return create_result; return createResult;
} }
return B_OK; return B_OK;
} }
else { else {
SetErrorMessage( "Couldn't find partition." ); SetErrorMessage("Couldn't find partition.");
return B_ENTRY_NOT_FOUND; return B_ENTRY_NOT_FOUND;
} }
} }
@@ -1,5 +1,11 @@
// KCreateChildJob.h /*
* Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold <[email protected]>
* Lubos Kulic <[email protected]>
*/
#ifndef _K_DISK_DEVICE_CREATE_CHILD_JOB_H #ifndef _K_DISK_DEVICE_CREATE_CHILD_JOB_H
#define _K_DISK_DEVICE_CREATE_CHILD_JOB_H #define _K_DISK_DEVICE_CREATE_CHILD_JOB_H
@@ -13,15 +19,6 @@ namespace DiskDevice {
*/ */
class KCreateChildJob : public KDiskDeviceJob { class KCreateChildJob : public KDiskDeviceJob {
public: public:
/**
* Creates the job.
*
* \param partition whose children should we create
* \param child new child ID
* \param offset where the child should start
* \param size size of the new child
* \param parameters additional parameters for the operation
*/
KCreateChildJob(partition_id partition, partition_id child, off_t offset, KCreateChildJob(partition_id partition, partition_id child, off_t offset,
off_t size, const char *type, const char *parameters); off_t size, const char *type, const char *parameters);
virtual ~KCreateChildJob(); virtual ~KCreateChildJob();
@@ -30,9 +27,10 @@ public:
private: private:
partition_id fChildID; partition_id fChildID;
off_t fOffset, fSize; off_t fOffset;
char * fType; off_t fSize;
char * fParameters; char* fType;
char* fParameters;
}; };
@@ -1,4 +1,11 @@
// KDefragmentJob.cpp /*
* Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold <[email protected]>
* Lubos Kulic <[email protected]>
*/
#include "KDefragmentJob.h" #include "KDefragmentJob.h"
@@ -16,77 +23,83 @@
#include "ddm_operation_validation.h" #include "ddm_operation_validation.h"
/**
Creates the job
\param partition which device should we defragment
*/
KDefragmentJob::KDefragmentJob(partition_id partition) KDefragmentJob::KDefragmentJob(partition_id partition)
: KDiskDeviceJob( B_DISK_DEVICE_JOB_DEFRAGMENT, partition, partition ) : KDiskDeviceJob(B_DISK_DEVICE_JOB_DEFRAGMENT, partition, partition)
{ {
SetDescription( "defragmenting partition" ); SetDescription("defragmenting partition");
} }
KDefragmentJob::~KDefragmentJob() {} KDefragmentJob::~KDefragmentJob()
{
}
status_t KDefragmentJob::Do(){
KDiskDeviceManager * manager = KDiskDeviceManager::Default(); status_t
KDefragmentJob::Do()
{
KDiskDeviceManager* manager = KDiskDeviceManager::Default();
KPartition * partition = manager->WriteLockPartition( PartitionID() ); KPartition* partition = manager->WriteLockPartition(PartitionID());
if( partition ) { if (partition) {
PartitionRegistrar registrar(partition, true); PartitionRegistrar registrar(partition, true);
PartitionRegistrar deviceRegistrar(partition->Device(), true); PartitionRegistrar deviceRegistrar(partition->Device(), true);
DeviceWriteLocker locker(partition->Device(), true); DeviceWriteLocker locker(partition->Device(), true);
//some basic checks // some basic checks
if (!partition->DiskSystem()) { if (!partition->DiskSystem()) {
SetErrorMessage("Partition has no disk system!"); SetErrorMessage("Partition has no disk system!");
return B_BAD_VALUE; return B_BAD_VALUE;
} }
// all descendants should be marked busy/descendant busy // all descendants should be marked busy/descendant busy
if ( isPartitionNotBusy( partition ) ) { if (IsPartitionNotBusy(partition) ) {
SetErrorMessage("Can't defragment non-busy partition!"); SetErrorMessage("Can't defragment non-busy partition!");
return B_ERROR; return B_ERROR;
} }
bool whileMounted; bool whileMounted;
//OK, seems alright, let's validate the job // OK, seems alright, let's validate the job
status_t validation_result = validate_defragment_partition( status_t validationResult = validate_defragment_partition(
partition, partition->ChangeCounter(), partition, partition->ChangeCounter(), &whileMounted, false);
&whileMounted, false);
if( validation_result != B_OK ) { if (validationResult != B_OK) {
SetErrorMessage( "Validation of defragmenting partition failed."); SetErrorMessage("Validation of defragmenting partition failed.");
return validation_result; return validationResult;
} }
if( !whileMounted && partition->IsMounted() ) { if (!whileMounted && partition->IsMounted()) {
SetErrorMessage( "This partition cannot be defragmented while mounted." ); SetErrorMessage("This partition cannot be defragmented while "
"mounted." );
return B_ERROR; return B_ERROR;
} }
//everything OK, let's do the job! // everything OK, let's do the job!
KDiskSystem *diskSystem = partition->DiskSystem(); KDiskSystem *diskSystem = partition->DiskSystem();
DiskSystemLoader loader(diskSystem); DiskSystemLoader loader(diskSystem);
locker.Unlock(); locker.Unlock();
status_t defrag_result = diskSystem->Defragment( partition, this ); status_t defragResult = diskSystem->Defragment(partition, this);
if( defrag_result != B_OK ) { if (defragResult != B_OK) {
SetErrorMessage( "Defragmenting partition failed!" ); SetErrorMessage("Defragmenting partition failed!");
return defrag_result; return defragResult;
} }
return B_OK; return B_OK;
} else { } else {
SetErrorMessage( "Couldn't find partition!" ); SetErrorMessage("Couldn't find partition!");
return B_ENTRY_NOT_FOUND; return B_ENTRY_NOT_FOUND;
} }
} }
@@ -1,5 +1,11 @@
// KDefragmentJob.h /*
* Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold <[email protected]>
* Lubos Kulic <[email protected]>
*/
#ifndef _K_DISK_DEVICE_DEFRAGMENT_JOB_H #ifndef _K_DISK_DEVICE_DEFRAGMENT_JOB_H
#define _K_DISK_DEVICE_DEFRAGMENT_JOB_H #define _K_DISK_DEVICE_DEFRAGMENT_JOB_H
@@ -13,12 +19,6 @@ namespace DiskDevice {
*/ */
class KDefragmentJob : public KDiskDeviceJob { class KDefragmentJob : public KDiskDeviceJob {
public: public:
/**
* Creates the job
*
* \param partition which device should we defragment
*/
KDefragmentJob(partition_id partition); KDefragmentJob(partition_id partition);
virtual ~KDefragmentJob(); virtual ~KDefragmentJob();
@@ -1,9 +1,14 @@
// KDeleteChildJob.cpp /*
* Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold <[email protected]>
* Lubos Kulic <[email protected]>
*/
#include "KDeleteChildJob.h" #include "KDeleteChildJob.h"
#include <KernelExport.h> #include <KernelExport.h>
#include <DiskDeviceDefs.h> #include <DiskDeviceDefs.h>
#include <KDiskDevice.h> #include <KDiskDevice.h>
@@ -17,64 +22,73 @@
#include "ddm_operation_validation.h" #include "ddm_operation_validation.h"
/*!
Creates the job
\param parent device of the deleted partition
\param partition partition supposed to be removed
*/
KDeleteChildJob::KDeleteChildJob(partition_id parent, partition_id partition) KDeleteChildJob::KDeleteChildJob(partition_id parent, partition_id partition)
: KDiskDeviceJob( B_DISK_DEVICE_JOB_DELETE, partition, parent ) : KDiskDeviceJob(B_DISK_DEVICE_JOB_DELETE, partition, parent)
{ {
SetDescription( "deleting child of the partition" ); SetDescription("deleting child of the partition");
} }
KDeleteChildJob::~KDeleteChildJob() {}
status_t KDeleteChildJob::Do(){ KDeleteChildJob::~KDeleteChildJob()
KDiskDeviceManager * manager = KDiskDeviceManager::Default(); {
}
KPartition * partition = manager->WriteLockPartition( PartitionID() );
if( partition ) { status_t
KDeleteChildJob::Do()
{
KDiskDeviceManager* manager = KDiskDeviceManager::Default();
KPartition* partition = manager->WriteLockPartition(PartitionID());
if (partition) {
PartitionRegistrar registrar(partition, true); PartitionRegistrar registrar(partition, true);
PartitionRegistrar deviceRegistrar(partition->Device(), true); PartitionRegistrar deviceRegistrar(partition->Device(), true);
DeviceWriteLocker locker(partition->Device(), true); DeviceWriteLocker locker(partition->Device(), true);
if (!partition->ParentDiskSystem()) { if (!partition->ParentDiskSystem()) {
SetErrorMessage("Partition has no parent disk system!"); SetErrorMessage("Partition has no parent disk system!");
return B_BAD_VALUE; return B_BAD_VALUE;
} }
// all descendants should be marked busy/descendant busy // all descendants should be marked busy/descendant busy
if ( isPartitionNotBusy( partition ) ) { if (IsPartitionNotBusy( partition)) {
SetErrorMessage("Can't delete child of non-busy partition!"); SetErrorMessage("Can't delete child of non-busy partition!");
return B_ERROR; return B_ERROR;
} }
status_t validation_result = validate_delete_child_partition( status_t validationResult = validate_delete_child_partition(
partition, partition->ChangeCounter(), partition, partition->ChangeCounter(), false);
false);
if( validation_result != B_OK ) { if (validationResult != B_OK) {
SetErrorMessage( "Validation of deleting child failed!" ); SetErrorMessage("Validation of deleting child failed!");
return validation_result; return validationResult;
} }
//everything OK, let's do the job! // everything OK, let's do the job!
KDiskSystem *parentDiskSystem = partition->ParentDiskSystem(); KDiskSystem *parentDiskSystem = partition->ParentDiskSystem();
DiskSystemLoader loader(parentDiskSystem ); DiskSystemLoader loader(parentDiskSystem );
locker.Unlock(); locker.Unlock();
status_t delete_result = parentDiskSystem->DeleteChild( partition, this ); status_t deleteResult = parentDiskSystem->DeleteChild(partition, this);
if( delete_result != B_OK ) { if (deleteResult != B_OK) {
SetErrorMessage( "Deleting child failed!" ); SetErrorMessage("Deleting child failed!");
return delete_result; return deleteResult;
} }
return B_OK; return B_OK;
} else { } else {
SetErrorMessage( "Couldn't find partition!" ); SetErrorMessage("Couldn't find partition!");
return B_ENTRY_NOT_FOUND; return B_ENTRY_NOT_FOUND;
} }
} }
@@ -1,5 +1,11 @@
// KDeleteChildJob.h /*
* Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold <[email protected]>
* Lubos Kulic <[email protected]>
*/
#ifndef _K_DISK_DEVICE_DELETE_CHILD_JOB_H #ifndef _K_DISK_DEVICE_DELETE_CHILD_JOB_H
#define _K_DISK_DEVICE_DELETE_CHILD_JOB_H #define _K_DISK_DEVICE_DELETE_CHILD_JOB_H
@@ -13,12 +19,6 @@ namespace DiskDevice {
*/ */
class KDeleteChildJob : public KDiskDeviceJob { class KDeleteChildJob : public KDiskDeviceJob {
public: public:
/**
* Creates the job
*
* \param parent device of the deleted partition
* \param partition partition supposed to be removed
*/
KDeleteChildJob(partition_id parent, partition_id partition); KDeleteChildJob(partition_id parent, partition_id partition);
virtual ~KDeleteChildJob(); virtual ~KDeleteChildJob();
@@ -1,4 +1,11 @@
// KInitializeJob.cpp /*
* Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold <[email protected]>
* Lubos Kulic <[email protected]>
*/
#include <stdio.h> #include <stdio.h>
@@ -21,21 +28,34 @@
#define OUT dprintf #define OUT dprintf
KInitializeJob::KInitializeJob(partition_id partition, disk_system_id diskSystemID, /*!
const char *name, const char *parameters) Creates the job.
: KDiskDeviceJob( B_DISK_DEVICE_JOB_INITIALIZE, partition, partition ),
fDiskSystemID( diskSystemID ), \param partition the partition to initialize
fName( !name ? NULL : strcpy( new char[strlen(name)+1], name ) ), \param diskSystemID which disk system the partition should be initialized with
fParameters( !parameters ? NULL : strcpy( new char[strlen(parameters)+1], parameters ) ) \param parameters additional parameters for the operation
*/
KInitializeJob::KInitializeJob(partition_id partition,
disk_system_id diskSystemID, const char *name, const char *parameters)
: KDiskDeviceJob(B_DISK_DEVICE_JOB_INITIALIZE, partition, partition),
fDiskSystemID(diskSystemID),
fName(!name ? NULL : strdup(name)),
fParameters(!parameters ? NULL : strdup(parameters))
{ {
SetDescription( "initializing the partition with given disk system" ); SetDescription("initializing the partition with given disk system");
} }
KInitializeJob::~KInitializeJob() {
delete[] fParameters; KInitializeJob::~KInitializeJob()
{
free(fName);
free(fParameters);
} }
status_t KInitializeJob::Do() {
status_t
KInitializeJob::Do()
{
DBG(OUT("KInitializeJob::Do(%ld)\n", PartitionID())); DBG(OUT("KInitializeJob::Do(%ld)\n", PartitionID()));
KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KDiskDeviceManager *manager = KDiskDeviceManager::Default();
KPartition *partition = manager->WriteLockPartition(PartitionID()); KPartition *partition = manager->WriteLockPartition(PartitionID());
@@ -52,54 +72,53 @@ DBG(OUT("KInitializeJob::Do(%ld)\n", PartitionID()));
// } // }
// all descendants should be marked busy/descendant busy // all descendants should be marked busy/descendant busy
if ( isPartitionNotBusy( partition ) ) { if (IsPartitionNotBusy(partition)) {
SetErrorMessage("Can't initialize non-busy partition!"); SetErrorMessage("Can't initialize non-busy partition!");
return B_ERROR; return B_ERROR;
} }
/* if( !fParameters ) { /* if (!fParameters) {
//no parameters for the operation //no parameters for the operation
SetErrorMessage( "No parameters for partition initialization." ); SetErrorMessage( "No parameters for partition initialization." );
return B_ERROR; return B_ERROR;
}*/ }*/
// TODO shouldn't we load the disk system AFTER the validation?
//TODO shouldn't we load the disk system AFTER the validation? KDiskSystem *diskSystemToInit = manager->LoadDiskSystem(fDiskSystemID);
KDiskSystem *diskSystemToInit = manager->LoadDiskSystem( fDiskSystemID ); if (!diskSystemToInit) {
if( ! diskSystemToInit ) { SetErrorMessage("Given DiskSystemID doesn't correspond to any "
SetErrorMessage( "Given DiskSystemID doesn't correspond to any known DiskSystem."); "known DiskSystem.");
return B_BAD_VALUE; return B_BAD_VALUE;
} }
DiskSystemLoader loader2(diskSystemToInit); DiskSystemLoader loader2(diskSystemToInit);
status_t validation_result = validate_initialize_partition( // TODO: The parameters are already validated and should not be changed again!
partition, partition->ChangeCounter(), status_t validationResult = validate_initialize_partition(partition,
diskSystemToInit->Name(), fName, partition->ChangeCounter(), diskSystemToInit->Name(), fName,
fParameters, false ); fParameters, false);
if( validation_result != B_OK ) { if (validationResult != B_OK) {
SetErrorMessage( "Validation of initializing partition failed!" ); SetErrorMessage("Validation of initializing partition failed!");
return validation_result; return validationResult;
} }
//everything seems OK -> let's do the job // everything seems OK -> let's do the job
locker.Unlock(); locker.Unlock();
status_t init_result = diskSystemToInit->Initialize( partition, fName, fParameters, this ); status_t initResult = diskSystemToInit->Initialize(partition, fName,
fParameters, this);
if( init_result != B_OK ) { if (initResult != B_OK) {
SetErrorMessage( "Initialization of partition failed!" ); SetErrorMessage("Initialization of partition failed!");
return init_result; return initResult;
} }
partition->SetDiskSystem(diskSystemToInit); partition->SetDiskSystem(diskSystemToInit);
return B_OK; return B_OK;
} else { } else {
SetErrorMessage( "Couldn't find partition." ); SetErrorMessage("Couldn't find partition.");
return B_ENTRY_NOT_FOUND; return B_ENTRY_NOT_FOUND;
} }
} }
@@ -1,5 +1,11 @@
// KInitializeJob.h /*
* Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold <[email protected]>
* Lubos Kulic <[email protected]>
*/
#ifndef _K_DISK_DEVICE_INITIALIZE_JOB_H #ifndef _K_DISK_DEVICE_INITIALIZE_JOB_H
#define _K_DISK_DEVICE_INITIALIZE_JOB_H #define _K_DISK_DEVICE_INITIALIZE_JOB_H
@@ -13,13 +19,6 @@ namespace DiskDevice {
*/ */
class KInitializeJob : public KDiskDeviceJob { class KInitializeJob : public KDiskDeviceJob {
public: public:
/**
* Creates the job.
*
* \param partition the partition to initialize
* \param diskSystemID which disk system the partition should be initialized with
* \param parameters additional parameters for the operation
*/
KInitializeJob(partition_id partition, disk_system_id diskSystemID, KInitializeJob(partition_id partition, disk_system_id diskSystemID,
const char *name, const char *parameters); const char *name, const char *parameters);
virtual ~KInitializeJob(); virtual ~KInitializeJob();
@@ -1,4 +1,12 @@
// KMoveJob.cpp /*
* Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold <[email protected]>
* Lubos Kulic <[email protected]>
*/
#include "KMoveJob.h" #include "KMoveJob.h"
#include <stdio.h> #include <stdio.h>
@@ -15,31 +23,42 @@
#include "ddm_operation_validation.h" #include "ddm_operation_validation.h"
// debugging // debugging
//#define DBG(x) //#define DBG(x)
#define DBG(x) x #define DBG(x) x
#define OUT dprintf #define OUT dprintf
KMoveJob::KMoveJob(partition_id parentID, partition_id partitionID, off_t offset)
: KDiskDeviceJob(B_DISK_DEVICE_JOB_MOVE, partitionID, parentID ), /**
Creates the job.
\param parentID the device whose child should be moved
\param partitionID the child to move
\param offset where to move
*/
KMoveJob::KMoveJob(partition_id parentID, partition_id partitionID,
off_t offset)
: KDiskDeviceJob(B_DISK_DEVICE_JOB_MOVE, partitionID, parentID),
fNewOffset(offset) fNewOffset(offset)
{ {
SetDescription( "moving partition" ); SetDescription("moving partition");
} }
KMoveJob::~KMoveJob() {} KMoveJob::~KMoveJob()
{
}
status_t KMoveJob::Do() { status_t
KMoveJob::Do()
{
DBG(OUT( "KMoveJob::Do(%ld)\n", PartitionID() )); DBG(OUT( "KMoveJob::Do(%ld)\n", PartitionID() ));
//get the partition // get the partition
KDiskDeviceManager * manager = KDiskDeviceManager::Default(); KDiskDeviceManager* manager = KDiskDeviceManager::Default();
KPartition *partition = manager->WriteLockPartition(PartitionID()); KPartition *partition = manager->WriteLockPartition(PartitionID());
if (partition) { if (partition) {
//OK, we have the partition, do some checks // OK, we have the partition, do some checks
PartitionRegistrar registrar(partition, true); PartitionRegistrar registrar(partition, true);
PartitionRegistrar deviceRegistrar(partition->Device(), true); PartitionRegistrar deviceRegistrar(partition->Device(), true);
@@ -51,48 +70,48 @@ status_t KMoveJob::Do() {
return B_BAD_VALUE; return B_BAD_VALUE;
} }
if(partition->Offset() == fNewOffset ) { if (partition->Offset() == fNewOffset) {
//we are already on the right place -> nothing to do... // we are already on the right place -> nothing to do...
return B_OK; return B_OK;
} }
off_t new_offset = fNewOffset; off_t newOffset = fNewOffset;
status_t validate_result = validate_move_partition(partition, partition->ChangeCounter(), status_t validateResult = validate_move_partition(partition,
&new_offset, true, false ); //TODO posledni 2 parametry???? partition->ChangeCounter(), &newOffset, true, false);
if( validate_result != B_OK ) { // TODO posledni 2 parametry????
SetErrorMessage( "Validation of the new partition offset failed." ); // TODO: Huh?
return validate_result; if (validateResult != B_OK) {
SetErrorMessage("Validation of the new partition offset failed.");
return validateResult;
} }
if( new_offset != fNewOffset ) { if (newOffset != fNewOffset) {
SetErrorMessage( "Requested partition offset not valid." ); SetErrorMessage("Requested partition offset not valid.");
return B_ERROR; return B_ERROR;
} }
// all descendants should be marked busy/descendant busy // all descendants should be marked busy/descendant busy
if ( isPartitionNotBusy( partition ) ) { if (IsPartitionNotBusy(partition)) {
SetErrorMessage("Can't move non-busy partition!"); SetErrorMessage("Can't move non-busy partition!");
return B_ERROR; return B_ERROR;
} }
//get all necessary objects // get all necessary objects
KDiskSystem *parentDiskSystem = partition->ParentDiskSystem(); KDiskSystem *parentDiskSystem = partition->ParentDiskSystem();
KDiskSystem *childDiskSystem = partition->DiskSystem(); KDiskSystem *childDiskSystem = partition->DiskSystem();
locker.Unlock(); locker.Unlock();
status_t move_result = parentDiskSystem->Move( partition, fNewOffset, this ); status_t moveResult = parentDiskSystem->Move(partition, fNewOffset,
if( move_result != B_OK ) { this);
SetErrorMessage( "Moving of partition failed." ); if (moveResult != B_OK) {
SetErrorMessage("Moving of partition failed.");
} }
return move_result; return moveResult;
//do the move
} else { } else {
SetErrorMessage("Couldn't find partition."); SetErrorMessage("Couldn't find partition.");
return B_ENTRY_NOT_FOUND; return B_ENTRY_NOT_FOUND;
} }
return B_ERROR;
} }
@@ -1,10 +1,17 @@
// KMoveJob.h /*
* Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold <[email protected]>
* Lubos Kulic <[email protected]>
*/
#ifndef _K_DISK_DEVICE_MOVE_JOB_H #ifndef _K_DISK_DEVICE_MOVE_JOB_H
#define _K_DISK_DEVICE_MOVE_JOB_H #define _K_DISK_DEVICE_MOVE_JOB_H
#include "KDiskDeviceJob.h" #include "KDiskDeviceJob.h"
namespace BPrivate { namespace BPrivate {
namespace DiskDevice { namespace DiskDevice {
@@ -13,19 +20,11 @@ namespace DiskDevice {
*/ */
class KMoveJob : public KDiskDeviceJob { class KMoveJob : public KDiskDeviceJob {
public: public:
/**
* Creates the job.
*
* \param parentID the device whose child should be moved
* \param partitionID the child to move
* \param offset where to move
*/
KMoveJob(partition_id parentID, partition_id partitionID, off_t offset); KMoveJob(partition_id parentID, partition_id partitionID, off_t offset);
virtual ~KMoveJob(); virtual ~KMoveJob();
virtual status_t Do(); virtual status_t Do();
private: private:
off_t fNewOffset; off_t fNewOffset;
}; };
@@ -1,8 +1,14 @@
// KRepairJob.cpp /*
* Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold <[email protected]>
* Lubos Kulic <[email protected]>
*/
#include "KRepairJob.h" #include "KRepairJob.h"
#include <KernelExport.h> #include <KernelExport.h>
#include <DiskDeviceDefs.h> #include <DiskDeviceDefs.h>
#include <KDiskDevice.h> #include <KDiskDevice.h>
@@ -16,80 +22,80 @@
#include "ddm_operation_validation.h" #include "ddm_operation_validation.h"
/**
Creates the job.
\param partition the partition which should be repared
\param checkOnly when true, the partition is only checked, but no actual
repairs are proceeded
*/
KRepairJob::KRepairJob(partition_id partition, bool checkOnly) KRepairJob::KRepairJob(partition_id partition, bool checkOnly)
: KDiskDeviceJob( B_DISK_DEVICE_JOB_REPAIR, partition, partition ), : KDiskDeviceJob(B_DISK_DEVICE_JOB_REPAIR, partition, partition),
fCheckOnly( checkOnly ) fCheckOnly( checkOnly )
{ {
SetDescription( "repairing partition" ); SetDescription("repairing partition");
} }
KRepairJob::~KRepairJob() {}
status_t KRepairJob::Do(){
KDiskDeviceManager * manager = KDiskDeviceManager::Default(); KRepairJob::~KRepairJob()
{
}
KPartition * partition = manager->WriteLockPartition( PartitionID() );
if( partition ) { status_t
KRepairJob::Do()
{
KDiskDeviceManager* manager = KDiskDeviceManager::Default();
KPartition* partition = manager->WriteLockPartition(PartitionID());
if (partition) {
PartitionRegistrar registrar(partition, true); PartitionRegistrar registrar(partition, true);
PartitionRegistrar deviceRegistrar(partition->Device(), true); PartitionRegistrar deviceRegistrar(partition->Device(), true);
DeviceWriteLocker locker(partition->Device(), true); DeviceWriteLocker locker(partition->Device(), true);
//basic checks // basic checks
if( !partition->DiskSystem() ) { if (!partition->DiskSystem()) {
SetErrorMessage( "Partition has no disk system." ); SetErrorMessage("Partition has no disk system.");
return B_BAD_VALUE; return B_BAD_VALUE;
} }
if ( isPartitionNotBusy( partition ) ) { if (IsPartitionNotBusy(partition)) {
SetErrorMessage("Can't repair non-busy partition!"); SetErrorMessage("Can't repair non-busy partition!");
return B_ERROR; return B_ERROR;
} }
bool whileMounted; bool whileMounted;
status_t validationResult = validate_repair_partition(partition,
partition->ChangeCounter(), fCheckOnly, &whileMounted, false);
status_t validation_result = validate_repair_partition( if (validationResult != B_OK) {
partition, partition->ChangeCounter(), SetErrorMessage("Validation repairing partition failed!");
fCheckOnly, &whileMounted, return validationResult;
false);
if( validation_result != B_OK ) {
SetErrorMessage( "Validation repairing partition failed!" );
return validation_result;
} }
//everything OK, let's do the job // everything OK, let's do the job
KDiskSystem * diskSystem = partition->DiskSystem(); KDiskSystem* diskSystem = partition->DiskSystem();
DiskSystemLoader loader(diskSystem); DiskSystemLoader loader(diskSystem);
locker.Unlock(); locker.Unlock();
status_t repair_result = diskSystem->Repair( partition, fCheckOnly, this ); status_t repairResult = diskSystem->Repair(partition, fCheckOnly, this);
if( repair_result != B_OK ) { if (repairResult != B_OK) {
if( fCheckOnly ) { if (fCheckOnly) {
SetErrorMessage( "Checking for repairing partition failed!" ); SetErrorMessage("Checking for repairing partition failed!");
} else { } else {
SetErrorMessage( "Repairing partition failed!" ); SetErrorMessage("Repairing partition failed!");
} }
return repair_result; return repairResult;
} }
return B_OK; return B_OK;
}else { } else {
SetErrorMessage( "Couldn't find partition!" ); SetErrorMessage("Couldn't find partition!");
return B_ENTRY_NOT_FOUND; return B_ENTRY_NOT_FOUND;
} }
} }
@@ -1,10 +1,17 @@
// KRepairJob.h /*
* Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold <[email protected]>
* Lubos Kulic <[email protected]>
*/
#ifndef _K_DISK_DEVICE_REPAIR_JOB_H #ifndef _K_DISK_DEVICE_REPAIR_JOB_H
#define _K_DISK_DEVICE_REPAIR_JOB_H #define _K_DISK_DEVICE_REPAIR_JOB_H
#include "KDiskDeviceJob.h" #include "KDiskDeviceJob.h"
namespace BPrivate { namespace BPrivate {
namespace DiskDevice { namespace DiskDevice {
@@ -13,13 +20,6 @@ namespace DiskDevice {
*/ */
class KRepairJob : public KDiskDeviceJob { class KRepairJob : public KDiskDeviceJob {
public: public:
/**
* Creates the job.
*
* \param partition the partition which should be repared
* \param checkOnly when true, the partition is only checked, but no actual
* repairs are proceeded
*/
KRepairJob(partition_id partition, bool checkOnly); KRepairJob(partition_id partition, bool checkOnly);
virtual ~KRepairJob(); virtual ~KRepairJob();
@@ -1,4 +1,10 @@
// KResizeJob.cpp /*
* Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold <[email protected]>
*/
#include <stdio.h> #include <stdio.h>
@@ -14,12 +20,21 @@
#include "ddm_operation_validation.h" #include "ddm_operation_validation.h"
#include "KResizeJob.h" #include "KResizeJob.h"
// debugging // debugging
//#define DBG(x) //#define DBG(x)
#define DBG(x) x #define DBG(x) x
#define OUT dprintf #define OUT dprintf
// constructor // constructor
/**
Creates the job.
\param parentID the device whose child should be resized
\param partitionID the partition which should be resized
\param size new size for the partition
*/
KResizeJob::KResizeJob(partition_id parentID, partition_id partitionID, KResizeJob::KResizeJob(partition_id parentID, partition_id partitionID,
off_t size) off_t size)
: KDiskDeviceJob(B_DISK_DEVICE_JOB_RESIZE, partitionID, parentID), : KDiskDeviceJob(B_DISK_DEVICE_JOB_RESIZE, partitionID, parentID),
@@ -28,16 +43,19 @@ KResizeJob::KResizeJob(partition_id parentID, partition_id partitionID,
SetDescription("resizing partition"); SetDescription("resizing partition");
} }
// destructor // destructor
KResizeJob::~KResizeJob() KResizeJob::~KResizeJob()
{ {
} }
// Do // Do
status_t status_t
KResizeJob::Do() KResizeJob::Do()
{ {
DBG(OUT("KResizeJob::Do(%ld)\n", PartitionID())); DBG(OUT("KResizeJob::Do(%ld)\n", PartitionID()));
// get the partition // get the partition
KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KDiskDeviceManager *manager = KDiskDeviceManager::Default();
KPartition *partition = manager->WriteLockPartition(PartitionID()); KPartition *partition = manager->WriteLockPartition(PartitionID());
@@ -45,14 +63,17 @@ KResizeJob::Do()
PartitionRegistrar registrar(partition, true); PartitionRegistrar registrar(partition, true);
PartitionRegistrar deviceRegistrar(partition->Device(), true); PartitionRegistrar deviceRegistrar(partition->Device(), true);
DeviceWriteLocker locker(partition->Device(), true); DeviceWriteLocker locker(partition->Device(), true);
// basic checks // basic checks
if (!partition->ParentDiskSystem()) { if (!partition->ParentDiskSystem()) {
SetErrorMessage("Partition has no parent disk system!"); SetErrorMessage("Partition has no parent disk system!");
return B_BAD_VALUE; return B_BAD_VALUE;
} }
// if size remains the same, then nothing's to do // if size remains the same, then nothing's to do
if (partition->Size() == fSize) if (partition->Size() == fSize)
return B_OK; return B_OK;
// check new size // check new size
off_t size = fSize; off_t size = fSize;
off_t contentSize = fSize; off_t contentSize = fSize;
@@ -66,6 +87,7 @@ KResizeJob::Do()
SetErrorMessage("Requested size is not valid."); SetErrorMessage("Requested size is not valid.");
return B_ERROR; return B_ERROR;
} }
// all descendants should be marked busy/descendant busy // all descendants should be marked busy/descendant busy
struct IsNotBusyVisitor : KPartitionVisitor { struct IsNotBusyVisitor : KPartitionVisitor {
virtual bool VisitPre(KPartition *partition) virtual bool VisitPre(KPartition *partition)
@@ -77,6 +99,7 @@ KResizeJob::Do()
SetErrorMessage("Can't resize non-busy partition!"); SetErrorMessage("Can't resize non-busy partition!");
return B_ERROR; return B_ERROR;
} }
// things look good: get all infos needed for resizing // things look good: get all infos needed for resizing
KDiskSystem *parentDiskSystem = partition->ParentDiskSystem(); KDiskSystem *parentDiskSystem = partition->ParentDiskSystem();
KDiskSystem *childDiskSystem = partition->DiskSystem(); KDiskSystem *childDiskSystem = partition->DiskSystem();
@@ -84,8 +107,10 @@ KResizeJob::Do()
DiskSystemLoader loader2(childDiskSystem); DiskSystemLoader loader2(childDiskSystem);
off_t oldSize = partition->Size(); off_t oldSize = partition->Size();
off_t oldContentSize = partition->ContentSize(); off_t oldContentSize = partition->ContentSize();
// unlock the device and resize the beast // unlock the device and resize the beast
locker.Unset(); locker.Unset();
// if growing, resize partition first // if growing, resize partition first
if (oldSize < fSize) { if (oldSize < fSize) {
status_t error = parentDiskSystem->ResizeChild(partition, fSize, status_t error = parentDiskSystem->ResizeChild(partition, fSize,
@@ -93,6 +118,7 @@ KResizeJob::Do()
if (error != B_OK) if (error != B_OK)
return error; return error;
} }
// resize contents // resize contents
if (childDiskSystem && oldContentSize != contentSize) { if (childDiskSystem && oldContentSize != contentSize) {
status_t error = childDiskSystem->Resize(partition, contentSize, status_t error = childDiskSystem->Resize(partition, contentSize,
@@ -100,6 +126,7 @@ KResizeJob::Do()
if (error != B_OK) if (error != B_OK)
return error; return error;
} }
// if shrinking, resize partition last // if shrinking, resize partition last
if (oldSize > fSize) { if (oldSize > fSize) {
status_t error = parentDiskSystem->ResizeChild(partition, fSize, status_t error = parentDiskSystem->ResizeChild(partition, fSize,
@@ -107,11 +134,12 @@ KResizeJob::Do()
if (error != B_OK) if (error != B_OK)
return error; return error;
} }
return B_OK;
} else { } else {
SetErrorMessage("Couldn't find partition."); SetErrorMessage("Couldn't find partition.");
return B_ENTRY_NOT_FOUND; return B_ENTRY_NOT_FOUND;
} }
// cannot come here
return B_ERROR;
} }
@@ -1,5 +1,10 @@
// KResizeJob.h /*
* Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold <[email protected]>
*/
#ifndef _K_DISK_DEVICE_RESIZE_JOB_H #ifndef _K_DISK_DEVICE_RESIZE_JOB_H
#define _K_DISK_DEVICE_RESIZE_JOB_H #define _K_DISK_DEVICE_RESIZE_JOB_H
@@ -13,13 +18,6 @@ namespace DiskDevice {
*/ */
class KResizeJob : public KDiskDeviceJob { class KResizeJob : public KDiskDeviceJob {
public: public:
/**
* Creates the job.
*
* \param parentID the device whose child should be resized
* \param partitionID the partition which should be resized
* \param size new size for the partition
*/
KResizeJob(partition_id parentID, partition_id partitionID, off_t size); KResizeJob(partition_id parentID, partition_id partitionID, off_t size);
virtual ~KResizeJob(); virtual ~KResizeJob();
@@ -1,4 +1,10 @@
// KScanPartitionJob.cpp /*
* Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold <bonefish@cs.tu-berlin.de>
*/
#include <KernelExport.h> #include <KernelExport.h>
@@ -18,6 +24,11 @@
#define OUT dprintf #define OUT dprintf
/**
Creates the job.
\param partitionID the partition to scan
*/
KScanPartitionJob::KScanPartitionJob(partition_id partitionID) KScanPartitionJob::KScanPartitionJob(partition_id partitionID)
: KDiskDeviceJob(B_DISK_DEVICE_JOB_SCAN, partitionID) : KDiskDeviceJob(B_DISK_DEVICE_JOB_SCAN, partitionID)
{ {
@@ -33,12 +44,6 @@ KScanPartitionJob::~KScanPartitionJob()
status_t status_t
KScanPartitionJob::Do() KScanPartitionJob::Do()
{ {
/*#ifdef _BOOT_MODE
OUT( "\nScanJob boot mode\n\n" );
#else
OUT( "\nScanJob NOT boot mode\n\n" );
#endif*/
// get the partition // get the partition
KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KDiskDeviceManager *manager = KDiskDeviceManager::Default();
KPartition *partition = manager->WriteLockPartition(PartitionID()); KPartition *partition = manager->WriteLockPartition(PartitionID());
@@ -1,5 +1,10 @@
// KScanPartitionJob.h /*
* Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold <bonefish@cs.tu-berlin.de>
*/
#ifndef _K_DISK_DEVICE_SCAN_PARTITION_JOB_H #ifndef _K_DISK_DEVICE_SCAN_PARTITION_JOB_H
#define _K_DISK_DEVICE_SCAN_PARTITION_JOB_H #define _K_DISK_DEVICE_SCAN_PARTITION_JOB_H
@@ -15,20 +20,12 @@ class KPartition;
*/ */
class KScanPartitionJob : public KDiskDeviceJob { class KScanPartitionJob : public KDiskDeviceJob {
public: public:
/**
* Creates the job.
*
* \param partitionID the partition to scan
*/
KScanPartitionJob(partition_id partitionID); KScanPartitionJob(partition_id partitionID);
virtual ~KScanPartitionJob(); virtual ~KScanPartitionJob();
virtual status_t Do(); virtual status_t Do();
private: private:
/**
* Do the actual scan.
*/
status_t _ScanPartition(KPartition *partition); status_t _ScanPartition(KPartition *partition);
}; };
@@ -1,3 +1,10 @@
/*
* Copyright 2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Lubos Kulic <lubos@radical.ed>
*/
#include "KSetNameJob.h" #include "KSetNameJob.h"
@@ -14,122 +21,128 @@
#include "ddm_operation_validation.h" #include "ddm_operation_validation.h"
KSetNameJob::KSetNameJob(partition_id parentID, partition_id partitionID, const char * name, /**
const char * contentName) Creates the job.
\param partitionID the partition/device whose name should be set
\param name the new name for \c partitionID
\param contentName the new name for the content of \c partitionID
*/
KSetNameJob::KSetNameJob(partition_id parentID, partition_id partitionID,
const char* name, const char* contentName)
: KDiskDeviceJob(B_DISK_DEVICE_JOB_SET_NAME, partitionID, parentID), : KDiskDeviceJob(B_DISK_DEVICE_JOB_SET_NAME, partitionID, parentID),
fName( !name ? NULL : strcpy( new char[strlen(name)+1], name ) ), fName(!name ? NULL : strdup(name)),
fContentName( !contentName ? NULL : strcpy( new char[strlen(contentName)+1], contentName ) ) fContentName(!contentName ? NULL : strdup(contentName))
{ {
SetDescription( "setting name for the partition or its content" ); SetDescription("setting name for the partition or its content");
} }
KSetNameJob::~KSetNameJob() KSetNameJob::~KSetNameJob()
{ {
delete[] fName; free(fName);
delete[] fContentName; free(fContentName);
} }
status_t KSetNameJob::Do() { status_t
KDiskDeviceManager * manager = KDiskDeviceManager::Default(); KSetNameJob::Do()
{
KDiskDeviceManager* manager = KDiskDeviceManager::Default();
KPartition * partition = manager->WriteLockPartition( PartitionID() ); KPartition* partition = manager->WriteLockPartition(PartitionID());
if( partition ) { if (partition) {
if( !fName && !fContentName ) { if (!fName && !fContentName) {
SetErrorMessage( "No name to set." ); SetErrorMessage("No name to set.");
return B_BAD_VALUE; return B_BAD_VALUE;
} }
PartitionRegistrar registrar(partition, true); PartitionRegistrar registrar(partition, true);
PartitionRegistrar deviceRegistrar(partition->Device(), true); PartitionRegistrar deviceRegistrar(partition->Device(), true);
//TODO is lock necessary? // TODO is lock necessary?
DeviceWriteLocker locker(partition->Device(), true); DeviceWriteLocker locker(partition->Device(), true);
//basic checks // basic checks
// all descendants should be marked busy/descendant busy // all descendants should be marked busy/descendant busy
if ( isPartitionNotBusy( partition ) ) { if (IsPartitionNotBusy(partition)) {
SetErrorMessage("Can't set name for non-busy partition!"); SetErrorMessage("Can't set name for non-busy partition!");
return B_ERROR; return B_ERROR;
} }
if( fName ) { if (fName) {
//set name of the partition // set name of the partition
//setting name of this partition -> via our parent disk system // setting name of this partition -> via our parent disk system
if( !partition->ParentDiskSystem() ) { if (!partition->ParentDiskSystem()) {
SetErrorMessage( "Partition has no parent disk system!" ); SetErrorMessage("Partition has no parent disk system!");
return B_BAD_VALUE; return B_BAD_VALUE;
} }
//TODO mayebe give copy of name // TODO maybe give copy of name
status_t validation_result = validate_set_partition_name( // TODO: The parameters are already validated and should not be changed again!
partition, partition->ChangeCounter(), status_t validationResult = validate_set_partition_name(
fName, false); partition, partition->ChangeCounter(), fName, false);
if( validation_result != B_OK) { if( validationResult != B_OK) {
SetErrorMessage( "Validation of setting partition name failed!" ); SetErrorMessage( "Validation of setting partition name failed!" );
return validation_result; return validationResult;
} }
//everything OK, let's do the job // everything OK, let's do the job
KDiskSystem * parentDiskSystem = partition->ParentDiskSystem(); KDiskSystem* parentDiskSystem = partition->ParentDiskSystem();
DiskSystemLoader loader(parentDiskSystem); DiskSystemLoader loader(parentDiskSystem);
locker.Unlock(); locker.Unlock();
status_t set_name_result = parentDiskSystem->SetName(partition, fName, this); status_t setNameResult = parentDiskSystem->SetName(partition, fName,
this);
if( set_name_result != B_OK ) { if (setNameResult != B_OK) {
SetErrorMessage( "Setting name of the partition failed!" ); SetErrorMessage( "Setting name of the partition failed!" );
} }
return set_name_result; return setNameResult;
} }
if( fContentName ) { if (fContentName) {
//set name of the contents // set name of the contents
//setting name of our contents -> via our disk system // setting name of our contents -> via our disk system
if( !partition->DiskSystem() ) { if (!partition->DiskSystem()) {
SetErrorMessage( "Partition has no disk system!"); SetErrorMessage( "Partition has no disk system!");
return B_BAD_VALUE; return B_BAD_VALUE;
} }
status_t validation_result = validate_set_partition_content_name( // TODO: The parameters are already validated and should not be changed again!
partition, partition->ChangeCounter(), status_t validationResult = validate_set_partition_content_name(
fContentName, false); partition, partition->ChangeCounter(), fContentName, false);
if( validation_result != B_OK ) { if (validationResult != B_OK) {
SetErrorMessage( "Validation of setting partition content name failed!" ); SetErrorMessage("Validation of setting partition content name "
return validation_result; "failed!");
return validationResult;
} }
//everything OK, let's do the job // everything OK, let's do the job
KDiskSystem * diskSystem = partition->DiskSystem(); KDiskSystem* diskSystem = partition->DiskSystem();
DiskSystemLoader loader( diskSystem ); DiskSystemLoader loader(diskSystem);
locker.Unlock(); locker.Unlock();
status_t set_cont_name_result = diskSystem->SetContentName( status_t result = diskSystem->SetContentName(partition,
partition, fContentName, this); fContentName, this);
if (result != B_OK) {
if( set_cont_name_result != B_OK ) { SetErrorMessage("Setting name of the partition's content "
SetErrorMessage( "Setting name of the partition's content failed!" ); "failed!" );
} }
return set_cont_name_result; return result;
} }
} else { } else {
SetErrorMessage( "Couldn't find partition!" ); SetErrorMessage("Couldn't find partition!");
return B_ENTRY_NOT_FOUND; return B_ENTRY_NOT_FOUND;
} }
return B_ERROR;
} }
@@ -1,3 +1,10 @@
/*
* Copyright 2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Lubos Kulic <lubos@radical.ed>
*/
#ifndef _K_DISK_DEVICE_SET_NAME_JOB_H #ifndef _K_DISK_DEVICE_SET_NAME_JOB_H
#define _K_DISK_DEVICE_SET_NAME_JOB_H #define _K_DISK_DEVICE_SET_NAME_JOB_H
@@ -14,32 +21,20 @@ namespace DiskDevice {
* it's possible to create it with only one of these name parameters and so * it's possible to create it with only one of these name parameters and so
* set only one of the names * set only one of the names
*/ */
class KSetNameJob : public KDiskDeviceJob class KSetNameJob : public KDiskDeviceJob {
{
public: public:
/** KSetNameJob(partition_id parentID, partition_id partitionID,
* Creates the job. const char* name, const char* contentName);
*
*
* \param partitionID the partition/device whose name should be set
* \param name the new name for \c partitionID
* \param contentName the new name for the content of \c partitionID
*/
KSetNameJob(partition_id parentID, partition_id partitionID, const char * name,
const char * contentName);
virtual ~KSetNameJob(); virtual ~KSetNameJob();
virtual status_t Do(); virtual status_t Do();
private: private:
char * fName, *fContentName; char* fName;
char* fContentName;
}; };
} }
} }
using BPrivate::DiskDevice::KSetNameJob; using BPrivate::DiskDevice::KSetNameJob;
@@ -1,6 +1,11 @@
// KSetParametersJob.cpp /*
* Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold <bonefish@cs.tu-berlin.de>
* Lubos Kulic <lubos@radical.ed>
*/
#include <KernelExport.h> #include <KernelExport.h>
#include <DiskDeviceDefs.h> #include <DiskDeviceDefs.h>
@@ -18,47 +23,56 @@
#include "ddm_operation_validation.h" #include "ddm_operation_validation.h"
/**
Creates the job.
KSetParametersJob::KSetParametersJob(partition_id parent, partition_id partition, \param partition the partition whose params (or content params) should be set
const char *parameters, const char *contentParameters) \param parameters the new parameters for the partition
\param contentParameters the new parameters for partition's content
*/
KSetParametersJob::KSetParametersJob(partition_id parent,
partition_id partition, const char *parameters,
const char *contentParameters)
: KDiskDeviceJob(B_DISK_DEVICE_JOB_SET_TYPE, partition, parent), : KDiskDeviceJob(B_DISK_DEVICE_JOB_SET_TYPE, partition, parent),
fParams( !parameters ? NULL : strcpy( new char[strlen(parameters)+1], parameters )), fParams(!parameters ? NULL : strdup(parameters)),
fContentParams( fContentParams(!contentParameters ? NULL : strdup(contentParameters))
!contentParameters ? NULL :
strcpy( new char[strlen(contentParameters)+1], contentParameters))
{ {
SetDescription( "setting partition parameters&content parameters" ); SetDescription("setting partition parameters&content parameters");
} }
KSetParametersJob::~KSetParametersJob(){} KSetParametersJob::~KSetParametersJob()
{
free(fParams);
free(fContentParams);
}
status_t KSetParametersJob::Do(){
status_t
KSetParametersJob::Do()
{
KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KDiskDeviceManager *manager = KDiskDeviceManager::Default();
KPartition *partition = manager->WriteLockPartition(PartitionID()); KPartition *partition = manager->WriteLockPartition(PartitionID());
if (partition) { if (partition) {
if( !fParams && !fContentParams ) { if (!fParams && !fContentParams) {
SetErrorMessage( "No parameter to set." ); SetErrorMessage("No parameter to set.");
return B_BAD_VALUE; return B_BAD_VALUE;
} }
PartitionRegistrar registrar(partition, true); PartitionRegistrar registrar(partition, true);
PartitionRegistrar deviceRegistrar(partition->Device(), true); PartitionRegistrar deviceRegistrar(partition->Device(), true);
//TODO is lock necessary? // TODO is lock necessary?
DeviceWriteLocker locker(partition->Device(), true); DeviceWriteLocker locker(partition->Device(), true);
// all descendants should be marked busy/descendant busy // all descendants should be marked busy/descendant busy
if ( isPartitionNotBusy( partition ) ) { if (IsPartitionNotBusy(partition)) {
SetErrorMessage("Can't set parameters for non-busy partition!"); SetErrorMessage("Can't set parameters for non-busy partition!");
return B_ERROR; return B_ERROR;
} }
//TODO unlock? // TODO unlock?
if( fParams ) { if (fParams) {
// basic checks // basic checks
if (!partition->ParentDiskSystem()) { if (!partition->ParentDiskSystem()) {
@@ -66,28 +80,31 @@ status_t KSetParametersJob::Do(){
return B_BAD_VALUE; return B_BAD_VALUE;
} }
//TODO mayebe give copy of parameters? // TODO maybe give copy of parameters?
//we have some parameters to set // we have some parameters to set
status_t validation_result = validate_set_partition_parameters( partition, partition->ChangeCounter(), fParams, false ); // TODO: The parameters are already validated and should not be changed again!
status_t validationResult = validate_set_partition_parameters(
partition, partition->ChangeCounter(), fParams, false);
KDiskSystem *parentDiskSystem = partition->ParentDiskSystem(); KDiskSystem *parentDiskSystem = partition->ParentDiskSystem();
DiskSystemLoader loader(parentDiskSystem); DiskSystemLoader loader(parentDiskSystem);
if( validation_result != B_OK ) { if (validationResult != B_OK) {
SetErrorMessage( "Validation of setting partition parameters failed." ); SetErrorMessage("Validation of setting partition parameters "
return validation_result; "failed.");
return validationResult;
} }
locker.Unlock(); locker.Unlock();
status_t set_pars_result = parentDiskSystem->SetParameters( partition, fParams, this ); status_t setParametersResult = parentDiskSystem->SetParameters(
partition, fParams, this);
if( set_pars_result != B_OK ) { if (setParametersResult != B_OK) {
SetErrorMessage( "Setting partition parameters failed." ); SetErrorMessage( "Setting partition parameters failed." );
} }
} }
if (fContentParams) {
if( fContentParams ) {
// basic checks // basic checks
if (!partition->DiskSystem()) { if (!partition->DiskSystem()) {
@@ -95,35 +112,34 @@ status_t KSetParametersJob::Do(){
return B_BAD_VALUE; return B_BAD_VALUE;
} }
// TODO: The parameters are already validated and should not be changed again!
status_t validationResult
= validate_set_partition_content_parameters(partition,
partition->ChangeCounter(), fContentParams, false);
if (validationResult != B_OK) {
status_t validation_result = validate_set_partition_content_parameters ( SetErrorMessage("Validation of setting partition content "
partition, partition->ChangeCounter(), fContentParams, false ); "parameters failed.");
return validationResult;
if( validation_result != B_OK ) {
SetErrorMessage( "Validation of setting partition content parameters failed." );
return validation_result;
} }
KDiskSystem *diskSystem = partition->DiskSystem(); KDiskSystem *diskSystem = partition->DiskSystem();
DiskSystemLoader loader(diskSystem); DiskSystemLoader loader(diskSystem);
locker.Unlock(); locker.Unlock();
status_t set_cont_pars_result = diskSystem->SetContentParameters( status_t result = diskSystem->SetContentParameters(partition,
partition, fContentParams, this ); fContentParams, this);
if( set_cont_pars_result != B_OK ) { if (result != B_OK) {
SetErrorMessage( "Setting partition content parameters failed." ); SetErrorMessage("Setting partition content parameters failed.");
} }
} }
// TODO: Check return values!
return B_OK; return B_OK;
} else { } else {
SetErrorMessage( "Couldn't find partition" ); SetErrorMessage( "Couldn't find partition" );
return B_ENTRY_NOT_FOUND; return B_ENTRY_NOT_FOUND;
} }
} }
@@ -1,5 +1,11 @@
// KSetParametersJob.h /*
* Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold <bonefish@cs.tu-berlin.de>
* Lubos Kulic <lubos@radical.ed>
*/
#ifndef _K_DISK_DEVICE_SET_PARAMETERS_JOB_H #ifndef _K_DISK_DEVICE_SET_PARAMETERS_JOB_H
#define _K_DISK_DEVICE_SET_PARAMETERS_JOB_H #define _K_DISK_DEVICE_SET_PARAMETERS_JOB_H
@@ -17,13 +23,6 @@ namespace DiskDevice {
*/ */
class KSetParametersJob : public KDiskDeviceJob { class KSetParametersJob : public KDiskDeviceJob {
public: public:
/**
* Creates the job.
*
* \param partition the partition whose params (or content params) should be set
* \param parameters the new parameters for the partition
* \param contentParameters the new parameters for partition's content
*/
KSetParametersJob(partition_id parent, partition_id partition, KSetParametersJob(partition_id parent, partition_id partition,
const char *parameters, const char *contentParameters); const char *parameters, const char *contentParameters);
virtual ~KSetParametersJob(); virtual ~KSetParametersJob();
@@ -1,15 +1,10 @@
// /*
// C++ Implementation: KSetTypeJob * Copyright 2007, Haiku, Inc. All Rights Reserved.
// * Distributed under the terms of the MIT License.
// Description: *
// * Authors:
// * Lubos Kulic <lubos@radical.ed>
// Author: <[email protected]>, (C) 2007 */
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include <KPartition.h> #include <KPartition.h>
#include <KernelExport.h> #include <KernelExport.h>
@@ -26,64 +21,76 @@
#include "KSetTypeJob.h" #include "KSetTypeJob.h"
#include "ddm_operation_validation.h" #include "ddm_operation_validation.h"
KSetTypeJob::KSetTypeJob(partition_id parentID, partition_id partitionID, const char *type)
/**
Creates the job.
\param partitionID the partition whose type should be set
\param type the new type for the partition
*/
KSetTypeJob::KSetTypeJob(partition_id parentID, partition_id partitionID,
const char *type)
: KDiskDeviceJob(B_DISK_DEVICE_JOB_SET_TYPE, partitionID, parentID), : KDiskDeviceJob(B_DISK_DEVICE_JOB_SET_TYPE, partitionID, parentID),
fType( !type ? NULL : strcpy( new char[strlen(type)+1], type ) ) fType(!type ? NULL : strdup(type))
{ {
SetDescription( "setting partition type" ); SetDescription("setting partition type");
} }
KSetTypeJob::~KSetTypeJob(){} KSetTypeJob::~KSetTypeJob()
{
}
status_t KSetTypeJob::Do() {
KDiskDeviceManager * manager = KDiskDeviceManager::Default();
KPartition * partition = manager->WriteLockPartition( PartitionID() ); status_t
KSetTypeJob::Do()
{
KDiskDeviceManager* manager = KDiskDeviceManager::Default();
if( partition ) { KPartition* partition = manager->WriteLockPartition(PartitionID());
if (partition) {
PartitionRegistrar registrar(partition, true); PartitionRegistrar registrar(partition, true);
PartitionRegistrar deviceRegistrar(partition->Device(), true); PartitionRegistrar deviceRegistrar(partition->Device(), true);
//TODO is lock necessary? // TODO is lock necessary?
DeviceWriteLocker locker(partition->Device(), true); DeviceWriteLocker locker(partition->Device(), true);
//basic checks // basic checks
if( !partition->ParentDiskSystem() ) { if (!partition->ParentDiskSystem()) {
SetErrorMessage( "Partition has no parent disk system!" ); SetErrorMessage("Partition has no parent disk system!");
return B_BAD_VALUE; return B_BAD_VALUE;
} }
if( !fType ) { if (!fType) {
SetErrorMessage( "No type to set!" ); SetErrorMessage("No type to set!");
return B_BAD_VALUE; return B_BAD_VALUE;
} }
status_t validation_result = validate_set_partition_type( // TODO: The parameters are already validated and should not be changed again!
partition, partition->ChangeCounter(), status_t validationResult = validate_set_partition_type(
fType, false); partition, partition->ChangeCounter(), fType, false);
if (validationResult != B_OK) {
if( validation_result != B_OK ) { SetErrorMessage("Validation of setting partition type failed!");
SetErrorMessage( "Validation of setting partition type failed!" ); return validationResult;
return validation_result;
} }
//everything OK, let's do the job // everything OK, let's do the job
KDiskSystem * parentDiskSystem = partition->ParentDiskSystem(); KDiskSystem* parentDiskSystem = partition->ParentDiskSystem();
DiskSystemLoader loader( parentDiskSystem ); DiskSystemLoader loader(parentDiskSystem);
status_t set_type_result = parentDiskSystem->SetType( partition, fType, this ); status_t setTypeResult = parentDiskSystem->SetType(partition, fType,
this);
if( set_type_result != B_OK ) { if (setTypeResult != B_OK) {
SetErrorMessage( "Setting partition type failed!" ); SetErrorMessage("Setting partition type failed!");
return set_type_result; return setTypeResult;
} }
return B_OK; return B_OK;
} else { } else {
SetErrorMessage( "Couldn't find partition!" ); SetErrorMessage("Couldn't find partition!");
return B_ENTRY_NOT_FOUND; return B_ENTRY_NOT_FOUND;
} }
} }
@@ -1,14 +1,10 @@
// /*
// C++ Interface: KSetTypeJob * Copyright 2007, Haiku, Inc. All Rights Reserved.
// * Distributed under the terms of the MIT License.
// Description: *
// * Authors:
// * Lubos Kulic <lubos@radical.ed>
// Author: <[email protected]>, (C) 2007 */
//
// Copyright: See COPYING file that comes with this distribution
//
//
#ifndef _K_DISK_DEVICE_SET_TYPE_JOB_H #ifndef _K_DISK_DEVICE_SET_TYPE_JOB_H
#define _K_DISK_DEVICE_SET_TYPE_JOB_H #define _K_DISK_DEVICE_SET_TYPE_JOB_H
@@ -24,25 +20,16 @@ namespace DiskDevice {
class KSetTypeJob : public KDiskDeviceJob class KSetTypeJob : public KDiskDeviceJob
{ {
public: public:
/**
* Creates the job.
*
* \param partitionID the partition whose type should be set
* \param type the new type for the partition
*/
KSetTypeJob(partition_id parentID, partition_id partitionID, const char *type); KSetTypeJob(partition_id parentID, partition_id partitionID, const char *type);
virtual ~KSetTypeJob(); virtual ~KSetTypeJob();
virtual status_t Do(); virtual status_t Do();
private: private:
char * fType; char * fType;
}; };
} }
} }
using BPrivate::DiskDevice::KSetTypeJob; using BPrivate::DiskDevice::KSetTypeJob;
@@ -1,4 +1,10 @@
// KInitializeJob.cpp /*
* Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold <bonefish@cs.tu-berlin.de>
*/
#include <stdio.h> #include <stdio.h>
@@ -1,5 +1,10 @@
// KInitializeJob.h /*
* Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold <bonefish@cs.tu-berlin.de>
*/
#ifndef _K_DISK_DEVICE_UNINITIALIZE_JOB_H #ifndef _K_DISK_DEVICE_UNINITIALIZE_JOB_H
#define _K_DISK_DEVICE_UNINITIALIZE_JOB_H #define _K_DISK_DEVICE_UNINITIALIZE_JOB_H
@@ -13,9 +18,6 @@ namespace DiskDevice {
*/ */
class KUninitializeJob : public KDiskDeviceJob { class KUninitializeJob : public KDiskDeviceJob {
public: public:
/**
* Creates the job
*/
KUninitializeJob(partition_id partitionID); KUninitializeJob(partition_id partitionID);
virtual ~KUninitializeJob(); virtual ~KUninitializeJob();