]> granicus.if.org Git - strace/blob - quota.c
CREDITS.in: use UTF-8 consistently
[strace] / quota.c
1 /*
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-2016 Dmitry V. Levin <ldv@altlinux.org>
7  * Copyright (c) 2006-2017 The strace developers.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #include "defs.h"
34 #include "print_fields.h"
35
36 #define SUBCMDMASK  0x00ff
37 #define SUBCMDSHIFT 8
38 #define QCMD_CMD(cmd)   ((uint32_t)(cmd) >> SUBCMDSHIFT)
39 #define QCMD_TYPE(cmd)  ((uint32_t)(cmd) & SUBCMDMASK)
40
41 #define OLD_CMD(cmd)    ((uint32_t)(cmd) << SUBCMDSHIFT)
42 #define NEW_CMD(cmd)    ((uint32_t)(cmd) | 0x800000)
43 #define XQM_CMD(cmd)    ((uint32_t)(cmd) | ('X' << SUBCMDSHIFT))
44
45 #include "xlat/quotacmds.h"
46 #include "xlat/quotatypes.h"
47 #include "xlat/quota_formats.h"
48 #include "xlat/xfs_quota_flags.h"
49 #include "xlat/xfs_dqblk_flags.h"
50 #include "xlat/if_dqblk_valid.h"
51 #include "xlat/if_dqinfo_flags.h"
52 #include "xlat/if_dqinfo_valid.h"
53
54 /*
55  * We add attribute packed due to the fact that the structure is 8-byte aligned
56  * on 64-bit systems and therefore has additional 4 bytes of padding, which
57  * leads to problems when it is used on 32-bit tracee which does not have such
58  * padding.
59  */
60 struct if_dqblk {
61         uint64_t dqb_bhardlimit;
62         uint64_t dqb_bsoftlimit;
63         uint64_t dqb_curspace;
64         uint64_t dqb_ihardlimit;
65         uint64_t dqb_isoftlimit;
66         uint64_t dqb_curinodes;
67         uint64_t dqb_btime;
68         uint64_t dqb_itime;
69         uint32_t dqb_valid;
70 } ATTRIBUTE_PACKED;
71
72 struct if_nextdqblk {
73         uint64_t dqb_bhardlimit;
74         uint64_t dqb_bsoftlimit;
75         uint64_t dqb_curspace;
76         uint64_t dqb_ihardlimit;
77         uint64_t dqb_isoftlimit;
78         uint64_t dqb_curinodes;
79         uint64_t dqb_btime;
80         uint64_t dqb_itime;
81         uint32_t dqb_valid;
82         uint32_t dqb_id;
83 };
84
85 struct xfs_dqblk {
86         int8_t  d_version;              /* version of this structure */
87         uint8_t  d_flags;               /* XFS_{USER,PROJ,GROUP}_QUOTA */
88         uint16_t d_fieldmask;           /* field specifier */
89         uint32_t d_id;                  /* user, project, or group ID */
90         uint64_t d_blk_hardlimit;       /* absolute limit on disk blks */
91         uint64_t d_blk_softlimit;       /* preferred limit on disk blks */
92         uint64_t d_ino_hardlimit;       /* maximum # allocated inodes */
93         uint64_t d_ino_softlimit;       /* preferred inode limit */
94         uint64_t d_bcount;              /* # disk blocks owned by the user */
95         uint64_t d_icount;              /* # inodes owned by the user */
96         int32_t d_itimer;               /* zero if within inode limits */
97         int32_t d_btimer;               /* similar to above; for disk blocks */
98         uint16_t d_iwarns;              /* # warnings issued wrt num inodes */
99         uint16_t d_bwarns;              /* # warnings issued wrt disk blocks */
100         int32_t d_padding2;             /* padding2 - for future use */
101         uint64_t d_rtb_hardlimit;       /* absolute limit on realtime blks */
102         uint64_t d_rtb_softlimit;       /* preferred limit on RT disk blks */
103         uint64_t d_rtbcount;            /* # realtime blocks owned */
104         int32_t d_rtbtimer;             /* similar to above; for RT disk blks */
105         uint16_t d_rtbwarns;            /* # warnings issued wrt RT disk blks */
106         int16_t d_padding3;             /* padding3 - for future use */
107         char    d_padding4[8];          /* yet more padding */
108 };
109
110 struct if_dqinfo {
111         uint64_t dqi_bgrace;
112         uint64_t dqi_igrace;
113         uint32_t dqi_flags;
114         uint32_t dqi_valid;
115 };
116
117 typedef struct fs_qfilestat {
118         uint64_t qfs_ino;       /* inode number */
119         uint64_t qfs_nblks;     /* number of BBs 512-byte-blks */
120         uint32_t qfs_nextents;  /* number of extents */
121 } fs_qfilestat_t;
122
123 struct xfs_dqstats {
124         int8_t  qs_version;             /* version number for future changes */
125         uint16_t qs_flags;              /* XFS_QUOTA_{U,P,G}DQ_{ACCT,ENFD} */
126         int8_t  qs_pad;                 /* unused */
127         fs_qfilestat_t qs_uquota;       /* user quota storage information */
128         fs_qfilestat_t qs_gquota;       /* group quota storage information */
129         uint32_t qs_incoredqs;          /* number of dquots incore */
130         int32_t qs_btimelimit;          /* limit for blks timer */
131         int32_t qs_itimelimit;          /* limit for inodes timer */
132         int32_t qs_rtbtimelimit;        /* limit for rt blks timer */
133         uint16_t qs_bwarnlimit;         /* limit for num warnings */
134         uint16_t qs_iwarnlimit;         /* limit for num warnings */
135 };
136
137 struct fs_qfilestatv {
138         uint64_t qfs_ino, qfs_nblks;
139         uint32_t qfs_nextents, qfs_pad;
140 };
141
142 struct fs_quota_statv {
143         int8_t qs_version;
144         uint8_t qs_pad1;
145         uint16_t qs_flags;
146         uint32_t qs_incoredqs;
147         struct fs_qfilestatv qs_uquota;
148         struct fs_qfilestatv qs_gquota;
149         struct fs_qfilestatv qs_pquota;
150         int32_t qs_btimelimit;
151         int32_t qs_itimelimit;
152         int32_t qs_rtbtimelimit;
153         uint16_t qs_bwarnlimit;
154         uint16_t qs_iwarnlimit;
155         uint64_t qs_pad2[8];
156 };
157
158 static int
159 decode_cmd_data(struct tcb *tcp, uint32_t id, uint32_t cmd, kernel_ulong_t data)
160 {
161         switch (cmd) {
162         case Q_QUOTAOFF:
163         case Q_SYNC:
164         case Q_XQUOTASYNC:
165                 break;
166         case Q_QUOTAON:
167                 tprints(", ");
168                 printxval(quota_formats, id, "QFMT_VFS_???");
169                 tprints(", ");
170                 printpath(tcp, data);
171                 break;
172         case Q_GETQUOTA:
173                 if (entering(tcp)) {
174                         printuid(", ", id);
175                         tprints(", ");
176
177                         return 0;
178                 }
179
180                 /* Fall-through */
181         case Q_SETQUOTA:
182         {
183                 struct if_dqblk dq;
184
185                 if (entering(tcp)) {
186                         printuid(", ", id);
187                         tprints(", ");
188                 }
189
190                 if (umove_or_printaddr(tcp, data, &dq))
191                         break;
192                 PRINT_FIELD_U("{", dq, dqb_bhardlimit);
193                 PRINT_FIELD_U(", ", dq, dqb_bsoftlimit);
194                 PRINT_FIELD_U(", ", dq, dqb_curspace);
195                 PRINT_FIELD_U(", ", dq, dqb_ihardlimit);
196                 PRINT_FIELD_U(", ", dq, dqb_isoftlimit);
197                 PRINT_FIELD_U(", ", dq, dqb_curinodes);
198                 if (!abbrev(tcp)) {
199                         PRINT_FIELD_U(", ", dq, dqb_btime);
200                         PRINT_FIELD_U(", ", dq, dqb_itime);
201                         PRINT_FIELD_FLAGS(", ", dq, dqb_valid,
202                                           if_dqblk_valid, "QIF_???");
203                 } else {
204                         tprints(", ...");
205                 }
206                 tprints("}");
207                 break;
208         }
209         case Q_GETNEXTQUOTA:
210         {
211                 struct if_nextdqblk dq;
212
213                 if (entering(tcp)) {
214                         printuid(", ", id);
215                         tprints(", ");
216
217                         return 0;
218                 }
219
220                 if (umove_or_printaddr(tcp, data, &dq))
221                         break;
222                 PRINT_FIELD_U("{", dq, dqb_bhardlimit);
223                 PRINT_FIELD_U(", ", dq, dqb_bsoftlimit);
224                 PRINT_FIELD_U(", ", dq, dqb_curspace);
225                 PRINT_FIELD_U(", ", dq, dqb_ihardlimit);
226                 PRINT_FIELD_U(", ", dq, dqb_isoftlimit);
227                 PRINT_FIELD_U(", ", dq, dqb_curinodes);
228                 if (!abbrev(tcp)) {
229                         PRINT_FIELD_U(", ", dq, dqb_btime);
230                         PRINT_FIELD_U(", ", dq, dqb_itime);
231                         PRINT_FIELD_FLAGS(", ", dq, dqb_valid,
232                                           if_dqblk_valid, "QIF_???");
233                         PRINT_FIELD_U(", ", dq, dqb_id);
234                 } else {
235                         PRINT_FIELD_U(", ", dq, dqb_id);
236                         tprints(", ...");
237                 }
238                 tprints("}");
239                 break;
240         }
241         case Q_XGETQUOTA:
242         case Q_XGETNEXTQUOTA:
243                 if (entering(tcp)) {
244                         printuid(", ", id);
245                         tprints(", ");
246
247                         return 0;
248                 }
249
250                 /* Fall-through */
251         case Q_XSETQLIM:
252         {
253                 struct xfs_dqblk dq;
254
255                 if (entering(tcp)) {
256                         printuid(", ", id);
257                         tprints(", ");
258                 }
259
260                 if (umove_or_printaddr(tcp, data, &dq))
261                         break;
262                 PRINT_FIELD_D("{", dq, d_version);
263                 PRINT_FIELD_FLAGS(", ", dq, d_flags,
264                                   xfs_dqblk_flags, "XFS_???_QUOTA");
265                 PRINT_FIELD_X(", ", dq, d_fieldmask);
266                 PRINT_FIELD_U(", ", dq, d_id);
267                 PRINT_FIELD_U(", ", dq, d_blk_hardlimit);
268                 PRINT_FIELD_U(", ", dq, d_blk_softlimit);
269                 PRINT_FIELD_U(", ", dq, d_ino_hardlimit);
270                 PRINT_FIELD_U(", ", dq, d_ino_softlimit);
271                 PRINT_FIELD_U(", ", dq, d_bcount);
272                 PRINT_FIELD_U(", ", dq, d_icount);
273                 if (!abbrev(tcp)) {
274                         PRINT_FIELD_D(", ", dq, d_itimer);
275                         PRINT_FIELD_D(", ", dq, d_btimer);
276                         PRINT_FIELD_U(", ", dq, d_iwarns);
277                         PRINT_FIELD_U(", ", dq, d_bwarns);
278                         PRINT_FIELD_U(", ", dq, d_rtb_hardlimit);
279                         PRINT_FIELD_U(", ", dq, d_rtb_softlimit);
280                         PRINT_FIELD_U(", ", dq, d_rtbcount);
281                         PRINT_FIELD_D(", ", dq, d_rtbtimer);
282                         PRINT_FIELD_U(", ", dq, d_rtbwarns);
283                 } else {
284                         tprints(", ...");
285                 }
286                 tprints("}");
287                 break;
288         }
289         case Q_GETFMT:
290         {
291                 uint32_t fmt;
292
293                 if (entering(tcp)) {
294                         tprints(", ");
295
296                         return 0;
297                 }
298
299                 if (umove_or_printaddr(tcp, data, &fmt))
300                         break;
301                 tprints("[");
302                 printxval(quota_formats, fmt, "QFMT_VFS_???");
303                 tprints("]");
304                 break;
305         }
306         case Q_GETINFO:
307                 if (entering(tcp)) {
308                         tprints(", ");
309
310                         return 0;
311                 }
312
313                 /* Fall-through */
314         case Q_SETINFO:
315         {
316                 struct if_dqinfo dq;
317
318                 if (entering(tcp))
319                         tprints(", ");
320
321                 if (umove_or_printaddr(tcp, data, &dq))
322                         break;
323                 PRINT_FIELD_U("{", dq, dqi_bgrace);
324                 PRINT_FIELD_U(", ", dq, dqi_igrace);
325                 PRINT_FIELD_FLAGS(", ", dq, dqi_flags, if_dqinfo_flags, "DQF_???");
326                 PRINT_FIELD_FLAGS(", ", dq, dqi_valid, if_dqinfo_valid, "IIF_???");
327                 tprints("}");
328                 break;
329         }
330         case Q_XGETQSTAT:
331         {
332                 struct xfs_dqstats dq;
333
334                 if (entering(tcp)) {
335                         tprints(", ");
336
337                         return 0;
338                 }
339
340                 if (umove_or_printaddr(tcp, data, &dq))
341                         break;
342                 PRINT_FIELD_D("{", dq, qs_version);
343                 if (!abbrev(tcp)) {
344                         PRINT_FIELD_FLAGS(", ", dq, qs_flags,
345                                           xfs_quota_flags, "XFS_QUOTA_???");
346                         PRINT_FIELD_U(", ", dq, qs_incoredqs);
347                         PRINT_FIELD_U(", qs_uquota={", dq.qs_uquota, qfs_ino);
348                         PRINT_FIELD_U(", ", dq.qs_uquota, qfs_nblks);
349                         PRINT_FIELD_U(", ", dq.qs_uquota, qfs_nextents);
350                         PRINT_FIELD_U("}, qs_gquota={", dq.qs_gquota, qfs_ino);
351                         PRINT_FIELD_U(", ", dq.qs_gquota, qfs_nblks);
352                         PRINT_FIELD_U(", ", dq.qs_gquota, qfs_nextents);
353                         PRINT_FIELD_D("}, ", dq, qs_btimelimit);
354                         PRINT_FIELD_D(", ", dq, qs_itimelimit);
355                         PRINT_FIELD_D(", ", dq, qs_rtbtimelimit);
356                         PRINT_FIELD_U(", ", dq, qs_bwarnlimit);
357                         PRINT_FIELD_U(", ", dq, qs_iwarnlimit);
358                 } else {
359                         tprints(", ...");
360                 }
361                 tprints("}");
362                 break;
363         }
364         case Q_XGETQSTATV:
365         {
366                 struct fs_quota_statv dq;
367
368                 if (entering(tcp)) {
369                         tprints(", ");
370
371                         return 0;
372                 }
373
374                 if (umove_or_printaddr(tcp, data, &dq))
375                         break;
376                 PRINT_FIELD_D("{", dq, qs_version);
377                 if (!abbrev(tcp)) {
378                         PRINT_FIELD_FLAGS(", ", dq, qs_flags,
379                                           xfs_quota_flags, "XFS_QUOTA_???");
380                         PRINT_FIELD_U(", ", dq, qs_incoredqs);
381                         PRINT_FIELD_U(", qs_uquota={", dq.qs_uquota, qfs_ino);
382                         PRINT_FIELD_U(", ", dq.qs_uquota, qfs_nblks);
383                         PRINT_FIELD_U(", ", dq.qs_uquota, qfs_nextents);
384                         PRINT_FIELD_U("}, qs_gquota={", dq.qs_gquota, qfs_ino);
385                         PRINT_FIELD_U(", ", dq.qs_gquota, qfs_nblks);
386                         PRINT_FIELD_U(", ", dq.qs_gquota, qfs_nextents);
387                         PRINT_FIELD_U("}, qs_pquota={", dq.qs_pquota, qfs_ino);
388                         PRINT_FIELD_U(", ", dq.qs_pquota, qfs_nblks);
389                         PRINT_FIELD_U(", ", dq.qs_pquota, qfs_nextents);
390                         PRINT_FIELD_D("}, ", dq, qs_btimelimit);
391                         PRINT_FIELD_D(", ", dq, qs_itimelimit);
392                         PRINT_FIELD_D(", ", dq, qs_rtbtimelimit);
393                         PRINT_FIELD_U(", ", dq, qs_bwarnlimit);
394                         PRINT_FIELD_U(", ", dq, qs_iwarnlimit);
395                 } else {
396                         tprints(", ...");
397                 }
398                 tprints("}");
399                 break;
400         }
401         case Q_XQUOTAON:
402         case Q_XQUOTAOFF:
403         {
404                 uint32_t flag;
405
406                 tprints(", ");
407
408                 if (umove_or_printaddr(tcp, data, &flag))
409                         break;
410                 tprints("[");
411                 printflags(xfs_quota_flags, flag, "XFS_QUOTA_???");
412                 tprints("]");
413                 break;
414         }
415         case Q_XQUOTARM:
416         {
417                 uint32_t flag;
418
419                 tprints(", ");
420
421                 if (umove_or_printaddr(tcp, data, &flag))
422                         break;
423                 tprints("[");
424                 printflags(xfs_dqblk_flags, flag, "XFS_???_QUOTA");
425                 tprints("]");
426                 break;
427         }
428         default:
429                 printuid(", ", id);
430                 tprints(", ");
431                 printaddr(data);
432                 break;
433         }
434         return RVAL_DECODED;
435 }
436
437 SYS_FUNC(quotactl)
438 {
439         /*
440          * The Linux kernel only looks at the low 32 bits of command and id
441          * arguments, but on some 64-bit architectures (s390x) this word
442          * will have been sign-extended when we see it.  The high 1 bits
443          * don't mean anything, so don't confuse the output with them.
444          */
445         uint32_t qcmd = tcp->u_arg[0];
446         uint32_t cmd = QCMD_CMD(qcmd);
447         uint32_t type = QCMD_TYPE(qcmd);
448         uint32_t id = tcp->u_arg[2];
449
450         if (entering(tcp)) {
451                 tprints("QCMD(");
452                 printxval(quotacmds, cmd, "Q_???");
453                 tprints(", ");
454                 printxval(quotatypes, type, "???QUOTA");
455                 tprints("), ");
456                 printpath(tcp, tcp->u_arg[1]);
457         }
458         return decode_cmd_data(tcp, id, cmd, tcp->u_arg[3]);
459 }