Disk Device Manager: generate a name for nameless volumes

This will give the same result as fs_stat_dev, so the filesystems will
have the same name everywhere.

Change-Id: Ic684142efaeb2c16b393f3f3e5c9c3010a054b30
Reviewed-on: https://review.haiku-os.org/c/haiku/+/5636
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>
This commit is contained in:
PulkoMandy 2022-09-10 11:51:35 +02:00 committed by Jérôme Duval
parent 74a5cb7bbc
commit e3d5904751
7 changed files with 48 additions and 16 deletions

View File

@ -43,7 +43,7 @@ public:
const char* Name() const; const char* Name() const;
status_t SetName(const char* name); status_t SetName(const char* name);
const char* ContentName() const; BString ContentName() const;
status_t SetContentName(const char* name); status_t SetContentName(const char* name);
const char* Type() const; const char* Type() const;

View File

@ -52,7 +52,7 @@ public:
uint32 Flags() const; uint32 Flags() const;
const char* Name() const; const char* Name() const;
const char* ContentName() const; BString ContentName() const;
const char* Type() const; // See DiskDeviceTypes.h const char* Type() const; // See DiskDeviceTypes.h
const char* ContentType() const; // See DiskDeviceTypes.h const char* ContentType() const; // See DiskDeviceTypes.h
partition_id ID() const; partition_id ID() const;

View File

@ -51,7 +51,7 @@ dump_partition_info(const BPartition* partition)
printf("\tIsBusy(): %s\n\n", partition->IsBusy() ? "true" : "false"); printf("\tIsBusy(): %s\n\n", partition->IsBusy() ? "true" : "false");
printf("\tFlags(): %" B_PRIx32 "\n\n", partition->Flags()); printf("\tFlags(): %" B_PRIx32 "\n\n", partition->Flags());
printf("\tName(): %s\n", partition->Name()); 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("\tType(): %s\n", partition->Type());
printf("\tContentType(): %s\n", partition->ContentType()); printf("\tContentType(): %s\n", partition->ContentType());
printf("\tID(): %" B_PRIx32 "\n\n", partition->ID()); printf("\tID(): %" B_PRIx32 "\n\n", partition->ID());

View File

@ -806,14 +806,14 @@ make_partition_label(BPartition* partition, char* label, char* menuLabel,
if (type == NULL) if (type == NULL)
type = B_TRANSLATE_COMMENT("Unknown Type", "Partition content type"); 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); path.Path(), type);
} else { } else {
sprintf(label, "%s - %s [%s]", partition->ContentName(), size, sprintf(label, "%s - %s [%s]", partition->ContentName().String(), size,
path.Path()); path.Path());
} }
sprintf(menuLabel, "%s - %s", partition->ContentName(), size); sprintf(menuLabel, "%s - %s", partition->ContentName().String(), size);
} }

View File

@ -215,9 +215,28 @@ BMutablePartition::SetName(const char* name)
// ContentName // ContentName
const char* BString
BMutablePartition::ContentName() const 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; return fData->content_name;
} }

View File

@ -248,9 +248,28 @@ BPartition::Name() const
} }
const char* BString
BPartition::ContentName() const 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; return _PartitionData()->content_name;
} }

View File

@ -984,14 +984,8 @@ AutoMounter::_SuggestMountFlags(const BPartition* partition, uint32* _flags)
if (askReadOnly) { if (askReadOnly) {
// Suggest to the user to mount read-only until Haiku is more mature. // Suggest to the user to mount read-only until Haiku is more mature.
BString string; BString string;
if (partition->ContentName() != NULL) { string.SetToFormat(B_TRANSLATE("Mounting volume '%s'\n\n"),
char buffer[512]; partition->ContentName().String());
snprintf(buffer, sizeof(buffer),
B_TRANSLATE("Mounting volume '%s'\n\n"),
partition->ContentName());
string << buffer;
} else
string << B_TRANSLATE("Mounting volume <unnamed volume>\n\n");
// TODO: Use distro name instead of "Haiku"... // TODO: Use distro name instead of "Haiku"...
string << B_TRANSLATE("The file system on this volume is not the " string << B_TRANSLATE("The file system on this volume is not the "