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.1.1.1 2008/10/15 03:29:27 james26_jang Exp $ 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 */ 47#define dbtob(num) (num << BLOCK_SIZE_BITS) 48#define btodb(num) (num >> BLOCK_SIZE_BITS) 49 50/* 51 * Convert count of filesystem blocks to diskquota blocks, meant 52 * for filesystems where i_blksize != BLOCK_SIZE 53 */ 54#define fs_to_dq_blocks(num, blksize) (((num) * (blksize)) / BLOCK_SIZE) 55 56/* 57 * Definitions for disk quotas imposed on the average user 58 * (big brother finally hits Linux). 59 * 60 * The following constants define the amount of time given a user 61 * before the soft limits are treated as hard limits (usually resulting 62 * in an allocation failure). The timer is started when the user crosses 63 * their soft limit, it is reset when they go below their soft limit. 64 */ 65#define MAX_IQ_TIME 604800 /* (7*24*60*60) 1 week */ 66#define MAX_DQ_TIME 604800 /* (7*24*60*60) 1 week */ 67 68#define MAXQUOTAS 2 69#define USRQUOTA 0 /* element used for user quotas */ 70#define GRPQUOTA 1 /* element used for group quotas */ 71 72/* 73 * Definitions for the default names of the quotas files. 74 */ 75#define INITQFNAMES { \ 76 "user", /* USRQUOTA */ \ 77 "group", /* GRPQUOTA */ \ 78 "undefined", \ 79}; 80 81#define QUOTAFILENAME "quota" 82#define QUOTAGROUP "staff" 83 84/* 85 * Command definitions for the 'quotactl' system call. 86 * The commands are broken into a main command defined below 87 * and a subcommand that is used to convey the type of 88 * quota that is being manipulated (see above). 89 */ 90#define SUBCMDMASK 0x00ff 91#define SUBCMDSHIFT 8 92#define QCMD(cmd, type) (((cmd) << SUBCMDSHIFT) | ((type) & SUBCMDMASK)) 93 94#define Q_QUOTAON 0x0100 /* enable quotas */ 95#define Q_QUOTAOFF 0x0200 /* disable quotas */ 96#define Q_GETQUOTA 0x0300 /* get limits and usage */ 97#define Q_SETQUOTA 0x0400 /* set limits and usage */ 98#define Q_SETUSE 0x0500 /* set usage */ 99#define Q_SYNC 0x0600 /* sync disk copy of a filesystems quotas */ 100#define Q_SETQLIM 0x0700 /* set limits */ 101#define Q_GETSTATS 0x0800 /* get collected stats */ 102#define Q_RSQUASH 0x1000 /* set root_squash option */ 103 104/* 105 * The following structure defines the format of the disk quota file 106 * (as it appears on disk) - the file is an array of these structures 107 * indexed by user or group number. 108 */ 109struct dqblk { 110 __u32 dqb_bhardlimit; /* absolute limit on disk blks alloc */ 111 __u32 dqb_bsoftlimit; /* preferred limit on disk blks */ 112 __u32 dqb_curblocks; /* current block count */ 113 __u32 dqb_ihardlimit; /* absolute limit on allocated inodes */ 114 __u32 dqb_isoftlimit; /* preferred inode limit */ 115 __u32 dqb_curinodes; /* current # allocated inodes */ 116 time_t dqb_btime; /* time limit for excessive disk use */ 117 time_t dqb_itime; /* time limit for excessive inode use */ 118}; 119 120/* 121 * Shorthand notation. 122 */ 123#define dq_bhardlimit dq_dqb.dqb_bhardlimit 124#define dq_bsoftlimit dq_dqb.dqb_bsoftlimit 125#define dq_curblocks dq_dqb.dqb_curblocks 126#define dq_ihardlimit dq_dqb.dqb_ihardlimit 127#define dq_isoftlimit dq_dqb.dqb_isoftlimit 128#define dq_curinodes dq_dqb.dqb_curinodes 129#define dq_btime dq_dqb.dqb_btime 130#define dq_itime dq_dqb.dqb_itime 131 132#define dqoff(UID) ((loff_t)((UID) * sizeof (struct dqblk))) 133 134struct dqstats { 135 __u32 lookups; 136 __u32 drops; 137 __u32 reads; 138 __u32 writes; 139 __u32 cache_hits; 140 __u32 allocated_dquots; 141 __u32 free_dquots; 142 __u32 syncs; 143}; 144 145#ifdef __KERNEL__ 146 147extern int nr_dquots, nr_free_dquots; 148extern int dquot_root_squash; 149 150#define NR_DQHASH 43 /* Just an arbitrary number */ 151 152#define DQ_LOCKED 0x01 /* dquot under IO */ 153#define DQ_MOD 0x02 /* dquot modified since read */ 154#define DQ_BLKS 0x10 /* uid/gid has been warned about blk limit */ 155#define DQ_INODES 0x20 /* uid/gid has been warned about inode limit */ 156#define DQ_FAKE 0x40 /* no limits only usage */ 157#define DQ_INVAL 0x80 /* dquot is going to be invalidated */ 158 159struct dquot { 160 struct list_head dq_hash; /* Hash list in memory */ 161 struct list_head dq_inuse; /* List of all quotas */ 162 struct list_head dq_free; /* Free list element */ 163 wait_queue_head_t dq_wait_lock; /* Pointer to waitqueue on dquot lock */ 164 wait_queue_head_t dq_wait_free; /* Pointer to waitqueue for quota to be unused */ 165 int dq_count; /* Reference count */ 166 167 /* fields after this point are cleared when invalidating */ 168 struct super_block *dq_sb; /* superblock this applies to */ 169 unsigned int dq_id; /* ID this applies to (uid, gid) */ 170 kdev_t dq_dev; /* Device this applies to */ 171 short dq_type; /* Type of quota */ 172 short dq_flags; /* See DQ_* */ 173 unsigned long dq_referenced; /* Number of times this dquot was 174 referenced during its lifetime */ 175 struct dqblk dq_dqb; /* Diskquota usage */ 176}; 177 178#define NODQUOT (struct dquot *)NULL 179 180/* 181 * Flags used for set_dqblk. 182 */ 183#define SET_QUOTA 0x02 184#define SET_USE 0x04 185#define SET_QLIMIT 0x08 186 187#define QUOTA_OK 0 188#define NO_QUOTA 1 189 190#else 191 192# /* nodep */ include <sys/cdefs.h> 193 194__BEGIN_DECLS 195long quotactl __P ((int, const char *, int, caddr_t)); 196__END_DECLS 197 198#endif /* __KERNEL__ */ 199#endif /* _QUOTA_ */ 200