From d86af8ce27128b44563a6e7f97d2ed2b94511aab Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Fri, 27 Jul 2007 16:32:47 +0000 Subject: [PATCH] * 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 --- .../disk_device_manager/KDiskDeviceJob.h | 65 +---- .../kernel/disk_device_manager/KDiskSystem.h | 11 +- .../kernel/disk_device_manager/KFileSystem.h | 17 +- .../kernel/disk_device_manager/KPartition.h | 11 +- .../disk_device_manager/KPartitioningSystem.h | 101 ++++--- .../disk_device_manager/KPhysicalPartition.h | 11 +- .../disk_device_manager/KShadowPartition.h | 16 +- .../disk_device_manager/KDiskDeviceJob.cpp | 64 +++- .../KDiskDeviceJobFactory.cpp | 21 +- .../KPartitioningSystem.cpp | 274 ++++++++++++------ .../ddm_userland_interface.cpp | 2 +- .../jobs/KCreateChildJob.cpp | 133 +++++---- .../jobs/KCreateChildJob.h | 30 +- .../jobs/KDefragmentJob.cpp | 103 ++++--- .../disk_device_manager/jobs/KDefragmentJob.h | 16 +- .../jobs/KDeleteChildJob.cpp | 88 +++--- .../jobs/KDeleteChildJob.h | 16 +- .../jobs/KInitializeJob.cpp | 111 ++++--- .../disk_device_manager/jobs/KInitializeJob.h | 17 +- .../disk_device_manager/jobs/KMoveJob.cpp | 105 ++++--- .../disk_device_manager/jobs/KMoveJob.h | 21 +- .../disk_device_manager/jobs/KRepairJob.cpp | 116 ++++---- .../disk_device_manager/jobs/KRepairJob.h | 18 +- .../disk_device_manager/jobs/KResizeJob.cpp | 42 ++- .../disk_device_manager/jobs/KResizeJob.h | 16 +- .../jobs/KScanPartitionJob.cpp | 19 +- .../jobs/KScanPartitionJob.h | 17 +- .../disk_device_manager/jobs/KSetNameJob.cpp | 173 ++++++----- .../disk_device_manager/jobs/KSetNameJob.h | 29 +- .../jobs/KSetParametersJob.cpp | 146 +++++----- .../jobs/KSetParametersJob.h | 17 +- .../disk_device_manager/jobs/KSetTypeJob.cpp | 113 ++++---- .../disk_device_manager/jobs/KSetTypeJob.h | 27 +- .../jobs/KUninitializeJob.cpp | 8 +- .../jobs/KUninitializeJob.h | 12 +- 35 files changed, 1124 insertions(+), 862 deletions(-) diff --git a/headers/private/kernel/disk_device_manager/KDiskDeviceJob.h b/headers/private/kernel/disk_device_manager/KDiskDeviceJob.h index 560c8c749a..a96dd985eb 100644 --- a/headers/private/kernel/disk_device_manager/KDiskDeviceJob.h +++ b/headers/private/kernel/disk_device_manager/KDiskDeviceJob.h @@ -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 + * Lubos Kulic + */ #ifndef _K_DISK_DEVICE_JOB_H #define _K_DISK_DEVICE_JOB_H @@ -15,38 +21,19 @@ class KDiskDeviceJobQueue; /** * Represents some action executed on the disk device. - * - * - */ class KDiskDeviceJob { 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, partition_id scopeID = -1); virtual ~KDiskDeviceJob(); - /** - * Unique identification of the job - */ disk_job_id ID() const; void SetJobQueue(KDiskDeviceJobQueue *queue); KDiskDeviceJobQueue *JobQueue() const; - /** - * Gets actual type of the action - */ uint32 Type() const; - void SetStatus(uint32 status); uint32 Status() const; @@ -81,21 +68,6 @@ public: status_t GetInfo(user_disk_device_job_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; private: @@ -116,27 +88,10 @@ private: 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: - //some stuff useful for all descendants + // some stuff useful for all descendants - /** - * 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 ); + bool IsPartitionNotBusy(KPartition* partition); }; diff --git a/headers/private/kernel/disk_device_manager/KDiskSystem.h b/headers/private/kernel/disk_device_manager/KDiskSystem.h index f789a5d7c2..659180567c 100644 --- a/headers/private/kernel/disk_device_manager/KDiskSystem.h +++ b/headers/private/kernel/disk_device_manager/KDiskSystem.h @@ -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 + */ #ifndef _K_DISK_DEVICE_SYSTEM_H #define _K_DISK_DEVICE_SYSTEM_H @@ -13,7 +18,7 @@ namespace DiskDevice { class KDiskDeviceJob; class KPartition; -/// \brief Common ancestor for disk system add-on wrappers +//! \brief Common ancestor for disk system add-on wrappers class KDiskSystem { public: KDiskSystem(const char *name); diff --git a/headers/private/kernel/disk_device_manager/KFileSystem.h b/headers/private/kernel/disk_device_manager/KFileSystem.h index dbd5a227d0..b46ca26c28 100644 --- a/headers/private/kernel/disk_device_manager/KFileSystem.h +++ b/headers/private/kernel/disk_device_manager/KFileSystem.h @@ -1,8 +1,13 @@ -// KFileSystem.h -// -// KFileSystem implements the KDiskSystem interface for file systems. -// It works with the FS API. - +/* + * Copyright 2003-2007, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Ingo Weinhold + * + * KFileSystem implements the KDiskSystem interface for file systems. + * It works with the FS API. + */ #ifndef _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 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 { public: KFileSystem(const char *name); diff --git a/headers/private/kernel/disk_device_manager/KPartition.h b/headers/private/kernel/disk_device_manager/KPartition.h index aa55b0a0cd..14063692b6 100644 --- a/headers/private/kernel/disk_device_manager/KPartition.h +++ b/headers/private/kernel/disk_device_manager/KPartition.h @@ -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 + */ #ifndef _K_DISK_DEVICE_PARTITION_H #define _K_DISK_DEVICE_PARTITION_H @@ -21,7 +26,7 @@ class KPath; class KPhysicalPartition; class KShadowPartition; -/// \brief Class representing a single partition. +//! \brief Class representing a single partition. class KPartition { public: KPartition(partition_id id = -1); diff --git a/headers/private/kernel/disk_device_manager/KPartitioningSystem.h b/headers/private/kernel/disk_device_manager/KPartitioningSystem.h index 737575fbba..4275d86116 100644 --- a/headers/private/kernel/disk_device_manager/KPartitioningSystem.h +++ b/headers/private/kernel/disk_device_manager/KPartitioningSystem.h @@ -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 + */ #ifndef _K_PARTITIONING_DISK_DEVICE_SYSTEM_H #define _K_PARTITIONING_DISK_DEVICE_SYSTEM_H @@ -24,9 +29,9 @@ public: // Scanning - /// Try to identify a given partition + //! Try to identify a given partition virtual float Identify(KPartition *partition, void **cookie); - /// Scan the partition + //! Scan the partition virtual status_t Scan(KPartition *partition, void *cookie); virtual void FreeIdentifyCookie(KPartition *partition, void *cookie); virtual void FreeCookie(KPartition *partition); @@ -34,132 +39,132 @@ public: // 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, 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); - /// 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); - /// 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); - /// 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); - /// 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); - /// 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, 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); - /// 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); - /// 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, 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); - /// 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, 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); - /// 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); - /// 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); - /// Validates parameters for resizing a partition + //! Validates parameters for resizing a partition 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); - /// Validates parameters for moving a partition + //! Validates parameters for moving a partition 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); - /// Validates parameters for setting name of a partition + //! Validates parameters for setting name of a partition 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); - /// Validates parameters for setting type of a partition + //! Validates parameters for setting type of a partition 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, 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, const char *parameters); - /// Validates parameters for initializing a partition + //! Validates parameters for initializing a partition virtual bool ValidateInitialize(KPartition *partition, char *name, 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, off_t *size, const char *type, const char *parameters, int32 *index); - /// Counts partitionable spaces on a partition + //! Counts partitionable spaces on a 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, partitionable_space_data *buffer, int32 count, int32 *actualCount = NULL); - /// Iterates through supported partition types + //! Iterates through supported partition types virtual status_t GetNextSupportedType(KPartition *partition, int32 *cookie, 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, char *type); // 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, uint32 operation); // Writing - /// Repairs a partition + //! Repairs a partition virtual status_t Repair(KPartition *partition, bool checkOnly, KDiskDeviceJob *job); - /// Resizes a partition + //! Resizes a partition virtual status_t Resize(KPartition *partition, off_t size, KDiskDeviceJob *job); - /// Resizes child of a partition + //! Resizes child of a partition virtual status_t ResizeChild(KPartition *child, off_t size, KDiskDeviceJob *job); - /// Moves a partition + //! Moves a partition virtual status_t Move(KPartition *partition, off_t offset, KDiskDeviceJob *job); - /// Moves child of a partition + //! Moves child of a partition virtual status_t MoveChild(KPartition *child, off_t offset, KDiskDeviceJob *job); - /// Sets name to a partition + //! Sets name of a partition virtual status_t SetName(KPartition *partition, char *name, 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, KDiskDeviceJob *job); - /// Sets type of a partition + //! Sets type of a partition virtual status_t SetType(KPartition *partition, char *type, KDiskDeviceJob *job); - /// Sets parameters of a partition + //! Sets parameters of a partition virtual status_t SetParameters(KPartition *partition, const char *parameters, KDiskDeviceJob *job); - /// Sets parameters to content of a partition + //! Sets parameters to content of a partition virtual status_t SetContentParameters(KPartition *partition, const char *parameters, KDiskDeviceJob *job); - /// Creates a child partition + //! Creates a child partition virtual status_t CreateChild(KPartition *partition, off_t offset, off_t size, const char *type, const char *parameters, KDiskDeviceJob *job, KPartition **child = NULL, partition_id childID = -1); - /// Deletes a child partition + //! Deletes a child partition 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, const char *parameters, KDiskDeviceJob *job); diff --git a/headers/private/kernel/disk_device_manager/KPhysicalPartition.h b/headers/private/kernel/disk_device_manager/KPhysicalPartition.h index a254a1ce92..83cf6d4e65 100644 --- a/headers/private/kernel/disk_device_manager/KPhysicalPartition.h +++ b/headers/private/kernel/disk_device_manager/KPhysicalPartition.h @@ -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 + */ #ifndef _K_DISK_DEVICE_PHYSICAL_PARTITION_H #define _K_DISK_DEVICE_PHYSICAL_PARTITION_H @@ -12,7 +17,7 @@ class KDiskDevice; class KDiskSystem; class KShadowPartition; -/// \brief Class representing an existing partition. +//! \brief Class representing an existing partition. class KPhysicalPartition : public KPartition { public: KPhysicalPartition(partition_id id = -1); diff --git a/headers/private/kernel/disk_device_manager/KShadowPartition.h b/headers/private/kernel/disk_device_manager/KShadowPartition.h index 7a52134ba6..eb76a91335 100644 --- a/headers/private/kernel/disk_device_manager/KShadowPartition.h +++ b/headers/private/kernel/disk_device_manager/KShadowPartition.h @@ -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 + */ #ifndef _K_DISK_DEVICE_SHADOW_PARTITION_H #define _K_DISK_DEVICE_SHADOW_PARTITION_H @@ -11,9 +16,10 @@ namespace DiskDevice { class KPhysicalPartition; -/// \brief Class representing a shadow of an existing partition. -/// -/// See \ref path_kernel_structures for more information. +/*! \brief Class representing a shadow of an existing partition. + + See \ref path_kernel_structures for more information. +*/ class KShadowPartition : public KPartition, private KPartitionListener { public: KShadowPartition(KPhysicalPartition *physicalPartition); diff --git a/src/system/kernel/disk_device_manager/KDiskDeviceJob.cpp b/src/system/kernel/disk_device_manager/KDiskDeviceJob.cpp index 60fc883c32..186d667893 100644 --- a/src/system/kernel/disk_device_manager/KDiskDeviceJob.cpp +++ b/src/system/kernel/disk_device_manager/KDiskDeviceJob.cpp @@ -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 + * Lubos Kulic + */ #include @@ -14,8 +21,19 @@ #define OUT dprintf // 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, - partition_id scopeID) + partition_id scopeID) : fID(_NextID()), fJobQueue(NULL), fType(type), @@ -233,6 +251,23 @@ KDiskDeviceJob::GetProgressInfo(disk_device_job_progress_info *info) 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 disk_job_id KDiskDeviceJob::_NextID() @@ -244,16 +279,29 @@ KDiskDeviceJob::_NextID() disk_job_id KDiskDeviceJob::fNextID = 0; -// IsNotBusyVisitor -bool KDiskDeviceJob::IsNotBusyVisitor::VisitPre( KPartition * partition ) { - return !(partition->IsBusy() || partition->IsDescendantBusy()); -} +/** + 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 -bool KDiskDeviceJob::isPartitionNotBusy( KPartition * partition ) { + \param partition the root of checked subtree of the whole partition + hierarchy +*/ +bool +KDiskDeviceJob::IsPartitionNotBusy(KPartition* partition) +{ if( !partition ) { return false; } + + struct IsNotBusyVisitor : KPartitionVisitor { + virtual bool VisitPre(KPartition* partition) + { + return !(partition->IsBusy() || partition->IsDescendantBusy()); + } + }; + IsNotBusyVisitor notBusyVisitor; - return partition->VisitEachDescendant(&fNotBusyVisitor); + return partition->VisitEachDescendant(¬BusyVisitor); } diff --git a/src/system/kernel/disk_device_manager/KDiskDeviceJobFactory.cpp b/src/system/kernel/disk_device_manager/KDiskDeviceJobFactory.cpp index 7aaf9bc95e..a457a4622a 100644 --- a/src/system/kernel/disk_device_manager/KDiskDeviceJobFactory.cpp +++ b/src/system/kernel/disk_device_manager/KDiskDeviceJobFactory.cpp @@ -1,11 +1,12 @@ /* - * Copyright 2004-2006, Haiku, Inc. All rights reserved. - * Copyright 2003-2004, Ingo Weinhold, bonefish@cs.tu-berlin.de. All rights reserved. - * + * Copyright 2003-2007, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. + * + * Authors: + * Ingo Weinhold + * Lubos Kulic */ - #include #include "KDiskDeviceJob.h" @@ -24,6 +25,7 @@ #include "KSetTypeJob.h" #include "KUninitializeJob.h" + using namespace std; @@ -61,8 +63,9 @@ KDiskDeviceJobFactory::CreateResizeJob(partition_id parentID, KDiskDeviceJob * -KDiskDeviceJobFactory::CreateMoveJob(partition_id parentID, partition_id partitionID, - off_t offset, const partition_id *contentsToMove, int32 contentsToMoveCount) +KDiskDeviceJobFactory::CreateMoveJob(partition_id parentID, + partition_id partitionID, off_t offset, const partition_id *contentsToMove, + int32 contentsToMoveCount) { // TODO: this is wierd, what in hell are contentsToMove etc? return new(nothrow) KMoveJob(parentID, partitionID, offset); @@ -113,7 +116,8 @@ KDiskDeviceJob * KDiskDeviceJobFactory::CreateInitializeJob(partition_id partitionID, 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, const char *parameters) { - return new(nothrow) KCreateChildJob(partitionID, childID, offset, size, type, parameters); + return new(nothrow) KCreateChildJob(partitionID, childID, offset, size, + type, parameters); } diff --git a/src/system/kernel/disk_device_manager/KPartitioningSystem.cpp b/src/system/kernel/disk_device_manager/KPartitioningSystem.cpp index d3d4ef84f5..bcb2ffef94 100644 --- a/src/system/kernel/disk_device_manager/KPartitioningSystem.cpp +++ b/src/system/kernel/disk_device_manager/KPartitioningSystem.cpp @@ -1,3 +1,12 @@ +/* + * Copyright 2003-2007, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Ingo Weinhold + * Lubos Kulic + */ + /** \file KPartitioningSystem.cpp * * \brief Implementation of \ref KPartitioningSystem class @@ -15,6 +24,7 @@ #include #include + // constructor KPartitioningSystem::KPartitioningSystem(const char *name) : KDiskSystem(name), @@ -44,6 +54,7 @@ KPartitioningSystem::Init() } // Identify +//! Try to identify a given partition float KPartitioningSystem::Identify(KPartition *partition, void **cookie) { @@ -53,12 +64,13 @@ KPartitioningSystem::Identify(KPartition *partition, void **cookie) if (partition->Open(O_RDONLY, &fd) != B_OK) return -1; float result = fModule->identify_partition(fd, partition->PartitionData(), - cookie); + cookie); close(fd); return result; } // Scan +//! Scan the partition status_t KPartitioningSystem::Scan(KPartition *partition, void *cookie) { @@ -80,7 +92,7 @@ KPartitioningSystem::FreeIdentifyCookie(KPartition *partition, void *cookie) if (!partition || !fModule || !fModule->free_identify_partition_cookie) return; fModule->free_identify_partition_cookie(partition->PartitionData(), - cookie); + cookie); } // FreeCookie @@ -108,9 +120,10 @@ KPartitioningSystem::FreeContentCookie(KPartition *partition) } // SupportsRepairing +//! Check whether the add-on supports repairing this partition. bool KPartitioningSystem::SupportsRepairing(KPartition *partition, bool checkOnly, - bool *whileMounted) + bool *whileMounted) { bool _whileMounted = false; if (!whileMounted) @@ -126,9 +139,9 @@ KPartitioningSystem::SupportsRepairing(KPartition *partition, bool checkOnly, } // SupportsResizing +//! Check whether the add-on supports resizing this partition. bool -KPartitioningSystem::SupportsResizing(KPartition *partition, - bool *whileMounted) +KPartitioningSystem::SupportsResizing(KPartition *partition, bool *whileMounted) { bool _whileMounted = false; if (!whileMounted) @@ -143,17 +156,18 @@ KPartitioningSystem::SupportsResizing(KPartition *partition, } // SupportsResizingChild +//! Check whether the add-on supports resizing children of this partition. bool KPartitioningSystem::SupportsResizingChild(KPartition *child) { return (child && child->Parent() && child->ParentDiskSystem() == this - && fModule && fModule->supports_resizing_child - && fModule->supports_resizing_child( - child->Parent()->PartitionData(), - child->PartitionData())); + && fModule && fModule->supports_resizing_child + && fModule->supports_resizing_child(child->Parent()->PartitionData(), + child->PartitionData())); } // SupportsMoving +//! Check whether the add-on supports moving this partition. bool KPartitioningSystem::SupportsMoving(KPartition *partition, bool *isNoOp) { @@ -168,28 +182,33 @@ KPartitioningSystem::SupportsMoving(KPartition *partition, bool *isNoOp) } // SupportsMovingChild +//! Check whether the add-on supports moving children of this partition. bool KPartitioningSystem::SupportsMovingChild(KPartition *child) { return (child && child->Parent() && child->ParentDiskSystem() != this - && fModule && fModule->supports_moving_child - && fModule->supports_moving_child(child->Parent()->PartitionData(), - child->PartitionData())); + && fModule && fModule->supports_moving_child + && fModule->supports_moving_child(child->Parent()->PartitionData(), + child->PartitionData())); } // SupportsSettingName +//! Check whether the add-on supports setting name of this partition. bool KPartitioningSystem::SupportsSettingName(KPartition *partition) { return (partition && partition->ParentDiskSystem() == this - && fModule && fModule->supports_setting_name - && fModule->supports_setting_name(partition->PartitionData())); + && fModule && fModule->supports_setting_name + && fModule->supports_setting_name(partition->PartitionData())); } // SupportsSettingContentName +/*! Check whether the add-on supports setting name of the content of this + partition. +*/ bool KPartitioningSystem::SupportsSettingContentName(KPartition *partition, - bool *whileMounted) + bool *whileMounted) { bool _whileMounted = false; if (!whileMounted) @@ -205,28 +224,32 @@ KPartitioningSystem::SupportsSettingContentName(KPartition *partition, } // SupportsSettingType +//! Check whether the add-on supports setting type of this partition. bool KPartitioningSystem::SupportsSettingType(KPartition *partition) { return (partition && partition->ParentDiskSystem() == this - && fModule && fModule->supports_setting_type - && fModule->supports_setting_type(partition->PartitionData())); + && fModule && fModule->supports_setting_type + && fModule->supports_setting_type(partition->PartitionData())); } // SupportsSettingParameters +//! Check whether the add-on supports setting parameters of this partition. bool KPartitioningSystem::SupportsSettingParameters(KPartition *partition) { return (partition && partition->ParentDiskSystem() == this - && fModule && fModule->supports_setting_parameters - && fModule->supports_setting_parameters( - partition->PartitionData())); + && fModule && fModule->supports_setting_parameters + && fModule->supports_setting_parameters(partition->PartitionData())); } // SupportsSettingContentParameters +/*! Check whether the add-on supports setting parameters of the content of this + partition. +*/ bool KPartitioningSystem::SupportsSettingContentParameters(KPartition *partition, - bool *whileMounted) + bool *whileMounted) { bool _whileMounted = false; if (!whileMounted) @@ -242,135 +265,149 @@ KPartitioningSystem::SupportsSettingContentParameters(KPartition *partition, } // SupportsInitializing +//! Check whether the add-on supports initializing this partition. bool KPartitioningSystem::SupportsInitializing(KPartition *partition) { return (partition && fModule && fModule->supports_initializing - && fModule->supports_initializing(partition->PartitionData())); + && fModule->supports_initializing(partition->PartitionData())); } // SupportsInitializingChild +//! Check whether the add-on supports initializing a child of this partition. bool KPartitioningSystem::SupportsInitializingChild(KPartition *child, - const char *diskSystem) + const char *diskSystem) { return (child && child->ParentDiskSystem() == this && diskSystem - && fModule && fModule->supports_initializing_child - && fModule->supports_initializing_child(child->PartitionData(), - diskSystem)); + && fModule && fModule->supports_initializing_child + && fModule->supports_initializing_child(child->PartitionData(), + diskSystem)); } // SupportsCreatingChild +//! Check whether the add-on supports creating children of this partition. bool KPartitioningSystem::SupportsCreatingChild(KPartition *partition) { return (partition && partition->DiskSystem() == this - && fModule && fModule->supports_creating_child - && fModule->supports_creating_child(partition->PartitionData())); + && fModule && fModule->supports_creating_child + && fModule->supports_creating_child(partition->PartitionData())); } // SupportsDeletingChild +//! Check whether the add-on supports deleting children of this partition. bool KPartitioningSystem::SupportsDeletingChild(KPartition *child) { return (child && child->Parent() && child->ParentDiskSystem() == this - && fModule && fModule->supports_deleting_child - && fModule->supports_deleting_child( - child->Parent()->PartitionData(), child->PartitionData())); + && fModule && fModule->supports_deleting_child + && fModule->supports_deleting_child(child->Parent()->PartitionData(), + child->PartitionData())); } // IsSubSystemFor +//! Check whether the add-on is a subsystem for a given partition. bool KPartitioningSystem::IsSubSystemFor(KPartition *partition) { return (partition && fModule && fModule->is_sub_system_for - && fModule->is_sub_system_for(partition->PartitionData())); + && fModule->is_sub_system_for(partition->PartitionData())); } // ValidateResize +//! Validates parameters for resizing a partition bool KPartitioningSystem::ValidateResize(KPartition *partition, off_t *size) { return (partition && size && partition->DiskSystem() == this && fModule - && fModule->validate_resize - && fModule->validate_resize(partition->PartitionData(), size)); + && fModule->validate_resize + && fModule->validate_resize(partition->PartitionData(), size)); } // ValidateResizeChild +//! Validates parameters for resizing a child partition bool KPartitioningSystem::ValidateResizeChild(KPartition *child, off_t *size) { return (child && size && child->Parent() - && child->ParentDiskSystem() == this && fModule - && fModule->validate_resize_child - && fModule->validate_resize_child(child->Parent()->PartitionData(), - child->PartitionData(), size)); + && child->ParentDiskSystem() == this && fModule + && fModule->validate_resize_child + && fModule->validate_resize_child(child->Parent()->PartitionData(), + child->PartitionData(), size)); } // ValidateMove +//! Validates parameters for moving a partition bool KPartitioningSystem::ValidateMove(KPartition *partition, off_t *start) { return (partition && start && partition->DiskSystem() == this && fModule - && fModule->validate_move - && fModule->validate_move(partition->PartitionData(), start)); + && fModule->validate_move + && fModule->validate_move(partition->PartitionData(), start)); } // ValidateMoveChild +//! Validates parameters for moving a child partition bool KPartitioningSystem::ValidateMoveChild(KPartition *child, off_t *start) { return (child && start && child->Parent() - && child->ParentDiskSystem() == this && fModule - && fModule->validate_move_child - && fModule->validate_move_child(child->Parent()->PartitionData(), - child->PartitionData(), start)); + && child->ParentDiskSystem() == this && fModule + && fModule->validate_move_child + && fModule->validate_move_child(child->Parent()->PartitionData(), + child->PartitionData(), start)); } // ValidateSetName +//! Validates parameters for setting name of a partition bool KPartitioningSystem::ValidateSetName(KPartition *partition, char *name) { return (partition && name && partition->Parent() - && partition->ParentDiskSystem() == this && fModule - && fModule->validate_set_name - && fModule->validate_set_name(partition->PartitionData(), name)); + && partition->ParentDiskSystem() == this && fModule + && fModule->validate_set_name + && fModule->validate_set_name(partition->PartitionData(), name)); } // ValidateSetContentName +//! Validates parameters for setting name of the content of a partition bool KPartitioningSystem::ValidateSetContentName(KPartition *partition, char *name) { return (partition && name && partition->DiskSystem() == this - && fModule && fModule->validate_set_content_name - && fModule->validate_set_content_name(partition->PartitionData(), - name)); + && fModule && fModule->validate_set_content_name + && fModule->validate_set_content_name(partition->PartitionData(), + name)); } // ValidateSetType +//! Validates parameters for setting type of a partition bool KPartitioningSystem::ValidateSetType(KPartition *partition, const char *type) { return (partition && type && partition->ParentDiskSystem() == this - && fModule && fModule->validate_set_type - && fModule->validate_set_type(partition->PartitionData(), type)); + && fModule && fModule->validate_set_type + && fModule->validate_set_type(partition->PartitionData(), type)); } // ValidateSetParameters +//! Validates parameters for setting parameters of a partition bool KPartitioningSystem::ValidateSetParameters(KPartition *partition, - const char *parameters) + const char *parameters) { return (partition && partition->ParentDiskSystem() == this - && fModule && fModule->validate_set_parameters - && fModule->validate_set_parameters(partition->PartitionData(), - parameters)); + && fModule && fModule->validate_set_parameters + && fModule->validate_set_parameters(partition->PartitionData(), + parameters)); } // ValidateSetContentParameters +//! Validates parameters for setting parameters of the content of a partition bool KPartitioningSystem::ValidateSetContentParameters(KPartition *partition, - const char *parameters) + const char *parameters) { return (partition && partition->DiskSystem() == this && fModule && fModule->validate_set_content_parameters @@ -379,33 +416,34 @@ KPartitioningSystem::ValidateSetContentParameters(KPartition *partition, } // ValidateInitialize +//! Validates parameters for initializing a partition bool KPartitioningSystem::ValidateInitialize(KPartition *partition, char *name, - const char *parameters) + const char *parameters) { return (partition && name && fModule && fModule->validate_initialize - && fModule->validate_initialize(partition->PartitionData(), name, - parameters)); + && fModule->validate_initialize(partition->PartitionData(), name, + parameters)); } // ValidateCreateChild +//! Validates parameters for creating child of a partition bool KPartitioningSystem::ValidateCreateChild(KPartition *partition, off_t *start, - off_t *size, const char *type, - const char *parameters, int32 *index) + off_t *size, const char *type, const char *parameters, int32 *index) { int32 _index = 0; if (!index) index = &_index; return (partition && start && size && type - && partition->DiskSystem() == this && fModule - && fModule->validate_create_child - && fModule->validate_create_child(partition->PartitionData(), - start, size, type, parameters, - index)); + && partition->DiskSystem() == this && fModule + && fModule->validate_create_child + && fModule->validate_create_child(partition->PartitionData(), start, + size, type, parameters, index)); } // CountPartitionableSpaces +//! Counts partitionable spaces on a partition int32 KPartitioningSystem::CountPartitionableSpaces(KPartition *partition) { @@ -422,10 +460,10 @@ KPartitioningSystem::CountPartitionableSpaces(KPartition *partition) } // GetPartitionableSpaces +//! Retrieves a list of partitionable spaces on a partition status_t KPartitioningSystem::GetPartitionableSpaces(KPartition *partition, - partitionable_space_data *buffer, - int32 count, int32 *actualCount) + partitionable_space_data *buffer, int32 count, int32 *actualCount) { if (!partition || partition->DiskSystem() != this || count > 0 && !buffer || !actualCount || !fModule) { @@ -436,13 +474,14 @@ KPartitioningSystem::GetPartitionableSpaces(KPartition *partition, return B_ENTRY_NOT_FOUND; } return fModule->get_partitionable_spaces(partition->PartitionData(), - buffer, count, actualCount); + buffer, count, actualCount); } // GetNextSupportedType +//! Iterates through supported partition types status_t KPartitioningSystem::GetNextSupportedType(KPartition *partition, int32 *cookie, - char *type) + char *type) { if (!partition || partition->DiskSystem() != this || !cookie || !type || !fModule) { @@ -455,6 +494,7 @@ KPartitioningSystem::GetNextSupportedType(KPartition *partition, int32 *cookie, } // GetTypeForContentType +//! Translates the "pretty" content type to an internal type status_t KPartitioningSystem::GetTypeForContentType(const char *contentType, char *type) { @@ -466,9 +506,10 @@ KPartitioningSystem::GetTypeForContentType(const char *contentType, char *type) } // ShadowPartitionChanged +//! Calls for additional modifications when shadow partition is changed status_t KPartitioningSystem::ShadowPartitionChanged(KPartition *partition, - uint32 operation) + uint32 operation) { if (!partition) return B_BAD_VALUE; @@ -482,6 +523,7 @@ KPartitioningSystem::ShadowPartitionChanged(KPartition *partition, } // Repair +//! Repairs a partition status_t KPartitioningSystem::Repair(KPartition *partition, bool checkOnly, KDiskDeviceJob *job) @@ -491,15 +533,17 @@ KPartitioningSystem::Repair(KPartition *partition, bool checkOnly, } // Resize +//! Resizes a partition status_t KPartitioningSystem::Resize(KPartition *partition, off_t size, - KDiskDeviceJob *job) + KDiskDeviceJob *job) { // check parameters if (!partition || !job || size < 0) return B_BAD_VALUE; if (!fModule->resize) return B_ENTRY_NOT_FOUND; + // lock partition and open partition device KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KPartition *_partition = manager->WriteLockPartition(partition->ID()); @@ -516,23 +560,27 @@ KPartitioningSystem::Resize(KPartition *partition, off_t size, if (result != B_OK) return result; } + // let the module do its job status_t result = fModule->resize(fd, partition->ID(), size, job->ID()); + // cleanup and return close(fd); return result; } // ResizeChild +//! Resizes child of a partition status_t KPartitioningSystem::ResizeChild(KPartition *child, off_t size, - KDiskDeviceJob *job) + KDiskDeviceJob *job) { // check parameters if (!child || !job || !child->Parent() || size < 0) return B_BAD_VALUE; if (!fModule->resize_child) return B_ENTRY_NOT_FOUND; + // lock partition and open (parent) partition device KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KPartition *_partition = manager->WriteLockPartition(child->ID()); @@ -550,23 +598,27 @@ KPartitioningSystem::ResizeChild(KPartition *child, off_t size, if (result != B_OK) return result; } + // let the module do its job status_t result = fModule->resize_child(fd, child->ID(), size, job->ID()); + // cleanup and return close(fd); return result; } // Move +//! Moves a partition status_t KPartitioningSystem::Move(KPartition *partition, off_t offset, - KDiskDeviceJob *job) + KDiskDeviceJob *job) { // check parameters if (!partition || !job) return B_BAD_VALUE; if (!fModule->move) return B_ENTRY_NOT_FOUND; + // lock partition and open partition device KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KPartition *_partition = manager->WriteLockPartition(partition->ID()); @@ -583,23 +635,27 @@ KPartitioningSystem::Move(KPartition *partition, off_t offset, if (result != B_OK) return result; } + // let the module do its job status_t result = fModule->move(fd, partition->ID(), offset, job->ID()); + // cleanup and return close(fd); return result; } // MoveChild +//! Moves child of a partition status_t KPartitioningSystem::MoveChild(KPartition *child, off_t offset, - KDiskDeviceJob *job) + KDiskDeviceJob *job) { // check parameters if (!child || !job || !child->Parent()) return B_BAD_VALUE; if (!fModule->move_child) return B_ENTRY_NOT_FOUND; + // lock partition and open (parent) partition device KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KPartition *_partition = manager->WriteLockPartition(child->ID()); @@ -617,23 +673,28 @@ KPartitioningSystem::MoveChild(KPartition *child, off_t offset, if (result != B_OK) return result; } + // 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 close(fd); return result; } // SetName +//! Sets name of a partition status_t KPartitioningSystem::SetName(KPartition *partition, char *name, - KDiskDeviceJob *job) + KDiskDeviceJob *job) { // check parameters if (!partition || !job || !name) return B_BAD_VALUE; if (!fModule->set_name) return B_ENTRY_NOT_FOUND; + // lock partition and open partition device KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KPartition *_partition = manager->WriteLockPartition(partition->ID()); @@ -650,23 +711,27 @@ KPartitioningSystem::SetName(KPartition *partition, char *name, if (result != B_OK) return result; } + // let the module do its job status_t result = fModule->set_name(fd, partition->ID(), name, job->ID()); + // cleanup and return close(fd); return result; } // SetContentName +//! Sets name of the content of a partition status_t KPartitioningSystem::SetContentName(KPartition *partition, char *name, - KDiskDeviceJob *job) + KDiskDeviceJob *job) { // check parameters if (!partition || !job || !name) return B_BAD_VALUE; if (!fModule->set_content_name) return B_ENTRY_NOT_FOUND; + // lock partition and open partition device KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KPartition *_partition = manager->WriteLockPartition(partition->ID()); @@ -683,23 +748,28 @@ KPartitioningSystem::SetContentName(KPartition *partition, char *name, if (result != B_OK) return result; } + // 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 close(fd); return result; } // SetType +//! Sets type of a partition status_t KPartitioningSystem::SetType(KPartition *partition, char *type, - KDiskDeviceJob *job) + KDiskDeviceJob *job) { // check parameters if (!partition || !job || !type) return B_BAD_VALUE; if (!fModule->set_type) return B_ENTRY_NOT_FOUND; + // lock partition and open partition device KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KPartition *_partition = manager->WriteLockPartition(partition->ID()); @@ -716,23 +786,27 @@ KPartitioningSystem::SetType(KPartition *partition, char *type, if (result != B_OK) return result; } + // let the module do its job status_t result = fModule->set_type(fd, partition->ID(), type, job->ID()); + // cleanup and return close(fd); return result; } // SetParameters +//! Sets parameters of a partition status_t KPartitioningSystem::SetParameters(KPartition *partition, - const char *parameters, KDiskDeviceJob *job) + const char *parameters, KDiskDeviceJob *job) { // check parameters if (!partition || !job || !parameters) return B_BAD_VALUE; if (!fModule->set_parameters) return B_ENTRY_NOT_FOUND; + // lock partition and open partition device KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KPartition *_partition = manager->WriteLockPartition(partition->ID()); @@ -749,24 +823,28 @@ KPartitioningSystem::SetParameters(KPartition *partition, if (result != B_OK) return result; } + // 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 close(fd); return result; } // SetContentParameters +//! Sets parameters of the content of a partition status_t KPartitioningSystem::SetContentParameters(KPartition *partition, - const char *parameters, - KDiskDeviceJob *job) + const char *parameters, KDiskDeviceJob *job) { // check parameters if (!partition || !job || !parameters) return B_BAD_VALUE; if (!fModule->set_content_parameters) return B_ENTRY_NOT_FOUND; + // lock partition and open partition device KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KPartition *_partition = manager->WriteLockPartition(partition->ID()); @@ -783,23 +861,28 @@ KPartitioningSystem::SetContentParameters(KPartition *partition, if (result != B_OK) return result; } + // 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 close(fd); return result; } // Initialize +//! Initializes a partition with this partitioning system status_t KPartitioningSystem::Initialize(KPartition *partition, const char *name, - const char *parameters, KDiskDeviceJob *job) + const char *parameters, KDiskDeviceJob *job) { // check parameters if (!partition || !job || !name /*|| !parameters*/) return B_BAD_VALUE; if (!fModule->initialize) return B_ENTRY_NOT_FOUND; + // lock partition and open partition device KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KPartition *_partition = manager->WriteLockPartition(partition->ID()); @@ -816,25 +899,29 @@ KPartitioningSystem::Initialize(KPartition *partition, const char *name, if (result != B_OK) return result; } + // 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 close(fd); return result; } // CreateChild +//! Creates a child partition status_t KPartitioningSystem::CreateChild(KPartition *partition, off_t offset, - off_t size, const char *type, - const char *parameters, KDiskDeviceJob *job, - KPartition **child, partition_id childID) + off_t size, const char *type, const char *parameters, KDiskDeviceJob *job, + KPartition **child, partition_id childID) { // check parameters if (!partition || !job || !type /*|| !parameters*/ || !child) return B_BAD_VALUE; if (!fModule->create_child) return B_ENTRY_NOT_FOUND; + // lock partition and open partition device KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KPartition *_partition = manager->WriteLockPartition(partition->ID()); @@ -851,9 +938,10 @@ KPartitioningSystem::CreateChild(KPartition *partition, off_t offset, if (result != B_OK) return result; } + // let the module do its job status_t result = fModule->create_child(fd, partition->ID(), offset, size, - type, parameters, job->ID(), &childID); + type, parameters, job->ID(), &childID); // find and return the child *child = manager->FindPartition(childID, false); @@ -864,6 +952,7 @@ KPartitioningSystem::CreateChild(KPartition *partition, off_t offset, } // DeleteChild +//! Deletes a child partition status_t KPartitioningSystem::DeleteChild(KPartition *child, KDiskDeviceJob *job) { @@ -889,4 +978,3 @@ KPartitioningSystem::UnloadModule() fModule = NULL; } } - diff --git a/src/system/kernel/disk_device_manager/ddm_userland_interface.cpp b/src/system/kernel/disk_device_manager/ddm_userland_interface.cpp index 8f04e61b68..8411835903 100644 --- a/src/system/kernel/disk_device_manager/ddm_userland_interface.cpp +++ b/src/system/kernel/disk_device_manager/ddm_userland_interface.cpp @@ -973,7 +973,7 @@ _user_validate_initialize_partition(partition_id partitionID, diskSystemName, name, parameters); } if (!error) - error = ddm_strlcpy(name, _name, B_DISK_DEVICE_NAME_LENGTH); + error = ddm_strlcpy(_name, name, B_DISK_DEVICE_NAME_LENGTH); free(parameters); return error; } diff --git a/src/system/kernel/disk_device_manager/jobs/KCreateChildJob.cpp b/src/system/kernel/disk_device_manager/jobs/KCreateChildJob.cpp index a53af21c4d..098d4256a4 100644 --- a/src/system/kernel/disk_device_manager/jobs/KCreateChildJob.cpp +++ b/src/system/kernel/disk_device_manager/jobs/KCreateChildJob.cpp @@ -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 + * Lubos Kulic + */ #include "KCreateChildJob.h" - #include #include #include @@ -16,99 +22,108 @@ #include "ddm_operation_validation.h" +/** + Creates the job. -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 : strcpy ( new char[strlen(type)+1], type ) ), - fParameters( !parameters ? NULL : strcpy( new char[strlen(parameters)+1], parameters ) ) + \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::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" ); } -KCreateChildJob::~KCreateChildJob() {} + +KCreateChildJob::~KCreateChildJob() +{ + free(fType); + free(fParameters); +} + /** * Do the actual creation * * \note in time of calling the \c KDiskSystem function for creating child, the partition is NOT locked */ -status_t KCreateChildJob::Do() { - KDiskDeviceManager * manager = KDiskDeviceManager::Default(); - - KPartition * partition = manager->WriteLockPartition( PartitionID() ); - - if( partition ) { +status_t +KCreateChildJob::Do() +{ + KDiskDeviceManager* manager = KDiskDeviceManager::Default(); + + KPartition* partition = manager->WriteLockPartition(PartitionID()); + + if (partition) { PartitionRegistrar registrar(partition, true); PartitionRegistrar deviceRegistrar(partition->Device(), true); - + DeviceWriteLocker locker(partition->Device(), true); - - + if (!partition->DiskSystem()) { SetErrorMessage("Partition has no disk system!"); return B_BAD_VALUE; } - - - + // all descendants should be marked busy/descendant busy - if ( isPartitionNotBusy( partition ) ) { + if (IsPartitionNotBusy(partition)) { SetErrorMessage("Can't create child of non-busy partition!"); return B_ERROR; } - - - KPartition * childPartition = manager->WriteLockPartition( fChildID ); - if( !childPartition ) { - //TODO + + KPartition* childPartition = manager->WriteLockPartition(fChildID); + if (!childPartition) { + // TODO } - - + off_t newOffset = fOffset; off_t newSize = fSize; - - - status_t validation_result = validate_create_child_partition ( - partition, partition->ChangeCounter(), - &newOffset, &fSize, fType, - fParameters, NULL, false - ); - - if( validation_result != B_OK ) { - SetErrorMessage( "Validating of creating new child failed!" ); - return validation_result; + status_t validationResult = validate_create_child_partition( + partition, partition->ChangeCounter(), + &newOffset, &fSize, fType, + fParameters, NULL, false); + + if (validationResult != B_OK) { + SetErrorMessage("Validating of creating new child failed!"); + return validationResult; } - - if( newOffset != fOffset ) { - SetErrorMessage( "Requested offset is not valid." ); + + if (newOffset != fOffset) { + SetErrorMessage("Requested offset is not valid."); return B_ERROR; } - - if( newSize != fSize ) { - SetErrorMessage( "Requested size is not valid" ); + + if (newSize != fSize) { + SetErrorMessage("Requested size is not valid"); } - + KDiskSystem *diskSystem = partition->DiskSystem(); DiskSystemLoader loader(diskSystem); - KPartition * newChild = 0; - + KPartition *newChild = 0; + locker.Unlock(); - - status_t create_result = diskSystem->CreateChild( - partition, newOffset, newSize, fType, - fParameters, this, &newChild, fChildID ); - - if( create_result != B_OK ) { - SetErrorMessage( "Creating new partition child failed!" ); - return create_result; + + status_t createResult = diskSystem->CreateChild(partition, newOffset, + newSize, fType, fParameters, this, &newChild, fChildID); + + if (createResult != B_OK) { + SetErrorMessage("Creating new partition child failed!"); + return createResult; } - + return B_OK; } else { - SetErrorMessage( "Couldn't find partition." ); + SetErrorMessage("Couldn't find partition."); return B_ENTRY_NOT_FOUND; } } diff --git a/src/system/kernel/disk_device_manager/jobs/KCreateChildJob.h b/src/system/kernel/disk_device_manager/jobs/KCreateChildJob.h index 629d1d073c..85118cb442 100644 --- a/src/system/kernel/disk_device_manager/jobs/KCreateChildJob.h +++ b/src/system/kernel/disk_device_manager/jobs/KCreateChildJob.h @@ -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 + * Lubos Kulic + */ #ifndef _K_DISK_DEVICE_CREATE_CHILD_JOB_H #define _K_DISK_DEVICE_CREATE_CHILD_JOB_H @@ -13,26 +19,18 @@ namespace DiskDevice { */ class KCreateChildJob : public KDiskDeviceJob { 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, - off_t size, const char *type, const char *parameters); + off_t size, const char *type, const char *parameters); virtual ~KCreateChildJob(); virtual status_t Do(); private: - partition_id fChildID; - off_t fOffset, fSize; - char * fType; - char * fParameters; + partition_id fChildID; + off_t fOffset; + off_t fSize; + char* fType; + char* fParameters; }; diff --git a/src/system/kernel/disk_device_manager/jobs/KDefragmentJob.cpp b/src/system/kernel/disk_device_manager/jobs/KDefragmentJob.cpp index 2c88448ba6..1902f7894f 100644 --- a/src/system/kernel/disk_device_manager/jobs/KDefragmentJob.cpp +++ b/src/system/kernel/disk_device_manager/jobs/KDefragmentJob.cpp @@ -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 + * Lubos Kulic + */ #include "KDefragmentJob.h" @@ -16,77 +23,83 @@ #include "ddm_operation_validation.h" +/** + Creates the job + + \param partition which device should we defragment +*/ 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(); - - KPartition * partition = manager->WriteLockPartition( PartitionID() ); - - if( partition ) { + +status_t +KDefragmentJob::Do() +{ + KDiskDeviceManager* manager = KDiskDeviceManager::Default(); + + KPartition* partition = manager->WriteLockPartition(PartitionID()); + + if (partition) { PartitionRegistrar registrar(partition, true); PartitionRegistrar deviceRegistrar(partition->Device(), true); - + DeviceWriteLocker locker(partition->Device(), true); - - //some basic checks - + + // some basic checks + if (!partition->DiskSystem()) { SetErrorMessage("Partition has no disk system!"); return B_BAD_VALUE; } - - + // all descendants should be marked busy/descendant busy - if ( isPartitionNotBusy( partition ) ) { + if (IsPartitionNotBusy(partition) ) { SetErrorMessage("Can't defragment non-busy partition!"); return B_ERROR; } - + bool whileMounted; - //OK, seems alright, let's validate the job - status_t validation_result = validate_defragment_partition( - partition, partition->ChangeCounter(), - &whileMounted, false); - - if( validation_result != B_OK ) { - SetErrorMessage( "Validation of defragmenting partition failed."); - return validation_result; + // OK, seems alright, let's validate the job + status_t validationResult = validate_defragment_partition( + partition, partition->ChangeCounter(), &whileMounted, false); + + if (validationResult != B_OK) { + SetErrorMessage("Validation of defragmenting partition failed."); + return validationResult; } - - if( !whileMounted && partition->IsMounted() ) { - SetErrorMessage( "This partition cannot be defragmented while mounted." ); + + if (!whileMounted && partition->IsMounted()) { + SetErrorMessage("This partition cannot be defragmented while " + "mounted." ); return B_ERROR; } - - //everything OK, let's do the job! - + + // everything OK, let's do the job! + KDiskSystem *diskSystem = partition->DiskSystem(); DiskSystemLoader loader(diskSystem); - + locker.Unlock(); - - status_t defrag_result = diskSystem->Defragment( partition, this ); - - if( defrag_result != B_OK ) { - SetErrorMessage( "Defragmenting partition failed!" ); - return defrag_result; + + status_t defragResult = diskSystem->Defragment(partition, this); + + if (defragResult != B_OK) { + SetErrorMessage("Defragmenting partition failed!"); + return defragResult; } - + return B_OK; - - + } else { - SetErrorMessage( "Couldn't find partition!" ); + SetErrorMessage("Couldn't find partition!"); return B_ENTRY_NOT_FOUND; } - } diff --git a/src/system/kernel/disk_device_manager/jobs/KDefragmentJob.h b/src/system/kernel/disk_device_manager/jobs/KDefragmentJob.h index d3f3230ccd..0a05eb3e3c 100644 --- a/src/system/kernel/disk_device_manager/jobs/KDefragmentJob.h +++ b/src/system/kernel/disk_device_manager/jobs/KDefragmentJob.h @@ -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 + * Lubos Kulic + */ #ifndef _K_DISK_DEVICE_DEFRAGMENT_JOB_H #define _K_DISK_DEVICE_DEFRAGMENT_JOB_H @@ -13,12 +19,6 @@ namespace DiskDevice { */ class KDefragmentJob : public KDiskDeviceJob { public: - /** - * Creates the job - * - * \param partition which device should we defragment - */ - KDefragmentJob(partition_id partition); virtual ~KDefragmentJob(); diff --git a/src/system/kernel/disk_device_manager/jobs/KDeleteChildJob.cpp b/src/system/kernel/disk_device_manager/jobs/KDeleteChildJob.cpp index db471ffe59..43739aee37 100644 --- a/src/system/kernel/disk_device_manager/jobs/KDeleteChildJob.cpp +++ b/src/system/kernel/disk_device_manager/jobs/KDeleteChildJob.cpp @@ -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 + * Lubos Kulic + */ #include "KDeleteChildJob.h" - - #include #include #include @@ -17,64 +22,73 @@ #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) - : 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(){ - KDiskDeviceManager * manager = KDiskDeviceManager::Default(); - - KPartition * partition = manager->WriteLockPartition( PartitionID() ); - - if( partition ) { +KDeleteChildJob::~KDeleteChildJob() +{ +} + + +status_t +KDeleteChildJob::Do() +{ + KDiskDeviceManager* manager = KDiskDeviceManager::Default(); + + KPartition* partition = manager->WriteLockPartition(PartitionID()); + + if (partition) { PartitionRegistrar registrar(partition, true); PartitionRegistrar deviceRegistrar(partition->Device(), true); - + DeviceWriteLocker locker(partition->Device(), true); - - + if (!partition->ParentDiskSystem()) { SetErrorMessage("Partition has no parent disk system!"); return B_BAD_VALUE; } - + // all descendants should be marked busy/descendant busy - if ( isPartitionNotBusy( partition ) ) { + if (IsPartitionNotBusy( partition)) { SetErrorMessage("Can't delete child of non-busy partition!"); return B_ERROR; } - - status_t validation_result = validate_delete_child_partition( - partition, partition->ChangeCounter(), - false); - - if( validation_result != B_OK ) { - SetErrorMessage( "Validation of deleting child failed!" ); - return validation_result; + + status_t validationResult = validate_delete_child_partition( + partition, partition->ChangeCounter(), false); + + if (validationResult != B_OK) { + SetErrorMessage("Validation of deleting child failed!"); + return validationResult; } - - //everything OK, let's do the job! + + // everything OK, let's do the job! KDiskSystem *parentDiskSystem = partition->ParentDiskSystem(); DiskSystemLoader loader(parentDiskSystem ); - + locker.Unlock(); - - status_t delete_result = parentDiskSystem->DeleteChild( partition, this ); - - if( delete_result != B_OK ) { - SetErrorMessage( "Deleting child failed!" ); - return delete_result; + + status_t deleteResult = parentDiskSystem->DeleteChild(partition, this); + + if (deleteResult != B_OK) { + SetErrorMessage("Deleting child failed!"); + return deleteResult; } - + return B_OK; - + } else { - SetErrorMessage( "Couldn't find partition!" ); + SetErrorMessage("Couldn't find partition!"); return B_ENTRY_NOT_FOUND; } } diff --git a/src/system/kernel/disk_device_manager/jobs/KDeleteChildJob.h b/src/system/kernel/disk_device_manager/jobs/KDeleteChildJob.h index 67955dd26e..d857556116 100644 --- a/src/system/kernel/disk_device_manager/jobs/KDeleteChildJob.h +++ b/src/system/kernel/disk_device_manager/jobs/KDeleteChildJob.h @@ -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 + * Lubos Kulic + */ #ifndef _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 { 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); virtual ~KDeleteChildJob(); diff --git a/src/system/kernel/disk_device_manager/jobs/KInitializeJob.cpp b/src/system/kernel/disk_device_manager/jobs/KInitializeJob.cpp index a090dad555..b441cc5a91 100644 --- a/src/system/kernel/disk_device_manager/jobs/KInitializeJob.cpp +++ b/src/system/kernel/disk_device_manager/jobs/KInitializeJob.cpp @@ -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 + * Lubos Kulic + */ #include @@ -21,85 +28,97 @@ #define OUT dprintf -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 : strcpy( new char[strlen(name)+1], name ) ), - fParameters( !parameters ? NULL : strcpy( new char[strlen(parameters)+1], parameters ) ) +/*! + 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::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())); KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KPartition *partition = manager->WriteLockPartition(PartitionID()); if (partition) { PartitionRegistrar registrar(partition, true); PartitionRegistrar deviceRegistrar(partition->Device(), true); - + DeviceWriteLocker locker(partition->Device(), true); // basic checks - + // if (!partition->ParentDiskSystem()) { // SetErrorMessage("Partition has no parent disk system!"); // return B_BAD_VALUE; // } - + // all descendants should be marked busy/descendant busy - if ( isPartitionNotBusy( partition ) ) { + if (IsPartitionNotBusy(partition)) { SetErrorMessage("Can't initialize non-busy partition!"); return B_ERROR; } - -/* if( !fParameters ) { + +/* if (!fParameters) { //no parameters for the operation SetErrorMessage( "No parameters for partition initialization." ); return B_ERROR; }*/ - - - //TODO shouldn't we load the disk system AFTER the validation? - KDiskSystem *diskSystemToInit = manager->LoadDiskSystem( fDiskSystemID ); - if( ! diskSystemToInit ) { - SetErrorMessage( "Given DiskSystemID doesn't correspond to any known DiskSystem."); + + // TODO shouldn't we load the disk system AFTER the validation? + KDiskSystem *diskSystemToInit = manager->LoadDiskSystem(fDiskSystemID); + if (!diskSystemToInit) { + SetErrorMessage("Given DiskSystemID doesn't correspond to any " + "known DiskSystem."); return B_BAD_VALUE; } DiskSystemLoader loader2(diskSystemToInit); - - status_t validation_result = validate_initialize_partition( - partition, partition->ChangeCounter(), - diskSystemToInit->Name(), fName, - fParameters, false ); - - if( validation_result != B_OK ) { - SetErrorMessage( "Validation of initializing partition failed!" ); - return validation_result; + +// TODO: The parameters are already validated and should not be changed again! + status_t validationResult = validate_initialize_partition(partition, + partition->ChangeCounter(), diskSystemToInit->Name(), fName, + fParameters, false); + + if (validationResult != B_OK) { + SetErrorMessage("Validation of initializing partition failed!"); + return validationResult; } - - //everything seems OK -> let's do the job + + // everything seems OK -> let's do the job locker.Unlock(); - - status_t init_result = diskSystemToInit->Initialize( partition, fName, fParameters, this ); - - if( init_result != B_OK ) { - SetErrorMessage( "Initialization of partition failed!" ); - return init_result; + + status_t initResult = diskSystemToInit->Initialize(partition, fName, + fParameters, this); + + if (initResult != B_OK) { + SetErrorMessage("Initialization of partition failed!"); + return initResult; } - + partition->SetDiskSystem(diskSystemToInit); - + return B_OK; - - + } else { - SetErrorMessage( "Couldn't find partition." ); + SetErrorMessage("Couldn't find partition."); return B_ENTRY_NOT_FOUND; } - } diff --git a/src/system/kernel/disk_device_manager/jobs/KInitializeJob.h b/src/system/kernel/disk_device_manager/jobs/KInitializeJob.h index f66b498a43..c697eb8b03 100644 --- a/src/system/kernel/disk_device_manager/jobs/KInitializeJob.h +++ b/src/system/kernel/disk_device_manager/jobs/KInitializeJob.h @@ -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 + * Lubos Kulic + */ #ifndef _K_DISK_DEVICE_INITIALIZE_JOB_H #define _K_DISK_DEVICE_INITIALIZE_JOB_H @@ -13,13 +19,6 @@ namespace DiskDevice { */ class KInitializeJob : public KDiskDeviceJob { 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, const char *name, const char *parameters); virtual ~KInitializeJob(); diff --git a/src/system/kernel/disk_device_manager/jobs/KMoveJob.cpp b/src/system/kernel/disk_device_manager/jobs/KMoveJob.cpp index 85953ecca6..bf8a086cdd 100644 --- a/src/system/kernel/disk_device_manager/jobs/KMoveJob.cpp +++ b/src/system/kernel/disk_device_manager/jobs/KMoveJob.cpp @@ -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 + * Lubos Kulic + */ + #include "KMoveJob.h" #include @@ -15,84 +23,95 @@ #include "ddm_operation_validation.h" - // debugging //#define DBG(x) #define DBG(x) x #define OUT dprintf -KMoveJob::KMoveJob(partition_id parentID, partition_id partitionID, off_t offset) - : KDiskDeviceJob(B_DISK_DEVICE_JOB_MOVE, partitionID, parentID ), - fNewOffset(offset) + +/** + 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) { - 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() )); - - //get the partition - KDiskDeviceManager * manager = KDiskDeviceManager::Default(); + + // get the partition + KDiskDeviceManager* manager = KDiskDeviceManager::Default(); KPartition *partition = manager->WriteLockPartition(PartitionID()); if (partition) { - //OK, we have the partition, do some checks + // OK, we have the partition, do some checks PartitionRegistrar registrar(partition, true); PartitionRegistrar deviceRegistrar(partition->Device(), true); - + DeviceWriteLocker locker(partition->Device(), true); - + // basic checks if (!partition->ParentDiskSystem()) { SetErrorMessage("Partition has no parent disk system!"); return B_BAD_VALUE; } - - if(partition->Offset() == fNewOffset ) { - //we are already on the right place -> nothing to do... + + if (partition->Offset() == fNewOffset) { + // we are already on the right place -> nothing to do... return B_OK; } - - off_t new_offset = fNewOffset; - - status_t validate_result = validate_move_partition(partition, partition->ChangeCounter(), - &new_offset, true, false ); //TODO posledni 2 parametry???? - if( validate_result != B_OK ) { - SetErrorMessage( "Validation of the new partition offset failed." ); - return validate_result; + + off_t newOffset = fNewOffset; + + status_t validateResult = validate_move_partition(partition, + partition->ChangeCounter(), &newOffset, true, false); + // TODO posledni 2 parametry???? + // TODO: Huh? + if (validateResult != B_OK) { + SetErrorMessage("Validation of the new partition offset failed."); + return validateResult; } - - if( new_offset != fNewOffset ) { - SetErrorMessage( "Requested partition offset not valid." ); + + if (newOffset != fNewOffset) { + SetErrorMessage("Requested partition offset not valid."); return B_ERROR; } - + // all descendants should be marked busy/descendant busy - if ( isPartitionNotBusy( partition ) ) { + if (IsPartitionNotBusy(partition)) { SetErrorMessage("Can't move non-busy partition!"); return B_ERROR; } - - //get all necessary objects + + // get all necessary objects KDiskSystem *parentDiskSystem = partition->ParentDiskSystem(); KDiskSystem *childDiskSystem = partition->DiskSystem(); - - + locker.Unlock(); - - status_t move_result = parentDiskSystem->Move( partition, fNewOffset, this ); - if( move_result != B_OK ) { - SetErrorMessage( "Moving of partition failed." ); + + status_t moveResult = parentDiskSystem->Move(partition, fNewOffset, + this); + if (moveResult != B_OK) { + SetErrorMessage("Moving of partition failed."); } - return move_result; - //do the move - + return moveResult; + } else { SetErrorMessage("Couldn't find partition."); return B_ENTRY_NOT_FOUND; } - return B_ERROR; } diff --git a/src/system/kernel/disk_device_manager/jobs/KMoveJob.h b/src/system/kernel/disk_device_manager/jobs/KMoveJob.h index f525d34c58..30fa7c8e73 100644 --- a/src/system/kernel/disk_device_manager/jobs/KMoveJob.h +++ b/src/system/kernel/disk_device_manager/jobs/KMoveJob.h @@ -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 + * Lubos Kulic + */ #ifndef _K_DISK_DEVICE_MOVE_JOB_H #define _K_DISK_DEVICE_MOVE_JOB_H #include "KDiskDeviceJob.h" + namespace BPrivate { namespace DiskDevice { @@ -13,19 +20,11 @@ namespace DiskDevice { */ class KMoveJob : public KDiskDeviceJob { 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); virtual ~KMoveJob(); virtual status_t Do(); - - + private: off_t fNewOffset; }; diff --git a/src/system/kernel/disk_device_manager/jobs/KRepairJob.cpp b/src/system/kernel/disk_device_manager/jobs/KRepairJob.cpp index 0a6ad415f0..6d89ec872f 100644 --- a/src/system/kernel/disk_device_manager/jobs/KRepairJob.cpp +++ b/src/system/kernel/disk_device_manager/jobs/KRepairJob.cpp @@ -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 + * Lubos Kulic + */ #include "KRepairJob.h" - #include #include #include @@ -16,80 +22,80 @@ #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) - : KDiskDeviceJob( B_DISK_DEVICE_JOB_REPAIR, partition, partition ), - fCheckOnly( checkOnly ) + : KDiskDeviceJob(B_DISK_DEVICE_JOB_REPAIR, partition, partition), + fCheckOnly( checkOnly ) { - SetDescription( "repairing partition" ); + SetDescription("repairing partition"); } -KRepairJob::~KRepairJob() {} -status_t KRepairJob::Do(){ - - KDiskDeviceManager * manager = KDiskDeviceManager::Default(); - - KPartition * partition = manager->WriteLockPartition( PartitionID() ); - - if( partition ) { + +KRepairJob::~KRepairJob() +{ +} + + +status_t +KRepairJob::Do() +{ + KDiskDeviceManager* manager = KDiskDeviceManager::Default(); + + KPartition* partition = manager->WriteLockPartition(PartitionID()); + + if (partition) { PartitionRegistrar registrar(partition, true); PartitionRegistrar deviceRegistrar(partition->Device(), true); - + DeviceWriteLocker locker(partition->Device(), true); - - //basic checks - if( !partition->DiskSystem() ) { - SetErrorMessage( "Partition has no disk system." ); + + // basic checks + if (!partition->DiskSystem()) { + SetErrorMessage("Partition has no disk system."); return B_BAD_VALUE; } - - if ( isPartitionNotBusy( partition ) ) { + + if (IsPartitionNotBusy(partition)) { SetErrorMessage("Can't repair non-busy partition!"); return B_ERROR; } - + bool whileMounted; - - status_t validation_result = validate_repair_partition( - partition, partition->ChangeCounter(), - fCheckOnly, &whileMounted, - false); - - if( validation_result != B_OK ) { - SetErrorMessage( "Validation repairing partition failed!" ); - return validation_result; + status_t validationResult = validate_repair_partition(partition, + partition->ChangeCounter(), fCheckOnly, &whileMounted, false); + + if (validationResult != B_OK) { + SetErrorMessage("Validation repairing partition failed!"); + return validationResult; } - - //everything OK, let's do the job - KDiskSystem * diskSystem = partition->DiskSystem(); + + // everything OK, let's do the job + KDiskSystem* diskSystem = partition->DiskSystem(); DiskSystemLoader loader(diskSystem); - + locker.Unlock(); - - status_t repair_result = diskSystem->Repair( partition, fCheckOnly, this ); - - if( repair_result != B_OK ) { - if( fCheckOnly ) { - SetErrorMessage( "Checking for repairing partition failed!" ); + + status_t repairResult = diskSystem->Repair(partition, fCheckOnly, this); + + if (repairResult != B_OK) { + if (fCheckOnly) { + SetErrorMessage("Checking for repairing partition failed!"); } else { - SetErrorMessage( "Repairing partition failed!" ); + SetErrorMessage("Repairing partition failed!"); } - return repair_result; + return repairResult; } - + return B_OK; - - }else { - SetErrorMessage( "Couldn't find partition!" ); + + } else { + SetErrorMessage("Couldn't find partition!"); return B_ENTRY_NOT_FOUND; } - - - - - - } diff --git a/src/system/kernel/disk_device_manager/jobs/KRepairJob.h b/src/system/kernel/disk_device_manager/jobs/KRepairJob.h index 421d9cd0d1..b47dbdc77d 100644 --- a/src/system/kernel/disk_device_manager/jobs/KRepairJob.h +++ b/src/system/kernel/disk_device_manager/jobs/KRepairJob.h @@ -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 + * Lubos Kulic + */ #ifndef _K_DISK_DEVICE_REPAIR_JOB_H #define _K_DISK_DEVICE_REPAIR_JOB_H #include "KDiskDeviceJob.h" + namespace BPrivate { namespace DiskDevice { @@ -13,13 +20,6 @@ namespace DiskDevice { */ class KRepairJob : public KDiskDeviceJob { 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); virtual ~KRepairJob(); diff --git a/src/system/kernel/disk_device_manager/jobs/KResizeJob.cpp b/src/system/kernel/disk_device_manager/jobs/KResizeJob.cpp index 48e8fce06d..f719982184 100644 --- a/src/system/kernel/disk_device_manager/jobs/KResizeJob.cpp +++ b/src/system/kernel/disk_device_manager/jobs/KResizeJob.cpp @@ -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 + */ #include @@ -14,30 +20,42 @@ #include "ddm_operation_validation.h" #include "KResizeJob.h" + // debugging //#define DBG(x) #define DBG(x) x #define OUT dprintf + // 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, - off_t size) + off_t size) : KDiskDeviceJob(B_DISK_DEVICE_JOB_RESIZE, partitionID, parentID), fSize(size) { SetDescription("resizing partition"); } + // destructor KResizeJob::~KResizeJob() { } + // Do status_t KResizeJob::Do() { DBG(OUT("KResizeJob::Do(%ld)\n", PartitionID())); + // get the partition KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KPartition *partition = manager->WriteLockPartition(PartitionID()); @@ -45,14 +63,17 @@ KResizeJob::Do() PartitionRegistrar registrar(partition, true); PartitionRegistrar deviceRegistrar(partition->Device(), true); DeviceWriteLocker locker(partition->Device(), true); + // basic checks if (!partition->ParentDiskSystem()) { SetErrorMessage("Partition has no parent disk system!"); return B_BAD_VALUE; } + // if size remains the same, then nothing's to do if (partition->Size() == fSize) return B_OK; + // check new size off_t size = fSize; off_t contentSize = fSize; @@ -66,6 +87,7 @@ KResizeJob::Do() SetErrorMessage("Requested size is not valid."); return B_ERROR; } + // all descendants should be marked busy/descendant busy struct IsNotBusyVisitor : KPartitionVisitor { virtual bool VisitPre(KPartition *partition) @@ -77,6 +99,7 @@ KResizeJob::Do() SetErrorMessage("Can't resize non-busy partition!"); return B_ERROR; } + // things look good: get all infos needed for resizing KDiskSystem *parentDiskSystem = partition->ParentDiskSystem(); KDiskSystem *childDiskSystem = partition->DiskSystem(); @@ -84,34 +107,39 @@ KResizeJob::Do() DiskSystemLoader loader2(childDiskSystem); off_t oldSize = partition->Size(); off_t oldContentSize = partition->ContentSize(); + // unlock the device and resize the beast locker.Unset(); + // if growing, resize partition first if (oldSize < fSize) { status_t error = parentDiskSystem->ResizeChild(partition, fSize, - this); + this); if (error != B_OK) return error; } + // resize contents if (childDiskSystem && oldContentSize != contentSize) { status_t error = childDiskSystem->Resize(partition, contentSize, - this); + this); if (error != B_OK) return error; } + // if shrinking, resize partition last if (oldSize > fSize) { status_t error = parentDiskSystem->ResizeChild(partition, fSize, - this); + this); if (error != B_OK) return error; } + + return B_OK; + } else { SetErrorMessage("Couldn't find partition."); return B_ENTRY_NOT_FOUND; } - // cannot come here - return B_ERROR; } diff --git a/src/system/kernel/disk_device_manager/jobs/KResizeJob.h b/src/system/kernel/disk_device_manager/jobs/KResizeJob.h index 606be1d7c9..6c6c5109dc 100644 --- a/src/system/kernel/disk_device_manager/jobs/KResizeJob.h +++ b/src/system/kernel/disk_device_manager/jobs/KResizeJob.h @@ -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 + */ #ifndef _K_DISK_DEVICE_RESIZE_JOB_H #define _K_DISK_DEVICE_RESIZE_JOB_H @@ -13,13 +18,6 @@ namespace DiskDevice { */ class KResizeJob : public KDiskDeviceJob { 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); virtual ~KResizeJob(); diff --git a/src/system/kernel/disk_device_manager/jobs/KScanPartitionJob.cpp b/src/system/kernel/disk_device_manager/jobs/KScanPartitionJob.cpp index 383fc83f18..f6ced112da 100644 --- a/src/system/kernel/disk_device_manager/jobs/KScanPartitionJob.cpp +++ b/src/system/kernel/disk_device_manager/jobs/KScanPartitionJob.cpp @@ -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 + */ #include @@ -18,6 +24,11 @@ #define OUT dprintf +/** + Creates the job. + + \param partitionID the partition to scan +*/ KScanPartitionJob::KScanPartitionJob(partition_id partitionID) : KDiskDeviceJob(B_DISK_DEVICE_JOB_SCAN, partitionID) { @@ -33,12 +44,6 @@ KScanPartitionJob::~KScanPartitionJob() status_t KScanPartitionJob::Do() { -/*#ifdef _BOOT_MODE - OUT( "\nScanJob boot mode\n\n" ); -#else - OUT( "\nScanJob NOT boot mode\n\n" ); -#endif*/ - // get the partition KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KPartition *partition = manager->WriteLockPartition(PartitionID()); diff --git a/src/system/kernel/disk_device_manager/jobs/KScanPartitionJob.h b/src/system/kernel/disk_device_manager/jobs/KScanPartitionJob.h index a33b48261f..3033fce99f 100644 --- a/src/system/kernel/disk_device_manager/jobs/KScanPartitionJob.h +++ b/src/system/kernel/disk_device_manager/jobs/KScanPartitionJob.h @@ -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 + */ #ifndef _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 { public: - /** - * Creates the job. - * - * \param partitionID the partition to scan - */ KScanPartitionJob(partition_id partitionID); virtual ~KScanPartitionJob(); virtual status_t Do(); private: - /** - * Do the actual scan. - */ status_t _ScanPartition(KPartition *partition); }; diff --git a/src/system/kernel/disk_device_manager/jobs/KSetNameJob.cpp b/src/system/kernel/disk_device_manager/jobs/KSetNameJob.cpp index 5a9f727b22..2b913092b4 100644 --- a/src/system/kernel/disk_device_manager/jobs/KSetNameJob.cpp +++ b/src/system/kernel/disk_device_manager/jobs/KSetNameJob.cpp @@ -1,3 +1,10 @@ +/* + * Copyright 2007, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Lubos Kulic + */ #include "KSetNameJob.h" @@ -14,122 +21,128 @@ #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), - fName( !name ? NULL : strcpy( new char[strlen(name)+1], name ) ), - fContentName( !contentName ? NULL : strcpy( new char[strlen(contentName)+1], contentName ) ) + fName(!name ? NULL : strdup(name)), + 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() { - delete[] fName; - delete[] fContentName; + free(fName); + free(fContentName); } -status_t KSetNameJob::Do() { - KDiskDeviceManager * manager = KDiskDeviceManager::Default(); - - KPartition * partition = manager->WriteLockPartition( PartitionID() ); - if( partition ) { - if( !fName && !fContentName ) { - SetErrorMessage( "No name to set." ); +status_t +KSetNameJob::Do() +{ + KDiskDeviceManager* manager = KDiskDeviceManager::Default(); + + KPartition* partition = manager->WriteLockPartition(PartitionID()); + if (partition) { + if (!fName && !fContentName) { + SetErrorMessage("No name to set."); return B_BAD_VALUE; } - + PartitionRegistrar registrar(partition, true); PartitionRegistrar deviceRegistrar(partition->Device(), true); - - //TODO is lock necessary? + + // TODO is lock necessary? DeviceWriteLocker locker(partition->Device(), true); - - //basic checks - + + // basic checks + // all descendants should be marked busy/descendant busy - if ( isPartitionNotBusy( partition ) ) { + if (IsPartitionNotBusy(partition)) { SetErrorMessage("Can't set name for non-busy partition!"); return B_ERROR; } - - if( fName ) { - //set name of the partition - - //setting name of this partition -> via our parent disk system - if( !partition->ParentDiskSystem() ) { - SetErrorMessage( "Partition has no parent disk system!" ); + + if (fName) { + // set name of the partition + + // setting name of this partition -> via our parent disk system + if (!partition->ParentDiskSystem()) { + SetErrorMessage("Partition has no parent disk system!"); return B_BAD_VALUE; } - - //TODO mayebe give copy of name - status_t validation_result = validate_set_partition_name( - partition, partition->ChangeCounter(), - fName, false); - - if( validation_result != B_OK) { + + // TODO maybe give copy of name +// TODO: The parameters are already validated and should not be changed again! + status_t validationResult = validate_set_partition_name( + partition, partition->ChangeCounter(), fName, false); + + if( validationResult != B_OK) { SetErrorMessage( "Validation of setting partition name failed!" ); - return validation_result; + return validationResult; } - - //everything OK, let's do the job - KDiskSystem * parentDiskSystem = partition->ParentDiskSystem(); - + + // everything OK, let's do the job + KDiskSystem* parentDiskSystem = partition->ParentDiskSystem(); + DiskSystemLoader loader(parentDiskSystem); - + locker.Unlock(); - - status_t set_name_result = parentDiskSystem->SetName(partition, fName, this); - - if( set_name_result != B_OK ) { + + status_t setNameResult = parentDiskSystem->SetName(partition, fName, + this); + if (setNameResult != B_OK) { SetErrorMessage( "Setting name of the partition failed!" ); } - return set_name_result; - + return setNameResult; } - - if( fContentName ) { - //set name of the contents - - //setting name of our contents -> via our disk system - if( !partition->DiskSystem() ) { + + if (fContentName) { + // set name of the contents + + // setting name of our contents -> via our disk system + if (!partition->DiskSystem()) { SetErrorMessage( "Partition has no disk system!"); return B_BAD_VALUE; } - - status_t validation_result = validate_set_partition_content_name( - partition, partition->ChangeCounter(), - fContentName, false); - - if( validation_result != B_OK ) { - SetErrorMessage( "Validation of setting partition content name failed!" ); - return validation_result; + +// TODO: The parameters are already validated and should not be changed again! + status_t validationResult = validate_set_partition_content_name( + partition, partition->ChangeCounter(), fContentName, false); + + if (validationResult != B_OK) { + SetErrorMessage("Validation of setting partition content name " + "failed!"); + return validationResult; } - - //everything OK, let's do the job - - KDiskSystem * diskSystem = partition->DiskSystem(); - DiskSystemLoader loader( diskSystem ); - + + // everything OK, let's do the job + + KDiskSystem* diskSystem = partition->DiskSystem(); + DiskSystemLoader loader(diskSystem); + locker.Unlock(); - - status_t set_cont_name_result = diskSystem->SetContentName( - partition, fContentName, this); - - if( set_cont_name_result != B_OK ) { - SetErrorMessage( "Setting name of the partition's content failed!" ); + + status_t result = diskSystem->SetContentName(partition, + fContentName, this); + if (result != B_OK) { + SetErrorMessage("Setting name of the partition's content " + "failed!" ); } - return set_cont_name_result; - + return result; } - - } else { - SetErrorMessage( "Couldn't find partition!" ); + SetErrorMessage("Couldn't find partition!"); return B_ENTRY_NOT_FOUND; } - - + + return B_ERROR; } diff --git a/src/system/kernel/disk_device_manager/jobs/KSetNameJob.h b/src/system/kernel/disk_device_manager/jobs/KSetNameJob.h index 3627a71803..36965c95af 100644 --- a/src/system/kernel/disk_device_manager/jobs/KSetNameJob.h +++ b/src/system/kernel/disk_device_manager/jobs/KSetNameJob.h @@ -1,3 +1,10 @@ +/* + * Copyright 2007, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Lubos Kulic + */ #ifndef _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 * set only one of the names */ -class KSetNameJob : public KDiskDeviceJob -{ +class KSetNameJob : public KDiskDeviceJob { public: - /** - * 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(partition_id parentID, partition_id partitionID, const char * name, - const char * contentName); - + KSetNameJob(partition_id parentID, partition_id partitionID, + const char* name, const char* contentName); virtual ~KSetNameJob(); virtual status_t Do(); private: - char * fName, *fContentName; - - + char* fName; + char* fContentName; }; } - } using BPrivate::DiskDevice::KSetNameJob; diff --git a/src/system/kernel/disk_device_manager/jobs/KSetParametersJob.cpp b/src/system/kernel/disk_device_manager/jobs/KSetParametersJob.cpp index e46d172c4b..0f610a78fc 100644 --- a/src/system/kernel/disk_device_manager/jobs/KSetParametersJob.cpp +++ b/src/system/kernel/disk_device_manager/jobs/KSetParametersJob.cpp @@ -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 + * Lubos Kulic + */ #include #include @@ -18,112 +23,123 @@ #include "ddm_operation_validation.h" +/** + Creates the job. -KSetParametersJob::KSetParametersJob(partition_id parent, partition_id partition, - const char *parameters, const char *contentParameters) + \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::KSetParametersJob(partition_id parent, + partition_id partition, const char *parameters, + const char *contentParameters) : KDiskDeviceJob(B_DISK_DEVICE_JOB_SET_TYPE, partition, parent), - fParams( !parameters ? NULL : strcpy( new char[strlen(parameters)+1], parameters )), - fContentParams( - !contentParameters ? NULL : - strcpy( new char[strlen(contentParameters)+1], contentParameters)) + fParams(!parameters ? NULL : strdup(parameters)), + fContentParams(!contentParameters ? NULL : strdup(contentParameters)) { - SetDescription( "setting partition parameters&content parameters" ); + SetDescription("setting partition parameters&content parameters"); } - - -KSetParametersJob::~KSetParametersJob(){} -status_t KSetParametersJob::Do(){ + +KSetParametersJob::~KSetParametersJob() +{ + free(fParams); + free(fContentParams); +} + + +status_t +KSetParametersJob::Do() +{ KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KPartition *partition = manager->WriteLockPartition(PartitionID()); if (partition) { - if( !fParams && !fContentParams ) { - SetErrorMessage( "No parameter to set." ); + if (!fParams && !fContentParams) { + SetErrorMessage("No parameter to set."); return B_BAD_VALUE; } PartitionRegistrar registrar(partition, true); PartitionRegistrar deviceRegistrar(partition->Device(), true); - - //TODO is lock necessary? + + // TODO is lock necessary? DeviceWriteLocker locker(partition->Device(), true); - - - - + // all descendants should be marked busy/descendant busy - if ( isPartitionNotBusy( partition ) ) { + if (IsPartitionNotBusy(partition)) { SetErrorMessage("Can't set parameters for non-busy partition!"); return B_ERROR; } - - //TODO unlock? - - if( fParams ) { + + // TODO unlock? + + if (fParams) { // basic checks - + if (!partition->ParentDiskSystem()) { SetErrorMessage("Partition has no parent disk system!"); return B_BAD_VALUE; } - //TODO mayebe give copy of parameters? - //we have some parameters to set - status_t validation_result = validate_set_partition_parameters( partition, partition->ChangeCounter(), fParams, false ); - + // TODO maybe give copy of parameters? + // we have some parameters to set +// 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(); DiskSystemLoader loader(parentDiskSystem); - - if( validation_result != B_OK ) { - SetErrorMessage( "Validation of setting partition parameters failed." ); - return validation_result; + + if (validationResult != B_OK) { + SetErrorMessage("Validation of setting partition parameters " + "failed."); + return validationResult; } - + locker.Unlock(); - status_t set_pars_result = parentDiskSystem->SetParameters( partition, fParams, this ); - - if( set_pars_result != B_OK ) { + status_t setParametersResult = parentDiskSystem->SetParameters( + partition, fParams, this); + + if (setParametersResult != B_OK) { SetErrorMessage( "Setting partition parameters failed." ); } } - - - if( fContentParams ) { + + if (fContentParams) { // basic checks - + if (!partition->DiskSystem()) { SetErrorMessage("Partition has no disk system!"); return B_BAD_VALUE; } - - - - status_t validation_result = validate_set_partition_content_parameters ( - partition, partition->ChangeCounter(), fContentParams, false ); - - if( validation_result != B_OK ) { - SetErrorMessage( "Validation of setting partition content parameters failed." ); - return validation_result; + +// 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) { + SetErrorMessage("Validation of setting partition content " + "parameters failed."); + return validationResult; } - + KDiskSystem *diskSystem = partition->DiskSystem(); DiskSystemLoader loader(diskSystem); - + locker.Unlock(); - status_t set_cont_pars_result = diskSystem->SetContentParameters( - partition, fContentParams, this ); - - if( set_cont_pars_result != B_OK ) { - SetErrorMessage( "Setting partition content parameters failed." ); + status_t result = diskSystem->SetContentParameters(partition, + fContentParams, this); + + if (result != B_OK) { + SetErrorMessage("Setting partition content parameters failed."); } } - - +// TODO: Check return values! + return B_OK; - - + } else { SetErrorMessage( "Couldn't find partition" ); return B_ENTRY_NOT_FOUND; } - } diff --git a/src/system/kernel/disk_device_manager/jobs/KSetParametersJob.h b/src/system/kernel/disk_device_manager/jobs/KSetParametersJob.h index efcad338ea..c2605c78dc 100644 --- a/src/system/kernel/disk_device_manager/jobs/KSetParametersJob.h +++ b/src/system/kernel/disk_device_manager/jobs/KSetParametersJob.h @@ -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 + * Lubos Kulic + */ #ifndef _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 { 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, const char *parameters, const char *contentParameters); virtual ~KSetParametersJob(); diff --git a/src/system/kernel/disk_device_manager/jobs/KSetTypeJob.cpp b/src/system/kernel/disk_device_manager/jobs/KSetTypeJob.cpp index 5ce4318dea..b613fdd0f7 100644 --- a/src/system/kernel/disk_device_manager/jobs/KSetTypeJob.cpp +++ b/src/system/kernel/disk_device_manager/jobs/KSetTypeJob.cpp @@ -1,15 +1,10 @@ -// -// C++ Implementation: KSetTypeJob -// -// Description: -// -// -// Author: , (C) 2007 -// -// Copyright: See COPYING file that comes with this distribution -// -// - +/* + * Copyright 2007, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Lubos Kulic + */ #include #include @@ -26,64 +21,76 @@ #include "KSetTypeJob.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), - 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() ); - - if( partition ) { + +status_t +KSetTypeJob::Do() +{ + KDiskDeviceManager* manager = KDiskDeviceManager::Default(); + + KPartition* partition = manager->WriteLockPartition(PartitionID()); + + if (partition) { PartitionRegistrar registrar(partition, true); PartitionRegistrar deviceRegistrar(partition->Device(), true); - - //TODO is lock necessary? + + // TODO is lock necessary? DeviceWriteLocker locker(partition->Device(), true); - - //basic checks - if( !partition->ParentDiskSystem() ) { - SetErrorMessage( "Partition has no parent disk system!" ); + + // basic checks + if (!partition->ParentDiskSystem()) { + SetErrorMessage("Partition has no parent disk system!"); return B_BAD_VALUE; } - - if( !fType ) { - SetErrorMessage( "No type to set!" ); + + if (!fType) { + SetErrorMessage("No type to set!"); return B_BAD_VALUE; } - - status_t validation_result = validate_set_partition_type( - partition, partition->ChangeCounter(), - fType, false); - - if( validation_result != B_OK ) { - SetErrorMessage( "Validation of setting partition type failed!" ); - return validation_result; + +// TODO: The parameters are already validated and should not be changed again! + status_t validationResult = validate_set_partition_type( + partition, partition->ChangeCounter(), fType, false); + if (validationResult != B_OK) { + SetErrorMessage("Validation of setting partition type failed!"); + return validationResult; } - - //everything OK, let's do the job - KDiskSystem * parentDiskSystem = partition->ParentDiskSystem(); - DiskSystemLoader loader( parentDiskSystem ); - - status_t set_type_result = parentDiskSystem->SetType( partition, fType, this ); - - if( set_type_result != B_OK ) { - SetErrorMessage( "Setting partition type failed!" ); - return set_type_result; + + // everything OK, let's do the job + KDiskSystem* parentDiskSystem = partition->ParentDiskSystem(); + DiskSystemLoader loader(parentDiskSystem); + + status_t setTypeResult = parentDiskSystem->SetType(partition, fType, + this); + + if (setTypeResult != B_OK) { + SetErrorMessage("Setting partition type failed!"); + return setTypeResult; } - + return B_OK; - + } else { - SetErrorMessage( "Couldn't find partition!" ); + SetErrorMessage("Couldn't find partition!"); return B_ENTRY_NOT_FOUND; } - } diff --git a/src/system/kernel/disk_device_manager/jobs/KSetTypeJob.h b/src/system/kernel/disk_device_manager/jobs/KSetTypeJob.h index c4de1ef8b7..7f070d61ed 100644 --- a/src/system/kernel/disk_device_manager/jobs/KSetTypeJob.h +++ b/src/system/kernel/disk_device_manager/jobs/KSetTypeJob.h @@ -1,14 +1,10 @@ -// -// C++ Interface: KSetTypeJob -// -// Description: -// -// -// Author: , (C) 2007 -// -// Copyright: See COPYING file that comes with this distribution -// -// +/* + * Copyright 2007, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Lubos Kulic + */ #ifndef _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 { 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); - virtual ~KSetTypeJob(); virtual status_t Do(); private: char * fType; - }; } - } using BPrivate::DiskDevice::KSetTypeJob; diff --git a/src/system/kernel/disk_device_manager/jobs/KUninitializeJob.cpp b/src/system/kernel/disk_device_manager/jobs/KUninitializeJob.cpp index d4f5eed0bf..e7164f8236 100644 --- a/src/system/kernel/disk_device_manager/jobs/KUninitializeJob.cpp +++ b/src/system/kernel/disk_device_manager/jobs/KUninitializeJob.cpp @@ -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 + */ #include diff --git a/src/system/kernel/disk_device_manager/jobs/KUninitializeJob.h b/src/system/kernel/disk_device_manager/jobs/KUninitializeJob.h index f77b51cd3d..1ed8ae2370 100644 --- a/src/system/kernel/disk_device_manager/jobs/KUninitializeJob.h +++ b/src/system/kernel/disk_device_manager/jobs/KUninitializeJob.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 + */ #ifndef _K_DISK_DEVICE_UNINITIALIZE_JOB_H #define _K_DISK_DEVICE_UNINITIALIZE_JOB_H @@ -13,9 +18,6 @@ namespace DiskDevice { */ class KUninitializeJob : public KDiskDeviceJob { public: - /** - * Creates the job - */ KUninitializeJob(partition_id partitionID); virtual ~KUninitializeJob();