Add a new option to edquota(8) - "-f", which will

allow to limit the prototype quota distribution (-p)
to a single filesystem. Useful when initializing
quotas on a newly added disk.

PR:		bin/30816
Submitted by:	Dmitry Morozovsky <marck@rinet.ru>
This commit is contained in:
Yaroslav Tykhiy 2001-09-28 10:22:36 +00:00
parent b9b0e19206
commit bc9c1e902f
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=84081
2 changed files with 38 additions and 10 deletions

View File

@ -44,18 +44,22 @@
.Sh SYNOPSIS
.Nm
.Op Fl u
.Op Fl f Ar fspath
.Op Fl p Ar proto-username
.Ar username ...
.Nm
.Fl g
.Op Fl f Ar fspath
.Op Fl p Ar proto-groupname
.Ar groupname ...
.Nm
.Fl t
.Op Fl u
.Op Fl f Ar fspath
.Nm
.Fl t
.Fl g
.Op Fl f Ar fspath
.Sh DESCRIPTION
.Nm Edquota
is a quota editor.
@ -113,6 +117,22 @@ for easy setup of default quotas for a group of users.
The uids in question do not have to be currently assigned in
.Pa /etc/passwd .
.Pp
If invoked with the
.Fl f
option,
.Nm
will read and modify quotas on the filesystem specified by
.Ar fspath
only.
The
.Ar fspath
argument may be either a special device
or a filesystem mount point.
The primary purpose of this option is to set the scope for the
.Fl p
option, which would overwrite quota records on every
filesystem with quotas otherwise.
.Pp
If the
.Fl g
flag is specified,

View File

@ -89,7 +89,7 @@ char *cvtstoa __P((time_t));
int editit __P((char *));
void freeprivs __P((struct quotause *));
int getentry __P((char *, int));
struct quotause *getprivs __P((long, int));
struct quotause *getprivs __P((long, int, char *));
int hasquota __P((struct fstab *, int, char **));
void putprivs __P((long, int, struct quotause *));
int readprivs __P((struct quotause *, char *));
@ -109,6 +109,7 @@ main(argc, argv)
register uid_t startuid, enduid;
char *protoname, *cp, ch;
int tflag = 0, pflag = 0;
char *fspath = NULL;
char buf[30];
if (argc < 2)
@ -116,8 +117,11 @@ main(argc, argv)
if (getuid())
errx(1, "permission denied");
quotatype = USRQUOTA;
while ((ch = getopt(argc, argv, "ugtp:")) != -1) {
while ((ch = getopt(argc, argv, "ugtf:p:")) != -1) {
switch(ch) {
case 'f':
fspath = optarg;
break;
case 'p':
protoname = optarg;
pflag++;
@ -140,7 +144,7 @@ main(argc, argv)
if (pflag) {
if ((protoid = getentry(protoname, quotatype)) == -1)
exit(1);
protoprivs = getprivs(protoid, quotatype);
protoprivs = getprivs(protoid, quotatype, fspath);
for (qup = protoprivs; qup; qup = qup->next) {
qup->dqblk.dqb_btime = 0;
qup->dqblk.dqb_itime = 0;
@ -173,7 +177,7 @@ main(argc, argv)
tmpfd = mkstemp(tmpfil);
fchown(tmpfd, getuid(), getgid());
if (tflag) {
protoprivs = getprivs(0, quotatype);
protoprivs = getprivs(0, quotatype, fspath);
if (writetimes(protoprivs, tmpfd, quotatype) == 0)
exit(1);
if (editit(tmpfil) && readtimes(protoprivs, tmpfil))
@ -186,7 +190,7 @@ main(argc, argv)
for ( ; argc > 0; argc--, argv++) {
if ((id = getentry(*argv, quotatype)) == -1)
continue;
curprivs = getprivs(id, quotatype);
curprivs = getprivs(id, quotatype, fspath);
if (writeprivs(curprivs, tmpfd, *argv, quotatype) == 0)
continue;
if (editit(tmpfil) && readprivs(curprivs, tmpfil))
@ -202,10 +206,10 @@ static void
usage()
{
fprintf(stderr, "%s\n%s\n%s\n%s\n",
"usage: edquota [-u] [-p username] username ...",
" edquota -g [-p groupname] groupname ...",
" edquota [-u] -t",
" edquota -g -t");
"usage: edquota [-u] [-f fspath] [-p username] username ...",
" edquota -g [-f fspath] [-p groupname] groupname ...",
" edquota [-u] -t [-f fspath]",
" edquota -g -t [-f fspath]");
exit(1);
}
@ -247,9 +251,10 @@ getentry(name, quotatype)
* Collect the requested quota information.
*/
struct quotause *
getprivs(id, quotatype)
getprivs(id, quotatype, fspath)
register long id;
int quotatype;
char *fspath;
{
register struct fstab *fs;
register struct quotause *qup, *quptail;
@ -262,6 +267,9 @@ getprivs(id, quotatype)
quphead = (struct quotause *)0;
qcmd = QCMD(Q_GETQUOTA, quotatype);
while ((fs = getfsent())) {
if (fspath && *fspath && strcmp(fspath, fs->fs_spec) &&
strcmp(fspath, fs->fs_file))
continue;
if (strcmp(fs->fs_vfstype, "ufs"))
continue;
if (!hasquota(fs, quotatype, &qfpathname))