1 /* quota.h Melb 4.2 82/10/20 */ 2 3 #ifdef QUOTA 4 /* 5 * Various junk to do with various quotas (etc) imposed upon 6 * the average user (big brother finally hits unix) 7 * 8 * The following structure exists in core for each logged on user 9 * It contains global junk relevant to that user's quotas 10 * 11 * The u_quota field of each user struct contains a pointer to 12 * the quota struct relevant to the current process, this is changed 13 * by 'setuid' sys call, &/or by the Q_SETUID quota() call 14 */ 15 16 typedef long class_t; 17 18 struct quinfo { 19 u_short qu_shares; /* allocated shares (MUSH) */ 20 short qu_plim; /* process limit */ 21 long qu_syflags; /* system permission flags */ 22 float qu_usage; /* current resource usage (MUSH) */ 23 class_t qu_class; /* user classes (MUSH) */ 24 }; 25 26 #ifdef KERNEL 27 struct quota { 28 struct quota *q_forw; /* hash chain - MUST be first */ 29 struct quota *q_back; /* hash chain - MUST be last */ 30 char q_flg; /* struct management flags */ 31 char q_lcnt; /* count of logins for user */ 32 short q_cnt; /* ref count (# processes) */ 33 short q_uid; /* real uid of owner */ 34 short q_nice; /* nice added to p_cpu (MUSH) */ 35 short q_acnt; /* count of 'at' processes (MUSH) */ 36 union { 37 struct { 38 long Q_rate; /* recent work rate (MUSH) */ 39 long Q_cost; /* cost in recent period (MUSH) */ 40 } q_s1; 41 struct { 42 struct quota *Q_freef; 43 struct quota **Q_freeb; 44 } q_s2; 45 } q_u; 46 struct quinfo q_uinfo; /* user limits & usage (MUSH) */ 47 struct dquot *q_dq[NMOUNT]; /* disc quotas for mounted filesys's */ 48 }; 49 #define NOQUOT ((struct quota *) 0) 50 #define q_rate q_u.q_s1.Q_rate 51 #define q_cost q_u.q_s1.Q_cost 52 #define q_freef q_u.q_s2.Q_freef 53 #define q_freeb q_u.q_s2.Q_freeb 54 #define q_shares q_uinfo.qu_shares 55 #define q_plim q_uinfo.qu_plim 56 #define q_syflags q_uinfo.qu_syflags 57 #define q_usage q_uinfo.qu_usage 58 #define q_class q_uinfo.qu_class 59 #endif 60 61 #define QF_KASYNC 0x02 /* kill async procs at logout */ 62 #define QF_FASTTY 0x04 /* permitted to raise tty speed */ 63 #define QF_NASYNC 0x08 /* nice async procs at logout */ 64 #define QF_MODTTY 0x10 /* permitted to modify other tty */ 65 #define QF_UMASK 0x20 /* not permitted to alter umask */ 66 67 #ifdef KERNEL 68 struct quota *quota, *quotaNQUOTA; 69 int nquota; 70 struct quota *getquota(), *qfind(); 71 #endif 72 73 /* q_flg flags */ 74 #define Q_LOCK 0x01 /* quota struct locked (for disc i/o) */ 75 #define Q_WANT 0x02 /* issue a wakeup when lock goes off */ 76 #define Q_NEW 0x04 /* new quota - no proc1 msg sent yet */ 77 #define Q_NDQ 0x08 /* account has NO disc quota */ 78 79 /* 80 * The following structure defines the format of the disc quota file 81 * (as it appears on disc) - the file is an array of these structures 82 * indexed by user number. A sys call (setquota) establishes the 83 * inode for each applicable file (a pointer is retained in the mount 84 * structure) 85 * 86 * nb: warning fields contain the number of warnings left before 87 * allocation is halted completely 88 */ 89 90 typedef unsigned short dlim_t; 91 92 struct dqblk { 93 dlim_t dqb_ilim; /* max num allocated inodes + 1 */ 94 dlim_t dqb_iq; /* preferred inode limit */ 95 dlim_t dqb_inod; /* current num allocated inodes */ 96 dlim_t dqb_iwarn; /* # warnings about excessive inodes */ 97 dlim_t dqb_blim; /* abs limit on disc blks alloc */ 98 dlim_t dqb_quot; /* preferred limit on disc blks */ 99 dlim_t dqb_blks; /* current block count */ 100 dlim_t dqb_dwarn; /* # warnings about excessive disc use */ 101 }; 102 #define MAX_IQ_WARN 3 103 #define MAX_DQ_WARN 3 104 105 /* 106 * The following structure records disc usage for a user on a filesystem 107 * There is one allocated for each quota that exists on any filesystem 108 * for the current user. A cache is kept of other recently used entries. 109 */ 110 111 struct dquot { 112 struct dquot *dq_forw; /* MUST be first entry */ 113 struct dquot *dq_back; /* MUST be second entry */ 114 union { 115 struct quota *Dq_own; /* the quota that points to this */ 116 struct { 117 struct dquot *Dq_freef; /* forward free chain ptr */ 118 struct dquot **Dq_freeb;/* backward free chain ptr */ 119 } dq_f; 120 } dq_u; 121 short dq_flg; 122 short dq_cnt; /* count of active references */ 123 short dq_uid; /* user this applies to */ 124 dev_t dq_dev; /* filesystem this relates to */ 125 struct dqblk dq_dqb; /* actual usage & quotas */ 126 }; 127 #define dq_own dq_u.Dq_own 128 #define dq_freef dq_u.dq_f.Dq_freef 129 #define dq_freeb dq_u.dq_f.Dq_freeb 130 #define dq_ilim dq_dqb.dqb_ilim 131 #define dq_iq dq_dqb.dqb_iq 132 #define dq_inod dq_dqb.dqb_inod 133 #define dq_iwarn dq_dqb.dqb_iwarn 134 #define dq_blim dq_dqb.dqb_blim 135 #define dq_quot dq_dqb.dqb_quot 136 #define dq_blks dq_dqb.dqb_blks 137 #define dq_dwarn dq_dqb.dqb_dwarn 138 #define NODQUOT ((struct dquot *) 0) 139 #define LOSTDQUOT ((struct dquot *) 1) 140 141 #ifdef KERNEL 142 struct dquot *dquot, *dquotNDQUOT; 143 int ndquot; 144 struct dquot *discquota(), *inoquota(), *dqalloc(); 145 #endif 146 147 /* dq_flg flags */ 148 #define DQ_LOCK 0x01 /* this quota locked (no MODS) */ 149 #define DQ_WANT 0x02 /* wakeup on unlock */ 150 #define DQ_MOD 0x04 /* this quota modified since read */ 151 #define DQ_FAKE 0x08 /* no limits here, just usage */ 152 #define DQ_BLKS 0x10 /* has been warned about blk limit */ 153 #define DQ_INODS 0x20 /* has been warned about inode limit */ 154 155 /* 156 * Commands for the 'quota' system call 157 */ 158 #define Q_SETDLIM 1 /* set disc limits & usage */ 159 #define Q_GETDLIM 2 /* get disc limits & usage */ 160 #define Q_SETDUSE 3 /* set disc usage only */ 161 #define Q_SYNC 4 /* update disc copy if quota usages */ 162 #define Q_LOGIN 5 /* Count this as a login process */ 163 #define Q_LCOUNT 6 /* get count of login processes */ 164 #define Q_PCOUNT 7 /* get count of processes */ 165 #define Q_USAGE 8 /* get current usage */ 166 #define Q_SFLAGS 9 /* set system flags */ 167 #define Q_SUSAGE 10 /* set usage */ 168 #define Q_SPLIMIT 11 /* set process limit */ 169 #define Q_ISLOGIN 12 /* is this a login process ?? */ 170 #define Q_SCLASS 13 /* set user class */ 171 #define Q_SCURCL 14 /* set current system classes */ 172 #define Q_GCURCL 15 /* get current system classes */ 173 #define Q_SETUID 16 /* change proc to use quotas for uid */ 174 #define Q_FLOGIN 17 /* "fake" login (counts as 1, but isn't) */ 175 #define Q_SETCOST 18 /* set system charge rates */ 176 #define Q_GETCOST 19 /* get system charge rates */ 177 #define Q_SSHARE 20 /* set shares */ 178 #define Q_SUINFO 21 /* set user info */ 179 #define Q_GUINFO 22 /* get user info */ 180 #define Q_ATJOB 23 /* this process is an 'at' job (background) */ 181 #define Q_ACOUNT 24 /* return count of procs descended from ATJ */ 182 #define Q_SETWARN 25 /* alter inode/block warning counts */ 183 #define Q_DOWARN 26 /* warn user about excessive space/inodes */ 184 #define Q_KILL 27 /* send signal to procs attatched to quota */ 185 #define Q_NICE 28 /* set niceness for procs attatched to quota */ 186 187 /* 188 * current class information 189 * 190 * records sched biasing for classes that are to have priority 191 * enhanced or degraded 192 */ 193 194 #define NCLASS 8 195 196 struct qclass { 197 class_t class; /* classes this applies to */ 198 long cost; /* +/- mod to cost incurred */ 199 short maxn; /* in this class, no nice > this */ 200 short minn; /* in this class, no nice < this */ 201 }; 202 203 #ifdef KERNEL 204 struct qclass curclass[NCLASS]; 205 #endif 206 207 /* 208 * Flag definitions for u_qflags in user struct (u_qflags) 209 */ 210 #define QUF_LOGIN 0x0001 /* this process incremented login cnt */ 211 #define QUF_ATJ 0x0002 /* this process descended from atrun */ 212 213 #endif QUOTA 214