Exemple #1
0
static int
showquotas(int type, u_long id, const char *name)
{
	struct quotause *qup;
	struct quotause *quplist;
	const char *msgi, *msgb;
	const char *nam;
	char *bgrace = NULL, *igrace = NULL;
	int lines = 0, overquota = 0;
	static time_t now;

	if (now == 0)
		time(&now);
	quplist = getprivs(id, type);
	for (qup = quplist; qup; qup = qup->next) {
		msgi = NULL;
		if (qup->dqblk.dqb_ihardlimit &&
		    qup->dqblk.dqb_curinodes >= qup->dqblk.dqb_ihardlimit) {
			overquota++;
			msgi = "File limit reached on";
		}
		else if (qup->dqblk.dqb_isoftlimit &&
		    qup->dqblk.dqb_curinodes >= qup->dqblk.dqb_isoftlimit) {
			overquota++;
			if (qup->dqblk.dqb_itime > now)
				msgi = "In file grace period on";
			else
				msgi = "Over file quota on";
		}
		msgb = NULL;
		if (qup->dqblk.dqb_bhardlimit &&
		    qup->dqblk.dqb_curblocks >= qup->dqblk.dqb_bhardlimit) {
			overquota++;
			msgb = "Block limit reached on";
		}
		else if (qup->dqblk.dqb_bsoftlimit &&
		    qup->dqblk.dqb_curblocks >= qup->dqblk.dqb_bsoftlimit) {
			overquota++;
			if (qup->dqblk.dqb_btime > now)
				msgb = "In block grace period on";
			else
				msgb = "Over block quota on";
		}
		if (rflag) {
			showrawquotas(type, id, qup);
			continue;
		}
		if (!vflag &&
		    qup->dqblk.dqb_isoftlimit == 0 &&
		    qup->dqblk.dqb_ihardlimit == 0 &&
		    qup->dqblk.dqb_bsoftlimit == 0 &&
		    qup->dqblk.dqb_bhardlimit == 0)
			continue;
		if (qflag) {
			if ((msgi != NULL || msgb != NULL) &&
			    lines++ == 0)
				heading(type, id, name, "");
			if (msgi != NULL)
				printf("\t%s %s\n", msgi, qup->fsname);
			if (msgb != NULL)
				printf("\t%s %s\n", msgb, qup->fsname);
			continue;
		}
		if (!vflag &&
		    qup->dqblk.dqb_curblocks == 0 &&
		    qup->dqblk.dqb_curinodes == 0)
			continue;
		if (lines++ == 0)
			heading(type, id, name, "");
		nam = qup->fsname;
		if (strlen(qup->fsname) > 15) {
			printf("%s\n", qup->fsname);
			nam = "";
		} 
		printf("%-15s", nam);
		if (hflag) {
			prthumanval(7, dbtob(qup->dqblk.dqb_curblocks));
			printf("%c", (msgb == NULL) ? ' ' : '*');
			prthumanval(7, dbtob(qup->dqblk.dqb_bsoftlimit));
			prthumanval(7, dbtob(qup->dqblk.dqb_bhardlimit));
		} else {
			printf(" %7ju%c %7ju %7ju",
			    (uintmax_t)dbtob(qup->dqblk.dqb_curblocks)
				/ 1024,
			    (msgb == NULL) ? ' ' : '*',
			    (uintmax_t)dbtob(qup->dqblk.dqb_bsoftlimit)
				/ 1024,
			    (uintmax_t)dbtob(qup->dqblk.dqb_bhardlimit)
				/ 1024);
		}
		if (msgb != NULL)
			bgrace = timeprt(qup->dqblk.dqb_btime);
		if (msgi != NULL)
			igrace = timeprt(qup->dqblk.dqb_itime);
		printf("%8s %6ju%c %6ju %6ju%8s\n"
			, (msgb == NULL) ? "" : bgrace
			, (uintmax_t)qup->dqblk.dqb_curinodes
			, (msgi == NULL) ? ' ' : '*'
			, (uintmax_t)qup->dqblk.dqb_isoftlimit
			, (uintmax_t)qup->dqblk.dqb_ihardlimit
			, (msgi == NULL) ? "" : igrace
		);
		if (msgb != NULL)
			free(bgrace);
		if (msgi != NULL)
			free(igrace);
	}
	if (!qflag && !rflag && lines == 0)
		heading(type, id, name, "none");
	return (overquota);
}
Exemple #2
0
int
repquota(struct fstab *fs, int type, char *qfpathname)
{
	struct fileusage *fup;
	FILE *qf;
	u_long id;
	struct ufs_dqblk dqbuf;
	static struct ufs_dqblk zerodqblk;
	static int warned = 0;
	static int multiple = 0;

	if (quotactl(fs->fs_file, QCMD(Q_SYNC, type), 0, 0) < 0 &&
	    errno == EOPNOTSUPP && !warned && vflag) {
		warned++;
		fprintf(stdout,
		    "*** Warning: Quotas are not compiled into this kernel\n");
	}
	if (multiple++)
		printf("\n");
	if (vflag)
		fprintf(stdout, "*** Report for %s quotas on %s (%s)\n",
		    qfextension[type], fs->fs_file, fs->fs_spec);
	if ((qf = fopen(qfpathname, "r")) == NULL) {
		warn("%s", qfpathname);
		return (1);
	}
	for (id = 0; ; id++) {
		fread(&dqbuf, sizeof(struct ufs_dqblk), 1, qf);
		if (feof(qf))
			break;
		if (dqbuf.dqb_curinodes == 0 && dqbuf.dqb_curblocks == 0)
			continue;
		if ((fup = lookup(id, type)) == 0)
			fup = addid(id, type, NULL);
		fup->fu_dqblk = dqbuf;
	}
	fclose(qf);
	printf("%*s                Block  limits                    File  limits\n",
		max(UT_NAMESIZE,10), " ");
	printf("User%*s   used     soft     hard  grace     used    soft    hard  grace\n",
		max(UT_NAMESIZE,10), " ");
	for (id = 0; id <= highid[type]; id++) {
		fup = lookup(id, type);
		if (fup == 0)
			continue;
		if (fup->fu_dqblk.dqb_curinodes == 0 &&
		    fup->fu_dqblk.dqb_curblocks == 0)
			continue;
		printf("%-*s", max(UT_NAMESIZE,10), fup->fu_name);
		printf("%c%c %8lu %8lu %8lu %6s",
			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 ? '+' : '-',
			(u_long)(dbtokb(fup->fu_dqblk.dqb_curblocks)),
			(u_long)(dbtokb(fup->fu_dqblk.dqb_bsoftlimit)),
			(u_long)(dbtokb(fup->fu_dqblk.dqb_bhardlimit)),
			fup->fu_dqblk.dqb_bsoftlimit &&
			    fup->fu_dqblk.dqb_curblocks >=
			    fup->fu_dqblk.dqb_bsoftlimit ?
			    timeprt(fup->fu_dqblk.dqb_btime) : "-");
		printf("  %7lu %7lu %7lu %6s\n",
			(u_long)fup->fu_dqblk.dqb_curinodes,
			(u_long)fup->fu_dqblk.dqb_isoftlimit,
			(u_long)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;
	}
	return (0);
}
Exemple #3
0
static void
showquotas(int type, u_long id, const char *name)
{
	struct quotause *qup;
	struct quotause *quplist;
	const char *msgi, *msgb;
	const char *nam;
	int lines = 0;
	static time_t now;

	if (now == 0)
		time(&now);
	quplist = getprivs(id, type);
	for (qup = quplist; qup; qup = qup->next) {
		if (!vflag &&
		    qup->dqblk.dqb_isoftlimit == 0 &&
		    qup->dqblk.dqb_ihardlimit == 0 &&
		    qup->dqblk.dqb_bsoftlimit == 0 &&
		    qup->dqblk.dqb_bhardlimit == 0)
			continue;
		msgi = NULL;
		if (qup->dqblk.dqb_ihardlimit &&
		    qup->dqblk.dqb_curinodes >= qup->dqblk.dqb_ihardlimit)
			msgi = "File limit reached on";
		else if (qup->dqblk.dqb_isoftlimit &&
		    qup->dqblk.dqb_curinodes >= qup->dqblk.dqb_isoftlimit) {
			if (qup->dqblk.dqb_itime > now)
				msgi = "In file grace period on";
			else
				msgi = "Over file quota on";
		}
		msgb = NULL;
		if (qup->dqblk.dqb_bhardlimit &&
		    qup->dqblk.dqb_curblocks >= qup->dqblk.dqb_bhardlimit)
			msgb = "Block limit reached on";
		else if (qup->dqblk.dqb_bsoftlimit &&
		    qup->dqblk.dqb_curblocks >= qup->dqblk.dqb_bsoftlimit) {
			if (qup->dqblk.dqb_btime > now)
				msgb = "In block grace period on";
			else
				msgb = "Over block quota on";
		}
		if (qflag) {
			if ((msgi != NULL || msgb != NULL) &&
			    lines++ == 0)
				heading(type, id, name, "");
			if (msgi != NULL)
				printf("\t%s %s\n", msgi, qup->fsname);
			if (msgb != NULL)
				printf("\t%s %s\n", msgb, qup->fsname);
			continue;
		}
		if (vflag ||
		    qup->dqblk.dqb_curblocks ||
		    qup->dqblk.dqb_curinodes) {
			if (lines++ == 0)
				heading(type, id, name, "");
			nam = qup->fsname;
			if (strlen(qup->fsname) > 15) {
				printf("%s\n", qup->fsname);
				nam = "";
			} 
			printf("%15s%8lu%c%7lu%8lu%8s"
				, nam
				, (u_long) (dbtob(qup->dqblk.dqb_curblocks)
					    / 1024)
				, (msgb == NULL) ? ' ' : '*'
				, (u_long) (dbtob(qup->dqblk.dqb_bsoftlimit)
					    / 1024)
				, (u_long) (dbtob(qup->dqblk.dqb_bhardlimit)
					    / 1024)
				, (msgb == NULL) ? ""
				    :timeprt(qup->dqblk.dqb_btime));
			printf("%8lu%c%7lu%8lu%8s\n"
				, (u_long)qup->dqblk.dqb_curinodes
				, (msgi == NULL) ? ' ' : '*'
				, (u_long)qup->dqblk.dqb_isoftlimit
				, (u_long)qup->dqblk.dqb_ihardlimit
				, (msgi == NULL) ? ""
				    : timeprt(qup->dqblk.dqb_itime)
			);
			continue;
		}
	}
	if (!qflag && lines == 0)
		heading(type, id, name, "none");
}
Exemple #4
0
int
repquota(struct fstab *fs, int type)
{
	struct fileusage *fup;
	struct quotafile *qf;
	u_long id, maxid;
	struct dqblk dqbuf;
	static int multiple = 0;

	if ((qf = quota_open(fs, type, O_RDONLY)) == NULL) {
		if (vflag && !aflag) {
			if (multiple++)
				printf("\n");
			fprintf(stdout, "*** No %s quotas on %s (%s)\n",
			    qfextension[type], fs->fs_file, fs->fs_spec);
			return(1);
		}
		return(0);
	}
	if (multiple++)
		printf("\n");
	if (vflag)
		fprintf(stdout, "*** Report for %s quotas on %s (%s)\n",
		    qfextension[type], fs->fs_file, fs->fs_spec);
	printf("%*s           Block  limits                    File  limits\n",
		max(MAXLOGNAME - 1, 10), " ");
	printf("User%*s  used   soft   hard  grace     used    soft    hard  grace\n",
		max(MAXLOGNAME - 1, 10), " ");
	maxid = quota_maxid(qf);
	for (id = 0; id <= maxid; id++) {
		if (quota_read(qf, &dqbuf, id) != 0)
			break;
		if (dqbuf.dqb_curinodes == 0 && dqbuf.dqb_curblocks == 0)
			continue;
		if ((fup = lookup(id, type)) == 0)
			fup = addid(id, type, (char *)0);
		printf("%-*s ", max(MAXLOGNAME - 1, 10), fup->fu_name);
		printf("%c%c", 
		    dqbuf.dqb_bsoftlimit &&
		    dqbuf.dqb_curblocks >=
		    dqbuf.dqb_bsoftlimit ? '+' : '-',
		    dqbuf.dqb_isoftlimit &&
		    dqbuf.dqb_curinodes >=
		    dqbuf.dqb_isoftlimit ? '+' : '-');
		prthumanval(dqbuf.dqb_curblocks);
		prthumanval(dqbuf.dqb_bsoftlimit);
		prthumanval(dqbuf.dqb_bhardlimit);
		printf(" %6s",
		    dqbuf.dqb_bsoftlimit &&
		    dqbuf.dqb_curblocks >=
		    dqbuf.dqb_bsoftlimit ?
		    timeprt(dqbuf.dqb_btime) : "-");
		printf("  %7ju %7ju %7ju %6s\n",
		    (uintmax_t)dqbuf.dqb_curinodes,
		    (uintmax_t)dqbuf.dqb_isoftlimit,
		    (uintmax_t)dqbuf.dqb_ihardlimit,
		    dqbuf.dqb_isoftlimit &&
		    dqbuf.dqb_curinodes >=
		    dqbuf.dqb_isoftlimit ?
		    timeprt(dqbuf.dqb_itime) : "-");
	}
	quota_close(qf);
	return (0);
}