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
This commit is contained in:
Ingo Weinhold
2008-07-15 11:28:18 +00:00
parent 8c121d2ca1
commit 0629fe02b3
@@ -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;
}