Hi Jacques,
Jacques Gelinas wrote:
> There is no command line in linuxconf to deal with quota. This is planned
> though.
Thanks for the reply. I was able to get the utility I had written
working, eventually (a bad interpretation of the quotactl() man page
was at fault :-).
In case anyone has any use for a commandline utility to set a users
block quota until linuxconf supports this, the source is below. It's
pretty basic; it sets the hard & soft limit to be the same, though
it would be trivial to extend to have seperate soft & hard limits.
Because this is intended to be used from scripts (at least, that
was my reason for writing it), it returns no output if it is
successful. The syntax is:
quotautil <uid> <quota in blocks> <device>
This utility was written on RH Linux 5.1; I'm not sure how
portable it is. It works for me, but YMMV.
Regards,
Nick Silberstein
---------%<---Cut here--------------------------------
/*
* This tool is (c) 1998 under the GNU GPL.
* No warranty whatsoever, use at your own risk, etc.
* Nick Silberstein <[EMAIL PROTECTED]>
*
* Compile with gcc -o quotoautil quotautil.c
* then cp to /usr/sbin & chown root:root /usr/sbin/quotautil
*
* Please send me any improvements you may come up with or
* tell me if you find it useful.
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/quota.h>
#include <errno.h>
#include <assert.h>
void checkErrors(int uid, char *device);
int main(int argc, char *argv[])
{
int uid, quotasize;
struct dqblk quota;
if (argc != 4)
{
assert (argv[0] != NULL);
fprintf(stderr, "Usage: %s <user id> <quota size> <block special "\
"device>\n", argv[0]);
exit(1);
}
uid = atoi(argv[1]);
quotasize = atoi(argv[2]);
if (uid <= 0 || quotasize <= 0 || argv[3] == NULL || strlen(argv[3])
== 0)
{
fprintf(stderr, "Usage: %s <user id> <quota size> <block special "\
"device>\nBoth user id and quota size must be integers "\
"greater than 0.\n ", argv[0]);
exit(1);
}
quota.dqb_bhardlimit = quotasize;
quota.dqb_bsoftlimit = quotasize;
quota.dqb_curblocks = 0;
quota.dqb_ihardlimit = 0;
quota.dqb_isoftlimit = 0;
quota.dqb_curinodes = 0;
quota.dqb_btime = 0;
quota.dqb_itime = 0;
if(quotactl(QCMD(Q_SETQLIM, USRQUOTA), argv[3], uid, (caddr_t)"a)
== -1)
checkErrors(uid, argv[3]);
return 0;
}
void checkErrors(int uid, char *device) {
switch (errno) {
case EFAULT:
fprintf(stderr, "Block special device or internal quota struct "\
"invalid.\n");
exit(1);
case EINVAL:
fprintf(stderr, "Kernel not compiled with QUOTA option.\n");
exit(1);
case ENOENT:
fprintf(stderr, "Block special device or part of internal quota "\
"struct does not exist.\n");
exit(1);
case ENOTBLK:
fprintf(stderr, "%s is not a block device.\n", device);
exit(1);
case EPERM:
fprintf(stderr, "You must be root to run this.\n");
exit(1);
case ESRCH:
fprintf(stderr, "No disc quota found for user %d.\n", uid);
exit(1);
case EUSERS:
fprintf(stderr, "Quota table is full.\n");
exit(1);
default:
fprintf(stderr, "UNKNOWN ERROR.\n");
exit(1);
}
}
------------------->%--------Cut here-----------------
--
Nick Silberstein | Fluent Communications
Webmaster of Yendor� | Seattle, WA, USA
This e-mail is copylefted under the GNU Public License!
Enjoy :-)
---
You are currently subscribed to linuxconf as: [[email protected]]
To unsubscribe, forward this message to [EMAIL PROTECTED]