Mirror of strace – the linux syscall tracer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ioprio.c 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (c) 2015 Dmitry V. Levin <ldv@altlinux.org>
  3. * Copyright (c) 2014-2019 The strace developers.
  4. * All rights reserved.
  5. *
  6. * SPDX-License-Identifier: LGPL-2.1-or-later
  7. */
  8. #include "defs.h"
  9. #include "xstring.h"
  10. #include "xlat/ioprio_who.h"
  11. #include "xlat/ioprio_class.h"
  12. #define IOPRIO_CLASS_SHIFT (13)
  13. #define IOPRIO_PRIO_MASK ((1ul << IOPRIO_CLASS_SHIFT) - 1)
  14. #define IOPRIO_PRIO_CLASS(mask) ((mask) >> IOPRIO_CLASS_SHIFT)
  15. #define IOPRIO_PRIO_DATA(mask) ((mask) & IOPRIO_PRIO_MASK)
  16. static const char *
  17. sprint_ioprio(unsigned int ioprio)
  18. {
  19. static char outstr[256];
  20. char class_buf[64];
  21. unsigned int class, data;
  22. class = IOPRIO_PRIO_CLASS(ioprio);
  23. data = IOPRIO_PRIO_DATA(ioprio);
  24. sprintxval(class_buf, sizeof(class_buf), ioprio_class, class,
  25. "IOPRIO_CLASS_???");
  26. xsprintf(outstr, "IOPRIO_PRIO_VALUE(%s, %d)", class_buf, data);
  27. return outstr;
  28. }
  29. void
  30. print_ioprio(unsigned int ioprio)
  31. {
  32. if (xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
  33. tprintf("%#x", ioprio);
  34. if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
  35. return;
  36. const char *str = sprint_ioprio(ioprio);
  37. (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE
  38. ? tprints_comment : tprints)(str);
  39. }
  40. SYS_FUNC(ioprio_get)
  41. {
  42. if (entering(tcp)) {
  43. /* int which */
  44. printxval(ioprio_who, tcp->u_arg[0], "IOPRIO_WHO_???");
  45. /* int who */
  46. tprintf(", %d", (int) tcp->u_arg[1]);
  47. return 0;
  48. } else {
  49. if (syserror(tcp))
  50. return 0;
  51. if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
  52. tcp->auxstr = NULL;
  53. else
  54. tcp->auxstr = sprint_ioprio(tcp->u_rval);
  55. return RVAL_STR;
  56. }
  57. }
  58. SYS_FUNC(ioprio_set)
  59. {
  60. /* int which */
  61. printxval(ioprio_who, tcp->u_arg[0], "IOPRIO_WHO_???");
  62. /* int who */
  63. tprintf(", %d, ", (int) tcp->u_arg[1]);
  64. /* int ioprio */
  65. if (xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
  66. tprintf("%d", (int) tcp->u_arg[2]);
  67. if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
  68. return RVAL_DECODED;
  69. (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE
  70. ? tprints_comment : tprints)(sprint_ioprio(tcp->u_arg[2]));
  71. return RVAL_DECODED;
  72. }