- Document the default disk block usage unit.

- Add option -h, human-readable output.

PR:		docs/53732
This commit is contained in:
ru 2006-10-21 23:57:38 +00:00
parent 83009d5ef8
commit 28e979171a
3 changed files with 48 additions and 21 deletions

View File

@ -4,7 +4,7 @@
PROG= quota
BINOWN= root
DPADD= ${LIBRPCSVC}
LDADD= -lrpcsvc
DPADD= ${LIBRPCSVC} ${LIBUTIL}
LDADD= -lrpcsvc -lutil
.include <bsd.prog.mk>

View File

@ -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

View File

@ -67,6 +67,7 @@ __FBSDID("$FreeBSD$");
#include <err.h>
#include <fstab.h>
#include <grp.h>
#include <libutil.h>
#include <netdb.h>
#include <pwd.h>
#include <stdio.h>
@ -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);
}
@ -248,6 +253,17 @@ showgrpname(char *name)
showquotas(GRPQUOTA, grp->gr_gid, 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)
{
@ -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