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.

loop.c 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * Copyright (c) 2012 The Chromium OS Authors.
  3. * Copyright (c) 2012-2018 The strace developers.
  4. * Written by Mike Frysinger <vapier@gentoo.org>.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. The name of the author may not be used to endorse or promote products
  15. * derived from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  18. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. #include "defs.h"
  29. #include <linux/ioctl.h>
  30. #include <linux/loop.h>
  31. typedef struct loop_info struct_loop_info;
  32. #include DEF_MPERS_TYPE(struct_loop_info)
  33. #include MPERS_DEFS
  34. #include "print_fields.h"
  35. #include "xlat/loop_cmds.h"
  36. #include "xlat/loop_flags_options.h"
  37. #include "xlat/loop_crypt_type_options.h"
  38. static void
  39. decode_loop_info(struct tcb *const tcp, const kernel_ulong_t addr)
  40. {
  41. struct_loop_info info;
  42. tprints(", ");
  43. if (umove_or_printaddr(tcp, addr, &info))
  44. return;
  45. tprintf("{lo_number=%d", info.lo_number);
  46. if (!abbrev(tcp)) {
  47. PRINT_FIELD_DEV(", ", info, lo_device);
  48. tprintf(", lo_inode=%" PRI_klu, (kernel_ulong_t) info.lo_inode);
  49. PRINT_FIELD_DEV(", ", info, lo_rdevice);
  50. }
  51. tprintf(", lo_offset=%#x", info.lo_offset);
  52. if (!abbrev(tcp) || info.lo_encrypt_type != LO_CRYPT_NONE) {
  53. tprints(", lo_encrypt_type=");
  54. printxval(loop_crypt_type_options, info.lo_encrypt_type,
  55. "LO_CRYPT_???");
  56. /*
  57. * It is converted to unsigned before use in kernel, see
  58. * loop_info64_from_old in drivers/block/loop.c
  59. */
  60. tprintf(", lo_encrypt_key_size=%" PRIu32,
  61. (uint32_t) info.lo_encrypt_key_size);
  62. }
  63. tprints(", lo_flags=");
  64. printflags(loop_flags_options, info.lo_flags, "LO_FLAGS_???");
  65. PRINT_FIELD_CSTRING(", ", info, lo_name);
  66. if (!abbrev(tcp) || info.lo_encrypt_type != LO_CRYPT_NONE) {
  67. const unsigned int lo_encrypt_key_size =
  68. MIN((unsigned) info.lo_encrypt_key_size, LO_KEY_SIZE);
  69. PRINT_FIELD_STRING(", ", info, lo_encrypt_key,
  70. lo_encrypt_key_size, 0);
  71. }
  72. if (!abbrev(tcp))
  73. tprintf(", lo_init=[%#" PRI_klx ", %#" PRI_klx "]"
  74. ", reserved=[%#hhx, %#hhx, %#hhx, %#hhx]}",
  75. (kernel_ulong_t) info.lo_init[0],
  76. (kernel_ulong_t) info.lo_init[1],
  77. info.reserved[0], info.reserved[1],
  78. info.reserved[2], info.reserved[3]);
  79. else
  80. tprints(", ...}");
  81. }
  82. static void
  83. decode_loop_info64(struct tcb *const tcp, const kernel_ulong_t addr)
  84. {
  85. struct loop_info64 info64;
  86. tprints(", ");
  87. if (umove_or_printaddr(tcp, addr, &info64))
  88. return;
  89. if (!abbrev(tcp)) {
  90. PRINT_FIELD_DEV("{", info64, lo_device);
  91. tprintf(", lo_inode=%" PRIu64, (uint64_t) info64.lo_inode);
  92. PRINT_FIELD_DEV(", ", info64, lo_rdevice);
  93. tprintf(", lo_offset=%#" PRIx64 ", lo_sizelimit=%" PRIu64
  94. ", lo_number=%" PRIu32,
  95. (uint64_t) info64.lo_offset,
  96. (uint64_t) info64.lo_sizelimit,
  97. (uint32_t) info64.lo_number);
  98. } else {
  99. tprintf("{lo_offset=%#" PRIx64 ", lo_number=%" PRIu32,
  100. (uint64_t) info64.lo_offset,
  101. (uint32_t) info64.lo_number);
  102. }
  103. if (!abbrev(tcp) || info64.lo_encrypt_type != LO_CRYPT_NONE) {
  104. tprints(", lo_encrypt_type=");
  105. printxval(loop_crypt_type_options, info64.lo_encrypt_type,
  106. "LO_CRYPT_???");
  107. tprintf(", lo_encrypt_key_size=%" PRIu32,
  108. info64.lo_encrypt_key_size);
  109. }
  110. tprints(", lo_flags=");
  111. printflags(loop_flags_options, info64.lo_flags, "LO_FLAGS_???");
  112. PRINT_FIELD_CSTRING(", ", info64, lo_file_name);
  113. if (!abbrev(tcp) || info64.lo_encrypt_type != LO_CRYPT_NONE) {
  114. PRINT_FIELD_CSTRING(", ", info64, lo_crypt_name);
  115. const unsigned int lo_encrypt_key_size =
  116. MIN((unsigned) info64.lo_encrypt_key_size, LO_KEY_SIZE);
  117. PRINT_FIELD_STRING(", ", info64, lo_encrypt_key,
  118. lo_encrypt_key_size, 0);
  119. }
  120. if (!abbrev(tcp))
  121. tprintf(", lo_init=[%#" PRIx64 ", %#" PRIx64 "]}",
  122. (uint64_t) info64.lo_init[0],
  123. (uint64_t) info64.lo_init[1]);
  124. else
  125. tprints(", ...}");
  126. }
  127. MPERS_PRINTER_DECL(int, loop_ioctl,
  128. struct tcb *tcp, const unsigned int code,
  129. const kernel_ulong_t arg)
  130. {
  131. switch (code) {
  132. case LOOP_GET_STATUS:
  133. if (entering(tcp))
  134. return 0;
  135. ATTRIBUTE_FALLTHROUGH;
  136. case LOOP_SET_STATUS:
  137. decode_loop_info(tcp, arg);
  138. break;
  139. case LOOP_GET_STATUS64:
  140. if (entering(tcp))
  141. return 0;
  142. ATTRIBUTE_FALLTHROUGH;
  143. case LOOP_SET_STATUS64:
  144. decode_loop_info64(tcp, arg);
  145. break;
  146. case LOOP_CLR_FD:
  147. case LOOP_SET_CAPACITY:
  148. /* newer loop-control stuff */
  149. case LOOP_CTL_GET_FREE:
  150. /* Takes no arguments */
  151. break;
  152. case LOOP_SET_FD:
  153. case LOOP_CHANGE_FD:
  154. tprints(", ");
  155. printfd(tcp, arg);
  156. break;
  157. /* newer loop-control stuff */
  158. case LOOP_CTL_ADD:
  159. case LOOP_CTL_REMOVE:
  160. tprintf(", %d", (int) arg);
  161. break;
  162. case LOOP_SET_DIRECT_IO:
  163. case LOOP_SET_BLOCK_SIZE:
  164. tprintf(", %" PRI_klu, arg);
  165. break;
  166. default:
  167. return RVAL_DECODED;
  168. }
  169. return RVAL_IOCTL_DECODED;
  170. }