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
This commit is contained in:
Ingo Weinhold 2008-07-13 12:50:35 +00:00
parent 64789466f1
commit f9f2d81621
2 changed files with 38 additions and 0 deletions

View File

@ -114,6 +114,12 @@ status_t scan_partition(partition_id partitionID);
// Service method for disks systems: Synchronously scans the partition. // Service method for disks systems: Synchronously scans the partition.
// Device must not be locked. // 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 systems
disk_system_id find_disk_system(const char *name); disk_system_id find_disk_system(const char *name);

View File

@ -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 // find_disk_system
disk_system_id disk_system_id
find_disk_system(const char *name) find_disk_system(const char *name)