2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
5 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
6 * Copyright (c) 2005, 2006 Dmitry V. Levin <ldv@altlinux.org>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #define SUBCMDMASK 0x00ff
36 #define QCMD_CMD(cmd) ((u_int32_t)(cmd) >> SUBCMDSHIFT)
37 #define QCMD_TYPE(cmd) ((u_int32_t)(cmd) & SUBCMDMASK)
39 #define OLD_CMD(cmd) ((u_int32_t)(cmd) << 8)
40 #define NEW_CMD(cmd) ((u_int32_t)(cmd) | 0x800000)
41 #define XQM_CMD(cmd) ((u_int32_t)(cmd) | ('X'<<8))
43 #define Q_V1_QUOTAON OLD_CMD(0x1)
44 #define Q_V1_QUOTAOFF OLD_CMD(0x2)
45 #define Q_V1_GETQUOTA OLD_CMD(0x3)
46 #define Q_V1_SETQUOTA OLD_CMD(0x4)
47 #define Q_V1_SETUSE OLD_CMD(0x5)
48 #define Q_V1_SYNC OLD_CMD(0x6)
49 #define Q_SETQLIM OLD_CMD(0x7)
50 #define Q_V1_GETSTATS OLD_CMD(0x8)
51 #define Q_V1_RSQUASH OLD_CMD(0x10)
53 #define Q_V2_GETQUOTA OLD_CMD(0xD)
54 #define Q_V2_SETQUOTA OLD_CMD(0xE)
55 #define Q_V2_SETUSE OLD_CMD(0xF)
56 #define Q_V2_GETINFO OLD_CMD(0x9)
57 #define Q_V2_SETINFO OLD_CMD(0xA)
58 #define Q_V2_SETGRACE OLD_CMD(0xB)
59 #define Q_V2_SETFLAGS OLD_CMD(0xC)
60 #define Q_V2_GETSTATS OLD_CMD(0x11)
62 #define Q_SYNC NEW_CMD(0x1)
63 #define Q_QUOTAON NEW_CMD(0x2)
64 #define Q_QUOTAOFF NEW_CMD(0x3)
65 #define Q_GETFMT NEW_CMD(0x4)
66 #define Q_GETINFO NEW_CMD(0x5)
67 #define Q_SETINFO NEW_CMD(0x6)
68 #define Q_GETQUOTA NEW_CMD(0x7)
69 #define Q_SETQUOTA NEW_CMD(0x8)
71 #define Q_XQUOTAON XQM_CMD(0x1)
72 #define Q_XQUOTAOFF XQM_CMD(0x2)
73 #define Q_XGETQUOTA XQM_CMD(0x3)
74 #define Q_XSETQLIM XQM_CMD(0x4)
75 #define Q_XGETQSTAT XQM_CMD(0x5)
76 #define Q_XQUOTARM XQM_CMD(0x6)
77 #define Q_XQUOTASYNC XQM_CMD(0x7)
79 static const struct xlat quotacmds[] = {
80 {Q_V1_QUOTAON, "Q_V1_QUOTAON"},
81 {Q_V1_QUOTAOFF, "Q_V1_QUOTAOFF"},
82 {Q_V1_GETQUOTA, "Q_V1_GETQUOTA"},
83 {Q_V1_SETQUOTA, "Q_V1_SETQUOTA"},
84 {Q_V1_SETUSE, "Q_V1_SETUSE"},
85 {Q_V1_SYNC, "Q_V1_SYNC"},
86 {Q_SETQLIM, "Q_SETQLIM"},
87 {Q_V1_GETSTATS, "Q_V1_GETSTATS"},
88 {Q_V1_RSQUASH, "Q_V1_RSQUASH"},
90 {Q_V2_GETQUOTA, "Q_V2_GETQUOTA"},
91 {Q_V2_SETQUOTA, "Q_V2_SETQUOTA"},
92 {Q_V2_SETUSE, "Q_V2_SETUSE"},
93 {Q_V2_GETINFO, "Q_V2_GETINFO"},
94 {Q_V2_SETINFO, "Q_V2_SETINFO"},
95 {Q_V2_SETGRACE, "Q_V2_SETGRACE"},
96 {Q_V2_SETFLAGS, "Q_V2_SETFLAGS"},
97 {Q_V2_GETSTATS, "Q_V2_GETSTATS"},
100 {Q_QUOTAON, "Q_QUOTAON"},
101 {Q_QUOTAOFF, "Q_QUOTAOFF"},
102 {Q_GETFMT, "Q_GETFMT"},
103 {Q_GETINFO, "Q_GETINFO"},
104 {Q_SETINFO, "Q_SETINFO"},
105 {Q_GETQUOTA, "Q_GETQUOTA"},
106 {Q_SETQUOTA, "Q_SETQUOTA"},
108 {Q_XQUOTAON, "Q_XQUOTAON"},
109 {Q_XQUOTAOFF, "Q_XQUOTAOFF"},
110 {Q_XGETQUOTA, "Q_XGETQUOTA"},
111 {Q_XSETQLIM, "Q_XSETQLIM"},
112 {Q_XGETQSTAT, "Q_XGETQSTAT"},
113 {Q_XQUOTARM, "Q_XQUOTARM"},
114 {Q_XQUOTASYNC, "Q_XQUOTASYNC"},
122 static const struct xlat quotatypes[] = {
123 {USRQUOTA, "USRQUOTA"},
124 {GRPQUOTA, "GRPQUOTA"},
128 /* Quota format identifiers */
129 #define QFMT_VFS_OLD 1
130 #define QFMT_VFS_V0 2
132 static const struct xlat quota_formats[] = {
133 {QFMT_VFS_OLD, "QFMT_VFS_OLD"},
134 {QFMT_VFS_V0, "QFMT_VFS_V0"},
138 #define XFS_QUOTA_UDQ_ACCT (1<<0) /* user quota accounting */
139 #define XFS_QUOTA_UDQ_ENFD (1<<1) /* user quota limits enforcement */
140 #define XFS_QUOTA_GDQ_ACCT (1<<2) /* group quota accounting */
141 #define XFS_QUOTA_GDQ_ENFD (1<<3) /* group quota limits enforcement */
143 #define XFS_USER_QUOTA (1<<0) /* user quota type */
144 #define XFS_PROJ_QUOTA (1<<1) /* (IRIX) project quota type */
145 #define XFS_GROUP_QUOTA (1<<2) /* group quota type */
147 static const struct xlat xfs_quota_flags[] = {
148 {XFS_QUOTA_UDQ_ACCT, "XFS_QUOTA_UDQ_ACCT"},
149 {XFS_QUOTA_UDQ_ENFD, "XFS_QUOTA_UDQ_ENFD"},
150 {XFS_QUOTA_GDQ_ACCT, "XFS_QUOTA_GDQ_ACCT"},
151 {XFS_QUOTA_GDQ_ENFD, "XFS_QUOTA_GDQ_ENFD"},
155 static const struct xlat xfs_dqblk_flags[] = {
156 {XFS_USER_QUOTA, "XFS_USER_QUOTA"},
157 {XFS_PROJ_QUOTA, "XFS_PROJ_QUOTA"},
158 {XFS_GROUP_QUOTA, "XFS_GROUP_QUOTA"},
163 * Following flags are used to specify which fields are valid
165 #define QIF_BLIMITS 1
167 #define QIF_ILIMITS 4
172 static const struct xlat if_dqblk_valid[] = {
173 {QIF_BLIMITS, "QIF_BLIMITS"},
174 {QIF_SPACE, "QIF_SPACE"},
175 {QIF_ILIMITS, "QIF_ILIMITS"},
176 {QIF_INODES, "QIF_INODES"},
177 {QIF_BTIME, "QIF_BTIME"},
178 {QIF_ITIME, "QIF_ITIME"},
184 u_int64_t dqb_bhardlimit;
185 u_int64_t dqb_bsoftlimit;
186 u_int64_t dqb_curspace;
187 u_int64_t dqb_ihardlimit;
188 u_int64_t dqb_isoftlimit;
189 u_int64_t dqb_curinodes;
197 u_int32_t dqb_bhardlimit; /* absolute limit on disk blks alloc */
198 u_int32_t dqb_bsoftlimit; /* preferred limit on disk blks */
199 u_int32_t dqb_curblocks; /* current block count */
200 u_int32_t dqb_ihardlimit; /* maximum # allocated inodes */
201 u_int32_t dqb_isoftlimit; /* preferred inode limit */
202 u_int32_t dqb_curinodes; /* current # allocated inodes */
203 time_t dqb_btime; /* time limit for excessive disk use */
204 time_t dqb_itime; /* time limit for excessive files */
209 unsigned int dqb_ihardlimit;
210 unsigned int dqb_isoftlimit;
211 unsigned int dqb_curinodes;
212 unsigned int dqb_bhardlimit;
213 unsigned int dqb_bsoftlimit;
214 u_int64_t dqb_curspace;
221 int8_t d_version; /* version of this structure */
222 int8_t d_flags; /* XFS_{USER,PROJ,GROUP}_QUOTA */
223 u_int16_t d_fieldmask; /* field specifier */
224 u_int32_t d_id; /* user, project, or group ID */
225 u_int64_t d_blk_hardlimit; /* absolute limit on disk blks */
226 u_int64_t d_blk_softlimit; /* preferred limit on disk blks */
227 u_int64_t d_ino_hardlimit; /* maximum # allocated inodes */
228 u_int64_t d_ino_softlimit; /* preferred inode limit */
229 u_int64_t d_bcount; /* # disk blocks owned by the user */
230 u_int64_t d_icount; /* # inodes owned by the user */
231 int32_t d_itimer; /* zero if within inode limits */
232 int32_t d_btimer; /* similar to above; for disk blocks */
233 u_int16_t d_iwarns; /* # warnings issued wrt num inodes */
234 u_int16_t d_bwarns; /* # warnings issued wrt disk blocks */
235 int32_t d_padding2; /* padding2 - for future use */
236 u_int64_t d_rtb_hardlimit; /* absolute limit on realtime blks */
237 u_int64_t d_rtb_softlimit; /* preferred limit on RT disk blks */
238 u_int64_t d_rtbcount; /* # realtime blocks owned */
239 int32_t d_rtbtimer; /* similar to above; for RT disk blks */
240 u_int16_t d_rtbwarns; /* # warnings issued wrt RT disk blks */
241 int16_t d_padding3; /* padding3 - for future use */
242 char d_padding4[8]; /* yet more padding */
246 * Following flags are used to specify which fields are valid
252 static const struct xlat if_dqinfo_valid[] = {
253 {IIF_BGRACE, "IIF_BGRACE"},
254 {IIF_IGRACE, "IIF_IGRACE"},
255 {IIF_FLAGS, "IIF_FLAGS"},
261 u_int64_t dqi_bgrace;
262 u_int64_t dqi_igrace;
269 unsigned int dqi_bgrace;
270 unsigned int dqi_igrace;
271 unsigned int dqi_flags;
272 unsigned int dqi_blocks;
273 unsigned int dqi_free_blk;
274 unsigned int dqi_free_entry;
283 u_int32_t cache_hits;
284 u_int32_t allocated_dquots;
285 u_int32_t free_dquots;
295 u_int32_t cache_hits;
296 u_int32_t allocated_dquots;
297 u_int32_t free_dquots;
302 typedef struct fs_qfilestat
304 u_int64_t qfs_ino; /* inode number */
305 u_int64_t qfs_nblks; /* number of BBs 512-byte-blks */
306 u_int32_t qfs_nextents; /* number of extents */
311 int8_t qs_version; /* version number for future changes */
312 u_int16_t qs_flags; /* XFS_QUOTA_{U,P,G}DQ_{ACCT,ENFD} */
313 int8_t qs_pad; /* unused */
314 fs_qfilestat_t qs_uquota; /* user quota storage information */
315 fs_qfilestat_t qs_gquota; /* group quota storage information */
316 u_int32_t qs_incoredqs; /* number of dquots incore */
317 int32_t qs_btimelimit; /* limit for blks timer */
318 int32_t qs_itimelimit; /* limit for inodes timer */
319 int32_t qs_rtbtimelimit; /* limit for rt blks timer */
320 u_int16_t qs_bwarnlimit; /* limit for num warnings */
321 u_int16_t qs_iwarnlimit; /* limit for num warnings */
325 decode_cmd_data(struct tcb *tcp, u_int32_t cmd, unsigned long data)
333 if (cmd == Q_GETQUOTA && syserror(tcp)) {
334 tprintf("%#lx", data);
337 if (umove(tcp, data, &dq) < 0) {
338 tprintf("{???} %#lx", data);
341 tprintf("{bhardlimit=%" PRIu64 ", ", dq.dqb_bhardlimit);
342 tprintf("bsoftlimit=%" PRIu64 ", ", dq.dqb_bsoftlimit);
343 tprintf("curspace=%" PRIu64 ", ", dq.dqb_curspace);
344 tprintf("ihardlimit=%" PRIu64 ", ", dq.dqb_ihardlimit);
345 tprintf("isoftlimit=%" PRIu64 ", ", dq.dqb_isoftlimit);
346 tprintf("curinodes=%" PRIu64 ", ", dq.dqb_curinodes);
348 tprintf("btime=%" PRIu64 ", ", dq.dqb_btime);
349 tprintf("itime=%" PRIu64 ", ", dq.dqb_itime);
351 printflags(if_dqblk_valid,
352 dq.dqb_valid, "QIF_???");
363 if (cmd == Q_V1_GETQUOTA && syserror(tcp)) {
364 tprintf("%#lx", data);
367 if (umove(tcp, data, &dq) < 0) {
368 tprintf("{???} %#lx", data);
371 tprintf("{bhardlimit=%u, ", dq.dqb_bhardlimit);
372 tprintf("bsoftlimit=%u, ", dq.dqb_bsoftlimit);
373 tprintf("curblocks=%u, ", dq.dqb_curblocks);
374 tprintf("ihardlimit=%u, ", dq.dqb_ihardlimit);
375 tprintf("isoftlimit=%u, ", dq.dqb_isoftlimit);
376 tprintf("curinodes=%u, ", dq.dqb_curinodes);
377 tprintf("btime=%lu, ", (long) dq.dqb_btime);
378 tprintf("itime=%lu}", (long) dq.dqb_itime);
386 if (cmd == Q_V2_GETQUOTA && syserror(tcp)) {
387 tprintf("%#lx", data);
390 if (umove(tcp, data, &dq) < 0) {
391 tprintf("{???} %#lx", data);
394 tprintf("{ihardlimit=%u, ", dq.dqb_ihardlimit);
395 tprintf("isoftlimit=%u, ", dq.dqb_isoftlimit);
396 tprintf("curinodes=%u, ", dq.dqb_curinodes);
397 tprintf("bhardlimit=%u, ", dq.dqb_bhardlimit);
398 tprintf("bsoftlimit=%u, ", dq.dqb_bsoftlimit);
399 tprintf("curspace=%" PRIu64 ", ", dq.dqb_curspace);
400 tprintf("btime=%lu, ", (long) dq.dqb_btime);
401 tprintf("itime=%lu}", (long) dq.dqb_itime);
409 if (cmd == Q_XGETQUOTA && syserror(tcp)) {
410 tprintf("%#lx", data);
413 if (umove(tcp, data, &dq) < 0) {
414 tprintf("{???} %#lx", data);
417 tprintf("{version=%d, ", dq.d_version);
419 printflags(xfs_dqblk_flags,
420 dq.d_flags, "XFS_???_QUOTA");
421 tprintf(", fieldmask=%#x, ", dq.d_fieldmask);
422 tprintf("id=%u, ", dq.d_id);
423 tprintf("blk_hardlimit=%" PRIu64 ", ", dq.d_blk_hardlimit);
424 tprintf("blk_softlimit=%" PRIu64 ", ", dq.d_blk_softlimit);
425 tprintf("ino_hardlimit=%" PRIu64 ", ", dq.d_ino_hardlimit);
426 tprintf("ino_softlimit=%" PRIu64 ", ", dq.d_ino_softlimit);
427 tprintf("bcount=%" PRIu64 ", ", dq.d_bcount);
428 tprintf("icount=%" PRIu64 ", ", dq.d_icount);
430 tprintf("itimer=%d, ", dq.d_itimer);
431 tprintf("btimer=%d, ", dq.d_btimer);
432 tprintf("iwarns=%u, ", dq.d_iwarns);
433 tprintf("bwarns=%u, ", dq.d_bwarns);
434 tprintf("rtbcount=%" PRIu64 ", ", dq.d_rtbcount);
435 tprintf("rtbtimer=%d, ", dq.d_rtbtimer);
436 tprintf("rtbwarns=%u}", dq.d_rtbwarns);
446 tprintf("%#lx", data);
449 if (umove(tcp, data, &fmt) < 0) {
450 tprintf("{???} %#lx", data);
454 printxval(quota_formats, fmt, "QFMT_VFS_???");
463 if (cmd == Q_GETINFO && syserror(tcp)) {
464 tprintf("%#lx", data);
467 if (umove(tcp, data, &dq) < 0) {
468 tprintf("{???} %#lx", data);
471 tprintf("{bgrace=%" PRIu64 ", ", dq.dqi_bgrace);
472 tprintf("igrace=%" PRIu64 ", ", dq.dqi_igrace);
473 tprintf("flags=%#x, ", dq.dqi_flags);
475 printflags(if_dqinfo_valid, dq.dqi_valid, "IIF_???");
484 if (cmd == Q_V2_GETINFO && syserror(tcp)) {
485 tprintf("%#lx", data);
488 if (umove(tcp, data, &dq) < 0) {
489 tprintf("{???} %#lx", data);
492 tprintf("{bgrace=%u, ", dq.dqi_bgrace);
493 tprintf("igrace=%u, ", dq.dqi_igrace);
494 tprintf("flags=%#x, ", dq.dqi_flags);
495 tprintf("blocks=%u, ", dq.dqi_blocks);
496 tprintf("free_blk=%u, ", dq.dqi_free_blk);
497 tprintf("free_entry=%u}", dq.dqi_free_entry);
502 struct v1_dqstats dq;
505 tprintf("%#lx", data);
508 if (umove(tcp, data, &dq) < 0) {
509 tprintf("{???} %#lx", data);
512 tprintf("{lookups=%u, ", dq.lookups);
513 tprintf("drops=%u, ", dq.drops);
514 tprintf("reads=%u, ", dq.reads);
515 tprintf("writes=%u, ", dq.writes);
516 tprintf("cache_hits=%u, ", dq.cache_hits);
517 tprintf("allocated_dquots=%u, ", dq.allocated_dquots);
518 tprintf("free_dquots=%u, ", dq.free_dquots);
519 tprintf("syncs=%u}", dq.syncs);
524 struct v2_dqstats dq;
527 tprintf("%#lx", data);
530 if (umove(tcp, data, &dq) < 0) {
531 tprintf("{???} %#lx", data);
534 tprintf("{lookups=%u, ", dq.lookups);
535 tprintf("drops=%u, ", dq.drops);
536 tprintf("reads=%u, ", dq.reads);
537 tprintf("writes=%u, ", dq.writes);
538 tprintf("cache_hits=%u, ", dq.cache_hits);
539 tprintf("allocated_dquots=%u, ", dq.allocated_dquots);
540 tprintf("free_dquots=%u, ", dq.free_dquots);
541 tprintf("syncs=%u, ", dq.syncs);
542 tprintf("version=%u}", dq.version);
547 struct xfs_dqstats dq;
550 tprintf("%#lx", data);
553 if (umove(tcp, data, &dq) < 0) {
554 tprintf("{???} %#lx", data);
557 tprintf("{version=%d, ", dq.qs_version);
563 printflags(xfs_quota_flags,
564 dq.qs_flags, "XFS_QUOTA_???");
565 tprintf(", incoredqs=%u, ", dq.qs_incoredqs);
566 tprintf("u_ino=%" PRIu64 ", ", dq.qs_uquota.qfs_ino);
567 tprintf("u_nblks=%" PRIu64 ", ", dq.qs_uquota.qfs_nblks);
568 tprintf("u_nextents=%u, ", dq.qs_uquota.qfs_nextents);
569 tprintf("g_ino=%" PRIu64 ", ", dq.qs_gquota.qfs_ino);
570 tprintf("g_nblks=%" PRIu64 ", ", dq.qs_gquota.qfs_nblks);
571 tprintf("g_nextents=%u, ", dq.qs_gquota.qfs_nextents);
572 tprintf("btimelimit=%d, ", dq.qs_btimelimit);
573 tprintf("itimelimit=%d, ", dq.qs_itimelimit);
574 tprintf("rtbtimelimit=%d, ", dq.qs_rtbtimelimit);
575 tprintf("bwarnlimit=%u, ", dq.qs_bwarnlimit);
576 tprintf("iwarnlimit=%u}", dq.qs_iwarnlimit);
583 if (umove(tcp, data, &flag) < 0) {
584 tprintf("{???} %#lx", data);
588 printflags(xfs_quota_flags, flag, "XFS_QUOTA_???");
593 tprintf("%#lx", data);
599 sys_quotactl(struct tcb *tcp)
602 * The Linux kernel only looks at the low 32 bits of command and id
603 * arguments, but on some 64-bit architectures (s390x) this word
604 * will have been sign-extended when we see it. The high 1 bits
605 * don't mean anything, so don't confuse the output with them.
607 u_int32_t qcmd = tcp->u_arg[0];
608 u_int32_t cmd = QCMD_CMD(qcmd);
609 u_int32_t type = QCMD_TYPE(qcmd);
610 u_int32_t id = tcp->u_arg[2];
613 return printargs(tcp);
616 printxval(quotacmds, cmd, "Q_???");
618 printxval(quotatypes, type, "???QUOTA");
620 printstr(tcp, tcp->u_arg[1], -1);
625 printxval(quota_formats, id, "QFMT_VFS_???");
641 tprintf("%#lx", tcp->u_arg[2]);
649 decode_cmd_data(tcp, cmd, tcp->u_arg[3]);