6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
8 * Set quota on specified device for specified user to specified value.
10 * Uses the NFS style quota system/quotactl rather than the Melbourne
14 * Revision 1.3 1988-10-06 10:46:08 raeburn
15 * (mar) Don't expire timers on users currently over quota.
17 * Revision 1.1 87/09/04 21:32:47 wesommer
23 static char *rcsid_setquota_c = "$Header$";
28 #include <sys/param.h>
30 #include <ufs/quota.h>
32 #define kb(n) (howmany(dbtob(n), 1024))
43 while (argc > 4 && *argv[1] == '-') {
57 fprintf(stderr, "usage: setquota [-u] special uid quota\n\
58 -u means set limit to <quota> + cur usage\n\
59 special is a mounted filesystem special device\n\
60 quota is in 1KB units\n");
64 if (!isdigit(*argv[2]) || !isdigit(*argv[3])) {
65 fprintf(stderr, "setquota: uid and quota must be numeric\n");
72 if (quotactl(Q_GETQUOTA, device, uid, &odb) != 0) {
73 perror("Can't get current quota info");
77 db.dqb_bsoftlimit = atoi(argv[3]);
78 db.dqb_bhardlimit = db.dqb_bsoftlimit * 1.2;
79 db.dqb_fsoftlimit = atoi(argv[3]) * .5;
80 db.dqb_fhardlimit = db.dqb_fsoftlimit * 1.2;
81 db.dqb_btimelimit = odb.dqb_btimelimit;
82 db.dqb_ftimelimit = odb.dqb_ftimelimit;
84 db.dqb_bsoftlimit *= btodb(1024);
85 db.dqb_bhardlimit *= btodb(1024);
88 db.dqb_bhardlimit += odb.dqb_curblocks;
89 db.dqb_bsoftlimit += odb.dqb_curblocks;
90 db.dqb_fhardlimit += odb.dqb_curfiles;
91 db.dqb_fsoftlimit += odb.dqb_curfiles;
94 if (quotactl(Q_SETQLIM, device, uid, &db) < 0) {
95 fprintf (stderr, "quotactl: %d on ", uid);
99 if (quotactl(Q_SYNC, device, 0, 0) < 0) {
100 perror ("can't sync disk quota");