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
decode_cmd_data(struct tcb * tcp,uint32_t id,uint32_t cmd,kernel_ulong_t data)158 decode_cmd_data(struct tcb *tcp, uint32_t id, uint32_t cmd, kernel_ulong_t data)
159 {
160 switch (cmd) {
161 case Q_QUOTAOFF:
162 case Q_SYNC:
163 case Q_XQUOTASYNC:
164 break;
165 case Q_QUOTAON:
166 tprints(", ");
167 printxval(quota_formats, id, "QFMT_VFS_???");
168 tprints(", ");
169 printpath(tcp, data);
170 break;
171 case Q_GETQUOTA:
172 if (entering(tcp)) {
173 printuid(", ", id);
174 tprints(", ");
175
176 return 0;
177 }
178
179 /* Fall-through */
180 case Q_SETQUOTA:
181 {
182 struct if_dqblk dq;
183
184 if (entering(tcp)) {
185 printuid(", ", id);
186 tprints(", ");
187 }
188
189 if (umove_or_printaddr(tcp, data, &dq))
190 break;
191 PRINT_FIELD_U("{", dq, dqb_bhardlimit);
192 PRINT_FIELD_U(", ", dq, dqb_bsoftlimit);
193 PRINT_FIELD_U(", ", dq, dqb_curspace);
194 PRINT_FIELD_U(", ", dq, dqb_ihardlimit);
195 PRINT_FIELD_U(", ", dq, dqb_isoftlimit);
196 PRINT_FIELD_U(", ", dq, dqb_curinodes);
197 if (!abbrev(tcp)) {
198 PRINT_FIELD_U(", ", dq, dqb_btime);
199 PRINT_FIELD_U(", ", dq, dqb_itime);
200 PRINT_FIELD_FLAGS(", ", dq, dqb_valid,
201 if_dqblk_valid, "QIF_???");
202 } else {
203 tprints(", ...");
204 }
205 tprints("}");
206 break;
207 }
208 case Q_GETNEXTQUOTA:
209 {
210 struct if_nextdqblk dq;
211
212 if (entering(tcp)) {
213 printuid(", ", id);
214 tprints(", ");
215
216 return 0;
217 }
218
219 if (umove_or_printaddr(tcp, data, &dq))
220 break;
221 PRINT_FIELD_U("{", dq, dqb_bhardlimit);
222 PRINT_FIELD_U(", ", dq, dqb_bsoftlimit);
223 PRINT_FIELD_U(", ", dq, dqb_curspace);
224 PRINT_FIELD_U(", ", dq, dqb_ihardlimit);
225 PRINT_FIELD_U(", ", dq, dqb_isoftlimit);
226 PRINT_FIELD_U(", ", dq, dqb_curinodes);
227 if (!abbrev(tcp)) {
228 PRINT_FIELD_U(", ", dq, dqb_btime);
229 PRINT_FIELD_U(", ", dq, dqb_itime);
230 PRINT_FIELD_FLAGS(", ", dq, dqb_valid,
231 if_dqblk_valid, "QIF_???");
232 PRINT_FIELD_U(", ", dq, dqb_id);
233 } else {
234 PRINT_FIELD_U(", ", dq, dqb_id);
235 tprints(", ...");
236 }
237 tprints("}");
238 break;
239 }
240 case Q_XGETQUOTA:
241 case Q_XGETNEXTQUOTA:
242 if (entering(tcp)) {
243 printuid(", ", id);
244 tprints(", ");
245
246 return 0;
247 }
248
249 /* Fall-through */
250 case Q_XSETQLIM:
251 {
252 struct xfs_dqblk dq;
253
254 if (entering(tcp)) {
255 printuid(", ", id);
256 tprints(", ");
257 }
258
259 if (umove_or_printaddr(tcp, data, &dq))
260 break;
261 PRINT_FIELD_D("{", dq, d_version);
262 PRINT_FIELD_FLAGS(", ", dq, d_flags,
263 xfs_dqblk_flags, "XFS_???_QUOTA");
264 PRINT_FIELD_X(", ", dq, d_fieldmask);
265 PRINT_FIELD_U(", ", dq, d_id);
266 PRINT_FIELD_U(", ", dq, d_blk_hardlimit);
267 PRINT_FIELD_U(", ", dq, d_blk_softlimit);
268 PRINT_FIELD_U(", ", dq, d_ino_hardlimit);
269 PRINT_FIELD_U(", ", dq, d_ino_softlimit);
270 PRINT_FIELD_U(", ", dq, d_bcount);
271 PRINT_FIELD_U(", ", dq, d_icount);
272 if (!abbrev(tcp)) {
273 PRINT_FIELD_D(", ", dq, d_itimer);
274 PRINT_FIELD_D(", ", dq, d_btimer);
275 PRINT_FIELD_U(", ", dq, d_iwarns);
276 PRINT_FIELD_U(", ", dq, d_bwarns);
277 PRINT_FIELD_U(", ", dq, d_rtb_hardlimit);
278 PRINT_FIELD_U(", ", dq, d_rtb_softlimit);
279 PRINT_FIELD_U(", ", dq, d_rtbcount);
280 PRINT_FIELD_D(", ", dq, d_rtbtimer);
281 PRINT_FIELD_U(", ", dq, d_rtbwarns);
282 } else {
283 tprints(", ...");
284 }
285 tprints("}");
286 break;
287 }
288 case Q_GETFMT:
289 {
290 uint32_t fmt;
291
292 if (entering(tcp)) {
293 tprints(", ");
294
295 return 0;
296 }
297
298 if (umove_or_printaddr(tcp, data, &fmt))
299 break;
300 tprints("[");
301 printxval(quota_formats, fmt, "QFMT_VFS_???");
302 tprints("]");
303 break;
304 }
305 case Q_GETINFO:
306 if (entering(tcp)) {
307 tprints(", ");
308
309 return 0;
310 }
311
312 /* Fall-through */
313 case Q_SETINFO:
314 {
315 struct if_dqinfo dq;
316
317 if (entering(tcp))
318 tprints(", ");
319
320 if (umove_or_printaddr(tcp, data, &dq))
321 break;
322 PRINT_FIELD_U("{", dq, dqi_bgrace);
323 PRINT_FIELD_U(", ", dq, dqi_igrace);
324 PRINT_FIELD_FLAGS(", ", dq, dqi_flags, if_dqinfo_flags, "DQF_???");
325 PRINT_FIELD_FLAGS(", ", dq, dqi_valid, if_dqinfo_valid, "IIF_???");
326 tprints("}");
327 break;
328 }
329 case Q_XGETQSTAT:
330 {
331 struct xfs_dqstats dq;
332
333 if (entering(tcp)) {
334 tprints(", ");
335
336 return 0;
337 }
338
339 if (umove_or_printaddr(tcp, data, &dq))
340 break;
341 PRINT_FIELD_D("{", dq, qs_version);
342 if (!abbrev(tcp)) {
343 PRINT_FIELD_FLAGS(", ", dq, qs_flags,
344 xfs_quota_flags, "XFS_QUOTA_???");
345 PRINT_FIELD_U(", ", dq, qs_incoredqs);
346 PRINT_FIELD_U(", qs_uquota={", dq.qs_uquota, qfs_ino);
347 PRINT_FIELD_U(", ", dq.qs_uquota, qfs_nblks);
348 PRINT_FIELD_U(", ", dq.qs_uquota, qfs_nextents);
349 PRINT_FIELD_U("}, qs_gquota={", dq.qs_gquota, qfs_ino);
350 PRINT_FIELD_U(", ", dq.qs_gquota, qfs_nblks);
351 PRINT_FIELD_U(", ", dq.qs_gquota, qfs_nextents);
352 PRINT_FIELD_D("}, ", dq, qs_btimelimit);
353 PRINT_FIELD_D(", ", dq, qs_itimelimit);
354 PRINT_FIELD_D(", ", dq, qs_rtbtimelimit);
355 PRINT_FIELD_U(", ", dq, qs_bwarnlimit);
356 PRINT_FIELD_U(", ", dq, qs_iwarnlimit);
357 } else {
358 tprints(", ...");
359 }
360 tprints("}");
361 break;
362 }
363 case Q_XGETQSTATV:
364 {
365 struct fs_quota_statv dq;
366
367 if (entering(tcp)) {
368 tprints(", ");
369
370 return 0;
371 }
372
373 if (umove_or_printaddr(tcp, data, &dq))
374 break;
375 PRINT_FIELD_D("{", dq, qs_version);
376 if (!abbrev(tcp)) {
377 PRINT_FIELD_FLAGS(", ", dq, qs_flags,
378 xfs_quota_flags, "XFS_QUOTA_???");
379 PRINT_FIELD_U(", ", dq, qs_incoredqs);
380 PRINT_FIELD_U(", qs_uquota={", dq.qs_uquota, qfs_ino);
381 PRINT_FIELD_U(", ", dq.qs_uquota, qfs_nblks);
382 PRINT_FIELD_U(", ", dq.qs_uquota, qfs_nextents);
383 PRINT_FIELD_U("}, qs_gquota={", dq.qs_gquota, qfs_ino);
384 PRINT_FIELD_U(", ", dq.qs_gquota, qfs_nblks);
385 PRINT_FIELD_U(", ", dq.qs_gquota, qfs_nextents);
386 PRINT_FIELD_U("}, qs_pquota={", dq.qs_pquota, qfs_ino);
387 PRINT_FIELD_U(", ", dq.qs_pquota, qfs_nblks);
388 PRINT_FIELD_U(", ", dq.qs_pquota, qfs_nextents);
389 PRINT_FIELD_D("}, ", dq, qs_btimelimit);
390 PRINT_FIELD_D(", ", dq, qs_itimelimit);
391 PRINT_FIELD_D(", ", dq, qs_rtbtimelimit);
392 PRINT_FIELD_U(", ", dq, qs_bwarnlimit);
393 PRINT_FIELD_U(", ", dq, qs_iwarnlimit);
394 } else {
395 tprints(", ...");
396 }
397 tprints("}");
398 break;
399 }
400 case Q_XQUOTAON:
401 case Q_XQUOTAOFF:
402 {
403 uint32_t flag;
404
405 tprints(", ");
406
407 if (umove_or_printaddr(tcp, data, &flag))
408 break;
409 tprints("[");
410 printflags(xfs_quota_flags, flag, "XFS_QUOTA_???");
411 tprints("]");
412 break;
413 }
414 case Q_XQUOTARM:
415 {
416 uint32_t flag;
417
418 tprints(", ");
419
420 if (umove_or_printaddr(tcp, data, &flag))
421 break;
422 tprints("[");
423 printflags(xfs_dqblk_flags, flag, "XFS_???_QUOTA");
424 tprints("]");
425 break;
426 }
427 default:
428 printuid(", ", id);
429 tprints(", ");
430 printaddr(data);
431 break;
432 }
433 return RVAL_DECODED;
434 }
435
SYS_FUNC(quotactl)436 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 uint32_t qcmd = tcp->u_arg[0];
445 uint32_t cmd = QCMD_CMD(qcmd);
446 uint32_t type = QCMD_TYPE(qcmd);
447 uint32_t id = tcp->u_arg[2];
448
449 if (entering(tcp)) {
450 tprints("QCMD(");
451 printxval(quotacmds, cmd, "Q_???");
452 tprints(", ");
453 printxval(quotatypes, type, "???QUOTA");
454 tprints("), ");
455 printpath(tcp, tcp->u_arg[1]);
456 }
457 return decode_cmd_data(tcp, id, cmd, tcp->u_arg[3]);
458 }
459