Missed those in the previous commit.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21720 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2007-07-27 15:37:23 +00:00
parent 2dc6403ddc
commit e098680c08
4 changed files with 321 additions and 0 deletions
@@ -0,0 +1,135 @@
#include "KSetNameJob.h"
#include <KernelExport.h>
#include <DiskDeviceDefs.h>
#include <KDiskDevice.h>
#include <KDiskDeviceManager.h>
#include <KDiskDeviceUtils.h>
#include <KDiskSystem.h>
#include <KPartition.h>
#include <KPartitionVisitor.h>
#include <string.h>
#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;
}
}
@@ -0,0 +1,47 @@
#ifndef _K_DISK_DEVICE_SET_NAME_JOB_H
#define _K_DISK_DEVICE_SET_NAME_JOB_H
#include <KDiskDeviceJob.h>
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
@@ -0,0 +1,89 @@
//
// C++ Implementation: KSetTypeJob
//
// Description:
//
//
// Author: <[email protected]>, (C) 2007
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include <KPartition.h>
#include <KernelExport.h>
#include <DiskDeviceDefs.h>
#include <KDiskDevice.h>
#include <KDiskDeviceManager.h>
#include <KDiskDeviceUtils.h>
#include <KDiskSystem.h>
#include <KPartitionVisitor.h>
#include <string.h>
#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;
}
}
@@ -0,0 +1,50 @@
//
// C++ Interface: KSetTypeJob
//
// Description:
//
//
// Author: <[email protected]>, (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 <KDiskDeviceJob.h>
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