* Copyright (c) 1980, 1990, 1993
* The Regents of the University of California. All rights reserved.
* This code is derived from software contributed to Berkeley by
* Robert Elz at The University of Melbourne.
* %sccs.include.redist.c%
static char copyright
[] =
"@(#) Copyright (c) 1980, 1990, 1993\n\
The Regents of the University of California. All rights reserved.\n";
static char sccsid
[] = "@(#)repquota.c 8.1 (Berkeley) %G%";
#include <ufs/ufs/quota.h>
char *qfname
= QUOTAFILENAME
;
char *qfextension
[] = INITQFNAMES
;
struct fileusage
*fu_next
;
#define FUHASH 1024 /* must be power of two */
struct fileusage
*fuhead
[MAXQUOTAS
][FUHASH
];
struct fileusage
*lookup();
struct fileusage
*addid();
u_long highid
[MAXQUOTAS
]; /* highest addid()'ed identifier per type */
int aflag
; /* all file systems */
register struct fstab
*fs
;
register struct passwd
*pw
;
register struct group
*gr
;
int gflag
= 0, uflag
= 0, errs
= 0;
long i
, argnum
, done
= 0;
while ((ch
= getopt(argc
, argv
, "aguv")) != EOF
) {
while ((gr
= getgrent()) != 0)
(void) addid((u_long
)gr
->gr_gid
, GRPQUOTA
, gr
->gr_name
);
while ((pw
= getpwent()) != 0)
(void) addid((u_long
)pw
->pw_uid
, USRQUOTA
, pw
->pw_name
);
while ((fs
= getfsent()) != NULL
) {
if (strcmp(fs
->fs_vfstype
, "ufs"))
if (gflag
&& hasquota(fs
, GRPQUOTA
, &qfnp
))
errs
+= repquota(fs
, GRPQUOTA
, qfnp
);
if (uflag
&& hasquota(fs
, USRQUOTA
, &qfnp
))
errs
+= repquota(fs
, USRQUOTA
, qfnp
);
if ((argnum
= oneof(fs
->fs_file
, argv
, argc
)) >= 0 ||
(argnum
= oneof(fs
->fs_spec
, argv
, argc
)) >= 0) {
if (gflag
&& hasquota(fs
, GRPQUOTA
, &qfnp
))
errs
+= repquota(fs
, GRPQUOTA
, qfnp
);
if (uflag
&& hasquota(fs
, USRQUOTA
, &qfnp
))
errs
+= repquota(fs
, USRQUOTA
, qfnp
);
for (i
= 0; i
< argc
; i
++)
if ((done
& (1 << i
)) == 0)
fprintf(stderr
, "%s not found in fstab\n", argv
[i
]);
fprintf(stderr
, "Usage:\n\t%s\n\t%s\n",
"repquota [-v] [-g] [-u] -a",
"repquota [-v] [-g] [-u] filesys ...");
repquota(fs
, type
, qfpathname
)
register struct fstab
*fs
;
register struct fileusage
*fup
;
static struct dqblk zerodqblk
;
if (quotactl(fs
->fs_file
, QCMD(Q_SYNC
, type
), 0, 0) < 0 &&
errno
== EOPNOTSUPP
&& !warned
&& vflag
) {
"*** Warning: Quotas are not compiled into this kernel\n");
fprintf(stdout
, "*** Report for %s quotas on %s (%s)\n",
qfextension
[type
], fs
->fs_file
, fs
->fs_spec
);
if ((qf
= fopen(qfpathname
, "r")) == NULL
) {
fread(&dqbuf
, sizeof(struct dqblk
), 1, qf
);
if (dqbuf
.dqb_curinodes
== 0 && dqbuf
.dqb_curblocks
== 0)
if ((fup
= lookup(id
, type
)) == 0)
fup
= addid(id
, type
, (char *)0);
printf(" Block limits File limits\n");
printf("User used soft hard grace used soft hard grace\n");
for (id
= 0; id
<= highid
[type
]; id
++) {
if (fup
->fu_dqblk
.dqb_curinodes
== 0 &&
fup
->fu_dqblk
.dqb_curblocks
== 0)
printf("%-10s", fup
->fu_name
);
printf("%c%c%8d%8d%8d%7s",
fup
->fu_dqblk
.dqb_bsoftlimit
&&
fup
->fu_dqblk
.dqb_curblocks
>=
fup
->fu_dqblk
.dqb_bsoftlimit
? '+' : '-',
fup
->fu_dqblk
.dqb_isoftlimit
&&
fup
->fu_dqblk
.dqb_curinodes
>=
fup
->fu_dqblk
.dqb_isoftlimit
? '+' : '-',
dbtob(fup
->fu_dqblk
.dqb_curblocks
) / 1024,
dbtob(fup
->fu_dqblk
.dqb_bsoftlimit
) / 1024,
dbtob(fup
->fu_dqblk
.dqb_bhardlimit
) / 1024,
fup
->fu_dqblk
.dqb_bsoftlimit
&&
fup
->fu_dqblk
.dqb_curblocks
>=
fup
->fu_dqblk
.dqb_bsoftlimit
?
timeprt(fup
->fu_dqblk
.dqb_btime
) : "");
printf(" %6d%6d%6d%7s\n",
fup
->fu_dqblk
.dqb_curinodes
,
fup
->fu_dqblk
.dqb_isoftlimit
,
fup
->fu_dqblk
.dqb_ihardlimit
,
fup
->fu_dqblk
.dqb_isoftlimit
&&
fup
->fu_dqblk
.dqb_curinodes
>=
fup
->fu_dqblk
.dqb_isoftlimit
?
timeprt(fup
->fu_dqblk
.dqb_itime
) : "");
fup
->fu_dqblk
= zerodqblk
;
* Check to see if target appears in list of size cnt.
register char *target
, *list
[];
for (i
= 0; i
< cnt
; i
++)
if (strcmp(target
, list
[i
]) == 0)
* Check to see if a particular quota is to be enabled.
hasquota(fs
, type
, qfnamep
)
register struct fstab
*fs
;
char *cp
, *index(), *strtok();
static char initname
, usrname
[100], grpname
[100];
sprintf(usrname
, "%s%s", qfextension
[USRQUOTA
], qfname
);
sprintf(grpname
, "%s%s", qfextension
[GRPQUOTA
], qfname
);
strcpy(buf
, fs
->fs_mntops
);
for (opt
= strtok(buf
, ","); opt
; opt
= strtok(NULL
, ",")) {
if (cp
= index(opt
, '='))
if (type
== USRQUOTA
&& strcmp(opt
, usrname
) == 0)
if (type
== GRPQUOTA
&& strcmp(opt
, grpname
) == 0)
(void) sprintf(buf
, "%s/%s.%s", fs
->fs_file
, qfname
, qfextension
[type
]);
* Routines to manage the file usage table.
* Lookup an id of a specific type.
register struct fileusage
*fup
;
for (fup
= fuhead
[type
][id
& (FUHASH
-1)]; fup
!= 0; fup
= fup
->fu_next
)
return ((struct fileusage
*)0);
* Add a new file usage id if it does not already exist.
struct fileusage
*fup
, **fhp
;
if (fup
= lookup(id
, type
))
if ((fup
= (struct fileusage
*)calloc(1, sizeof(*fup
) + len
)) == NULL
) {
fprintf(stderr
, "out of memory for fileusage structures\n");
fhp
= &fuhead
[type
][id
& (FUHASH
- 1)];
bcopy(name
, fup
->fu_name
, len
+ 1);
sprintf(fup
->fu_name
, "%u", id
);
* 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
);