1QUOTACTL(2)                Linux Programmer's Manual               QUOTACTL(2)
2
3
4

NAME

6       quotactl - manipulate disk quotas
7

SYNOPSIS

9       #include <sys/quota.h>
10       #include <xfs/xqm.h> /* Definition of Q_X* and XFS_QUOTA_* constants
11                               (or <linux/dqblk_xfs.h>; see NOTES) */
12
13       int quotactl(int cmd, const char *special, int id, caddr_t addr);
14

DESCRIPTION

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

RETURN VALUE

425       On success, quotactl() returns 0; on error -1 is returned, and errno is
426       set to indicate the error.
427

ERRORS

429       EACCES cmd  is Q_QUOTAON, and the quota file pointed to by addr exists,
430              but is not a regular file or is not on the filesystem pointed to
431              by special.
432
433       EBUSY  cmd  is  Q_QUOTAON,  but another Q_QUOTAON had already been per‐
434              formed.
435
436       EFAULT addr or special is invalid.
437
438       EINVAL cmd or type is invalid.
439
440       EINVAL cmd is Q_QUOTAON, but the specified quota file is corrupted.
441
442       EINVAL (since Linux 5.5)
443              cmd is Q_XQUOTARM, but addr does not point to valid quota types.
444
445       ENOENT The file specified by special or addr does not exist.
446
447       ENOSYS The kernel has not been compiled with the CONFIG_QUOTA option.
448
449       ENOTBLK
450              special is not a block device.
451
452       EPERM  The caller lacked the required privilege (CAP_SYS_ADMIN) for the
453              specified operation.
454
455       ERANGE cmd is Q_SETQUOTA, but the specified limits are out of the range
456              allowed by the quota format.
457
458       ESRCH  No disk quota is found for the indicated user.  Quotas have  not
459              been turned on for this filesystem.
460
461       ESRCH  cmd is Q_QUOTAON, but the specified quota format was not found.
462
463       ESRCH  cmd  is  Q_GETNEXTQUOTA  or  Q_XGETNEXTQUOTA, but there is no ID
464              greater than or equal to id that has an active quota.
465

NOTES

467       Instead of <xfs/xqm.h> one can use <linux/dqblk_xfs.h>, taking into ac‐
468       count that there are several naming discrepancies:
469
470       •  Quota  enabling  flags (of format XFS_QUOTA_[UGP]DQ_{ACCT,ENFD}) are
471          defined without a leading "X", as FS_QUOTA_[UGP]DQ_{ACCT,ENFD}.
472
473       •  The same is true for XFS_{USER,GROUP,PROJ}_QUOTA quota  type  flags,
474          which are defined as FS_{USER,GROUP,PROJ}_QUOTA.
475
476       •  The  dqblk_xfs.h  header  file defines its own XQM_USRQUOTA, XQM_GR‐
477          PQUOTA, and XQM_PRJQUOTA constants for the  available  quota  types,
478          but their values are the same as for constants without the XQM_ pre‐
479          fix.
480

SEE ALSO

482       quota(1), getrlimit(2), quotacheck(8), quotaon(8)
483

COLOPHON

485       This page is part of release 5.13 of the Linux  man-pages  project.   A
486       description  of  the project, information about reporting bugs, and the
487       latest    version    of    this    page,    can     be     found     at
488       https://www.kernel.org/doc/man-pages/.
489
490
491
492Linux                             2021-03-22                       QUOTACTL(2)
Impressum