Browse Source

quotactl: add xlat styles support

* quota.c (print_qcmd): New function.
(SYS_FUNC(quotactl)): Use it to print the quotactl command.
* tests/quotactl.c (print_dqinfo, print_dqfmt): Handle XLAT_RAW
and XLAT_VERBOSE.
(QUOTA_STR, QUOTA_ID_STR, QUOTA_STR_INVALID): New macros.
(gen_quotacmd, gen_quotaid): New functions.
(main): Use them.
* tests/quotactl-Xabbrev.c: New file.
* tests/quotactl-Xraw.c: Likewise.
* tests/quotactl-Xverbose.c: Likewise.
* tests/gen_tests.in (quotactl-Xabbrev, quotactl-Xraw,
quotactl-Xverbose): New tests.
* tests/pure_executables.list: Add quotactl-Xabbrev, quotactl-Xraw,
and quotactl-Xverbose.
* tests/.gitignore: Likewise.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
Shankara Pailoor 11 months ago
parent
commit
1448070a00
8 changed files with 130 additions and 30 deletions
  1. 26
    5
      quota.c
  2. 3
    0
      tests/.gitignore
  3. 3
    0
      tests/gen_tests.in
  4. 3
    0
      tests/pure_executables.list
  5. 1
    0
      tests/quotactl-Xabbrev.c
  6. 2
    0
      tests/quotactl-Xraw.c
  7. 2
    0
      tests/quotactl-Xverbose.c
  8. 90
    25
      tests/quotactl.c

+ 26
- 5
quota.c View File

@@ -394,6 +394,31 @@ decode_cmd_data(struct tcb *tcp, uint32_t id, uint32_t cmd, kernel_ulong_t data)
394 394
 	return RVAL_DECODED;
395 395
 }
396 396
 
397
+static void
398
+print_qcmd(const uint32_t qcmd)
399
+{
400
+	const uint32_t cmd = QCMD_CMD(qcmd);
401
+	const uint32_t type = QCMD_TYPE(qcmd);
402
+
403
+	if (xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
404
+		tprintf("%u", qcmd);
405
+
406
+	if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
407
+		return;
408
+
409
+	if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE)
410
+		tprints(" /* ");
411
+
412
+	tprints("QCMD(");
413
+	printxvals_ex(cmd, "Q_???", XLAT_STYLE_ABBREV, quotacmds, NULL);
414
+	tprints(", ");
415
+	printxvals_ex(type, "???QUOTA", XLAT_STYLE_ABBREV, quotatypes, NULL);
416
+	tprints(")");
417
+
418
+	if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE)
419
+		tprints(" */");
420
+}
421
+
397 422
 SYS_FUNC(quotactl)
