From e098680c08efca556ea15766a2034e13d548fde2 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Fri, 27 Jul 2007 15:37:23 +0000 Subject: [PATCH] Missed those in the previous commit. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21720 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../disk_device_manager/jobs/KSetNameJob.cpp | 135 ++++++++++++++++++ .../disk_device_manager/jobs/KSetNameJob.h | 47 ++++++ .../disk_device_manager/jobs/KSetTypeJob.cpp | 89 ++++++++++++ .../disk_device_manager/jobs/KSetTypeJob.h | 50 +++++++ 4 files changed, 321 insertions(+) create mode 100644 src/system/kernel/disk_device_manager/jobs/KSetNameJob.cpp create mode 100644 src/system/kernel/disk_device_manager/jobs/KSetNameJob.h create mode 100644 src/system/kernel/disk_device_manager/jobs/KSetTypeJob.cpp create mode 100644 src/system/kernel/disk_device_manager/jobs/KSetTypeJob.h diff --git a/src/system/kernel/disk_device_manager/jobs/KSetNameJob.cpp b/src/system/kernel/disk_device_manager/jobs/KSetNameJob.cpp new file mode 100644 index 0000000000..5a9f727b22 --- /dev/null +++ b/src/system/kernel/disk_device_manager/jobs/KSetNameJob.cpp @@ -0,0 +1,135 @@ + +#include "KSetNameJob.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "ddm_operation_validation.h" + + +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 ) ) +{ + SetDescription( "setting name for the partition or its content" ); +} + + +KSetNameJob::~KSetNameJob() +{ + delete[] fName; + delete[] fContentName; +} + + +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? + DeviceWriteLocker locker(partition->Device(), true); + + //basic checks + + // all descendants should be marked busy/descendant busy + 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!" ); + 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) { + SetErrorMessage( "Validation of setting partition name failed!" ); + return validation_result; + } + + //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 ) { + SetErrorMessage( "Setting name of the partition failed!" ); + } + return set_name_result; + + } + + 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; + } + + //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!" ); + } + return set_cont_name_result; + + } + + + } else { + SetErrorMessage( "Couldn't find partition!" ); + return B_ENTRY_NOT_FOUND; + } + + +} diff --git a/src/system/kernel/disk_device_manager/jobs/KSetNameJob.h b/src/system/kernel/disk_device_manager/jobs/KSetNameJob.h new file mode 100644 index 0000000000..3627a71803 --- /dev/null +++ b/src/system/kernel/disk_device_manager/jobs/KSetNameJob.h @@ -0,0 +1,47 @@ +#ifndef _K_DISK_DEVICE_SET_NAME_JOB_H +#define _K_DISK_DEVICE_SET_NAME_JOB_H + +#include + +namespace BPrivate { + +namespace DiskDevice { + +/** + * Sets the name for partition/device and/or its content + * + * - can set both name and content name for the partition - but + * 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 +{ +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); + + virtual ~KSetNameJob(); + + virtual status_t Do(); + +private: + char * fName, *fContentName; + + +}; + +} + +} + +using BPrivate::DiskDevice::KSetNameJob; + +#endif diff --git a/src/system/kernel/disk_device_manager/jobs/KSetTypeJob.cpp b/src/system/kernel/disk_device_manager/jobs/KSetTypeJob.cpp new file mode 100644 index 0000000000..5ce4318dea --- /dev/null +++ b/src/system/kernel/disk_device_manager/jobs/KSetTypeJob.cpp @@ -0,0 +1,89 @@ +// +// C++ Implementation: KSetTypeJob +// +// Description: +// +// +// Author: , (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// + + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include "KSetTypeJob.h" +#include "ddm_operation_validation.h" + +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 ) ) +{ + SetDescription( "setting partition type" ); +} + + +KSetTypeJob::~KSetTypeJob(){} + +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? + DeviceWriteLocker locker(partition->Device(), true); + + //basic checks + if( !partition->ParentDiskSystem() ) { + SetErrorMessage( "Partition has no parent disk system!" ); + return B_BAD_VALUE; + } + + 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; + } + + //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; + } + + return B_OK; + + } else { + 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 new file mode 100644 index 0000000000..c4de1ef8b7 --- /dev/null +++ b/src/system/kernel/disk_device_manager/jobs/KSetTypeJob.h @@ -0,0 +1,50 @@ +// +// C++ Interface: KSetTypeJob +// +// Description: +// +// +// Author: , (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef _K_DISK_DEVICE_SET_TYPE_JOB_H +#define _K_DISK_DEVICE_SET_TYPE_JOB_H + +#include + +namespace BPrivate { + +namespace DiskDevice { + +/** + * Sets type of the device/partition + */ +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; + +#endif