FreeBSD/sbin/quotacheck/quotacheck.c
/*
 * Update a specified quota file.
 */
Update a specified quota file.
Update a specified quota file .
int
update(const char *fsname, struct quotafile *qf, int type)
{
	struct fileusage *fup;
	u_long id, lastid, highid = 0;
	struct dqblk dqbuf;
	struct stat sb;
	static struct dqblk zerodqbuf;
	static struct fileusage zerofileusage;
	lastid = quota_maxid(qf);
	for (id = 0; id <= lastid; id++) {
		if (quota_read(qf, &dqbuf, id) < 0)
			dqbuf = zerodqbuf;
		if ((fup = lookup(id, type)) == NULL)
			fup = &zerofileusage;
		if (fup->fu_curinodes || fup->fu_curblocks ||
		    dqbuf.dqb_bsoftlimit || dqbuf.dqb_bhardlimit ||
		    dqbuf.dqb_isoftlimit || dqbuf.dqb_ihardlimit)
			highid = id;
		if (dqbuf.dqb_curinodes == fup->fu_curinodes &&
		    dqbuf.dqb_curblocks == fup->fu_curblocks) {
			fup->fu_curinodes = 0;
			fup->fu_curblocks = 0;
			continue;
		}
		printchanges(fsname, type, &dqbuf, fup, id);
		dqbuf.dqb_curinodes = fup->fu_curinodes;
		dqbuf.dqb_curblocks = fup->fu_curblocks;
		(void) quota_write_usage(qf, &dqbuf, id);
		fup->fu_curinodes = 0;
		fup->fu_curblocks = 0;
	}
	for (id = 0; id < FUHASH; id++) {
		for (fup = fuhead[type][id]; fup != NULL; fup = fup->fu_next) {
			if (fup->fu_id <= lastid)
				continue;
			if (fup->fu_curinodes == 0 && fup->fu_curblocks == 0)
				continue;
			bzero(&dqbuf, sizeof(struct dqblk));
			if (fup->fu_id > highid)
				highid = fup->fu_id;
			printchanges(fsname, type, &dqbuf, fup, fup->fu_id);
			dqbuf.dqb_curinodes = fup->fu_curinodes;
			dqbuf.dqb_curblocks = fup->fu_curblocks;
			(void) quota_write_usage(qf, &dqbuf, fup->fu_id);
			fup->fu_curinodes = 0;
			fup->fu_curblocks = 0;
		}
	}
	if (highid < lastid &&
	    stat(quota_qfname(qf), &sb) == 0 &&
	    sb.st_size > (((off_t)highid + 2) * sizeof(struct dqblk)))
		truncate(quota_qfname(qf),
		    (((off_t)highid + 2) * sizeof(struct dqblk)));
	return (0);
}
int update ( const char * fsname , struct quotafile * qf , int type ) { struct fileusage * fup ; u_long id , lastid , highid = 0 ; struct dqblk dqbuf ; struct stat sb ; static struct dqblk zerodqbuf ; static struct fileusage zerofileusage ; lastid = quota_maxid ( qf ) ; for ( id = 0 ; id <= lastid ; id ++ ) { if ( quota_read ( qf , & dqbuf , id ) < 0 ) dqbuf = zerodqbuf ; if ( ( fup = lookup ( id , type ) ) == NULL ) fup = & zerofileusage ; if ( fup -> fu_curinodes || fup -> fu_curblocks || dqbuf . dqb_bsoftlimit || dqbuf . dqb_bhardlimit || dqbuf . dqb_isoftlimit || dqbuf . dqb_ihardlimit ) highid = id ; if ( dqbuf . dqb_curinodes == fup -> fu_curinodes && dqbuf . dqb_curblocks == fup -> fu_curblocks ) { fup -> fu_curinodes = 0 ; fup -> fu_curblocks = 0 ; continue ; } printchanges ( fsname , type , & dqbuf , fup , id ) ; dqbuf . dqb_curinodes = fup -> fu_curinodes ; dqbuf . dqb_curblocks = fup -> fu_curblocks ; ( void ) quota_write_usage ( qf , & dqbuf , id ) ; fup -> fu_curinodes = 0 ; fup -> fu_curblocks = 0 ; } for ( id = 0 ; id < FUHASH ; id ++ ) { for ( fup = fuhead [ type ] [ id ] ; fup != NULL ; fup = fup -> fu_next ) { if ( fup -> fu_id <= lastid ) continue ; if ( fup -> fu_curinodes == 0 && fup -> fu_curblocks == 0 ) continue ; bzero ( & dqbuf , sizeof ( struct dqblk ) ) ; if ( fup -> fu_id > highid ) highid = fup -> fu_id ; printchanges ( fsname , type , & dqbuf , fup , fup -> fu_id ) ; dqbuf . dqb_curinodes = fup -> fu_curinodes ; dqbuf . dqb_curblocks = fup -> fu_curblocks ; ( void ) quota_write_usage ( qf , & dqbuf , fup -> fu_id ) ; fup -> fu_curinodes = 0 ; fup -> fu_curblocks = 0 ; } } if ( highid < lastid && stat ( quota_qfname ( qf ) , & sb ) == 0 && sb . st_size > ( ( ( off_t ) highid + 2 ) * sizeof ( struct dqblk ) ) ) truncate ( quota_qfname ( qf ) , ( ( ( off_t ) highid + 2 ) * sizeof ( struct dqblk ) ) ) ; return ( 0 ) ; }
Update a specified quota file.
Update a specified quota file .
/*
	 * Scan the on-disk quota file and record any usage changes.
	 */ /*
	 * Walk the hash table looking for ids with non-zero usage
	 * that are not currently recorded in the quota file. E.g.
	 * ids that are past the end of the current file.
	 */ /*
	 * If this is old format file, then size may be smaller,
	 * so ensure that we only truncate when it will make things
	 * smaller, and not if it will grow an old format file.
	 */