summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2008-02-28 17:49:23 +0000
committerjhb <jhb@FreeBSD.org>2008-02-28 17:49:23 +0000
commitca134b8a3438ba8668c0915a727f8d0418d74e9e (patch)
tree1908f4d66aa1bb51923d5b71c511625e0bac84c3
parent0247edab67050d66c379a8c0d5ef1c5b932fcad8 (diff)
downloadFreeBSD-src-ca134b8a3438ba8668c0915a727f8d0418d74e9e.zip
FreeBSD-src-ca134b8a3438ba8668c0915a727f8d0418d74e9e.tar.gz
Tweak the verbose disk printing a bit:
- Consolidate the code to humanize the size of a disk partition into a single function based on the code for GPT partitions and use it for GPT partitions, BSD slices, and BSD partitions. - Teach the humanize code to use KB for small partitions (e.g. GPT boot partitions now show up as 64KB rather than 0MB). - Pad a few partition type names out so that things line up in the common case. MFC after: 1 week
-rw-r--r--sys/boot/i386/libi386/biosdisk.c110
1 files changed, 51 insertions, 59 deletions
diff --git a/sys/boot/i386/libi386/biosdisk.c b/sys/boot/i386/libi386/biosdisk.c
index c673e10..333857b 100644
--- a/sys/boot/i386/libi386/biosdisk.c
+++ b/sys/boot/i386/libi386/biosdisk.c
@@ -316,6 +316,29 @@ bd_print(int verbose)
}
}
+/* Given a size in 512 byte sectors, convert it to a human-readable number. */
+static char *
+display_size(uint64_t size)
+{
+ static char buf[80];
+ char unit;
+
+ size /= 2;
+ unit = 'K';
+ if (size >= 10485760000LL) {
+ size /= 1073741824;
+ unit = 'T';
+ } else if (size >= 10240000) {
+ size /= 1048576;
+ unit = 'G';
+ } else if (size >= 10000) {
+ size /= 1024;
+ unit = 'M';
+ }
+ sprintf(buf, "%.6ld%cB", (long)size, unit);
+ return (buf);
+}
+
static uuid_t efi = GPT_ENT_TYPE_EFI;
static uuid_t freebsd_boot = GPT_ENT_TYPE_FREEBSD_BOOT;
static uuid_t freebsd_ufs = GPT_ENT_TYPE_FREEBSD_UFS;
@@ -329,33 +352,22 @@ bd_printgptpart(struct open_disk *od, struct gpt_part *gp, char *prefix,
{
char stats[80];
char line[96];
- uint64_t size;
- char unit;
- if (verbose) {
- size = (gp->gp_end + 1 - gp->gp_start) / 2048;
- unit = 'M';
- if (size >= 10240000) {
- size /= 1048576;
- unit = 'T';
- } else if (size >= 10000) {
- size /= 1024;
- unit = 'G';
- }
- sprintf(stats, " %.6ld%cB", (long)size, unit);
- } else
+ if (verbose)
+ sprintf(stats, " %s", display_size(gp->gp_end + 1 - gp->gp_start));
+ else
stats[0] = '\0';
if (uuid_equal(&gp->gp_type, &efi, NULL))
- sprintf(line, "%s: EFI%s\n", prefix, stats);
+ sprintf(line, "%s: EFI %s\n", prefix, stats);
else if (uuid_equal(&gp->gp_type, &ms_basic_data, NULL))
- sprintf(line, "%s: FAT/NTFS%s\n", prefix, stats);
+ sprintf(line, "%s: FAT/NTFS %s\n", prefix, stats);
else if (uuid_equal(&gp->gp_type, &freebsd_boot, NULL))
sprintf(line, "%s: FreeBSD boot%s\n", prefix, stats);
else if (uuid_equal(&gp->gp_type, &freebsd_ufs, NULL))
- sprintf(line, "%s: FreeBSD UFS%s\n", prefix, stats);
+ sprintf(line, "%s: FreeBSD UFS %s\n", prefix, stats);
else if (uuid_equal(&gp->gp_type, &freebsd_zfs, NULL))
- sprintf(line, "%s: FreeBSD ZFS%s\n", prefix, stats);
+ sprintf(line, "%s: FreeBSD ZFS %s\n", prefix, stats);
else if (uuid_equal(&gp->gp_type, &freebsd_swap, NULL))
sprintf(line, "%s: FreeBSD swap%s\n", prefix, stats);
else
@@ -377,70 +389,50 @@ static void
bd_printslice(struct open_disk *od, struct dos_partition *dp, char *prefix,
int verbose)
{
+ char stats[80];
char line[80];
+ if (verbose)
+ sprintf(stats, " %s (%d - %d)", display_size(dp->dp_size),
+ dp->dp_start, dp->dp_start + dp->dp_size);
+ else
+ stats[0] = '\0';
+
switch (dp->dp_typ) {
case DOSPTYP_386BSD:
bd_printbsdslice(od, (daddr_t)dp->dp_start, prefix, verbose);
return;
case DOSPTYP_LINSWP:
- if (verbose)
- sprintf(line, "%s: Linux swap %.6dMB (%d - %d)\n",
- prefix, dp->dp_size / 2048,
- dp->dp_start, dp->dp_start + dp->dp_size);
- else
- sprintf(line, "%s: Linux swap\n", prefix);
+ sprintf(line, "%s: Linux swap%s\n", prefix, stats);
break;
case DOSPTYP_LINUX:
/*
* XXX
* read the superblock to confirm this is an ext2fs partition?
*/
- if (verbose)
- sprintf(line, "%s: ext2fs %.6dMB (%d - %d)\n", prefix,
- dp->dp_size / 2048, dp->dp_start,
- dp->dp_start + dp->dp_size);
- else
- sprintf(line, "%s: ext2fs\n", prefix);
+ sprintf(line, "%s: ext2fs%s\n", prefix, stats);
break;
case 0x00: /* unused partition */
case DOSPTYP_EXT:
return;
case 0x01:
- if (verbose)
- sprintf(line, "%s: FAT-12 %.6dMB (%d - %d)\n", prefix,
- dp->dp_size / 2048, dp->dp_start,
- dp->dp_start + dp->dp_size);
- else
- sprintf(line, "%s: FAT-12\n", prefix);
+ sprintf(line, "%s: FAT-12%s\n", prefix, stats);
break;
case 0x04:
case 0x06:
case 0x0e:
- if (verbose)
- sprintf(line, "%s: FAT-16 %.6dMB (%d - %d)\n", prefix,
- dp->dp_size / 2048, dp->dp_start,
- dp->dp_start + dp->dp_size);
- else
- sprintf(line, "%s: FAT-16\n", prefix);
+ sprintf(line, "%s: FAT-16%s\n", prefix, stats);
+ break;
+ case 0x07:
+ sprintf(line, "%s: NTFS/HPFS%s\n", prefix, stats);
break;
case 0x0b:
case 0x0c:
- if (verbose)
- sprintf(line, "%s: FAT-32 %.6dMB (%d - %d)\n", prefix,
- dp->dp_size / 2048, dp->dp_start,
- dp->dp_start + dp->dp_size);
- else
- sprintf(line, "%s: FAT-32\n", prefix);
+ sprintf(line, "%s: FAT-32%s\n", prefix, stats);
break;
default:
- if (verbose)
- sprintf(line, "%s: Unknown fs: 0x%x %.6dMB (%d - %d)\n",
- prefix, dp->dp_typ, dp->dp_size / 2048,
- dp->dp_start, dp->dp_start + dp->dp_size);
- else
- sprintf(line, "%s: Unknown fs: 0x%x\n", prefix,
- dp->dp_typ);
+ sprintf(line, "%s: Unknown fs: 0x%x %s\n", prefix, dp->dp_typ,
+ stats);
}
pager_output(line);
}
@@ -484,11 +476,11 @@ bd_printbsdslice(struct open_disk *od, daddr_t offset, char *prefix,
/* Only print out statistics in verbose mode */
if (verbose)
- sprintf(line, " %s%c: %s %.6dMB (%d - %d)\n", prefix, 'a' + i,
- (lp->d_partitions[i].p_fstype == FS_SWAP) ? "swap" :
+ sprintf(line, " %s%c: %s %s (%d - %d)\n", prefix, 'a' + i,
+ (lp->d_partitions[i].p_fstype == FS_SWAP) ? "swap " :
(lp->d_partitions[i].p_fstype == FS_VINUM) ? "vinum" :
- "FFS",
- lp->d_partitions[i].p_size / 2048,
+ "FFS ",
+ display_size(lp->d_partitions[i].p_size),
lp->d_partitions[i].p_offset,
lp->d_partitions[i].p_offset + lp->d_partitions[i].p_size);
else
OpenPOWER on IntegriCloud