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