From 584fea2f92d8bdbedf4d4b45cff7acd9602ae1ad Mon Sep 17 00:00:00 2001 From: mpp Date: Tue, 27 Feb 1996 01:53:17 +0000 Subject: Fix quotacheck to not do a bunch of unneeded fseeks if the quota file information is accurate. This makes it about twice as fast when the uid name space is very large. --- sbin/quotacheck/quotacheck.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sbin/quotacheck/quotacheck.c b/sbin/quotacheck/quotacheck.c index 913e381..823ed46 100644 --- a/sbin/quotacheck/quotacheck.c +++ b/sbin/quotacheck/quotacheck.c @@ -311,6 +311,7 @@ update(fsname, quotafile, type) register struct fileusage *fup; register FILE *qfi, *qfo; register u_long id, lastid; + register off_t offset; struct dqblk dqbuf; static int warned = 0; static struct dqblk zerodqbuf; @@ -343,7 +344,8 @@ update(fsname, quotafile, type) (void)printf("*** Warning: %s\n", "Quotas are not compiled into this kernel"); } - for (lastid = highid[type], id = 0; id <= lastid; id++) { + for (lastid = highid[type], id = 0, offset = 0; id <= lastid; + id++, offset += sizeof(struct dqblk)) { if (fread((char *)&dqbuf, sizeof(struct dqblk), 1, qfi) == 0) dqbuf = zerodqbuf; if ((fup = lookup(id, type)) == 0) @@ -352,7 +354,6 @@ update(fsname, quotafile, type) dqbuf.dqb_curblocks == fup->fu_curblocks) { fup->fu_curinodes = 0; fup->fu_curblocks = 0; - fseek(qfo, (long)sizeof(struct dqblk), 1); continue; } if (vflag) { @@ -381,6 +382,12 @@ update(fsname, quotafile, type) dqbuf.dqb_itime = 0; dqbuf.dqb_curinodes = fup->fu_curinodes; dqbuf.dqb_curblocks = fup->fu_curblocks; + if (fseek(qfo, offset, SEEK_SET) < 0) { + (void) fprintf(stderr, + "quotacheck: %s: seek failed: %s\n", + quotafile, strerror(errno)); + return(1); + } fwrite((char *)&dqbuf, sizeof(struct dqblk), 1, qfo); (void) quotactl(fsname, QCMD(Q_SETUSE, type), id, (caddr_t)&dqbuf); -- cgit v1.1