2012-01-09 19:38:20 +04:00
|
|
|
/* $NetBSD: repquota.c,v 1.34 2012/01/09 15:38:20 dholland 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
|
2012-01-09 19:38:20 +04:00
|
|
|
__RCSID("$NetBSD: repquota.c,v 1.34 2012/01/09 15:38:20 dholland 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
|
|
|
|
2011-03-24 20:05:39 +03:00
|
|
|
#include <quota/quota.h>
|
2011-03-06 20:08:10 +03:00
|
|
|
#include <ufs/ufs/quota1.h>
|
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"
|
|
|
|
#include "quotautil.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
|
|
|
|
|
|
|
struct fileusage {
|
|
|
|
struct fileusage *fu_next;
|
2011-11-25 20:55:05 +04:00
|
|
|
struct quotaval fu_qv[QUOTA_NLIMITS];
|
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 */
|
|
|
|
};
|
|
|
|
#define FUHASH 1024 /* must be power of two */
|
2011-03-24 20:05:39 +03:00
|
|
|
static struct fileusage *fuhead[QUOTA_NCLASS][FUHASH];
|
|
|
|
static uint32_t highid[QUOTA_NCLASS]; /* highest addid()'ed identifier per class */
|
|
|
|
int valid[QUOTA_NCLASS];
|
2011-11-25 20:55:05 +04:00
|
|
|
static struct quotaval defaultqv[QUOTA_NCLASS][QUOTA_NLIMITS];
|
2011-03-07 01:33:55 +03:00
|
|
|
|
|
|
|
static int vflag = 0; /* verbose */
|
|
|
|
static int aflag = 0; /* all file systems */
|
|
|
|
static int Dflag = 0; /* debug */
|
|
|
|
static int hflag = 0; /* humanize */
|
|
|
|
static int xflag = 0; /* export */
|
|
|
|
|
|
|
|
|
|
|
|
static struct fileusage *addid(uint32_t, int, const char *);
|
|
|
|
static struct fileusage *lookup(uint32_t, int);
|
|
|
|
static struct fileusage *qremove(uint32_t, int);
|
|
|
|
static int repquota(const struct statvfs *, int);
|
|
|
|
static int repquota2(const struct statvfs *, int);
|
|
|
|
static int repquota1(const struct statvfs *, int);
|
|
|
|
static void usage(void) __attribute__((__noreturn__));
|
|
|
|
static void printquotas(int, const struct statvfs *, int);
|
|
|
|
static void exportquotas(void);
|
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;
|
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
|
|
|
while ((ch = getopt(argc, argv, "Daguhvx")) != -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 'D':
|
|
|
|
Dflag++;
|
|
|
|
break;
|
|
|
|
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;
|
|
|
|
if (aflag) {
|
2011-03-06 20:08:10 +03:00
|
|
|
if (gflag)
|
2012-01-09 19:38:20 +04:00
|
|
|
errs += repquota(&fst[i], QUOTA_IDTYPE_GROUP);
|
2011-03-06 20:08:10 +03:00
|
|
|
if (uflag)
|
2012-01-09 19:38:20 +04:00
|
|
|
errs += repquota(&fst[i], QUOTA_IDTYPE_USER);
|
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;
|
|
|
|
}
|
2011-03-06 20:08:10 +03:00
|
|
|
if ((argnum = oneof(fst[i].f_mntonname, argv, argc)) >= 0 ||
|
|
|
|
(argnum = oneof(fst[i].f_mntfromname, argv, argc)) >= 0) {
|
2011-03-07 01:33:55 +03:00
|
|
|
done |= 1U << argnum;
|
2011-03-06 20:08:10 +03:00
|
|
|
if (gflag)
|
2012-01-09 19:38:20 +04:00
|
|
|
errs += repquota(&fst[i], QUOTA_IDTYPE_GROUP);
|
2011-03-06 20:08:10 +03:00
|
|
|
if (uflag)
|
2012-01-09 19:38:20 +04:00
|
|
|
errs += repquota(&fst[i], QUOTA_IDTYPE_USER);
|
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:20 +04:00
|
|
|
repquota(const struct statvfs *vfs, int idtype)
|
2011-03-06 20:08:10 +03:00
|
|
|
{
|
2012-01-09 19:38:20 +04:00
|
|
|
if (repquota2(vfs, idtype) != 0)
|
|
|
|
return repquota1(vfs, idtype);
|
2011-03-06 20:08:10 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-07 01:33:55 +03:00
|
|
|
static int
|
2012-01-09 19:38:20 +04:00
|
|
|
repquota2(const struct statvfs *vfs, int idtype)
|
2011-03-06 20:08:10 +03:00
|
|
|
{
|
|
|
|
prop_dictionary_t dict, data, cmd;
|
|
|
|
prop_array_t cmds, datas;
|
|
|
|
struct plistref pref;
|
|
|
|
int8_t error8, version = 0;
|
|
|
|
prop_object_iterator_t cmditer, dataiter;
|
2011-11-25 20:55:05 +04:00
|
|
|
struct quotaval *qvp;
|
2011-03-06 20:08:10 +03:00
|
|
|
struct fileusage *fup;
|
|
|
|
const char *strid;
|
|
|
|
uint32_t id;
|
2011-03-24 20:05:39 +03:00
|
|
|
uint64_t *values[QUOTA_NLIMITS];
|
2011-03-06 20:08:10 +03:00
|
|
|
|
2011-03-24 20:05:39 +03:00
|
|
|
dict = quota_prop_create();
|
2011-03-06 20:08:10 +03:00
|
|
|
cmds = prop_array_create();
|
|
|
|
datas = prop_array_create();
|
|
|
|
|
|
|
|
if (dict == NULL || cmds == NULL || datas == NULL)
|
|
|
|
errx(1, "can't allocate proplist");
|
2011-03-24 20:05:39 +03:00
|
|
|
if (!quota_prop_add_command(cmds, "getall",
|
2012-01-09 19:38:20 +04:00
|
|
|
ufs_quota_class_names[idtype], datas))
|
2011-03-06 20:08:10 +03:00
|
|
|
err(1, "prop_add_command");
|
2011-03-24 20:05:39 +03:00
|
|
|
if (!quota_prop_add_command(cmds, "get version",
|
2012-01-09 19:38:20 +04:00
|
|
|
ufs_quota_class_names[idtype], prop_array_create()))
|
2011-03-06 20:08:10 +03:00
|
|
|
err(1, "prop_add_command");
|
|
|
|
if (!prop_dictionary_set(dict, "commands", cmds))
|
|
|
|
err(1, "prop_dictionary_set(command)");
|
|
|
|
if (Dflag)
|
|
|
|
printf("message to kernel:\n%s\n",
|
|
|
|
prop_dictionary_externalize(dict));
|
2011-10-01 02:08:18 +04:00
|
|
|
if (prop_dictionary_send_syscall(dict, &pref) != 0)
|
2011-03-06 20:08:10 +03:00
|
|
|
err(1, "prop_dictionary_send_syscall");
|
|
|
|
prop_object_release(dict);
|
|
|
|
|
|
|
|
if (quotactl(vfs->f_mntonname, &pref) != 0)
|
|
|
|
err(1, "quotactl");
|
|
|
|
|
2011-10-01 02:08:18 +04:00
|
|
|
if (prop_dictionary_recv_syscall(&pref, &dict) != 0) {
|
2011-03-07 01:33:55 +03:00
|
|
|
err(1, "prop_dictionary_recv_syscall");
|
2011-03-06 20:08:10 +03:00
|
|
|
}
|
|
|
|
if (Dflag)
|
|
|
|
printf("reply from kernel:\n%s\n",
|
|
|
|
prop_dictionary_externalize(dict));
|
2011-03-24 20:05:39 +03:00
|
|
|
if ((errno = quota_get_cmds(dict, &cmds)) != 0) {
|
|
|
|
err(1, "quota_get_cmds");
|
2011-03-06 20:08:10 +03:00
|
|
|
}
|
|
|
|
cmditer = prop_array_iterator(cmds);
|
|
|
|
if (cmditer == NULL)
|
|
|
|
err(1, "prop_array_iterator(cmds)");
|
|
|
|
|
|
|
|
while ((cmd = prop_object_iterator_next(cmditer)) != NULL) {
|
|
|
|
const char *cmdstr;
|
|
|
|
if (!prop_dictionary_get_cstring_nocopy(cmd, "command",
|
|
|
|
&cmdstr))
|
|
|
|
err(1, "prop_get(command)");
|
|
|
|
|
|
|
|
if (!prop_dictionary_get_int8(cmd, "return", &error8))
|
|
|
|
err(1, "prop_get(return)");
|
|
|
|
|
|
|
|
if (error8) {
|
|
|
|
prop_object_release(dict);
|
|
|
|
if (error8 != EOPNOTSUPP) {
|
2011-03-07 01:33:55 +03:00
|
|
|
errno = error8;
|
2011-03-24 20:05:39 +03:00
|
|
|
warn("get %s quotas",
|
2012-01-09 19:38:20 +04:00
|
|
|
ufs_quota_class_names[idtype]);
|
2011-03-06 20:08:10 +03:00
|
|
|
}
|
2011-03-07 01:33:55 +03:00
|
|
|
return error8;
|
2011-03-06 20:08:10 +03:00
|
|
|
}
|
|
|
|
datas = prop_dictionary_get(cmd, "data");
|
|
|
|
if (datas == NULL)
|
|
|
|
err(1, "prop_dict_get(datas)");
|
|
|
|
|
|
|
|
if (strcmp("get version", cmdstr) == 0) {
|
|
|
|
data = prop_array_get(datas, 0);
|
|
|
|
if (data == NULL)
|
|
|
|
err(1, "prop_array_get(version)");
|
|
|
|
if (!prop_dictionary_get_int8(data, "version",
|
|
|
|
&version))
|
|
|
|
err(1, "prop_get_int8(version)");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
dataiter = prop_array_iterator(datas);
|
|
|
|
if (dataiter == NULL)
|
|
|
|
err(1, "prop_array_iterator");
|
|
|
|
|
2012-01-09 19:38:20 +04:00
|
|
|
valid[idtype] = 0;
|
2011-03-06 20:08:10 +03:00
|
|
|
while ((data = prop_object_iterator_next(dataiter)) != NULL) {
|
2012-01-09 19:38:20 +04:00
|
|
|
valid[idtype] = 1;
|
2011-03-06 20:08:10 +03:00
|
|
|
strid = NULL;
|
|
|
|
if (!prop_dictionary_get_uint32(data, "id", &id)) {
|
|
|
|
if (!prop_dictionary_get_cstring_nocopy(data,
|
|
|
|
"id", &strid))
|
|
|
|
errx(1, "can't find id in quota entry");
|
|
|
|
if (strcmp(strid, "default") != 0) {
|
|
|
|
errx(1,
|
|
|
|
"wrong id string %s in quota entry",
|
|
|
|
strid);
|
|
|
|
}
|
2012-01-09 19:38:20 +04:00
|
|
|
qvp = defaultqv[idtype];
|
2011-03-06 20:08:10 +03:00
|
|
|
} else {
|
2012-01-09 19:38:20 +04:00
|
|
|
if ((fup = lookup(id, idtype)) == 0)
|
|
|
|
fup = addid(id, idtype, (char *)0);
|
2011-11-25 20:55:05 +04:00
|
|
|
qvp = fup->fu_qv;
|
2011-03-06 20:08:10 +03:00
|
|
|
}
|
2011-03-24 20:05:39 +03:00
|
|
|
values[QUOTA_LIMIT_BLOCK] =
|
2011-11-25 20:55:05 +04:00
|
|
|
&qvp[QUOTA_LIMIT_BLOCK].qv_hardlimit;
|
2011-03-24 20:05:39 +03:00
|
|
|
values[QUOTA_LIMIT_FILE] =
|
2011-11-25 20:55:05 +04:00
|
|
|
&qvp[QUOTA_LIMIT_FILE].qv_hardlimit;
|
2011-03-06 20:08:10 +03:00
|
|
|
|
2011-03-24 20:05:39 +03:00
|
|
|
errno = proptoquota64(data, values,
|
|
|
|
ufs_quota_entry_names, UFS_QUOTA_NENTRIES,
|
|
|
|
ufs_quota_limit_names, QUOTA_NLIMITS);
|
2011-03-07 01:33:55 +03:00
|
|
|
if (errno)
|
2011-03-24 20:05:39 +03:00
|
|
|
err(1, "proptoquota64");
|
2011-03-06 20:08:10 +03:00
|
|
|
}
|
|
|
|
prop_object_iterator_release(dataiter);
|
|
|
|
}
|
|
|
|
prop_object_iterator_release(cmditer);
|
|
|
|
prop_object_release(dict);
|
2012-01-09 19:38:20 +04:00
|
|
|
if (xflag == 0 && valid[idtype])
|
|
|
|
printquotas(idtype, vfs, version);
|
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 int
|
2012-01-09 19:38:20 +04:00
|
|
|
repquota1(const struct statvfs *vfs, 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
|
|
|
{
|
2011-03-07 01:33:55 +03:00
|
|
|
char qfpathname[MAXPATHLEN];
|
2011-03-06 20:08:10 +03:00
|
|
|
struct fstab *fs;
|
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
|
|
|
FILE *qf;
|
2011-03-07 01:33:55 +03:00
|
|
|
uint32_t 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
|
|
|
struct dqblk dqbuf;
|
2011-03-06 20:08:10 +03:00
|
|
|
time_t bgrace = MAX_DQ_TIME, igrace = MAX_DQ_TIME;
|
2012-01-09 19:38:20 +04:00
|
|
|
int type = ufsclass2qtype(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
|
|
|
|
2011-03-06 20:08:10 +03:00
|
|
|
setfsent();
|
|
|
|
while ((fs = getfsent()) != NULL) {
|
|
|
|
if (strcmp(fs->fs_vfstype, "ffs") == 0 &&
|
|
|
|
strcmp(fs->fs_file, vfs->f_mntonname) == 0)
|
|
|
|
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
|
|
|
}
|
2011-03-06 20:08:10 +03:00
|
|
|
endfsent();
|
|
|
|
if (fs == NULL) {
|
2011-03-07 01:33:55 +03:00
|
|
|
warnx("%s not found in fstab", vfs->f_mntonname);
|
2011-03-06 20:08:10 +03:00
|
|
|
return 1;
|
|
|
|
}
|
2011-03-07 01:33:55 +03:00
|
|
|
if (!hasquota(qfpathname, sizeof(qfpathname), fs, type))
|
2011-03-06 20:08:10 +03:00
|
|
|
return 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
|
|
|
if ((qf = fopen(qfpathname, "r")) == NULL) {
|
2011-03-07 01:33:55 +03:00
|
|
|
warn("Cannot open `%s'", qfpathname);
|
|
|
|
return 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
|
|
|
}
|
|
|
|
for (id = 0; ; id++) {
|
|
|
|
fread(&dqbuf, sizeof(struct dqblk), 1, qf);
|
|
|
|
if (feof(qf))
|
|
|
|
break;
|
2011-03-06 20:08:10 +03:00
|
|
|
if (id == 0) {
|
|
|
|
if (dqbuf.dqb_btime > 0)
|
|
|
|
bgrace = dqbuf.dqb_btime;
|
|
|
|
if (dqbuf.dqb_itime > 0)
|
|
|
|
igrace = dqbuf.dqb_itime;
|
|
|
|
}
|
|
|
|
if (dqbuf.dqb_curinodes == 0 && dqbuf.dqb_curblocks == 0 &&
|
|
|
|
dqbuf.dqb_bsoftlimit == 0 && dqbuf.dqb_bhardlimit == 0 &&
|
|
|
|
dqbuf.dqb_isoftlimit == 0 && dqbuf.dqb_ihardlimit == 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:20 +04:00
|
|
|
if ((fup = lookup(id, idtype)) == 0)
|
|
|
|
fup = addid(id, idtype, (char *)0);
|
2011-11-25 20:55:05 +04:00
|
|
|
dqblk_to_quotaval(&dqbuf, fup->fu_qv);
|
|
|
|
fup->fu_qv[QUOTA_LIMIT_BLOCK].qv_grace = bgrace;
|
|
|
|
fup->fu_qv[QUOTA_LIMIT_FILE].qv_grace = igrace;
|
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
|
|
|
defaultqv[idtype][QUOTA_LIMIT_BLOCK].qv_grace = bgrace;
|
|
|
|
defaultqv[idtype][QUOTA_LIMIT_FILE].qv_grace = igrace;
|
|
|
|
defaultqv[idtype][QUOTA_LIMIT_BLOCK].qv_softlimit =
|
|
|
|
defaultqv[idtype][QUOTA_LIMIT_BLOCK].qv_hardlimit =
|
|
|
|
defaultqv[idtype][QUOTA_LIMIT_FILE].qv_softlimit =
|
|
|
|
defaultqv[idtype][QUOTA_LIMIT_FILE].qv_hardlimit = QUOTA_NOLIMIT;
|
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
|
|
|
fclose(qf);
|
2012-01-09 19:38:20 +04:00
|
|
|
valid[idtype] = 1;
|
2011-03-06 20:08:10 +03:00
|
|
|
if (xflag == 0)
|
2012-01-09 19:38:20 +04:00
|
|
|
printquotas(idtype, vfs, 1);
|
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:20 +04:00
|
|
|
printquotas(int idtype, const struct statvfs *vfs, int version)
|
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;
|
2011-03-24 20:05:39 +03:00
|
|
|
const char *timemsg[QUOTA_NLIMITS];
|
|
|
|
char overchar[QUOTA_NLIMITS];
|
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];
|
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)
|
2011-03-07 01:33:55 +03:00
|
|
|
printf("*** Report for %s quotas on %s (%s, version %d)\n",
|
2012-01-09 19:38:20 +04:00
|
|
|
ufs_quota_class_names[idtype], vfs->f_mntonname,
|
2011-03-24 20:05:39 +03:00
|
|
|
vfs->f_mntfromname, version);
|
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"
|
|
|
|
"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;
|
2011-03-24 20:05:39 +03:00
|
|
|
for (i = 0; i < QUOTA_NLIMITS; i++) {
|
2011-11-25 20:55:05 +04:00
|
|
|
switch (QL_STATUS(quota_check_limit(q[i].qv_usage, 1,
|
|
|
|
q[i].qv_softlimit, q[i].qv_hardlimit,
|
|
|
|
q[i].qv_expiretime, now))) {
|
2011-03-06 20:08:10 +03:00
|
|
|
case QL_S_DENY_HARD:
|
|
|
|
case QL_S_DENY_GRACE:
|
|
|
|
case QL_S_ALLOW_SOFT:
|
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] = '+';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
timemsg[i] = (vflag && version == 2) ?
|
2011-11-25 20:55:05 +04:00
|
|
|
timeprt(b0[i], 8, 0, q[i].qv_grace) : "";
|
2011-03-06 20:08:10 +03:00
|
|
|
overchar[i] = '-';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-25 20:55:05 +04:00
|
|
|
if (q[QUOTA_LIMIT_BLOCK].qv_usage == 0 &&
|
|
|
|
q[QUOTA_LIMIT_FILE].qv_usage == 0 && vflag == 0 &&
|
2011-03-24 20:05:39 +03:00
|
|
|
overchar[QUOTA_LIMIT_BLOCK] == '-' &&
|
|
|
|
overchar[QUOTA_LIMIT_FILE] == '-')
|
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);
|
2011-03-06 20:08:10 +03:00
|
|
|
printf("%c%c%9s%9s%9s%7s",
|
2011-03-24 20:05:39 +03:00
|
|
|
overchar[QUOTA_LIMIT_BLOCK], overchar[QUOTA_LIMIT_FILE],
|
2011-11-25 20:55:05 +04:00
|
|
|
intprt(b1, 10, q[QUOTA_LIMIT_BLOCK].qv_usage,
|
2011-03-24 20:05:39 +03:00
|
|
|
HN_B, hflag),
|
2011-11-25 20:55:05 +04:00
|
|
|
intprt(b2, 10, q[QUOTA_LIMIT_BLOCK].qv_softlimit,
|
2011-03-24 20:05:39 +03:00
|
|
|
HN_B, hflag),
|
2011-11-25 20:55:05 +04:00
|
|
|
intprt(b3, 10, q[QUOTA_LIMIT_BLOCK].qv_hardlimit,
|
2011-03-24 20:05:39 +03:00
|
|
|
HN_B, hflag),
|
|
|
|
timemsg[QUOTA_LIMIT_BLOCK]);
|
2011-03-06 20:08:10 +03:00
|
|
|
printf(" %8s%8s%8s%7s\n",
|
2011-11-25 20:55:05 +04:00
|
|
|
intprt(b1, 9, q[QUOTA_LIMIT_FILE].qv_usage, 0, hflag),
|
|
|
|
intprt(b2, 9, q[QUOTA_LIMIT_FILE].qv_softlimit,
|
2011-03-24 20:05:39 +03:00
|
|
|
0, hflag),
|
2011-11-25 20:55:05 +04:00
|
|
|
intprt(b3, 9, q[QUOTA_LIMIT_FILE].qv_hardlimit,
|
2011-03-24 20:05:39 +03:00
|
|
|
0, hflag),
|
|
|
|
timemsg[QUOTA_LIMIT_FILE]);
|
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
|
|
|
|
exportquotas(void)
|
2011-03-06 20:08:10 +03:00
|
|
|
{
|
2011-03-07 01:33:55 +03:00
|
|
|
uint32_t id;
|
2011-03-06 20:08:10 +03:00
|
|
|
struct fileusage *fup;
|
|
|
|
prop_dictionary_t dict, data;
|
|
|
|
prop_array_t cmds, datas;
|
2012-01-09 19:38:20 +04:00
|
|
|
int idtype;
|
2011-03-24 20:05:39 +03:00
|
|
|
uint64_t *valuesp[QUOTA_NLIMITS];
|
2011-03-06 20:08:10 +03:00
|
|
|
|
2011-03-24 20:05:39 +03:00
|
|
|
dict = quota_prop_create();
|
2011-03-06 20:08:10 +03:00
|
|
|
cmds = prop_array_create();
|
|
|
|
|
|
|
|
if (dict == NULL || cmds == NULL) {
|
|
|
|
errx(1, "can't allocate proplist");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-09 19:38:20 +04:00
|
|
|
for (idtype = 0; idtype < QUOTA_NCLASS; idtype++) {
|
|
|
|
if (valid[idtype] == 0)
|
2011-03-06 20:08:10 +03:00
|
|
|
continue;
|
|
|
|
datas = prop_array_create();
|
|
|
|
if (datas == NULL)
|
|
|
|
errx(1, "can't allocate proplist");
|
2011-03-24 20:05:39 +03:00
|
|
|
valuesp[QUOTA_LIMIT_BLOCK] =
|
2012-01-09 19:38:20 +04:00
|
|
|
&defaultqv[idtype][QUOTA_LIMIT_BLOCK].qv_hardlimit;
|
2011-03-24 20:05:39 +03:00
|
|
|
valuesp[QUOTA_LIMIT_FILE] =
|
2012-01-09 19:38:20 +04:00
|
|
|
&defaultqv[idtype][QUOTA_LIMIT_FILE].qv_hardlimit;
|
2011-03-24 20:05:39 +03:00
|
|
|
data = quota64toprop(0, 1, valuesp,
|
|
|
|
ufs_quota_entry_names, UFS_QUOTA_NENTRIES,
|
|
|
|
ufs_quota_limit_names, QUOTA_NLIMITS);
|
2011-03-06 20:08:10 +03:00
|
|
|
if (data == NULL)
|
2011-03-24 20:05:39 +03:00
|
|
|
err(1, "quota64toprop(default)");
|
2011-03-06 20:08:10 +03:00
|
|
|
if (!prop_array_add_and_rel(datas, data))
|
|
|
|
err(1, "prop_array_add(data)");
|
|
|
|
|
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;
|
2011-03-24 20:05:39 +03:00
|
|
|
valuesp[QUOTA_LIMIT_BLOCK] =
|
2011-11-25 20:55:05 +04:00
|
|
|
&fup->fu_qv[QUOTA_LIMIT_BLOCK].qv_hardlimit;
|
2011-03-24 20:05:39 +03:00
|
|
|
valuesp[QUOTA_LIMIT_FILE] =
|
2011-11-25 20:55:05 +04:00
|
|
|
&fup->fu_qv[QUOTA_LIMIT_FILE].qv_hardlimit;
|
2011-03-24 20:05:39 +03:00
|
|
|
data = quota64toprop(id, 0, valuesp,
|
|
|
|
ufs_quota_entry_names, UFS_QUOTA_NENTRIES,
|
|
|
|
ufs_quota_limit_names, QUOTA_NLIMITS);
|
2011-03-06 20:08:10 +03:00
|
|
|
if (data == NULL)
|
2011-03-24 20:05:39 +03:00
|
|
|
err(1, "quota64toprop(id)");
|
2011-03-06 20:08:10 +03:00
|
|
|
if (!prop_array_add_and_rel(datas, data))
|
|
|
|
err(1, "prop_array_add(data)");
|
|
|
|
free(fup);
|
|
|
|
}
|
|
|
|
|
2011-03-24 20:05:39 +03:00
|
|
|
if (!quota_prop_add_command(cmds, "set",
|
2012-01-09 19:38:20 +04:00
|
|
|
ufs_quota_class_names[idtype], datas))
|
2011-03-06 20:08:10 +03:00
|
|
|
err(1, "prop_add_command");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!prop_dictionary_set(dict, "commands", cmds))
|
|
|
|
err(1, "prop_dictionary_set(command)");
|
|
|
|
|
|
|
|
printf("%s\n", prop_dictionary_externalize(dict));
|
|
|
|
return;
|
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:
|
2012-01-09 19:38:20 +04:00
|
|
|
errx(1, "Unknown quota ID type %d\n", 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:38:20 +04:00
|
|
|
fup->fu_qv[QUOTA_LIMIT_BLOCK] = defaultqv[idtype][QUOTA_LIMIT_BLOCK];
|
|
|
|
fup->fu_qv[QUOTA_LIMIT_FILE] = defaultqv[idtype][QUOTA_LIMIT_FILE];
|
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
|
|
|
}
|