Fix quota(1) output.

- Fix calculation of 1024-byte sized blocks from disk blocks shown when -h
option isn't specified. It was broken with quota64 integration.
- In prthumanval(): limit the size of a buffer passed to humanize_number()
to a width of 5 bytes but allow a shorter length if requested. That's what
users expect.

PR:		bin/150151
Reviewed by:	Kirk McKusick
This commit is contained in:
Sergey Kandaurov 2011-06-30 09:20:26 +00:00
parent 85e9da38fe
commit 2f39985f00
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=223690

View File

@ -264,8 +264,11 @@ prthumanval(int len, u_int64_t bytes)
{ {
char buf[len + 1]; char buf[len + 1];
humanize_number(buf, sizeof(buf), bytes, "", HN_AUTOSCALE, /*
HN_B | HN_NOSPACE | HN_DECIMAL); * Limit the width to 5 bytes as that is what users expect.
*/
humanize_number(buf, sizeof(buf) < 5 ? sizeof(buf) : 5, bytes, "",
HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
(void)printf(" %*s", len, buf); (void)printf(" %*s", len, buf);
} }
@ -352,10 +355,13 @@ showquotas(int type, u_long id, const char *name)
prthumanval(7, dbtob(qup->dqblk.dqb_bhardlimit)); prthumanval(7, dbtob(qup->dqblk.dqb_bhardlimit));
} else { } else {
printf(" %7ju%c %7ju %7ju", printf(" %7ju%c %7ju %7ju",
dbtob(1024) * (uintmax_t)qup->dqblk.dqb_curblocks, (uintmax_t)dbtob(qup->dqblk.dqb_curblocks)
/ 1024,
(msgb == NULL) ? ' ' : '*', (msgb == NULL) ? ' ' : '*',
dbtob(1024) * (uintmax_t)qup->dqblk.dqb_bsoftlimit, (uintmax_t)dbtob(qup->dqblk.dqb_bsoftlimit)
dbtob(1024) * (uintmax_t)qup->dqblk.dqb_bhardlimit); / 1024,
(uintmax_t)dbtob(qup->dqblk.dqb_bhardlimit)
/ 1024);
} }
if (msgb != NULL) if (msgb != NULL)
bgrace = timeprt(qup->dqblk.dqb_btime); bgrace = timeprt(qup->dqblk.dqb_btime);