398 423
 {
399 424
 	/*
@@ -404,15 +429,11 @@ SYS_FUNC(quotactl)
404 429
 	 */
405 430
 	uint32_t qcmd = tcp->u_arg[0];
406 431
 	uint32_t cmd = QCMD_CMD(qcmd);
407
-	uint32_t type = QCMD_TYPE(qcmd);
408 432
 	uint32_t id = tcp->u_arg[2];
409 433
 
410 434
 	if (entering(tcp)) {
411
-		tprints("QCMD(");
412
-		printxval(quotacmds, cmd, "Q_???");
435
+		print_qcmd(qcmd);
413 436
 		tprints(", ");
414
-		printxval(quotatypes, type, "???QUOTA");
415
-		tprints("), ");
416 437
 		printpath(tcp, tcp->u_arg[1]);
417 438
 	}
418 439
 	return decode_cmd_data(tcp, id, cmd, tcp->u_arg[3]);

+ 3
- 0
tests/.gitignore View File

@@ -412,6 +412,9 @@ qual_inject-retval
412 412
 qual_inject-signal
413 413
 qual_signal
414 414
 quotactl
415
+quotactl-Xabbrev
416
+quotactl-Xraw
417
+quotactl-Xverbose
415 418
 quotactl-success
416 419
 quotactl-success-v
417 420
 quotactl-v

+ 3
- 0
tests/gen_tests.in View File

@@ -338,6 +338,9 @@ ptrace	-a23 -e signal=none
338 338
 ptrace_syscall_info	-a35 -e signal=none -e trace=ptrace
339 339
 pwritev	-a22 -s7
340 340
 quotactl
341
+quotactl-Xabbrev	-Xabbrev -e trace=quotactl
342
+quotactl-Xraw	-a27 -Xraw -e trace=quotactl
343
+quotactl-Xverbose	-Xverbose -e trace=quotactl
341 344
 quotactl-v	-v -e trace=quotactl
342 345
 quotactl-xfs	-e trace=quotactl
343 346
 quotactl-xfs-v	-v -e trace=quotactl

+ 3
- 0
tests/pure_executables.list View File

@@ -342,6 +342,9 @@ ptrace
342 342
 ptrace_syscall_info
343 343
 pwritev
344 344
 quotactl
345
+quotactl-Xabbrev
346
+quotactl-Xraw
347
+quotactl-Xverbose
345 348
 quotactl-xfs
346 349
 read-write
347 350
 readahead

+ 1
- 0
tests/quotactl-Xabbrev.c View File

@@ -0,0 +1 @@
1
+#include "quotactl.c"

+ 2
- 0
tests/quotactl-Xraw.c View File

@@ -0,0 +1,2 @@
1
+#define XLAT_RAW 1
2
+#include "quotactl.c"

+ 2
- 0
tests/quotactl-Xverbose.c View File

@@ -0,0 +1,2 @@
1
+#define XLAT_VERBOSE 1
2
+#include "quotactl.c"

+ 90
- 25
tests/quotactl.c View File

@@ -57,6 +57,10 @@ struct if_nextdqblk {
57 57
 # include "xlat/if_dqinfo_flags.h"
58 58
 # include "xlat/if_dqinfo_valid.h"
59 59
 
60
+#define QUOTA_STR(_arg) (_arg), gen_quotacmd(#_arg, _arg)
61
+#define QUOTA_ID_STR(_arg) (_arg), gen_quotaid(#_arg, _arg)
62
+#define QUOTA_STR_INVALID(_arg, str) (_arg), gen_quotacmd(str, _arg)
63
+
60 64
 void
61 65
 print_dqblk(long rc, void *ptr, void *arg)
62 66
 {
@@ -135,9 +139,25 @@ print_dqinfo(long rc, void *ptr, void *arg)
135 139
 	PRINT_FIELD_U(", ", *di, dqi_igrace);
136 140
 
137 141
 	printf(", dqi_flags=");
142
+#if XLAT_RAW
143
+	printf("%#x", di->dqi_flags);
144
+#elif XLAT_VERBOSE
145
+	printf("%#x /* ", di->dqi_flags);
146
+	printflags(if_dqinfo_flags, di->dqi_flags, "DQF_???");
147
+	printf(" */");
148
+#else /* XLAT_ABBREV */
138 149
 	printflags(if_dqinfo_flags, di->dqi_flags, "DQF_???");
150
+#endif
139 151
 	printf(", dqi_valid=");
152
+#if XLAT_RAW
153
+	printf("%#x", di->dqi_valid);
154
+#elif XLAT_VERBOSE
155
+	printf("%#x /* ", di->dqi_valid);
140 156
 	printflags(if_dqinfo_valid, di->dqi_valid, "IIF_???");
157
+	printf(" */");
158
+#else /* XLAT_ABBREV */
159
+	printflags(if_dqinfo_valid, di->dqi_valid, "IIF_???");
160
+#endif
141 161
 	printf("}");
142 162
 }
143 163
 
@@ -153,6 +173,10 @@ print_dqfmt(long rc, void *ptr, void *arg)
153 173
 		return;
154 174
 	}
155 175
 	printf("[");
176
+#if XLAT_RAW
177
+	printf("%#x]", *fmtval);
178
+	return;
179
+#else
156 180
 	switch (*fmtval) {
157 181
 	case 1:
158 182
 		fmtstr = "QFMT_VFS_OLD";
@@ -170,9 +194,43 @@ print_dqfmt(long rc, void *ptr, void *arg)
170 194
 		printf("%#x /* QFMT_VFS_??? */]", *fmtval);
171 195
 		return;
172 196
 	}
197
+#endif
198
+#if XLAT_VERBOSE
199
+	printf("%#x /* %s */]", *fmtval, fmtstr);
200
+#else
173 201
 	printf("%s]", fmtstr);
202
+#endif
203
+}
204
+
205
+const char *
206
+gen_quotacmd(const char *abbrev_str, const uint32_t cmd)
207
+{
208
+	static char quotacmd_str[2048];
209
+
210
+#if XLAT_RAW
211
+	snprintf(quotacmd_str, sizeof(quotacmd_str), "%u", cmd);
212
+#elif XLAT_VERBOSE
213
+	snprintf(quotacmd_str, sizeof(quotacmd_str), "%u /* %s */", cmd, abbrev_str);
214
+#else
215
+	return abbrev_str;
216
+#endif
217
+	return quotacmd_str;
174 218
 }
