libroot: generate a name for nameless volumes
Generate a name indicating the volume size and filesystem. Remove code that was doing that or similar things in various filesystems. Change-Id: I6b993735e58cdfaf1f19af575e918614c7fe5679 Reviewed-on: https://review.haiku-os.org/c/haiku/+/5381 Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org> Reviewed-by: Jessica Hamilton <jessica.l.hamilton@gmail.com> Reviewed-by: John Scipione <jscipione@gmail.com>
This commit is contained in:
parent
d39a334eec
commit
d9e730c808
@ -109,10 +109,8 @@ Volume::HasExtendedAttributes() const
|
||||
const char*
|
||||
Volume::Name() const
|
||||
{
|
||||
if (fSuperBlock.name[0])
|
||||
return fSuperBlock.name;
|
||||
|
||||
return fName;
|
||||
// The name may be empty, in that case, userspace will generate one.
|
||||
return fSuperBlock.name;
|
||||
}
|
||||
|
||||
|
||||
@ -333,26 +331,6 @@ Volume::Mount(const char* deviceName, uint32 flags)
|
||||
// all went fine
|
||||
opener.Keep();
|
||||
|
||||
if (!fSuperBlock.name[0]) {
|
||||
// generate a more or less descriptive volume name
|
||||
off_t divisor = 1ULL << 40;
|
||||
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);
|
||||
// %g in the kernel does not support precision...
|
||||
|
||||
snprintf(fName, sizeof(fName), "%g %cB Ext2 Volume",
|
||||
size / 10, unit);
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
@ -166,7 +166,6 @@ private:
|
||||
fs_volume* fFSVolume;
|
||||
int fDevice;
|
||||
ext2_super_block fSuperBlock;
|
||||
char fName[32];
|
||||
|
||||
BlockAllocator* fBlockAllocator;
|
||||
InodeAllocator fInodeAllocator;
|
||||
|
@ -710,7 +710,7 @@ dosfs_identify_partition(int fd, partition_data *partition, void **_cookie)
|
||||
if (buf[0x15] != 0xf0 && buf[0x15] < 0xf8)
|
||||
return -1;
|
||||
|
||||
strcpy(name, "no name");
|
||||
name[0] = 0;
|
||||
sectors_per_fat = read16(buf, 0x16);
|
||||
if (sectors_per_fat == 0) {
|
||||
total_sectors = read32(buf, 0x20);
|
||||
@ -995,8 +995,10 @@ dosfs_read_fs_stat(fs_volume *_vol, struct fs_info * fss)
|
||||
|
||||
if (vol->vol_entry > -2)
|
||||
strlcpy(fss->volume_name, vol->vol_label, sizeof(fss->volume_name));
|
||||
else
|
||||
strcpy(fss->volume_name, "no name");
|
||||
else {
|
||||
// No name defined, let userspace decide of one
|
||||
fss->volume_name[0] = 0;
|
||||
}
|
||||
|
||||
sanitize_name(fss->volume_name, 12);
|
||||
|
||||
|
@ -21,7 +21,7 @@ local posixSources = [ FDirName $(librootSources) posix ] ;
|
||||
local sources =
|
||||
driver_settings.cpp
|
||||
find_directory.cpp
|
||||
fs_info.c
|
||||
fs_info.cpp
|
||||
system_revision.c
|
||||
wait_for_objects.cpp
|
||||
;
|
||||
|
@ -24,7 +24,7 @@ for architectureObject in [ MultiArchSubDirSetup ] {
|
||||
find_paths.cpp
|
||||
fs_attr.cpp
|
||||
fs_index.c
|
||||
fs_info.c
|
||||
fs_info.cpp
|
||||
fs_query.cpp
|
||||
fs_volume.c
|
||||
image.cpp
|
||||
|
@ -6,9 +6,10 @@
|
||||
|
||||
#include <fs_info.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <errno_private.h>
|
||||
#include <syscalls.h>
|
||||
@ -40,6 +41,28 @@ fs_stat_dev(dev_t device, fs_info *info)
|
||||
{
|
||||
status_t status = _kern_read_fs_info(device, info);
|
||||
|
||||
if (info != NULL) {
|
||||
if (info->volume_name[0] == 0) {
|
||||
// Give a default name to unnamed volumes
|
||||
off_t divisor = 1ULL << 40;
|
||||
off_t diskSize = info->total_blocks * info->block_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);
|
||||
|
||||
sprintf(info->volume_name, "%g %ciB %s volume", size / 10, unit, info->fsh_name);
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_AND_SET_ERRNO(status);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user