* 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
[] = "@(#)quotacheck.c 5.2 (Berkeley) %G%";
* Fix up / report on disc quotas & usage
struct dinode itab
[ITABSZ
];
struct fileusage
*fu_next
;
char fu_name
[LOGINNAMESIZE
+ 1];
struct fileusage
*fuhead
[FUHASH
];
struct fileusage
*lookup();
struct fileusage
*adduid();
struct passwd
*getpwent();
char *malloc(), *makerawname();
int aflag
; /* all file systems */
char quotafile
[MAXPATHLEN
+ 1];
register struct fstab
*fs
;
register struct fileusage
*fup
;
register struct passwd
*pw
;
if (argc
> 0 && strcmp(*argv
, "-v") == 0) {
if (argc
> 0 && strcmp(*argv
, "-a") == 0) {
if (argc
<= 0 && !aflag
) {
fprintf(stderr
, "Usage:\n\t%s\n\t%s\n",
"quotacheck [-v] filesys ...");
while ((pw
= getpwent()) != 0) {
fup
= lookup(pw
->pw_uid
);
fup
= adduid(pw
->pw_uid
);
strncpy(fup
->fu_name
, pw
->pw_name
,
while ((fs
= getfsent()) != NULL
) {
(fs
->fs_type
== 0 || strcmp(fs
->fs_type
, "rq") != 0))
!(oneof(fs
->fs_file
, argv
, argc
) ||
oneof(fs
->fs_spec
, argv
, argc
)))
(void) sprintf(quotafile
, "%s/%s", fs
->fs_file
, qfname
);
errs
+= chkquota(fs
->fs_spec
, quotafile
);
for (i
= 0; i
< argc
; i
++)
if ((done
& (1 << i
)) == 0)
fprintf(stderr
, "%s not found in /etc/fstab\n",
register struct fileusage
*fup
;
rawdisk
= makerawname(fsdev
);
fprintf(stdout
, "*** Check quotas for %s\n", rawdisk
);
qf
= fopen(qffile
, "r+");
if (fstat(fileno(qf
), &statb
) < 0) {
if (stat(fsdev
, &statb
) < 0) {
if (quotadev
!= statb
.st_rdev
) {
fprintf(stderr
, "%s dev (0x%x) mismatch %s dev (0x%x)\n",
qffile
, quotadev
, fsdev
, statb
.st_rdev
);
if (quota(Q_SYNC
, 0, quotadev
, 0) < 0 &&
errno
== EINVAL
&& !warned
&& vflag
) {
"*** Warning: Quotas are not compiled into this kernel\n");
bread(SBLOCK
, (char *)&sblock
, SBSIZE
);
for (cg
= 0; cg
< sblock
.fs_ncg
; cg
++) {
for (i
= 0; i
< sblock
.fs_ipg
; i
++)
for (uid
= 0; uid
<= highuid
; uid
++) {
i
= fread(&dqbuf
, sizeof(struct dqblk
), 1, qf
);
if ((dqbuf
.dqb_curinodes
!= 0 ||
dqbuf
.dqb_curblocks
!= 0) &&
fseek(qf
, uid
* sizeof(struct dqblk
), 0);
fwrite(&dqbuf
, sizeof(struct dqblk
), 1, qf
);
fseek(qf
, (uid
+ 1) * sizeof(struct dqblk
), 0);
if (dqbuf
.dqb_curinodes
== fup
->fu_usage
.du_curinodes
&&
dqbuf
.dqb_curblocks
== fup
->fu_usage
.du_curblocks
) {
fup
->fu_usage
.du_curinodes
= 0;
fup
->fu_usage
.du_curblocks
= 0;
if (fup
->fu_name
[0] != '\0')
printf("%-10s fixed:", fup
->fu_name
);
printf("#%-9d fixed:", uid
);
fprintf(stdout
, " inodes (old %d, new %d)",
dqbuf
.dqb_curinodes
, fup
->fu_usage
.du_curinodes
);
fprintf(stdout
, " blocks (old %d, new %d)\n",
dqbuf
.dqb_curblocks
, fup
->fu_usage
.du_curblocks
);
dqbuf
.dqb_curinodes
= fup
->fu_usage
.du_curinodes
;
dqbuf
.dqb_curblocks
= fup
->fu_usage
.du_curblocks
;
fseek(qf
, uid
* sizeof(struct dqblk
), 0);
fwrite(&dqbuf
, sizeof(struct dqblk
), 1, qf
);
fseek(qf
, (uid
+ 1) * sizeof(struct dqblk
), 0);
quota(Q_SETDUSE
, uid
, quotadev
, &fup
->fu_usage
);
fup
->fu_usage
.du_curinodes
= 0;
fup
->fu_usage
.du_curblocks
= 0;
ftruncate(fileno(qf
), (highuid
+ 1) * sizeof(struct dqblk
));
register struct dinode
*ip
;
register struct fileusage
*fup
;
fup
= lookup(ip
->di_uid
);
fup
= adduid(ip
->di_uid
);
fup
->fu_usage
.du_curinodes
++;
if ((ip
->di_mode
& IFMT
) == IFCHR
|| (ip
->di_mode
& IFMT
) == IFBLK
)
fup
->fu_usage
.du_curblocks
+= ip
->di_blocks
;
if (strcmp(target
, list
[i
]) == 0) {
register unsigned long iblk
;
if (dp
== NULL
|| ++dp
>= &itab
[ITABSZ
]) {
iblk
= itod(&sblock
, ino
);
bread(fsbtodb(&sblock
, iblk
), (char *)itab
, sizeof itab
);
dp
= &itab
[ino
% INOPB(&sblock
)];
lseek(fi
, (long)dbtob(bno
), 0);
if (read(fi
, buf
, cnt
) != cnt
) {
printf("read error %u\n", bno
);
register struct fileusage
*fup
;
for (fup
= fuhead
[uid
% FUHASH
]; fup
!= 0; fup
= fup
->fu_next
)
return ((struct fileusage
*)0);
struct fileusage
*fup
, **fhp
;
fup
= (struct fileusage
*)calloc(1, sizeof(struct fileusage
));
fprintf(stderr
, "out of memory for fileusage structures\n");
fhp
= &fuhead
[uid
% FUHASH
];
static char rawname
[MAXPATHLEN
];
cp
= rindex(rawname
, '/') + 1;
if (cp
== (char *)1 || *cp
== 'r')
for (ch
= 'r'; *cp
!= '\0'; ) {