From 1844af0bfafd94359561c1a0418319d0f1fcca76 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Mon, 9 Jun 2003 23:10:09 +0000 Subject: [PATCH] Mostly empty implementations for the disk device manager classes. Save KPartition which is partially done. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3455 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/core/Jamfile | 1 + src/kernel/core/disk_device_manager/Jamfile | 31 + .../core/disk_device_manager/KDiskDevice.cpp | 3 + .../disk_device_manager/KDiskDeviceJob.cpp | 3 + .../KDiskDeviceJobFactory.cpp | 3 + .../KDiskDeviceJobQueue.cpp | 3 + .../KDiskDeviceManager.cpp | 3 + .../core/disk_device_manager/KDiskSystem.cpp | 3 + .../core/disk_device_manager/KFileSystem.cpp | 3 + .../core/disk_device_manager/KPartition.cpp | 573 ++++++++++++++++++ .../KPartitioningSystem.cpp | 3 + src/kernel/core/disk_device_manager/List.h | 385 ++++++++++++ .../disk_device_manager.cpp | 3 + .../jobs/KCreateChildJob.cpp | 3 + .../jobs/KCreateChildJob.h | 25 + .../jobs/KDefragmentJob.cpp | 3 + .../disk_device_manager/jobs/KDefragmentJob.h | 24 + .../jobs/KDeleteChildJob.cpp | 3 + .../jobs/KDeleteChildJob.h | 24 + .../jobs/KInitializeJob.cpp | 3 + .../disk_device_manager/jobs/KInitializeJob.h | 25 + .../disk_device_manager/jobs/KMoveJob.cpp | 3 + .../core/disk_device_manager/jobs/KMoveJob.h | 24 + .../disk_device_manager/jobs/KRepairJob.cpp | 3 + .../disk_device_manager/jobs/KRepairJob.h | 24 + .../disk_device_manager/jobs/KResizeJob.cpp | 3 + .../disk_device_manager/jobs/KResizeJob.h | 24 + .../jobs/KScanPartitionJob.cpp | 3 + .../jobs/KScanPartitionJob.h | 24 + .../jobs/KSetParametersJob.cpp | 3 + .../jobs/KSetParametersJob.h | 25 + 31 files changed, 1263 insertions(+) create mode 100644 src/kernel/core/disk_device_manager/Jamfile create mode 100644 src/kernel/core/disk_device_manager/KDiskDevice.cpp create mode 100644 src/kernel/core/disk_device_manager/KDiskDeviceJob.cpp create mode 100644 src/kernel/core/disk_device_manager/KDiskDeviceJobFactory.cpp create mode 100644 src/kernel/core/disk_device_manager/KDiskDeviceJobQueue.cpp create mode 100644 src/kernel/core/disk_device_manager/KDiskDeviceManager.cpp create mode 100644 src/kernel/core/disk_device_manager/KDiskSystem.cpp create mode 100644 src/kernel/core/disk_device_manager/KFileSystem.cpp create mode 100644 src/kernel/core/disk_device_manager/KPartition.cpp create mode 100644 src/kernel/core/disk_device_manager/KPartitioningSystem.cpp create mode 100644 src/kernel/core/disk_device_manager/List.h create mode 100644 src/kernel/core/disk_device_manager/disk_device_manager.cpp create mode 100644 src/kernel/core/disk_device_manager/jobs/KCreateChildJob.cpp create mode 100644 src/kernel/core/disk_device_manager/jobs/KCreateChildJob.h create mode 100644 src/kernel/core/disk_device_manager/jobs/KDefragmentJob.cpp create mode 100644 src/kernel/core/disk_device_manager/jobs/KDefragmentJob.h create mode 100644 src/kernel/core/disk_device_manager/jobs/KDeleteChildJob.cpp create mode 100644 src/kernel/core/disk_device_manager/jobs/KDeleteChildJob.h create mode 100644 src/kernel/core/disk_device_manager/jobs/KInitializeJob.cpp create mode 100644 src/kernel/core/disk_device_manager/jobs/KInitializeJob.h create mode 100644 src/kernel/core/disk_device_manager/jobs/KMoveJob.cpp create mode 100644 src/kernel/core/disk_device_manager/jobs/KMoveJob.h create mode 100644 src/kernel/core/disk_device_manager/jobs/KRepairJob.cpp create mode 100644 src/kernel/core/disk_device_manager/jobs/KRepairJob.h create mode 100644 src/kernel/core/disk_device_manager/jobs/KResizeJob.cpp create mode 100644 src/kernel/core/disk_device_manager/jobs/KResizeJob.h create mode 100644 src/kernel/core/disk_device_manager/jobs/KScanPartitionJob.cpp create mode 100644 src/kernel/core/disk_device_manager/jobs/KScanPartitionJob.h create mode 100644 src/kernel/core/disk_device_manager/jobs/KSetParametersJob.cpp create mode 100644 src/kernel/core/disk_device_manager/jobs/KSetParametersJob.h diff --git a/src/kernel/core/Jamfile b/src/kernel/core/Jamfile index 833cd24407..c929e3510d 100644 --- a/src/kernel/core/Jamfile +++ b/src/kernel/core/Jamfile @@ -45,6 +45,7 @@ KernelLd linkhack.so : SubInclude OBOS_TOP src kernel core addons ; SubInclude OBOS_TOP src kernel core arch ; +SubInclude OBOS_TOP src kernel core disk_device_manager ; SubInclude OBOS_TOP src kernel core fs ; SubInclude OBOS_TOP src kernel core vm ; #SubInclude OBOS_TOP src kernel core net ; diff --git a/src/kernel/core/disk_device_manager/Jamfile b/src/kernel/core/disk_device_manager/Jamfile new file mode 100644 index 0000000000..ce5310cada --- /dev/null +++ b/src/kernel/core/disk_device_manager/Jamfile @@ -0,0 +1,31 @@ +SubDir OBOS_TOP src kernel core disk_device_manager ; + +SEARCH_SOURCE += [ FDirName $(SUBDIR) jobs ] ; + +UsePrivateHeaders [ FDirName kernel disk_device_manager ] ; +UsePrivateHeaders [ FDirName shared ] ; +UsePrivateHeaders [ FDirName storage ] ; + +SharedLibrary disk_device_manager : + KDiskDevice.cpp + KDiskDeviceJob.cpp + KDiskDeviceJobFactory.cpp + KDiskDeviceJobQueue.cpp + KDiskDeviceManager.cpp + KDiskSystem.cpp + KFileSystem.cpp + KPartition.cpp + KPartitioningSystem.cpp + disk_device_manager.cpp + + # jobs + KCreateChildJob.cpp + KDefragmentJob.cpp + KDeleteChildJob.cpp + KInitializeJob.cpp + KMoveJob.cpp + KRepairJob.cpp + KResizeJob.cpp + KScanPartitionJob.cpp + KSetParametersJob.cpp +; diff --git a/src/kernel/core/disk_device_manager/KDiskDevice.cpp b/src/kernel/core/disk_device_manager/KDiskDevice.cpp new file mode 100644 index 0000000000..5ad3612f96 --- /dev/null +++ b/src/kernel/core/disk_device_manager/KDiskDevice.cpp @@ -0,0 +1,3 @@ +// KDiskDevice.cpp + +#include "KDiskDevice.h" diff --git a/src/kernel/core/disk_device_manager/KDiskDeviceJob.cpp b/src/kernel/core/disk_device_manager/KDiskDeviceJob.cpp new file mode 100644 index 0000000000..a985d0edb6 --- /dev/null +++ b/src/kernel/core/disk_device_manager/KDiskDeviceJob.cpp @@ -0,0 +1,3 @@ +// KDiskDeviceJob.cpp + +#include "KDiskDeviceJob.h" diff --git a/src/kernel/core/disk_device_manager/KDiskDeviceJobFactory.cpp b/src/kernel/core/disk_device_manager/KDiskDeviceJobFactory.cpp new file mode 100644 index 0000000000..a985d0edb6 --- /dev/null +++ b/src/kernel/core/disk_device_manager/KDiskDeviceJobFactory.cpp @@ -0,0 +1,3 @@ +// KDiskDeviceJob.cpp + +#include "KDiskDeviceJob.h" diff --git a/src/kernel/core/disk_device_manager/KDiskDeviceJobQueue.cpp b/src/kernel/core/disk_device_manager/KDiskDeviceJobQueue.cpp new file mode 100644 index 0000000000..6b575f2c42 --- /dev/null +++ b/src/kernel/core/disk_device_manager/KDiskDeviceJobQueue.cpp @@ -0,0 +1,3 @@ +// KDiskDeviceJobQueue.cpp + +#include "KDiskDeviceJobQueue.h" diff --git a/src/kernel/core/disk_device_manager/KDiskDeviceManager.cpp b/src/kernel/core/disk_device_manager/KDiskDeviceManager.cpp new file mode 100644 index 0000000000..9a9915942c --- /dev/null +++ b/src/kernel/core/disk_device_manager/KDiskDeviceManager.cpp @@ -0,0 +1,3 @@ +// KDiskDeviceManager.cpp + +#include "KDiskDeviceManager.h" diff --git a/src/kernel/core/disk_device_manager/KDiskSystem.cpp b/src/kernel/core/disk_device_manager/KDiskSystem.cpp new file mode 100644 index 0000000000..068e7328a8 --- /dev/null +++ b/src/kernel/core/disk_device_manager/KDiskSystem.cpp @@ -0,0 +1,3 @@ +// KDiskSystem.cpp + +#include "KDiskSystem.h" diff --git a/src/kernel/core/disk_device_manager/KFileSystem.cpp b/src/kernel/core/disk_device_manager/KFileSystem.cpp new file mode 100644 index 0000000000..bffb0866ba --- /dev/null +++ b/src/kernel/core/disk_device_manager/KFileSystem.cpp @@ -0,0 +1,3 @@ +// KFileSystem.cpp + +#include "KFileSystem.h" diff --git a/src/kernel/core/disk_device_manager/KPartition.cpp b/src/kernel/core/disk_device_manager/KPartition.cpp new file mode 100644 index 0000000000..514a34a23b --- /dev/null +++ b/src/kernel/core/disk_device_manager/KPartition.cpp @@ -0,0 +1,573 @@ +// KPartition.cpp + +#include +#include + +//#include + // TODO: Move the definitions needed in the kernel to a separate header. + +#include "KPartition.h" + +using namespace std; +using BPrivate::DiskDevice::KDiskDevice; +using BPrivate::DiskDevice::KDiskSystem; + +// set_string +// simple helper +static +status_t +set_string(char *&location, const char *newValue) +{ + // unset old value + if (location) { + free(location); + location = NULL; + } + // set new value + status_t error = B_OK; + if (newValue) { + location = strdup(newValue); + if (!location) + error = B_NO_MEMORY; + } + return error; +} + +// constructor +KPartition::KPartition(partition_id id) + : fPartitionData(), + fChildren(), + fDevice(NULL), + fParent(NULL), + fDiskSystem(NULL), + fParentDiskSystem(NULL), + fReferenceCount(0) +{ + fPartitionData.id = id; + fPartitionData.offset = 0; + fPartitionData.size = 0; + fPartitionData.block_size = 0; + fPartitionData.child_count = 0; + fPartitionData.index = -1; + fPartitionData.status = /*B_PARTITION_UNRECOGNIZED*/ 0; + fPartitionData.flags = 0; + fPartitionData.volume = -1; + fPartitionData.name = NULL; + fPartitionData.content_name = NULL; + fPartitionData.type = NULL; + fPartitionData.content_type = NULL; + fPartitionData.parameters = NULL; + fPartitionData.content_parameters = NULL; + fPartitionData.cookie = NULL; + fPartitionData.content_cookie = NULL; +} + +// destructor +KPartition::~KPartition() +{ + free(fPartitionData.name); + free(fPartitionData.content_name); + free(fPartitionData.type); + free(fPartitionData.content_type); + free(fPartitionData.parameters); + free(fPartitionData.content_parameters); +} + +// Register +bool +KPartition::Register() +{ + fReferenceCount++; + return true; +} + +// Unregister +bool +KPartition::Unregister() +{ + fReferenceCount--; + return true; +} + +// CountReferences +int32 +KPartition::CountReferences() const +{ + return fReferenceCount; +} + +// SetBusy +void +KPartition::SetBusy(bool busy) +{ + if (busy) + fPartitionData.flags |= B_PARTITION_BUSY; + else + fPartitionData.flags &= ~B_PARTITION_BUSY; +} + +// IsBusy +bool +KPartition::IsBusy() const +{ + return (fPartitionData.flags & B_PARTITION_BUSY); +} + +// SetDescendantBusy +void +KPartition::SetDescendantBusy(bool busy) +{ + if (busy) + fPartitionData.flags |= B_PARTITION_DESCENDANT_BUSY; + else + fPartitionData.flags &= ~B_PARTITION_DESCENDANT_BUSY; +} + +// IsDescendantBusy +bool +KPartition::IsDescendantBusy() const +{ + return (fPartitionData.flags & B_PARTITION_DESCENDANT_BUSY); +} + +// SetOffset +void +KPartition::SetOffset(off_t offset) +{ + fPartitionData.offset = offset; +} + +// Offset +off_t +KPartition::Offset() const +{ + return fPartitionData.offset; +} + +// SetSize +void +KPartition::SetSize(off_t size) +{ + fPartitionData.size = size; +} + +// Size +off_t +KPartition::Size() const +{ + return fPartitionData.size; +} + +// SetBlockSize +void +KPartition::SetBlockSize(uint32 blockSize) +{ + fPartitionData.block_size = blockSize; +} + +// BlockSize +uint32 +KPartition::BlockSize() const +{ + return fPartitionData.block_size; +} + +// SetIndex +void +KPartition::SetIndex(int32 index) +{ + fPartitionData.index = index; +} + +// Index +int32 +KPartition::Index() const +{ + return fPartitionData.index; +} + +// SetStatus +void +KPartition::SetStatus(uint32 status) +{ + fPartitionData.status = status; +} + +// Status +uint32 +KPartition::Status() const +{ + return fPartitionData.status; +} + +// SetFlags +void +KPartition::SetFlags(uint32 flags) +{ + fPartitionData.flags = flags; +} + +// Flags +uint32 +KPartition::Flags() const +{ + return fPartitionData.flags; +} + +// IsMountable +bool +KPartition::IsMountable() const +{ + return (fPartitionData.flags & B_PARTITION_MOUNTABLE); +} + +// IsPartitionable +bool +KPartition::IsPartitionable() const +{ + return (fPartitionData.flags & B_PARTITION_PARTITIONABLE); +} + +// IsReadOnly +bool +KPartition::IsReadOnly() const +{ + return (fPartitionData.flags & B_PARTITION_READ_ONLY); +} + +// IsMounted +bool +KPartition::IsMounted() const +{ + return (fPartitionData.flags & B_PARTITION_MOUNTED); +} + +// IsDevice +bool +KPartition::IsDevice() const +{ + return (fPartitionData.flags & B_PARTITION_IS_DEVICE); +} + +// SetName +status_t +KPartition::SetName(const char *name) +{ + return set_string(fPartitionData.name, name); +} + +// Name +const char * +KPartition::Name() const +{ + return fPartitionData.name; +} + +// SetContentName +status_t +KPartition::SetContentName(const char *name) +{ + return set_string(fPartitionData.content_name, name); +} + +// ContentName +const char * +KPartition::ContentName() const +{ + return fPartitionData.content_name; +} + +// SetType +status_t +KPartition::SetType(const char *type) +{ + return set_string(fPartitionData.type, type); +} + +// Type +const char * +KPartition::Type() const +{ + return fPartitionData.type; +} + +// SetContentType +status_t +KPartition::SetContentType(const char *type) +{ + return set_string(fPartitionData.content_type, type); +} + +// ContentType +const char * +KPartition::ContentType() const +{ + return fPartitionData.content_type; +} + +// PartitionData +partition_data * +KPartition::PartitionData() +{ + return &fPartitionData; +} + +// PartitionData +const partition_data * +KPartition::PartitionData() const +{ + return &fPartitionData; +} + +// SetID +void +KPartition::SetID(partition_id id) +{ + fPartitionData.id = id; +} + +// ID +partition_id +KPartition::ID() const +{ + return fPartitionData.id; +} + +// ChangeCounter +int32 +KPartition::ChangeCounter() const +{ +} + +// GetPath +status_t +KPartition::GetPath(char *path) const +{ + // not implemented + return B_ERROR; +} + +// SetVolumeID +void +KPartition::SetVolumeID(dev_t volumeID) +{ + fPartitionData.volume = volumeID; +} + +// VolumeID +dev_t +KPartition::VolumeID() const +{ + return fPartitionData.id; +} + +// Mount +status_t +KPartition::Mount(uint32 mountFlags, const char *parameters) +{ + // not implemented + return B_ERROR; +} + +// Unmount +status_t +KPartition::Unmount() +{ + // not implemented + return B_ERROR; +} + +// SetParameters +status_t +KPartition::SetParameters(const char *parameters) +{ + return set_string(fPartitionData.parameters, parameters); +} + +// Parameters +const char * +KPartition::Parameters() const +{ + return fPartitionData.parameters; +} + +// SetContentParameters +status_t +KPartition::SetContentParameters(const char *parameters) +{ + return set_string(fPartitionData.content_parameters, parameters); +} + +// ContentParameters +const char * +KPartition::ContentParameters() const +{ + return fPartitionData.content_parameters; +} + +// SetDevice +void +KPartition::SetDevice(KDiskDevice *device) +{ + fDevice = device; +} + +// Device +KDiskDevice * +KPartition::Device() const +{ + return fDevice; +} + +// SetParent +void +KPartition::SetParent(KPartition *parent) +{ + fParent = parent; +} + +// Parent +KPartition * +KPartition::Parent() const +{ + return fParent; +} + +// AddChild +status_t +KPartition::AddChild(KPartition *partition, int32 index) +{ + // check parameters + int32 count = fPartitionData.child_count; + if (index == -1) + index = count; + if (index < 0 || index > count || !partition) + return B_BAD_VALUE; + // add partition +// TODO: Lock the disk device manager! + if (!fChildren.AddItem(partition, index)) + return B_NO_MEMORY; + fPartitionData.child_count++; + partition->SetParent(this); + partition->SetDevice(Device()); + return B_OK; +} + +// RemoveChild +KPartition * +KPartition::RemoveChild(int32 index) +{ + KPartition *partition = NULL; + if (index >= 0 && index < fPartitionData.child_count) { +// TODO: Lock the disk device manager! + partition = fChildren.ItemAt(index); + if (partition && fChildren.RemoveItem(index)) { + fPartitionData.child_count--; + partition->SetParent(NULL); + partition->SetDevice(NULL); + } + } + return partition; +} + +// ChildAt +KPartition * +KPartition::ChildAt(int32 index) const +{ + return fChildren.ItemAt(index); +} + +// CountChildren +int32 +KPartition::CountChildren() const +{ + return fPartitionData.child_count; +} + +// CreateShadowPartition +KPartition * +KPartition::CreateShadowPartition() +{ + // not implemented + return NULL; +} + +// DeleteShadowPartition +void +KPartition::DeleteShadowPartition() +{ + // not implemented +} + +// ShadowPartition +KPartition * +KPartition::ShadowPartition() const +{ + // not implemented + return NULL; +} + +// IsShadowPartition +bool +KPartition::IsShadowPartition() const +{ + // not implemented + return false; +} + +// SetDiskSystem +void +KPartition::SetDiskSystem(KDiskSystem *diskSystem) +{ + fDiskSystem = diskSystem; +} + +// DiskSystem +KDiskSystem * +KPartition::DiskSystem() const +{ + return fDiskSystem; +} + +// SetParentDiskSystem +void +KPartition::SetParentDiskSystem(KDiskSystem *diskSystem) +{ + fParentDiskSystem = diskSystem; +} + +// ParentDiskSystem +KDiskSystem * +KPartition::ParentDiskSystem() const +{ + return fParentDiskSystem; +} + +// SetCookie +void +KPartition::SetCookie(void *cookie) +{ + fPartitionData.cookie = cookie; +} + +// Cookie +void * +KPartition::Cookie() const +{ + return fPartitionData.cookie; +} + +// SetContentCookie +void +KPartition::SetContentCookie(void *cookie) +{ + fPartitionData.content_cookie = cookie; +} + +// ContentCookie +void * +KPartition::ContentCookie() const +{ + return fPartitionData.content_cookie; +} + diff --git a/src/kernel/core/disk_device_manager/KPartitioningSystem.cpp b/src/kernel/core/disk_device_manager/KPartitioningSystem.cpp new file mode 100644 index 0000000000..c82d65a0b8 --- /dev/null +++ b/src/kernel/core/disk_device_manager/KPartitioningSystem.cpp @@ -0,0 +1,3 @@ +// KPartitioningSystem.cpp + +#include "KPartitioningSystem.h" diff --git a/src/kernel/core/disk_device_manager/List.h b/src/kernel/core/disk_device_manager/List.h new file mode 100644 index 0000000000..21aeb87533 --- /dev/null +++ b/src/kernel/core/disk_device_manager/List.h @@ -0,0 +1,385 @@ +// List.h +// +// Copyright (c) 2003, Ingo Weinhold (bonefish@cs.tu-berlin.de) +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// +// Except as contained in this notice, the name of a copyright holder shall +// not be used in advertising or otherwise to promote the sale, use or other +// dealings in this Software without prior written authorization of the +// copyright holder. + +#ifndef LIST_H +#define LIST_H + +#include +#include +#include + +#include + +template +class DefaultDefaultItemCreator { +public: + static inline ITEM GetItem() { return ITEM(0); } +}; + +/*! + \class List + \brief A generic list implementation. +*/ +template > +class List { +public: + typedef ITEM item_t; + typedef List list_t; + +private: + static item_t sDefaultItem; + static const size_t kDefaultChunkSize = 10; + static const size_t kMaximalChunkSize = 1024 * 1024; + +public: + List(size_t chunkSize = kDefaultChunkSize); + ~List(); + + inline const item_t &GetDefaultItem() const; + inline item_t &GetDefaultItem(); + + bool AddItem(const item_t &item, int32 index); + bool AddItem(const item_t &item); +// bool AddList(list_t *list, int32 index); +// bool AddList(list_t *list); + + bool RemoveItem(const item_t &item); + bool RemoveItem(int32 index); + + bool ReplaceItem(int32 index, const item_t &item); + + bool MoveItem(int32 oldIndex, int32 newIndex); + + void MakeEmpty(); + + int32 CountItems() const; + bool IsEmpty() const; + const item_t &ItemAt(int32 index) const; + item_t &ItemAt(int32 index); + const item_t *Items() const; + int32 IndexOf(const item_t &item) const; + bool HasItem(const item_t &item) const; + + // debugging + int32 GetCapacity() const { return fCapacity; } + +private: + inline static void _MoveItems(item_t* items, int32 offset, int32 count); + bool _Resize(size_t count); + +private: + size_t fCapacity; + size_t fChunkSize; + int32 fItemCount; + item_t *fItems; +}; + +// sDefaultItem +template +List::item_t + List::sDefaultItem( + DEFAULT_ITEM_SUPPLIER::GetItem()); + +// constructor +template +List::List(size_t chunkSize) + : fCapacity(0), + fChunkSize(chunkSize), + fItemCount(0), + fItems(NULL) +{ + if (fChunkSize == 0 || fChunkSize > kMaximalChunkSize) + fChunkSize = kDefaultChunkSize; + _Resize(0); +} + +// destructor +template +List::~List() +{ + MakeEmpty(); + free(fItems); +} + +// GetDefaultItem +template +inline +const List::item_t & +List::GetDefaultItem() const +{ + return sDefaultItem; +} + +// GetDefaultItem +template +inline +List::item_t & +List::GetDefaultItem() +{ + return sDefaultItem; +} + +// _MoveItems +template +inline +void +List::_MoveItems(item_t* items, int32 offset, int32 count) +{ + if (count > 0 && offset != 0) + memmove(items + offset, items, count * sizeof(item_t)); +} + +// AddItem +template +bool +List::AddItem(const item_t &item, int32 index) +{ + bool result = (index >= 0 && index <= fItemCount + && _Resize(fItemCount + 1)); + if (result) { + _MoveItems(fItems + index, 1, fItemCount - index - 1); + new(fItems + index) item_t(item); + } + return result; +} + +// AddItem +template +bool +List::AddItem(const item_t &item) +{ + bool result = true; + if ((int32)fCapacity > fItemCount) { + new(fItems + fItemCount) item_t(item); + fItemCount++; + } else { + if ((result = _Resize(fItemCount + 1))) + new(fItems + (fItemCount - 1)) item_t(item); + } + return result; +} + +// These don't use the copy constructor! +/* +// AddList +template +bool +List::AddList(list_t *list, int32 index) +{ + bool result = (list && index >= 0 && index <= fItemCount); + if (result && list->fItemCount > 0) { + int32 count = list->fItemCount; + result = _Resize(fItemCount + count); + if (result) { + _MoveItems(fItems + index, count, fItemCount - index - count); + memcpy(fItems + index, list->fItems, + list->fItemCount * sizeof(item_t)); + } + } + return result; +} + +// AddList +template +bool +List::AddList(list_t *list) +{ + bool result = (list); + if (result && list->fItemCount > 0) { + int32 index = fItemCount; + int32 count = list->fItemCount; + result = _Resize(fItemCount + count); + if (result) { + memcpy(fItems + index, list->fItems, + list->fItemCount * sizeof(item_t)); + } + } + return result; +} +*/ + +// RemoveItem +template +bool +List::RemoveItem(const item_t &item) +{ + int32 index = IndexOf(item); + bool result = (index >= 0); + if (result) + RemoveItem(index); + return result; +} + +// RemoveItem +template +bool +List::RemoveItem(int32 index) +{ + if (index >= 0 && index < fItemCount) { + fItems[index].~item_t(); + _MoveItems(fItems + index + 1, -1, fItemCount - index - 1); + _Resize(fItemCount - 1); + return true; + } + return false; +} + +// ReplaceItem +template +bool +List::ReplaceItem(int32 index, const item_t &item) +{ + if (index >= 0 && index < fItemCount) { + fItems[index] = item; + return true; + } + return false; +} + +// MoveItem +template +bool +List::MoveItem(int32 oldIndex, int32 newIndex) +{ + if (oldIndex >= 0 && oldIndex < fItemCount + && newIndex >= 0 && newIndex <= fItemCount) { + if (oldIndex < newIndex - 1) { + item_t item = fItems[oldIndex]; + _MoveItems(fItems + oldIndex + 1, -1, newIndex - oldIndex - 1); + fItems[newIndex] = item; + } else if (oldIndex > newIndex) { + item_t item = fItems[oldIndex]; + _MoveItems(fItems + newIndex, 1, oldIndex - newIndex); + fItems[newIndex] = item; + } + return true; + } + return false; +} + +// MakeEmpty +template +void +List::MakeEmpty() +{ + for (int32 i = 0; i < fItemCount; i++) + fItems[i].~item_t(); + _Resize(0); +} + +// CountItems +template +int32 +List::CountItems() const +{ + return fItemCount; +} + +// IsEmpty +template +bool +List::IsEmpty() const +{ + return (fItemCount == 0); +} + +// ItemAt +template +const List::item_t & +List::ItemAt(int32 index) const +{ + if (index >= 0 && index < fItemCount) + return fItems[index]; + return sDefaultItem; +} + +// ItemAt +template +List::item_t & +List::ItemAt(int32 index) +{ + if (index >= 0 && index < fItemCount) + return fItems[index]; + return sDefaultItem; +} + +// Items +template +const List::item_t * +List::Items() const +{ + return fItems; +} + +// IndexOf +template +int32 +List::IndexOf(const item_t &item) const +{ + for (int32 i = 0; i < fItemCount; i++) { + if (fItems[i] == item) + return i; + } + return -1; +} + +// HasItem +template +bool +List::HasItem(const item_t &item) const +{ + return (IndexOf(item) >= 0); +} + +// _Resize +template +bool +List::_Resize(size_t count) +{ + bool result = true; + // calculate the new capacity + int32 newSize = count; + if (newSize <= 0) + newSize = 1; + newSize = ((newSize - 1) / fChunkSize + 1) * fChunkSize; + // resize if necessary + if ((size_t)newSize != fCapacity) { + item_t* newItems + = (item_t*)realloc(fItems, newSize * sizeof(item_t)); + if (newItems) { + fItems = newItems; + fCapacity = newSize; + } else + result = false; + } + if (result) + fItemCount = count; + return result; +} + +#endif // LIST_H diff --git a/src/kernel/core/disk_device_manager/disk_device_manager.cpp b/src/kernel/core/disk_device_manager/disk_device_manager.cpp new file mode 100644 index 0000000000..8107d5d567 --- /dev/null +++ b/src/kernel/core/disk_device_manager/disk_device_manager.cpp @@ -0,0 +1,3 @@ +// disk_device_manager.cpp + +#include "disk_device_manager.h" diff --git a/src/kernel/core/disk_device_manager/jobs/KCreateChildJob.cpp b/src/kernel/core/disk_device_manager/jobs/KCreateChildJob.cpp new file mode 100644 index 0000000000..72c41fd938 --- /dev/null +++ b/src/kernel/core/disk_device_manager/jobs/KCreateChildJob.cpp @@ -0,0 +1,3 @@ +// KCreateChildJob.cpp + +#include "KCreateChildJob.h" diff --git a/src/kernel/core/disk_device_manager/jobs/KCreateChildJob.h b/src/kernel/core/disk_device_manager/jobs/KCreateChildJob.h new file mode 100644 index 0000000000..d0a631b324 --- /dev/null +++ b/src/kernel/core/disk_device_manager/jobs/KCreateChildJob.h @@ -0,0 +1,25 @@ +// KCreateChildJob.h + +#ifndef _K_DISK_DEVICE_CREATE_CHILD_JOB_H +#define _K_DISK_DEVICE_CREATE_CHILD_JOB_H + +#include "KDiskDeviceJob.h" + +namespace BPrivate { +namespace DiskDevice { + +class KCreateChildJob : public KDiskDeviceJob { +public: + KCreateChildJob(partition_id partition, partition_id child, off_t offset, + off_t size, const char *parameters); + virtual ~KCreateChildJob(); + + virtual status_t Do(); +}; + +} // namespace DiskDevice +} // namespace BPrivate + +using BPrivate::DiskDevice::KCreateChildJob; + +#endif // _DISK_DEVICE_CREATE_CHILD_JOB_H diff --git a/src/kernel/core/disk_device_manager/jobs/KDefragmentJob.cpp b/src/kernel/core/disk_device_manager/jobs/KDefragmentJob.cpp new file mode 100644 index 0000000000..58fa11aff3 --- /dev/null +++ b/src/kernel/core/disk_device_manager/jobs/KDefragmentJob.cpp @@ -0,0 +1,3 @@ +// KDefragmentJob.cpp + +#include "KDefragmentJob.h" diff --git a/src/kernel/core/disk_device_manager/jobs/KDefragmentJob.h b/src/kernel/core/disk_device_manager/jobs/KDefragmentJob.h new file mode 100644 index 0000000000..28e3982308 --- /dev/null +++ b/src/kernel/core/disk_device_manager/jobs/KDefragmentJob.h @@ -0,0 +1,24 @@ +// KDefragmentJob.h + +#ifndef _K_DISK_DEVICE_DEFRAGMENT_JOB_H +#define _K_DISK_DEVICE_DEFRAGMENT_JOB_H + +#include "KDiskDeviceJob.h" + +namespace BPrivate { +namespace DiskDevice { + +class KDefragmentJob : public KDiskDeviceJob { +public: + KDefragmentJob(partition_id partition); + virtual ~KDefragmentJob(); + + virtual status_t Do(); +}; + +} // namespace DiskDevice +} // namespace BPrivate + +using BPrivate::DiskDevice::KDefragmentJob; + +#endif // _DISK_DEVICE_DEFRAGMENT_JOB_H diff --git a/src/kernel/core/disk_device_manager/jobs/KDeleteChildJob.cpp b/src/kernel/core/disk_device_manager/jobs/KDeleteChildJob.cpp new file mode 100644 index 0000000000..5eb856a830 --- /dev/null +++ b/src/kernel/core/disk_device_manager/jobs/KDeleteChildJob.cpp @@ -0,0 +1,3 @@ +// KDeleteChildJob.cpp + +#include "KDeleteChildJob.h" diff --git a/src/kernel/core/disk_device_manager/jobs/KDeleteChildJob.h b/src/kernel/core/disk_device_manager/jobs/KDeleteChildJob.h new file mode 100644 index 0000000000..fec4cd5a1a --- /dev/null +++ b/src/kernel/core/disk_device_manager/jobs/KDeleteChildJob.h @@ -0,0 +1,24 @@ +// KDeleteChildJob.h + +#ifndef _K_DISK_DEVICE_DELETE_CHILD_JOB_H +#define _K_DISK_DEVICE_DELETE_CHILD_JOB_H + +#include "KDiskDeviceJob.h" + +namespace BPrivate { +namespace DiskDevice { + +class KDeleteChildJob : public KDiskDeviceJob { +public: + KDeleteChildJob(partition_id parent, partition_id partition); + virtual ~KDeleteChildJob(); + + virtual status_t Do(); +}; + +} // namespace DiskDevice +} // namespace BPrivate + +using BPrivate::DiskDevice::KDeleteChildJob; + +#endif // _DISK_DEVICE_DELETE_CHILD_JOB_H diff --git a/src/kernel/core/disk_device_manager/jobs/KInitializeJob.cpp b/src/kernel/core/disk_device_manager/jobs/KInitializeJob.cpp new file mode 100644 index 0000000000..ededba4573 --- /dev/null +++ b/src/kernel/core/disk_device_manager/jobs/KInitializeJob.cpp @@ -0,0 +1,3 @@ +// KInitializeJob.cpp + +#include "KInitializeJob.h" diff --git a/src/kernel/core/disk_device_manager/jobs/KInitializeJob.h b/src/kernel/core/disk_device_manager/jobs/KInitializeJob.h new file mode 100644 index 0000000000..055cd75243 --- /dev/null +++ b/src/kernel/core/disk_device_manager/jobs/KInitializeJob.h @@ -0,0 +1,25 @@ +// KInitializeJob.h + +#ifndef _K_DISK_DEVICE_INITIALIZE_JOB_H +#define _K_DISK_DEVICE_INITIALIZE_JOB_H + +#include "KDiskDeviceJob.h" + +namespace BPrivate { +namespace DiskDevice { + +class KInitializeJob : public KDiskDeviceJob { +public: + KInitializeJob(partition_id partition, disk_system_id diskSystemID, + const char *parameters); + virtual ~KInitializeJob(); + + virtual status_t Do(); +}; + +} // namespace DiskDevice +} // namespace BPrivate + +using BPrivate::DiskDevice::KInitializeJob; + +#endif // _DISK_DEVICE_INITIALIZE_JOB_H diff --git a/src/kernel/core/disk_device_manager/jobs/KMoveJob.cpp b/src/kernel/core/disk_device_manager/jobs/KMoveJob.cpp new file mode 100644 index 0000000000..948aa5d40e --- /dev/null +++ b/src/kernel/core/disk_device_manager/jobs/KMoveJob.cpp @@ -0,0 +1,3 @@ +// KMoveJob.cpp + +#include "KMoveJob.h" diff --git a/src/kernel/core/disk_device_manager/jobs/KMoveJob.h b/src/kernel/core/disk_device_manager/jobs/KMoveJob.h new file mode 100644 index 0000000000..de96c9ff02 --- /dev/null +++ b/src/kernel/core/disk_device_manager/jobs/KMoveJob.h @@ -0,0 +1,24 @@ +// KMoveJob.h + +#ifndef _K_DISK_DEVICE_MOVE_JOB_H +#define _K_DISK_DEVICE_MOVE_JOB_H + +#include "KDiskDeviceJob.h" + +namespace BPrivate { +namespace DiskDevice { + +class KMoveJob : public KDiskDeviceJob { +public: + KMoveJob(partition_id parent, partition_id partition, off_t offset); + virtual ~KMoveJob(); + + virtual status_t Do(); +}; + +} // namespace DiskDevice +} // namespace BPrivate + +using BPrivate::DiskDevice::KMoveJob; + +#endif // _DISK_DEVICE_MOVE_JOB_H diff --git a/src/kernel/core/disk_device_manager/jobs/KRepairJob.cpp b/src/kernel/core/disk_device_manager/jobs/KRepairJob.cpp new file mode 100644 index 0000000000..9261a41e58 --- /dev/null +++ b/src/kernel/core/disk_device_manager/jobs/KRepairJob.cpp @@ -0,0 +1,3 @@ +// KRepairJob.cpp + +#include "KRepairJob.h" diff --git a/src/kernel/core/disk_device_manager/jobs/KRepairJob.h b/src/kernel/core/disk_device_manager/jobs/KRepairJob.h new file mode 100644 index 0000000000..a666bed994 --- /dev/null +++ b/src/kernel/core/disk_device_manager/jobs/KRepairJob.h @@ -0,0 +1,24 @@ +// KRepairJob.h + +#ifndef _K_DISK_DEVICE_REPAIR_JOB_H +#define _K_DISK_DEVICE_REPAIR_JOB_H + +#include "KDiskDeviceJob.h" + +namespace BPrivate { +namespace DiskDevice { + +class KRepairJob : public KDiskDeviceJob { +public: + KRepairJob(partition_id partition); + virtual ~KRepairJob(); + + virtual status_t Do(); +}; + +} // namespace DiskDevice +} // namespace BPrivate + +using BPrivate::DiskDevice::KRepairJob; + +#endif // _DISK_DEVICE_REPAIR_JOB_H diff --git a/src/kernel/core/disk_device_manager/jobs/KResizeJob.cpp b/src/kernel/core/disk_device_manager/jobs/KResizeJob.cpp new file mode 100644 index 0000000000..01a440a3e0 --- /dev/null +++ b/src/kernel/core/disk_device_manager/jobs/KResizeJob.cpp @@ -0,0 +1,3 @@ +// KResizeJob.cpp + +#include "KResizeJob.h" diff --git a/src/kernel/core/disk_device_manager/jobs/KResizeJob.h b/src/kernel/core/disk_device_manager/jobs/KResizeJob.h new file mode 100644 index 0000000000..442a6eb681 --- /dev/null +++ b/src/kernel/core/disk_device_manager/jobs/KResizeJob.h @@ -0,0 +1,24 @@ +// KResizeJob.h + +#ifndef _K_DISK_DEVICE_RESIZE_JOB_H +#define _K_DISK_DEVICE_RESIZE_JOB_H + +#include "KDiskDeviceJob.h" + +namespace BPrivate { +namespace DiskDevice { + +class KResizeJob : public KDiskDeviceJob { +public: + KResizeJob(partition_id parent, partition_id partition, off_t size); + virtual ~KResizeJob(); + + virtual status_t Do(); +}; + +} // namespace DiskDevice +} // namespace BPrivate + +using BPrivate::DiskDevice::KResizeJob; + +#endif // _DISK_DEVICE_RESIZE_JOB_H diff --git a/src/kernel/core/disk_device_manager/jobs/KScanPartitionJob.cpp b/src/kernel/core/disk_device_manager/jobs/KScanPartitionJob.cpp new file mode 100644 index 0000000000..d12846b5f9 --- /dev/null +++ b/src/kernel/core/disk_device_manager/jobs/KScanPartitionJob.cpp @@ -0,0 +1,3 @@ +// KScanPartitionJob.cpp + +#include "KScanPartitionJob.h" diff --git a/src/kernel/core/disk_device_manager/jobs/KScanPartitionJob.h b/src/kernel/core/disk_device_manager/jobs/KScanPartitionJob.h new file mode 100644 index 0000000000..26c85cf623 --- /dev/null +++ b/src/kernel/core/disk_device_manager/jobs/KScanPartitionJob.h @@ -0,0 +1,24 @@ +// KScanPartitionJob.h + +#ifndef _K_DISK_DEVICE_SCAN_PARTITION_JOB_H +#define _K_DISK_DEVICE_SCAN_PARTITION_JOB_H + +namespace BPrivate { +namespace DiskDevice { + +#include "KDiskDeviceJob.h" + +class KScanPartitionJob : public KDiskDeviceJob { +public: + KScanPartitionJob(partition_id partition); + virtual ~KScanPartitionJob(); + + virtual status_t Do(); +}; + +} // namespace DiskDevice +} // namespace BPrivate + +using BPrivate::DiskDevice::KScanPartitionJob; + +#endif // _DISK_DEVICE_SCAN_PARTITION_JOB_H diff --git a/src/kernel/core/disk_device_manager/jobs/KSetParametersJob.cpp b/src/kernel/core/disk_device_manager/jobs/KSetParametersJob.cpp new file mode 100644 index 0000000000..2e40a4beca --- /dev/null +++ b/src/kernel/core/disk_device_manager/jobs/KSetParametersJob.cpp @@ -0,0 +1,3 @@ +// KSetParametersJob.cpp + +#include "KSetParametersJob.h" diff --git a/src/kernel/core/disk_device_manager/jobs/KSetParametersJob.h b/src/kernel/core/disk_device_manager/jobs/KSetParametersJob.h new file mode 100644 index 0000000000..418dfc33cb --- /dev/null +++ b/src/kernel/core/disk_device_manager/jobs/KSetParametersJob.h @@ -0,0 +1,25 @@ +// KSetParametersJob.h + +#ifndef _K_DISK_DEVICE_SET_PARAMETERS_JOB_H +#define _K_DISK_DEVICE_SET_PARAMETERS_JOB_H + +namespace BPrivate { +namespace DiskDevice { + +#include "KDiskDeviceJob.h" + +class KSetParametersJob : public KDiskDeviceJob { +public: + KSetParametersJob(partition_id parent, partition_id partition, + const char *parameters, const char *contentParameters); + virtual ~KSetParametersJob(); + + virtual status_t Do(); +}; + +} // namespace DiskDevice +} // namespace BPrivate + +using BPrivate::DiskDevice::KSetParametersJob; + +#endif // _DISK_DEVICE_SET_PARAMETERS_JOB_H