175 219
 
220
+const char *
221
+gen_quotaid(const char *abbrev_str, const uint32_t id)
222
+{
223
+	static char quotaid_str[1024];
224
+
225
+#if XLAT_RAW
226
+	snprintf(quotaid_str, sizeof(quotaid_str), "%#x", id);
227
+#elif XLAT_VERBOSE
228
+	snprintf(quotaid_str, sizeof(quotaid_str), "%#x /* %s */", id, abbrev_str);
229
+#else
230
+	return abbrev_str;
231
+#endif
232
+	return quotaid_str;
233
+}
176 234
 
177 235
 int
178 236
 main(void)
@@ -199,65 +257,71 @@ main(void)
199 257
 
200 258
 
201 259
 	/* Invalid commands */
202
-
203 260
 	snprintf(invalid_cmd_str, sizeof(invalid_cmd_str),
204 261
 		 "QCMD(%#x /* Q_??? */, %#x /* ???QUOTA */)",
205 262
 		 QCMD_CMD(bogus_cmd), QCMD_TYPE(bogus_cmd));
206
-	check_quota(CQF_NONE, bogus_cmd, invalid_cmd_str,
263
+	check_quota(CQF_NONE, bogus_cmd, gen_quotacmd(invalid_cmd_str, bogus_cmd),
207 264
 		    bogus_special, bogus_special_str, bogus_id, bogus_addr);
208 265
 
209 266
 	snprintf(invalid_cmd_str, sizeof(invalid_cmd_str),
210 267
 		 "QCMD(0 /* Q_??? */, USRQUOTA)");
211
-	check_quota(CQF_ADDR_STR, 0, invalid_cmd_str,
268
+	check_quota(CQF_ADDR_STR, 0, gen_quotacmd(invalid_cmd_str, 0),
212 269
 		    ARG_STR(NULL), -1, ARG_STR(NULL));
213 270
 
214 271
 
215 272
 	/* Q_QUOTAON */
216 273
 
217 274
 	check_quota(CQF_ID_STR | CQF_ADDR_STR,
218
-		    ARG_STR(QCMD(Q_QUOTAON, USRQUOTA)),
219
-		    ARG_STR("/dev/bogus/"), ARG_STR(QFMT_VFS_OLD),
275
+		    QUOTA_STR(QCMD(Q_QUOTAON, USRQUOTA)),
276
+		    ARG_STR("/dev/bogus/"), QUOTA_ID_STR(QFMT_VFS_OLD),
220 277
 		    ARG_STR("/tmp/bogus/"));
221 278
 
222 279
 	snprintf(invalid_cmd_str, sizeof(invalid_cmd_str),
223 280
 		 "QCMD(Q_QUOTAON, %#x /* ???QUOTA */)",
224 281
 		 QCMD_TYPE(QCMD(Q_QUOTAON, 0xfacefeed)));
282
+#if XLAT_RAW
283
+	snprintf(invalid_id_str, sizeof(invalid_id_str),
284
+		 "%#x", bogus_id);
285
+#else
225 286
 	snprintf(invalid_id_str, sizeof(invalid_id_str),
226 287
 		 "%#x /* QFMT_VFS_??? */", bogus_id);
288
+#endif
227 289
 	check_quota(CQF_ID_STR, QCMD(Q_QUOTAON, 0xfacefeed),
228
-		    invalid_cmd_str, bogus_dev, bogus_dev_str,
290
+		    gen_quotacmd(invalid_cmd_str, QCMD(Q_QUOTAON, 0xfacefeed)),
291
+		    bogus_dev, bogus_dev_str,
229 292
 		    bogus_id, invalid_id_str, bogus_addr);
230 293
 
231 294
 
232 295
 	/* Q_QUOTAOFF */
233 296
 
234 297
 	check_quota(CQF_ID_SKIP | CQF_ADDR_SKIP,
235
-		    ARG_STR(QCMD(Q_QUOTAOFF, USRQUOTA)),
298
+		    QUOTA_STR(QCMD(Q_QUOTAOFF, USRQUOTA)),
236 299
 		    bogus_special, bogus_special_str);
237 300
 	check_quota(CQF_ID_SKIP | CQF_ADDR_SKIP,
238
-		    ARG_STR(QCMD(Q_QUOTAOFF, GRPQUOTA)),
301
+		    QUOTA_STR(QCMD(Q_QUOTAOFF, GRPQUOTA)),
239 302
 		    ARG_STR("/dev/bogus/"));
240 303
 	check_quota(CQF_ID_SKIP | CQF_ADDR_SKIP,
241
-		    ARG_STR(QCMD(Q_QUOTAOFF, PRJQUOTA)), ARG_STR(NULL));
304
+		    QUOTA_STR(QCMD(Q_QUOTAOFF, PRJQUOTA)), ARG_STR(NULL));
305
+	const char *cmd_str = "QCMD(Q_QUOTAOFF, 0x3 /* ???QUOTA */)";
242 306
 	check_quota(CQF_ID_SKIP | CQF_ADDR_SKIP,
243
-		    QCMD(Q_QUOTAOFF, 3), "QCMD(Q_QUOTAOFF, 0x3 /* ???QUOTA */)",
307
+		    QUOTA_STR_INVALID(QCMD(Q_QUOTAOFF, 3), cmd_str),
244 308
 		    ARG_STR(NULL));
245 309
 
246 310
 
247 311
 	/* Q_GETQUOTA */
248 312
 
249 313
 	/* Trying our best to get successful result */
250
-	check_quota(CQF_ADDR_CB, ARG_STR(QCMD(Q_GETQUOTA, USRQUOTA)),
314
+	check_quota(CQF_ADDR_CB, QUOTA_STR(QCMD(Q_GETQUOTA, USRQUOTA)),
251 315
 		    ARG_STR("/dev/sda1"), getuid(), dqblk, print_dqblk,
252 316
 		    (intptr_t) 1);
253 317
 
254
-	check_quota(CQF_ADDR_CB, ARG_STR(QCMD(Q_GETQUOTA, GRPQUOTA)),
318
+	check_quota(CQF_ADDR_CB, QUOTA_STR(QCMD(Q_GETQUOTA, GRPQUOTA)),
255 319
 		    ARG_STR(NULL), -1, dqblk, print_dqblk, (intptr_t) 1);
256 320
 
257 321
 
258 322
 	/* Q_GETNEXTQUOTA */
259 323
 
260
-	check_quota(CQF_ADDR_CB, ARG_STR(QCMD(Q_GETNEXTQUOTA, USRQUOTA)),
324
+	check_quota(CQF_ADDR_CB, QUOTA_STR(QCMD(Q_GETNEXTQUOTA, USRQUOTA)),
261 325
 		    ARG_STR("/dev/sda1"), 0, nextdqblk, print_nextdqblk,
262 326
 		    (intptr_t) 1);
263 327
 
@@ -266,10 +330,10 @@ main(void)
266 330
 
267 331
 	fill_memory(dqblk, sizeof(*dqblk));
268 332
 
269
-	check_quota(CQF_NONE, ARG_STR(QCMD(Q_SETQUOTA, PRJQUOTA)),
333
+	check_quota(CQF_NONE, QUOTA_STR(QCMD(Q_SETQUOTA, PRJQUOTA)),
270 334
 		    bogus_special, bogus_special_str, 0, bogus_addr);
271 335
 
272
-	check_quota(CQF_ADDR_CB, ARG_STR(QCMD(Q_SETQUOTA, PRJQUOTA)),
336
+	check_quota(CQF_ADDR_CB, QUOTA_STR(QCMD(Q_SETQUOTA, PRJQUOTA)),
273 337
 		    ARG_STR("/dev/bogus/"), 3141592653U, dqblk, print_dqblk,
274 338
 		    (intptr_t) 0);
275 339
 
@@ -277,11 +341,11 @@ main(void)
277 341
 	/* Q_GETINFO */
278 342
 
279 343
 	check_quota(CQF_ID_SKIP | CQF_ADDR_CB,
280
-		    ARG_STR(QCMD(Q_GETINFO, GRPQUOTA)),
344
+		    QUOTA_STR(QCMD(Q_GETINFO, GRPQUOTA)),
281 345
 		    ARG_STR("/dev/sda1"), dqinfo, print_dqinfo, (intptr_t) 1);
282 346
 
283 347
 	check_quota(CQF_ID_SKIP | CQF_ADDR_CB,
284
-		    ARG_STR(QCMD(Q_GETINFO, GRPQUOTA)),
348
+		    QUOTA_STR(QCMD(Q_GETINFO, GRPQUOTA)),
285 349
 		    bogus_special, bogus_special_str, dqinfo,
286 350
 		    print_dqinfo, (intptr_t) 1);
287 351
 
@@ -292,39 +356,40 @@ main(void)
292 356
 	dqinfo->dqi_flags = 0xdeadabcd;
293 357
 
294 358
 	check_quota(CQF_ID_SKIP | CQF_ADDR_STR,
295
-		    ARG_STR(QCMD(Q_SETINFO, PRJQUOTA)),
359
+		    QUOTA_STR(QCMD(Q_SETINFO, PRJQUOTA)),
296 360
 		    bogus_special, bogus_special_str, ARG_STR(NULL));
297 361
 
298 362
 	check_quota(CQF_ID_SKIP | CQF_ADDR_CB,
299
-		    ARG_STR(QCMD(Q_SETINFO, USRQUOTA)),
363
+		    QUOTA_STR(QCMD(Q_SETINFO, USRQUOTA)),
300 364
 		    ARG_STR("/dev/bogus/"), dqinfo, print_dqinfo, (intptr_t) 0);
301 365
 
302 366
 
303 367
 	/* Q_GETFMT */
304 368
 
305 369
 	check_quota(CQF_ID_SKIP | CQF_ADDR_STR,
306
-		    ARG_STR(QCMD(Q_GETFMT, PRJQUOTA)),
370
+		    QUOTA_STR(QCMD(Q_GETFMT, PRJQUOTA)),
307 371
 		    bogus_special, bogus_special_str, ARG_STR(NULL));
308 372
 	check_quota(CQF_ID_SKIP,
309
-		    ARG_STR(QCMD(Q_GETFMT, USRQUOTA)),
373
+		    QUOTA_STR(QCMD(Q_GETFMT, USRQUOTA)),
310 374
 		    unterminated, unterminated_str, fmt + 1);
311 375
 	check_quota(CQF_ID_SKIP | CQF_ADDR_CB,
312
-		    ARG_STR(QCMD(Q_GETFMT, GRPQUOTA)),
376
+		    QUOTA_STR(QCMD(Q_GETFMT, GRPQUOTA)),
313 377
 		    ARG_STR("/dev/sda1"), fmt, print_dqfmt, (uintptr_t) 1);
314 378
 	/* Try to check valid quota format */
315 379
 	*fmt = QFMT_VFS_OLD;
316 380
 	check_quota(CQF_ID_SKIP | CQF_ADDR_CB,
317
-		    ARG_STR(QCMD(Q_GETFMT, GRPQUOTA)),
381
+		    QUOTA_STR(QCMD(Q_GETFMT, GRPQUOTA)),
318 382
 		    ARG_STR("/dev/sda1"), fmt, print_dqfmt, (uintptr_t) 1);
319 383
 
320 384
 
321 385
 	/* Q_SYNC */
322 386
 
323 387
 	check_quota(CQF_ID_SKIP | CQF_ADDR_SKIP,
324
-		    ARG_STR(QCMD(Q_SYNC, USRQUOTA)),
388
+		    QUOTA_STR(QCMD(Q_SYNC, USRQUOTA)),
325 389
 		    bogus_special, bogus_special_str);
390
+	cmd_str = "QCMD(Q_SYNC, 0xff /* ???QUOTA */)";
326 391
 	check_quota(CQF_ID_SKIP | CQF_ADDR_SKIP,
327
-		    QCMD(Q_SYNC, 0xfff), "QCMD(Q_SYNC, 0xff /* ???QUOTA */)",
392
+		    QUOTA_STR_INVALID(QCMD(Q_SYNC, 0xfff), cmd_str),
328 393
 		    ARG_STR(NULL));
329 394
 
330 395
 	puts("+++ exited with 0 +++");

Loading…
Cancel
Save