1quotactl(2)                   System Calls Manual                  quotactl(2)
2
3
4

NAME

6       quotactl - manipulate disk quotas
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

430       On success, quotactl() returns 0; on error -1 is returned, and errno is
431       set to indicate the error.
432

ERRORS

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

NOTES

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

SEE ALSO

487       quota(1), getrlimit(2), quotacheck(8), quotaon(8)
488
489
490
491Linux man-pages 6.05              2023-05-03                       quotactl(2)
Impressum