From f9f2d81621773564eb49394e172ab8bb198471f2 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sun, 13 Jul 2008 12:50:35 +0000 Subject: [PATCH] Added helper function get_default_partition_content_name() that can be used by file systems to get a useful name, if the file system (or just that specific volume) doesn't have one. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26403 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/os/drivers/disk_device_manager.h | 6 ++++ .../disk_device_manager.cpp | 32 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/headers/os/drivers/disk_device_manager.h b/headers/os/drivers/disk_device_manager.h index 54e156246f..a36d72609e 100644 --- a/headers/os/drivers/disk_device_manager.h +++ b/headers/os/drivers/disk_device_manager.h @@ -114,6 +114,12 @@ status_t scan_partition(partition_id partitionID); // Service method for disks systems: Synchronously scans the partition. // Device must not be locked. +// partition support functions +// (no lock required) +status_t get_default_partition_content_name(partition_id partitionID, + const char* fileSystemName, char* buffer, size_t bufferSize); + // The partition_data::content_size field must already be initialized. + // disk systems disk_system_id find_disk_system(const char *name); diff --git a/src/system/kernel/disk_device_manager/disk_device_manager.cpp b/src/system/kernel/disk_device_manager/disk_device_manager.cpp index 8d367cf8ca..37fff53fef 100644 --- a/src/system/kernel/disk_device_manager/disk_device_manager.cpp +++ b/src/system/kernel/disk_device_manager/disk_device_manager.cpp @@ -224,6 +224,38 @@ scan_partition(partition_id partitionID) } +// get_default_partition_content_name +status_t +get_default_partition_content_name(partition_id partitionID, + const char* fileSystemName, char* buffer, size_t bufferSize) +{ + KDiskDeviceManager *manager = KDiskDeviceManager::Default(); + KPartition *partition = manager->RegisterPartition(partitionID); + if (partition == NULL) + return B_ENTRY_NOT_FOUND; + + off_t size = partition->ContentSize(); + partition->Unregister(); + + const char* const suffixes[] = { + "", "K", "M", "G", "T", "P", "E", NULL + }; + + size *= 10; + // We want one digit precision. + int index = 0; + while (size >= 1024 * 10 && suffixes[index + 1]) { + size /= 1024; + index++; + } + + snprintf(buffer, bufferSize, "%s Volume (%ld.%ld %sB)", fileSystemName, + int32(size / 10), int32(size % 10), suffixes[index]); + + return B_OK; +} + + // find_disk_system disk_system_id find_disk_system(const char *name)