* Copyright (c) 1980, 1990 Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* Robert Elz at The University of Melbourne.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
"@(#) Copyright (c) 1980, 1990 Regents of the University of California.\n\
static char sccsid
[] = "@(#)quota.c 5.10 (Berkeley) %G%";
* Disk quota reporting program.
char fsname
[MAXPATHLEN
+ 1];
int ngroups
, gidset
[NGROUPS
];
int i
, gflag
= 0, uflag
= 0;
extern int optind
, errno
;
if (quotactl("/", 0, 0, (caddr_t
)0) < 0 && errno
== EOPNOTSUPP
) {
fprintf(stderr
, "There are no quotas on this system\n");
while ((ch
= getopt(argc
, argv
, "ugvq")) != EOF
) {
ngroups
= getgroups(NGROUPS
, gidset
);
perror("quota: getgroups");
for (i
= 1; i
< ngroups
; i
++)
for (; argc
> 0; argc
--, argv
++) {
for (; argc
> 0; argc
--, argv
++) {
fprintf(stderr
, "%s\n%s\n%s\n",
"\tquota [-qv] -u username ...",
"\tquota [-qv] -g groupname ...");
* Print out quotas for a specified user identifier.
struct passwd
*pwd
= getpwuid(uid
);
if (uid
!= myuid
&& myuid
!= 0) {
printf("quota: %s (uid %d): permission denied\n", name
, uid
);
showquotas(USRQUOTA
, uid
, name
);
* Print out quotas for a specifed user name.
struct passwd
*pwd
= getpwnam(name
);
fprintf(stderr
, "quota: %s: unknown user\n", name
);
if (pwd
->pw_uid
!= myuid
&& myuid
!= 0) {
fprintf(stderr
, "quota: %s (uid %d): permission denied\n",
showquotas(USRQUOTA
, pwd
->pw_uid
, name
);
* Print out quotas for a specified group identifier.
struct group
*grp
= getgrgid(gid
);
int ngroups
, gidset
[NGROUPS
];
ngroups
= getgroups(NGROUPS
, gidset
);
perror("quota: getgroups");
for (i
= 1; i
< ngroups
; i
++)
if (i
>= ngroups
&& getuid() != 0) {
fprintf(stderr
, "quota: %s (gid %d): permission denied\n",
showquotas(GRPQUOTA
, gid
, name
);
* Print out quotas for a specifed group name.
struct group
*grp
= getgrnam(name
);
int ngroups
, gidset
[NGROUPS
];
fprintf(stderr
, "quota: %s: unknown group\n", name
);
ngroups
= getgroups(NGROUPS
, gidset
);
perror("quota: getgroups");
for (i
= 1; i
< ngroups
; i
++)
if (grp
->gr_gid
== gidset
[i
])
if (i
>= ngroups
&& getuid() != 0) {
fprintf(stderr
, "quota: %s (gid %d): permission denied\n",
showquotas(GRPQUOTA
, grp
->gr_gid
, name
);
showquotas(type
, id
, name
)
register struct quotause
*qup
;
struct quotause
*quplist
, *getprivs();
char *msgi
, *msgb
, *timeprt();
int myuid
, fd
, lines
= 0;
quplist
= getprivs(id
, type
);
for (qup
= quplist
; qup
; qup
= qup
->next
) {
qup
->dqblk
.dqb_isoftlimit
== 0 &&
qup
->dqblk
.dqb_ihardlimit
== 0 &&
qup
->dqblk
.dqb_bsoftlimit
== 0 &&
qup
->dqblk
.dqb_bhardlimit
== 0)
if (qup
->dqblk
.dqb_ihardlimit
&&
qup
->dqblk
.dqb_curinodes
>= qup
->dqblk
.dqb_ihardlimit
)
msgi
= "File limit reached on";
else if (qup
->dqblk
.dqb_isoftlimit
&&
qup
->dqblk
.dqb_curinodes
>= qup
->dqblk
.dqb_isoftlimit
)
if (qup
->dqblk
.dqb_itime
> now
)
msgi
= "In file grace period on";
msgi
= "Over file quota on";
if (qup
->dqblk
.dqb_bhardlimit
&&
qup
->dqblk
.dqb_curblocks
>= qup
->dqblk
.dqb_bhardlimit
)
msgb
= "Block limit reached on";
else if (qup
->dqblk
.dqb_bsoftlimit
&&
qup
->dqblk
.dqb_curblocks
>= qup
->dqblk
.dqb_bsoftlimit
)
if (qup
->dqblk
.dqb_btime
> now
)
msgb
= "In block grace period on";
msgb
= "Over block quota on";
if ((msgi
!= (char *)0 || msgb
!= (char *)0) &&
heading(type
, id
, name
, "");
printf("\t%s %s\n", msgi
, qup
->fsname
);
printf("\t%s %s\n", msgb
, qup
->fsname
);
qup
->dqblk
.dqb_curblocks
||
qup
->dqblk
.dqb_curinodes
) {
heading(type
, id
, name
, "");
printf("%15s%8d%c%7d%8d%8s"
, dbtob(qup
->dqblk
.dqb_curblocks
) / 1024
, (msgb
== (char *)0) ? ' ' : '*'
, dbtob(qup
->dqblk
.dqb_bsoftlimit
) / 1024
, dbtob(qup
->dqblk
.dqb_bhardlimit
) / 1024
, (msgb
== (char *)0) ? ""
: timeprt(qup
->dqblk
.dqb_btime
));
printf("%8d%c%7d%8d%8s\n"
, qup
->dqblk
.dqb_curinodes
, (msgi
== (char *)0) ? ' ' : '*'
, qup
->dqblk
.dqb_isoftlimit
, qup
->dqblk
.dqb_ihardlimit
, (msgi
== (char *)0) ? ""
: timeprt(qup
->dqblk
.dqb_itime
)
if (!qflag
&& lines
== 0)
heading(type
, id
, name
, "none");
heading(type
, id
, name
, tag
)
printf("Disk quotas for %s %s (%cid %d): %s\n", qfextension
[type
],
name
, *qfextension
[type
], id
, tag
);
if (!qflag
&& tag
[0] == '\0') {
printf("%15s%8s %7s%8s%8s%8s %7s%8s%8s\n"
* Calculate the grace period and return a printable string for it.
minutes
= (seconds
+ 30) / 60;
hours
= (minutes
+ 30) / 60;
sprintf(buf
, "%ddays", (hours
+ 12) / 24);
sprintf(buf
, "%2d:%d", minutes
/ 60, minutes
% 60);
sprintf(buf
, "%2d", minutes
);
* Collect the requested quota information.
register struct fstab
*fs
;
char qfilename
[MAXPATHLEN
+ 1];
register struct quotause
*qup
, *quptail
;
struct quotause
*quphead
;
quphead
= (struct quotause
*)0;
qcmd
= QCMD(Q_GETQUOTA
, quotatype
);
while (fs
= getfsent()) {
if (!hasquota(fs
->fs_mntops
, quotatype
))
sprintf(qfilename
, "%s/%s.%s", fs
->fs_file
, qfname
,
if ((fd
= open(qfilename
, O_RDONLY
)) < 0) {
if ((qup
= (struct quotause
*)malloc(sizeof *qup
)) == NULL
) {
fprintf(stderr
, "quota: out of memory\n");
if (quotactl(qfilename
, qcmd
, id
, &qup
->dqblk
) != 0) {
lseek(fd
, (long)(id
* sizeof(struct dqblk
)), L_SET
);
switch (read(fd
, &qup
->dqblk
, sizeof(struct dqblk
))) {
* Convert implicit 0 quota (EOF)
* into an explicit one (zero'ed dqblk)
bzero((caddr_t
)&qup
->dqblk
,
case sizeof(struct dqblk
): /* OK */
fprintf(stderr
, "quota: read error");
strcpy(qup
->fsname
, fs
->fs_file
);
* Check to see if a particular quota is to be enabled.
static char initname
, usrname
[100], grpname
[100];
sprintf(usrname
, "%s%s", qfextension
[USRQUOTA
], qfname
);
sprintf(grpname
, "%s%s", qfextension
[GRPQUOTA
], qfname
);
for (opt
= strtok(buf
, ","); opt
; opt
= strtok(NULL
, ",")) {
if (type
== USRQUOTA
&& strcmp(opt
, usrname
) == 0)
if (type
== GRPQUOTA
&& strcmp(opt
, grpname
) == 0)