* 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.6 (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 */
int pflag
; /* fsck like parallel check */
char quotafile
[MAXPATHLEN
+ 1];
struct fileusage zerofileusage
;
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 && strcmp(*argv
, "-p") == 0) {
if (argc
<= 0 && !aflag
) {
fprintf(stderr
, "Usage:\n\t%s\n\t%s\n",
"quotacheck [-v] [-p] -a",
"quotacheck [-v] [-p] filesys ...");
while ((pw
= getpwent()) != 0) {
fup
= lookup(pw
->pw_uid
);
fup
= adduid(pw
->pw_uid
);
strncpy(fup
->fu_name
, pw
->pw_name
,
errs
= preen(argc
, argv
);
fprintf(stderr
, "Can't open ");
while ((fs
= getfsent()) != NULL
) {
strcmp(fs
->fs_type
, FSTAB_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
, fs
->fs_file
, quotafile
);
for (i
= 0; i
< argc
; i
++)
if ((done
& (1 << i
)) == 0)
fprintf(stderr
, "%s not found in %s\n",
register struct fstab
*fs
;
register int passno
, anygtr
;
fprintf(stderr
, "Can't open ");
while ((fs
= getfsent()) != NULL
) {
if (fs
->fs_passno
> passno
)
strcmp(fs
->fs_type
, FSTAB_RQ
) != 0))
!(oneof(fs
->fs_file
, argv
, argc
) ||
oneof(fs
->fs_spec
, argv
, argc
)))
if (fs
->fs_passno
!= passno
)
sprintf(quotafile
, "%s/%s",
exit(chkquota(fs
->fs_spec
,
fs
->fs_file
, quotafile
));
while (wait(&status
) != -1)
errs
+= status
.w_retcode
;
chkquota(fsdev
, fsfile
, qffile
)
register struct fileusage
*fup
;
register FILE *qfi
, *qfo
;
rawdisk
= makerawname(fsdev
);
fprintf(stdout
, "*** Checking quotas for %s (%s)\n", rawdisk
, fsfile
);
qfi
= fopen(qffile
, "r");
if (fstat(fileno(qfi
), &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
);
* Must do fdopen(open(qffile, 1), "w") instead of fopen(qffile, "w")
* because fopen(qffile, "w") would truncate the quota file.
if (fdo
< 0 || (qfo
= fdopen(fdo
, "w")) == NULL
) {
if (quota(Q_SYNC
, 0, quotadev
, (caddr_t
)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, qfi
);
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;
fseek(qfo
, (long)sizeof(struct dqblk
), 1);
if (fup
->fu_name
[0] != '\0')
printf("%-8s fixed:", fup
->fu_name
);
printf("#%-7d fixed:", uid
);
if (dqbuf
.dqb_curinodes
!= fup
->fu_usage
.du_curinodes
)
fprintf(stdout
, "\tinodes %d -> %d",
dqbuf
.dqb_curinodes
, fup
->fu_usage
.du_curinodes
);
if (dqbuf
.dqb_curblocks
!= fup
->fu_usage
.du_curblocks
)
fprintf(stdout
, "\tblocks %d -> %d",
dqbuf
.dqb_curblocks
, fup
->fu_usage
.du_curblocks
);
dqbuf
.dqb_curinodes
= fup
->fu_usage
.du_curinodes
;
dqbuf
.dqb_curblocks
= fup
->fu_usage
.du_curblocks
;
fwrite(&dqbuf
, sizeof(struct dqblk
), 1, qfo
);
quota(Q_SETDUSE
, uid
, quotadev
, &fup
->fu_usage
);
fup
->fu_usage
.du_curinodes
= 0;
fup
->fu_usage
.du_curblocks
= 0;
ftruncate(fileno(qfo
), (off_t
)((highuid
+ 1) * sizeof(struct dqblk
)));
register struct dinode
*ip
;
register struct fileusage
*fup
;
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
)];
if (lseek(fi
, pos
, 0) != pos
) {
if (read(fi
, buf
, cnt
) != cnt
) {
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
, '/');
for (ch
= 'r'; *cp
!= '\0'; ) {