s4:torture/smb2: add smb2.notify.session-reconnect test
[Samba.git] / source3 / include / samba_linux_quota.h
blob8dbbec237f327bb8a9cc4eb5bb63bc82e88ecd0c
1 #ifndef _SAMBA_LINUX_QUOTA_H_
2 #define _SAMBA_LINUX_QUOTA_H_
3 /*
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 3 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, see <http://www.gnu.org/licenses/>.
22 This file is needed because Quota support on Linux has
23 been broken since Linus kernel 2.4.x. It will only get
24 better (and this file be removed) when all the distributions
25 ship a glibc with a working quota.h file. This is very
26 bad. JRA.
28 Original file came from Christoph Hellwig <hch@infradead.org>.
29 Massaged into one nasty include file (to stop us having to
30 add multiple files into Samba just for Linux braindamage)
31 by JRA.
34 #undef QUOTABLOCK_SIZE
36 #ifndef _QUOTAIO_LINUX_V1
37 #define _QUOTAIO_LINUX_V1
40 * Headerfile for old quotafile format
43 #include <sys/types.h>
45 #define V1_DQBLK_SIZE_BITS 10
46 #define V1_DQBLK_SIZE (1 << V1_DQBLK_SIZE_BITS) /* Size of one quota block in bytes in old format */
48 #define V1_DQOFF(__id) ((loff_t) ((__id) * sizeof(struct v1_disk_dqblk)))
50 /* Structure of quota on disk */
51 struct v1_disk_dqblk {
52 u_int32_t dqb_bhardlimit; /* absolute limit on disk blks alloc */
53 u_int32_t dqb_bsoftlimit; /* preferred limit on disk blks */
54 u_int32_t dqb_curblocks; /* current block count */
55 u_int32_t dqb_ihardlimit; /* maximum # allocated inodes */
56 u_int32_t dqb_isoftlimit; /* preferred limit on inodes */
57 u_int32_t dqb_curinodes; /* current # allocated inodes */
58 time_t dqb_btime; /* time limit for excessive disk use */
59 time_t dqb_itime; /* time limit for excessive files */
60 } __attribute__ ((packed));
62 /* Structure used for communication with kernel */
63 struct v1_kern_dqblk {
64 u_int32_t dqb_bhardlimit; /* absolute limit on disk blks alloc */
65 u_int32_t dqb_bsoftlimit; /* preferred limit on disk blks */
66 u_int32_t dqb_curblocks; /* current block count */
67 u_int32_t dqb_ihardlimit; /* maximum # allocated inodes */
68 u_int32_t dqb_isoftlimit; /* preferred inode limit */
69 u_int32_t dqb_curinodes; /* current # allocated inodes */
70 time_t dqb_btime; /* time limit for excessive disk use */
71 time_t dqb_itime; /* time limit for excessive files */
74 struct v1_dqstats {
75 u_int32_t lookups;
76 u_int32_t drops;
77 u_int32_t reads;
78 u_int32_t writes;
79 u_int32_t cache_hits;
80 u_int32_t allocated_dquots;
81 u_int32_t free_dquots;
82 u_int32_t syncs;
83 };
85 #ifndef Q_V1_GETQUOTA
86 #define Q_V1_GETQUOTA 0x300
87 #endif
88 #ifndef Q_V1_SETQUOTA
89 #define Q_V1_SETQUOTA 0x400
90 #endif
92 #endif /* _QUOTAIO_LINUX_V1 */
96 * Header file for disk format of new quotafile format
100 #ifndef _QUOTAIO_LINUX_V2
101 #define _QUOTAIO_LINUX_V2
103 #include <sys/types.h>
105 #ifndef _QUOTA_LINUX
106 #define _QUOTA_LINUX
108 #include <sys/types.h>
110 typedef u_int32_t qid_t; /* Type in which we store ids in memory */
111 typedef u_int64_t qsize_t; /* Type in which we store size limitations */
113 #define MAXQUOTAS 2
114 #define USRQUOTA 0 /* element used for user quotas */
115 #define GRPQUOTA 1 /* element used for group quotas */
118 * Definitions for the default names of the quotas files.
120 #define INITQFNAMES { \
121 "user", /* USRQUOTA */ \
122 "group", /* GRPQUOTA */ \
123 "undefined", \
127 * Definitions of magics and versions of current quota files
129 #define INITQMAGICS {\
130 0xd9c01f11, /* USRQUOTA */\
131 0xd9c01927 /* GRPQUOTA */\
134 /* Size of blocks in which are counted size limits in generic utility parts */
135 #define QUOTABLOCK_BITS 10
136 #define QUOTABLOCK_SIZE (1 << QUOTABLOCK_BITS)
138 /* Conversion routines from and to quota blocks */
139 #define qb2kb(x) ((x) << (QUOTABLOCK_BITS-10))
140 #define kb2qb(x) ((x) >> (QUOTABLOCK_BITS-10))
141 #define toqb(x) (((x) + QUOTABLOCK_SIZE - 1) >> QUOTABLOCK_BITS)
144 * Command definitions for the 'quotactl' system call.
145 * The commands are broken into a main command defined below
146 * and a subcommand that is used to convey the type of
147 * quota that is being manipulated (see above).
149 #define SUBCMDMASK 0x00ff
150 #define SUBCMDSHIFT 8
151 #define QCMD(cmd, type) (((cmd) << SUBCMDSHIFT) | ((type) & SUBCMDMASK))
153 #define Q_6_5_QUOTAON 0x0100 /* enable quotas */
154 #define Q_6_5_QUOTAOFF 0x0200 /* disable quotas */
155 #define Q_6_5_SYNC 0x0600 /* sync disk copy of a filesystems quotas */
157 #define Q_SYNC 0x800001 /* sync disk copy of a filesystems quotas */
158 #define Q_QUOTAON 0x800002 /* turn quotas on */
159 #define Q_QUOTAOFF 0x800003 /* turn quotas off */
160 #define Q_GETFMT 0x800004 /* get quota format used on given filesystem */
161 #define Q_GETINFO 0x800005 /* get information about quota files */
162 #define Q_SETINFO 0x800006 /* set information about quota files */
163 #define Q_GETQUOTA 0x800007 /* get user quota structure */
164 #define Q_SETQUOTA 0x800008 /* set user quota structure */
167 * Quota structure used for communication with userspace via quotactl
168 * Following flags are used to specify which fields are valid
170 #define QIF_BLIMITS 1
171 #define QIF_SPACE 2
172 #define QIF_ILIMITS 4
173 #define QIF_INODES 8
174 #define QIF_BTIME 16
175 #define QIF_ITIME 32
176 #define QIF_LIMITS (QIF_BLIMITS | QIF_ILIMITS)
177 #define QIF_USAGE (QIF_SPACE | QIF_INODES)
178 #define QIF_TIMES (QIF_BTIME | QIF_ITIME)
179 #define QIF_ALL (QIF_LIMITS | QIF_USAGE | QIF_TIMES)
181 struct if_dqblk {
182 u_int64_t dqb_bhardlimit;
183 u_int64_t dqb_bsoftlimit;
184 u_int64_t dqb_curspace;
185 u_int64_t dqb_ihardlimit;
186 u_int64_t dqb_isoftlimit;
187 u_int64_t dqb_curinodes;
188 u_int64_t dqb_btime;
189 u_int64_t dqb_itime;
190 u_int32_t dqb_valid;
194 * Structure used for setting quota information about file via quotactl
195 * Following flags are used to specify which fields are valid
197 #define IIF_BGRACE 1
198 #define IIF_IGRACE 2
199 #define IIF_FLAGS 4
200 #define IIF_ALL (IIF_BGRACE | IIF_IGRACE | IIF_FLAGS)
202 struct if_dqinfo {
203 u_int64_t dqi_bgrace;
204 u_int64_t dqi_igrace;
205 u_int32_t dqi_flags;
206 u_int32_t dqi_valid;
209 /* Quota format identifiers */
210 #define QFMT_VFS_OLD 1
211 #define QFMT_VFS_V0 2
213 /* Flags supported by kernel */
214 #define V1_DQF_RSQUASH 1
216 /* Ioctl for getting quota size */
217 #include <sys/ioctl.h>
218 #ifndef FIOQSIZE
219 #if defined(__alpha__) || defined(__powerpc__) || defined(__sh__) || defined(__sparc__) || defined(__sparc64__)
220 #define FIOQSIZE _IOR('f', 128, loff_t)
221 #elif defined(__arm__) || defined(__mc68000__) || defined(__s390__)
222 #define FIOQSIZE 0x545E
223 #elif defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__ia64__) || defined(__parisc__) || defined(__cris__) || defined(__hppa__)
224 #define FIOQSIZE 0x5460
225 #elif defined(__mips__) || defined(__mips64__)
226 #define FIOQSIZE 0x6667
227 #endif
228 #endif
230 long quotactl __P((int, const char *, qid_t, caddr_t));
232 #endif /* _QUOTA_LINUX */
234 #define V2_DQINFOOFF sizeof(struct v2_disk_dqheader) /* Offset of info header in file */
235 #define V2_DQBLKSIZE_BITS 10
236 #define V2_DQBLKSIZE (1 << V2_DQBLKSIZE_BITS) /* Size of block with quota structures */
237 #define V2_DQTREEOFF 1 /* Offset of tree in file in blOcks */
238 #define V2_DQTREEDEPTH 4 /* Depth of quota tree */
239 #define V2_DQSTRINBLK ((V2_DQBLKSIZE - sizeof(struct v2_disk_dqdbheader)) / sizeof(struct v2_disk_dqblk)) /* Number of entries in one blocks */
240 #define V2_GETIDINDEX(id, depth) (((id) >> ((V2_DQTREEDEPTH-(depth)-1)*8)) & 0xff)
241 #define V2_GETENTRIES(buf) ((struct v2_disk_dqblk *)(((char *)(buf)) + sizeof(struct v2_disk_dqdbheader)))
242 #define INIT_V2_VERSIONS { 0, 0}
244 struct v2_disk_dqheader {
245 u_int32_t dqh_magic; /* Magic number identifying file */
246 u_int32_t dqh_version; /* File version */
247 } __attribute__ ((packed));
249 /* Flags for version specific files */
250 #define V2_DQF_MASK 0x0000 /* Mask for all valid ondisk flags */
252 /* Header with type and version specific information */
253 struct v2_disk_dqinfo {
254 u_int32_t dqi_bgrace; /* Time before block soft limit becomes hard limit */
255 u_int32_t dqi_igrace; /* Time before inode soft limit becomes hard limit */
256 u_int32_t dqi_flags; /* Flags for quotafile (DQF_*) */
257 u_int32_t dqi_blocks; /* Number of blocks in file */
258 u_int32_t dqi_free_blk; /* Number of first free block in the list */
259 u_int32_t dqi_free_entry; /* Number of block with at least one free entry */
260 } __attribute__ ((packed));
263 * Structure of header of block with quota structures. It is padded to 16 bytes so
264 * there will be space for exactly 18 quota-entries in a block
266 struct v2_disk_dqdbheader {
267 u_int32_t dqdh_next_free; /* Number of next block with free entry */
268 u_int32_t dqdh_prev_free; /* Number of previous block with free entry */
269 u_int16_t dqdh_entries; /* Number of valid entries in block */
270 u_int16_t dqdh_pad1;
271 u_int32_t dqdh_pad2;
272 } __attribute__ ((packed));
274 /* Structure of quota for one user on disk */
275 struct v2_disk_dqblk {
276 u_int32_t dqb_id; /* id this quota applies to */
277 u_int32_t dqb_ihardlimit; /* absolute limit on allocated inodes */
278 u_int32_t dqb_isoftlimit; /* preferred inode limit */
279 u_int32_t dqb_curinodes; /* current # allocated inodes */
280 u_int32_t dqb_bhardlimit; /* absolute limit on disk space (in QUOTABLOCK_SIZE) */
281 u_int32_t dqb_bsoftlimit; /* preferred limit on disk space (in QUOTABLOCK_SIZE) */
282 u_int64_t dqb_curspace; /* current space occupied (in bytes) */
283 u_int64_t dqb_btime; /* time limit for excessive disk use */
284 u_int64_t dqb_itime; /* time limit for excessive inode use */
285 } __attribute__ ((packed));
287 /* Structure of quota for communication with kernel */
288 struct v2_kern_dqblk {
289 unsigned int dqb_ihardlimit;
290 unsigned int dqb_isoftlimit;
291 unsigned int dqb_curinodes;
292 unsigned int dqb_bhardlimit;
293 unsigned int dqb_bsoftlimit;
294 qsize_t dqb_curspace;
295 time_t dqb_btime;
296 time_t dqb_itime;
299 /* Structure of quotafile info for communication with kernel */
300 struct v2_kern_dqinfo {
301 unsigned int dqi_bgrace;
302 unsigned int dqi_igrace;
303 unsigned int dqi_flags;
304 unsigned int dqi_blocks;
305 unsigned int dqi_free_blk;
306 unsigned int dqi_free_entry;
309 /* Structure with gathered statistics from kernel */
310 struct v2_dqstats {
311 u_int32_t lookups;
312 u_int32_t drops;
313 u_int32_t reads;
314 u_int32_t writes;
315 u_int32_t cache_hits;
316 u_int32_t allocated_dquots;
317 u_int32_t free_dquots;
318 u_int32_t syncs;
319 u_int32_t version;
322 #ifndef Q_V2_GETQUOTA
323 #define Q_V2_GETQUOTA 0x0D00
324 #endif
325 #ifndef Q_V2_SETQUOTA
326 #define Q_V2_SETQUOTA 0x0E00
327 #endif
329 #endif /* _QUOTAIO_LINUX_V2 */
331 #ifndef QUOTABLOCK_SIZE
332 #define QUOTABLOCK_SIZE 1024
333 #endif
335 #endif /* _SAMBA_LINUX_QUOTA_H_ */