1 /* 2 * Copyright (c) 1982, 1986 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that this notice is preserved and that due credit is given 7 * to the University of California at Berkeley. The name of the University 8 * may not be used to endorse or promote products derived from this 9 * software without specific prior written permission. This software 10 * is provided ``as is'' without express or implied warranty. 11 * 12 * @(#)quota.h 7.2 (Berkeley) 05/20/88 13 */ 14 15 /* 16 * MELBOURNE DISC QUOTAS 17 * 18 * Various junk to do with various quotas (etc) imposed upon 19 * the average user (big brother finally hits UNIX). 20 * 21 * The following structure exists in core for each logged on user. 22 * It contains global junk relevant to that user's quotas. 23 * 24 * The u_quota field of each user struct contains a pointer to 25 * the quota struct relevant to the current process, this is changed 26 * by 'setuid' sys call, &/or by the Q_SETUID quota() call. 27 */ 28 struct quota { 29 struct quota *q_forw, *q_back; /* hash chain, MUST be first */ 30 short q_cnt; /* ref count (# processes) */ 31 uid_t q_uid; /* real uid of owner */ 32 int q_flags; /* struct management flags */ 33 #define Q_LOCK 0x01 /* quota struct locked (for disc i/o) */ 34 #define Q_WANT 0x02 /* issue a wakeup when lock goes off */ 35 #define Q_NEW 0x04 /* new quota - no proc1 msg sent yet */ 36 #define Q_NDQ 0x08 /* account has NO disc quota */ 37 struct quota *q_freef, **q_freeb; 38 struct dquot *q_dq[NMOUNT]; /* disc quotas for mounted filesys's */ 39 }; 40 41 #define NOQUOTA ((struct quota *) 0) 42 43 #if defined(KERNEL) && defined(QUOTA) 44 struct quota *quota, *quotaNQUOTA; 45 int nquota; 46 struct quota *getquota(), *qfind(); 47 #endif 48 49 /* 50 * The following structure defines the format of the disc quota file 51 * (as it appears on disc) - the file is an array of these structures 52 * indexed by user number. The setquota sys call establishes the inode 53 * for each quota file (a pointer is retained in the mount structure). 54 * 55 * The following constants define the number of warnings given a user 56 * before the soft limits are treated as hard limits (usually resulting 57 * in an allocation failure). The warnings are normally manipulated 58 * each time a user logs in through the Q_DOWARN quota call. If 59 * the user logs in and is under the soft limit the warning count 60 * is reset to MAX_*_WARN, otherwise a message is printed and the 61 * warning count is decremented. This makes MAX_*_WARN equivalent to 62 * the number of logins before soft limits are treated as hard limits. 63 */ 64 #define MAX_IQ_WARN 3 65 #define MAX_DQ_WARN 3 66 67 struct dqblk { 68 u_long dqb_bhardlimit; /* absolute limit on disc blks alloc */ 69 u_long dqb_bsoftlimit; /* preferred limit on disc blks */ 70 u_long dqb_curblocks; /* current block count */ 71 u_short dqb_ihardlimit; /* maximum # allocated inodes + 1 */ 72 u_short dqb_isoftlimit; /* preferred inode limit */ 73 u_short dqb_curinodes; /* current # allocated inodes */ 74 u_char dqb_bwarn; /* # warnings left about excessive disc use */ 75 u_char dqb_iwarn; /* # warnings left about excessive inodes */ 76 }; 77 78 /* 79 * The following structure records disc usage for a user on a filesystem. 80 * There is one allocated for each quota that exists on any filesystem 81 * for the current user. A cache is kept of other recently used entries. 82 */ 83 struct dquot { 84 struct dquot *dq_forw, *dq_back;/* MUST be first entry */ 85 union { 86 struct quota *Dq_own; /* the quota that points to this */ 87 struct { /* free list */ 88 struct dquot *Dq_freef, **Dq_freeb; 89 } dq_f; 90 } dq_u; 91 short dq_flags; 92 #define DQ_LOCK 0x01 /* this quota locked (no MODS) */ 93 #define DQ_WANT 0x02 /* wakeup on unlock */ 94 #define DQ_MOD 0x04 /* this quota modified since read */ 95 #define DQ_FAKE 0x08 /* no limits here, just usage */ 96 #define DQ_BLKS 0x10 /* has been warned about blk limit */ 97 #define DQ_INODS 0x20 /* has been warned about inode limit */ 98 short dq_cnt; /* count of active references */ 99 uid_t dq_uid; /* user this applies to */ 100 dev_t dq_dev; /* filesystem this relates to */ 101 struct dqblk dq_dqb; /* actual usage & quotas */ 102 }; 103 104 #define dq_own dq_u.Dq_own 105 #define dq_freef dq_u.dq_f.Dq_freef 106 #define dq_freeb dq_u.dq_f.Dq_freeb 107 #define dq_bhardlimit dq_dqb.dqb_bhardlimit 108 #define dq_bsoftlimit dq_dqb.dqb_bsoftlimit 109 #define dq_curblocks dq_dqb.dqb_curblocks 110 #define dq_ihardlimit dq_dqb.dqb_ihardlimit 111 #define dq_isoftlimit dq_dqb.dqb_isoftlimit 112 #define dq_curinodes dq_dqb.dqb_curinodes 113 #define dq_bwarn dq_dqb.dqb_bwarn 114 #define dq_iwarn dq_dqb.dqb_iwarn 115 116 #define NODQUOT ((struct dquot *) 0) 117 #define LOSTDQUOT ((struct dquot *) 1) 118 119 #if defined(KERNEL) && defined(QUOTA) 120 struct dquot *dquot, *dquotNDQUOT; 121 int ndquot; 122 struct dquot *discquota(), *inoquota(), *dqalloc(), *dqp(); 123 #endif 124 125 /* 126 * Definitions for the 'quota' system call. 127 */ 128 #define Q_SETDLIM 1 /* set disc limits & usage */ 129 #define Q_GETDLIM 2 /* get disc limits & usage */ 130 #define Q_SETDUSE 3 /* set disc usage only */ 131 #define Q_SYNC 4 /* update disc copy of quota usages */ 132 #define Q_SETUID 16 /* change proc to use quotas for uid */ 133 #define Q_SETWARN 25 /* alter inode/block warning counts */ 134 #define Q_DOWARN 26 /* warn user about excessive space/inodes */ 135 136 /* 137 * Used in Q_SETDUSE. 138 */ 139 struct dqusage { 140 u_short du_curinodes; 141 u_long du_curblocks; 142 }; 143 144 /* 145 * Used in Q_SETWARN. 146 */ 147 struct dqwarn { 148 u_char dw_bwarn; 149 u_char dw_iwarn; 150 }; 151