]>
Commit | Line | Data |
---|---|---|
5dc7ec18 | 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$ | |
cd901bbd | 14 | * Revision 1.3 1988-10-06 10:46:08 raeburn |
15 | * (mar) Don't expire timers on users currently over quota. | |
5dc7ec18 | 16 | * |
95d08e4b | 17 | * Revision 1.1 87/09/04 21:32:47 wesommer |
18 | * Initial revision | |
19 | * | |
5dc7ec18 | 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; | |
95d08e4b | 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 | } | |
5dc7ec18 | 54 | |
55 | if (argc != 4) { | |
56 | usage: | |
95d08e4b | 57 | fprintf(stderr, "usage: setquota [-u] special uid quota\n\ |
58 | -u means set limit to <quota> + cur usage\n\ | |
5dc7ec18 | 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 | ||
cd901bbd | 72 | if (quotactl(Q_GETQUOTA, device, uid, &odb) != 0) { |
73 | perror("Can't get current quota info"); | |
74 | exit(1); | |
75 | } | |
76 | ||
5dc7ec18 | 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; | |
cd901bbd | 81 | db.dqb_btimelimit = odb.dqb_btimelimit; |
82 | db.dqb_ftimelimit = odb.dqb_ftimelimit; | |
5dc7ec18 | 83 | |
84 | db.dqb_bsoftlimit *= btodb(1024); | |
85 | db.dqb_bhardlimit *= btodb(1024); | |
86 | ||
95d08e4b | 87 | if (uflag) { |
95d08e4b | 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; | |
95d08e4b | 92 | } |
93 | ||
5dc7ec18 | 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 |