1 /* 2 * Copyright (c) 1982, 1986 Regents of the University of California. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Robert Elz at The University of Melbourne. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by the University of 19 * California, Berkeley and its contributors. 20 * 4. Neither the name of the University nor the names of its contributors 21 * may be used to endorse or promote products derived from this software 22 * without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 * 36 * Version: $Id: quota.h,v 1.8 1995/03/11 11:43:07 mvw Exp mvw $ 37 */ 38 39 #ifndef _LINUX_QUOTA_ 40 #define _LINUX_QUOTA_ 41 42 #include <linux/errno.h> 43 44 /* 45 * Convert diskblocks to blocks and the other way around. 46 * currently only to fool the BSD source. :-) 47 */ 48 #define dbtob(num) (num << 10) 49 #define btodb(num) (num >> 10) 50 51 /* 52 * Convert count of filesystem blocks to diskquota blocks, meant 53 * for filesystems where i_blksize != BLOCK_SIZE 54 */ 55 #define fs_to_dq_blocks(num, blksize) (((num) * (blksize)) / BLOCK_SIZE) 56 57 /* 58 * Definitions for disk quotas imposed on the average user 59 * (big brother finally hits Linux). 60 * 61 * The following constants define the amount of time given a user 62 * before the soft limits are treated as hard limits (usually resulting 63 * in an allocation failure). The timer is started when the user crosses 64 * their soft limit, it is reset when they go below their soft limit. 65 */ 66 #define MAX_IQ_TIME 604800 /* (7*24*60*60) 1 week */ 67 #define MAX_DQ_TIME 604800 /* (7*24*60*60) 1 week */ 68 69 #define MAXQUOTAS 2 70 #define USRQUOTA 0 /* element used for user quotas */ 71 #define GRPQUOTA 1 /* element used for group quotas */ 72 73 /* 74 * Definitions for the default names of the quotas files. 75 */ 76 #define INITQFNAMES { \ 77 "user", /* USRQUOTA */ \ 78 "group", /* GRPQUOTA */ \ 79 "undefined", \ 80 }; 81 82 #define QUOTAFILENAME "quota" 83 #define QUOTAGROUP "staff" 84 85 #define NR_DQHASH 43 /* Just an arbitrary number any suggestions ? */ 86 #define NR_DQUOTS 256 /* Number of quotas active at one time */ 87 88 /* 89 * Command definitions for the 'quotactl' system call. 90 * The commands are broken into a main command defined below 91 * and a subcommand that is used to convey the type of 92 * quota that is being manipulated (see above). 93 */ 94 #define SUBCMDMASK 0x00ff 95 #define SUBCMDSHIFT 8 96 #define QCMD(cmd, type) (((cmd) << SUBCMDSHIFT) | ((type) & SUBCMDMASK)) 97 98 #define Q_QUOTAON 0x0100 /* enable quotas */ 99 #define Q_QUOTAOFF 0x0200 /* disable quotas */ 100 #define Q_GETQUOTA 0x0300 /* get limits and usage */ 101 #define Q_SETQUOTA 0x0400 /* set limits and usage */ 102 #define Q_SETUSE 0x0500 /* set usage */ 103 #define Q_SYNC 0x0600 /* sync disk copy of a filesystems quotas */ 104 #define Q_SETQLIM 0x0700 /* set limits */ 105 #define Q_GETSTATS 0x0800 /* get collected stats */ 106 107 /* 108 * The following structure defines the format of the disk quota file 109 * (as it appears on disk) - the file is an array of these structures 110 * indexed by user or group number. 111 */ 112 struct dqblk { 113 __u32 dqb_bhardlimit; /* absolute limit on disk blks alloc */ 114 __u32 dqb_bsoftlimit; /* preferred limit on disk blks */ 115 __u32 dqb_curblocks; /* current block count */ 116 __u32 dqb_ihardlimit; /* maximum # allocated inodes */ 117 __u32 dqb_isoftlimit; /* preferred inode limit */ 118 __u32 dqb_curinodes; /* current # allocated inodes */ 119 time_t dqb_btime; /* time limit for excessive disk use */ 120 time_t dqb_itime; /* time limit for excessive files */ 121 }; 122 123 /* 124 * Shorthand notation. 125 */ 126 #define dq_bhardlimit dq_dqb.dqb_bhardlimit 127 #define dq_bsoftlimit dq_dqb.dqb_bsoftlimit 128 #define dq_curblocks dq_dqb.dqb_curblocks 129 #define dq_ihardlimit dq_dqb.dqb_ihardlimit 130 #define dq_isoftlimit dq_dqb.dqb_isoftlimit 131 #define dq_curinodes dq_dqb.dqb_curinodes 132 #define dq_btime dq_dqb.dqb_btime 133 #define dq_itime dq_dqb.dqb_itime 134 135 #define dqoff(UID) ((off_t)((UID) * sizeof (struct dqblk))) 136 137 struct dqstats { 138 __u32 lookups; 139 __u32 drops; 140 __u32 reads; 141 __u32 writes; 142 __u32 cache_hits; 143 __u32 pages_allocated; 144 __u32 allocated_dquots; 145 __u32 free_dquots; 146 __u32 syncs; 147 }; 148 149 #ifdef __KERNEL__ 150 151 #include <linux/mount.h> 152 153 /* 154 * Maximum length of a message generated in the quota system, 155 * that needs to be kicked onto the tty. 156 */ 157 #define MAX_QUOTA_MESSAGE 75 158 159 #define DQ_LOCKED 0x01 /* locked for update */ 160 #define DQ_WANT 0x02 /* wanted for update */ 161 #define DQ_MOD 0x04 /* dquot modified since read */ 162 #define DQ_BLKS 0x10 /* uid/gid has been warned about blk limit */ 163 #define DQ_INODES 0x20 /* uid/gid has been warned about inode limit */ 164 #define DQ_FAKE 0x40 /* no limits only usage */ 165 166 struct dquot { 167 unsigned int dq_id; /* id this applies to (uid, gid) */ 168 short dq_type; /* type of quota */ 169 kdev_t dq_dev; /* Device this applies to */ 170 short dq_flags; /* see DQ_* */ 171 short dq_count; /* reference count */ 172 struct vfsmount *dq_mnt; /* vfsmountpoint this applies to */ 173 struct dqblk dq_dqb; /* diskquota usage */ 174 struct wait_queue *dq_wait; /* pointer to waitqueue */ 175 struct dquot *dq_prev; /* pointer to prev dquot */ 176 struct dquot *dq_next; /* pointer to next dquot */ 177 struct dquot *dq_hash_prev; /* pointer to prev dquot */ 178 struct dquot *dq_hash_next; /* pointer to next dquot */ 179 }; 180 181 #define NODQUOT (struct dquot *)NULL 182 183 /* 184 * Flags used for set_dqblk. 185 */ 186 #define QUOTA_SYSCALL 0x01 187 #define SET_QUOTA 0x02 188 #define SET_USE 0x04 189 #define SET_QLIMIT 0x08 190 191 #define QUOTA_OK 0 192 #define NO_QUOTA 1 193 194 /* 195 * declaration of quota_function calls in kernel. 196 */ 197 198 extern void dquot_initialize(struct inode *inode, short type); 199 extern void dquot_drop(struct inode *inode); 200 extern int dquot_alloc_block(const struct inode *inode, unsigned long number); 201 extern int dquot_alloc_inode(const struct inode *inode, unsigned long number); 202 extern void dquot_free_block(const struct inode *inode, unsigned long number); 203 extern void dquot_free_inode(const struct inode *inode, unsigned long number); 204 extern int dquot_transfer(struct inode *inode, struct iattr *iattr, char direction); 205 206 extern void invalidate_dquots(kdev_t dev, short type); 207 extern int quota_off(kdev_t dev, short type); 208 extern int sync_dquots(kdev_t dev, short type); 209 210 #else 211 212 #include <sys/cdefs.h> 213 214 __BEGIN_DECLS 215 int quotactl __P ((int, const char *, int, caddr_t)); 216 __END_DECLS 217 218 #endif /* __KERNEL__ */ 219 #endif /* _QUOTA_ */