Made the output of the volume listing more useful: added size, and device information.
size_string() was taken from df. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21573 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+54
-10
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2005-2006, Ingo Weinhold, [email protected]. All rights reserved.
|
* Copyright 2005-2007, Ingo Weinhold, [email protected]. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -83,7 +83,33 @@ print_usage_and_exit(bool error)
|
|||||||
exit(error ? 0 : 1);
|
exit(error ? 0 : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// MountVisitor
|
static const char *
|
||||||
|
size_string(int64 size)
|
||||||
|
{
|
||||||
|
double blocks = size;
|
||||||
|
static char string[64];
|
||||||
|
|
||||||
|
if (size < 1024)
|
||||||
|
sprintf(string, "%Ld", size);
|
||||||
|
else {
|
||||||
|
char *units[] = {"K", "M", "G", NULL};
|
||||||
|
int32 i = -1;
|
||||||
|
|
||||||
|
do {
|
||||||
|
blocks /= 1024.0;
|
||||||
|
i++;
|
||||||
|
} while (blocks >= 1024 && units[i + 1]);
|
||||||
|
|
||||||
|
snprintf(string, sizeof(string), "%.1f%s", blocks, units[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
struct MountVisitor : public BDiskDeviceVisitor {
|
struct MountVisitor : public BDiskDeviceVisitor {
|
||||||
MountVisitor()
|
MountVisitor()
|
||||||
: silent(false),
|
: silent(false),
|
||||||
@@ -219,12 +245,28 @@ struct PrintPartitionsVisitor : public BDiskDeviceVisitor {
|
|||||||
if (type == NULL)
|
if (type == NULL)
|
||||||
type = "<unknown>";
|
type = "<unknown>";
|
||||||
|
|
||||||
BPath path;
|
// shorten known types for display
|
||||||
if (partition->IsMounted())
|
if (!strcmp(type, kPartitionTypeMultisession))
|
||||||
partition->GetMountPoint(&path);
|
type = "Multisession";
|
||||||
|
else if (!strcmp(type, kPartitionTypeIntelExtended))
|
||||||
|
type = "Intel Extended";
|
||||||
|
|
||||||
printf("%-16s %-20s %s\n",
|
BPath path;
|
||||||
name, type, partition->IsMounted() ? path.Path() : "");
|
partition->GetPath(&path);
|
||||||
|
|
||||||
|
// cut off beginning of the device path (if /dev/disk/)
|
||||||
|
int32 skip = strlen("/dev/disk/");
|
||||||
|
if (strncmp(path.Path(), "/dev/disk/", skip))
|
||||||
|
skip = 0;
|
||||||
|
|
||||||
|
BPath mountPoint;
|
||||||
|
if (partition->IsMounted())
|
||||||
|
partition->GetMountPoint(&mountPoint);
|
||||||
|
|
||||||
|
printf("%-14s %-20s %8s %s (%s)\n",
|
||||||
|
name, type, size_string(partition->Size()),
|
||||||
|
partition->IsMounted() ? mountPoint.Path() : "",
|
||||||
|
path.Path() + skip);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,7 +275,9 @@ struct PrintPartitionsVisitor : public BDiskDeviceVisitor {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// main
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
@@ -328,8 +372,8 @@ main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (printPartitionsVisitor.IsUsed()) {
|
if (printPartitionsVisitor.IsUsed()) {
|
||||||
puts("Volume File System Mounted At");
|
puts("Volume File System Size Mounted At (Device)");
|
||||||
puts("----------------------------------------------------------");
|
puts("---------------------------------------------------------------------");
|
||||||
|
|
||||||
if (printPartitionsVisitor.listAllPartitions)
|
if (printPartitionsVisitor.listAllPartitions)
|
||||||
deviceList.VisitEachPartition(&printPartitionsVisitor);
|
deviceList.VisitEachPartition(&printPartitionsVisitor);
|
||||||
|
|||||||
Reference in New Issue
Block a user