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 <[email protected]> Reviewed-by: Jessica Hamilton <[email protected]> Reviewed-by: John Scipione <[email protected]>
This commit is contained in:
committed by
Jessica Hamilton
parent
d39a334eec
commit
d9e730c808
@@ -109,10 +109,8 @@ Volume::HasExtendedAttributes() const
|
|||||||
const char*
|
const char*
|
||||||
Volume::Name() const
|
Volume::Name() const
|
||||||
{
|
{
|
||||||
if (fSuperBlock.name[0])
|
// The name may be empty, in that case, userspace will generate one.
|
||||||
return fSuperBlock.name;
|
return fSuperBlock.name;
|
||||||
|
|
||||||
return fName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -333,26 +331,6 @@ Volume::Mount(const char* deviceName, uint32 flags)
|
|||||||
// all went fine
|
// all went fine
|
||||||
opener.Keep();
|
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;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -166,7 +166,6 @@ private:
|
|||||||
fs_volume* fFSVolume;
|
fs_volume* fFSVolume;
|
||||||
int fDevice;
|
int fDevice;
|
||||||
ext2_super_block fSuperBlock;
|
ext2_super_block fSuperBlock;
|
||||||
char fName[32];
|
|
||||||
|
|
||||||
BlockAllocator* fBlockAllocator;
|
BlockAllocator* fBlockAllocator;
|
||||||
InodeAllocator fInodeAllocator;
|
InodeAllocator fInodeAllocator;
|
||||||
|
|||||||
@@ -710,7 +710,7 @@ dosfs_identify_partition(int fd, partition_data *partition, void **_cookie)
|
|||||||
if (buf[0x15] != 0xf0 && buf[0x15] < 0xf8)
|
if (buf[0x15] != 0xf0 && buf[0x15] < 0xf8)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
strcpy(name, "no name");
|
name[0] = 0;
|
||||||
sectors_per_fat = read16(buf, 0x16);
|
sectors_per_fat = read16(buf, 0x16);
|
||||||
if (sectors_per_fat == 0) {
|
if (sectors_per_fat == 0) {
|
||||||
total_sectors = read32(buf, 0x20);
|
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)
|
if (vol->vol_entry > -2)
|
||||||
strlcpy(fss->volume_name, vol->vol_label, sizeof(fss->volume_name));
|
strlcpy(fss->volume_name, vol->vol_label, sizeof(fss->volume_name));
|
||||||
else
|
else {
|
||||||
strcpy(fss->volume_name, "no name");
|
// No name defined, let userspace decide of one
|
||||||
|
fss->volume_name[0] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
sanitize_name(fss->volume_name, 12);
|
sanitize_name(fss->volume_name, 12);
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ local posixSources = [ FDirName $(librootSources) posix ] ;
|
|||||||
local sources =
|
local sources =
|
||||||
driver_settings.cpp
|
driver_settings.cpp
|
||||||
find_directory.cpp
|
find_directory.cpp
|
||||||
fs_info.c
|
fs_info.cpp
|
||||||
system_revision.c
|
system_revision.c
|
||||||
wait_for_objects.cpp
|
wait_for_objects.cpp
|
||||||
;
|
;
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ for architectureObject in [ MultiArchSubDirSetup ] {
|
|||||||
find_paths.cpp
|
find_paths.cpp
|
||||||
fs_attr.cpp
|
fs_attr.cpp
|
||||||
fs_index.c
|
fs_index.c
|
||||||
fs_info.c
|
fs_info.cpp
|
||||||
fs_query.cpp
|
fs_query.cpp
|
||||||
fs_volume.c
|
fs_volume.c
|
||||||
image.cpp
|
image.cpp
|
||||||
|
|||||||
@@ -6,9 +6,10 @@
|
|||||||
|
|
||||||
#include <fs_info.h>
|
#include <fs_info.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <errno_private.h>
|
#include <errno_private.h>
|
||||||
#include <syscalls.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);
|
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);
|
RETURN_AND_SET_ERRNO(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user