diff --git a/headers/private/kernel/disk_device_manager/KPartition.h b/headers/private/kernel/disk_device_manager/KPartition.h index 14063692b6..23716c58f7 100644 --- a/headers/private/kernel/disk_device_manager/KPartition.h +++ b/headers/private/kernel/disk_device_manager/KPartition.h @@ -49,6 +49,7 @@ public: virtual status_t Open(int flags, int *fd); virtual status_t PublishDevice(); virtual status_t UnpublishDevice(); + bool IsPublished() const; void SetBusy(bool busy); bool IsBusy() const; @@ -234,6 +235,7 @@ protected: uint32 fAlgorithmData; int32 fReferenceCount; bool fObsolete; + bool fPublished; static int32 fNextID; }; diff --git a/src/system/kernel/disk_device_manager/KDiskDevice.cpp b/src/system/kernel/disk_device_manager/KDiskDevice.cpp index 90cda405a3..62ce05c26b 100644 --- a/src/system/kernel/disk_device_manager/KDiskDevice.cpp +++ b/src/system/kernel/disk_device_manager/KDiskDevice.cpp @@ -31,6 +31,7 @@ KDiskDevice::KDiskDevice(partition_id id) { Unset(); fDevice = this; + fPublished = true; } // destructor diff --git a/src/system/kernel/disk_device_manager/KPartition.cpp b/src/system/kernel/disk_device_manager/KPartition.cpp index 6b0b428244..13adc4961b 100644 --- a/src/system/kernel/disk_device_manager/KPartition.cpp +++ b/src/system/kernel/disk_device_manager/KPartition.cpp @@ -46,7 +46,8 @@ KPartition::KPartition(partition_id id) fChangeCounter(0), fAlgorithmData(0), fReferenceCount(0), - fObsolete(false) + fObsolete(false), + fPublished(false) { fPartitionData.id = (id >= 0 ? id : _NextID()); fPartitionData.offset = 0; @@ -164,6 +165,15 @@ KPartition::UnpublishDevice() return B_ERROR; } + +// IsPublished +bool +KPartition::IsPublished() const +{ + return fPublished; +} + + // SetBusy void KPartition::SetBusy(bool busy) diff --git a/src/system/kernel/disk_device_manager/KPhysicalPartition.cpp b/src/system/kernel/disk_device_manager/KPhysicalPartition.cpp index b491189dae..f0f353f3f7 100644 --- a/src/system/kernel/disk_device_manager/KPhysicalPartition.cpp +++ b/src/system/kernel/disk_device_manager/KPhysicalPartition.cpp @@ -37,7 +37,6 @@ KPhysicalPartition::~KPhysicalPartition() { } -// Register // PrepareForRemoval bool KPhysicalPartition::PrepareForRemoval() @@ -72,6 +71,9 @@ KPhysicalPartition::Open(int flags, int *fd) status_t KPhysicalPartition::PublishDevice() { + if (fPublished) + return B_OK; + // get the path KPath path; status_t error = GetPath(&path); @@ -90,20 +92,31 @@ KPhysicalPartition::PublishDevice() return B_NAME_TOO_LONG; } - return devfs_publish_partition(path.Path() + 5, &info); + 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 }