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:
parent
74a5cb7bbc
commit
e3d5904751
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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());
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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 <unnamed 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 "
|
||||
|
Loading…
Reference in New Issue
Block a user