From 0629fe02b37fb9d34e3440e1e8ed3a5d8582ead3 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Tue, 15 Jul 2008 11:28:18 +0000 Subject: [PATCH] Properly round the partition size in get_default_partition_content_name(). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26417 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../disk_device_manager.cpp | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) 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 37fff53fef..abdd60fe31 100644 --- a/src/system/kernel/disk_device_manager/disk_device_manager.cpp +++ b/src/system/kernel/disk_device_manager/disk_device_manager.cpp @@ -234,23 +234,25 @@ get_default_partition_content_name(partition_id partitionID, if (partition == NULL) return B_ENTRY_NOT_FOUND; - off_t size = partition->ContentSize(); + double size = partition->ContentSize(); partition->Unregister(); - const char* const suffixes[] = { - "", "K", "M", "G", "T", "P", "E", NULL - }; + 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++; - } + int index = 0; + while (size >= 1024 && suffixes[index + 1]) { + size /= 1024; + index++; + } - snprintf(buffer, bufferSize, "%s Volume (%ld.%ld %sB)", fileSystemName, - int32(size / 10), int32(size % 10), suffixes[index]); + // Our kernel snprintf() ignores the precision argument, so we manually + // do one digit precision. + uint64 result = uint64(size * 10 + 0.5); + + snprintf(buffer, bufferSize, "%s Volume (%ld.%ld %sB)", fileSystemName, + int32(result / 10), int32(result % 10), suffixes[index]); return B_OK; }