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.2 1988-10-06 10:41:55 raeburn
15 * (wesommer?) implemented -u flag to update quota values with increment
18 * Revision 1.1 87/09/04 21:32:47 wesommer
24 static char *rcsid_setquota_c = "$Header$";
29 #include <sys/param.h>
31 #include <ufs/quota.h>
33 #define kb(n) (howmany(dbtob(n), 1024))
44 while (argc > 4 && *argv[1] == '-') {
58 fprintf(stderr, "usage: setquota [-u] special uid quota\n\
59 -u means set limit to <quota> + cur usage\n\
60 special is a mounted filesystem special device\n\
61 quota is in 1KB units\n");
65 if (!isdigit(*argv[2]) || !isdigit(*argv[3])) {
66 fprintf(stderr, "setquota: uid and quota must be numeric\n");
73 db.dqb_bsoftlimit = atoi(argv[3]);
74 db.dqb_bhardlimit = db.dqb_bsoftlimit * 1.2;
75 db.dqb_fsoftlimit = atoi(argv[3]) * .5;
76 db.dqb_fhardlimit = db.dqb_fsoftlimit * 1.2;
77 db.dqb_btimelimit = DQ_FTIMELIMIT;
78 db.dqb_btimelimit = DQ_BTIMELIMIT;
80 db.dqb_bsoftlimit *= btodb(1024);
81 db.dqb_bhardlimit *= btodb(1024);
84 if (quotactl(Q_GETQUOTA, device, uid, &odb) == 0) {
85 db.dqb_bhardlimit += odb.dqb_curblocks;
86 db.dqb_bsoftlimit += odb.dqb_curblocks;
87 db.dqb_fhardlimit += odb.dqb_curfiles;
88 db.dqb_fsoftlimit += odb.dqb_curfiles;
92 if (quotactl(Q_SETQLIM, device, uid, &db) < 0) {
93 fprintf (stderr, "quotactl: %d on ", uid);
97 if (quotactl(Q_SYNC, device, 0, 0) < 0) {
98 perror ("can't sync disk quota");