diff --git a/headers/private/storage/MutablePartition.h b/headers/private/storage/MutablePartition.h index 61df51b7b9..178a5c28b7 100644 --- a/headers/private/storage/MutablePartition.h +++ b/headers/private/storage/MutablePartition.h @@ -43,7 +43,7 @@ public: const char* Name() const; status_t SetName(const char* name); - const char* ContentName() const; + BString ContentName() const; status_t SetContentName(const char* name); const char* Type() const; diff --git a/headers/private/storage/Partition.h b/headers/private/storage/Partition.h index a0e356bb4c..aff04da79c 100644 --- a/headers/private/storage/Partition.h +++ b/headers/private/storage/Partition.h @@ -52,7 +52,7 @@ public: uint32 Flags() const; const char* Name() const; - const char* ContentName() const; + BString ContentName() const; const char* Type() const; // See DiskDeviceTypes.h const char* ContentType() const; // See DiskDeviceTypes.h partition_id ID() const; diff --git a/src/apps/drivesetup/Support.cpp b/src/apps/drivesetup/Support.cpp index 5de07d6025..72361173c3 100644 --- a/src/apps/drivesetup/Support.cpp +++ b/src/apps/drivesetup/Support.cpp @@ -51,7 +51,7 @@ dump_partition_info(const BPartition* partition) printf("\tIsBusy(): %s\n\n", partition->IsBusy() ? "true" : "false"); printf("\tFlags(): %" B_PRIx32 "\n\n", partition->Flags()); printf("\tName(): %s\n", partition->Name()); - printf("\tContentName(): %s\n", partition->ContentName()); + printf("\tContentName(): %s\n", partition->ContentName().String()); printf("\tType(): %s\n", partition->Type()); printf("\tContentType(): %s\n", partition->ContentType()); printf("\tID(): %" B_PRIx32 "\n\n", partition->ID()); diff --git a/src/apps/installer/WorkerThread.cpp b/src/apps/installer/WorkerThread.cpp index 0dce8c9984..d7a7c9038d 100644 --- a/src/apps/installer/WorkerThread.cpp +++ b/src/apps/installer/WorkerThread.cpp @@ -806,14 +806,14 @@ make_partition_label(BPartition* partition, char* label, char* menuLabel, if (type == NULL) type = B_TRANSLATE_COMMENT("Unknown Type", "Partition content type"); - sprintf(label, "%s - %s [%s] (%s)", partition->ContentName(), size, + sprintf(label, "%s - %s [%s] (%s)", partition->ContentName().String(), size, path.Path(), type); } else { - sprintf(label, "%s - %s [%s]", partition->ContentName(), size, + sprintf(label, "%s - %s [%s]", partition->ContentName().String(), size, path.Path()); } - sprintf(menuLabel, "%s - %s", partition->ContentName(), size); + sprintf(menuLabel, "%s - %s", partition->ContentName().String(), size); } diff --git a/src/kits/storage/disk_device/MutablePartition.cpp b/src/kits/storage/disk_device/MutablePartition.cpp index bb406d282c..3c2325cfe5 100644 --- a/src/kits/storage/disk_device/MutablePartition.cpp +++ b/src/kits/storage/disk_device/MutablePartition.cpp @@ -215,9 +215,28 @@ BMutablePartition::SetName(const char* name) // ContentName -const char* +BString BMutablePartition::ContentName() const { + if (fData->content_name == NULL) { + // Give a default name to unnamed volumes + off_t divisor = 1ULL << 40; + off_t diskSize = fData->content_size; + char unit = 'T'; + if (diskSize < divisor) { + divisor = 1UL << 30; + unit = 'G'; + if (diskSize < divisor) { + divisor = 1UL << 20; + unit = 'M'; + } + } + double size = double((10 * diskSize + divisor - 1) / divisor); + BString name; + name.SetToFormat("%g %ciB %s volume", size / 10, unit, fData->content_type); + return name; + } + return fData->content_name; } diff --git a/src/kits/storage/disk_device/Partition.cpp b/src/kits/storage/disk_device/Partition.cpp index 935c2fd8da..a7158dba7a 100644 --- a/src/kits/storage/disk_device/Partition.cpp +++ b/src/kits/storage/disk_device/Partition.cpp @@ -248,9 +248,28 @@ BPartition::Name() const } -const char* +BString BPartition::ContentName() const { + if (_PartitionData()->content_name == NULL) { + // Give a default name to unnamed volumes + off_t divisor = 1ULL << 40; + off_t diskSize = _PartitionData()->content_size; + char unit = 'T'; + if (diskSize < divisor) { + divisor = 1UL << 30; + unit = 'G'; + if (diskSize < divisor) { + divisor = 1UL << 20; + unit = 'M'; + } + } + double size = double((10 * diskSize + divisor - 1) / divisor); + BString name; + name.SetToFormat("%g %ciB %s volume", size / 10, unit, _PartitionData()->content_type); + return name; + } + return _PartitionData()->content_name; } diff --git a/src/servers/mount/AutoMounter.cpp b/src/servers/mount/AutoMounter.cpp index e5605d862d..a9d9a9de82 100644 --- a/src/servers/mount/AutoMounter.cpp +++ b/src/servers/mount/AutoMounter.cpp @@ -984,14 +984,8 @@ AutoMounter::_SuggestMountFlags(const BPartition* partition, uint32* _flags) if (askReadOnly) { // Suggest to the user to mount read-only until Haiku is more mature. BString string; - if (partition->ContentName() != NULL) { - char buffer[512]; - snprintf(buffer, sizeof(buffer), - B_TRANSLATE("Mounting volume '%s'\n\n"), - partition->ContentName()); - string << buffer; - } else - string << B_TRANSLATE("Mounting volume \n\n"); + string.SetToFormat(B_TRANSLATE("Mounting volume '%s'\n\n"), + partition->ContentName().String()); // TODO: Use distro name instead of "Haiku"... string << B_TRANSLATE("The file system on this volume is not the "