]> andersk Git - moira.git/blob - gen/setquota.c
b39794776ffa9a8d14f721da713b907704480072
[moira.git] / gen / setquota.c
1 /*
2  *      $Source$
3  *      $Author$
4  *      $Header$
5  *
6  *      Copyright (C) 1987 by the Massachusetts Institute of Technology
7  *
8  *      Set quota on specified device for specified user to specified value.
9  *
10  *      Uses the NFS style quota system/quotactl rather than the Melbourne
11  * quota system.
12  *      
13  *      $Log$
14  *      Revision 1.2  1988-10-06 10:41:55  raeburn
15  *      (wesommer?) implemented -u flag to update quota values with increment
16  *      from current.
17  *
18  * Revision 1.1  87/09/04  21:32:47  wesommer
19  * Initial revision
20  * 
21  */
22
23 #ifndef lint
24 static char *rcsid_setquota_c = "$Header$";
25 #endif lint
26
27 #include <stdio.h>
28 #include <ctype.h>
29 #include <sys/param.h>
30 #include <sys/time.h>
31 #include <ufs/quota.h>
32
33 #define kb(n)   (howmany(dbtob(n), 1024))
34
35 main(argc, argv)
36         int argc;
37         char **argv;
38 {
39         char *device;
40         int uid;
41         struct dqblk db, odb;
42         int uflag = 0;
43         
44         while (argc > 4 && *argv[1] == '-') {
45                 switch(argv[1][1]) {
46                 case 'u':
47                         uflag = 1;
48                         --argc;
49                         ++argv;
50                         break;
51                 default:
52                         goto usage;
53                 }
54         }
55         
56         if (argc != 4) {
57         usage:
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");
62                 exit(1);
63         }
64
65         if (!isdigit(*argv[2]) || !isdigit(*argv[3])) {
66                 fprintf(stderr, "setquota: uid and quota must be numeric\n");
67                 goto usage;
68         }
69         
70         device = argv[1];
71         uid = atoi(argv[2]);
72         
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;
79
80         db.dqb_bsoftlimit *= btodb(1024);
81         db.dqb_bhardlimit *= btodb(1024);
82
83         if (uflag) {
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;
89                 }
90         }
91         
92         if (quotactl(Q_SETQLIM, device, uid, &db) < 0) {
93                 fprintf (stderr, "quotactl: %d on ", uid);
94                 perror (device);
95                 exit (1);
96         }
97         if (quotactl(Q_SYNC, device, 0, 0) < 0) {
98                 perror ("can't sync disk quota");
99                 exit (1);
100         }
101         exit (0);
102 }
103         
This page took 0.061543 seconds and 3 git commands to generate.