* Copyright (c) 1980 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
"@(#) Copyright (c) 1980 Regents of the University of California.\n\
static char sccsid
[] = "@(#)edquota.c 5.9 (Berkeley) %G%";
struct dquot odq
[NMOUNT
];
char dqf
[NMOUNT
][MAXPATHLEN
+ 1];
char odqf
[NMOUNT
][MAXPATHLEN
+ 1];
char tmpfil
[] = _PATH_TMP
;
close(creat(tmpfil
, 0600));
chown(tmpfil
, getuid(), getgid());
fprintf(stderr
, "Usage: %s [-p username] username ...\n", arg0
);
fprintf(stderr
, "%s: permission denied\n", arg0
);
if (argc
> 2 && strcmp(*argv
, "-p") == 0) {
getdiscq(uid
, odq
, odqf
);
else if (pw
= getpwnam(name
))
fprintf(stderr
, "%s: no such user\n", name
);
omask
= sigblock(sigmask(SIGINT
)|sigmask(SIGQUIT
)|sigmask(SIGHUP
));
if ((pid
= fork()) < 0) {
fprintf(stderr
, "You have too many processes\n");
if ((ed
= getenv("EDITOR")) == (char *)0)
execlp(ed
, ed
, tmpfil
, 0);
while ((xpid
= wait(&stat
)) >= 0)
for (i
= 0; i
< NMOUNT
; i
++) {
if ((fd
= fopen(tmpfil
, "w")) == NULL
) {
fprintf(stderr
, "edquota: ");
for (i
= 0; i
< NMOUNT
; i
++) {
"fs %s blocks (soft = %d, hard = %d) inodes (soft = %d, hard = %d)\n"
, dbtob(dq
[i
].dq_bsoftlimit
) / 1024
, dbtob(dq
[i
].dq_bhardlimit
) / 1024
fprintf(stderr
, "Can't re-read temp file!!\n");
for (i
= 0; i
< NMOUNT
; i
++) {
if (fgets(line
, sizeof (line
), fd
) == NULL
)
while (*cp
&& *cp
== '\t' && *cp
== ' ')
dp
= cp
, cp
= next(cp
, " \t");
while (*cp
&& *cp
== '\t' && *cp
== ' ')
"blocks (soft = %d, hard = %d) inodes (soft = %hd, hard = %hd)\n"
fprintf(stderr
, "%s: bad format\n", cp
);
dq
[i
].dq_bsoftlimit
= btodb(dq
[i
].dq_bsoftlimit
* 1024);
dq
[i
].dq_bhardlimit
= btodb(dq
[i
].dq_bhardlimit
* 1024);
for (i
= 0; i
< n
; i
++) {
for (j
= 0; j
< NMOUNT
; j
++) {
if (strcmp(dqf
[i
], odqf
[j
]) == 0)
* This isn't really good enough, it is quite likely
* to have changed while we have been away editing,
* but it's not important enough to worry about at
dq
[i
].dq_curblocks
= odq
[j
].dq_curblocks
;
dq
[i
].dq_curinodes
= odq
[j
].dq_curinodes
;
* If we've upped the inode or disk block limits
* and the guy is out of warnings, reinitialize.
if (dq
[i
].dq_bsoftlimit
> odq
[j
].dq_bsoftlimit
&&
dq
[i
].dq_bwarn
= MAX_DQ_WARN
;
if (dq
[i
].dq_isoftlimit
> odq
[j
].dq_isoftlimit
&&
dq
[i
].dq_iwarn
= MAX_IQ_WARN
;
for (j
= 0; j
< NMOUNT
; j
++) {
* Same applies as just above
* but matters not at all, as we are just
* turning quota'ing off for this filesys.
dq
[i
].dq_curblocks
= odq
[j
].dq_curblocks
;
dq
[i
].dq_curinodes
= odq
[j
].dq_curinodes
;
for (dp
= match
; dp
&& *dp
; dp
++)
register struct dquot
*dq
;
register char (*dqf
)[MAXPATHLEN
+ 1];
register struct fstab
*fs
;
char qfilename
[MAXPATHLEN
+ 1];
while (fs
= getfsent()) {
if (stat(fs
->fs_spec
, &statb
) < 0)
sprintf(qfilename
, "%s/%s", fs
->fs_file
, qfname
);
if (stat(qfilename
, &statb
) < 0 || statb
.st_dev
!= fsdev
)
if (quota(Q_GETDLIM
, uid
, fsdev
, &dqblk
) != 0) {
if (errno
== EINVAL
&& !warned
) {
fprintf(stderr
, "Warning: %s\n",
"Quotas are not compiled into this kernel");
fd
= open(qfilename
, O_RDONLY
);
lseek(fd
, (long)(uid
* sizeof dqblk
), L_SET
);
switch (read(fd
, &dqblk
, sizeof dqblk
)) {
* Convert implicit 0 quota (EOF)
* into an explicit one (zero'ed dqblk)
bzero((caddr_t
)&dqblk
, sizeof dqblk
);
case sizeof dqblk
: /* OK */
fprintf(stderr
, "edquota: read error in ");
strcpy(*dqf
, fs
->fs_file
);
register struct dquot
*dq
;
register char (*dqf
)[MAXPATHLEN
+ 1];
for (cnt
= 0; ++cnt
<= NMOUNT
&& **dqf
; dq
++, dqf
++) {
fprintf(stderr
, "%s: not in fstab\n", *dqf
);
if (stat(*dqf
, &sb
) >= 0)
quota(Q_SETDLIM
, uid
, sb
.st_dev
, &dq
->dq_dqb
);
if ((fd
= open(*dqf
, 1)) < 0) {
lseek(fd
, (long)uid
* (long)sizeof (struct dqblk
), 0);
if (write(fd
, &dq
->dq_dqb
, sizeof (struct dqblk
)) !=
fprintf(stderr
, "edquota: ");