diff --git a/headers/private/kernel/disk_device_manager/KDiskDevice.h b/headers/private/kernel/disk_device_manager/KDiskDevice.h index 50b8c21a37..6ea59a78f9 100644 --- a/headers/private/kernel/disk_device_manager/KDiskDevice.h +++ b/headers/private/kernel/disk_device_manager/KDiskDevice.h @@ -41,6 +41,9 @@ public: virtual void SetID(partition_id id); + virtual status_t PublishDevice(); + virtual status_t UnpublishDevice(); + void SetDeviceFlags(uint32 flags); // comprises the ones below uint32 DeviceFlags() const; bool IsRemovable() const; diff --git a/headers/private/kernel/disk_device_manager/KPartition.h b/headers/private/kernel/disk_device_manager/KPartition.h index ef56bc8c97..9e70012f50 100644 --- a/headers/private/kernel/disk_device_manager/KPartition.h +++ b/headers/private/kernel/disk_device_manager/KPartition.h @@ -37,8 +37,8 @@ public: int32 CountReferences() const; status_t Open(int flags, int *fd); - status_t PublishDevice(); - status_t UnpublishDevice(); + virtual status_t PublishDevice(); + virtual status_t UnpublishDevice(); void SetBusy(bool busy); bool IsBusy() const; diff --git a/src/kernel/core/disk_device_manager/KDiskDevice.cpp b/src/kernel/core/disk_device_manager/KDiskDevice.cpp index 8996f7278b..37bbe241c5 100644 --- a/src/kernel/core/disk_device_manager/KDiskDevice.cpp +++ b/src/kernel/core/disk_device_manager/KDiskDevice.cpp @@ -125,6 +125,25 @@ KDiskDevice::SetID(partition_id id) fDeviceData.id = id; } +// PublishDevice +status_t +KDiskDevice::PublishDevice() +{ + // PublishDevice() and UnpublishDevice() are no-ops for KDiskDevices, + // since they are always published. + return B_OK; +} + +// UnpublishDevice +status_t +KDiskDevice::UnpublishDevice() +{ + // PublishDevice() and UnpublishDevice() are no-ops for KDiskDevices, + // since they are always published. + return B_OK; +} + + // SetDeviceFlags void KDiskDevice::SetDeviceFlags(uint32 flags) diff --git a/src/kernel/core/disk_device_manager/KPartition.cpp b/src/kernel/core/disk_device_manager/KPartition.cpp index 077efa6e34..0ed3ed1f79 100644 --- a/src/kernel/core/disk_device_manager/KPartition.cpp +++ b/src/kernel/core/disk_device_manager/KPartition.cpp @@ -5,7 +5,9 @@ #include #include #include +#include +#include #include //#include @@ -103,16 +105,46 @@ KPartition::Open(int flags, int *fd) status_t KPartition::PublishDevice() { - // not implemented - return B_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 (strlen(Device()->Path()) >= 256) + return B_NAME_TOO_LONG; + strcpy(info.device, Device()->Path()); + // get the entry path + char path[B_PATH_NAME_LENGTH]; + status_t error = GetPath(path); + if (error != B_OK) + return error; + // create the entry + int fd = creat(path, 0666); + if (fd < 0) + return errno; + // set the partition info + error = B_OK; + if (ioctl(fd, B_SET_PARTITION, &info) < 0) + error = errno; + close(fd); + return error; } // UnpublishDevice status_t KPartition::UnpublishDevice() { - // not implemented - return B_ERROR; + // get the entry path + char path[B_PATH_NAME_LENGTH]; + status_t error = GetPath(path); + if (error != B_OK) + return error; + // remove the entry + if (remove(path) < 0) + return errno; + return B_OK; } // SetBusy @@ -381,7 +413,10 @@ KPartition::GetPath(char *path) const int32 leafLen = strlen("/raw"); if (len <= leafLen || strcmp(path + len - leafLen, "/raw")) return B_ERROR; - sprintf(path + len - leafLen + 1, "%ld", Index()); +// TODO: For the time being the name is "obos_*" to not interfere with R5's +// names. +// sprintf(path + len - leafLen + 1, "%ld", Index()); + sprintf(path + len - leafLen + 1, "obos_%ld", Index()); } else { // Our parent is a normal partition, no device: Append our index. sprintf(path + len, "_%ld", Index());