1 #ifndef _SAMBA_LINUX_QUOTA_H_
2 #define _SAMBA_LINUX_QUOTA_H_
4 Unix SMB/CIFS implementation.
5 Copyright (C) Andrew Tridgell 1994-2002
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 This file is needed because Quota support on Linux has
24 been broken since Linus kernel 2.4.x. It will only get
25 better (and this file be removed) when all the distributions
26 ship a glibc with a working quota.h file. This is very
29 Original file came from Christoph Hellwig <hch@infradead.org>.
30 Massaged into one nasty include file (to stop us having to
31 add multiple files into Samba just for Linux braindamage)
35 #undef QUOTABLOCK_SIZE
37 #ifndef _QUOTAIO_LINUX_V1
38 #define _QUOTAIO_LINUX_V1
41 * Headerfile for old quotafile format
44 #include <sys/types.h>
46 #define V1_DQBLK_SIZE_BITS 10
47 #define V1_DQBLK_SIZE (1 << V1_DQBLK_SIZE_BITS) /* Size of one quota block in bytes in old format */
49 #define V1_DQOFF(__id) ((loff_t) ((__id) * sizeof(struct v1_disk_dqblk)))
51 /* Structure of quota on disk */
52 struct v1_disk_dqblk
{
53 u_int32_t dqb_bhardlimit
; /* absolute limit on disk blks alloc */
54 u_int32_t dqb_bsoftlimit
; /* preferred limit on disk blks */
55 u_int32_t dqb_curblocks
; /* current block count */
56 u_int32_t dqb_ihardlimit
; /* maximum # allocated inodes */
57 u_int32_t dqb_isoftlimit
; /* preferred limit on inodes */
58 u_int32_t dqb_curinodes
; /* current # allocated inodes */
59 time_t dqb_btime
; /* time limit for excessive disk use */
60 time_t dqb_itime
; /* time limit for excessive files */
61 } __attribute__ ((packed
));
63 /* Structure used for communication with kernel */
64 struct v1_kern_dqblk
{
65 u_int32_t dqb_bhardlimit
; /* absolute limit on disk blks alloc */
66 u_int32_t dqb_bsoftlimit
; /* preferred limit on disk blks */
67 u_int32_t dqb_curblocks
; /* current block count */
68 u_int32_t dqb_ihardlimit
; /* maximum # allocated inodes */
69 u_int32_t dqb_isoftlimit
; /* preferred inode limit */
70 u_int32_t dqb_curinodes
; /* current # allocated inodes */
71 time_t dqb_btime
; /* time limit for excessive disk use */
72 time_t dqb_itime
; /* time limit for excessive files */
81 u_int32_t allocated_dquots
;
82 u_int32_t free_dquots
;
87 #define Q_V1_GETQUOTA 0x300
90 #define Q_V1_SETQUOTA 0x400
93 #endif /* _QUOTAIO_LINUX_V1 */
97 * Header file for disk format of new quotafile format
101 #ifndef _QUOTAIO_LINUX_V2
102 #define _QUOTAIO_LINUX_V2
104 #include <sys/types.h>
109 #include <sys/types.h>
111 typedef u_int32_t qid_t
; /* Type in which we store ids in memory */
112 typedef u_int64_t qsize_t
; /* Type in which we store size limitations */
115 #define USRQUOTA 0 /* element used for user quotas */
116 #define GRPQUOTA 1 /* element used for group quotas */
119 * Definitions for the default names of the quotas files.
121 #define INITQFNAMES { \
122 "user", /* USRQUOTA */ \
123 "group", /* GRPQUOTA */ \
128 * Definitions of magics and versions of current quota files
130 #define INITQMAGICS {\
131 0xd9c01f11, /* USRQUOTA */\
132 0xd9c01927 /* GRPQUOTA */\
135 /* Size of blocks in which are counted size limits in generic utility parts */
136 #define QUOTABLOCK_BITS 10
137 #define QUOTABLOCK_SIZE (1 << QUOTABLOCK_BITS)
139 /* Conversion routines from and to quota blocks */
140 #define qb2kb(x) ((x) << (QUOTABLOCK_BITS-10))
141 #define kb2qb(x) ((x) >> (QUOTABLOCK_BITS-10))
142 #define toqb(x) (((x) + QUOTABLOCK_SIZE - 1) >> QUOTABLOCK_BITS)
145 * Command definitions for the 'quotactl' system call.
146 * The commands are broken into a main command defined below
147 * and a subcommand that is used to convey the type of
148 * quota that is being manipulated (see above).
150 #define SUBCMDMASK 0x00ff
151 #define SUBCMDSHIFT 8
152 #define QCMD(cmd, type) (((cmd) << SUBCMDSHIFT) | ((type) & SUBCMDMASK))
154 #define Q_6_5_QUOTAON 0x0100 /* enable quotas */
155 #define Q_6_5_QUOTAOFF 0x0200 /* disable quotas */
156 #define Q_6_5_SYNC 0x0600 /* sync disk copy of a filesystems quotas */
158 #define Q_SYNC 0x800001 /* sync disk copy of a filesystems quotas */
159 #define Q_QUOTAON 0x800002 /* turn quotas on */
160 #define Q_QUOTAOFF 0x800003 /* turn quotas off */
161 #define Q_GETFMT 0x800004 /* get quota format used on given filesystem */
162 #define Q_GETINFO 0x800005 /* get information about quota files */
163 #define Q_SETINFO 0x800006 /* set information about quota files */
164 #define Q_GETQUOTA 0x800007 /* get user quota structure */
165 #define Q_SETQUOTA 0x800008 /* set user quota structure */
168 * Quota structure used for communication with userspace via quotactl
169 * Following flags are used to specify which fields are valid
171 #define QIF_BLIMITS 1
173 #define QIF_ILIMITS 4
177 #define QIF_LIMITS (QIF_BLIMITS | QIF_ILIMITS)
178 #define QIF_USAGE (QIF_SPACE | QIF_INODES)
179 #define QIF_TIMES (QIF_BTIME | QIF_ITIME)
180 #define QIF_ALL (QIF_LIMITS | QIF_USAGE | QIF_TIMES)
183 u_int64_t dqb_bhardlimit
;
184 u_int64_t dqb_bsoftlimit
;
185 u_int64_t dqb_curspace
;
186 u_int64_t dqb_ihardlimit
;
187 u_int64_t dqb_isoftlimit
;
188 u_int64_t dqb_curinodes
;
195 * Structure used for setting quota information about file via quotactl
196 * Following flags are used to specify which fields are valid
201 #define IIF_ALL (IIF_BGRACE | IIF_IGRACE | IIF_FLAGS)
204 u_int64_t dqi_bgrace
;
205 u_int64_t dqi_igrace
;
210 /* Quota format identifiers */
211 #define QFMT_VFS_OLD 1
212 #define QFMT_VFS_V0 2
214 /* Flags supported by kernel */
215 #define V1_DQF_RSQUASH 1
217 /* Ioctl for getting quota size */
218 #include <sys/ioctl.h>
220 #if defined(__alpha__) || defined(__powerpc__) || defined(__sh__) || defined(__sparc__) || defined(__sparc64__)
221 #define FIOQSIZE _IOR('f', 128, loff_t)
222 #elif defined(__arm__) || defined(__mc68000__) || defined(__s390__)
223 #define FIOQSIZE 0x545E
224 #elif defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__ia64__) || defined(__parisc__) || defined(__cris__) || defined(__hppa__)
225 #define FIOQSIZE 0x5460
226 #elif defined(__mips__) || defined(__mips64__)
227 #define FIOQSIZE 0x6667
231 long quotactl
__P((int, const char *, qid_t
, caddr_t
));
233 #endif /* _QUOTA_LINUX */
235 #define V2_DQINFOOFF sizeof(struct v2_disk_dqheader) /* Offset of info header in file */
236 #define V2_DQBLKSIZE_BITS 10
237 #define V2_DQBLKSIZE (1 << V2_DQBLKSIZE_BITS) /* Size of block with quota structures */
238 #define V2_DQTREEOFF 1 /* Offset of tree in file in blOcks */
239 #define V2_DQTREEDEPTH 4 /* Depth of quota tree */
240 #define V2_DQSTRINBLK ((V2_DQBLKSIZE - sizeof(struct v2_disk_dqdbheader)) / sizeof(struct v2_disk_dqblk)) /* Number of entries in one blocks */
241 #define V2_GETIDINDEX(id, depth) (((id) >> ((V2_DQTREEDEPTH-(depth)-1)*8)) & 0xff)
242 #define V2_GETENTRIES(buf) ((struct v2_disk_dqblk *)(((char *)(buf)) + sizeof(struct v2_disk_dqdbheader)))
243 #define INIT_V2_VERSIONS { 0, 0}
245 struct v2_disk_dqheader
{
246 u_int32_t dqh_magic
; /* Magic number identifying file */
247 u_int32_t dqh_version
; /* File version */
248 } __attribute__ ((packed
));
250 /* Flags for version specific files */
251 #define V2_DQF_MASK 0x0000 /* Mask for all valid ondisk flags */
253 /* Header with type and version specific information */
254 struct v2_disk_dqinfo
{
255 u_int32_t dqi_bgrace
; /* Time before block soft limit becomes hard limit */
256 u_int32_t dqi_igrace
; /* Time before inode soft limit becomes hard limit */
257 u_int32_t dqi_flags
; /* Flags for quotafile (DQF_*) */
258 u_int32_t dqi_blocks
; /* Number of blocks in file */
259 u_int32_t dqi_free_blk
; /* Number of first free block in the list */
260 u_int32_t dqi_free_entry
; /* Number of block with at least one free entry */
261 } __attribute__ ((packed
));
264 * Structure of header of block with quota structures. It is padded to 16 bytes so
265 * there will be space for exactly 18 quota-entries in a block
267 struct v2_disk_dqdbheader
{
268 u_int32_t dqdh_next_free
; /* Number of next block with free entry */
269 u_int32_t dqdh_prev_free
; /* Number of previous block with free entry */
270 u_int16_t dqdh_entries
; /* Number of valid entries in block */
273 } __attribute__ ((packed
));
275 /* Structure of quota for one user on disk */
276 struct v2_disk_dqblk
{
277 u_int32_t dqb_id
; /* id this quota applies to */
278 u_int32_t dqb_ihardlimit
; /* absolute limit on allocated inodes */
279 u_int32_t dqb_isoftlimit
; /* preferred inode limit */
280 u_int32_t dqb_curinodes
; /* current # allocated inodes */
281 u_int32_t dqb_bhardlimit
; /* absolute limit on disk space (in QUOTABLOCK_SIZE) */
282 u_int32_t dqb_bsoftlimit
; /* preferred limit on disk space (in QUOTABLOCK_SIZE) */
283 u_int64_t dqb_curspace
; /* current space occupied (in bytes) */
284 u_int64_t dqb_btime
; /* time limit for excessive disk use */
285 u_int64_t dqb_itime
; /* time limit for excessive inode use */
286 } __attribute__ ((packed
));
288 /* Structure of quota for communication with kernel */
289 struct v2_kern_dqblk
{
290 unsigned int dqb_ihardlimit
;
291 unsigned int dqb_isoftlimit
;
292 unsigned int dqb_curinodes
;
293 unsigned int dqb_bhardlimit
;
294 unsigned int dqb_bsoftlimit
;
295 qsize_t dqb_curspace
;
300 /* Structure of quotafile info for communication with kernel */
301 struct v2_kern_dqinfo
{
302 unsigned int dqi_bgrace
;
303 unsigned int dqi_igrace
;
304 unsigned int dqi_flags
;
305 unsigned int dqi_blocks
;
306 unsigned int dqi_free_blk
;
307 unsigned int dqi_free_entry
;
310 /* Structure with gathered statistics from kernel */
316 u_int32_t cache_hits
;
317 u_int32_t allocated_dquots
;
318 u_int32_t free_dquots
;
323 #ifndef Q_V2_GETQUOTA
324 #define Q_V2_GETQUOTA 0x0D00
326 #ifndef Q_V2_SETQUOTA
327 #define Q_V2_SETQUOTA 0x0E00
330 #endif /* _QUOTAIO_LINUX_V2 */
332 #ifndef QUOTABLOCK_SIZE
333 #define QUOTABLOCK_SIZE 1024
336 #endif /* _SAMBA_LINUX_QUOTA_H_ */