* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
"@(#) Copyright (c) 1980 Regents of the University of California.\n\
static char sccsid
[] = "@(#)quota.c 5.4 (Berkeley) %G%";
* Disk quota reporting program.
if (quota(Q_SYNC
, 0, 0, (caddr_t
)0) < 0 && errno
== EINVAL
) {
fprintf(stderr
, "There are no quotas on this system\n");
for (cp
= &argv
[0][1]; *cp
; cp
++) switch (*cp
) {
fprintf(stderr
, "quota: %c: unknown option\n",
for (; argc
> 0; argc
--, argv
++) {
struct passwd
*pwd
= getpwuid(uid
);
showquotas(uid
, "(no account)");
showquotas(uid
, pwd
->pw_name
);
struct passwd
*pwd
= getpwnam(name
);
fprintf(stderr
, "quota: %s: unknown user\n", name
);
showquotas(pwd
->pw_uid
, name
);
register struct fstab
*fs
;
register char *msgi
, *msgb
;
char qfilename
[MAXPATHLEN
+ 1], iwarn
[8], dwarn
[8];
if (uid
!= myuid
&& myuid
!= 0) {
printf("quota: %s (uid %d): permission denied\n", name
, uid
);
while (fs
= getfsent()) {
if (stat(fs
->fs_spec
, &statb
) < 0)
msgi
= msgb
= (char *) 0;
(void) sprintf(qfilename
, "%s/%s", fs
->fs_file
, qfname
);
if (stat(qfilename
, &statb
) < 0 || statb
.st_dev
!= fsdev
)
if (quota(Q_GETDLIM
, uid
, fsdev
, (caddr_t
)&dqblk
) != 0) {
fd
= open(qfilename
, O_RDONLY
);
(void) lseek(fd
, (off_t
)(uid
* sizeof (dqblk
)), L_SET
);
switch (read(fd
, (char *)&dqblk
, sizeof dqblk
)) {
* Convert implicit 0 quota (EOF)
* into an explicit one (zero'ed dqblk).
bzero((caddr_t
)&dqblk
, sizeof dqblk
);
case sizeof dqblk
: /* OK */
fprintf(stderr
, "quota: read error in ");
if (!vflag
&& dqblk
.dqb_isoftlimit
== 0 &&
dqblk
.dqb_bsoftlimit
== 0)
if (dqblk
.dqb_ihardlimit
&&
dqblk
.dqb_curinodes
>= dqblk
.dqb_ihardlimit
)
msgi
= "File count limit reached on %s";
else if (enab
&& dqblk
.dqb_iwarn
== 0)
msgi
= "Out of inode warnings on %s";
else if (dqblk
.dqb_isoftlimit
&&
dqblk
.dqb_curinodes
>= dqblk
.dqb_isoftlimit
)
msgi
= "Too many files on %s";
if (dqblk
.dqb_bhardlimit
&&
dqblk
.dqb_curblocks
>= dqblk
.dqb_bhardlimit
)
msgb
= "Block limit reached on %s";
else if (enab
&& dqblk
.dqb_bwarn
== 0)
msgb
= "Out of block warnings on %s";
else if (dqblk
.dqb_bsoftlimit
&&
dqblk
.dqb_curblocks
>= dqblk
.dqb_bsoftlimit
)
msgb
= "Over disc quota on %s";
if (dqblk
.dqb_iwarn
< MAX_IQ_WARN
)
(void) sprintf(iwarn
, "%d", dqblk
.dqb_iwarn
);
if (dqblk
.dqb_bwarn
< MAX_DQ_WARN
)
(void) sprintf(dwarn
, "%d", dqblk
.dqb_bwarn
);
if (msgi
!= (char *)0 || msgb
!= (char *)0)
xprintf(msgi
, fs
->fs_file
);
xprintf(msgb
, fs
->fs_file
);
if (vflag
|| dqblk
.dqb_curblocks
|| dqblk
.dqb_curinodes
) {
printf("%10s%8d%c%7d%8d%8s%8d%c%7d%8d%8s\n"
, dbtob(dqblk
.dqb_curblocks
) / 1024
, (msgb
== (char *)0) ? ' ' : '*'
, dbtob(dqblk
.dqb_bsoftlimit
) / 1024
, dbtob(dqblk
.dqb_bhardlimit
) / 1024
, (msgi
== (char *)0) ? ' ' : '*'
xprintf("Disc quotas for %s (uid %d):", name
, uid
);
xprintf("User %s (uid %d):", name
, uid
);
xprintf("Disc quotas for %s (uid %d):", name
, uid
);
printf("%10s%8s %7s%8s%8s%8s %7s%8s%8s\n"
xprintf(fmt
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
)
if (fmt
== 0 && column
|| column
>= 40) {
(void) sprintf(buf
, fmt
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
if (column
!= 0 && strlen(buf
) < 39)