1QUOTACTL(2) Linux Programmer's Manual QUOTACTL(2)
2
3
4
6 quotactl - manipulate disk quotas
7
9 #include <sys/quota.h>
10 #include <xfs/xqm.h> /* for XFS quotas */
11
12 int quotactl(int cmd, const char *special, int id, caddr_t addr);
13
15 The quota system can be used to set per-user, per-group, and per-
16 project limits on the amount of disk space used on a filesystem. For
17 each user and/or group, a soft limit and a hard limit can be set for
18 each filesystem. The hard limit can't be exceeded. The soft limit can
19 be exceeded, but warnings will ensue. Moreover, the user can't exceed
20 the soft limit for more than grace period duration (one week by
21 default) at a time; after this, the soft limit counts as a hard limit.
22
23 The quotactl() call manipulates disk quotas. The cmd argument indi‐
24 cates a command to be applied to the user or group ID specified in id.
25 To initialize the cmd argument, use the QCMD(subcmd, type) macro. The
26 type value is either USRQUOTA, for user quotas, GRPQUOTA, for group
27 quotas, or (since Linux 4.1) PRJQUOTA, for project quotas. The subcmd
28 value is described below.
29
30 The special argument is a pointer to a null-terminated string contain‐
31 ing the pathname of the (mounted) block special device for the filesys‐
32 tem being manipulated.
33
34 The addr argument is the address of an optional, command-specific, data
35 structure that is copied in or out of the system. The interpretation
36 of addr is given with each operation below.
37
38 The subcmd value is one of the following operations:
39
40 Q_QUOTAON
41 Turn on quotas for a filesystem. The id argument is the iden‐
42 tification number of the quota format to be used. Currently,
43 there are three supported quota formats:
44
45 QFMT_VFS_OLD The original quota format.
46
47 QFMT_VFS_V0 The standard VFS v0 quota format, which can handle
48 32-bit UIDs and GIDs and quota limits up to 2^42
49 bytes and 2^32 inodes.
50
51 QFMT_VFS_V1 A quota format that can handle 32-bit UIDs and
52 GIDs and quota limits of 2^64 bytes and 2^64
53 inodes.
54
55 The addr argument points to the pathname of a file containing
56 the quotas for the filesystem. The quota file must exist; it
57 is normally created with the quotacheck(8) program
58
59 Quota information can be also stored in hidden system inodes
60 for ext4, XFS, and other filesystems if the filesystem is con‐
61 figured so. In this case, there are no visible quota files and
62 there is no need to use quotacheck(8). Quota information is
63 always kept consistent by the filesystem and the Q_QUOTAON
64 operation serves only to enable enforcement of quota limits.
65 The presence of hidden system inodes with quota information is
66 indicated by the DQF_SYS_FILE flag in the dqi_flags field
67 returned by the Q_GETINFO operation.
68
69 This operation requires privilege (CAP_SYS_ADMIN).
70
71 Q_QUOTAOFF
72 Turn off quotas for a filesystem. The addr and id arguments
73 are ignored. This operation requires privilege
74 (CAP_SYS_ADMIN).
75
76 Q_GETQUOTA
77 Get disk quota limits and current usage for user or group id.
78 The addr argument is a pointer to a dqblk structure defined in
79 <sys/quota.h> as follows:
80
81 /* uint64_t is an unsigned 64-bit integer;
82 uint32_t is an unsigned 32-bit integer */
83
84 struct dqblk { /* Definition since Linux 2.4.22 */
85 uint64_t dqb_bhardlimit; /* Absolute limit on disk
86 quota blocks alloc */
87 uint64_t dqb_bsoftlimit; /* Preferred limit on
88 disk quota blocks */
89 uint64_t dqb_curspace; /* Current occupied space
90 (in bytes) */
91 uint64_t dqb_ihardlimit; /* Maximum number of
92 allocated inodes */
93 uint64_t dqb_isoftlimit; /* Preferred inode limit */
94 uint64_t dqb_curinodes; /* Current number of
95 allocated inodes */
96 uint64_t dqb_btime; /* Time limit for excessive
97 disk use */
98 uint64_t dqb_itime; /* Time limit for excessive
99 files */
100 uint32_t dqb_valid; /* Bit mask of QIF_*
101 constants */
102 };
103
104 /* Flags in dqb_valid that indicate which fields in
105 dqblk structure are valid. */
106
107 #define QIF_BLIMITS 1
108 #define QIF_SPACE 2
109 #define QIF_ILIMITS 4
110 #define QIF_INODES 8
111 #define QIF_BTIME 16
112 #define QIF_ITIME 32
113 #define QIF_LIMITS (QIF_BLIMITS | QIF_ILIMITS)
114 #define QIF_USAGE (QIF_SPACE | QIF_INODES)
115 #define QIF_TIMES (QIF_BTIME | QIF_ITIME)
116 #define QIF_ALL (QIF_LIMITS | QIF_USAGE | QIF_TIMES)
117
118 The dqb_valid field is a bit mask that is set to indicate the
119 entries in the dqblk structure that are valid. Currently, the
120 kernel fills in all entries of the dqblk structure and marks
121 them as valid in the dqb_valid field. Unprivileged users may
122 retrieve only their own quotas; a privileged user
123 (CAP_SYS_ADMIN) can retrieve the quotas of any user.
124
125 Q_GETNEXTQUOTA (since Linux 4.6)
126 This operation is the same as Q_GETQUOTA, but it returns quota
127 information for the next ID greater than or equal to id that
128 has a quota set.
129
130 The addr argument is a pointer to a nextdqblk structure whose
131 fields are as for the dqblk, except for the addition of a
132 dqb_id field that is used to return the ID for which quota
133 information is being returned:
134
135 struct nextdqblk {
136 uint64_t dqb_bhardlimit;
137 uint64_t dqb_bsoftlimit;
138 uint64_t dqb_curspace;
139 uint64_t dqb_ihardlimit;
140 uint64_t dqb_isoftlimit;
141 uint64_t dqb_curinodes;
142 uint64_t dqb_btime;
143 uint64_t dqb_itime;
144 uint32_t dqb_valid;
145 uint32_t dqb_id;
146 };
147
148 Q_SETQUOTA
149 Set quota information for user or group id, using the informa‐
150 tion supplied in the dqblk structure pointed to by addr. The
151 dqb_valid field of the dqblk structure indicates which entries
152 in the structure have been set by the caller. This operation
153 supersedes the Q_SETQLIM and Q_SETUSE operations in the previ‐
154 ous quota interfaces. This operation requires privilege
155 (CAP_SYS_ADMIN).
156
157 Q_GETINFO (since Linux 2.4.22)
158 Get information (like grace times) about quotafile. The addr
159 argument should be a pointer to a dqinfo structure. This
160 structure is defined in <sys/quota.h> as follows:
161
162 /* uint64_t is an unsigned 64-bit integer;
163 uint32_t is an unsigned 32-bit integer */
164
165 struct dqinfo { /* Defined since kernel 2.4.22 */
166 uint64_t dqi_bgrace; /* Time before block soft limit
167 becomes hard limit */
168 uint64_t dqi_igrace; /* Time before inode soft limit
169 becomes hard limit */
170 uint32_t dqi_flags; /* Flags for quotafile
171 (DQF_*) */
172 uint32_t dqi_valid;
173 };
174
175 /* Bits for dqi_flags */
176
177 /* Quota format QFMT_VFS_OLD */
178
179 #define DQF_ROOT_SQUASH (1 << 0) /* Root squash enabled */
180 /* Before Linux v4.0, this had been defined
181 privately as V1_DQF_RSQUASH */
182
183 /* Quota format QFMT_VFS_V0 / QFMT_VFS_V1 */
184
185 #define DQF_SYS_FILE (1 << 16) /* Quota stored in
186 a system file */
187
188 /* Flags in dqi_valid that indicate which fields in
189 dqinfo structure are valid. */
190
191 #define IIF_BGRACE 1
192 #define IIF_IGRACE 2
193 #define IIF_FLAGS 4
194 #define IIF_ALL (IIF_BGRACE | IIF_IGRACE | IIF_FLAGS)
195
196 The dqi_valid field in the dqinfo structure indicates the
197 entries in the structure that are valid. Currently, the kernel
198 fills in all entries of the dqinfo structure and marks them all
199 as valid in the dqi_valid field. The id argument is ignored.
200
201 Q_SETINFO (since Linux 2.4.22)
202 Set information about quotafile. The addr argument should be a
203 pointer to a dqinfo structure. The dqi_valid field of the
204 dqinfo structure indicates the entries in the structure that
205 have been set by the caller. This operation supersedes the
206 Q_SETGRACE and Q_SETFLAGS operations in the previous quota
207 interfaces. The id argument is ignored. This operation
208 requires privilege (CAP_SYS_ADMIN).
209
210 Q_GETFMT (since Linux 2.4.22)
211 Get quota format used on the specified filesystem. The addr
212 argument should be a pointer to a 4-byte buffer where the for‐
213 mat number will be stored.
214
215 Q_SYNC Update the on-disk copy of quota usages for a filesystem. If
216 special is NULL, then all filesystems with active quotas are
217 sync'ed. The addr and id arguments are ignored.
218
219 Q_GETSTATS (supported up to Linux 2.4.21)
220 Get statistics and other generic information about the quota
221 subsystem. The addr argument should be a pointer to a dqstats
222 structure in which data should be stored. This structure is
223 defined in <sys/quota.h>. The special and id arguments are
224 ignored.
225
226 This operation is obsolete and was removed in Linux 2.4.22.
227 Files in /proc/sys/fs/quota/ carry the information instead.
228
229 For XFS filesystems making use of the XFS Quota Manager (XQM), the
230 above operations are bypassed and the following operations are used:
231
232 Q_XQUOTAON
233 Turn on quotas for an XFS filesystem. XFS provides the ability
234 to turn on/off quota limit enforcement with quota accounting.
235 Therefore, XFS expects addr to be a pointer to an unsigned int
236 that contains a combination of the following flags (defined in
237 <xfs/xqm.h>):
238
239 #define XFS_QUOTA_UDQ_ACCT (1<<0) /* User quota
240 accounting */
241 #define XFS_QUOTA_UDQ_ENFD (1<<1) /* User quota limits
242 enforcement */
243 #define XFS_QUOTA_GDQ_ACCT (1<<2) /* Group quota
244 accounting */
245 #define XFS_QUOTA_GDQ_ENFD (1<<3) /* Group quota limits
246 enforcement */
247 #define XFS_QUOTA_PDQ_ACCT (1<<4) /* Project quota
248 accounting */
249 #define XFS_QUOTA_PDQ_ENFD (1<<5) /* Project quota limits
250 enforcement */
251
252 This operation requires privilege (CAP_SYS_ADMIN). The id
253 argument is ignored.
254
255 Q_XQUOTAOFF
256 Turn off quotas for an XFS filesystem. As with Q_QUOTAON, XFS
257 filesystems expect a pointer to an unsigned int that specifies
258 whether quota accounting and/or limit enforcement need to be
259 turned off (using the same flags as for Q_XQUOTAON operation).
260 This operation requires privilege (CAP_SYS_ADMIN). The id
261 argument is ignored.
262
263 Q_XGETQUOTA
264 Get disk quota limits and current usage for user id. The addr
265 argument is a pointer to an fs_disk_quota structure, which is
266 defined in <xfs/xqm.h> as follows:
267
268 /* All the blk units are in BBs (Basic Blocks) of
269 512 bytes. */
270
271 #define FS_DQUOT_VERSION 1 /* fs_disk_quota.d_version */
272
273 #define XFS_USER_QUOTA (1<<0) /* User quota type */
274 #define XFS_PROJ_QUOTA (1<<1) /* Project quota type */
275 #define XFS_GROUP_QUOTA (1<<2) /* Group quota type */
276
277 struct fs_disk_quota {
278 int8_t d_version; /* Version of this structure */
279 int8_t d_flags; /* XFS_{USER,PROJ,GROUP}_QUOTA */
280 uint16_t d_fieldmask; /* Field specifier */
281 uint32_t d_id; /* User, project, or group ID */
282 uint64_t d_blk_hardlimit; /* Absolute limit on
283 disk blocks */
284 uint64_t d_blk_softlimit; /* Preferred limit on
285 disk blocks */
286 uint64_t d_ino_hardlimit; /* Maximum # allocated
287 inodes */
288 uint64_t d_ino_softlimit; /* Preferred inode limit */
289 uint64_t d_bcount; /* # disk blocks owned by
290 the user */
291 uint64_t d_icount; /* # inodes owned by the user */
292 int32_t d_itimer; /* Zero if within inode limits */
293 /* If not, we refuse service */
294 int32_t d_btimer; /* Similar to above; for
295 disk blocks */
296 uint16_t d_iwarns; /* # warnings issued with
297 respect to # of inodes */
298 uint16_t d_bwarns; /* # warnings issued with
299 respect to disk blocks */
300 int32_t d_padding2; /* Padding - for future use */
301 uint64_t d_rtb_hardlimit; /* Absolute limit on realtime
302 (RT) disk blocks */
303 uint64_t d_rtb_softlimit; /* Preferred limit on RT
304 disk blocks */
305 uint64_t d_rtbcount; /* # realtime blocks owned */
306 int32_t d_rtbtimer; /* Similar to above; for RT
307 disk blocks */
308 uint16_t d_rtbwarns; /* # warnings issued with
309 respect to RT disk blocks */
310 int16_t d_padding3; /* Padding - for future use */
311 char d_padding4[8]; /* Yet more padding */
312 };
313
314 Unprivileged users may retrieve only their own quotas; a privi‐
315 leged user (CAP_SYS_ADMIN) may retrieve the quotas of any user.
316
317 Q_XGETNEXTQUOTA (since Linux 4.6)
318 This operation is the same as Q_XGETQUOTA, but it returns (in
319 the fs_disk_quota structure pointed by addr) quota information
320 for the next ID greater than or equal to id that has a quota
321 set. Note that since fs_disk_quota already has q_id field, no
322 separate structure type is needed (in contrast with Q_GETQUOTA
323 and Q_GETNEXTQUOTA operations)
324
325 Q_XSETQLIM
326 Set disk quota limits for user id. The addr argument is a
327 pointer to an fs_disk_quota structure. This operation requires
328 privilege (CAP_SYS_ADMIN).
329
330 Q_XGETQSTAT
331 Returns XFS filesystem-specific quota information in the
332 fs_quota_stat structure pointed by addr. This is useful for
333 finding out how much space is used to store quota information,
334 and also to get the quota on/off status of a given local XFS
335 filesystem. The fs_quota_stat structure itself is defined as
336 follows:
337
338 #define FS_QSTAT_VERSION 1 /* fs_quota_stat.qs_version */
339
340 struct fs_qfilestat {
341 uint64_t qfs_ino; /* Inode number */
342 uint64_t qfs_nblks; /* Number of BBs
343 512-byte-blocks */
344 uint32_t qfs_nextents; /* Number of extents */
345 };
346
347 struct fs_quota_stat {
348 int8_t qs_version; /* Version number for
349 future changes */
350 uint16_t qs_flags; /* XFS_QUOTA_{U,P,G}DQ_{ACCT,ENFD} */
351 int8_t qs_pad; /* Unused */
352 struct fs_qfilestat qs_uquota; /* User quota storage
353 information */
354 struct fs_qfilestat qs_gquota; /* Group quota storage
355 information */
356 uint32_t qs_incoredqs; /* Number of dquots in core */
357 int32_t qs_btimelimit; /* Limit for blocks timer */
358 int32_t qs_itimelimit; /* Limit for inodes timer */
359 int32_t qs_rtbtimelimit;/* Limit for RT
360 blocks timer */
361 uint16_t qs_bwarnlimit; /* Limit for # of warnings */
362 uint16_t qs_iwarnlimit; /* Limit for # of warnings */
363 };
364
365 The id argument is ignored.
366
367 Q_XGETQSTATV
368 Returns XFS filesystem-specific quota information in the
369 fs_quota_statv pointed to by addr. This version of the opera‐
370 tion uses a structure with proper versioning support, along
371 with appropriate layout (all fields are naturally aligned) and
372 padding to avoiding special compat handling; it also provides
373 the ability to get statistics regarding the project quota file.
374 The fs_quota_statv structure itself is defined as follows:
375
376 #define FS_QSTATV_VERSION1 1 /* fs_quota_statv.qs_version */
377
378 struct fs_qfilestatv {
379 uint64_t qfs_ino; /* Inode number */
380 uint64_t qfs_nblks; /* Number of BBs
381 512-byte-blocks */
382 uint32_t qfs_nextents; /* Number of extents */
383 uint32_t qfs_pad; /* Pad for 8-byte alignment */
384 };
385
386 struct fs_quota_statv {
387 int8_t qs_version; /* Version for future
388 changes */
389 uint8_t qs_pad1; /* Pad for 16-bit alignment */
390 uint16_t qs_flags; /* XFS_QUOTA_.* flags */
391 uint32_t qs_incoredqs; /* Number of dquots incore */
392 struct fs_qfilestatv qs_uquota; /* User quota
393 information */
394 struct fs_qfilestatv qs_gquota; /* Group quota
395 information */
396 struct fs_qfilestatv qs_pquota; /* Project quota
397 information */
398 int32_t qs_btimelimit; /* Limit for blocks timer */
399 int32_t qs_itimelimit; /* Limit for inodes timer */
400 int32_t qs_rtbtimelimit; /* Limit for RT blocks
401 timer */
402 uint16_t qs_bwarnlimit; /* Limit for # of warnings */
403 uint16_t qs_iwarnlimit; /* Limit for # of warnings */
404 uint64_t qs_pad2[8]; /* For future proofing */
405 };
406
407 The qs_version field of the structure should be filled with the
408 version of the structure supported by the callee (for now, only
409 FS_QSTAT_VERSION1 is supported). The kernel will fill the
410 structure in accordance with version provided. The id argument
411 is ignored.
412
413 Q_XQUOTARM() (since Linux 3.16)
414 Free the disk space taken by disk quotas. The addr argument
415 should be a pointer to an unsigned int value containing flags
416 (the same as in d_flags field of fs_disk_quota structure) which
417 identify what types of quota should be removed (note that the
418 quota type passed in the cmd argument is ignored, but should
419 remain valid in order to pass preliminary quotactl syscall han‐
420 dler checks).
421
422 Quotas must have already been turned off. The id argument is
423 ignored.
424
425 Q_XQUOTASYNC (since Linux 2.6.15; no-op since Linux 3.4)
426 This operation was an XFS quota equivalent to Q_SYNC, but it is
427 no-op since Linux 3.4, as sync(1) writes quota information to
428 disk now (in addition to the other filesystem metadata that it
429 writes out). The special, id and addr arguments are ignored.
430
432 On success, quotactl() returns 0; on error -1 is returned, and errno is
433 set to indicate the error.
434
436 EACCES cmd is Q_QUOTAON, and the quota file pointed to by addr exists,
437 but is not a regular file or is not on the filesystem pointed to
438 by special.
439
440 EBUSY cmd is Q_QUOTAON, but another Q_QUOTAON had already been per‐
441 formed.
442
443 EFAULT addr or special is invalid.
444
445 EINVAL cmd or type is invalid.
446
447 EINVAL cmd is Q_QUOTAON, but the specified quota file is corrupted.
448
449 ENOENT The file specified by special or addr does not exist.
450
451 ENOSYS The kernel has not been compiled with the CONFIG_QUOTA option.
452
453 ENOTBLK
454 special is not a block device.
455
456 EPERM The caller lacked the required privilege (CAP_SYS_ADMIN) for the
457 specified operation.
458
459 ERANGE cmd is Q_SETQUOTA, but the specified limits are out of the range
460 allowed by the quota format.
461
462 ESRCH No disk quota is found for the indicated user. Quotas have not
463 been turned on for this filesystem.
464
465 ESRCH cmd is Q_QUOTAON, but the specified quota format was not found.
466
467 ESRCH cmd is Q_GETNEXTQUOTA or Q_XGETNEXTQUOTA, but there is no ID
468 greater than or equal to id that has an active quota.
469
471 Instead of <xfs/xqm.h> one can use <linux/dqblk_xfs.h>, taking into
472 account that there are several naming discrepancies:
473
474 · Quota enabling flags (of format XFS_QUOTA_[UGP]DQ_{ACCT,ENFD}) are
475 defined without a leading "X", as FS_QUOTA_[UGP]DQ_{ACCT,ENFD}.
476
477 · The same is true for XFS_{USER,GROUP,PROJ}_QUOTA quota type flags,
478 which are defined as FS_{USER,GROUP,PROJ}_QUOTA.
479
480 · The dqblk_xfs.h header file defines its own XQM_USRQUOTA,
481 XQM_GRPQUOTA, and XQM_PRJQUOTA constants for the available quota
482 types, but their values are the same as for constants without the
483 XQM_ prefix.
484
486 quota(1), getrlimit(2), quotacheck(8), quotaon(8)
487
489 This page is part of release 5.04 of the Linux man-pages project. A
490 description of the project, information about reporting bugs, and the
491 latest version of this page, can be found at
492 https://www.kernel.org/doc/man-pages/.
493
494
495
496Linux 2019-11-19 QUOTACTL(2)