2015-06-17 02:04:13 +03:00
|
|
|
/* $NetBSD: repquota.c,v 1.45 2015/06/16 23:04:14 christos Exp $ */
|
2011-03-07 01:33:55 +03:00
|
|
|
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
/*
|
1994-06-14 02:04:11 +04:00
|
|
|
* Copyright (c) 1980, 1990, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Robert Elz at The University of Melbourne.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 15:25:11 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1997-10-17 11:35:05 +04:00
|
|
|
#include <sys/cdefs.h>
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
#ifndef lint
|
2008-07-21 17:36:57 +04:00
|
|
|
__COPYRIGHT("@(#) Copyright (c) 1980, 1990, 1993\
|
|
|
|
The Regents of the University of California. All rights reserved.");
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#ifndef lint
|
1997-10-17 11:35:05 +04:00
|
|
|
#if 0
|
|
|
|
static char sccsid[] = "@(#)repquota.c 8.2 (Berkeley) 11/22/94";
|
|
|
|
#else
|
2015-06-17 02:04:13 +03:00
|
|
|
__RCSID("$NetBSD: repquota.c,v 1.45 2015/06/16 23:04:14 christos Exp $");
|
1997-10-17 11:35:05 +04:00
|
|
|
#endif
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Quota report
|
|
|
|
*/
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/stat.h>
|
2011-03-06 20:08:10 +03:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/statvfs.h>
|
|
|
|
|
1997-10-17 17:02:01 +04:00
|
|
|
#include <errno.h>
|
2011-03-06 20:08:10 +03:00
|
|
|
#include <err.h>
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
#include <fstab.h>
|
|
|
|
#include <grp.h>
|
1997-10-17 17:02:01 +04:00
|
|
|
#include <pwd.h>
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
#include <stdio.h>
|
1997-10-17 17:02:01 +04:00
|
|
|
#include <stdlib.h>
|
1994-12-23 19:39:28 +03:00
|
|
|
#include <string.h>
|
1997-10-17 17:02:01 +04:00
|
|
|
#include <unistd.h>
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
|
2012-01-09 19:38:20 +04:00
|
|
|
#include <quota.h>
|
2011-03-06 20:08:10 +03:00
|
|
|
|
2011-03-07 01:33:55 +03:00
|
|
|
#include "printquota.h"
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
|
2012-01-25 05:24:53 +04:00
|
|
|
/*
|
|
|
|
* XXX. Ideally we shouldn't compile either of these in, but it's a
|
|
|
|
* nontrivial rework to avoid it and it'll work ok for now.
|
|
|
|
*/
|
|
|
|
#define REPQUOTA_NUMIDTYPES 2
|
|
|
|
#define REPQUOTA_NUMOBJTYPES 2
|
|
|
|
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
struct fileusage {
|
|
|
|
struct fileusage *fu_next;
|
2012-01-25 05:24:53 +04:00
|
|
|
struct quotaval fu_qv[REPQUOTA_NUMOBJTYPES];
|
2011-03-07 01:33:55 +03:00
|
|
|
uint32_t fu_id;
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
char fu_name[1];
|
|
|
|
/* actually bigger */
|
|
|
|
};
|
2012-01-25 05:24:53 +04:00
|
|
|
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
#define FUHASH 1024 /* must be power of two */
|
2012-01-25 05:24:53 +04:00
|
|
|
static struct fileusage *fuhead[REPQUOTA_NUMIDTYPES][FUHASH];
|
|
|
|
|
|
|
|
/* highest addid()'ed identifier per idtype */
|
|
|
|
static uint32_t highid[REPQUOTA_NUMIDTYPES];
|
|
|
|
|
|
|
|
int valid[REPQUOTA_NUMIDTYPES];
|
|
|
|
|
|
|
|
static struct quotaval defaultqv[REPQUOTA_NUMIDTYPES][REPQUOTA_NUMOBJTYPES];
|
2011-03-07 01:33:55 +03:00
|
|
|
|
|
|
|
static int vflag = 0; /* verbose */
|
|
|
|
static int aflag = 0; /* all file systems */
|
|
|
|
static int hflag = 0; /* humanize */
|
|
|
|
static int xflag = 0; /* export */
|
|
|
|
|
2012-01-25 05:24:53 +04:00
|
|
|
/*
|
|
|
|
* XXX this should go away and be replaced with a call to
|
|
|
|
* quota_idtype_getname(), but that needs a quotahandle and requires
|
|
|
|
* the same nontrivial rework as getting rid of REPQUOTA_NUMIDTYPES.
|
|
|
|
*/
|
|
|
|
static const char *const repquota_idtype_names[REPQUOTA_NUMIDTYPES] = {
|
|
|
|
"user",
|
|
|
|
"group",
|
|
|
|
};
|
2011-03-07 01:33:55 +03:00
|
|
|
|
|
|
|
static struct fileusage *addid(uint32_t, int, const char *);
|
|
|
|
static struct fileusage *lookup(uint32_t, int);
|
|
|
|
static struct fileusage *qremove(uint32_t, int);
|
2012-01-09 19:38:59 +04:00
|
|
|
static int repquota(struct quotahandle *, int);
|
2011-03-07 01:33:55 +03:00
|
|
|
static void usage(void) __attribute__((__noreturn__));
|
2012-01-09 19:38:59 +04:00
|
|
|
static void printquotas(int, struct quotahandle *);
|
2011-03-07 01:33:55 +03:00
|
|
|
static void exportquotas(void);
|
2012-01-09 19:42:37 +04:00
|
|
|
static int oneof(const char *, char *[], int cnt);
|
2012-02-01 21:48:10 +04:00
|
|
|
static int isover(struct quotaval *qv, time_t now);
|
1997-10-17 17:02:01 +04:00
|
|
|
|
|
|
|
int
|
2011-03-07 01:33:55 +03:00
|
|
|
main(int argc, char **argv)
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
{
|
|
|
|
int gflag = 0, uflag = 0, errs = 0;
|
|
|
|
long i, argnum, done = 0;
|
1996-03-31 03:49:48 +04:00
|
|
|
int ch;
|
2011-03-06 20:08:10 +03:00
|
|
|
struct statvfs *fst;
|
|
|
|
int nfst;
|
2012-01-09 19:38:59 +04:00
|
|
|
struct quotahandle *qh;
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
|
2012-02-13 05:35:06 +04:00
|
|
|
if (!strcmp(getprogname(), "quotadump")) {
|
|
|
|
xflag = 1;
|
|
|
|
}
|
|
|
|
|
2012-05-12 23:47:26 +04:00
|
|
|
while ((ch = getopt(argc, argv, "aguhvx")) != -1) {
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
switch(ch) {
|
|
|
|
case 'a':
|
|
|
|
aflag++;
|
|
|
|
break;
|
|
|
|
case 'g':
|
|
|
|
gflag++;
|
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
uflag++;
|
|
|
|
break;
|
2011-03-06 20:08:10 +03:00
|
|
|
case 'h':
|
|
|
|
hflag++;
|
|
|
|
break;
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
case 'v':
|
|
|
|
vflag++;
|
|
|
|
break;
|
2011-03-06 20:08:10 +03:00
|
|
|
case 'x':
|
|
|
|
xflag++;
|
|
|
|
break;
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
2011-03-06 20:08:10 +03:00
|
|
|
if (xflag && (argc != 1 || aflag))
|
|
|
|
usage();
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
if (argc == 0 && !aflag)
|
|
|
|
usage();
|
|
|
|
if (!gflag && !uflag) {
|
|
|
|
if (aflag)
|
|
|
|
gflag++;
|
|
|
|
uflag++;
|
|
|
|
}
|
2011-03-06 20:08:10 +03:00
|
|
|
|
|
|
|
nfst = getmntinfo(&fst, MNT_WAIT);
|
|
|
|
if (nfst == 0)
|
2011-03-07 01:33:55 +03:00
|
|
|
errx(1, "no filesystems mounted!");
|
2011-03-06 20:08:10 +03:00
|
|
|
for (i = 0; i < nfst; i++) {
|
|
|
|
if ((fst[i].f_flag & ST_QUOTA) == 0)
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
continue;
|
2012-01-09 19:38:59 +04:00
|
|
|
/* check if we want this volume */
|
|
|
|
if (!aflag) {
|
|
|
|
argnum = oneof(fst[i].f_mntonname, argv, argc);
|
|
|
|
if (argnum < 0) {
|
|
|
|
argnum = oneof(fst[i].f_mntfromname,
|
|
|
|
argv, argc);
|
|
|
|
}
|
|
|
|
if (argnum < 0) {
|
|
|
|
continue;
|
|
|
|
}
|
2011-03-07 01:33:55 +03:00
|
|
|
done |= 1U << argnum;
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
}
|
2012-01-09 19:38:59 +04:00
|
|
|
|
|
|
|
qh = quota_open(fst[i].f_mntonname);
|
|
|
|
if (qh == NULL) {
|
|
|
|
/* XXX: check this errno */
|
|
|
|
if (errno == EOPNOTSUPP || errno == ENXIO) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
warn("%s: quota_open", fst[i].f_mntonname);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gflag)
|
|
|
|
errs += repquota(qh, QUOTA_IDTYPE_GROUP);
|
|
|
|
if (uflag)
|
|
|
|
errs += repquota(qh, QUOTA_IDTYPE_USER);
|
|
|
|
|
|
|
|
quota_close(qh);
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
}
|
2011-03-06 20:08:10 +03:00
|
|
|
if (xflag)
|
|
|
|
exportquotas();
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
for (i = 0; i < argc; i++)
|
2011-03-07 01:33:55 +03:00
|
|
|
if ((done & (1U << i)) == 0)
|
|
|
|
warnx("%s not mounted", argv[i]);
|
|
|
|
return errs;
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
}
|
|
|
|
|
2011-03-07 01:33:55 +03:00
|
|
|
static void
|
|
|
|
usage(void)
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
{
|
2011-03-07 01:33:55 +03:00
|
|
|
const char *p = getprogname();
|
|
|
|
fprintf(stderr, "usage: %s [-D] [-v] [-g] [-u] -a\n"
|
|
|
|
"\t%s [-D] [-v] [-g] [-u] filesys ...\n"
|
|
|
|
"\t%s -x [-D] [-g] [-u] filesys\n", p, p, p);
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2011-03-07 01:33:55 +03:00
|
|
|
static int
|
2012-01-09 19:38:59 +04:00
|
|
|
repquota(struct quotahandle *qh, int idtype)
|
|
|
|
{
|
2012-01-09 19:40:47 +04:00
|
|
|
struct quotacursor *qc;
|
|
|
|
struct quotakey qk;
|
|
|
|
struct quotaval qv;
|
2012-01-09 19:38:59 +04:00
|
|
|
struct quotaval *qvp;
|
|
|
|
struct fileusage *fup;
|
|
|
|
|
2012-01-09 19:40:47 +04:00
|
|
|
qc = quota_opencursor(qh);
|
|
|
|
if (qc == NULL) {
|
2012-01-09 19:38:59 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-01-09 19:40:47 +04:00
|
|
|
if (idtype == QUOTA_IDTYPE_USER) {
|
|
|
|
quotacursor_skipidtype(qc, QUOTA_IDTYPE_GROUP);
|
|
|
|
}
|
|
|
|
if (idtype == QUOTA_IDTYPE_GROUP) {
|
|
|
|
quotacursor_skipidtype(qc, QUOTA_IDTYPE_USER);
|
|
|
|
}
|
|
|
|
|
|
|
|
valid[idtype] = 0;
|
|
|
|
while (!quotacursor_atend(qc)) {
|
|
|
|
if (quotacursor_get(qc, &qk, &qv)) {
|
|
|
|
err(1, "%s: quotacursor_get", quota_getmountpoint(qh));
|
|
|
|
}
|
|
|
|
if (qk.qk_idtype != idtype) {
|
|
|
|
continue;
|
2011-03-06 20:08:10 +03:00
|
|
|
}
|
2012-01-09 19:40:47 +04:00
|
|
|
|
|
|
|
valid[idtype] = 1;
|
|
|
|
if (qk.qk_id == QUOTA_DEFAULTID) {
|
|
|
|
qvp = defaultqv[idtype];
|
|
|
|
} else {
|
|
|
|
if ((fup = lookup(qk.qk_id, idtype)) == 0)
|
|
|
|
fup = addid(qk.qk_id, idtype, (char *)0);
|
|
|
|
qvp = fup->fu_qv;
|
|
|
|
}
|
|
|
|
if (qk.qk_objtype == QUOTA_OBJTYPE_BLOCKS) {
|
|
|
|
qvp[QUOTA_OBJTYPE_BLOCKS] = qv;
|
|
|
|
} else if (qk.qk_objtype == QUOTA_OBJTYPE_FILES) {
|
|
|
|
qvp[QUOTA_OBJTYPE_FILES] = qv;
|
|
|
|
}
|
|
|
|
}
|
2012-01-09 19:38:59 +04:00
|
|
|
|
2012-01-09 19:38:20 +04:00
|
|
|
if (xflag == 0 && valid[idtype])
|
2012-01-09 19:38:59 +04:00
|
|
|
printquotas(idtype, qh);
|
|
|
|
|
2011-03-07 01:33:55 +03:00
|
|
|
return 0;
|
2011-03-06 20:08:10 +03:00
|
|
|
}
|
|
|
|
|
2011-03-07 01:33:55 +03:00
|
|
|
static void
|
2012-01-09 19:38:59 +04:00
|
|
|
printquotas(int idtype, struct quotahandle *qh)
|
2011-03-06 20:08:10 +03:00
|
|
|
{
|
|
|
|
static int multiple = 0;
|
2011-03-07 01:33:55 +03:00
|
|
|
uint32_t id;
|
2011-03-06 20:08:10 +03:00
|
|
|
int i;
|
|
|
|
struct fileusage *fup;
|
2011-11-25 20:55:05 +04:00
|
|
|
struct quotaval *q;
|
2012-01-25 05:24:53 +04:00
|
|
|
const char *timemsg[REPQUOTA_NUMOBJTYPES];
|
|
|
|
char overchar[REPQUOTA_NUMOBJTYPES];
|
2011-03-07 01:33:55 +03:00
|
|
|
time_t now;
|
2011-03-07 14:56:31 +03:00
|
|
|
char b0[2][20], b1[20], b2[20], b3[20];
|
2012-01-25 05:24:53 +04:00
|
|
|
int ok, objtype;
|
|
|
|
int isbytes, width;
|
2011-03-06 20:08:10 +03:00
|
|
|
|
2012-01-09 19:38:20 +04:00
|
|
|
switch (idtype) {
|
|
|
|
case QUOTA_IDTYPE_GROUP:
|
2011-03-06 20:08:10 +03:00
|
|
|
{
|
|
|
|
struct group *gr;
|
|
|
|
setgrent();
|
|
|
|
while ((gr = getgrent()) != 0)
|
2012-01-09 19:38:20 +04:00
|
|
|
(void)addid(gr->gr_gid, idtype, gr->gr_name);
|
2011-03-06 20:08:10 +03:00
|
|
|
endgrent();
|
|
|
|
break;
|
|
|
|
}
|
2012-01-09 19:38:20 +04:00
|
|
|
case QUOTA_IDTYPE_USER:
|
2011-03-06 20:08:10 +03:00
|
|
|
{
|
|
|
|
struct passwd *pw;
|
|
|
|
setpwent();
|
|
|
|
while ((pw = getpwent()) != 0)
|
2012-01-09 19:38:20 +04:00
|
|
|
(void)addid(pw->pw_uid, idtype, pw->pw_name);
|
2011-03-06 20:08:10 +03:00
|
|
|
endpwent();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2012-01-09 19:38:20 +04:00
|
|
|
errx(1, "Unknown quota ID type %d", idtype);
|
2011-03-06 20:08:10 +03:00
|
|
|
}
|
|
|
|
|
2011-03-07 01:33:55 +03:00
|
|
|
time(&now);
|
2011-03-06 20:08:10 +03:00
|
|
|
|
|
|
|
if (multiple++)
|
|
|
|
printf("\n");
|
|
|
|
if (vflag)
|
2012-01-09 19:38:59 +04:00
|
|
|
printf("*** Report for %s quotas on %s (%s: %s)\n",
|
2012-01-25 05:24:53 +04:00
|
|
|
repquota_idtype_names[idtype], quota_getmountpoint(qh),
|
2012-01-09 19:38:59 +04:00
|
|
|
quota_getmountdevice(qh), quota_getimplname(qh));
|
2011-03-07 01:33:55 +03:00
|
|
|
printf(" Block limits "
|
|
|
|
"File limits\n");
|
2012-01-09 19:38:20 +04:00
|
|
|
printf(idtype == QUOTA_IDTYPE_USER ? "User " : "Group");
|
2011-03-07 01:33:55 +03:00
|
|
|
printf(" used soft hard grace used"
|
2012-01-29 11:23:52 +04:00
|
|
|
" soft hard grace\n");
|
2012-01-09 19:38:20 +04:00
|
|
|
for (id = 0; id <= highid[idtype]; id++) {
|
|
|
|
fup = qremove(id, idtype);
|
2011-11-25 20:55:05 +04:00
|
|
|
q = fup->fu_qv;
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
if (fup == 0)
|
|
|
|
continue;
|
2012-01-25 05:24:53 +04:00
|
|
|
for (i = 0; i < REPQUOTA_NUMOBJTYPES; i++) {
|
2012-02-01 21:48:10 +04:00
|
|
|
if (isover(&q[i], now)) {
|
2011-03-07 14:56:31 +03:00
|
|
|
timemsg[i] = timeprt(b0[i], 8, now,
|
2011-11-25 20:55:05 +04:00
|
|
|
q[i].qv_expiretime);
|
2011-03-06 20:08:10 +03:00
|
|
|
overchar[i] = '+';
|
2012-02-01 21:48:10 +04:00
|
|
|
} else {
|
2012-01-09 19:38:59 +04:00
|
|
|
if (vflag && q[i].qv_grace != QUOTA_NOTIME) {
|
|
|
|
timemsg[i] = timeprt(b0[i], 8, 0,
|
|
|
|
q[i].qv_grace);
|
|
|
|
} else {
|
|
|
|
timemsg[i] = "";
|
|
|
|
}
|
2011-03-06 20:08:10 +03:00
|
|
|
overchar[i] = '-';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-25 05:24:53 +04:00
|
|
|
ok = 1;
|
|
|
|
for (objtype = 0; objtype < REPQUOTA_NUMOBJTYPES; objtype++) {
|
|
|
|
if (q[objtype].qv_usage != 0 ||
|
|
|
|
overchar[objtype] != '-') {
|
|
|
|
ok = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ok && vflag == 0)
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
continue;
|
2005-03-05 17:46:29 +03:00
|
|
|
if (strlen(fup->fu_name) > 9)
|
|
|
|
printf("%s ", fup->fu_name);
|
|
|
|
else
|
|
|
|
printf("%-10s", fup->fu_name);
|
2012-01-25 05:24:53 +04:00
|
|
|
for (objtype = 0; objtype < REPQUOTA_NUMOBJTYPES; objtype++) {
|
|
|
|
printf("%c", overchar[objtype]);
|
|
|
|
}
|
|
|
|
for (objtype = 0; objtype < REPQUOTA_NUMOBJTYPES; objtype++) {
|
|
|
|
isbytes = quota_objtype_isbytes(qh, objtype);
|
|
|
|
width = isbytes ? 9 : 8;
|
|
|
|
printf("%*s%*s%*s%7s",
|
|
|
|
width,
|
|
|
|
intprt(b1, width+1, q[objtype].qv_usage,
|
|
|
|
isbytes ? HN_B : 0, hflag),
|
|
|
|
width,
|
|
|
|
intprt(b2, width+1, q[objtype].qv_softlimit,
|
|
|
|
isbytes ? HN_B : 0, hflag),
|
|
|
|
width,
|
|
|
|
intprt(b3, width+1, q[objtype].qv_hardlimit,
|
|
|
|
isbytes ? HN_B : 0, hflag),
|
|
|
|
timemsg[objtype]);
|
|
|
|
|
|
|
|
if (objtype + 1 < REPQUOTA_NUMOBJTYPES) {
|
|
|
|
printf(" ");
|
|
|
|
} else {
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
}
|
2011-03-06 20:08:10 +03:00
|
|
|
free(fup);
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
}
|
2011-03-06 20:08:10 +03:00
|
|
|
}
|
|
|
|
|
2011-03-07 01:33:55 +03:00
|
|
|
static void
|
2012-02-01 09:12:45 +04:00
|
|
|
exportquotaval(const struct quotaval *qv)
|
2011-03-06 20:08:10 +03:00
|
|
|
{
|
2012-02-01 09:12:45 +04:00
|
|
|
if (qv->qv_hardlimit == QUOTA_NOLIMIT) {
|
|
|
|
printf(" -");
|
|
|
|
} else {
|
|
|
|
printf(" %llu", (unsigned long long)qv->qv_hardlimit);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (qv->qv_softlimit == QUOTA_NOLIMIT) {
|
|
|
|
printf(" -");
|
|
|
|
} else {
|
|
|
|
printf(" %llu", (unsigned long long)qv->qv_softlimit);
|
|
|
|
}
|
2011-03-06 20:08:10 +03:00
|
|
|
|
2012-02-01 09:12:45 +04:00
|
|
|
printf(" %llu", (unsigned long long)qv->qv_usage);
|
2011-03-06 20:08:10 +03:00
|
|
|
|
2012-02-01 09:12:45 +04:00
|
|
|
if (qv->qv_expiretime == QUOTA_NOTIME) {
|
|
|
|
printf(" -");
|
|
|
|
} else {
|
|
|
|
printf(" %lld", (long long)qv->qv_expiretime);
|
2011-03-06 20:08:10 +03:00
|
|
|
}
|
|
|
|
|
2012-02-01 09:12:45 +04:00
|
|
|
if (qv->qv_grace == QUOTA_NOTIME) {
|
|
|
|
printf(" -");
|
|
|
|
} else {
|
|
|
|
printf(" %lld", (long long)qv->qv_grace);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
exportquotas(void)
|
|
|
|
{
|
|
|
|
int idtype;
|
|
|
|
id_t id;
|
|
|
|
struct fileusage *fup;
|
|
|
|
|
|
|
|
/* header */
|
|
|
|
printf("@format netbsd-quota-dump v1\n");
|
|
|
|
printf("# idtype id objtype hard soft usage expire grace\n");
|
2011-03-06 20:08:10 +03:00
|
|
|
|
2012-01-25 05:24:53 +04:00
|
|
|
for (idtype = 0; idtype < REPQUOTA_NUMIDTYPES; idtype++) {
|
2012-01-09 19:38:20 +04:00
|
|
|
if (valid[idtype] == 0)
|
2011-03-06 20:08:10 +03:00
|
|
|
continue;
|
2012-02-01 09:12:45 +04:00
|
|
|
|
2012-02-13 05:35:06 +04:00
|
|
|
printf("%s default block ", repquota_idtype_names[idtype]);
|
2012-02-01 09:12:45 +04:00
|
|
|
exportquotaval(&defaultqv[idtype][QUOTA_OBJTYPE_BLOCKS]);
|
|
|
|
printf("\n");
|
|
|
|
|
2012-02-13 05:35:06 +04:00
|
|
|
printf("%s default file ", repquota_idtype_names[idtype]);
|
2012-02-01 09:12:45 +04:00
|
|
|
exportquotaval(&defaultqv[idtype][QUOTA_OBJTYPE_FILES]);
|
|
|
|
printf("\n");
|
2011-03-06 20:08:10 +03:00
|
|
|
|
2012-01-09 19:38:20 +04:00
|
|
|
for (id = 0; id <= highid[idtype]; id++) {
|
|
|
|
fup = qremove(id, idtype);
|
2011-03-06 20:08:10 +03:00
|
|
|
if (fup == 0)
|
|
|
|
continue;
|
|
|
|
|
2012-02-13 05:35:06 +04:00
|
|
|
printf("%s %u block ", repquota_idtype_names[idtype],
|
2012-02-01 09:12:45 +04:00
|
|
|
id);
|
|
|
|
exportquotaval(&fup->fu_qv[QUOTA_OBJTYPE_BLOCKS]);
|
|
|
|
printf("\n");
|
2011-03-06 20:08:10 +03:00
|
|
|
|
2012-02-13 05:35:06 +04:00
|
|
|
printf("%s %u file ", repquota_idtype_names[idtype],
|
2012-02-01 09:12:45 +04:00
|
|
|
id);
|
|
|
|
exportquotaval(&fup->fu_qv[QUOTA_OBJTYPE_FILES]);
|
|
|
|
printf("\n");
|
2011-03-06 20:08:10 +03:00
|
|
|
|
2012-02-01 09:12:45 +04:00
|
|
|
free(fup);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("@end\n");
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Routines to manage the file usage table.
|
|
|
|
*
|
2012-01-09 19:38:20 +04:00
|
|
|
* Lookup an id of a specific id type.
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
*/
|
|
|
|
struct fileusage *
|
2012-01-09 19:38:20 +04:00
|
|
|
lookup(uint32_t id, int idtype)
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
{
|
1997-10-17 17:02:01 +04:00
|
|
|
struct fileusage *fup;
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
|
2012-01-09 19:38:20 +04:00
|
|
|
for (fup = fuhead[idtype][id & (FUHASH-1)]; fup != 0; fup = fup->fu_next)
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
if (fup->fu_id == id)
|
2011-03-07 01:33:55 +03:00
|
|
|
return fup;
|
|
|
|
return NULL;
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
}
|
2011-03-06 20:08:10 +03:00
|
|
|
/*
|
2012-01-09 19:38:20 +04:00
|
|
|
* Lookup and remove an id of a specific id type.
|
2011-03-06 20:08:10 +03:00
|
|
|
*/
|
2011-03-07 01:33:55 +03:00
|
|
|
static struct fileusage *
|
2012-01-09 19:38:20 +04:00
|
|
|
qremove(uint32_t id, int idtype)
|
2011-03-06 20:08:10 +03:00
|
|
|
{
|
|
|
|
struct fileusage *fup, **fupp;
|
|
|
|
|
2012-01-09 19:38:20 +04:00
|
|
|
for (fupp = &fuhead[idtype][id & (FUHASH-1)]; *fupp != 0;) {
|
2011-03-06 20:08:10 +03:00
|
|
|
fup = *fupp;
|
|
|
|
if (fup->fu_id == id) {
|
|
|
|
*fupp = fup->fu_next;
|
2011-03-07 01:33:55 +03:00
|
|
|
return fup;
|
2011-03-06 20:08:10 +03:00
|
|
|
}
|
|
|
|
fupp = &fup->fu_next;
|
|
|
|
}
|
2011-03-07 01:33:55 +03:00
|
|
|
return NULL;
|
2011-03-06 20:08:10 +03:00
|
|
|
}
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a new file usage id if it does not already exist.
|
|
|
|
*/
|
2011-03-07 01:33:55 +03:00
|
|
|
static struct fileusage *
|
2012-01-09 19:38:20 +04:00
|
|
|
addid(uint32_t id, int idtype, const char *name)
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
{
|
|
|
|
struct fileusage *fup, **fhp;
|
2011-03-06 20:08:10 +03:00
|
|
|
struct group *gr = NULL;
|
|
|
|
struct passwd *pw = NULL;
|
2011-03-07 01:33:55 +03:00
|
|
|
size_t len;
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
|
2012-01-09 19:38:20 +04:00
|
|
|
if ((fup = lookup(id, idtype)) != NULL) {
|
2011-03-07 01:33:55 +03:00
|
|
|
return fup;
|
2011-03-06 20:08:10 +03:00
|
|
|
}
|
|
|
|
if (name == NULL) {
|
2012-01-09 19:38:20 +04:00
|
|
|
switch(idtype) {
|
|
|
|
case QUOTA_IDTYPE_GROUP:
|
2011-03-06 20:08:10 +03:00
|
|
|
gr = getgrgid(id);
|
|
|
|
|
|
|
|
if (gr != NULL)
|
|
|
|
name = gr->gr_name;
|
|
|
|
break;
|
2012-01-09 19:38:20 +04:00
|
|
|
case QUOTA_IDTYPE_USER:
|
2011-03-06 20:08:10 +03:00
|
|
|
pw = getpwuid(id);
|
|
|
|
if (pw)
|
|
|
|
name = pw->pw_name;
|
|
|
|
break;
|
|
|
|
default:
|
2015-06-17 02:04:13 +03:00
|
|
|
errx(1, "Unknown quota ID type %d", idtype);
|
2011-03-06 20:08:10 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
if (name)
|
|
|
|
len = strlen(name);
|
|
|
|
else
|
|
|
|
len = 10;
|
2011-03-07 01:33:55 +03:00
|
|
|
if ((fup = calloc(1, sizeof(*fup) + len)) == NULL)
|
|
|
|
err(1, "out of memory for fileusage structures");
|
2012-01-09 19:38:20 +04:00
|
|
|
fhp = &fuhead[idtype][id & (FUHASH - 1)];
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
fup->fu_next = *fhp;
|
|
|
|
*fhp = fup;
|
|
|
|
fup->fu_id = id;
|
2012-01-09 19:38:20 +04:00
|
|
|
if (id > highid[idtype])
|
|
|
|
highid[idtype] = id;
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
if (name) {
|
1997-10-18 15:23:55 +04:00
|
|
|
memmove(fup->fu_name, name, len + 1);
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
} else {
|
2011-03-07 02:25:42 +03:00
|
|
|
snprintf(fup->fu_name, len + 1, "%u", id);
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
}
|
2012-01-09 19:40:47 +04:00
|
|
|
/*
|
|
|
|
* XXX nothing guarantees the default limits have been loaded yet
|
|
|
|
*/
|
2012-01-25 05:24:53 +04:00
|
|
|
fup->fu_qv[QUOTA_OBJTYPE_BLOCKS] = defaultqv[idtype][QUOTA_OBJTYPE_BLOCKS];
|
|
|
|
fup->fu_qv[QUOTA_OBJTYPE_FILES] = defaultqv[idtype][QUOTA_OBJTYPE_FILES];
|
2011-03-07 01:33:55 +03:00
|
|
|
return fup;
|
added accton, edquota, flcopy, gettable, htable, iostat, quotaon,
repquota, trpt, and trsp, per (currently alpha) patch 125.
1993-04-09 16:15:37 +04:00
|
|
|
}
|
2012-01-09 19:42:37 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check to see if target appears in list of size cnt.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
oneof(const char *target, char *list[], int cnt)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < cnt; i++)
|
|
|
|
if (strcmp(target, list[i]) == 0)
|
|
|
|
return i;
|
|
|
|
return -1;
|
|
|
|
}
|
2012-02-01 21:48:10 +04:00
|
|
|
|
|
|
|
static int
|
|
|
|
isover(struct quotaval *qv, time_t now)
|
|
|
|
{
|
|
|
|
return (qv->qv_usage >= qv->qv_hardlimit ||
|
|
|
|
qv->qv_usage >= qv->qv_softlimit);
|
|
|
|
}
|