]> andersk Git - moira.git/blob - gen/setquota.c
added nickname field
[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.3  1988-10-06 10:46:08  raeburn
15  *      (mar) Don't expire timers on users currently over quota.
16  *
17  * Revision 1.1  87/09/04  21:32:47  wesommer
18  * Initial revision
19  * 
20  */
21
22 #ifndef lint
23 static char *rcsid_setquota_c = "$Header$";
24 #endif lint
25
26 #include <stdio.h>
27 #include <ctype.h>
28 #include <sys/param.h>
29 #include <sys/time.h>
30 #include <ufs/quota.h>
31
32 #define kb(n)   (howmany(dbtob(n), 1024))
33
34 main(argc, argv)
35         int argc;
36         char **argv;
37 {
38         char *device;
39         int uid;
40         struct dqblk db, odb;
41         int uflag = 0;
42         
43         while (argc > 4 && *argv[1] == '-') {
44                 switch(argv[1][1]) {
45                 case 'u':
46                         uflag = 1;
47                         --argc;
48                         ++argv;
49                         break;
50                 default:
51                         goto usage;
52                 }
53         }
54         
55         if (argc != 4) {
56         usage:
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");
61                 exit(1);
62         }
63
64         if (!isdigit(*argv[2]) || !isdigit(*argv[3])) {
65                 fprintf(stderr, "setquota: uid and quota must be numeric\n");
66                 goto usage;
67         }
68         
69         device = argv[1];
70         uid = atoi(argv[2]);
71         
72         if (quotactl(Q_GETQUOTA, device, uid, &odb) != 0) {
73             perror("Can't get current quota info");
74             exit(1);
75         }
76
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;
83
84         db.dqb_bsoftlimit *= btodb(1024);
85         db.dqb_bhardlimit *= btodb(1024);
86
87         if (uflag) {
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;
92         }
93         
94         if (quotactl(Q_SETQLIM, device, uid, &db) < 0) {
95                 fprintf (stderr, "quotactl: %d on ", uid);
96                 perror (device);
97                 exit (1);
98         }
99         if (quotactl(Q_SYNC, device, 0, 0) < 0) {
100                 perror ("can't sync disk quota");
101                 exit (1);
102         }
103         exit (0);
104 }
105         
This page took 0.136027 seconds and 5 git commands to generate.