diff options
author | le <le@FreeBSD.org> | 2004-11-15 12:30:59 +0000 |
---|---|---|
committer | le <le@FreeBSD.org> | 2004-11-15 12:30:59 +0000 |
commit | c174c57d9d244a5eab7ccbb84ae730653d1ff5a1 (patch) | |
tree | 01ac4707cda830f537ca5674c94dc50c02a0b8ad /sys/geom/vinum/geom_vinum_share.c | |
parent | d8b3df3cb90ffaa3381db166cd1e1f43fa25aa69 (diff) | |
download | FreeBSD-src-c174c57d9d244a5eab7ccbb84ae730653d1ff5a1.zip FreeBSD-src-c174c57d9d244a5eab7ccbb84ae730653d1ff5a1.tar.gz |
Share gv_roughlength() between kernel and userland, as we will need it
there later.
Diffstat (limited to 'sys/geom/vinum/geom_vinum_share.c')
-rw-r--r-- | sys/geom/vinum/geom_vinum_share.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/sys/geom/vinum/geom_vinum_share.c b/sys/geom/vinum/geom_vinum_share.c index 2b572c3..1219f0e 100644 --- a/sys/geom/vinum/geom_vinum_share.c +++ b/sys/geom/vinum/geom_vinum_share.c @@ -650,3 +650,38 @@ gv_new_sd(int max, char *token[]) return (s); } + +/* + * Take a size in bytes and return a pointer to a string which represents the + * size best. If lj is != 0, return left justified, otherwise in a fixed 10 + * character field suitable for columnar printing. + * + * Note this uses a static string: it's only intended to be used immediately + * for printing. + */ +const char * +gv_roughlength(off_t bytes, int lj) +{ + static char desc[16]; + + /* Gigabytes. */ + if (bytes > (off_t)MEGABYTE * 10000) + snprintf(desc, sizeof(desc), lj ? "%jd GB" : "%10jd GB", + bytes / GIGABYTE); + + /* Megabytes. */ + else if (bytes > KILOBYTE * 10000) + snprintf(desc, sizeof(desc), lj ? "%jd MB" : "%10jd MB", + bytes / MEGABYTE); + + /* Kilobytes. */ + else if (bytes > 10000) + snprintf(desc, sizeof(desc), lj ? "%jd kB" : "%10jd kB", + bytes / KILOBYTE); + + /* Bytes. */ + else + snprintf(desc, sizeof(desc), lj ? "%jd B" : "%10jd B", bytes); + + return (desc); +} |