Folded KPhysicalPartition into KPartition. Removed the notion of shadow
partitions from the disk device manager. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22800 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -97,7 +97,6 @@ int32 find_partition(const char *path);
|
|||||||
// disk device/partition read access
|
// disk device/partition read access
|
||||||
// (read lock required)
|
// (read lock required)
|
||||||
disk_device_data *get_disk_device(partition_id partitionID);
|
disk_device_data *get_disk_device(partition_id partitionID);
|
||||||
partition_data *get_physical_partition(partition_id partitionID);
|
|
||||||
partition_data *get_partition(partition_id partitionID);
|
partition_data *get_partition(partition_id partitionID);
|
||||||
partition_data *get_parent_partition(partition_id partitionID);
|
partition_data *get_parent_partition(partition_id partitionID);
|
||||||
partition_data *get_child_partition(partition_id partitionID, int32 index);
|
partition_data *get_child_partition(partition_id partitionID, int32 index);
|
||||||
|
|||||||
@@ -7,15 +7,18 @@
|
|||||||
|
|
||||||
#include <OS.h>
|
#include <OS.h>
|
||||||
|
|
||||||
#include "KPhysicalPartition.h"
|
#include "KPartition.h"
|
||||||
#include "RWLocker.h"
|
#include "RWLocker.h"
|
||||||
|
|
||||||
|
|
||||||
namespace BPrivate {
|
namespace BPrivate {
|
||||||
namespace DiskDevice {
|
namespace DiskDevice {
|
||||||
|
|
||||||
|
|
||||||
class UserDataWriter;
|
class UserDataWriter;
|
||||||
|
|
||||||
class KDiskDevice : public KPhysicalPartition {
|
|
||||||
|
class KDiskDevice : public KPartition {
|
||||||
public:
|
public:
|
||||||
KDiskDevice(partition_id id = -1);
|
KDiskDevice(partition_id id = -1);
|
||||||
virtual ~KDiskDevice();
|
virtual ~KDiskDevice();
|
||||||
@@ -38,8 +41,6 @@ public:
|
|||||||
void WriteUnlock();
|
void WriteUnlock();
|
||||||
bool IsWriteLocked();
|
bool IsWriteLocked();
|
||||||
|
|
||||||
virtual bool PrepareForRemoval();
|
|
||||||
|
|
||||||
virtual void SetID(partition_id id);
|
virtual void SetID(partition_id id);
|
||||||
|
|
||||||
virtual status_t PublishDevice();
|
virtual status_t PublishDevice();
|
||||||
@@ -70,14 +71,9 @@ public:
|
|||||||
disk_device_data *DeviceData();
|
disk_device_data *DeviceData();
|
||||||
const disk_device_data *DeviceData() const;
|
const disk_device_data *DeviceData() const;
|
||||||
|
|
||||||
status_t CreateShadowDevice(team_id team);
|
|
||||||
status_t DeleteShadowDevice();
|
|
||||||
void SetShadowOwner(team_id team);
|
|
||||||
team_id ShadowOwner() const;
|
|
||||||
|
|
||||||
virtual void WriteUserData(UserDataWriter &writer,
|
virtual void WriteUserData(UserDataWriter &writer,
|
||||||
user_partition_data *data);
|
user_partition_data *data);
|
||||||
void WriteUserData(UserDataWriter &writer, bool shadow);
|
void WriteUserData(UserDataWriter &writer);
|
||||||
|
|
||||||
virtual void Dump(bool deep = true, int32 level = 0);
|
virtual void Dump(bool deep = true, int32 level = 0);
|
||||||
|
|
||||||
@@ -92,9 +88,9 @@ private:
|
|||||||
RWLocker fLocker;
|
RWLocker fLocker;
|
||||||
int fFD;
|
int fFD;
|
||||||
status_t fMediaStatus;
|
status_t fMediaStatus;
|
||||||
team_id fShadowOwner;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace DiskDevice
|
} // namespace DiskDevice
|
||||||
} // namespace BPrivate
|
} // namespace BPrivate
|
||||||
|
|
||||||
|
|||||||
@@ -43,15 +43,15 @@ public:
|
|||||||
// manager must be locked
|
// manager must be locked
|
||||||
KDiskDevice *FindDevice(const char *path);
|
KDiskDevice *FindDevice(const char *path);
|
||||||
KDiskDevice *FindDevice(partition_id id, bool deviceOnly = true);
|
KDiskDevice *FindDevice(partition_id id, bool deviceOnly = true);
|
||||||
KPartition *FindPartition(const char *path, bool noShadow = false);
|
KPartition *FindPartition(const char *path);
|
||||||
KPartition *FindPartition(partition_id id, bool noShadow = false);
|
KPartition *FindPartition(partition_id id);
|
||||||
KFileDiskDevice *FindFileDevice(const char *filePath);
|
KFileDiskDevice *FindFileDevice(const char *filePath);
|
||||||
|
|
||||||
KDiskDevice *RegisterDevice(const char *path);
|
KDiskDevice *RegisterDevice(const char *path);
|
||||||
KDiskDevice *RegisterDevice(partition_id id, bool deviceOnly = true);
|
KDiskDevice *RegisterDevice(partition_id id, bool deviceOnly = true);
|
||||||
KDiskDevice *RegisterNextDevice(int32 *cookie);
|
KDiskDevice *RegisterNextDevice(int32 *cookie);
|
||||||
KPartition *RegisterPartition(const char *path, bool noShadow = false);
|
KPartition *RegisterPartition(const char *path);
|
||||||
KPartition *RegisterPartition(partition_id id, bool noShadow = false);
|
KPartition *RegisterPartition(partition_id id);
|
||||||
KFileDiskDevice *RegisterFileDevice(const char *filePath);
|
KFileDiskDevice *RegisterFileDevice(const char *filePath);
|
||||||
|
|
||||||
KDiskDevice *ReadLockDevice(partition_id id, bool deviceOnly = true);
|
KDiskDevice *ReadLockDevice(partition_id id, bool deviceOnly = true);
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ class KPartitionListener;
|
|||||||
class KPartitionVisitor;
|
class KPartitionVisitor;
|
||||||
class KPath;
|
class KPath;
|
||||||
class KPhysicalPartition;
|
class KPhysicalPartition;
|
||||||
class KShadowPartition;
|
|
||||||
|
|
||||||
//! \brief Class representing a single partition.
|
//! \brief Class representing a single partition.
|
||||||
class KPartition {
|
class KPartition {
|
||||||
@@ -139,7 +138,7 @@ public:
|
|||||||
|
|
||||||
status_t AddChild(KPartition *partition, int32 index = -1);
|
status_t AddChild(KPartition *partition, int32 index = -1);
|
||||||
virtual status_t CreateChild(partition_id id, int32 index,
|
virtual status_t CreateChild(partition_id id, int32 index,
|
||||||
KPartition **child = NULL) = 0;
|
KPartition **child = NULL);
|
||||||
bool RemoveChild(int32 index);
|
bool RemoveChild(int32 index);
|
||||||
bool RemoveChild(KPartition *child);
|
bool RemoveChild(KPartition *child);
|
||||||
bool RemoveAllChildren();
|
bool RemoveAllChildren();
|
||||||
@@ -149,14 +148,6 @@ public:
|
|||||||
|
|
||||||
KPartition *VisitEachDescendant(KPartitionVisitor *visitor);
|
KPartition *VisitEachDescendant(KPartitionVisitor *visitor);
|
||||||
|
|
||||||
// Shadow Partition
|
|
||||||
|
|
||||||
virtual status_t CreateShadowPartition(); // creates a complete tree
|
|
||||||
virtual void UnsetShadowPartition(bool doDelete);
|
|
||||||
virtual KShadowPartition *ShadowPartition() const = 0;
|
|
||||||
virtual bool IsShadowPartition() const = 0;
|
|
||||||
virtual KPhysicalPartition *PhysicalPartition() const = 0;
|
|
||||||
|
|
||||||
// DiskSystem
|
// DiskSystem
|
||||||
|
|
||||||
void SetDiskSystem(KDiskSystem *diskSystem);
|
void SetDiskSystem(KDiskSystem *diskSystem);
|
||||||
|
|||||||
@@ -1,61 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
|
|
||||||
* Distributed under the terms of the MIT License.
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* Ingo Weinhold <[email protected]>
|
|
||||||
*/
|
|
||||||
#ifndef _K_DISK_DEVICE_PHYSICAL_PARTITION_H
|
|
||||||
#define _K_DISK_DEVICE_PHYSICAL_PARTITION_H
|
|
||||||
|
|
||||||
#include <KPartition.h>
|
|
||||||
|
|
||||||
namespace BPrivate {
|
|
||||||
namespace DiskDevice {
|
|
||||||
|
|
||||||
class KDiskDevice;
|
|
||||||
class KDiskSystem;
|
|
||||||
class KShadowPartition;
|
|
||||||
|
|
||||||
//! \brief Class representing an existing partition.
|
|
||||||
class KPhysicalPartition : public KPartition {
|
|
||||||
public:
|
|
||||||
KPhysicalPartition(partition_id id = -1);
|
|
||||||
virtual ~KPhysicalPartition();
|
|
||||||
|
|
||||||
virtual bool PrepareForRemoval();
|
|
||||||
|
|
||||||
virtual status_t Open(int flags, int *fd);
|
|
||||||
virtual status_t PublishDevice();
|
|
||||||
virtual status_t UnpublishDevice();
|
|
||||||
|
|
||||||
virtual status_t Mount(uint32 mountFlags, const char *parameters);
|
|
||||||
virtual status_t Unmount();
|
|
||||||
|
|
||||||
// Hierarchy
|
|
||||||
|
|
||||||
virtual status_t CreateChild(partition_id id, int32 index,
|
|
||||||
KPartition **child = NULL);
|
|
||||||
|
|
||||||
// Shadow Partition
|
|
||||||
|
|
||||||
virtual status_t CreateShadowPartition(); // creates a complete tree
|
|
||||||
virtual void UnsetShadowPartition(bool doDelete);
|
|
||||||
virtual KShadowPartition *ShadowPartition() const;
|
|
||||||
virtual bool IsShadowPartition() const;
|
|
||||||
virtual KPhysicalPartition *PhysicalPartition() const;
|
|
||||||
|
|
||||||
// DiskSystem
|
|
||||||
|
|
||||||
virtual void Dump(bool deep, int32 level);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
KShadowPartition *fShadowPartition;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace DiskDevice
|
|
||||||
} // namespace BPrivate
|
|
||||||
|
|
||||||
using BPrivate::DiskDevice::KPhysicalPartition;
|
|
||||||
|
|
||||||
#endif // _K_DISK_DEVICE_PHYSICAL_PARTITION_H
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
|
|
||||||
* Distributed under the terms of the MIT License.
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* Ingo Weinhold <[email protected]>
|
|
||||||
*/
|
|
||||||
#ifndef _K_DISK_DEVICE_SHADOW_PARTITION_H
|
|
||||||
#define _K_DISK_DEVICE_SHADOW_PARTITION_H
|
|
||||||
|
|
||||||
#include <KPartition.h>
|
|
||||||
#include <KPartitionListener.h>
|
|
||||||
|
|
||||||
namespace BPrivate {
|
|
||||||
namespace DiskDevice {
|
|
||||||
|
|
||||||
class KPhysicalPartition;
|
|
||||||
|
|
||||||
/*! \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);
|
|
||||||
virtual ~KShadowPartition();
|
|
||||||
|
|
||||||
// Hierarchy
|
|
||||||
|
|
||||||
virtual status_t CreateChild(partition_id id, int32 index,
|
|
||||||
KPartition **child = NULL);
|
|
||||||
|
|
||||||
// Shadow Partition
|
|
||||||
|
|
||||||
virtual KShadowPartition *ShadowPartition() const;
|
|
||||||
virtual bool IsShadowPartition() const;
|
|
||||||
void UnsetPhysicalPartition();
|
|
||||||
virtual KPhysicalPartition *PhysicalPartition() const;
|
|
||||||
|
|
||||||
void SyncWithPhysicalPartition();
|
|
||||||
|
|
||||||
virtual void WriteUserData(UserDataWriter &writer,
|
|
||||||
user_partition_data *data);
|
|
||||||
|
|
||||||
virtual void Dump(bool deep, int32 level);
|
|
||||||
|
|
||||||
private:
|
|
||||||
virtual void OffsetChanged(KPartition *partition, off_t offset);
|
|
||||||
virtual void SizeChanged(KPartition *partition, off_t size);
|
|
||||||
virtual void ContentSizeChanged(KPartition *partition, off_t size);
|
|
||||||
virtual void BlockSizeChanged(KPartition *partition, uint32 blockSize);
|
|
||||||
virtual void IndexChanged(KPartition *partition, int32 index);
|
|
||||||
virtual void StatusChanged(KPartition *partition, uint32 status);
|
|
||||||
virtual void FlagsChanged(KPartition *partition, uint32 flags);
|
|
||||||
virtual void NameChanged(KPartition *partition, const char *name);
|
|
||||||
virtual void ContentNameChanged(KPartition *partition, const char *name);
|
|
||||||
virtual void TypeChanged(KPartition *partition, const char *type);
|
|
||||||
virtual void IDChanged(KPartition *partition, partition_id id);
|
|
||||||
virtual void VolumeIDChanged(KPartition *partition, dev_t volumeID);
|
|
||||||
virtual void MountCookieChanged(KPartition *partition, void *cookie);
|
|
||||||
virtual void ParametersChanged(KPartition *partition,
|
|
||||||
const char *parameters);
|
|
||||||
virtual void ContentParametersChanged(KPartition *partition,
|
|
||||||
const char *parameters);
|
|
||||||
virtual void ChildAdded(KPartition *partition, KPartition *child,
|
|
||||||
int32 index);
|
|
||||||
virtual void ChildRemoved(KPartition *partition, KPartition *child,
|
|
||||||
int32 index);
|
|
||||||
virtual void DiskSystemChanged(KPartition *partition,
|
|
||||||
KDiskSystem *diskSystem);
|
|
||||||
virtual void CookieChanged(KPartition *partition, void *cookie);
|
|
||||||
virtual void ContentCookieChanged(KPartition *partition, void *cookie);
|
|
||||||
|
|
||||||
private:
|
|
||||||
KPhysicalPartition *fPhysicalPartition;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace DiskDevice
|
|
||||||
} // namespace BPrivate
|
|
||||||
|
|
||||||
using BPrivate::DiskDevice::KShadowPartition;
|
|
||||||
|
|
||||||
#endif // _K_DISK_DEVICE_SHADOW_PARTITION_H
|
|
||||||
@@ -17,7 +17,6 @@ extern "C" {
|
|||||||
typedef struct user_partition_data user_partition_data;
|
typedef struct user_partition_data user_partition_data;
|
||||||
struct user_partition_data {
|
struct user_partition_data {
|
||||||
partition_id id;
|
partition_id id;
|
||||||
partition_id shadow_id;
|
|
||||||
off_t offset;
|
off_t offset;
|
||||||
off_t size;
|
off_t size;
|
||||||
off_t content_size;
|
off_t content_size;
|
||||||
@@ -70,8 +69,8 @@ partition_id _user_get_next_disk_device_id(int32 *cookie, size_t *neededSize);
|
|||||||
partition_id _user_find_disk_device(const char *filename, size_t *neededSize);
|
partition_id _user_find_disk_device(const char *filename, size_t *neededSize);
|
||||||
partition_id _user_find_partition(const char *filename, size_t *neededSize);
|
partition_id _user_find_partition(const char *filename, size_t *neededSize);
|
||||||
status_t _user_get_disk_device_data(partition_id deviceID, bool deviceOnly,
|
status_t _user_get_disk_device_data(partition_id deviceID, bool deviceOnly,
|
||||||
bool shadow, user_disk_device_data *buffer,
|
user_disk_device_data *buffer, size_t bufferSize,
|
||||||
size_t bufferSize, size_t *neededSize);
|
size_t *neededSize);
|
||||||
|
|
||||||
partition_id _user_register_file_device(const char *filename);
|
partition_id _user_register_file_device(const char *filename);
|
||||||
status_t _user_unregister_file_device(partition_id deviceID,
|
status_t _user_unregister_file_device(partition_id deviceID,
|
||||||
|
|||||||
@@ -324,8 +324,8 @@ extern status_t _kern_get_cpuid(cpuid_info *info, uint32 eax, uint32 cpu);
|
|||||||
extern partition_id _kern_get_next_disk_device_id(int32 *cookie, size_t *neededSize);
|
extern partition_id _kern_get_next_disk_device_id(int32 *cookie, size_t *neededSize);
|
||||||
extern partition_id _kern_find_disk_device(const char *filename, size_t *neededSize);
|
extern partition_id _kern_find_disk_device(const char *filename, size_t *neededSize);
|
||||||
extern partition_id _kern_find_partition(const char *filename, size_t *neededSize);
|
extern partition_id _kern_find_partition(const char *filename, size_t *neededSize);
|
||||||
extern status_t _kern_get_disk_device_data(partition_id deviceID, bool deviceOnly,
|
extern status_t _kern_get_disk_device_data(partition_id deviceID,
|
||||||
bool shadow, struct user_disk_device_data *buffer,
|
bool deviceOnly, struct user_disk_device_data *buffer,
|
||||||
size_t bufferSize, size_t *neededSize);
|
size_t bufferSize, size_t *neededSize);
|
||||||
extern partition_id _kern_register_file_device(const char *filename);
|
extern partition_id _kern_register_file_device(const char *filename);
|
||||||
extern status_t _kern_unregister_file_device(partition_id deviceID,
|
extern status_t _kern_unregister_file_device(partition_id deviceID,
|
||||||
|
|||||||
@@ -740,7 +740,7 @@ pm_shadow_changed(partition_data *partition, partition_data *child,
|
|||||||
case B_PARTITION_SHADOW:
|
case B_PARTITION_SHADOW:
|
||||||
{
|
{
|
||||||
// get the physical partition
|
// get the physical partition
|
||||||
partition_data* physicalPartition = get_physical_partition(
|
partition_data* physicalPartition = get_partition(
|
||||||
partition->id);
|
partition->id);
|
||||||
if (!physicalPartition) {
|
if (!physicalPartition) {
|
||||||
dprintf("intel: pm_shadow_changed(B_PARTITION_SHADOW): no "
|
dprintf("intel: pm_shadow_changed(B_PARTITION_SHADOW): no "
|
||||||
@@ -774,7 +774,7 @@ pm_shadow_changed(partition_data *partition, partition_data *child,
|
|||||||
case B_PARTITION_SHADOW_CHILD:
|
case B_PARTITION_SHADOW_CHILD:
|
||||||
{
|
{
|
||||||
// get the physical child partition
|
// get the physical child partition
|
||||||
partition_data* physical = get_physical_partition(child->id);
|
partition_data* physical = get_partition(child->id);
|
||||||
if (!physical) {
|
if (!physical) {
|
||||||
dprintf("intel: pm_shadow_changed(B_PARTITION_SHADOW_CHILD): "
|
dprintf("intel: pm_shadow_changed(B_PARTITION_SHADOW_CHILD): "
|
||||||
"no physical partition with ID %ld\n", child->id);
|
"no physical partition with ID %ld\n", child->id);
|
||||||
|
|||||||
@@ -366,7 +366,7 @@ BDiskDevice::_GetData(partition_id id, bool deviceOnly, size_t neededSize,
|
|||||||
|
|
||||||
status_t error = B_OK;
|
status_t error = B_OK;
|
||||||
do {
|
do {
|
||||||
error = _kern_get_disk_device_data(id, deviceOnly, false,
|
error = _kern_get_disk_device_data(id, deviceOnly,
|
||||||
(user_disk_device_data*)buffer, bufferSize, &neededSize);
|
(user_disk_device_data*)buffer, bufferSize, &neededSize);
|
||||||
if (error == B_BUFFER_OVERFLOW) {
|
if (error == B_BUFFER_OVERFLOW) {
|
||||||
// buffer to small re-allocate it
|
// buffer to small re-allocate it
|
||||||
|
|||||||
@@ -24,8 +24,6 @@ KernelMergeObject kernel_disk_device_manager.o :
|
|||||||
KPartitioningSystem.cpp
|
KPartitioningSystem.cpp
|
||||||
KPartitionListener.cpp
|
KPartitionListener.cpp
|
||||||
KPartitionVisitor.cpp
|
KPartitionVisitor.cpp
|
||||||
KPhysicalPartition.cpp
|
|
||||||
KShadowPartition.cpp
|
|
||||||
UserDataWriter.cpp
|
UserDataWriter.cpp
|
||||||
|
|
||||||
# utilities
|
# utilities
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
#include "ddm_userland_interface.h"
|
#include "ddm_userland_interface.h"
|
||||||
#include "KDiskDevice.h"
|
#include "KDiskDevice.h"
|
||||||
#include "KDiskDeviceUtils.h"
|
#include "KDiskDeviceUtils.h"
|
||||||
#include "KShadowPartition.h"
|
|
||||||
#include "KPath.h"
|
#include "KPath.h"
|
||||||
#include "UserDataWriter.h"
|
#include "UserDataWriter.h"
|
||||||
|
|
||||||
@@ -22,12 +21,11 @@
|
|||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
KDiskDevice::KDiskDevice(partition_id id)
|
KDiskDevice::KDiskDevice(partition_id id)
|
||||||
: KPhysicalPartition(id),
|
: KPartition(id),
|
||||||
fDeviceData(),
|
fDeviceData(),
|
||||||
fLocker("diskdevice"),
|
fLocker("diskdevice"),
|
||||||
fFD(-1),
|
fFD(-1),
|
||||||
fMediaStatus(B_ERROR),
|
fMediaStatus(B_ERROR)
|
||||||
fShadowOwner(-1)
|
|
||||||
{
|
{
|
||||||
Unset();
|
Unset();
|
||||||
fDevice = this;
|
fDevice = this;
|
||||||
@@ -98,7 +96,6 @@ KDiskDevice::Unset()
|
|||||||
fFD = -1;
|
fFD = -1;
|
||||||
}
|
}
|
||||||
fMediaStatus = B_ERROR;
|
fMediaStatus = B_ERROR;
|
||||||
fShadowOwner = -1;
|
|
||||||
fDeviceData.id = -1;
|
fDeviceData.id = -1;
|
||||||
fDeviceData.flags = 0;
|
fDeviceData.flags = 0;
|
||||||
if (fDeviceData.path) {
|
if (fDeviceData.path) {
|
||||||
@@ -164,20 +161,12 @@ KDiskDevice::IsWriteLocked()
|
|||||||
return fLocker.IsWriteLocked();
|
return fLocker.IsWriteLocked();
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrepareForRemoval
|
|
||||||
bool
|
|
||||||
KDiskDevice::PrepareForRemoval()
|
|
||||||
{
|
|
||||||
if (ShadowOwner() >= 0)
|
|
||||||
DeleteShadowDevice();
|
|
||||||
return KPhysicalPartition::PrepareForRemoval();
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetID
|
// SetID
|
||||||
void
|
void
|
||||||
KDiskDevice::SetID(partition_id id)
|
KDiskDevice::SetID(partition_id id)
|
||||||
{
|
{
|
||||||
KPhysicalPartition::SetID(id);
|
KPartition::SetID(id);
|
||||||
fDeviceData.id = id;
|
fDeviceData.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -312,58 +301,19 @@ KDiskDevice::DeviceData() const
|
|||||||
return &fDeviceData;
|
return &fDeviceData;
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateShadowDevice
|
|
||||||
status_t
|
|
||||||
KDiskDevice::CreateShadowDevice(team_id team)
|
|
||||||
{
|
|
||||||
if (fShadowOwner >= 0 || team < 0 || !HasMedia())
|
|
||||||
return B_BAD_VALUE;
|
|
||||||
// create the shadow partitions
|
|
||||||
status_t error = CreateShadowPartition();
|
|
||||||
if (error == B_OK)
|
|
||||||
SetShadowOwner(team);
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeleteShadowDevice
|
|
||||||
status_t
|
|
||||||
KDiskDevice::DeleteShadowDevice()
|
|
||||||
{
|
|
||||||
if (fShadowOwner < 0)
|
|
||||||
return B_BAD_VALUE;
|
|
||||||
UnsetShadowPartition(true);
|
|
||||||
SetShadowOwner(-1);
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetShadowOwner
|
|
||||||
void
|
|
||||||
KDiskDevice::SetShadowOwner(team_id team)
|
|
||||||
{
|
|
||||||
fShadowOwner = team;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ShadowOwner
|
|
||||||
team_id
|
|
||||||
KDiskDevice::ShadowOwner() const
|
|
||||||
{
|
|
||||||
return fShadowOwner;
|
|
||||||
}
|
|
||||||
|
|
||||||
// WriteUserData
|
// WriteUserData
|
||||||
void
|
void
|
||||||
KDiskDevice::WriteUserData(UserDataWriter &writer, user_partition_data *data)
|
KDiskDevice::WriteUserData(UserDataWriter &writer, user_partition_data *data)
|
||||||
{
|
{
|
||||||
return KPhysicalPartition::WriteUserData(writer, data);
|
return KPartition::WriteUserData(writer, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteUserData
|
// WriteUserData
|
||||||
void
|
void
|
||||||
KDiskDevice::WriteUserData(UserDataWriter &writer, bool shadow)
|
KDiskDevice::WriteUserData(UserDataWriter &writer)
|
||||||
{
|
{
|
||||||
KPartition *partition = shadow ? ShadowPartition() : static_cast<KPartition *>(this);
|
KPartition *partition = this;
|
||||||
if (!partition)
|
|
||||||
partition = this;
|
|
||||||
user_disk_device_data *data
|
user_disk_device_data *data
|
||||||
= writer.AllocateDeviceData(partition->CountChildren());
|
= writer.AllocateDeviceData(partition->CountChildren());
|
||||||
char *path = writer.PlaceString(Path());
|
char *path = writer.PlaceString(Path());
|
||||||
@@ -384,7 +334,7 @@ KDiskDevice::Dump(bool deep, int32 level)
|
|||||||
OUT(" media status: %s\n", strerror(fMediaStatus));
|
OUT(" media status: %s\n", strerror(fMediaStatus));
|
||||||
OUT(" device flags: %lx\n", DeviceFlags());
|
OUT(" device flags: %lx\n", DeviceFlags());
|
||||||
if (fMediaStatus == B_OK)
|
if (fMediaStatus == B_OK)
|
||||||
KPhysicalPartition::Dump(deep, 0);
|
KPartition::Dump(deep, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetMediaStatus
|
// GetMediaStatus
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
#include "KPartitioningSystem.h"
|
#include "KPartitioningSystem.h"
|
||||||
#include "KPartitionVisitor.h"
|
#include "KPartitionVisitor.h"
|
||||||
#include "KPath.h"
|
#include "KPath.h"
|
||||||
#include "KShadowPartition.h"
|
|
||||||
|
|
||||||
#include <VectorMap.h>
|
#include <VectorMap.h>
|
||||||
#include <VectorSet.h>
|
#include <VectorSet.h>
|
||||||
@@ -252,36 +251,34 @@ KDiskDeviceManager::FindDevice(partition_id id, bool deviceOnly)
|
|||||||
|
|
||||||
// FindPartition
|
// FindPartition
|
||||||
KPartition *
|
KPartition *
|
||||||
KDiskDeviceManager::FindPartition(const char *path, bool noShadow)
|
KDiskDeviceManager::FindPartition(const char *path)
|
||||||
{
|
{
|
||||||
// TODO: Optimize!
|
// TODO: Optimize!
|
||||||
KPath partitionPath;
|
KPath partitionPath;
|
||||||
if (partitionPath.InitCheck() != B_OK)
|
if (partitionPath.InitCheck() != B_OK)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
for (PartitionMap::Iterator it = fPartitions->Begin();
|
for (PartitionMap::Iterator it = fPartitions->Begin();
|
||||||
it != fPartitions->End();
|
it != fPartitions->End();
|
||||||
++it) {
|
++it) {
|
||||||
KPartition *partition = it->Value();
|
KPartition *partition = it->Value();
|
||||||
if (partition->GetPath(&partitionPath) == B_OK
|
if (partition->GetPath(&partitionPath) == B_OK
|
||||||
&& partitionPath == path) {
|
&& partitionPath == path) {
|
||||||
if (noShadow && partition->IsShadowPartition())
|
|
||||||
return partition->PhysicalPartition();
|
|
||||||
return partition;
|
return partition;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindPartition
|
// FindPartition
|
||||||
KPartition *
|
KPartition *
|
||||||
KDiskDeviceManager::FindPartition(partition_id id, bool noShadow)
|
KDiskDeviceManager::FindPartition(partition_id id)
|
||||||
{
|
{
|
||||||
PartitionMap::Iterator it = fPartitions->Find(id);
|
PartitionMap::Iterator it = fPartitions->Find(id);
|
||||||
if (it != fPartitions->End()) {
|
if (it != fPartitions->End())
|
||||||
if (noShadow && it->Value()->IsShadowPartition())
|
|
||||||
return it->Value()->PhysicalPartition();
|
|
||||||
return it->Value();
|
return it->Value();
|
||||||
}
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -342,10 +339,10 @@ KDiskDeviceManager::RegisterNextDevice(int32 *cookie)
|
|||||||
|
|
||||||
// RegisterPartition
|
// RegisterPartition
|
||||||
KPartition *
|
KPartition *
|
||||||
KDiskDeviceManager::RegisterPartition(const char *path, bool noShadow)
|
KDiskDeviceManager::RegisterPartition(const char *path)
|
||||||
{
|
{
|
||||||
if (ManagerLocker locker = this) {
|
if (ManagerLocker locker = this) {
|
||||||
if (KPartition *partition = FindPartition(path, noShadow)) {
|
if (KPartition *partition = FindPartition(path)) {
|
||||||
partition->Register();
|
partition->Register();
|
||||||
return partition;
|
return partition;
|
||||||
}
|
}
|
||||||
@@ -355,10 +352,10 @@ KDiskDeviceManager::RegisterPartition(const char *path, bool noShadow)
|
|||||||
|
|
||||||
// RegisterPartition
|
// RegisterPartition
|
||||||
KPartition *
|
KPartition *
|
||||||
KDiskDeviceManager::RegisterPartition(partition_id id, bool noShadow)
|
KDiskDeviceManager::RegisterPartition(partition_id id)
|
||||||
{
|
{
|
||||||
if (ManagerLocker locker = this) {
|
if (ManagerLocker locker = this) {
|
||||||
if (KPartition *partition = FindPartition(id, noShadow)) {
|
if (KPartition *partition = FindPartition(id)) {
|
||||||
partition->Register();
|
partition->Register();
|
||||||
return partition;
|
return partition;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include <util/kernel_cpp.h>
|
#include <util/kernel_cpp.h>
|
||||||
|
|
||||||
#include <ddm_userland_interface.h>
|
#include <ddm_userland_interface.h>
|
||||||
|
#include <fs/devfs.h>
|
||||||
#include <KDiskDevice.h>
|
#include <KDiskDevice.h>
|
||||||
#include <KDiskDeviceManager.h>
|
#include <KDiskDeviceManager.h>
|
||||||
#include <KDiskDeviceUtils.h>
|
#include <KDiskDeviceUtils.h>
|
||||||
@@ -147,22 +148,75 @@ KPartition::PrepareForDeletion()
|
|||||||
status_t
|
status_t
|
||||||
KPartition::Open(int flags, int *fd)
|
KPartition::Open(int flags, int *fd)
|
||||||
{
|
{
|
||||||
return B_BAD_VALUE;
|
if (!fd)
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
|
// get the path
|
||||||
|
KPath path;
|
||||||
|
status_t error = GetPath(&path);
|
||||||
|
if (error != B_OK)
|
||||||
|
return error;
|
||||||
|
|
||||||
|
// open the device
|
||||||
|
*fd = open(path.Path(), flags);
|
||||||
|
if (*fd < 0)
|
||||||
|
return errno;
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// PublishDevice
|
// PublishDevice
|
||||||
status_t
|
status_t
|
||||||
KPartition::PublishDevice()
|
KPartition::PublishDevice()
|
||||||
{
|
{
|
||||||
// we're just a stupid base class, what do we know?
|
if (fPublished)
|
||||||
return B_ERROR;
|
return B_OK;
|
||||||
|
|
||||||
|
// get the path
|
||||||
|
KPath path;
|
||||||
|
status_t error = GetPath(&path);
|
||||||
|
if (error != B_OK)
|
||||||
|
return error;
|
||||||
|
|
||||||
|
// prepare a partition_info
|
||||||
|
partition_info info;
|
||||||
|
info.offset = Offset();
|
||||||
|
info.size = Size();
|
||||||
|
info.logical_block_size = BlockSize();
|
||||||
|
info.session = 0;
|
||||||
|
info.partition = ID();
|
||||||
|
if (strlcpy(info.device, Device()->Path(), B_PATH_NAME_LENGTH)
|
||||||
|
>= B_PATH_NAME_LENGTH) {
|
||||||
|
return B_NAME_TOO_LONG;
|
||||||
|
}
|
||||||
|
|
||||||
|
error = devfs_publish_partition(path.Path() + 5, &info);
|
||||||
|
// we need to remove the "/dev/" part from the path
|
||||||
|
if (error != B_OK)
|
||||||
|
return error;
|
||||||
|
|
||||||
|
fPublished = true;
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnpublishDevice
|
// UnpublishDevice
|
||||||
status_t
|
status_t
|
||||||
KPartition::UnpublishDevice()
|
KPartition::UnpublishDevice()
|
||||||
{
|
{
|
||||||
return B_ERROR;
|
if (!fPublished)
|
||||||
|
return B_OK;
|
||||||
|
|
||||||
|
// get the path
|
||||||
|
KPath path;
|
||||||
|
status_t error = GetPath(&path);
|
||||||
|
if (error != B_OK)
|
||||||
|
return error;
|
||||||
|
|
||||||
|
fPublished = false;
|
||||||
|
|
||||||
|
return devfs_unpublish_partition(path.Path() + 5);
|
||||||
|
// we need to remove the "/dev/" part from the path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -660,6 +714,35 @@ KPartition::AddChild(KPartition *partition, int32 index)
|
|||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// CreateChild
|
||||||
|
status_t
|
||||||
|
KPartition::CreateChild(partition_id id, int32 index, KPartition **_child)
|
||||||
|
{
|
||||||
|
// check parameters
|
||||||
|
int32 count = fPartitionData.child_count;
|
||||||
|
if (index == -1)
|
||||||
|
index = count;
|
||||||
|
if (index < 0 || index > count)
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
|
// create and add partition
|
||||||
|
KPartition *child = new(nothrow) KPartition(id);
|
||||||
|
if (!child)
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
|
status_t error = AddChild(child, index);
|
||||||
|
|
||||||
|
// cleanup / set result
|
||||||
|
if (error != B_OK)
|
||||||
|
delete child;
|
||||||
|
else if (_child)
|
||||||
|
*_child = child;
|
||||||
|
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// RemoveChild
|
// RemoveChild
|
||||||
bool
|
bool
|
||||||
KPartition::RemoveChild(int32 index)
|
KPartition::RemoveChild(int32 index)
|
||||||
@@ -752,20 +835,6 @@ KPartition::VisitEachDescendant(KPartitionVisitor *visitor)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateShadowPartition
|
|
||||||
status_t
|
|
||||||
KPartition::CreateShadowPartition()
|
|
||||||
{
|
|
||||||
// implemented by derived classes
|
|
||||||
return B_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnsetShadowPartition
|
|
||||||
void
|
|
||||||
KPartition::UnsetShadowPartition(bool doDelete)
|
|
||||||
{
|
|
||||||
// implemented by derived classes
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetDiskSystem
|
// SetDiskSystem
|
||||||
void
|
void
|
||||||
@@ -991,7 +1060,6 @@ KPartition::WriteUserData(UserDataWriter &writer, user_partition_data *data)
|
|||||||
// fill in data
|
// fill in data
|
||||||
if (data) {
|
if (data) {
|
||||||
data->id = ID();
|
data->id = ID();
|
||||||
data->shadow_id = -1;
|
|
||||||
data->offset = Offset();
|
data->offset = Offset();
|
||||||
data->size = Size();
|
data->size = Size();
|
||||||
data->content_size = ContentSize();
|
data->content_size = ContentSize();
|
||||||
|
|||||||
@@ -1,276 +0,0 @@
|
|||||||
// KPhysicalPartition.cpp
|
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include <Drivers.h>
|
|
||||||
#include <Errors.h>
|
|
||||||
#include <util/kernel_cpp.h>
|
|
||||||
#include <devfs.h>
|
|
||||||
|
|
||||||
#include "KDiskDevice.h"
|
|
||||||
#include "KDiskDeviceManager.h"
|
|
||||||
#include "KDiskDeviceUtils.h"
|
|
||||||
#include "KPath.h"
|
|
||||||
#include "KPhysicalPartition.h"
|
|
||||||
#include "KShadowPartition.h"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
// debugging
|
|
||||||
//#define DBG(x)
|
|
||||||
#define DBG(x) x
|
|
||||||
#define OUT dprintf
|
|
||||||
|
|
||||||
// constructor
|
|
||||||
KPhysicalPartition::KPhysicalPartition(partition_id id)
|
|
||||||
: KPartition(id),
|
|
||||||
fShadowPartition(NULL)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// destructor
|
|
||||||
KPhysicalPartition::~KPhysicalPartition()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// PrepareForRemoval
|
|
||||||
bool
|
|
||||||
KPhysicalPartition::PrepareForRemoval()
|
|
||||||
{
|
|
||||||
bool result = KPartition::PrepareForRemoval();
|
|
||||||
if (result) {
|
|
||||||
UnsetShadowPartition(false);
|
|
||||||
UnpublishDevice();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Open
|
|
||||||
status_t
|
|
||||||
KPhysicalPartition::Open(int flags, int *fd)
|
|
||||||
{
|
|
||||||
if (!fd)
|
|
||||||
return B_BAD_VALUE;
|
|
||||||
// get the path
|
|
||||||
KPath path;
|
|
||||||
status_t error = GetPath(&path);
|
|
||||||
if (error != B_OK)
|
|
||||||
return error;
|
|
||||||
// open the device
|
|
||||||
*fd = open(path.Path(), flags);
|
|
||||||
if (*fd < 0)
|
|
||||||
return errno;
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PublishDevice
|
|
||||||
status_t
|
|
||||||
KPhysicalPartition::PublishDevice()
|
|
||||||
{
|
|
||||||
if (fPublished)
|
|
||||||
return B_OK;
|
|
||||||
|
|
||||||
// get the path
|
|
||||||
KPath path;
|
|
||||||
status_t error = GetPath(&path);
|
|
||||||
if (error != B_OK)
|
|
||||||
return error;
|
|
||||||
|
|
||||||
// prepare a partition_info
|
|
||||||
partition_info info;
|
|
||||||
info.offset = Offset();
|
|
||||||
info.size = Size();
|
|
||||||
info.logical_block_size = BlockSize();
|
|
||||||
info.session = 0;
|
|
||||||
info.partition = ID();
|
|
||||||
if (strlcpy(info.device, Device()->Path(), B_PATH_NAME_LENGTH)
|
|
||||||
>= B_PATH_NAME_LENGTH) {
|
|
||||||
return B_NAME_TOO_LONG;
|
|
||||||
}
|
|
||||||
|
|
||||||
error = devfs_publish_partition(path.Path() + 5, &info);
|
|
||||||
// we need to remove the "/dev/" part from the path
|
|
||||||
if (error != B_OK)
|
|
||||||
return error;
|
|
||||||
|
|
||||||
fPublished = true;
|
|
||||||
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnpublishDevice
|
|
||||||
status_t
|
|
||||||
KPhysicalPartition::UnpublishDevice()
|
|
||||||
{
|
|
||||||
if (!fPublished)
|
|
||||||
return B_OK;
|
|
||||||
|
|
||||||
// get the path
|
|
||||||
KPath path;
|
|
||||||
status_t error = GetPath(&path);
|
|
||||||
if (error != B_OK)
|
|
||||||
return error;
|
|
||||||
|
|
||||||
fPublished = false;
|
|
||||||
|
|
||||||
return devfs_unpublish_partition(path.Path() + 5);
|
|
||||||
// we need to remove the "/dev/" part from the path
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mount
|
|
||||||
status_t
|
|
||||||
KPhysicalPartition::Mount(uint32 mountFlags, const char *parameters)
|
|
||||||
{
|
|
||||||
// not implemented
|
|
||||||
return B_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unmount
|
|
||||||
status_t
|
|
||||||
KPhysicalPartition::Unmount()
|
|
||||||
{
|
|
||||||
// not implemented
|
|
||||||
return B_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateChild
|
|
||||||
status_t
|
|
||||||
KPhysicalPartition::CreateChild(partition_id id, int32 index,
|
|
||||||
KPartition **_child)
|
|
||||||
{
|
|
||||||
// check parameters
|
|
||||||
int32 count = fPartitionData.child_count;
|
|
||||||
if (index == -1)
|
|
||||||
index = count;
|
|
||||||
if (index < 0 || index > count)
|
|
||||||
return B_BAD_VALUE;
|
|
||||||
// create and add partition
|
|
||||||
KPhysicalPartition *child = new(nothrow) KPhysicalPartition(id);
|
|
||||||
if (!child)
|
|
||||||
return B_NO_MEMORY;
|
|
||||||
status_t error = AddChild(child, index);
|
|
||||||
// cleanup / set result
|
|
||||||
if (error != B_OK)
|
|
||||||
delete child;
|
|
||||||
else if (_child)
|
|
||||||
*_child = child;
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateShadowPartition
|
|
||||||
status_t
|
|
||||||
KPhysicalPartition::CreateShadowPartition()
|
|
||||||
{
|
|
||||||
if (fShadowPartition)
|
|
||||||
return B_BAD_VALUE;
|
|
||||||
|
|
||||||
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
||||||
if (ManagerLocker locker = manager) {
|
|
||||||
// create shadow partition
|
|
||||||
fShadowPartition = new(nothrow) KShadowPartition(this);
|
|
||||||
if (!fShadowPartition)
|
|
||||||
return B_NO_MEMORY;
|
|
||||||
|
|
||||||
// make it known to the manager
|
|
||||||
if (!manager->PartitionAdded(fShadowPartition)) {
|
|
||||||
delete fShadowPartition;
|
|
||||||
fShadowPartition = NULL;
|
|
||||||
return B_NO_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
// notify the disk systems
|
|
||||||
// parent disk system
|
|
||||||
status_t error;
|
|
||||||
if (Parent()) {
|
|
||||||
error = Parent()->DiskSystem()->ShadowPartitionChanged(
|
|
||||||
Parent()->ShadowPartition(), fShadowPartition,
|
|
||||||
B_PARTITION_SHADOW_CHILD);
|
|
||||||
if (error != B_OK) {
|
|
||||||
UnsetShadowPartition(true);
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// this partition's disk system
|
|
||||||
if (fShadowPartition->DiskSystem()) {
|
|
||||||
error = fShadowPartition->DiskSystem()->ShadowPartitionChanged(
|
|
||||||
fShadowPartition, NULL, B_PARTITION_SHADOW);
|
|
||||||
if (error != B_OK) {
|
|
||||||
UnsetShadowPartition(true);
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif // 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// create shadows for children
|
|
||||||
for (int32 i = 0; KPartition *child = ChildAt(i); i++) {
|
|
||||||
status_t error = child->CreateShadowPartition();
|
|
||||||
if (error == B_OK)
|
|
||||||
error = fShadowPartition->AddChild(child->ShadowPartition(), i);
|
|
||||||
|
|
||||||
// cleanup on error
|
|
||||||
if (error != B_OK) {
|
|
||||||
for (int32 k = 0; k <= i; k++)
|
|
||||||
ChildAt(k)->UnsetShadowPartition(true);
|
|
||||||
UnsetShadowPartition(true);
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnsetShadowPartition
|
|
||||||
void
|
|
||||||
KPhysicalPartition::UnsetShadowPartition(bool doDelete)
|
|
||||||
{
|
|
||||||
if (!fShadowPartition)
|
|
||||||
return;
|
|
||||||
// unset children's shadows
|
|
||||||
for (int32 i = 0; KPartition *child = ChildAt(i); i++)
|
|
||||||
child->UnsetShadowPartition(false);
|
|
||||||
// unset the thing
|
|
||||||
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
||||||
if (ManagerLocker locker = manager) {
|
|
||||||
fShadowPartition->UnsetPhysicalPartition();
|
|
||||||
if (doDelete) {
|
|
||||||
PartitionRegistrar _(fShadowPartition);
|
|
||||||
manager->PartitionRemoved(fShadowPartition);
|
|
||||||
}
|
|
||||||
fShadowPartition = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ShadowPartition
|
|
||||||
KShadowPartition *
|
|
||||||
KPhysicalPartition::ShadowPartition() const
|
|
||||||
{
|
|
||||||
return fShadowPartition;
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsShadowPartition
|
|
||||||
bool
|
|
||||||
KPhysicalPartition::IsShadowPartition() const
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PhysicalPartition
|
|
||||||
KPhysicalPartition *
|
|
||||||
KPhysicalPartition::PhysicalPartition() const
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dump
|
|
||||||
void
|
|
||||||
KPhysicalPartition::Dump(bool deep, int32 level)
|
|
||||||
{
|
|
||||||
KPartition::Dump(deep, level);
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,291 +0,0 @@
|
|||||||
// KShadowPartition.cpp
|
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include <Drivers.h>
|
|
||||||
#include <Errors.h>
|
|
||||||
#include <util/kernel_cpp.h>
|
|
||||||
|
|
||||||
#include "ddm_userland_interface.h"
|
|
||||||
#include "KDiskDevice.h"
|
|
||||||
#include "KDiskDeviceManager.h"
|
|
||||||
#include "KDiskDeviceUtils.h"
|
|
||||||
#include "KShadowPartition.h"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
// debugging
|
|
||||||
//#define DBG(x)
|
|
||||||
#define DBG(x) x
|
|
||||||
#define OUT dprintf
|
|
||||||
|
|
||||||
// constructor
|
|
||||||
KShadowPartition::KShadowPartition(KPhysicalPartition *partition)
|
|
||||||
: KPartition(),
|
|
||||||
KPartitionListener(),
|
|
||||||
fPhysicalPartition(partition)
|
|
||||||
{
|
|
||||||
SyncWithPhysicalPartition();
|
|
||||||
if (fPhysicalPartition)
|
|
||||||
fPhysicalPartition->AddListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
// destructor
|
|
||||||
KShadowPartition::~KShadowPartition()
|
|
||||||
{
|
|
||||||
UnsetPhysicalPartition();
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateChild
|
|
||||||
status_t
|
|
||||||
KShadowPartition::CreateChild(partition_id id, int32 index,
|
|
||||||
KPartition **_child)
|
|
||||||
{
|
|
||||||
// check parameters
|
|
||||||
int32 count = fPartitionData.child_count;
|
|
||||||
if (index == -1)
|
|
||||||
index = count;
|
|
||||||
if (index < 0 || index > count)
|
|
||||||
return B_BAD_VALUE;
|
|
||||||
// create and add partition
|
|
||||||
KShadowPartition *child = new(nothrow) KShadowPartition(NULL);
|
|
||||||
if (!child)
|
|
||||||
return B_NO_MEMORY;
|
|
||||||
status_t error = AddChild(child, index);
|
|
||||||
// cleanup / set result
|
|
||||||
if (error != B_OK)
|
|
||||||
delete child;
|
|
||||||
else if (_child)
|
|
||||||
*_child = child;
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsShadowPartition
|
|
||||||
bool
|
|
||||||
KShadowPartition::IsShadowPartition() const
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ShadowPartition
|
|
||||||
KShadowPartition*
|
|
||||||
KShadowPartition::ShadowPartition() const
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnsetPhysicalPartition
|
|
||||||
void
|
|
||||||
KShadowPartition::UnsetPhysicalPartition()
|
|
||||||
{
|
|
||||||
if (fPhysicalPartition) {
|
|
||||||
fPhysicalPartition->RemoveListener(this);
|
|
||||||
fPhysicalPartition = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// PhysicalPartition
|
|
||||||
KPhysicalPartition*
|
|
||||||
KShadowPartition::PhysicalPartition() const
|
|
||||||
{
|
|
||||||
return fPhysicalPartition;
|
|
||||||
}
|
|
||||||
|
|
||||||
// SyncWithPhysicalPartition
|
|
||||||
void
|
|
||||||
KShadowPartition::SyncWithPhysicalPartition()
|
|
||||||
{
|
|
||||||
if (!fPhysicalPartition)
|
|
||||||
return;
|
|
||||||
SetDevice(fPhysicalPartition->Device());
|
|
||||||
SetDiskSystem(fPhysicalPartition->DiskSystem());
|
|
||||||
SetOffset(fPhysicalPartition->Offset());
|
|
||||||
SetSize(fPhysicalPartition->Size());
|
|
||||||
SetContentSize(fPhysicalPartition->ContentSize());
|
|
||||||
SetBlockSize(fPhysicalPartition->BlockSize());
|
|
||||||
SetStatus(fPhysicalPartition->Status());
|
|
||||||
SetFlags(fPhysicalPartition->Flags());
|
|
||||||
SetName(fPhysicalPartition->Name());
|
|
||||||
SetContentName(fPhysicalPartition->ContentName());
|
|
||||||
SetType(fPhysicalPartition->Type());
|
|
||||||
SetVolumeID(fPhysicalPartition->VolumeID());
|
|
||||||
SetParameters(fPhysicalPartition->Parameters());
|
|
||||||
SetContentParameters(fPhysicalPartition->ContentParameters());
|
|
||||||
// TODO: Cookie, ContentCookie, MountCookie?
|
|
||||||
}
|
|
||||||
|
|
||||||
// WriteUserData
|
|
||||||
void
|
|
||||||
KShadowPartition::WriteUserData(UserDataWriter &writer,
|
|
||||||
user_partition_data *data)
|
|
||||||
{
|
|
||||||
KPartition::WriteUserData(writer, data);
|
|
||||||
// fix the ID in the user data
|
|
||||||
if (data) {
|
|
||||||
if (fPhysicalPartition)
|
|
||||||
data->id = fPhysicalPartition->ID();
|
|
||||||
data->shadow_id = ID();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dump
|
|
||||||
void
|
|
||||||
KShadowPartition::Dump(bool deep, int32 level)
|
|
||||||
{
|
|
||||||
KPartition::Dump(deep, level);
|
|
||||||
}
|
|
||||||
|
|
||||||
// OffsetChanged
|
|
||||||
void
|
|
||||||
KShadowPartition::OffsetChanged(KPartition *partition, off_t offset)
|
|
||||||
{
|
|
||||||
SetOffset(offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
// SizeChanged
|
|
||||||
void
|
|
||||||
KShadowPartition::SizeChanged(KPartition *partition, off_t size)
|
|
||||||
{
|
|
||||||
SetSize(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ContentSizeChanged
|
|
||||||
void
|
|
||||||
KShadowPartition::ContentSizeChanged(KPartition *partition, off_t size)
|
|
||||||
{
|
|
||||||
SetContentSize(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
// BlockSizeChanged
|
|
||||||
void
|
|
||||||
KShadowPartition::BlockSizeChanged(KPartition *partition, uint32 blockSize)
|
|
||||||
{
|
|
||||||
SetBlockSize(blockSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
// IndexChanged
|
|
||||||
void
|
|
||||||
KShadowPartition::IndexChanged(KPartition *partition, int32 index)
|
|
||||||
{
|
|
||||||
// should be set automatically
|
|
||||||
}
|
|
||||||
|
|
||||||
// StatusChanged
|
|
||||||
void
|
|
||||||
KShadowPartition::StatusChanged(KPartition *partition, uint32 status)
|
|
||||||
{
|
|
||||||
SetStatus(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
// FlagsChanged
|
|
||||||
void
|
|
||||||
KShadowPartition::FlagsChanged(KPartition *partition, uint32 flags)
|
|
||||||
{
|
|
||||||
SetFlags(flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
// NameChanged
|
|
||||||
void
|
|
||||||
KShadowPartition::NameChanged(KPartition *partition, const char *name)
|
|
||||||
{
|
|
||||||
SetName(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ContentNameChanged
|
|
||||||
void
|
|
||||||
KShadowPartition::ContentNameChanged(KPartition *partition, const char *name)
|
|
||||||
{
|
|
||||||
SetContentName(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TypeChanged
|
|
||||||
void
|
|
||||||
KShadowPartition::TypeChanged(KPartition *partition, const char *type)
|
|
||||||
{
|
|
||||||
SetType(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
// IDChanged
|
|
||||||
void
|
|
||||||
KShadowPartition::IDChanged(KPartition *partition, partition_id id)
|
|
||||||
{
|
|
||||||
// nothing to do
|
|
||||||
}
|
|
||||||
|
|
||||||
// VolumeIDChanged
|
|
||||||
void
|
|
||||||
KShadowPartition::VolumeIDChanged(KPartition *partition, dev_t volumeID)
|
|
||||||
{
|
|
||||||
SetVolumeID(volumeID);
|
|
||||||
}
|
|
||||||
|
|
||||||
// MountCookieChanged
|
|
||||||
void
|
|
||||||
KShadowPartition::MountCookieChanged(KPartition *partition, void *cookie)
|
|
||||||
{
|
|
||||||
// TODO: set the mount cookie?
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParametersChanged
|
|
||||||
void
|
|
||||||
KShadowPartition::ParametersChanged(KPartition *partition,
|
|
||||||
const char *parameters)
|
|
||||||
{
|
|
||||||
SetParameters(parameters);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ContentParametersChanged
|
|
||||||
void
|
|
||||||
KShadowPartition::ContentParametersChanged(KPartition *partition,
|
|
||||||
const char *parameters)
|
|
||||||
{
|
|
||||||
SetContentParameters(parameters);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ChildAdded
|
|
||||||
void
|
|
||||||
KShadowPartition::ChildAdded(KPartition *partition, KPartition *child,
|
|
||||||
int32 index)
|
|
||||||
{
|
|
||||||
// TODO: Mmh, in the CreateShadowPartition() phase, creating and
|
|
||||||
// adding the shadow partitions is done recursively and we shouldn't
|
|
||||||
// do that here. But when a new partition is added later?
|
|
||||||
// Maybe KPhysicalPartition::CreateChild() should create a shadow for
|
|
||||||
// the new child manually.
|
|
||||||
}
|
|
||||||
|
|
||||||
// ChildRemoved
|
|
||||||
void
|
|
||||||
KShadowPartition::ChildRemoved(KPartition *partition, KPartition *child,
|
|
||||||
int32 index)
|
|
||||||
{
|
|
||||||
// TODO: We could remove the corresponding partition, but for consistency
|
|
||||||
// we should proceed analogously to adding partitions.
|
|
||||||
}
|
|
||||||
|
|
||||||
// DiskSystemChanged
|
|
||||||
void
|
|
||||||
KShadowPartition::DiskSystemChanged(KPartition *partition,
|
|
||||||
KDiskSystem *diskSystem)
|
|
||||||
{
|
|
||||||
SetDiskSystem(diskSystem);
|
|
||||||
}
|
|
||||||
|
|
||||||
// CookieChanged
|
|
||||||
void
|
|
||||||
KShadowPartition::CookieChanged(KPartition *partition, void *cookie)
|
|
||||||
{
|
|
||||||
// TODO: set the cookie?
|
|
||||||
}
|
|
||||||
|
|
||||||
// ContentCookieChanged
|
|
||||||
void
|
|
||||||
KShadowPartition::ContentCookieChanged(KPartition *partition, void *cookie)
|
|
||||||
{
|
|
||||||
// TODO: set the content cookie?
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -12,7 +12,6 @@
|
|||||||
#include <KDiskDeviceUtils.h>
|
#include <KDiskDeviceUtils.h>
|
||||||
#include <KDiskSystem.h>
|
#include <KDiskSystem.h>
|
||||||
#include <KFileDiskDevice.h>
|
#include <KFileDiskDevice.h>
|
||||||
#include <KShadowPartition.h>
|
|
||||||
#include <syscall_args.h>
|
#include <syscall_args.h>
|
||||||
|
|
||||||
#include "UserDataWriter.h"
|
#include "UserDataWriter.h"
|
||||||
@@ -105,7 +104,7 @@ _user_get_next_disk_device_id(int32 *_cookie, size_t *neededSize)
|
|||||||
if (DeviceReadLocker locker = device) {
|
if (DeviceReadLocker locker = device) {
|
||||||
// get the needed size
|
// get the needed size
|
||||||
UserDataWriter writer;
|
UserDataWriter writer;
|
||||||
device->WriteUserData(writer, false);
|
device->WriteUserData(writer);
|
||||||
*neededSize = writer.AllocatedSize();
|
*neededSize = writer.AllocatedSize();
|
||||||
} else {
|
} else {
|
||||||
id = B_ERROR;
|
id = B_ERROR;
|
||||||
@@ -139,7 +138,7 @@ _user_find_disk_device(const char *_filename, size_t *neededSize)
|
|||||||
if (DeviceReadLocker locker = device) {
|
if (DeviceReadLocker locker = device) {
|
||||||
// get the needed size
|
// get the needed size
|
||||||
UserDataWriter writer;
|
UserDataWriter writer;
|
||||||
device->WriteUserData(writer, false);
|
device->WriteUserData(writer);
|
||||||
*neededSize = writer.AllocatedSize();
|
*neededSize = writer.AllocatedSize();
|
||||||
} else
|
} else
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
@@ -176,7 +175,7 @@ _user_find_partition(const char *_filename, size_t *neededSize)
|
|||||||
if (DeviceReadLocker locker = device) {
|
if (DeviceReadLocker locker = device) {
|
||||||
// get the needed size
|
// get the needed size
|
||||||
UserDataWriter writer;
|
UserDataWriter writer;
|
||||||
device->WriteUserData(writer, false);
|
device->WriteUserData(writer);
|
||||||
*neededSize = writer.AllocatedSize();
|
*neededSize = writer.AllocatedSize();
|
||||||
} else
|
} else
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
@@ -206,9 +205,6 @@ _user_find_partition(const char *_filename, size_t *neededSize)
|
|||||||
itself (if \a deviceOnly is true).
|
itself (if \a deviceOnly is true).
|
||||||
\param deviceOnly Specifies whether only IDs of disk devices (\c true),
|
\param deviceOnly Specifies whether only IDs of disk devices (\c true),
|
||||||
or also IDs of partitions (\c false) are accepted for \a id.
|
or also IDs of partitions (\c false) are accepted for \a id.
|
||||||
\param shadow If \c true, the data of the shadow disk device is returned,
|
|
||||||
otherwise of the physical device. If there is no shadow device,
|
|
||||||
the parameter is ignored.
|
|
||||||
\param buffer The buffer into which the disk device data shall be written.
|
\param buffer The buffer into which the disk device data shall be written.
|
||||||
May be \c NULL.
|
May be \c NULL.
|
||||||
\param bufferSize The size of \a buffer.
|
\param bufferSize The size of \a buffer.
|
||||||
@@ -229,7 +225,7 @@ _user_find_partition(const char *_filename, size_t *neededSize)
|
|||||||
- another error code...
|
- another error code...
|
||||||
*/
|
*/
|
||||||
status_t
|
status_t
|
||||||
_user_get_disk_device_data(partition_id id, bool deviceOnly, bool shadow,
|
_user_get_disk_device_data(partition_id id, bool deviceOnly,
|
||||||
user_disk_device_data *buffer, size_t bufferSize, size_t *_neededSize)
|
user_disk_device_data *buffer, size_t bufferSize, size_t *_neededSize)
|
||||||
{
|
{
|
||||||
if (!buffer && bufferSize > 0)
|
if (!buffer && bufferSize > 0)
|
||||||
@@ -241,7 +237,7 @@ _user_get_disk_device_data(partition_id id, bool deviceOnly, bool shadow,
|
|||||||
if (DeviceReadLocker locker = device) {
|
if (DeviceReadLocker locker = device) {
|
||||||
// do a dry run first to get the needed size
|
// do a dry run first to get the needed size
|
||||||
UserDataWriter writer;
|
UserDataWriter writer;
|
||||||
device->WriteUserData(writer, shadow);
|
device->WriteUserData(writer);
|
||||||
size_t neededSize = writer.AllocatedSize();
|
size_t neededSize = writer.AllocatedSize();
|
||||||
if (_neededSize) {
|
if (_neededSize) {
|
||||||
status_t error = copy_ref_var_to_user(neededSize, _neededSize);
|
status_t error = copy_ref_var_to_user(neededSize, _neededSize);
|
||||||
@@ -260,7 +256,7 @@ _user_get_disk_device_data(partition_id id, bool deviceOnly, bool shadow,
|
|||||||
MemoryDeleter deleter(kernelBuffer);
|
MemoryDeleter deleter(kernelBuffer);
|
||||||
// write the device data into the buffer
|
// write the device data into the buffer
|
||||||
writer.SetTo(kernelBuffer, bufferSize);
|
writer.SetTo(kernelBuffer, bufferSize);
|
||||||
device->WriteUserData(writer, shadow);
|
device->WriteUserData(writer);
|
||||||
// sanity check
|
// sanity check
|
||||||
if (writer.AllocatedSize() != neededSize) {
|
if (writer.AllocatedSize() != neededSize) {
|
||||||
ERROR(("Size of written disk device user data changed from "
|
ERROR(("Size of written disk device user data changed from "
|
||||||
|
|||||||
@@ -119,22 +119,12 @@ get_disk_device(partition_id partitionID)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// get_physical_partition
|
|
||||||
partition_data*
|
|
||||||
get_physical_partition(partition_id partitionID)
|
|
||||||
{
|
|
||||||
KDiskDeviceManager* manager = KDiskDeviceManager::Default();
|
|
||||||
KPartition* partition = manager->FindPartition(partitionID, true);
|
|
||||||
return (partition ? partition->PartitionData() : NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// get_partition
|
// get_partition
|
||||||
partition_data *
|
partition_data *
|
||||||
get_partition(partition_id partitionID)
|
get_partition(partition_id partitionID)
|
||||||
{
|
{
|
||||||
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
||||||
KPartition *partition = manager->FindPartition(partitionID, false);
|
KPartition *partition = manager->FindPartition(partitionID);
|
||||||
return (partition ? partition->PartitionData() : NULL);
|
return (partition ? partition->PartitionData() : NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5343,7 +5343,7 @@ fs_mount(char *path, const char *device, const char *fsName, uint32 flags,
|
|||||||
return status;
|
return status;
|
||||||
|
|
||||||
// get a corresponding partition from the DDM
|
// get a corresponding partition from the DDM
|
||||||
partition = ddm->RegisterPartition(normalizedDevice.Path(), true);
|
partition = ddm->RegisterPartition(normalizedDevice.Path());
|
||||||
|
|
||||||
if (!partition) {
|
if (!partition) {
|
||||||
// Partition not found: This either means, the user supplied
|
// Partition not found: This either means, the user supplied
|
||||||
@@ -5352,7 +5352,7 @@ fs_mount(char *path, const char *device, const char *fsName, uint32 flags,
|
|||||||
partition_id deviceID = ddm->CreateFileDevice(normalizedDevice.Path(),
|
partition_id deviceID = ddm->CreateFileDevice(normalizedDevice.Path(),
|
||||||
&newlyCreatedFileDevice);
|
&newlyCreatedFileDevice);
|
||||||
if (deviceID >= 0) {
|
if (deviceID >= 0) {
|
||||||
partition = ddm->RegisterPartition(deviceID, true);
|
partition = ddm->RegisterPartition(deviceID);
|
||||||
if (newlyCreatedFileDevice)
|
if (newlyCreatedFileDevice)
|
||||||
fileDeviceDeleter.id = deviceID;
|
fileDeviceDeleter.id = deviceID;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user