From 28e979171a910b478a8b7cce9fd4a27c1f9b8ff4 Mon Sep 17 00:00:00 2001 From: ru Date: Sat, 21 Oct 2006 23:57:38 +0000 Subject: - Document the default disk block usage unit. - Add option -h, human-readable output. PR: docs/53732 --- usr.bin/quota/Makefile | 4 ++-- usr.bin/quota/quota.1 | 12 ++++++++---- usr.bin/quota/quota.c | 53 ++++++++++++++++++++++++++++++++++++-------------- 3 files changed, 48 insertions(+), 21 deletions(-) (limited to 'usr.bin/quota') diff --git a/usr.bin/quota/Makefile b/usr.bin/quota/Makefile index 666a3ba..a479402 100644 --- a/usr.bin/quota/Makefile +++ b/usr.bin/quota/Makefile @@ -4,7 +4,7 @@ PROG= quota BINOWN= root -DPADD= ${LIBRPCSVC} -LDADD= -lrpcsvc +DPADD= ${LIBRPCSVC} ${LIBUTIL} +LDADD= -lrpcsvc -lutil .include diff --git a/usr.bin/quota/quota.1 b/usr.bin/quota/quota.1 index cf16941..9150198 100644 --- a/usr.bin/quota/quota.1 +++ b/usr.bin/quota/quota.1 @@ -35,7 +35,7 @@ .\" from: @(#)quota.1 8.1 (Berkeley) 6/6/93 .\" $FreeBSD$ .\" -.Dd August 8, 2002 +.Dd October 22, 2006 .Dt QUOTA 1 .Os .Sh NAME @@ -43,15 +43,15 @@ .Nd display disk usage and limits .Sh SYNOPSIS .Nm -.Op Fl glu +.Op Fl ghlu .Op Fl v | Fl q .Nm -.Op Fl lu +.Op Fl hlu .Op Fl v | Fl q .Ar user ... .Nm .Fl g -.Op Fl l +.Op Fl hl .Op Fl v | Fl q .Ar group ... .Sh DESCRIPTION @@ -59,12 +59,16 @@ The .Nm utility displays users' disk usage and limits. By default only the user quotas are printed. +Disk block usage and limits are shown in 1024-byte blocks. .Pp The following options are available: .Bl -tag -width indent .It Fl g Print group quotas for the group of which the user is a member. +.It Fl h +"Human-readable" output. +Use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte. .It Fl l Do not report quotas on .Tn NFS diff --git a/usr.bin/quota/quota.c b/usr.bin/quota/quota.c index 2b0dd49..0aa6b5f 100644 --- a/usr.bin/quota/quota.c +++ b/usr.bin/quota/quota.c @@ -67,6 +67,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -102,6 +103,7 @@ static int callaurpc(char *host, int prognum, int versnum, int procnum, xdrproc_t inproc, char *in, xdrproc_t outproc, char *out); static int alldigits(char *s); +int hflag; int lflag; int qflag; int vflag; @@ -113,11 +115,14 @@ main(int argc, char *argv[]) gid_t mygid, gidset[NGROUPS]; int i, ch, gflag = 0, uflag = 0; - while ((ch = getopt(argc, argv, "glquv")) != -1) { + while ((ch = getopt(argc, argv, "ghlquv")) != -1) { switch(ch) { case 'g': gflag++; break; + case 'h': + hflag++; + break; case 'l': lflag++; break; @@ -180,9 +185,9 @@ usage(void) { fprintf(stderr, "%s\n%s\n%s\n", - "usage: quota [-glu] [-v | -q]", - " quota [-lu] [-v | -q] user ...", - " quota -g [-l] [-v | -q] group ..."); + "usage: quota [-ghlu] [-v | -q]", + " quota [-hlu] [-v | -q] user ...", + " quota -g [-hl] [-v | -q] group ..."); exit(1); } @@ -249,6 +254,17 @@ showgrpname(char *name) } static void +prthumanval(int len, int64_t bytes) +{ + char buf[len + 1]; + + humanize_number(buf, sizeof(buf), bytes, "", HN_AUTOSCALE, + HN_B | HN_NOSPACE | HN_DECIMAL); + + (void)printf(" %*s", len, buf); +} + +static void showquotas(int type, u_long id, const char *name) { struct quotause *qup; @@ -310,18 +326,25 @@ showquotas(int type, u_long id, const char *name) printf("%s\n", qup->fsname); nam = ""; } - printf("%15s%8lu%c%7lu%8lu%8s" - , nam - , (u_long) (dbtob(qup->dqblk.dqb_curblocks) - / 1024) - , (msgb == (char *)0) ? ' ' : '*' - , (u_long) (dbtob(qup->dqblk.dqb_bsoftlimit) - / 1024) - , (u_long) (dbtob(qup->dqblk.dqb_bhardlimit) - / 1024) + printf("%15s", nam); + if (hflag) { + prthumanval(7, dbtob(qup->dqblk.dqb_curblocks)); + printf("%c", (msgb == (char *)0) ? ' ' : '*'); + prthumanval(6, dbtob(qup->dqblk.dqb_bsoftlimit)); + prthumanval(7, dbtob(qup->dqblk.dqb_bhardlimit)); + } else { + printf("%8lu%c%7lu%8lu" + , (u_long) (dbtob(qup->dqblk.dqb_curblocks) + / 1024) + , (msgb == (char *)0) ? ' ' : '*' + , (u_long) (dbtob(qup->dqblk.dqb_bsoftlimit) + / 1024) + , (u_long) (dbtob(qup->dqblk.dqb_bhardlimit) + / 1024)); + } + printf("%8s%8lu%c%7lu%8lu%8s\n" , (msgb == (char *)0) ? "" - :timeprt(qup->dqblk.dqb_btime)); - printf("%8lu%c%7lu%8lu%8s\n" + :timeprt(qup->dqblk.dqb_btime) , (u_long)qup->dqblk.dqb_curinodes , (msgi == (char *)0) ? ' ' : '*' , (u_long)qup->dqblk.dqb_isoftlimit -- cgit v1.1